def Draw(self):

        OVERALL, PER_VERTEX, PER_PART, PER_FACE = 10, 11, 12, 13
        #NONE, OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
        
        propConst = DejaVu.viewerConst.propConst
        noCol = 1
        vert = self.vertexSet.vertices.array
        if len(vert)==0: return
        if not self.stripBegin or len(self.stripBegin)==0: return


        if self.materials[GL.GL_FRONT] and not self.inheritMaterial:
            frontMat = fpProp = []
            frontMatBind = fpBind = []
            mat = self.materials[GL.GL_FRONT]
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                fpProp.append(p)
                fpBind.append(b)
            fpProp.append(mat.prop[4])
            fpBind.append(mat.binding[4])

        else:
            frontMat = None
            frontMatBind = None

        if self.materials[GL.GL_BACK] and not self.inheritMaterial:
            backMat = bpProp = []
            backMatBind = bpBind = []
            mat = self.materials[GL.GL_BACK]
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                bpProp.append(p)
                bpBind.append(b)
            bpProp.append(mat.prop[4])
            bpBind.append(mat.binding[4])

        else:
            backMat = None
            backMatBind = None

        if not self.frontAndBack is None:
            face = GL.GL_FRONT
        else:
            face = GL.GL_FRONT_AND_BACK

        n = self.normals
        if self.normals is None:    # overall color for no normals or lighting
            if frontMat:
                if frontMatBind[noCol] == OVERALL:
                    GL.glColor4fv( frontMat[noCol][0] )
        else:
            if len(self.normals)==1:             # overall normal
                GL.glNormal3dv(n[0])
            if frontMat:
                for j in range(5):               # overall materials
                    if frontMatBind[j] == OVERALL:
                        glMaterialWithCheck( face, propConst[j],
                                             frontMat[j][0] )
            if backMat and not self.frontAndBack:
                for j in range(5):
                    if backMatBind[j] == OVERALL:
                        glMaterialWithCheck( GL.GL_BACK, propConst[j],
                                             backMat[j][0] )

        self.isNewColor()
        #self.isNewMaterial(0,0,0)

        # loop over each strip
        sB = self.stripBegin
        sE = self.stripEnd
        self.sE = sE
        self.sB= sB
        for stripNum in range(len(sB)):
            #print 'stripNum',stripNum
            GL.glPushName(stripNum)
            GL.glBegin(GL.GL_TRIANGLE_STRIP)

            # per part material properties
            if frontMat:
                if frontMatBind[noCol] == PER_PART:
                    if self.isNewColor(c=frontMat[noCol][stripNum]):
                        GL.glColor4fv(frontMat[noCol][stripNum])

            if n is not None:
                if frontMat:
                    for j in range(5):
                        if frontMatBind[j]==PER_PART:
                            glMaterialWithCheck( face,
                                                 propConst[j],
                                                 frontMat[j][stripNum] )

                if backMat and not self.frontAndBack:
                    for j in range(5):
                        if backMatBind[j] ==  PER_PART:
                            glMaterialWithCheck( GL.GL_BACK,
                                                 propConst[j],
                                                 backMat[j][stripNum] )

            #   loop over each vertex in a strip
            i = 0
            for ind in range(sB[stripNum],sE[stripNum]):
                if ind >= len(vert):
                    print 'ERROR',ind
                v = vert[ind]
                # normals for flat or smooth shading
                if n is not None:
                    if self.shading==GL.GL_FLAT:
                        if i > 1:
                            GL.glNormal3dv(n[sB[stripNum]+i-(2*(stripNum+1))])
                    elif self.shading==GL.GL_SMOOTH:
                        GL.glNormal3fv(n[ind])
                    else:
                        pass

                # per face (per triangle) material properties
                if n is None:
                    if frontMat:
                        if frontMatBind[noCol] == PER_FACE:
                            if i > 1:
                                if self.isNewColor(c=frontMat[noCol][sB[stripNum]+i-(2*(stripNum+1))]):
                                    GL.glColor4fv(frontMat[noCol][sB[stripNum]+i-(2*(stripNum+1))])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_FACE:
                                if i > 1:
                                    glMaterialWithCheck( face,
                                                         propConst[k],
                               frontMat[k][sB[stripNum]+i-(2*(stripNum+1))] )

                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_FACE:
                                if i > 1 and i%2==0:
                                    glMaterialWithCheck( GL.GL_BACK,
                                                         propConst[k],
                                backMat[k][sB[stripNum]+i-(2*(stripNum+1))] )


                #  per vertex material properties
                if n is None:
                    if frontMat:
                        if frontMatBind[noCol] == PER_VERTEX:
                            if self.isNewColor(c=frontMat[noCol][sB[stripNum]+i]):
                                GL.glColor4fv(frontMat[noCol][sB[stripNum]+i])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck( face,
                                                     propConst[k],
                                            frontMat[k][sB[stripNum]+i] )
                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck( GL.GL_BACK,
                                                     propConst[k],
                                             backMat[k][sB[stripNum]+i] )

                # draw vertex
                #GL.glVertex3dv(v)
                gllib.glVertex3fv(v)
                i = i + 1

            GL.glEnd()
            GL.glPopName()
        return 1
