[vtkusers] Display different ImageData Scalar to different Viewport

Ruben Di Battista rubendibattista at gmail.com
Fri Jun 1 09:53:17 EDT 2018


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 <david.gobbi at gmail.com> 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 <
> rubendibattista at gmail.com> 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
    ,.,    |∞∞∞∞∞∞
  .'   '.  |∞∞∞∞
-'       `'
http://rdb.is
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180601/8e160aab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sphere.py
Type: text/x-python
Size: 8682 bytes
Desc: not available
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180601/8e160aab/attachment.py>


More information about the vtkusers mailing list