Example #1
0
 def buildPointList0(self):
     """
     This is just to test memory and speed
     """
     n1, n2, n3 = 256, 256, 256
     zdata = numpy.arange(n1*n2*n3).astype(numpy.float32)
     zdata.shape= -1, 1
     (image,size,minmax)= spslut.transform(zdata,
                                       (1,0),
                                       (spslut.LINEAR,3.0),
                                       "RGBX",
                                       spslut.TEMP,
                                       1,
                                       (0, 1),
                                       (0, 255),1)
     image.shape = -1, 4
     image[:,3] = 255
     #self.vertexColors = image.astype(numpy.float32)
     x = numpy.arange(n1).astype(numpy.float32)
     y = numpy.arange(n2).astype(numpy.float32)
     z = numpy.arange(n3).astype(numpy.float32)
     #Object3DCTools.draw3DGridQuads(x, y, y)
     #Object3DCTools.draw3DGridLines(x, y, z, image)
     Object3DCTools.draw3DGridPoints(x, y, z, image)
     self.zdata = zdata
Example #2
0
 def buildPointList0(self):
     """
     This is just to test memory and speed
     """
     n1, n2, n3 = 256, 256, 256
     zdata = numpy.arange(n1*n2*n3).astype(numpy.float32)
     zdata.shape= -1, 1
     (image,size,minmax)= spslut.transform(zdata,
                                       (1,0),
                                       (spslut.LINEAR,3.0),
                                       "RGBX",
                                       spslut.TEMP,
                                       1,
                                       (0, 1),
                                       (0, 255),1)
     image.shape = -1, 4
     image[:,3] = 255
     #self.vertexColors = image.astype(numpy.float32)
     x = numpy.arange(n1).astype(numpy.float32)
     y = numpy.arange(n2).astype(numpy.float32)
     z = numpy.arange(n3).astype(numpy.float32)
     #Object3DCTools.draw3DGridQuads(x, y, y)
     #Object3DCTools.draw3DGridLines(x, y, z, image)
     Object3DCTools.draw3DGridPoints(x, y, z, image)
     self.zdata = zdata
Example #3
0
 def _drawMesh(self):
     alpha = 1.0 - self._configuration['common']['transparency']
     if alpha < 0:
         alpha = 0
     elif alpha >= 1.0:
         alpha = 255
     else:
         alpha = int(255 * alpha)
     self.pixmap[:, 3] = alpha
     shape = self._imageData.shape
     self._imageData.shape = -1,1
     if DRAW_MODES[self._configuration['common']['mode']] == "POINT":
         if False:
             Object3DCTools.drawXYZPoints(self.vertices,
                                      self.pixmap)
         else:
             Object3DCTools.draw2DGridPoints(self._xValues,
                        self._yValues,
                        self._zValues,
                        self.pixmap)
     elif DRAW_MODES[self._configuration['common']['mode']] == "WIRE":
         Object3DCTools.draw2DGridLines(self._xValues,
                        self._yValues,
                        self._zValues,
                        self.pixmap)
     elif DRAW_MODES[self._configuration['common']['mode']] == "SURFACE":
         Object3DCTools.draw2DGridQuads(self._xValues,
                        self._yValues,
                        self._zValues,
                        self.pixmap)
     self._imageData.shape = shape
Example #4
0
 def __fillVerticesBufferObject(self):
     if self.vertices is None:
         self.vertices = Object3DCTools.get3DGridFromXYZ(
             self._x, self._y, self._z)
         self.indices = numpy.arange(self.nVertices)
     self._verticesBufferObject = buffers.VertexBuffer(
         self.vertices, GL.GL_STATIC_DRAW)
     self.vertices = None
Example #5
0
 def buildPointListOLD(self):
     if self.vertices is None:
         self.vertices = Object3DCTools.get3DGridFromXYZ(
             self._x, self._y, self._z)
     GL.glVertexPointerf(self.vertices)
     GL.glColorPointerub(self.vertexColors)
     GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
     GL.glEnableClientState(GL.GL_COLOR_ARRAY)
     GL.glDrawArrays(GL.GL_POINTS, 0, self.nVertices)
