[vtkusers] VTK centering vtkChartXY on polydata (Python)
mafiaskafia
tsilveira1993 at gmail.com
Wed Jun 27 11:37:01 EDT 2018
I'm trying to implement a gridline behind a vtkPolydata Object that
represents a 2D mesh, so it's easier for the end-user to see it's
dimensions. I managed to implement a gridline using vtkChartXY, but i
couldn't figure out how i could set the origin of the gridline to be on the
center of the vtkPolyData object, and also how i could make the gridline
appear before the Object and not after like this:
<http://vtk.1045678.n5.nabble.com/file/t342418/halppp.png>
This is the code i used to make the gridline:
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()
And this is the code i used to make the "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())
I would be very appreciated if anyone could help me out! Thanks in advance!
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list