[vtkusers] Use transfer function editors from Python?
Elvis Stansvik
elvis.stansvik at orexplore.com
Mon May 23 09:42:39 EDT 2016
2016-05-23 15:38 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
> 2016-05-23 15:35 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
>
>> 2016-04-15 18:54 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
>>
>>> 2016-04-15 18:51 GMT+02:00 Cory Quammen <cory.quammen at kitware.com>:
>>>
>>>> On Fri, Apr 15, 2016 at 11:46 AM, Elvis Stansvik
>>>> <elvis.stansvik at orexplore.com> wrote:
>>>> > 2016-04-15 16:36 GMT+02:00 Elvis Stansvik <
>>>> elvis.stansvik at orexplore.com>:
>>>> >>
>>>> >> 2016-04-15 16:09 GMT+02:00 Cory Quammen <cory.quammen at kitware.com>:
>>>> >>>
>>>> >>> Hi Elvis,
>>>> >>>
>>>> >>> Have a look at
>>>> >>>
>>>> >>>
>>>> >>>
>>>> http://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Charts/Core/Testing/Cxx/TestScalarsToColors.cxx
>>>> >>>
>>>> >>> for an example of how to set up the transfer function editors used
>>>> in
>>>> >>> ParaView.
>>>> >>>
>>>> >>> You can eliminate the check at the end for
>>>> vtkOpenGL2ContextDevice2D -
>>>> >>> make sure to initialize and start the interactor, though.
>>>> >>>
>>>> >>> I don't see anything in this example that won't work in Python - if
>>>> >>> there is, please report back any problems you encounter.
>>>> >>
>>>> >>
>>>> >> Excellent, thanks a lot. I'll report back how it went.
>>>> >
>>>> >
>>>> > Worked like a charm :) It's not quite the same as the editors in
>>>> ParaView
>>>> > though. In ParaView, the opacity and color transfer functions are
>>>> edited
>>>> > separately, like this:
>>>> >
>>>> > https://blog.kitware.com/blog/files/48_1536770536.png
>>>> >
>>>> > Do you know if it's possible to get that kind of editing through VTK
>>>> > classes, with the color transfer function edited using a gradient
>>>> editor
>>>> > below and the X/Y editor only for the the opacity transfer function,
>>>> or is
>>>> > ParaView doing something custom here?
>>>>
>>>> Yes. You can use a vtkPiecewiseFunctionItem and
>>>> vtkPiecewiseControlePointsItem to edit the opacity function and a
>>>> vtkColorTransferFunctionItem and a vtkColorTransferControlPointsItem
>>>> to edit the color transfer function. These can be displayed in two
>>>> separate widgets, much like ParaView does. In each widget, you can
>>>> have a vtkContextView. This is probably the easiest implementation for
>>>> what you are after.
>>>>
>>>
>>> Ah, excellent. Thanks. It was the vtkPiecewiseFunctionItem I was
>>> missing. Was searching for something called "opacity" or somesuch, but
>>> makes sense it's just a general piecewise function editor class.
>>>
>>
>> Had to take a long break from this particular task, but now I'm back.
>>
>> I have a short and hopefully simple question about the above: When you say
>>
>> "In each widget, you can have a vtkContextView."
>>
>> I'm not quite sure how I add a vtkContextView to my widget
>> (QVTKRenderWindowInteractor). I mean, how I establish a link between them.
>>
>> Should I
>>
>> * Set the render window of the context view to the render window of the
>> QVTKRenderWindowInteractor using SetRenderView(...)?
>> * Get the renderer of the context view with GetRenderer() and add it to
>> the render window of the QVTKRenderWindowInteractor using AddRenderer(...)?
>> * Something else?
>>
>
> Another question that comes up is if I need to set the interactor of the
> context view to the QVTKRenderWindowInteractor using SetInteractor for the
> interaction to work?
>
Ah, I think I found the answer to both questions in vtkRenderViewBase
(which vtkContextView inherit):
"In order to use the view with a QVTKWidget the following code is required
to ensure the interactor and render window are initialized properly.
QVTKWidget *widget = new QVTKWidget;
vtkContextView *view = vtkContextView::New();
view->SetInteractor(widget->GetInteractor());
widget->SetRenderWindow(view->GetRenderWindow());"
So I'll give that a try. Sorry for the noise.
Of course interested in if there are any other (undocumented) gotchas here.
Elvis
>
> Elvis
>
>
>> Sorry if this is obvious, but it's a little hard to navigate the VTK
>> classes and figure out how they are to be used together :)
>>
>> Thanks in advance,
>> Elvis
>>
>>
>>> Elvis
>>>
>>>
>>>> Cory
>>>>
>>>> > (I the class vtkCompositeTransferFunctionItem has "composite" in its
>>>> name
>>>> > precisely because it provides editing of both color/opacity in the
>>>> same
>>>> > editor, while I would like the separated approach that ParaView has.)
>>>> >
>>>> > Elvis
>>>> >
>>>> >>
>>>> >> Elvis
>>>> >>
>>>> >>>
>>>> >>>
>>>> >>> HTH,
>>>> >>> Cory
>>>> >>>
>>>> >>> On Fri, Apr 15, 2016 at 8:54 AM, Elvis Stansvik
>>>> >>> <elvis.stansvik at orexplore.com> wrote:
>>>> >>> > Hi all,
>>>> >>> >
>>>> >>> > I'd like to use the transfer function editors that VTK seems to
>>>> provide
>>>> >>> > (used by e.g. Paraview) from Python. Is it possible?
>>>> >>> >
>>>> >>> > Looking at
>>>> >>> >
>>>> >>> >
>>>> http://www.vtk.org/pipermail/vtkusers/2013-December/082410.html
>>>> >>> >
>>>> >>> > I read the slightly worrying:
>>>> >>> >
>>>> >>> > "[...] Save/restore state and python interface are not
>>>> working as
>>>> >>> > expected. [...]"
>>>> >>> >
>>>> >>> > Though that was an old message when the new editors were first
>>>> >>> > introduced in
>>>> >>> > 2013. Is it still the case that the Python interface for the
>>>> editor
>>>> >>> > classes
>>>> >>> > is not working as expected?
>>>> >>> >
>>>> >>> > Does anyone know of a Python application/example that makes use
>>>> of the
>>>> >>> > editors? (I'm using VTK 6.2 and PyQt 5.5.1).
>>>> >>> >
>>>> >>> > Thanks,
>>>> >>> > Elvis
>>>> >>> >
>>>> >>> > _______________________________________________
>>>> >>> > 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:
>>>> >>> > http://public.kitware.com/mailman/listinfo/vtkusers
>>>> >>> >
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> --
>>>> >>> Cory Quammen
>>>> >>> R&D Engineer
>>>> >>> Kitware, Inc.
>>>> >>
>>>> >>
>>>> >
>>>>
>>>>
>>>>
>>>> --
>>>> Cory Quammen
>>>> R&D Engineer
>>>> Kitware, Inc.
>>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160523/223d6169/attachment.html>
More information about the vtkusers
mailing list