def DisplayFunction(self):
        """ display function. may be re-implemented by subclass
"""
        #print "Common2d3dObject.DisplayFunction", self
        if self.dpyList is not None:
            currentcontext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
            if currentcontext != self.dpyList[1]:
                warnings.warn("""DisplayFunction failed because the current context is the wrong one""")
                #print "currentcontext != self.dpyList[1]", currentcontext, self.dpyList[1]
            else:
                #print '#%d'%self.dpyList[0], currentcontext, "glCallList Common2d3d"
                GL.glCallList(self.dpyList[0])
示例#2
0
 def chooseTemplate(self):
     GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
     #print '+%d'%self.templateDSPL[0], "glNewList Ellipsoids0"
     if self.invertNormals:
         #print "GLU_INSIDE reversed normals"
         #print '#%d'%(self.templateDSPL[0]+2), "glCallList Ellipsoids2"
         GL.glCallList(self.templateDSPL[0]+2)
     else:
         #print "GLU_OUTSIDE regular normals"
         #print '#%d'%(self.templateDSPL[0]+1), "glCallList Ellipsoids1"
         GL.glCallList(self.templateDSPL[0]+1)
     #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Ellipsoids0"
     GL.glEndList()
示例#3
0
    def DisplayFunction(self):
        """ display function. may be re-implemented by subclass
"""
        #print "Common2d3dObject.DisplayFunction", self
        if self.dpyList is not None:
            currentcontext = self.viewer.currentCamera.tk.call(
                self.viewer.currentCamera._w, 'contexttag')
            if currentcontext != self.dpyList[1]:
                warnings.warn(
                    """DisplayFunction failed because the current context is the wrong one"""
                )
                #print "currentcontext != self.dpyList[1]", currentcontext, self.dpyList[1]
            else:
                #print '#%d'%self.dpyList[0], currentcontext, "glCallList Common2d3d"
                GL.glCallList(self.dpyList[0])
示例#4
0
 def chooseTemplate(self):
     if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     # make sure we are not already in a newlist
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
         #print '+%d'%self.templateDSPL[0], "glNewList Spheres0"
         if self.invertNormals:
             #print "GLU_INSIDE reversed normals"
             #print '#%d'%(self.templateDSPL[0]+2), "glCallList Spheres2"
             GL.glCallList(self.templateDSPL[0] + 2)
         else:
             #print "GLU_OUTSIDE regular normals"
             #print '#%d'%(self.templateDSPL[0]+1), "glCallList Spheres1"
             GL.glCallList(self.templateDSPL[0] + 1)
         #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres0"
         GL.glEndList()
示例#5
0
 def chooseTemplate(self):
     if __debug__:
      if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     # make sure we are not already in a newlist
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
         #print '+%d'%self.templateDSPL[0], "glNewList Spheres0"
         if self.invertNormals:
             #print "GLU_INSIDE reversed normals"
             #print '#%d'%(self.templateDSPL[0]+2), "glCallList Spheres2"
             GL.glCallList(self.templateDSPL[0]+2)
         else:
             #print "GLU_OUTSIDE regular normals"
             #print '#%d'%(self.templateDSPL[0]+1), "glCallList Spheres1"
             GL.glCallList(self.templateDSPL[0]+1)
         #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres0"
         GL.glEndList()
示例#6
0
    def render(self, mode='render'):
        # call with mode='csg' to render simple shape to setup Zbuffer for CSG
        # call with mode='render' to render by calling geom's draw function
        if self.geom:
            #import traceback
            #print traceback.print_stack()
            #print self.geom
            #print "========================================================="
            root = self.geom.viewer.rootObject

            instance = [0]
            p = self.geom.parent
            while p:
                instance.append(0)
                p = p.parent

            #mat = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
            #print 'mat OK', mat
            GL.glPushMatrix()
            GL.glLoadIdentity()
            self.geom.viewer.currentCamera.BuildTransformation()
            self.geom.BuildMat(self.geom, root, True, instance)

            #mat = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
            #print 'mat PB', mat
            #print 'render ', mode, self.geom
            if mode == 'csg':
                if self.dpyListCSG is None:
                    self.redoDisplayListCSG()
                GL.glCallList(self.dpyListCSG)
            elif mode == 'render':
                obj = self.geom
                if not obj.inheritMaterial:
                    obj.InitMaterial(0)
                    obj.InitColor(0)
                obj.DisplayFunction()

            GL.glPopMatrix()