Example #6
0
 def __fillVerticesBufferObject(self):
     if self.vertices is None:
         self.vertices = Object3DCTools.get3DGridFromXYZ(self._x,
                                                self._y,
                                                self._z)
         self.indices = numpy.arange(self.nVertices)
     self._verticesBufferObject = buffers.VertexBuffer(self.vertices,
                                                     GL.GL_STATIC_DRAW)
     self.vertices = None
Example #7
0
 def buildPointListOLD(self):
     if self.vertices is None:
         self.vertices = Object3DCTools.get3DGridFromXYZ(self._x,
                                                    self._y,
                                                    self._z)
     GL.glVertexPointerf(self.vertices)
     GL.glColorPointerub(self.vertexColors)
     GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
     GL.glEnableClientState(GL.GL_COLOR_ARRAY)
     GL.glDrawArrays(GL.GL_POINTS, 0, self.nVertices)
Example #8
0
 def buildPointList(self, selection=False):
     if selection:
         if self.vertexSelectionColors is None:
             self._getVertexSelectionColors()
         if self._configuration['private']['colorfilter']:
             tinyNumber = 1.0e-10
             minValue = self._configuration['common']['colormap'][2] + tinyNumber
             maxValue = self._configuration['common']['colormap'][3] - tinyNumber
             Object3DCTools.draw3DGridPoints(self._x,
                                        self._y,
                                        self._z,
                                        self.vertexSelectionColors,
                                        self.values,
                                        0,
                                        [1, minValue, maxValue])
         else:
             Object3DCTools.draw3DGridPoints(self._x,
                                    self._y,
                                    self._z,
                                    self.vertexSelectionColors,
                                    self.values,
                                    0,
                                    self._configuration['private']['useminmax'])
     else:
         Object3DCTools.draw3DGridPoints(self._x,
                                    self._y,
                                    self._z,
                                    self.vertexColors,
                                    self.values,
                                    self._configuration['private']['colorfilter'],
                                    self._configuration['private']['useminmax'])
Example #9
0
 def buildPointList(self, selection=False):
     if selection:
         if self.vertexSelectionColors is None:
             self._getVertexSelectionColors()
         if self._configuration['private']['colorfilter']:
             tinyNumber = 1.0e-10
             minValue = self._configuration['common']['colormap'][2] + tinyNumber
             maxValue = self._configuration['common']['colormap'][3] - tinyNumber
             Object3DCTools.draw3DGridPoints(self._x,
                                        self._y,
                                        self._z,
                                        self.vertexSelectionColors,
                                        self.values,
                                        0,
                                        [1, minValue, maxValue])
         else:
             Object3DCTools.draw3DGridPoints(self._x,
                                    self._y,
                                    self._z,
                                    self.vertexSelectionColors,
                                    self.values,
                                    0,
                                    self._configuration['private']['useminmax'])
     else:
         Object3DCTools.draw3DGridPoints(self._x,
                                    self._y,
                                    self._z,
                                    self.vertexColors,
                                    self.values,
                                    self._configuration['private']['colorfilter'],
                                    self._configuration['private']['useminmax'])
Example #10
0
    def buildPointListXYZ(self, selection=False):
        if 1:
            if selection:
                if self.vertexSelectionColors is None:
                    self._getVertexSelectionColors()
                if self._configuration['private']['colorfilter']:
                    tinyNumber = 1.0e-10
                    minValue = self._configuration['common']['colormap'][
                        2] + tinyNumber
                    maxValue = self._configuration['common']['colormap'][
                        3] - tinyNumber
                    Object3DCTools.drawXYZPoints(self.vertices,
                                                 self.vertexSelectionColors,
                                                 self.values, None, 0,
                                                 [1, minValue, maxValue])
                else:
                    Object3DCTools.drawXYZPoints(
                        self.vertices, self.vertexSelectionColors, self.values,
                        None, 0, self._configuration['private']['useminmax'])
            else:
                Object3DCTools.drawXYZPoints(
                    self.vertices, self.vertexColors, self.values, None,
                    self._configuration['private']['colorfilter'],
                    self._configuration['private']['useminmax'])
        return

        GL.glVertexPointerf(self.vertices)
        if selection:
            GL.glColorPointerub(self.vertexSelectionColors)
        else:
            GL.glColorPointerub(self.vertexColors)
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
        GL.glEnableClientState(GL.GL_COLOR_ARRAY)
        GL.glDrawArrays(GL.GL_POINTS, 0, self.nVertices)