예제 #2
0
    def Draw(self):

        OVERALL, PER_VERTEX, PER_PART, PER_FACE = 10, 11, 12, 13
        #NONE, OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13

        propConst = DejaVu.viewerConst.propConst
        noCol = 1
        vert = self.vertexSet.vertices.array
        if len(vert) == 0: return
        if not self.stripBegin or len(self.stripBegin) == 0: return

        if self.materials[GL.GL_FRONT] and not self.inheritMaterial:
            frontMat = fpProp = []
            frontMatBind = fpBind = []
            mat = self.materials[GL.GL_FRONT]
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                fpProp.append(p)
                fpBind.append(b)
            fpProp.append(mat.prop[4])
            fpBind.append(mat.binding[4])

        else:
            frontMat = None
            frontMatBind = None

        if self.materials[GL.GL_BACK] and not self.inheritMaterial:
            backMat = bpProp = []
            backMatBind = bpBind = []
            mat = self.materials[GL.GL_BACK]
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                bpProp.append(p)
                bpBind.append(b)
            bpProp.append(mat.prop[4])
            bpBind.append(mat.binding[4])

        else:
            backMat = None
            backMatBind = None

        if not self.frontAndBack is None:
            face = GL.GL_FRONT
        else:
            face = GL.GL_FRONT_AND_BACK

        n = self.normals
        if self.normals is None:  # overall color for no normals or lighting
            if frontMat:
                if frontMatBind[noCol] == OVERALL:
                    GL.glColor4fv(frontMat[noCol][0])
        else:
            if len(self.normals) == 1:  # overall normal
                GL.glNormal3dv(n[0])
            if frontMat:
                for j in range(5):  # overall materials
                    if frontMatBind[j] == OVERALL:
                        glMaterialWithCheck(face, propConst[j], frontMat[j][0])
            if backMat and not self.frontAndBack:
                for j in range(5):
                    if backMatBind[j] == OVERALL:
                        glMaterialWithCheck(GL.GL_BACK, propConst[j],
                                            backMat[j][0])

        self.isNewColor()
        #self.isNewMaterial(0,0,0)

        # loop over each strip
        sB = self.stripBegin
        sE = self.stripEnd
        self.sE = sE
        self.sB = sB
        for stripNum in range(len(sB)):
            #print 'stripNum',stripNum
            GL.glPushName(stripNum)
            GL.glBegin(GL.GL_TRIANGLE_STRIP)

            # per part material properties
            if frontMat:
                if frontMatBind[noCol] == PER_PART:
                    if self.isNewColor(c=frontMat[noCol][stripNum]):
                        GL.glColor4fv(frontMat[noCol][stripNum])

            if n is not None:
                if frontMat:
                    for j in range(5):
                        if frontMatBind[j] == PER_PART:
                            glMaterialWithCheck(face, propConst[j],
                                                frontMat[j][stripNum])

                if backMat and not self.frontAndBack:
                    for j in range(5):
                        if backMatBind[j] == PER_PART:
                            glMaterialWithCheck(GL.GL_BACK, propConst[j],
                                                backMat[j][stripNum])

            #   loop over each vertex in a strip
            i = 0
            for ind in range(sB[stripNum], sE[stripNum]):
                if ind >= len(vert):
                    print 'ERROR', ind
                v = vert[ind]
                # normals for flat or smooth shading
                if n is not None:
                    if self.shading == GL.GL_FLAT:
                        if i > 1:
                            GL.glNormal3dv(n[sB[stripNum] + i -
                                             (2 * (stripNum + 1))])
                    elif self.shading == GL.GL_SMOOTH:
                        GL.glNormal3fv(n[ind])
                    else:
                        pass

                # per face (per triangle) material properties
                if n is None:
                    if frontMat:
                        if frontMatBind[noCol] == PER_FACE:
                            if i > 1:
                                if self.isNewColor(
                                        c=frontMat[noCol][sB[stripNum] + i -
                                                          (2 *
                                                           (stripNum + 1))]):
                                    GL.glColor4fv(
                                        frontMat[noCol][sB[stripNum] + i -
                                                        (2 * (stripNum + 1))])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_FACE:
                                if i > 1:
                                    glMaterialWithCheck(
                                        face, propConst[k],
                                        frontMat[k][sB[stripNum] + i -
                                                    (2 * (stripNum + 1))])

                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_FACE:
                                if i > 1 and i % 2 == 0:
                                    glMaterialWithCheck(
                                        GL.GL_BACK, propConst[k],
                                        backMat[k][sB[stripNum] + i -
                                                   (2 * (stripNum + 1))])

                #  per vertex material properties
                if n is None:
                    if frontMat:
                        if frontMatBind[noCol] == PER_VERTEX:
                            if self.isNewColor(c=frontMat[noCol][sB[stripNum] +
                                                                 i]):
                                GL.glColor4fv(frontMat[noCol][sB[stripNum] +
                                                              i])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck(
                                    face, propConst[k],
                                    frontMat[k][sB[stripNum] + i])
                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck(
                                    GL.GL_BACK, propConst[k],
                                    backMat[k][sB[stripNum] + i])

                # draw vertex
                #GL.glVertex3dv(v)
                gllib.glVertex3fv(v)
                i = i + 1

            GL.glEnd()
            GL.glPopName()
        return 1