示例#7
0
    def render(self, mode='render'):
        # call with mode='csg' to render simple shape to setup Zbuffer for CSG
        # call with mode='render' to render by calling geom's draw function
        if self.geom:
            #import traceback
            #print traceback.print_stack()
            #print self.geom
            #print "========================================================="
            root = self.geom.viewer.rootObject

            instance = [0]
            p = self.geom.parent
            while p:
                instance.append(0)
                p = p.parent

            #mat = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
            #print 'mat OK', mat
            GL.glPushMatrix()
            GL.glLoadIdentity()
            self.geom.viewer.currentCamera.BuildTransformation()
            self.geom.BuildMat(self.geom, root, True, instance)

            #mat = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
            #print 'mat PB', mat
            #print 'render ', mode, self.geom
            if mode=='csg':
                if self.dpyListCSG is None:
                    self.redoDisplayListCSG()
                GL.glCallList(self.dpyListCSG)
            elif mode=='render':
                obj = self.geom
                if not obj.inheritMaterial:
                    obj.InitMaterial(0)
                    obj.InitColor(0)
                obj.DisplayFunction()
                
            GL.glPopMatrix()
示例#8
0
    def Draw(self):
        if __debug__:
            if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        """Draw function of the geom
return status 0 or 1
If you want fast rendering, you need to set self.templateDSPL
using MakeTemplate.
"""
        #print "Spheres.Draw", self.name

        assert self.templateDSPL is not None

        currentcontext = self.viewer.currentCamera.tk.call(
            self.viewer.currentCamera._w, 'contexttag')
        if currentcontext != self.templateDSPL[1]:
            import traceback
            traceback.print_stack()
            warnings.warn(
                """draw failed because the current context is the wrong one""")
            #print "currentcontext != self.templateDSPL[1]", currentcontext, self.templateDSPL[1]
            return 0

        centers = self.vertexSet.vertices.array
        if len(centers) == 0:
            return 0

        # handle overall binding of material
        if self.inheritMaterial:
            fp = None
            fpProp = None
            bp = None
        else:
            mat = self.materials[GL.GL_FRONT]
            fpProp = []
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                fpProp.append(p)
            fpProp.append(mat.prop[4])

            fp = self.materials[GL.GL_FRONT]
            #colorFront = Numeric.array(self.materials[GL.GL_FRONT].prop[1], copy=1)
            colorFront = Numeric.array(fpProp[1], copy=1)
            if self.frontAndBack:
                bp = None
                face = GL.GL_FRONT_AND_BACK
            else:
                bp = self.materials[GL.GL_BACK]
                face = GL.GL_FRONT

        if fp:
            for m in (0, 1, 2, 3, 4):
                if fp.binding[m] == viewerConst.OVERALL:
                    glMaterialWithCheck(face, viewerConst.propConst[m],
                                        fpProp[m][0])
            if fp.binding[1] == viewerConst.OVERALL:
                GL.glColor4fv(colorFront[0])

            if fp:
                for m in (0, 1, 2, 3, 4):
                    if fp.binding[m] != viewerConst.OVERALL:
                        glMaterialWithCheck(face, viewerConst.propConst[m],
                                            fpProp[m][0])

                if fp.binding[1] != viewerConst.OVERALL:
                    GL.glColor4fv(colorFront[0])
            if bp:
                for m in (0, 1, 2, 3, 4):
                    if bp.binding[m] != viewerConst.OVERALL:
                        glMaterialWithCheck(GL.GL_BACK,
                                            viewerConst.propConst[m],
                                            bp.prop[m][0])

        #print self.name
        #if fp: print fp.prop[1], fp.binding
        #else: print

        if self.fastSpheres:
            #print "self.fastSpheres", self.fastSpheres
            if self.oneRadius == viewerConst.NO:
                radii = self.vertexSet.radii.array
                #FIXME: quick fix because can be called from base class Set
                # method after centers have been set BUT before radii have been
                # set
                if len(self.vertexSet.vertices) != len(radii):
                    return 0
            else:
                radii = Numeric.ones(centers.shape[0]) * self.radius
            radii.shape = (-1, 1)
            coords = Numeric.concatenate((centers, radii), 1)

            ##             if not self.inheritMaterial:
            ##                 mat = self.materials[GL.GL_FRONT]
            ##                 fpProp = []
            ##                 for propInd in range(4):
            ##                     b, p = mat.GetProperty(propInd)
            ##                     fpProp.append(p)
            ##                 fpProp.append(mat.prop[4])
            ##                 #fpProp = self.materials[GL.GL_FRONT].prop[:5]
            ##             else:
            ##                 fpProp = None

            #print 'FUGU OVERWRITE COLOR', fpProp
            #import numpy
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, numpy.array((.6,.6,.6,1), 'f'))
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, numpy.array((1.,1.,1.,1), 'f'))
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, numpy.array((.4,.4,.4,1), 'f'))
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, numpy.array((0,0,0,1), 'f'))
            #GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 1.)

            status = glDrawSphereSet(
                self.templateDSPL[0],
                coords.astype('f'),
                fpProp,  #self.materials[GL.GL_FRONT].prop,
                highlight=self.highlight,
            )
            #print "Spheres, status: ", status
            return status
        else:
            resetMaterialMemory()
            #print "SLOW Spheres"
            if self.oneRadius == viewerConst.NO:
                radii = self.vertexSet.radii.array
            else:
                radii = Numeric.ones(centers.shape[0]) * self.radius

            if len(self.vertexSet.vertices) != len(radii):
                return 0

            for i in xrange(centers.shape[0]):
                GL.glPushName(i)
                GL.glPushMatrix()
                GL.glTranslatef(float(centers[i][0]), float(centers[i][1]),
                                float(centers[i][2]))
                if not self.oneRadius:
                    GL.glScalef(float(radii[i]), float(radii[i]),
                                float(radii[i]))
                else:
                    GL.glScalef(float(self.radius), float(self.radius),
                                float(self.radius))
                #print '#%d'%self.templateDSPL[0], "glCallList Spheres0"
                if fp:
                    for m in (0, 1, 2, 3, 4):
                        if fp.binding[m] != viewerConst.OVERALL:
                            glMaterialWithCheck(face,
                                                viewerConst.propConst[m],
                                                fp.prop[m][0],
                                                geom=self)
                GL.glCallList(self.templateDSPL[0])
                GL.glPopMatrix()
                GL.glPopName()
            return 1