Example #11
0
 def _drawMesh(self):
     alpha = 1.0 - self._configuration['common']['transparency']
     if alpha < 0:
         alpha = 0
     elif alpha >= 1.0:
         alpha = 255
     else:
         alpha = int(255 * alpha)
     self.pixmap[:, 3] = alpha
     shape = self._imageData.shape
     self._imageData.shape = -1, 1
     if DRAW_MODES[self._configuration['common']['mode']] == "POINT":
         if False:
             Object3DCTools.drawXYZPoints(self.vertices, self.pixmap)
         else:
             Object3DCTools.draw2DGridPoints(self._xValues, self._yValues,
                                             self._zValues, self.pixmap)
     elif DRAW_MODES[self._configuration['common']['mode']] == "WIRE":
         Object3DCTools.draw2DGridLines(self._xValues, self._yValues,
                                        self._zValues, self.pixmap)
     elif DRAW_MODES[self._configuration['common']['mode']] == "SURFACE":
         Object3DCTools.draw2DGridQuads(self._xValues, self._yValues,
                                        self._zValues, self.pixmap)
     self._imageData.shape = shape
Example #12
0
    def buildPointListXYZ(self, selection=False):
        if 1:
            if selection:
                if self.vertexSelectionColors is None:
                    self._getVertexSelectionColors()
                if self._configuration['private']['colorfilter']:
                    tinyNumber = 1.0e-10
                    minValue = self._configuration['common']['colormap'][2] + tinyNumber
                    maxValue = self._configuration['common']['colormap'][3] - tinyNumber
                    Object3DCTools.drawXYZPoints(self.vertices,
                             self.vertexSelectionColors,
                             self.values,
                             None,
                             0,
                             [1, minValue, maxValue])
                else:
                    Object3DCTools.drawXYZPoints(self.vertices,
                             self.vertexSelectionColors,
                             self.values,
                             None,
                             0,
                             self._configuration['private']['useminmax'])
            else:
                Object3DCTools.drawXYZPoints(self.vertices,
                             self.vertexColors,
                             self.values,
                             None,
                             self._configuration['private']['colorfilter'],
                             self._configuration['private']['useminmax'])
        return


        GL.glVertexPointerf(self.vertices)
        if selection:
            GL.glColorPointerub(self.vertexSelectionColors)
        else:
            GL.glColorPointerub(self.vertexColors)
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
        GL.glEnableClientState(GL.GL_COLOR_ARRAY)
        GL.glDrawArrays(GL.GL_POINTS, 0, self.nVertices)
Example #13
0
            object3D = Object3DMesh(os.path.basename(f))
    else:
        data = numpy.arange(200.).astype(numpy.float32)
        data.shape = [40, 5]
        object3D = Object3DMesh('builtin')

    #several options: regular grid, irregular grid
    if len(sys.argv) > 1:
        #print "IMPOSSING A 1000 OFFSET"
        #offset = 1000.0
        offset = 0
        #irregular grid
        xSize, ySize = data.shape[0:2]
        zSize = 1
        xyz = Object3DCTools.get3DGridFromXYZ(numpy.arange(xSize).astype(numpy.float32)-offset,
                                       numpy.arange(xSize).astype(numpy.float32)+offset,
                                       numpy.arange(1)+1)
        a = xyz[:,0] * 1
        xyz[:,0] = xyz[:,1] * 1
        xyz[:,1] = a[:]
        #print xyz[0:3,:]
        #print xyz.shape
        #print Object3DCTools.getVertexArrayMeshAxes(xyz)
        #sys.exit(0)
        data.shape = 1, xSize * ySize
        xyz[:,2] = data[:]
        object3D.setData(data, xyz=xyz)
    elif 0:
        #flat
        object3D.setData(data, z=4)
    else:
