@@ -83,14 +83,14 @@ def exceptionDialog(msg):
8383 dlg .exec_ ()
8484
8585
86- def transformAndPlot (interface , plot ):
86+ def transformAndPlot (plot , matrix ):
8787 try :
88- transformationMatrix = Matrix ([[ N ( interface . matrix00 . text ()), N ( interface . matrix10 . text ()), N ( interface . matrix20 . text ())],
89- [ N ( interface . matrix01 . text ()), N ( interface . matrix11 . text ()), N ( interface . matrix21 . text ())],
90- [ N ( interface .matrix02 . text ()), N ( interface . matrix12 . text ()), N ( interface . matrix22 . text ())]] )
91-
92-
93- xyzgrid = get_transformedGrid ( originalGrid , transformationMatrix ) # get a transformed grid
88+ matrix = array ( matrix )
89+ print ( matrix )
90+ interface .setMatrix ( matrix )
91+ xyzgrid = get_transformedGrid ( originalGrid , Matrix ([[ N ( matrix [ 0 , 0 ]), N ( matrix [ 0 , 1 ]), N ( matrix [ 0 , 2 ])],
92+ [ N ( matrix [ 1 , 0 ]), N ( matrix [ 1 , 1 ]), N ( matrix [ 1 , 2 ])],
93+ [ N ( matrix [ 2 , 0 ]), N ( matrix [ 2 , 1 ]), N ( matrix [ 2 , 2 ])]]) ) # get a transformed grid
9494
9595 plot .scatter (xyzgrid ,colors )
9696 adjust_plot (plot .axes )
@@ -100,14 +100,28 @@ def transformAndPlot(interface, plot):
100100 print (err )
101101 exceptionDialog ('An error has ocurred. Remember that you only can write operations between numbers or trigonometric functions in the matrix boxes. ex. sin(3*pi/2) or 30+0.5' )
102102
103+ def examplesComboBox (window ,comboBox ):
104+ examples = {
105+ 'Original Grid' :[[1 , 0 , 0 ],[0 , 1 , 0 ],[0 , 0 , 1 ]],
106+ 'X rotation 45º' :[[1 , 0 , 0 ],[0 , 'cos(45*pi/180)' , - sin (45 * pi / 180 )],[0 , sin (45 * pi / 180 ), cos (45 * pi / 180 )]],
107+ 'Y rotation 45º' :[[cos (45 * pi / 180 ), - sin (45 * pi / 180 ), 0 ],[sin (45 * pi / 180 ), cos (45 * pi / 180 ), 0 ],[0 , 0 , 1 ]],
108+ 'Z rotation 45º' :[[cos (45 * pi / 180 ), 0 , - sin (45 * pi / 180 )],[0 , 1 , 0 ],[sin (45 * pi / 180 ), 0 , cos (45 * pi / 180 )]]
109+ }
110+ for key in examples :
111+ examplesWidget .addItem (key )
112+
113+ examplesWidget .activated [str ].connect (lambda str : transformAndPlot (window ,examples .get (str )))
114+
115+ window .addToLayout (examplesWidget , [11 ,1 ],[3 ,1 ])
116+
103117if __name__ == "__main__" :
104118 """Transformation matrix"""
105- transformationMatrix = Matrix ( [[1 , 0 , 0 ],
106- [0 , 1 , 0 ],
107- [0 , 0 , 1 ]])
119+ transformationMatrix = [[1 , 0 , 0 ],
120+ [0 , 1 , 0 ],
121+ [0 , 0 , 1 ]]
108122
109123 originalGrid = get_grid (- 2 ,2 ) # Create a straigh grid
110- xyzgrid = get_transformedGrid (originalGrid , transformationMatrix ) # get a transformed grid
124+ xyzgrid = get_transformedGrid (originalGrid , Matrix ( transformationMatrix ) ) # get a transformed grid
111125
112126 colors = list (map (colorizer , originalGrid [0 ], originalGrid [1 ], originalGrid [2 ])) # Asign the colors to the points
113127
@@ -117,15 +131,20 @@ def transformAndPlot(interface, plot):
117131 plot .scatter (xyzgrid ,colors ) # Scatter
118132
119133 adjust_plot (plot .axes ) # Set the limits of the axes
120-
121- plot .addToLayout (QtWidgets .QLabel ('Titulo' ),[11 ,0 ],[1 ,1 ])
134+
135+ plot .addToLayout (QtWidgets .QLabel ('Examples' ),[11 ,0 ],[1 ,1 ])
136+ examplesWidget = QtWidgets .QComboBox ()
137+ examplesComboBox (plot ,examplesWidget )
122138
123139 interface = MatrixButtons () # Get the interface
124140 plot .addToLayout (interface ,[11 ,4 ],[10 ,2 ]) # add the interface to the plot layout
125141
126- interface .setMatrix (transformationMatrix )
142+ interface .setMatrix (array ( transformationMatrix ) )
127143
128- interface .plotButton .clicked .connect (lambda : transformAndPlot (interface ,plot ))
144+ interface .plotButton .clicked .connect (
145+ lambda : transformAndPlot (plot ,[[interface .matrix00 .text (), interface .matrix10 .text (), interface .matrix20 .text ()],
146+ [interface .matrix01 .text (), interface .matrix11 .text (), interface .matrix21 .text ()],
147+ [interface .matrix02 .text (), interface .matrix12 .text (), interface .matrix22 .text ()]]))
129148
130149 plot .show ()
131150 app .exec ()
0 commit comments