示例#9
0
    def Draw(self):
        """ Draw function of the geom
return status 0 or 1
If you want fast rendering, you need to set self.templateDSPL
using MakeTemplate.
"""
        #print "Ellipsoids.Draw"
        
        assert self.templateDSPL is not None

        currentcontext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
        if currentcontext != self.templateDSPL[1]:
            warnings.warn("""draw failed because the current context is the wrong one""")
            #print "currentcontext != self.templateDSPL[1]", currentcontext, self.templateDSPL[1]
            return 0

        centers = self.vertexSet.vertices.array
        if len(centers) == 0: return
        scaling = self.scaling
        orientation = self.orientation
        vertices = self.vertexSet.vertices.array
        
        if len(vertices) != len(scaling) or len(vertices) != len(orientation):
            return

        if self.inheritMaterial:
            fp = None
            bp = None
        else:
            fp = self.materials[GL.GL_FRONT]
            if not self.frontAndBack:
                bp = self.materials[GL.GL_BACK]
                face = GL.GL_FRONT
            else:
                bp = None
                face = GL.GL_FRONT_AND_BACK

        for i in xrange(len(vertices)):
            GL.glPushName(i)

            if fp:
                for m in (0,1,2,3,4):
                    if fp.binding[m] != viewerConst.OVERALL:
                        glMaterialWithCheck( face,
                                             viewerConst.propConst[m],
                                             fp.prop[m][i] )
            if bp:
                for m in (0,1,2,3,4):
                    if bp.binding[m] != viewerConst.OVERALL:
                        glMaterialWithCheck( face,
                                             viewerConst.propConst[m],
                                             bp.prop[m][i] )

            GL.glPushMatrix()
            GL.glTranslatef(float(vertices[i][0]),
                            float(vertices[i][1]),
                            float(vertices[i][2]))
            GL.glMultMatrixf( orientation[i].ravel() )
            GL.glScalef(float(scaling[i][0]),
                        float(scaling[i][1]),
                        float(scaling[i][2]))
            #print '#%d'%self.templateDSPL[0], "glCallList Ellipsoids0"
            GL.glCallList(self.templateDSPL[0])
            GL.glPopMatrix()

            GL.glPopName()

        return True
    def DisplayFunction(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        """display a set of indexed geometric primitives"""
        
        if self.dpyList:

#            print "DisplayFunction", self.dpyList, self.fullName

            lDrawOutline = (self.getDrawOutlineMode('front'), self.getDrawOutlineMode('back'))
            if (lDrawOutline[0] or lDrawOutline[1]) and self.viewer.hasOffsetExt:

                outl = self.outline

                if   self.GetPolyMode('front') == GL.GL_FILL \
                  or self.GetPolyMode('back') == GL.GL_FILL:

                    mode = GL.GL_POLYGON_OFFSET_FILL

                    GL.glEnable(mode)
                    self.viewer.polyOffset( outl.factor, outl.unit)
                    Geom.DisplayFunction(self)
                    GL.glDisable(mode)

                    GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
                    if not outl.colorAsMaterial:
                        if outl.lighting:
                            GL.glMaterialfv( GL.GL_FRONT_AND_BACK,
                                             GL.GL_EMISSION,
                                             outl.color )
                        else:
                            GL.glDisable(GL.GL_LIGHTING)
                            GL.glColor4fv (outl.color)

                    GL.glLineWidth(outl.lineWidth)

                    if lDrawOutline[0] is False or lDrawOutline[1] is False:
                        GL.glEnable(GL.GL_CULL_FACE)
                        if lDrawOutline[0]:
                            GL.glCullFace(GL.GL_BACK)
                        elif lDrawOutline[1]:
                            GL.glCullFace(GL.GL_FRONT)
                    else:
                        GL.glDisable(GL.GL_CULL_FACE)

                    if outl.dpyList:
                        currentcontext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
                        if currentcontext != outl.dpyList[1]:
                            warnings.warn("""DisplayFunction failed because the current context is the wrong one""")
                            #print "currentcontext != outl.dpyList[1]", currentcontext, outl.dpyList[1]
                        else:
                            #print '#%d'%outl.dpyList[0], currentcontext, "glCallList IndexedGeom"
                            GL.glCallList(outl.dpyList[0])

                    GL.glEnable(GL.GL_CULL_FACE)
                    GL.glEnable(GL.GL_LIGHTING)

                else:
                    Geom.DisplayFunction(self)
            else:
                Geom.DisplayFunction(self)
示例#11
0
    def Draw(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        """Draw function of the geom
return status 0 or 1
If you want fast rendering, you need to set self.templateDSPL
using MakeTemplate.
"""
        #print "Spheres.Draw", self.name

        assert self.templateDSPL is not None

        currentcontext = self.viewer.currentCamera.tk.call(
            self.viewer.currentCamera._w, 'contexttag')
        if currentcontext != self.templateDSPL[1]:
            import traceback;traceback.print_stack()
            warnings.warn("""draw failed because the current context is the wrong one""")
            #print "currentcontext != self.templateDSPL[1]", currentcontext, self.templateDSPL[1]
            return 0
            
        centers = self.vertexSet.vertices.array
        if len(centers) == 0: 
            return 0

        # handle overall binding of material
        if self.inheritMaterial:
            fp = None
            fpProp = None
            bp = None
        else:
            mat = self.materials[GL.GL_FRONT]
            fpProp = []
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                fpProp.append(p)
            fpProp.append(mat.prop[4])


            fp = self.materials[GL.GL_FRONT]
            #colorFront = Numeric.array(self.materials[GL.GL_FRONT].prop[1], copy=1)
            colorFront = Numeric.array(fpProp[1], copy=1)
            if self.frontAndBack:
                bp = None
                face = GL.GL_FRONT_AND_BACK
            else:
                bp = self.materials[GL.GL_BACK]
                face = GL.GL_FRONT

        if fp:
            for m in (0,1,2,3,4):
                if fp.binding[m] == viewerConst.OVERALL:
                    glMaterialWithCheck( face,
                                         viewerConst.propConst[m],
                                         fpProp[m][0])
            if fp.binding[1] == viewerConst.OVERALL:
                GL.glColor4fv(colorFront[0])

            if fp:
                for m in (0,1,2,3,4):
                    if fp.binding[m] != viewerConst.OVERALL:
                        glMaterialWithCheck( face,
                                             viewerConst.propConst[m],
                                             fpProp[m][0])

                if fp.binding[1] != viewerConst.OVERALL:
                    GL.glColor4fv(colorFront[0])
            if bp:
                for m in (0,1,2,3,4):
                    if bp.binding[m] != viewerConst.OVERALL:
                        glMaterialWithCheck( GL.GL_BACK,
                                             viewerConst.propConst[m],
                                             bp.prop[m][0])

        #print self.name
        #if fp: print fp.prop[1], fp.binding
        #else: print
        
        if self.fastSpheres:
            #print "self.fastSpheres", self.fastSpheres
            if self.oneRadius == viewerConst.NO:
                radii = self.vertexSet.radii.array
                #FIXME: quick fix because can be called from base class Set
                # method after centers have been set BUT before radii have been
                # set
                if len(self.vertexSet.vertices) != len(radii):
                    return 0
            else:
                radii = Numeric.ones( centers.shape[0] ) * self.radius
            radii.shape = (-1,1)
            coords = Numeric.concatenate ( (centers, radii), 1 )

##             if not self.inheritMaterial:
##                 mat = self.materials[GL.GL_FRONT]
##                 fpProp = []
##                 for propInd in range(4):
##                     b, p = mat.GetProperty(propInd)
##                     fpProp.append(p)
##                 fpProp.append(mat.prop[4])
##                 #fpProp = self.materials[GL.GL_FRONT].prop[:5]
##             else:
##                 fpProp = None

            #print 'FUGU OVERWRITE COLOR', fpProp
            #import numpy
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, numpy.array((.6,.6,.6,1), 'f'))
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, numpy.array((1.,1.,1.,1), 'f'))
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, numpy.array((.4,.4,.4,1), 'f'))
            #GL.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, numpy.array((0,0,0,1), 'f'))
            #GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 1.)

            status = glDrawSphereSet( 
                                  self.templateDSPL[0],
                                  coords.astype('f'),
                                  fpProp, #self.materials[GL.GL_FRONT].prop,
                                  highlight=self.highlight,
                                  )
            #print "Spheres, status: ", status
            return status
        else:
            resetMaterialMemory()
            #print "SLOW Spheres"
            if self.oneRadius == viewerConst.NO:
                radii = self.vertexSet.radii.array
            else:
                radii = Numeric.ones( centers.shape[0] ) * self.radius

            if len(self.vertexSet.vertices) != len(radii):
                return 0
            
            for i in xrange(centers.shape[0]):
                GL.glPushName(i)
                GL.glPushMatrix()
                GL.glTranslatef(float(centers[i][0]),
                                float(centers[i][1]),
                                float(centers[i][2]))
                if not self.oneRadius:
                    GL.glScalef(float(radii[i]),float(radii[i]),float(radii[i]))
                else:
                    GL.glScalef(float(self.radius), float(self.radius), float(self.radius))
                #print '#%d'%self.templateDSPL[0], "glCallList Spheres0"
                if fp:
                    for m in (0,1,2,3,4):
                        if fp.binding[m] != viewerConst.OVERALL:
                            glMaterialWithCheck( face,
                                                 viewerConst.propConst[m],
                                                 fp.prop[m][0], geom=self)
                GL.glCallList(self.templateDSPL[0])
                GL.glPopMatrix()
                GL.glPopName()
            return 1