Example #14
0
 def buildWireList(self):
     Object3DCTools.draw3DGridLines(self._x, self._y, self._z,
                                    self.vertexColors)
Example #15
0
    def drawObject(self):
        if self.values is None:
            return
        GL.glPushAttrib(GL.GL_ALL_ATTRIB_BITS)
        GL.glShadeModel(GL.GL_FLAT)
        if DEBUG:
            t0 = time.time()
        if self.drawMode == 'NONE':
            pass
        elif (GL.glGetIntegerv(GL.GL_RENDER_MODE) == GL.GL_SELECT) or \
           self._vertexSelectionMode:
            GL.glPointSize(self._configuration['common']['pointsize'])
            if self._xyz:
                self.buildPointListXYZ(selection=True)
            else:
                self.buildPointList(selection=True)
        elif self.drawMode == 'POINT':
            GL.glShadeModel(GL.GL_FLAT)
            GL.glPointSize(self._configuration['common']['pointsize'])
            if self._xyz:
                self.buildPointListXYZ(selection=False)
            else:
                self.buildPointList(selection=False)
        elif self.drawMode == 'POINT_SELECTION':
            GL.glShadeModel(GL.GL_FLAT)
            GL.glPointSize(self._configuration['common']['pointsize'])
            self.buildPointList(selection=True)
        elif self.drawMode in ['LINES', 'WIRE']:
            GL.glLineWidth(self._configuration['common']['linewidth'])
            GL.glShadeModel(GL.GL_SMOOTH)
            if self._xyz:
                if self.facets is None:
                    self._getFacets()
                Object3DCTools.drawXYZLines(
                    self.vertices, self.vertexColors, self.values, self.facets,
                    self._configuration['private']['colorfilter'],
                    self._configuration['private']['useminmax'])
                #sys.exit(1)
            elif self.__flat:
                Object3DCTools.draw3DGridLines(
                    self._x, self._y, self._z, self.vertexColors, self.values,
                    self._configuration['private']['colorfilter'],
                    self._configuration['private']['useminmax'])
            else:
                Object3DCTools.draw2DGridLines(
                    self._x, self._y, self._z, self.vertexColors, self.values,
                    self._configuration['private']['colorfilter'],
                    self._configuration['private']['useminmax'])
        elif self.drawMode == "SURFACE":
            GL.glShadeModel(GL.GL_SMOOTH)
            if self._xyz:
                if self.facets is None:
                    self._getFacets()
                Object3DCTools.drawXYZTriangles(
                    self.vertices, self.vertexColors, self.values, self.facets,
                    self._configuration['private']['colorfilter'],
                    self._configuration['private']['useminmax'])

            elif self.__flat:
                Object3DCTools.draw3DGridQuads(
                    self._x, self._y, self._z, self.vertexColors, self.values,
                    self._configuration['private']['colorfilter'],
                    self._configuration['private']['useminmax'])
            else:
                Object3DCTools.draw2DGridQuads(
                    self._x, self._y, self._z, self.vertexColors, self.values,
                    self._configuration['private']['colorfilter'],
                    self._configuration['private']['useminmax'])
        else:
            print("UNSUPPORTED MODE")
        GL.glPopAttrib()
        if DEBUG:
            print("Drawing takes ", time.time() - t0)
