Esempio n. 1
0
    def operateInternal(self):
        # Access the mesh and filename from the parameters
        mesh = smtk.mesh.Component.CastTo(
            self.parameters().associations().objectValue(0)).mesh()
        filename = self.parameters().find('filename').value(0)

        # Collect point coordinates
        coords = []

        class GetPoints(smtk.mesh.PointForEach):

            def __init__(self):
                smtk.mesh.PointForEach.__init__(self)

            def forPoints(self, pointIds, xyz, doModify):
                for pId in range(pointIds.size()):
                    coords.insert(pId, [xyz[3 * pId + i] for i in range(3)])

        getPoints = GetPoints()
        smtk.mesh.for_each(mesh.points(), getPoints)

        # Collect triangles
        tris = []

        class GetTriangles(smtk.mesh.CellForEach):

            def __init__(self):
                smtk.mesh.CellForEach.__init__(self, False)

            def forCell(self, cellId, cellType, numPoints):
                if numPoints == 3:
                    tris.append(
                        [mesh.points().find(self.pointId(i)) for i in range(numPoints)])

        getTriangles = GetTriangles()
        smtk.mesh.for_each(mesh.cells(), getTriangles)

        # Construct a pyplot, populate it with the triangles and color it by the
        # z-coordinate of the mesh
        fig1, ax1 = plt.subplots()
        ax1.set_aspect('equal')
        tcf = ax1.tricontourf([c[0] for c in coords], [c[1]
                                                       for c in coords], tris, [c[2] for c in coords])
        fig1.colorbar(tcf)
        plt.title('Mesh Elevation')
        plt.xlabel('X (units)')
        plt.ylabel('Y (units)')

        # Save the resulting image to the user-defined filename
        plt.savefig(filename, bbox_inches='tight')

        # Return with success
        result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED)
        return result
Esempio n. 2
0
    def operateInternal(self):
        # Access the mesh and filename from the specification
        mesh = self.specification().findMesh('mesh').value(0)
        filename = self.specification().findFile('filename').value(0)

        # Collect point coordinates
        coords = []

        class GetPoints(smtk.mesh.PointForEach):
            def __init__(self):
                smtk.mesh.PointForEach.__init__(self)

            def forPoints(self, pointIds, xyz, doModify):
                for pId in xrange(pointIds.size()):
                    coords.insert(pId, [xyz[3 * pId + i] for i in xrange(3)])

        getPoints = GetPoints()
        smtk.mesh.for_each(mesh.points(), getPoints)

        # Collect triangles
        tris = []

        class GetTriangles(smtk.mesh.CellForEach):
            def __init__(self):
                smtk.mesh.CellForEach.__init__(self, False)

            def forCell(self, cellId, cellType, numPoints):
                if numPoints == 3:
                    tris.append([
                        mesh.points().find(self.pointId(i))
                        for i in xrange(numPoints)
                    ])

        getTriangles = GetTriangles()
        smtk.mesh.for_each(mesh.cells(), getTriangles)

        # Construct a pyplot, populate it with the triangles and color it by the
        # z-coordinate of the mesh
        plt.figure(figsize=(3, 2), dpi=100)
        plt.tricontourf([c[0] for c in coords], [c[1] for c in coords], tris,
                        [c[2] for c in coords])
        plt.colorbar()
        plt.title('Mesh Elevation')
        plt.xlabel('X (units)')
        plt.ylabel('Y (units)')

        # Save the resulting image to the user-defined filename
        plt.savefig(filename, bbox_inches='tight')

        # Return with success
        result = self.createResult(smtk.model.OPERATION_SUCCEEDED)
        return result
Esempio n. 3
0
    def operateInternal(self):
        # Access the mesh and filename from the parameters
        mesh = self.parameters().find('mesh').value(0)
        filename = self.parameters().find('filename').value(0)

        # Collect point coordinates
        coords = []

        class GetPoints(smtk.mesh.PointForEach):

            def __init__(self):
                smtk.mesh.PointForEach.__init__(self)

            def forPoints(self, pointIds, xyz, doModify):
                for pId in range(pointIds.size()):
                    coords.insert(pId, [xyz[3 * pId + i] for i in range(3)])

        getPoints = GetPoints()
        smtk.mesh.for_each(mesh.points(), getPoints)

        # Collect triangles
        tris = []

        class GetTriangles(smtk.mesh.CellForEach):

            def __init__(self):
                smtk.mesh.CellForEach.__init__(self, False)

            def forCell(self, cellId, cellType, numPoints):
                if numPoints == 3:
                    tris.append(
                        [mesh.points().find(self.pointId(i)) for i in range(numPoints)])

        getTriangles = GetTriangles()
        smtk.mesh.for_each(mesh.cells(), getTriangles)

        # Construct a pyplot, populate it with the triangles and color it by the
        # z-coordinate of the mesh
        plt.figure(figsize=(3, 2), dpi=100)
        plt.tricontourf([c[0] for c in coords], [c[1]
                        for c in coords], tris, [c[2] for c in coords])
        plt.colorbar()
        plt.title('Mesh Elevation')
        plt.xlabel('X (units)')
        plt.ylabel('Y (units)')

        # Save the resulting image to the user-defined filename
        plt.savefig(filename, bbox_inches='tight')

        # Return with success
        result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED)
        return result
Esempio n. 4
0
 def forCell(self, cellId, cellType, numPoints):
     if numPoints == 3:
         tris.append(
             [mesh.points().find(self.pointId(i)) for i in range(numPoints)])
Esempio n. 5
0
 def forCell(self, cellId, cellType, numPoints):
     if numPoints == 3:
         tris.append(
             [mesh.points().find(self.pointId(i)) for i in range(numPoints)])