This file is indexed.

/usr/share/pyshared/PyMca/Object3D/Object3DBase.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
import numpy
import Object3DQt as qt
import weakref
import sys
import Object3DPrivateConfig

try:
    import OpenGL.GL  as GL
except ImportError:
    raise ImportError, "OpenGL must be installed to use these functionalities"

DEBUG = 0
    
DRAW_MODES = ['NONE',
              'POINT',
              'WIRE',
              'SURFACE']
              #'LIGHT',
              #'POINT_SELECTION']

class Object3D:
    def __init__(self, name = "Object3D"):
        self._configuration ={}

        #default limits
        self._limits = numpy.zeros((2,3), numpy.float32)
        self._limits[1,0] = 1.0
        self._limits[1,1] = 1.0
        self._limitsChanged = False
        self.__name = name

        #the possible private configuration widget
        self._privateConfigurationWidget = None

        self.initCommonConfiguration(name)
        self.initPrivateConfiguration(name)

        # the object should know if it is the active object
        self._selected = False

        # vertex selection mode
        self._vertexSelectionMode = False

        #bounding box gl list
        self.boundingBoxList = 0

        #bounding box indices
        #Bottom XY plane
        self._bottomPlane = numpy.zeros(5).astype(numpy.uint32)
        self._bottomPlane[0] = 0
        self._bottomPlane[1] = 2
        self._bottomPlane[2] = 6
        self._bottomPlane[3] = 4
        self._bottomPlane[4] = 0

        #Top XY plane
        self._topPlane = numpy.zeros(5).astype(numpy.uint32)
        self._topPlane[0] = 1
        self._topPlane[1] = 3
        self._topPlane[2] = 7
        self._topPlane[3] = 5
        self._topPlane[4] = 1

        #Parallel edges
        self._edges = numpy.arange(8).astype(numpy.uint32)


    def __del__(self):
        if GL is not None:
            if self.boundingBoxList != 0:
                GL.glDeleteLists(self.boundingBoxList, 1)
        if DEBUG:
            print "DELETING Object3d base"
            print self.name(), "DELETED"

    def name(self):
        return self.__name

    def isVertexSelectionModeSupported(self):
        return False
        
    def setVertexSelectionMode(self, flag):
        # This is to tell the widget the application is trying
        # to get information about a vertex. 
        self._vertexSelectionMode = flag
        
    def initCommonConfiguration(self, name):
        """
        Fills the default configuration features
        found in all objects
        """
        
        ddict = {}

        ddict['name'] = name
        
        ddict['pointsize']    = 1.0     #always supported
        ddict['linewidth']    = 1.0     #always supported
        ddict['transparency'] = 0.0     #solid color

        #scaling parameters
        ddict['scale']        = [1.0, 1.0, 1.0]
        ddict['scalefactor']  = 1.0

        #default anchoring is the origin
        ddict['anchor']       = [0, 0, 0] #warning:these are flags

        #translation
        ddict['translation']  = [0.0, 0.0, 0.0]

        #rotation in (degrees)
        ddict['rotation']     = [ 0.0, 0.0, 0.0]

        #drawing modes
        ddict['drawingmodes']   = DRAW_MODES

        #current mode
        ddict['mode'] = 0

        #supported modes
        supportedModes = []
        for i in range(len(DRAW_MODES)):
            supportedModes.append(i)
        supportedModes [0] = 1          #no drawing is always possible
        ddict['supportedmodes'] = supportedModes

        #show bounding box
        ddict['bboxflag']  = 0

        #limits
        ddict['showlimits'] = [0, 0, 0]

        #clipping planes
        #clipping planes have the form [flag, A, B, C, D]
        ddict['clippingplanes'] = [[0, 0.0, 0.0, 1.0, 0.0], #XY
                                   [0, 0.0, 1.0, 0.0, 0.0], #XZ
                                   [0, 1.0, 0.0, 0.0, 0.0], #YZ
                                   [0, 0.0, 0.0, 1.0, 0.0]] #U0
                                           

        ddict['limits'] = self.getLimits()

        ddict['colormap'] = [2, True, 0, 1, -10, 10, 0]

        self._configuration['common'] = ddict

    def initPrivateConfiguration(self, name):
        """
        Specific configuration. To be overwitten
        """
        self._configuration['private'] = {}
        if self._privateConfigurationWidget is None:
            self._privateConfigurationWidget = Object3DPrivateConfig.Object3DPrivateConfig(None,
                                                                                       name=name)
        self._configuration['private']['widget'] = weakref.proxy(self._privateConfigurationWidget)

    def getConfiguration(self):
        return self._configuration

    def setConfiguration(self, ddict):
        """
        You will very likely overwrite this method
        """
        if ddict.has_key('common'):
            self._configuration['common'].update(ddict['common'])
        if ddict.has_key('private'):
            #do not overwrite widget!!!
            widget = self._configuration['private']['widget']
            self._configuration['private'].update(ddict['private'])
            if widget is not None:
                #restore former widget
                self._configuration['private']['widget'] = widget

    def setSelected(self, flag = True):
        self._selected = flag

    def selected(self):
        return self._selected

    def getLimits(self):
        """
        This method returns the limits of the object
        Typically will be its bounding box.
        The form is a 2 row numpy array:
        [[xmin, ymin, zmin],
         [xmax, ymax, zmax]]
        """
        return self._limits

    def setLimits(self, xmin, ymin, zmin, xmax, ymax, zmax):
        self._limits[0,:] = xmin, ymin, zmin
        self._limits[1,:] = xmax, ymax, zmax
        self._limitsArray = numpy.zeros((8,3), numpy.float32)
        i = 0
        for x in [xmin, xmax]:
            for y in [ymin, ymax]:
                for z in [zmin, zmax]:
                    self._limitsArray[i, 0] = x 
                    self._limitsArray[i, 1] = y 
                    self._limitsArray[i, 2] = z
                    i += 1
        
        self._limitsChanged = True
        self._configuration['common']['limits'] = self._limits

    def draw(self):
        """
        This is the method called to perform all the openGL stuff.
        The default implementation calls drawObject.
        If the objects is selected, it also calls drawBoundingBox.
        Perhaps, you should consider overwriting just drawObject in
        your application.
        """
        self.enableClippingPlanes()
        self.drawObject()
        self.disableClippingPlanes()
        #Default implementattion:
        #A selected object draws its bounding box
        #unless we are selecting but in that case it does not get here.
        if self._selected:
            if not self._vertexSelectionMode:
                self.drawBoundingBox()

    def enableClippingPlanes(self):
        plane =  self._configuration['common']['clippingplanes']
        GL.glClipPlane(GL.GL_CLIP_PLANE0, plane[0][1:])
        GL.glClipPlane(GL.GL_CLIP_PLANE1, plane[1][1:])
        GL.glClipPlane(GL.GL_CLIP_PLANE2, plane[2][1:])
        GL.glClipPlane(GL.GL_CLIP_PLANE3, plane[3][1:])
        if plane[0][0]:
            GL.glEnable(GL.GL_CLIP_PLANE0)
        if plane[1][0]:
            GL.glEnable(GL.GL_CLIP_PLANE1)
        if plane[2][0]:
            GL.glEnable(GL.GL_CLIP_PLANE2)
        if plane[3][0]:
            GL.glEnable(GL.GL_CLIP_PLANE3)

    def disableClippingPlanes(self):
        plane =  self._configuration['common']['clippingplanes']
        GL.glDisable(GL.GL_CLIP_PLANE0)
        GL.glDisable(GL.GL_CLIP_PLANE1)
        GL.glDisable(GL.GL_CLIP_PLANE2)
        GL.glDisable(GL.GL_CLIP_PLANE3)
        
    def drawObject(self):
        pass

    def drawCoordinates(self):
        if self._coordinates is not None:
            self._coordinates.draw()

    def drawBoundingBox(self):
        if 0:
            self.drawBoundingBoxNew()
        else:
            self.drawBoundingBoxOld()

    def drawBoundingBoxNew(self):
        #should I consider the alpha?
        alpha = 1. - self._configuration['common']['transparency']
        GL.glColor4f(0., 0., 0., alpha)
        GL.glVertexPointerf(self._limitsArray)
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
        GL.glDrawElements(GL.GL_LINE_STRIP,
                          5,
                          GL.GL_UNSIGNED_INT,
                          self._bottomPlane)
        GL.glDrawElements(GL.GL_LINE_STRIP,
                          5,
                          GL.GL_UNSIGNED_INT,
                          self._topPlane)
        GL.glDrawElements(GL.GL_LINES,
                          8,
                          GL.GL_UNSIGNED_INT,
                          self._edges)
        GL.glDisableClientState(GL.GL_VERTEX_ARRAY)

    def drawBoundingBoxOld(self):
        if self.boundingBoxList == 0:
            self.buildBoundingBoxList()
        else:
            if self._limitsChanged:
                #the old bounding box list is not valid
                GL.glDeleteLists(self.boundingBoxList, 1)
                self.buildBoundingBoxList()
            
        #should I consider the alpha?
        alpha = 1. - self._configuration['common']['transparency']
        GL.glColor4f(0., 0., 0., alpha)
        GL.glCallList(self.boundingBoxList)

    def buildBoundingBoxList(self):
        (xmin, ymin, zmin) = self._limits[0,:]
        (xmax, ymax, zmax) = self._limits[1,:]
        
        self.boundingBoxList = GL.glGenLists(1)
        GL.glColor3f(0.5, 0.0, 0.0)

        # Bottom XY plane
        GL.glNewList(self.boundingBoxList, GL.GL_COMPILE)
        GL.glBegin(GL.GL_LINE_STRIP)
        GL.glVertex3f(xmin, ymin, zmin)
        GL.glVertex3f(xmax, ymin, zmin)
        GL.glVertex3f(xmax, ymax, zmin)
        GL.glVertex3f(xmin, ymax, zmin)
        GL.glVertex3f(xmin, ymin, zmin)
        GL.glEnd()

        # Top XY plane
        GL.glBegin(GL.GL_LINE_STRIP)
        GL.glVertex3f(xmin, ymin, zmax)
        GL.glVertex3f(xmax, ymin, zmax)
        GL.glVertex3f(xmax, ymax, zmax)
        GL.glVertex3f(xmin, ymax, zmax)
        GL.glVertex3f(xmin, ymin, zmax)
        GL.glEnd()

        # Parallel edges
        GL.glBegin(GL.GL_LINES)
        GL.glVertex3f(xmin, ymin, zmin)
        GL.glVertex3f(xmin, ymin, zmax)

        GL.glVertex3f(xmax, ymin, zmin)
        GL.glVertex3f(xmax, ymin, zmax)

        GL.glVertex3f(xmin, ymax, zmin)
        GL.glVertex3f(xmin, ymax, zmax)

        GL.glVertex3f(xmax, ymax, zmin)
        GL.glVertex3f(xmax, ymax, zmax)

        GL.glEnd()
        #self.buildTicks()
        GL.glEndList()


    def buildTicks(self):
        (xmin, ymin, zmin) = self._limits[0,:]
        (xmax, ymax, zmax) = self._limits[1,:]
        xdelta = self.getTickDelta(xmin, xmax)
        ydelta = self.getTickDelta(ymin, ymax)
        zdelta = self.getTickDelta(zmin, zmax)
        p = 30.
        xTickSize = (xmax - xmin)/p
        yTickSize = (ymax - ymin)/p
        zTickSize = (zmax - zmin)/p
        if xdelta > 0:
            GL.glBegin(GL.GL_LINES)
            x = xmin + xdelta
            while x <= xmax:
                GL.glVertex3f(x, ymin, zmin)
                GL.glVertex3f(x, ymin + yTickSize, zmin)
                GL.glVertex3f(x, ymax, zmin)
                GL.glVertex3f(x, ymax - yTickSize, zmin)
                x += xdelta
            GL.glEnd()

        if ydelta > 0:
            GL.glBegin(GL.GL_LINES)
            y = ymin + ydelta
            while y <= ymax:
                GL.glVertex3f(xmin, y, zmin)
                GL.glVertex3f(xmin + xTickSize, y, zmin)
                GL.glVertex3f(xmax, y, zmin)
                GL.glVertex3f(xmax - xTickSize, y, zmin)
                y += ydelta
            GL.glEnd()

        if zdelta > 0:        
            GL.glBegin(GL.GL_LINES)
            z = zmin + zdelta
            while z <= zmax:
                GL.glVertex3f(xmin, ymin, z)
                GL.glVertex3f(xmin + xTickSize, ymin, z)
                GL.glVertex3f(xmax, ymin, z)
                GL.glVertex3f(xmax - xTickSize, ymin, z)

                GL.glVertex3f(xmin, ymin, z)                
                GL.glVertex3f(xmin, ymin + yTickSize, z)
                GL.glVertex3f(xmin, ymax, z)
                GL.glVertex3f(xmin, ymax - yTickSize, z)
                z += zdelta
            GL.glEnd()

    def getTickDelta(self, minval0, maxval0, nticks = 5):
        if minval0 < 0:
            minval = -minval0
        else:
            minval = minval0
        if maxval0 < 0:
            maxval = -maxval0
        else:
            maxval = maxval0        
        if minval > maxval:
            temp = minval * 1.0
            minval = maxval * 1.0
            maxval = temp
        #both are positive now
        delta = maxval - minval
        if delta <= 0:
            stepInterval = 1
        else:
            stepInterval = pow(10.0, int(numpy.log10(maxval - minval))+1)
        finalInterval = stepInterval * 1
        ticks = (maxval - minval)/ stepInterval
        counter = 0
        divider = 1.0
        while ticks < nticks:
            if (counter % 3) == 0:
                divider = 2.
            elif (counter % 3) == 1:
                divider = 5.
            elif (counter % 3) == 2:
                divider = 1.
                stepInterval /= 10.
            counter += 1
            finalInterval = stepInterval/divider
            ticks = (maxval-minval)/ finalInterval
        return finalInterval

    def getIndexValues(self, index):
        """
        To be overwritten.
        Expected to give back x, y, z, I for index
        """
        return None, None, None, None

    def updatePrivateConfigurationWidget(self):
        # This rarely be called from here unless for initialization.
        # The graphic interface should deal with the configuration.
        if hasPrivateConfigurationWidget():
            return self._privateConfigurationWidget.setConfiguration(self._configuration)
        else:
            return True

    def hasPrivateConfigurationWidget(self):
        if self._privateConfigurationWidget is not None:
            return True
        else:
            return False

def getObject3DInstance(config=None):
    return Object3D()

if __name__ == "__main__":
    import sys
    app = qt.QApplication(sys.argv)
    name = "Base 3D-Object"
    object3D = Object3D(name)
    object3D.setLimits(10.0, 10.0, 10., 30., 30., 30)
    object3D.setSelected(1) #otherways we'll see nothing
    if 0:
        import SceneGLWidget
        window = SceneGLWidget.SceneGLWidget()
        window.addObject3D(object3D, name)
        window.show()
    else:
        import SceneGLWindow
        window = SceneGLWindow.SceneGLWindow()
        #Needed to initialize SceneGLWidget
        window.show()
        window.addObject(object3D, name, update_scene=False)
        #window.glWidget.setZoomFactor(window.glWidget.getZoomFactor())
        window.glWidget.setZoomFactor(0.9)
    app.exec_()