Display different ImageData Scalar to different Viewport

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

Display different ImageData Scalar to different Viewport

Ruben Di Battista
Hello, 
I'm playing a bit with VTK and its Python bindings. I wrote down a simple case where I generate the distance function of a sphere, I extract the surface from it using the FlyingEdge3D algorithm, then I calculate the curvatures using the vtkCurvatures filter, and then I'd like to show the Mean_Curvature and the Gauss_Curvature in two different viewports. 

What I tried to do is to use the `SetActiveScalars` method of the `PointData` associated to my `ImageData` dataset, but at the end I get two Viewports showing the same scalar (the last one activated). I also tried to stop the program execution using a debugger and triggering the render before the second scalar is made "active", and it correctly shows the first scalar field. So It's like that the two mappers rendered are "linked". 

Do I need to do a ShallowCopy somewhere? 

Here below the `Sphere.show` method. The full code is attached. `self.surface` is an `ImageData` dataset. 

    def show(self):
        # Render Window
        rw = vtk.vtkRenderWindow()
        rw.SetSize(800, 800)

        # Defining Bounds of Viewports
        xmins = [0, 0.5]
        xmaxs = [0.5, 1]
        ymins = [0, 0]
        ymaxs = [1, 1]

        # Curvature Types
        curv_types = ['Mean_Curvature', 'Gauss_Curvature']

        for i in six.moves.range(2):
            render = vtk.vtkRenderer()
            rw.AddRenderer(render)

            # Mean Curvature View
            render.SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i])

            # Create mapper
            mapper = vtk.vtkPolyDataMapper()
            self.surface.GetPointData().SetActiveScalars(curv_types[i])
            mapper.SetInputData(self.surface)
            mapper.SetScalarRange(-1, 1)
            mapper.Update()

            # ColorBar
            color_bar = vtk.vtkScalarBarActor()
            color_bar.SetLookupTable(mapper.GetLookupTable())

            # Surface Actor
            actor = vtk.vtkActor()
            actor.SetMapper(mapper)
            actor.GetProperty().EdgeVisibilityOn()

            render.AddActor(actor)
            render.AddActor2D(color_bar)

        # Render Window Interactor
        rwi = vtk.vtkRenderWindowInteractor()
        rwi.SetRenderWindow(rw)

        rwi.Initialize()
        rwi.Start()


--
          _  
-.     .´  |∞∞∞∞
  ',  ;    |∞∞∞∞∞∞
    ˜˜     |∞∞∞∞∞∞∞∞∞ RdB 
    ,.,    |∞∞∞∞∞∞
  .'   '.  |∞∞∞∞
-'       `'


_______________________________________________
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

sphere.py (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Display different ImageData Scalar to different Viewport

David Gobbi
Hi Ruben,

Instead of data.SetActiveScalars(), use mapper.SetArrayId(i) or mapper.SetArrayName(name).

 - David


On Thu, May 31, 2018 at 8:57 AM, Ruben Di Battista <[hidden email]> wrote:
Hello, 
I'm playing a bit with VTK and its Python bindings. I wrote down a simple case where I generate the distance function of a sphere, I extract the surface from it using the FlyingEdge3D algorithm, then I calculate the curvatures using the vtkCurvatures filter, and then I'd like to show the Mean_Curvature and the Gauss_Curvature in two different viewports. 

What I tried to do is to use the `SetActiveScalars` method of the `PointData` associated to my `ImageData` dataset, but at the end I get two Viewports showing the same scalar (the last one activated). I also tried to stop the program execution using a debugger and triggering the render before the second scalar is made "active", and it correctly shows the first scalar field. So It's like that the two mappers rendered are "linked". 

Do I need to do a ShallowCopy somewhere? 


_______________________________________________
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: Display different ImageData Scalar to different Viewport

Ruben Di Battista
Hello David, 

thanks for your answer. 

I changed my `show` method like this: 

    def show(self):
        # Render Window
        rw = vtk.vtkRenderWindow()
        rw.SetSize(800, 800)

        # Defining Bounds of Viewports
        xmins = [0, 0.5]
        xmaxs = [0.5, 1]
        ymins = [0, 0]
        ymaxs = [1, 1]

        # Curvature Types
        curv_types = ['Mean_Curvature', 'Gauss_Curvature']

        for i in six.moves.range(2):

            render = vtk.vtkRenderer()
            rw.AddRenderer(render)

            # Mean Curvature View
            render.SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i])

            # Create mapper
            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInputData(self.surface)
            mapper.Update()  # Probably useless
            mapper.SetScalarRange(-1, 1)
            mapper.SetArrayName(curv_types[0])
            mapper.Update()

            # ColorBar
            color_bar = vtk.vtkScalarBarActor()
            color_bar.SetLookupTable(mapper.GetLookupTable())

            # Surface Actor
            actor = vtk.vtkActor()
            actor.SetMapper(mapper)
            actor.GetProperty().EdgeVisibilityOn()

            render.AddActor(actor)
            render.AddActor2D(color_bar)

            import ipdb
            ipdb.set_trace()

        # Render Window Interactor
        rwi = vtk.vtkRenderWindowInteractor()
        rwi.SetRenderWindow(rw)

        rwi.Initialize()
        rwi.Start()