Example #16
0
    def setData(self, data, x=None, y=None, z=None, xyz=None):
        self.values = data[:]
        self._configuration['private']['useminmax'] = [
            0, self.values.min(), self.values.max()
        ]
        if (xyz is not None) and (x is None) and (y is None):
            arr = Object3DCTools.getVertexArrayMeshAxes(xyz)
            if arr is not None:
                doit = True
                x = arr[0]
                if len(x) > 1:
                    if abs(x[1] - xyz[0, 0]) > 1.0e-10:
                        #not proper C order
                        #prevent bad plotting of a regular grid
                        doit = False
                        x = None
                if doit:
                    y = arr[1]
                    z = numpy.zeros(x.shape[0] * y.shape[0], numpy.float)
                    z[:] = xyz[:, 2]
                    xyz = None
        if (x is None) and (y is None) and (xyz is None):
            #regular mesh
            self.xSize, self.ySize = data.shape
            self.zSize = 1
            self._x = numpy.arange(self.xSize).astype(numpy.float32)
            self._y = numpy.arange(self.ySize).astype(numpy.float32)
            if z is not None:
                self._z = numpy.array(z).astype(numpy.float32)
                if len(self._z.shape) == 0:
                    #assume just a number
                    self._z.shape = 1, 1
                    self.zSize = 1
                else:
                    self._z.shape = -1, 1
                    self.zSize = self._z.shape[0]
                    self.__flat = False
            else:
                self._z = numpy.arange(self.zSize).astype(numpy.float32)
                self._z.shape = 1, 1
                self.zSize = 1
        elif xyz is not None:
            #full irregular mesh
            self.__setXYZArray(xyz, values=data)
            self.xSize = self.vertices.shape[0]
            self.ySize = 1
            self._x = self.vertices[:, 0]
            self._y = self.vertices[:, 1]
            self._z = self.vertices[:, 2]
            self._xyz = True
        elif (x is not None) and (y is not None):
            #regular mesh
            self._x = numpy.array(x).astype(numpy.float32)
            self._y = numpy.array(y).astype(numpy.float32)
            self._x.shape = -1, 1
            self._y.shape = -1, 1
            self.xSize = self._x.shape[0]
            self.ySize = self._y.shape[0]
            if z is not None:
                self._z = numpy.array(z).astype(numpy.float32)
                if len(self._z.shape) == 0:
                    #assume just a number
                    self._z.shape = 1, 1
                    self.zSize = 1
                else:
                    self._z.shape = -1, 1
                    self.zSize = self._z.shape[0]
                    self.__flat = False
            else:
                self._z = numpy.arange(self.zSize).astype(numpy.float32)
                self._z.shape = 1, 1
                self.zSize = 1
        else:
            raise ValueError("Unhandled case")
        self.nVertices = self.xSize * self.ySize
        self.values.shape = self.nVertices, 1

        self.getColors()
        self._obtainLimits()
Example #17
0
            object3D = Object3DMesh(os.path.basename(f))
    else:
        data = numpy.arange(200.).astype(numpy.float32)
        data.shape = [40, 5]
        object3D = Object3DMesh('builtin')

    #several options: regular grid, irregular grid
    if len(sys.argv) > 1:
        #print "IMPOSSING A 1000 OFFSET"
        #offset = 1000.0
        offset = 0
        #irregular grid
        xSize, ySize = data.shape[0:2]
        zSize = 1
        xyz = Object3DCTools.get3DGridFromXYZ(
            numpy.arange(xSize).astype(numpy.float32) - offset,
            numpy.arange(xSize).astype(numpy.float32) + offset,
            numpy.arange(1) + 1)
        a = xyz[:, 0] * 1
        xyz[:, 0] = xyz[:, 1] * 1
        xyz[:, 1] = a[:]
        #print xyz[0:3,:]
        #print xyz.shape
        #print Object3DCTools.getVertexArrayMeshAxes(xyz)
        #sys.exit(0)
        data.shape = 1, xSize * ySize
        xyz[:, 2] = data[:]
        object3D.setData(data, xyz=xyz)
    elif 0:
        #flat
        object3D.setData(data, z=4)
    else:
