Exemplo n.º 1
0
    def get_scene_graph(self, resolution=None):
        """
        Any object that provides a nice QuadMesh from the previous code should be able to render in Coin3D with with the following...

        Prefer to allow objects to calculate a 'suitable' resolution based on size.
        """
        n = coin.SoSeparator()
        X, Y, Z = self.mesh(resolution)
        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)

        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)

        qm = coin.SoQuadMesh()
        qm.verticesPerRow = nc
        qm.verticesPerColumn = nr
        n.addChild(qm)
        return n
Exemplo n.º 2
0
def simple_quad_mesh(points, num_u, num_v, colors=None):
    msh_sep = coin.SoSeparator()
    msh = coin.SoQuadMesh()
    vertexproperty = coin.SoVertexProperty()
    vertexproperty.vertex.setValues(0, len(points), points)
    msh.verticesPerRow = num_u
    msh.verticesPerColumn = num_v
    if colors:
        vertexproperty.materialBinding = coin.SoMaterialBinding.PER_VERTEX
        for i in range(len(colors)):
            vertexproperty.orderedRGBA.set1Value(
                i,
                coin.SbColor(colors[i]).getPackedValue())
    msh.vertexProperty = vertexproperty

    shape_hint = coin.SoShapeHints()
    shape_hint.vertexOrdering = coin.SoShapeHints.COUNTERCLOCKWISE
    shape_hint.creaseAngle = np.pi / 3
    msh_sep += [shape_hint, msh]
    return msh_sep
Exemplo n.º 3
0
                   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
myQuadMesh.verticesPerColumn = v_dess

result += myQuadMesh

import FreeCADGui
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
sg += result
Exemplo n.º 4
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