but it's not working. 

Actually stopping the execution at the first iteration of the `for` loop, and then triggering rwi.Initialize() and rwi.Start() just after the first iteration still shows that the Mapper is rendering the last scalar added to the `PolyData` and not the one specified by `mapper.SetArrayName`.

In my previous email, at least, if I stopped the execution at the first iteration and then manually triggering the rendering, was correctly showing the first scalar (i.e. `Mean_Curvatures`).

I'm still attaching the complete example.

On Thu, May 31, 2018 at 10:07 PM David Gobbi <[hidden email]> wrote:
Hi Ruben,

Instead of data.SetActiveScalars(), use mapper.SetArrayId(i) or mapper.SetArrayName(name).

 - David


On Thu, May 31, 2018 at 8:57 AM, Ruben Di Battista <[hidden email]> wrote:
Hello, 
I'm playing a bit with VTK and its Python bindings. I wrote down a simple case where I generate the distance function of a sphere, I extract the surface from it using the FlyingEdge3D algorithm, then I calculate the curvatures using the vtkCurvatures filter, and then I'd like to show the Mean_Curvature and the Gauss_Curvature in two different viewports. 

What I tried to do is to use the `SetActiveScalars` method of the `PointData` associated to my `ImageData` dataset, but at the end I get two Viewports showing the same scalar (the last one activated). I also tried to stop the program execution using a debugger and triggering the render before the second scalar is made "active", and it correctly shows the first scalar field. So It's like that the two mappers rendered are "linked". 

Do I need to do a ShallowCopy somewhere? 



--
          _  
-.     .´  |∞∞∞∞
  ',  ;    |∞∞∞∞∞∞
    ˜˜     |∞∞∞∞∞∞∞∞∞ RdB 
    ,.,    |∞∞∞∞∞∞
  .'   '.  |∞∞∞∞
-'       `'


_______________________________________________
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

sphere.py (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Display different ImageData Scalar to different Viewport

David Gobbi
There might be other settings for the mapper that are needed in addition to SetArrayName().  Take a look at the docs for vtkMapper, it has lots of methods related to scalars.

On Fri, Jun 1, 2018 at 7:53 AM, Ruben Di Battista <[hidden email]> wrote:
Hello David, 

thanks for your answer. 

I changed my `show` method like this: 

    def show(self):
        # Render Window
        rw = vtk.vtkRenderWindow()
        rw.SetSize(800, 800)

        # Defining Bounds of Viewports
        xmins = [0, 0.5]
        xmaxs = [0.5, 1]
        ymins = [0, 0]
        ymaxs = [1, 1]

        # Curvature Types
        curv_types = ['Mean_Curvature', 'Gauss_Curvature']

        for i in six.moves.range(2):

            render = vtk.vtkRenderer()
            rw.AddRenderer(render)

            # Mean Curvature View
            render.SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i])

            # Create mapper
            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInputData(self.surface)
            mapper.Update()  # Probably useless
            mapper.SetScalarRange(-1, 1)
            mapper.SetArrayName(curv_types[0])
            mapper.Update()

            # ColorBar
            color_bar = vtk.vtkScalarBarActor()
            color_bar.SetLookupTable(mapper.GetLookupTable())

            # Surface Actor
            actor = vtk.vtkActor()
            actor.SetMapper(mapper)
            actor.GetProperty().EdgeVisibilityOn()

            render.AddActor(actor)
            render.AddActor2D(color_bar)

            import ipdb
            ipdb.set_trace()

        # Render Window Interactor
        rwi = vtk.vtkRenderWindowInteractor()
        rwi.SetRenderWindow(rw)

        rwi.Initialize()
        rwi.Start()