예제 #3
0
파일: Spheres.py 프로젝트: lisarosalina/App
    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
예제 #4
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
예제 #5
0
    def Draw(self):

        OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
        #NONE, OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
        propConst = DejaVu.viewerConst.propConst
        noCol = 1
        vert = self.vertexSet.vertices.array
        if len(vert)==0: return

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

        if self.materials[GL.GL_BACK] and not self.inheritMaterial:
            mat = self.materials[GL.GL_BACK]
            backMat = bpProp = []
            backMatBind = bpBind = []
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                bpProp.append(p)
                bpBind.append(b)
            bpProp.append(mat.prop[4])
            bpBind.append(mat.binding[4])
#		backMat = self.materials[GL.GL_BACK].prop
#		backMatBind = self.materials[GL.GL_BACK].binding
        else:
            backMat = None
            backMatBind = None

##              texCoords = None
##  	    if hasattr(self.vertexSet, "texCoords"):
##  		if self.vertexSet.texCoords.status >= viewerConst.COMPUTED:
##  		    texCoords = self.vertexSet.texCoords.array

        if not self.frontAndBack is None:
            face = GL.GL_FRONT
        else:
            face = GL.GL_FRONT_AND_BACK

        if not self.normals:     # overall color for no normals or lighting
            if frontMat:
                if frontMatBind[noCol] == OVERALL:
                    GL.glColor4fv( frontMat[noCol][0] )
        else:
            if len(self.normals)==1:             # overall normal
                n = self.normals
                GL.glNormal3dv(n[0])
            if frontMat:
                for j in range(5):		     # overall materials
                    if frontMatBind[j] == OVERALL:
                        glMaterialWithCheck( face, propConst[j],
                                             frontMat[j][0] )
            if backMat and not self.frontAndBack:
                for j in range(5):
                    if backMatBind[j] == OVERALL:
                        glMaterialWithCheck( GL.GL_BACK, propConst[j],
                                             backMat[j][0] )

        self.isNewColor()
        #self.isNewMaterial(0,0,0)

        n = self.normals            

        # loop over each strip
        for stripNum in range(1,len(self.stripBegin)):
            c = vert[self.stripBegin[stripNum-1]:self.stripBegin[stripNum]]
            GL.glPushName(stripNum)
            GL.glBegin(GL.GL_QUAD_STRIP)

            # per part material properties
            if frontMat:
                if frontMatBind[noCol] == PER_PART:
                    if self.isNewColor(c=frontMat[noCol][stripNum-1]):
                        GL.glColor4fv(frontMat[noCol][stripNum-1])

            if n:
                if frontMat:
                    for j in range(5):
                        if frontMatBind[j]==PER_PART:
                            glMaterialWithCheck( face,
                                                 propConst[j],
                                                 frontMat[j][stripNum-1] )

                if backMat and not self.frontAndBack:
                    for j in range(5):
                        if backMatBind[j] ==  PER_PART:
                            glMaterialWithCheck( GL.GL_BACK,
                                                 propConst[j],
                                                 backMat[j][stripNum-1] )

            #   loop over each vertex in a strip
            i = 0
            for v in c:
                if n:
                    if self.shading==GL.GL_FLAT:
                        if i > 1 and i%2==0:
                            GL.glNormal3dv(n[(self.stripBegin[stripNum-1]+i-(2*stripNum))/2])
                    elif self.shading==GL.GL_SMOOTH:
                        GL.glNormal3dv(n[self.stripBegin[stripNum-1]+i])
                    else:
                        pass

                # per face (per triangle) material properties
                if not n:
                    if frontMat:
                        if frontMatBind[noCol] == PER_FACE:
                            if i > 1 and i%2==0:
                                if self.isNewColor(c=frontMat[noCol][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2]):
                                    GL.glColor4fv(frontMat[noCol][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_FACE:
                                if i > 1 and i%2==0:
                                    glMaterialWithCheck( face,
                                                         propConst[k],
              frontMat[k][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2] )

                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_FACE:
                                if i > 1 and i%2==0:
                                    glMaterialWithCheck( GL.GL_BACK,
                                                         propConst[k],
               backMat[k][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2] )


                #  per vertex material properties
                if not n:
                    if frontMat:
                        if frontMatBind[noCol] == PER_VERTEX:
                            if self.isNewColor(c=frontMat[noCol][self.stripBegin[stripNum-1]+i]):
                                GL.glColor4fv(frontMat[noCol][self.stripBegin[stripNum-1]+i])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck( face, propConst[k],
                               frontMat[k][self.stripBegin[stripNum-1]+i] )
                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck( GL.GL_BACK,
                                                     propConst[k],
                               backMat[k][self.stripBegin[stripNum-1]+i] )

                # draw vertex
                GL.glVertex3dv(v)
                i = i + 1

            GL.glEnd()
            GL.glPopName()
        return 1
예제 #6
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
예제 #7
0
    def Draw(self):

        OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
        #NONE, OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
        propConst = DejaVu.viewerConst.propConst
        noCol = 1
        vert = self.vertexSet.vertices.array
        if len(vert) == 0: return

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

        if self.materials[GL.GL_BACK] and not self.inheritMaterial:
            mat = self.materials[GL.GL_BACK]
            backMat = bpProp = []
            backMatBind = bpBind = []
            for propInd in range(4):
                b, p = mat.GetProperty(propInd)
                bpProp.append(p)
                bpBind.append(b)
            bpProp.append(mat.prop[4])
            bpBind.append(mat.binding[4])
#		backMat = self.materials[GL.GL_BACK].prop
#		backMatBind = self.materials[GL.GL_BACK].binding
        else:
            backMat = None
            backMatBind = None


##              texCoords = None
##  	    if hasattr(self.vertexSet, "texCoords"):
##  		if self.vertexSet.texCoords.status >= viewerConst.COMPUTED:
##  		    texCoords = self.vertexSet.texCoords.array

        if not self.frontAndBack is None:
            face = GL.GL_FRONT
        else:
            face = GL.GL_FRONT_AND_BACK

        if not self.normals:  # overall color for no normals or lighting
            if frontMat:
                if frontMatBind[noCol] == OVERALL:
                    GL.glColor4fv(frontMat[noCol][0])
        else:
            if len(self.normals) == 1:  # overall normal
                n = self.normals
                GL.glNormal3dv(n[0])
            if frontMat:
                for j in range(5):  # overall materials
                    if frontMatBind[j] == OVERALL:
                        glMaterialWithCheck(face, propConst[j], frontMat[j][0])
            if backMat and not self.frontAndBack:
                for j in range(5):
                    if backMatBind[j] == OVERALL:
                        glMaterialWithCheck(GL.GL_BACK, propConst[j],
                                            backMat[j][0])

        self.isNewColor()
        #self.isNewMaterial(0,0,0)

        n = self.normals

        # loop over each strip
        for stripNum in range(1, len(self.stripBegin)):
            c = vert[self.stripBegin[stripNum - 1]:self.stripBegin[stripNum]]
            GL.glPushName(stripNum)
            GL.glBegin(GL.GL_QUAD_STRIP)

            # per part material properties
            if frontMat:
                if frontMatBind[noCol] == PER_PART:
                    if self.isNewColor(c=frontMat[noCol][stripNum - 1]):
                        GL.glColor4fv(frontMat[noCol][stripNum - 1])

            if n:
                if frontMat:
                    for j in range(5):
                        if frontMatBind[j] == PER_PART:
                            glMaterialWithCheck(face, propConst[j],
                                                frontMat[j][stripNum - 1])

                if backMat and not self.frontAndBack:
                    for j in range(5):
                        if backMatBind[j] == PER_PART:
                            glMaterialWithCheck(GL.GL_BACK, propConst[j],
                                                backMat[j][stripNum - 1])

            #   loop over each vertex in a strip
            i = 0
            for v in c:
                if n:
                    if self.shading == GL.GL_FLAT:
                        if i > 1 and i % 2 == 0:
                            GL.glNormal3dv(
                                n[(self.stripBegin[stripNum - 1] + i -
                                   (2 * stripNum)) / 2])
                    elif self.shading == GL.GL_SMOOTH:
                        GL.glNormal3dv(n[self.stripBegin[stripNum - 1] + i])
                    else:
                        pass

                # per face (per triangle) material properties
                if not n:
                    if frontMat:
                        if frontMatBind[noCol] == PER_FACE:
                            if i > 1 and i % 2 == 0:
                                if self.isNewColor(c=frontMat[noCol][
                                    (self.stripBegin[stripNum - 1] + i -
                                     (2 * stripNum)) / 2]):
                                    GL.glColor4fv(frontMat[noCol][
                                        (self.stripBegin[stripNum - 1] + i -
                                         (2 * stripNum)) / 2])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_FACE:
                                if i > 1 and i % 2 == 0:
                                    glMaterialWithCheck(
                                        face, propConst[k], frontMat[k]
                                        [(self.stripBegin[stripNum - 1] + i -
                                          (2 * stripNum)) / 2])

                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_FACE:
                                if i > 1 and i % 2 == 0:
                                    glMaterialWithCheck(
                                        GL.GL_BACK, propConst[k], backMat[k]
                                        [(self.stripBegin[stripNum - 1] + i -
                                          (2 * stripNum)) / 2])

                #  per vertex material properties
                if not n:
                    if frontMat:
                        if frontMatBind[noCol] == PER_VERTEX:
                            if self.isNewColor(c=frontMat[noCol][
                                    self.stripBegin[stripNum - 1] + i]):
                                GL.glColor4fv(
                                    frontMat[noCol][self.stripBegin[stripNum -
                                                                    1] + i])

                else:
                    if frontMat:
                        for k in range(5):
                            if frontMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck(
                                    face, propConst[k],
                                    frontMat[k][self.stripBegin[stripNum - 1] +
                                                i])
                    if backMat and not self.frontAndBack:
                        for k in range(5):
                            if backMatBind[k] == PER_VERTEX:
                                glMaterialWithCheck(
                                    GL.GL_BACK, propConst[k],
                                    backMat[k][self.stripBegin[stripNum - 1] +
                                               i])

                # draw vertex
                GL.glVertex3dv(v)
                i = i + 1

            GL.glEnd()
            GL.glPopName()
        return 1
예제 #8
0
    def Draw(self):
        #print "GlfLabels.Draw", self

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

        labels = self.labels
        if labels is None or len(labels) == 0:
            return
        elif len(labels) == centers.shape[0]:
            txt = None
        else:
            txt = labels[0]
            if type(txt) != types.StringType:
                txt = str(txt)

        self.prepareBillboardAndNormalForAllTextLines()

        glf.glfSetSymbolSpace(self.fontSpacing)

        if self.fontTypeIsVector:
            font = self.vectorFonts[self.font]
            glf.glfSetCurrentFont(font)
        else:
            font = self.bitmapFonts[self.font]
            glf.glfSetCurrentBMFFont(font)
            glf.glfStartBitmapDrawing()

        resetMaterialMemory()
        if self.inheritMaterial:
            fp = None
            bp = None
        else:
            fp = self.materials[GL.GL_FRONT]
            colorFront = Numeric.array(self.materials[GL.GL_FRONT].prop[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],
                                        fp.prop[m][0])
            if fp.binding[1] == viewerConst.OVERALL:
                GL.glColor4fv(colorFront[0])

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

            #GL.glPushName(i)
            if txt is None:
                txt2 = self.labels[i]
                if type(txt2) != types.StringType:
                    txt2 = str(txt2)
                self.drawOne3dTextLine(txt2, i)
            else:
                self.drawOne3dTextLine(txt, i)
            #GL.glPopName()

        if self.fontTypeIsVector is False:
            glf.glfStopBitmapDrawing()

        return 1