VTK将vtkChartXY放在多数据上(Python)

时间:2018-06-27 15:34:12

标签: python pyqt vtk

我正在尝试在表示2D网格的vtkPolydata对象后面实现网格线,因此最终用户可以更轻松地看到其尺寸。我设法使用vtkChartXY实现了网格线,但是我不知道如何将网格线的原点设置在vtkPolyData对象的中心,以及如何使网格线出现在Object之前而不是之后像这样:

meshGridLine

这是我用来制作网格线的代码:

    def openGL_Design(self):

        self.chart = vtk.vtkChartXY()
        self.plot = vtk.vtkPlotPoints()
        self.chart.AddPlot(self.plot)

        self.view = vtk.vtkContextActor()
        self.view.GetScene().AddItem(self.chart)

        #Create a Window interactor using the central frame object from Qt
        self.vtkDesign = QVTKRenderWindowInteractor(self.centralFrame)
        self.vl = Qt.QVBoxLayout()
        self.vl.setContentsMargins(0, 0, 0, 0)
        self.vl.setSpacing(0)              
        self.vl.addWidget(self.vtkDesign)

        #Create a renderer and add it to the window
        self.renDesign = vtk.vtkRenderer()
        self.vtkDesign.GetRenderWindow().AddRenderer(self.renDesign)
        self.renDesign.SetBackground(.85, .85, .85) 
        self.irenDesign = self.vtkDesign.GetRenderWindow().GetInteractor()


        #Set a dummy actor so i don't end up with repeated meshes
        self.MeshActor = vtk.vtkActor()
        self.centroidActor = vtk.vtkActor()
        self.renDesign.AddActor(self.view)
        self.renDesign.AddActor(self.MeshActor)
        self.renDesign.AddActor(self.centroidActor)

        self.centralFrame.setLayout(self.vl)

        self.show()
        self.irenDesign.Initialize()
        self.irenDesign.Start()

这是我用来制作“ Mesh Actor”的代码

def addVisual_Mesh(self):

    self.renDesign.RemoveActor(self.MeshActor) #Removes the old actor

    def mkVtkIdList(it):
        vil = vtk.vtkIdList()
        for i in it:
            vil.InsertNextId(int(i))
        return vil

    colors = vtk.vtkNamedColors() 

    #Array of vectors containing the coordinates of each point
    nodes = self.Results.nodes

    #Array of tuples containing the nodes correspondent of each element
    elements = self.Results.elements

    #Make the building blocks of polyData attributes
    Mesh = vtk.vtkPolyData()
    Points = vtk.vtkPoints()
    Cells = vtk.vtkCellArray()  

    #Load the point and cell's attributes
    for i in range(self.Results.numNodes):
        Points.InsertPoint(i, nodes[i])

    for i in range(self.Results.numElements):
        Cells.InsertNextCell(mkVtkIdList(elements[i]))

    #Assign pieces to vtkPolyData
    Mesh.SetPoints(Points)
    Mesh.SetPolys(Cells)

    #Mapping the whole thing
    MeshMapper = vtk.vtkPolyDataMapper()
    if vtk.VTK_MAJOR_VERSION <= 5:
        MeshMapper.SetInput(Mesh)
    else:
        MeshMapper.SetInputData(Mesh)

    #Create an actor
    self.MeshActor = vtk.vtkActor() 
    self.MeshActor.SetMapper(MeshMapper)
    #self.MeshActor.GetProperty().EdgeVisibilityOn()
    self.MeshActor.GetProperty().SetColor(colors.GetColor3d("Red"))
    #self.MeshActor.GetProperty().SetEdgeColor(colors.GetColor3d("Black"))

    self.renDesign.AddActor(self.MeshActor)

    #Camera Stuff
    camera = vtk.vtkCamera()
    camera.SetPosition(1,1,1000000)
    camera.SetFocalPoint(0,0,0)

    self.renDesign.SetActiveCamera(camera)
    self.renDesign.ResetCamera()

    self.vtkDesign.SetInteractorStyle(self.Interactor2D())

如果有人可以帮助我,我将不胜感激!预先感谢!

0 个答案:

没有答案