but it's not working. 

Actually stopping the execution at the first iteration of the `for` loop, and then triggering rwi.Initialize() and rwi.Start() just after the first iteration still shows that the Mapper is rendering the last scalar added to the `PolyData` and not the one specified by `mapper.SetArrayName`.

In my previous email, at least, if I stopped the execution at the first iteration and then manually triggering the rendering, was correctly showing the first scalar (i.e. `Mean_Curvatures`).

I'm still attaching the complete example.


_______________________________________________
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: Display different ImageData Scalar to different Viewport

Ruben Di Battista
Hello David, 
I reali lurked in the Classes reference and in the documentation and I cannot find a method to select which data array to plot in a PolyDataMapper. 

So just to resume for other readers: I have a PolyData object that stores two PointData Double Arrays. I would like to know how, once I set up the PolyDataMapper, I choose which of the two “scalars” I want to render in the RenderWindow. 

What I tried so far:
- polydata_object.GetPointData().SetActiveScalars(i)
- polydata_mapper_object.SetArrayName(array_names[i])
- polydata_mapper_object.ColorByArrayComponent(array_names[i], 0)  # This seems to be for vector fields

Thanks for your kind help, 

          _   
-.     .´  |∞∞∞∞
  ',  ;    |∞∞∞∞∞∞
    ˜˜     |∞∞∞∞∞∞∞∞∞ RdB
    ,.,    |∞∞∞∞∞∞
  .'   '.  |∞∞∞∞
-'       `’

http://rdb.is

On 1 giugno 2018 a 09:13:33, David Gobbi ([hidden email]) scritto:

There might be other settings for the mapper that are needed in addition to SetArrayName().  Take a look at the docs for vtkMapper, it has lots of methods related to scalars.

On Fri, Jun 1, 2018 at 7:53 AM, Ruben Di Battista <[hidden email]> wrote:
Hello David, 

thanks for your answer. 

I changed my `show` method like this: 

    def show(self):
        # Render Window
        rw = vtk.vtkRenderWindow()
        rw.SetSize(800, 800)

        # Defining Bounds of Viewports
        xmins = [0, 0.5]
        xmaxs = [0.5, 1]
        ymins = [0, 0]
        ymaxs = [1, 1]

        # Curvature Types
        curv_types = ['Mean_Curvature', 'Gauss_Curvature']

        for i in six.moves.range(2):

            render = vtk.vtkRenderer()
            rw.AddRenderer(render)

            # Mean Curvature View
            render.SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i])

            # Create mapper
            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInputData(self.surface)
            mapper.Update()  # Probably useless
            mapper.SetScalarRange(-1, 1)
            mapper.SetArrayName(curv_types[0])
            mapper.Update()

            # ColorBar
            color_bar = vtk.vtkScalarBarActor()
            color_bar.SetLookupTable(mapper.GetLookupTable())

            # Surface Actor
            actor = vtk.vtkActor()
            actor.SetMapper(mapper)
            actor.GetProperty().EdgeVisibilityOn()

            render.AddActor(actor)
            render.AddActor2D(color_bar)

            import ipdb
            ipdb.set_trace()

        # Render Window Interactor
        rwi = vtk.vtkRenderWindowInteractor()
        rwi.SetRenderWindow(rw)

        rwi.Initialize()
        rwi.Start()

but it's not working. 

Actually stopping the execution at the first iteration of the `for` loop, and then triggering rwi.Initialize() and rwi.Start() just after the first iteration still shows that the Mapper is rendering the last scalar added to the `PolyData` and not the one specified by `mapper.SetArrayName`.

In my previous email, at least, if I stopped the execution at the first iteration and then manually triggering the rendering, was correctly showing the first scalar (i.e. `Mean_Curvatures`).

I'm still attaching the complete example.


_______________________________________________
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