VTK centering vtkChartXY on polydata (Python)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

VTK centering vtkChartXY on polydata (Python)

mafiaskafia
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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK centering vtkChartXY on polydata (Python)

Slaughter, Andrew E
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 <[hidden email]> 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=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC4NFNnqRhnEbPw&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=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC4NFNnqRhnEbPw&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=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC4NFNnqRhnEbPw&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=BABQFHs0jxxGdf8nxpi7I3bDZRMpEC4NFNnqRhnEbPw&s=9EGrEaOM2rmrlz4QHDkxZHSjgJLH5GuUVSq3r3ENNKA&e=


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK centering vtkChartXY on polydata (Python)

mafiaskafia
Thank you for your quick answer! But by creating two different layers, how
can i "connect" the gridline with the vtkPolyData? For example, if i have a
2x2 square with its center on coordinates (0,0), how can i set the origin of
the gridline to be on the center of the square? So that the range of the
values on the gridline match the dimensions of the rectangle.

Cheers!



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK centering vtkChartXY on polydata (Python)

Slaughter, Andrew E
I don't know the answer to that question, it likely depends on the type of interactor you are using. It is possible to use the same camera across renderers, which might help.

On Wed, Jun 27, 2018 at 10:01 AM, mafiaskafia <[hidden email]> wrote:
Thank you for your quick answer! But by creating two different layers, how
can i "connect" the gridline with the vtkPolyData? For example, if i have a
2x2 square with its center on coordinates (0,0), how can i set the origin of
the gridline to be on the center of the square? So that the range of the
values on the gridline match the dimensions of the rectangle.

Cheers!



--
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=2j4g900IFL_D3AFivfPLbqkz65XqiD76ofQ-AO7mp6A&s=PiR0q-NraMaKXLlI5gcIo1S-iHIxX2PMBzcRSSybil8&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=2j4g900IFL_D3AFivfPLbqkz65XqiD76ofQ-AO7mp6A&s=0yZJ-A6Cm4u6-iPBwiomU3Yr9xTU4BB7ThiHLRES-fE&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=2j4g900IFL_D3AFivfPLbqkz65XqiD76ofQ-AO7mp6A&s=F57D8uGRwGw2zhpdZZdyZLl32xobvQYaoCIelDkvBZ8&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=2j4g900IFL_D3AFivfPLbqkz65XqiD76ofQ-AO7mp6A&s=qjfhihukNZPudwgRmP2KYmUy8mZVMLCmn2OdgvC8JFM&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=2j4g900IFL_D3AFivfPLbqkz65XqiD76ofQ-AO7mp6A&s=3-Xjzxou3AIXREldNVxDE9bGCFGmKPiCEKW_UzPzVWY&e=


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK centering vtkChartXY on polydata (Python)

mafiaskafia
ok, thanks anyway!



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers