Beispiel #1
0
    def __createHintTextsAndColors(self):
        rootHint = coin.SoSeparator()

        # hint lines
        colorLines = coin.SoSeparator()
        rootHint.addChild(colorLines)
        mat = coin.SoMaterial()
        mat.diffuseColor.setValues(0, len(self.__hintColors),
                                   self.__hintColors)
        colorLines.addChild(mat)
        bind = coin.SoMaterialBinding()
        bind.value = coin.SoMaterialBinding.PER_PART
        colorLines.addChild(bind)

        lineCoords = coin.SoCoordinate3()
        colorLines.addChild(lineCoords)
        lineset = coin.SoLineSet()
        colorLines.addChild(lineset)
        space = self.__AxisHeight / self.__scalesNum4XAxis

        startX = self.__AxisWidth * 1.05
        pts = []
        for i, s in enumerate(self.__hintTexts):
            pts.append((startX, self.__AxisHeight - i * space, 0))
            pts.append((startX + space, self.__AxisHeight - i * space, 0))

        lineCoords.point.setValues(0, len(pts), pts)
        nums = [2] * (len(pts) / 2)
        lineset.numVertices.setValues(0, len(nums), nums)

        # add texts
        font = coin.SoFont()
        font.name.setValue('Times-Roman')
        font.size.setValue(9)
        scaleLen = self.__AxisHeight / self.__scalesNum4XAxis
        for i in range(len(self.__hintColors)):
            g = coin.SoSeparator()

            # translation
            t = coin.SoTranslation()
            t.translation.setValue(startX + space * 2,
                                   self.__AxisHeight - i * space, 0)
            g.addChild(t)

            # color
            col = coin.SoBaseColor()
            col.rgb.setValue(self.__hintColors[i][:3])
            g.addChild(col)

            #font
            g.addChild(font)

            # text
            text = coin.SoText3()
            text.string = self.__hintTexts[i]
            text.justification = coin.SoText3.LEFT
            g.addChild(text)
            rootHint.addChild(g)

        self.__root.addChild(rootHint)
Beispiel #2
0
 def __init__(self, color = (0.,0.,0.)):
     super(colorNode, self).__init__()
     self.coinColor = coin.SoMaterial()
     self.binding = coin.SoMaterialBinding()
     self.binding.value = coin.SoMaterialBinding.PER_PART
     self.addChild(self.binding)
     self.addChild(self.coinColor)
     self.color = color
Beispiel #3
0
    def showStatisticsLine(self, docName , shapeName , pts , color):
        import FreeCADGui
        from pivy import coin
        
        sg = FreeCADGui.getDocument(docName).ActiveView.getSceneGraph()
        lines = coin.SoSeparator()
        self.__setRootNode(docName, sg, lines)
        
        drawStyle = coin.SoDrawStyle()
        drawStyle.style = coin.SoDrawStyle.LINES
        drawStyle.lineWidth = 2
#        drawStyle.pointSize = 3
        lines.addChild(drawStyle)
        
#        norm = coin.SoNormal()
#        norm.vector.setValue(0,0,1)
#        lines.addChild(norm)
        
        # set color for block
        matColors = coin.SoMaterial()
        col = (color[0],color[1],color[2])
#        matColors.ambientColor.setValue(color[0],color[1],color[2])
#        matColors.diffuseColor.setValue(color[0],color[1],color[2])
#        matColors.specularColor.setValue(color[0],color[1],color[2])
        matColors.diffuseColor.setValues(0,len(pts),[col]*len(pts))
        lines.addChild(matColors)

        tmpMatBind = coin.SoMaterialBinding()
        tmpMatBind.value = coin.SoMaterialBinding.PER_PART
        lines.addChild(tmpMatBind)
#        lineColor = coin.SoBaseColor()
#        lineColor.rgb = (color[0],color[1],color[2])
#        lines.addChild(lineColor)

        # point
#        tmpPts = []
#        for i in range(len(pts)-1):
#            tmpPts.append(pts[i])
#            tmpPts.append(pts[i+1])
        data = coin.SoCoordinate3()
#        data.point.setValues(0 , len(tmpPts),tmpPts)
        data.point.setValues(0 , len(pts),pts)
        lines.addChild(data)
        
        lineset=coin.SoLineSet()
        lineset.numVertices.setValues(0,1, [len(pts)] )
#        lineset = coin.SoIndexedLineSet()
#        nums = range(len(pts))
#        nums.append(-1)
#        lineset.coordIndex.setValues(0,len(nums), nums)
        lines.addChild(lineset)
        
        self.__setRootNode(docName, sg , lines)
Beispiel #4
0
    def build_lines(self):
        np = self._number_of_points
        n = 1 + 2 * np

        self.line_mat1 = coin.SoMaterial()
        ol = list()  #[(0.2,0.2,0.2)] + [(0.6,0.6,0.6)] * 9
        bind1 = coin.SoMaterialBinding()
        bind1.value = coin.SoMaterialBinding.PER_PART
        l1 = coin.SoIndexedLineSet()
        l1.coordIndex.setValue(0)
        ind = list()
        for i in range(2 * self._number_of_points + 1):
            if not i == self._number_of_points:
                ind.append((i * n))
                ind.append(((i + 1) * n) - 1)
                ind.append(-1)
                if (i % 10) == 0:
                    ol.append((0.2, 0.2, 0.2))
                else:
                    ol.append((0.4, 0.4, 0.4))
            #print(ind)
        self.line_mat1.diffuseColor.setValues(0, len(ol), ol)
        l1.coordIndex.setValues(0, len(ind), ind)

        l2 = coin.SoIndexedLineSet()
        l2.coordIndex.setValue(0)
        ind2 = list()
        for i in range(2 * self._number_of_points + 1):
            if not i == self._number_of_points:
                ind2.append(i)
                ind2.append(i + (n - 1) * n)
                ind2.append(-1)
                #if (i % 10) == 0:
                #ol.append((0.2,0.2,0.2))
                #else:
                #ol.append((0.4,0.4,0.4))
            #print(ind)
        #self.line_mat1.diffuseColor.setValues(0, len(ol), ol )
        l2.coordIndex.setValues(0, len(ind2), ind2)

        self.sep2.addChild(bind1)
        self.sep2.addChild(self.line_mat1)
        self.sep2.addChild(l1)
        self.sep2.addChild(l2)
Beispiel #5
0
a.getDuVector(np.array([0, 0]))
du = a.getDuMatrix(np.array(uv)) * z_points
dv = a.getDvMatrix(np.array(uv)) * z_points
du = du**2 + dv**2

colors = (du - min(du)) / (max(du) - min(du))
colors = np.array([colors,
                   np.zeros(len(colors)),
                   np.zeros(len(colors))]).T.tolist()
from pivy import coin
# # from pivy_primitives_new_new import Marker

result = coin.SoSeparator()

myBinding = coin.SoMaterialBinding()
myBinding.value = coin.SoMaterialBinding.PER_VERTEX_INDEXED
result.addChild(myBinding)

myMaterial = coin.SoMaterial()
myMaterial.diffuseColor.setValues(0, len(colors), colors)
result += myMaterial

# Define coordinates for vertices
myCoords = coin.SoCoordinate3()
myCoords.point.setValues(0, len(pos), pos.tolist())
result += myCoords

# Define the QuadMesh.
myQuadMesh = coin.SoQuadMesh()
myQuadMesh.verticesPerRow = u_dess
Beispiel #6
0
    def attach(self, vobj):
        '''
        Create Object visuals in 3D view.
        '''
        # GeoCoords Node.
        self.geo_coords = coin.SoGeoCoordinate()

        # Surface features.
        self.triangles = coin.SoIndexedFaceSet()
        shape_hints = coin.SoShapeHints()
        shape_hints.vertex_ordering = coin.SoShapeHints.COUNTERCLOCKWISE
        self.mat_color = coin.SoMaterial()
        mat_binding = coin.SoMaterialBinding()
        mat_binding.value = coin.SoMaterialBinding.OVERALL
        edge_color = coin.SoBaseColor()
        edge_color.rgb = (0.5, 0.5, 0.5)
        offset = coin.SoPolygonOffset()

        # Line style.
        line_style = coin.SoDrawStyle()
        line_style.style = coin.SoDrawStyle.LINES
        line_style.lineWidth = 2

        # Contour features.
        cont_color = coin.SoBaseColor()
        cont_color.rgb = (1, 1, 0)
        self.cont_coords = coin.SoGeoCoordinate()
        self.cont_lines = coin.SoLineSet()

        # Contour root.
        contours = coin.SoSeparator()
        contours.addChild(cont_color)
        contours.addChild(line_style)
        contours.addChild(self.cont_coords)
        contours.addChild(self.cont_lines)

        # Face root.
        faces = coin.SoSeparator()
        faces.addChild(shape_hints)
        faces.addChild(self.mat_color)
        faces.addChild(mat_binding)
        faces.addChild(self.geo_coords)
        faces.addChild(self.triangles)

        # Highlight for selection.
        highlight = coin.SoType.fromName('SoFCSelection').createInstance()
        #highlight.documentName.setValue(FreeCAD.ActiveDocument.Name)
        #highlight.objectName.setValue(vobj.Object.Name)
        #highlight.subElementName.setValue("Main")
        highlight.addChild(edge_color)
        highlight.addChild(line_style)
        highlight.addChild(self.geo_coords)
        highlight.addChild(self.triangles)

        # Surface root.
        surface_root = coin.SoSeparator()
        surface_root.addChild(contours)
        surface_root.addChild(offset)
        surface_root.addChild(faces)
        surface_root.addChild(offset)
        surface_root.addChild(highlight)
        vobj.addDisplayMode(surface_root,"Surface")

        # Take features from properties.
        self.onChanged(vobj,"TriangleColor")
Beispiel #7
0
    def get_scene_graph(self, resolution, fluxmap, trans, vmin, vmax):
        """
		Any object that provides a nice QuadMesh from the previous code should be able to render in Coin3D with with the following...
		"""
        from pivy import coin
        import matplotlib.cm as cm
        from matplotlib import colors

        n0 = self.get_scene_graph_transform()
        o = self.get_optics_manager()

        if (o.__class__.__name__ == N.array(['Reflective',
                                             'RealReflective'])).any():
            mat = coin.SoMaterial()
            mat.diffuseColor = (.5, .5, .5)
            mat.specularColor = (.6, .6, .6)
            mat.shininess = 1. - o._abs
            n0.addChild(mat)
            fluxmap = False
        elif fluxmap != None:
            if hasattr(o, 'get_all_hits'):
                e, h = o.get_all_hits()
                xyz = self.global_to_local(h)[:3]
                # plot the histogram into the scenegraph
                g = self.get_geometry_manager()
                if hasattr(g, 'get_fluxmap'):
                    flux = g.get_fluxmap(e, xyz, resolution)
                    if not (hasattr(flux[0], '__len__')):
                        flux = [flux]
                else:
                    fluxmap = False

        meshes = self._geom.get_scene_graph(resolution)
        for m in xrange(len(meshes) / 3):
            n = coin.SoSeparator()

            X, Y, Z = meshes[3 * m:3 * m + 3]
            nr, nc = X.shape
            A = [(X.flat[i], Y.flat[i], Z.flat[i]) for i in range(len(X.flat))]
            coor = coin.SoCoordinate3()
            coor.point.setValues(0, len(A), A)
            n.addChild(coor)

            qm = coin.SoQuadMesh()
            qm.verticesPerRow = nc
            qm.verticesPerColumn = nr
            n.addChild(qm)

            sh = coin.SoShapeHints()
            sh.shapeType = coin.SoShapeHintsElement.UNKNOWN_SHAPE_TYPE
            sh.vertexOrdering = coin.SoShapeHintsElement.COUNTERCLOCKWISE
            sh.faceType = coin.SoShapeHintsElement.UNKNOWN_FACE_TYPE
            n.addChild(sh)

            if fluxmap:
                # It works using n0 instead of n here but I have absolutely not clue why.
                norm = colors.Normalize(vmin=vmin, vmax=vmax)
                M = cm.ScalarMappable(norm=norm, cmap=cm.viridis)
                colormap = M.to_rgba(flux[m])
                mat = coin.SoMaterial()
                mat.ambientColor = (1, 1, 1)
                mat.diffuseColor.setValues(0, colormap.shape[0], colormap)
                if trans == True:
                    mat.transparency.setValues(0, colormap.shape[0],
                                               1. - flux[m] / N.amax(flux[m]))
                n0.addChild(mat)

                mymatbind = coin.SoMaterialBinding()
                mymatbind.value = coin.SoMaterialBinding.PER_FACE
                n0.addChild(mymatbind)

            n0.addChild(n)

        return n0