Example #18
0
    def drawObject(self):
        if self.values is None:
            return
        if DEBUG:
            t0=time.time()
        GL.glPushAttrib(GL.GL_ALL_ATTRIB_BITS)
        GL.glShadeModel(GL.GL_FLAT)
        if self.drawMode == 'NONE':
            pass
        elif (GL.glGetIntegerv(GL.GL_RENDER_MODE) == GL.GL_SELECT) or \
           self._vertexSelectionMode:
            self.buildPointList(selection=True)
        elif self.drawMode == 'POINT':
            self.buildPointList(selection=False)
            #self.buildPointListNEW(selection=False)
        elif self.drawMode == 'POINT_SELECTION':
            self.buildPointList(selection=True)
        elif self.drawMode in ['LINES', 'WIRE']:
            Object3DCTools.draw3DGridLines(self._x,
                                       self._y,
                                       self._z,
                                       self.vertexColors,
                                       self.values,
                                       self._configuration['private']['colorfilter'],
                                       self._configuration['private']['useminmax'])
        elif self.drawMode == "SURFACE":
            flag = 1
            i = 0
            for use, value, label, cr, cg, cb, ca in self._configuration['private']['isosurfaces']:
                color = (cr, cg, cb, ca)
                if None in color:
                    color = None
                if use:
                    flag = 0
                    GL.glEnable(GL.GL_LIGHTING)
                    if color is not None:
                        GL.glColor4ub(color[0],
                                      color[1],
                                      color[2],
                                      self._alpha)
                    colorflag = False
                    if self.__isosurfacesDict[i]['list'] > 0:
                        if self.__isosurfacesDict[i]['color'] == color:
                            colorflag = True
                        elif (self.__isosurfacesDict[i]['color'] != None) and\
                             (color != None):
                            colorflag = True
                    if self.__isosurfacesDict[i]['list'] > 0:
                        if (self.__isosurfacesDict[i]['value'] == value) and\
                           colorflag:
                            GL.glCallList(self.__isosurfacesDict[i]['list'])
                            i += 1
                            continue
                        GL.glDeleteLists(self.__isosurfacesDict[i]['list'],
                                            1)
                    self.__isosurfacesDict[i]['value']= value
                    self.__isosurfacesDict[i]['color']= color
                    self.__isosurfacesDict[i]['list'] = GL.glGenLists(1)
                    GL.glNewList(self.__isosurfacesDict[i]['list'],
                                                 GL.GL_COMPILE)

                    GL.glBegin(GL.GL_TRIANGLES)
                    Object3DCTools.gridMarchingCubes(self._x, self._y, self._z, self.values, value, color, (1, 1, 1), 1)
                    #Object3DCTools.gridMarchingCubes(self._x, self._y, self._z, self.values, value, None, (1, 1, 1), 1)
                    GL.glEnd()
                    GL.glEndList()
                    GL.glCallList(self.__isosurfacesDict[i]['list'])
                    GL.glDisable(GL.GL_LIGHTING)
                i += 1
            if flag:
                #This is useless, only isosurfaces makes sense
                Object3DCTools.draw3DGridQuads(self._x,
                                       self._y,
                                       self._z,
                                       self.vertexColors,
                                       self.values,
                                       self._configuration['private']['colorfilter'],
                                       self._configuration['private']['useminmax'])
        else:
            print("UNSUPPORTED MODE")
        GL.glPopAttrib()
        if DEBUG:
            print("Drawing takes ", time.time() - t0)
Example #19
0
 def buildWireList(self):
     Object3DCTools.draw3DGridLines(self._x,
                                    self._y,
                                    self._z,
                                    self.vertexColors)
