[vtkusers] VTK centering vtkChartXY on polydata (Python)
Slaughter, Andrew E
andrew.slaughter at inl.gov
Wed Jun 27 11:45:23 EDT 2018
You can use two different vtkRenderer objects and use the "SetLayer" method
to control which appears on top. I think you will also need to set the
number of layers on the window: "vtkRenderWindow::SetNumberOfLayers".
On Wed, Jun 27, 2018 at 9:37 AM, mafiaskafia <tsilveira1993 at gmail.com>
wrote:
> 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:
>
> <https://urldefense.proofpoint.com/v2/url?u=http-
> 3A__vtk.1045678.n5.nabble.com_file_t342418_halppp.png&d=DwICAg&c=
> 54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_
> HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC
> 4NFNnqRhnEbPw&s=vxGxgaNCkxP5q-nzL5RyEEFVx71Cw5A3BQcU_P1qzmo&e=>
>
> 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: https://urldefense.proofpoint.com/v2/url?u=http-3A__vtk.
> 1045678.n5.nabble.com_VTK-2DUsers-2Df1224199.html&d=DwICAg&c=
> 54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_
> HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC
> 4NFNnqRhnEbPw&s=_rVA5V9ZjR6S9HFCvPDXsDZ6cPhFa29xy-q5fFR2VLE&e=
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at https://urldefense.proofpoint.
> com/v2/url?u=http-3A__www.kitware.com_opensource_
> opensource.html&d=DwICAg&c=54IZrppPQZKX9mLzcGdPfFD1hxrcB_
> _aEkJFOKJFd00&r=h7heP8xwI1i_HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=
> BABQFHs0jxxGdf8nxpi7I3bDZRMpEC4NFNnqRhnEbPw&s=
> IOBcMazQV0OuHRsveg0B4Cn1alnxvbDGoXyFRV7li48&e=
>
> Please keep messages on-topic and check the VTK FAQ at:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.vtk.
> org_Wiki_VTK-5FFAQ&d=DwICAg&c=54IZrppPQZKX9mLzcGdPfFD1hxrcB_
> _aEkJFOKJFd00&r=h7heP8xwI1i_HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=
> BABQFHs0jxxGdf8nxpi7I3bDZRMpEC4NFNnqRhnEbPw&s=X517J-49oSESWpkye-
> qXsuX6IDYPg7pG5WYSU-WU7Uk&e=
>
> Search the list archives at: https://urldefense.proofpoint.
> com/v2/url?u=http-3A__markmail.org_search_-3Fq-3Dvtkusers&d=DwICAg&c=
> 54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_
> HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC
> 4NFNnqRhnEbPw&s=Hp9usDPi61EkBCTLC8JtnDX3-Y-_ARqeNTA6xOAam28&e=
>
> Follow this link to subscribe/unsubscribe:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__public.
> kitware.com_mailman_listinfo_vtkusers&d=DwICAg&c=
> 54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_
> HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC
> 4NFNnqRhnEbPw&s=9EGrEaOM2rmrlz4QHDkxZHSjgJLH5GuUVSq3r3ENNKA&e=
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180627/1b0c3a00/attachment-0001.html>
More information about the vtkusers
mailing list