/usr/share/pyshared/PyMca/Object3D/ClippingPlaneConfiguration.py is in pymca 4.5.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | import Object3DQt as qt
import PyQt4.Qwt5 as Qwt
from Object3DMovement import Object3DRotationWidget, Object3DTranslationWidget
import numpy
DEBUG = 0
class ClippingPlaneConfiguration(qt.QGroupBox):
def __init__(self, parent = None):
qt.QGroupBox.__init__(self, parent)
self.setTitle("Clipping Planes: Only points satisfying Ax + By + Cz + D >=0 will be plotted")
self.__disconnected = False
self.build()
def build(self):
self.l = qt.QGridLayout(self)
self.l.setMargin(4)
self.l.setSpacing(2)
i = 0
j = 0
for item in ['Use', 'Ax', 'By', 'Cz', 'D']:
label = qt.QLabel(self)
label.setText(item)
self.l.addWidget(label, i , j)
j += 1
self.useList = []
self.planeList = []
self.validatorList = []
for item in [ 'XY', 'XZ', 'YZ', 'U0']:
use = qt.QCheckBox(self)
use.setText(item)
vector = [use]
self.connect(use,
qt.SIGNAL("clicked()"),
self._signal)
for k in [0, 1, 2, 3]:
line = qt.QLineEdit(self)
line.setFixedWidth(line.fontMetrics().width('########'))
line.setText('0.0')
line.setReadOnly(True)
v = qt.QDoubleValidator(line)
line.setValidator(v)
self.validatorList.append(v)
vector.append(line)
if item != "U0":
slider = Qwt.QwtSlider(self, qt.Qt.Horizontal)
slider.setRange(-100, 100, 0.05)
slider.setValue(0.0)
self.connect(slider,
qt.SIGNAL("valueChanged(double)"),
self._sliderSlot)
vector.append(slider)
self.planeList.append(vector)
#XY plane
#vector and point
self.planeList[0][3].setText('1.0')
self.planeList[0][3].setReadOnly(False)
self.planeList[0][4].setReadOnly(False)
#XZ plane
#vector and point
self.planeList[1][2].setText('1.0')
self.planeList[1][2].setReadOnly(False)
self.planeList[1][4].setReadOnly(False)
#YZ plane
#vector and point
self.planeList[2][1].setText('1.0')
self.planeList[2][1].setReadOnly(False)
self.planeList[2][4].setReadOnly(False)
for i in range(3):
self.connect(self.planeList[i][4],
qt.SIGNAL('editingFinished()'),
self._lineSlot)
for p in self.planeList:
i += 1
for j in range(len(p)):
self.l.addWidget(p[j], i, j)
def _sliderSlot(self, *var):
if self.__disconnected: return
if DEBUG:print "sliderSlot"
for i in range(3):
value = self.planeList[i][5].value()
self.planeList[i][4].setText("%f" % value)
self._signal()
def _lineSlot(self):
if DEBUG:print "lineSlot"
for i in range(3):
oldValue = self.planeList[i][5].value()
value = float(str(self.planeList[i][4].text()))
if (oldValue-value) != 0.0:
self.planeList[i][5].setValue(value)
def getParameters(self):
ddict = {}
ddict['clippingplanes'] = []
for plane in self.planeList:
use = plane[0].isChecked()
A = float(str(plane[1].text()))
B = float(str(plane[2].text()))
C = float(str(plane[3].text()))
D = float(str(plane[4].text()))
ddict['clippingplanes'].append([use, A, B, C, D])
return ddict
def setParameters(self, ddict=None):
if ddict is None:return
if ddict.has_key('limits'):
xmin, ymin, zmin = ddict['limits'][0]
xmax, ymax, zmax = ddict['limits'][1]
self.planeList[0][5].setRange(-abs(zmax), abs(zmax))
self.planeList[1][5].setRange(-abs(ymax), abs(ymax))
self.planeList[2][5].setRange(-abs(xmax), abs(xmax))
if ddict.has_key('clippingplanes'):
i = 0
self.__disconnected = True
for plane in ddict['clippingplanes']:
self.planeList[i][0].setChecked(plane[0])
for j in [1, 2, 3, 4]:
self.planeList[i][j].setText("%f"% plane[j])
i += 1
self.__disconnected = False
def _signal(self, event = None):
if event is None:
event = "ClippingPlaneUpdated"
ddict = self.getParameters()
ddict['event'] = event
self.emit(qt.SIGNAL('ClippingPlaneSignal'),ddict)
class UserClippingPlaneWidget(qt.QWidget):
def __init__(self, parent = None, vector = None, point = None, rotation=None):
qt.QWidget.__init__(self, parent)
self.l = qt.QHBoxLayout(self)
self.l.setMargin(0)
self.l.setSpacing(0)
if vector is None: vector = [0.0, 0.0, 1.0]
self.vectorWidget = Object3DTranslationWidget(self, vector, labels = ['Axis', 'Value'])
self.vectorWidget.setTitle("U0 Plane Vector")
text = "Normal vector to the U0 Plane\n"
text += "prior to rotations"
self.vectorWidget.setToolTip(text)
self.pointWidget = Object3DTranslationWidget(self, point, ['Axis', 'Value'])
self.pointWidget.setTitle("U0 Plane Point")
text = "Coordinates of a U0 Plane point\n"
text += "in object coordinates"
self.pointWidget.setToolTip(text)
self.rotationWidget = Object3DRotationWidget(self, rotation)
self.rotationWidget.setTitle("U0 Plane Rotation")
self.l.addWidget(self.vectorWidget)
self.l.addWidget(self.pointWidget)
self.l.addWidget(self.rotationWidget)
self.__disconnected = False
self.connect(self.vectorWidget,
qt.SIGNAL('Object3DTranslationSignal'),
self._slot)
self.connect(self.pointWidget,
qt.SIGNAL('Object3DTranslationSignal'),
self._slot)
self.connect(self.rotationWidget,
qt.SIGNAL('Object3DRotationSignal'),
self._slot)
def _slot(self, ddict):
self._emitSignal()
def getParameters(self):
ddict={}
ddict['U0vector'] = self.vectorWidget.getTranslation()
ddict['U0point'] = self.pointWidget.getTranslation()
ddict['U0rotation'] = self.rotationWidget.getRotation()
return ddict
def setParameters(self, ddict):
self.__disconnected = True
if ddict.has_key('U0vector'):
self.vectorWidget.setTranslation(ddict['U0vector'])
if ddict.has_key('U0point'):
self.pointWidget.setTranslation(ddict['U0point'])
if ddict.has_key('U0rotation'):
self.rotationWidget.setRotation(ddict['U0rotation'])
self.__disconnected = False
def _emitSignal(self, event=None):
if self.__disconnected: return
if DEBUG:print "Emitting UserClippingPlaneSignal"
if event is None:event="U0PlaneUpdated"
ddict = self.getParameters()
ddict['event'] = event
self.emit(qt.SIGNAL('UserClippingPlaneSignal'), ddict)
class ClippingPlaneWidget(qt.QWidget):
def __init__(self, parent = None):
qt.QWidget.__init__(self, parent)
self.mainLayout = qt.QVBoxLayout(self)
self.standardClippingPlane = ClippingPlaneConfiguration(self)
self.userClippingPlane = UserClippingPlaneWidget(self)
self.mainLayout.addWidget(self.standardClippingPlane)
self.mainLayout.addWidget(self.userClippingPlane)
self.connect(self.standardClippingPlane,
qt.SIGNAL('ClippingPlaneSignal'),
self._emitSignal)
self.connect(self.userClippingPlane,
qt.SIGNAL('UserClippingPlaneSignal'),
self._userPlaneSlot)
def _userPlaneSlot(self, ddict):
x, y, z = ddict['U0vector']
if numpy.sqrt(x*x + y*y + z*z) == 0.0:
if 0:
msg = qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText('Invalid Normal Vector. Module = 0')
msg.exec_()
return
equation = self.calculatePlaneEquation(ddict['U0vector'],
ddict['U0point'],
ddict['U0rotation'])
ddict = self.standardClippingPlane.getParameters()
ddict['clippingplanes'][-1][1] = equation [0]
ddict['clippingplanes'][-1][2] = equation [1]
ddict['clippingplanes'][-1][3] = equation [2]
ddict['clippingplanes'][-1][4] = equation [3]
self.standardClippingPlane.setParameters(ddict)
self._emitSignal()
def calculatePlaneEquation(self, vector, point, rotation):
if (rotation[0] != 0.0) or (rotation[1] != 0.0) or (rotation[2] != 0):
#RotX
angle = rotation[0]*numpy.pi/180.
cs = numpy.cos(angle)
sn = numpy.sin(angle)
rotX = numpy.zeros((3,3), numpy.float64)
rotX[0,0] = 1
rotX[1,1] = 1
rotX[2,2] = 1
rotX[1,1] = cs; rotX[1,2] = sn
rotX[2,1] = -sn; rotX[2,2] = cs
#RotY
angle = rotation[1]*numpy.pi/180.
cs = numpy.cos(angle)
sn = numpy.sin(angle)
rotY = numpy.zeros((3,3), numpy.float64)
rotY[0,0] = 1
rotY[1,1] = 1
rotY[2,2] = 1
rotY[0,0] = cs; rotY[0,2] = -sn #inverted respect to the others
rotY[2,0] = sn; rotY[2,2] = cs
#RotZ
angle = rotation[2]*numpy.pi/180.
cs = numpy.cos(angle)
sn = numpy.sin(angle)
rotZ = numpy.zeros((3,3), numpy.float64)
rotZ[0,0] = 1
rotZ[1,1] = 1
rotZ[2,2] = 1
rotZ[0,0] = cs; rotZ[0,1] = sn
rotZ[1,0] = -sn; rotZ[1,1] = cs
#The final matrix
rotMatrix = numpy.dot(rotZ,numpy.dot(rotY, rotX))
else:
rotMatrix = numpy.zeros((3,3), numpy.float64)
rotMatrix[0,0] = 1
rotMatrix[1,1] = 1
rotMatrix[2,2] = 1
#ABC
A, B, C = numpy.dot(rotMatrix, numpy.array(vector)).tolist()
#calculate D
D = -(A * point[0] +\
B * point[1] +\
C * point[2] )
return [A, B, C, D]
def _emitSignal(self, event = None):
if DEBUG:print "Emitting ClippingPlaneWidgetSignal"
if event is None:event = 'ClippingPlaneWidgetUpdated'
ddict = self.standardClippingPlane.getParameters()
ddict.update(self.userClippingPlane.getParameters())
ddict['event'] = event
self.emit(qt.SIGNAL('ClippingPlaneWidgetSignal'), ddict)
def setParameters(self, ddict):
self.standardClippingPlane.setParameters(ddict)
self.userClippingPlane.setParameters(ddict)
if __name__ == "__main__":
import sys
app = qt.QApplication(sys.argv)
def myslot(ddict):
print "Signal received"
print "ddict = ", ddict
if 0:
w = ClippingPlaneConfiguration()
qt.QObject.connect(w,
qt.SIGNAL('ClippingPlaneSignal'),
myslot)
elif 1:
w = ClippingPlaneWidget()
qt.QObject.connect(w,
qt.SIGNAL('ClippingPlaneWidgetSignal'),
myslot)
w.show()
app.exec_()
|