Example #20
0
    def drawObject(self):
        if self.values is None:
            return
        GL.glPushAttrib(GL.GL_ALL_ATTRIB_BITS)
        GL.glShadeModel(GL.GL_FLAT)
        if DEBUG:
            t0=time.time()
        if self.drawMode == 'NONE':
            pass
        elif (GL.glGetIntegerv(GL.GL_RENDER_MODE) == GL.GL_SELECT) or \
           self._vertexSelectionMode:
            GL.glPointSize(self._configuration['common']['pointsize'])
            if self._xyz:
                self.buildPointListXYZ(selection=True)
            else:
                self.buildPointList(selection=True)
        elif self.drawMode == 'POINT':
            GL.glShadeModel(GL.GL_FLAT)
            GL.glPointSize(self._configuration['common']['pointsize'])
            if self._xyz:
                self.buildPointListXYZ(selection=False)
            else:
                self.buildPointList(selection=False)
        elif self.drawMode == 'POINT_SELECTION':
            GL.glShadeModel(GL.GL_FLAT)
            GL.glPointSize(self._configuration['common']['pointsize'])
            self.buildPointList(selection=True)
        elif self.drawMode in ['LINES', 'WIRE']:
            GL.glLineWidth(self._configuration['common']['linewidth'])
            GL.glShadeModel(GL.GL_SMOOTH)
            if self._xyz:
                if self.facets is None:
                    self._getFacets()
                Object3DCTools.drawXYZLines(self.vertices,
                             self.vertexColors,
                             self.values,
                             self.facets,
                             self._configuration['private']['colorfilter'],
                             self._configuration['private']['useminmax'])
                #sys.exit(1)
            elif self.__flat:
                Object3DCTools.draw3DGridLines(self._x,
                                self._y,
                                self._z,
                                self.vertexColors,
                                self.values,
                                self._configuration['private']['colorfilter'],
                                self._configuration['private']['useminmax'])
            else:
                Object3DCTools.draw2DGridLines(self._x,
                                self._y,
                                self._z,
                                self.vertexColors,
                                self.values,
                                self._configuration['private']['colorfilter'],
                                self._configuration['private']['useminmax'])
        elif self.drawMode == "SURFACE":
            GL.glShadeModel(GL.GL_SMOOTH)
            if self._xyz:
                if self.facets is None:
                    self._getFacets()
                Object3DCTools.drawXYZTriangles(self.vertices,
                             self.vertexColors,
                             self.values,
                             self.facets,
                             self._configuration['private']['colorfilter'],
                             self._configuration['private']['useminmax'])

            elif self.__flat:
                Object3DCTools.draw3DGridQuads(self._x,
                            self._y,
                            self._z,
                            self.vertexColors,
                            self.values,
                            self._configuration['private']['colorfilter'],
                            self._configuration['private']['useminmax'])
            else:
                Object3DCTools.draw2DGridQuads(self._x,
                            self._y,
                            self._z,
                            self.vertexColors,
                            self.values,
                            self._configuration['private']['colorfilter'],
                            self._configuration['private']['useminmax'])
        else:
            print("UNSUPPORTED MODE")
        GL.glPopAttrib()
        if DEBUG:
            print("Drawing takes ", time.time() - t0)
Example #21
0
    def setData(self, data, x=None, y=None, z=None, xyz=None):
        self.values = data[:]
        self._configuration['private']['useminmax'] = [0, self.values.min(), self.values.max()]
        if (xyz is not None) and (x is None) and (y is None):
            arr = Object3DCTools.getVertexArrayMeshAxes(xyz)
            if arr is not None:
                doit = True
                x = arr[0]
                if len(x) > 1:
                    if abs(x[1] - xyz[0,0]) > 1.0e-10:
                        #not proper C order
                        #prevent bad plotting of a regular grid
                        doit = False
                        x = None
                if doit:
                    y = arr[1]
                    z = numpy.zeros(x.shape[0]*y.shape[0], numpy.float)
                    z[:] = xyz[:, 2]
                    xyz = None
        if (x is None) and (y is None) and (xyz is None):
            #regular mesh
            self.xSize, self.ySize = data.shape
            self.zSize = 1
            self._x = numpy.arange(self.xSize).astype(numpy.float32)
            self._y = numpy.arange(self.ySize).astype(numpy.float32)
            if z is not None:
                self._z = numpy.array(z).astype(numpy.float32)
                if len(self._z.shape) == 0:
                    #assume just a number
                    self._z.shape = 1, 1
                    self.zSize = 1
                else:
                    self._z.shape = -1, 1
                    self.zSize = self._z.shape[0]
                    self.__flat = False
            else:
                self._z = numpy.arange(self.zSize).astype(numpy.float32)
                self._z.shape = 1, 1
                self.zSize = 1
        elif xyz is not None:
            #full irregular mesh
            self.__setXYZArray(xyz, values=data)
            self.xSize = self.vertices.shape[0]
            self.ySize = 1
            self._x = self.vertices[:,0]
            self._y = self.vertices[:,1]
            self._z = self.vertices[:,2]
            self._xyz = True
        elif (x is not None) and (y is not  None):
            #regular mesh
            self._x = numpy.array(x).astype(numpy.float32)
            self._y = numpy.array(y).astype(numpy.float32)
            self._x.shape = -1, 1
            self._y.shape = -1, 1
            self.xSize = self._x.shape[0]
            self.ySize = self._y.shape[0]
            if z is not None:
                self._z = numpy.array(z).astype(numpy.float32)
                if len(self._z.shape) == 0:
                    #assume just a number
                    self._z.shape = 1, 1
                    self.zSize = 1
                else:
                    self._z.shape = -1, 1
                    self.zSize = self._z.shape[0]
                    self.__flat = False
            else:
                self._z = numpy.arange(self.zSize).astype(numpy.float32)
                self._z.shape = 1, 1
                self.zSize = 1
        else:
            raise ValueError("Unhandled case")
        self.nVertices = self.xSize * self.ySize
        self.values.shape = self.nVertices, 1

        self.getColors()
        self._obtainLimits()
Example #22
0
    def drawObject(self):
        if self.values is None:
            return
        if DEBUG:
            t0=time.time()
        GL.glPushAttrib(GL.GL_ALL_ATTRIB_BITS)
        GL.glShadeModel(GL.GL_FLAT)
        if self.drawMode == 'NONE':
            pass
        elif (GL.glGetIntegerv(GL.GL_RENDER_MODE) == GL.GL_SELECT) or \
           self._vertexSelectionMode:
            self.buildPointList(selection=True)
        elif self.drawMode == 'POINT':
            self.buildPointList(selection=False)
            #self.buildPointListNEW(selection=False)
        elif self.drawMode == 'POINT_SELECTION':
            self.buildPointList(selection=True)
        elif self.drawMode in ['LINES', 'WIRE']:
            Object3DCTools.draw3DGridLines(self._x,
                                       self._y,
                                       self._z,
                                       self.vertexColors,
                                       self.values,
                                       self._configuration['private']['colorfilter'],
                                       self._configuration['private']['useminmax'])
        elif self.drawMode == "SURFACE":
            flag = 1
            i = 0
            for use, value, label, cr, cg, cb, ca in self._configuration['private']['isosurfaces']:
                color = (cr, cg, cb, ca)
                if None in color:
                    color = None
                if use:
                    flag = 0
                    GL.glEnable(GL.GL_LIGHTING)
                    if color is not None:
                        GL.glColor4ub(color[0],
                                      color[1],
                                      color[2],
                                      self._alpha)
                    colorflag = False
                    if self.__isosurfacesDict[i]['list'] > 0:
                        if self.__isosurfacesDict[i]['color'] == color:
                            colorflag = True
                        elif (self.__isosurfacesDict[i]['color'] != None) and\
                             (color != None):
                            colorflag = True
                    if self.__isosurfacesDict[i]['list'] > 0:
                        if (self.__isosurfacesDict[i]['value'] == value) and\
                           colorflag:
                            GL.glCallList(self.__isosurfacesDict[i]['list'])
                            i += 1
                            continue
                        GL.glDeleteLists(self.__isosurfacesDict[i]['list'],
                                            1)
                    self.__isosurfacesDict[i]['value']= value
                    self.__isosurfacesDict[i]['color']= color
                    self.__isosurfacesDict[i]['list'] = GL.glGenLists(1)
                    GL.glNewList(self.__isosurfacesDict[i]['list'],
                                                 GL.GL_COMPILE)

                    GL.glBegin(GL.GL_TRIANGLES)
                    Object3DCTools.gridMarchingCubes(self._x, self._y, self._z, self.values, value, color, (1, 1, 1), 1)
                    #Object3DCTools.gridMarchingCubes(self._x, self._y, self._z, self.values, value, None, (1, 1, 1), 1)
                    GL.glEnd()
                    GL.glEndList()
                    GL.glCallList(self.__isosurfacesDict[i]['list'])
                    GL.glDisable(GL.GL_LIGHTING)
                i += 1
            if flag:
                #This is useless, only isosurfaces makes sense
                Object3DCTools.draw3DGridQuads(self._x,
                                       self._y,
                                       self._z,
                                       self.vertexColors,
                                       self.values,
                                       self._configuration['private']['colorfilter'],
                                       self._configuration['private']['useminmax'])
        else:
            print("UNSUPPORTED MODE")
        GL.glPopAttrib()
        if DEBUG:
            print("Drawing takes ", time.time() - t0)