[vtkusers] SetInputData migration VTK 6

Laurent Chauvin lchauvin at bwh.harvard.edu
Tue Jul 22 21:08:48 EDT 2014


Oh okay, this is what I tought.

Thank you very much for your explanations.
-Laurent


On Tue, Jul 22, 2014 at 8:50 PM, Berk Geveci <berk.geveci at kitware.com>
wrote:

> Ah, this is a bug but would have been in the old pipeline too. The key is
> that tubeFilter->GetOutput() will always return the same object (there are
> some exception but they require low level manipulation of tubeFilter). So
> during the Update(), the mrmlNode1 polydata will be modified.
> Furthermore, mrmlNode2 will always point to the same object. If you want
> to preserve the output of a filter even after it executes, you need to copy
> it to another object. Something like this:
>
> splineFilter->SetInputData(polydata)
> tubeFilter->SetInputConnection(splineFilter->GetOutputPort())
>
> vtkPolyData* pd = vtkPolyData::New();
> pd->ShallowCopy(tubeFilter->GetOutput())
> mrmlNode1->SetAndObservePolyData(pd)
>
> Best,
> -berk
>
>
> On Tue, Jul 22, 2014 at 8:40 PM, Laurent Chauvin <lchauvin at bwh.harvard.edu
> > wrote:
>
>> Thank you Berk for your answer.
>>
>> My polydata is not an output of a filter, it's a stand-alone object, that
>> I modify myself directly.
>>
>> So what would happen if I had something like this:
>>
>> polydata = vtk.vtkPolyData()
>>
>> splineFilter->SetInputData(polydata)
>> tubeFilter->SetInputConnection(splineFilter->GetOutputPort())
>>
>> mrmlNode1->SetAndObservePolyData(tubeFilter->GetOutput())
>>
>> //modify polydata
>> splineFilter->Update()
>> tubeFilter->Update() (I don't know if this one is necessary of if
>> Updating splineFilter will automatically trigger an update of tubeFilter)
>>
>> mrmlNode2->SetAndObservePolyData(tubeFilter->GetOuput())
>>
>>
>> My understanding was as splineFilter has been updated after getting the
>> output of tube filter for mrmlNode1, mrmlNode1 and mrmlNode2 should be
>> different.
>> However, it seems that it's not the case. As they both observe the output
>> of tubeFilter, when I update tubeFilter, it modifies polydata of mrmlNode1
>> and mrmlNode2.
>>
>> Is it correct ?
>>
>> Thank you very much.
>> -Laurent
>>
>>
>>
>>
>> On Tue, Jul 22, 2014 at 8:10 PM, Berk Geveci <berk.geveci at kitware.com>
>> wrote:
>>
>>> It is correct that SetInputData() does not connect the pipeline. To be
>>> more specific, consider 2 examples:
>>>
>>> 1)
>>>
>>> polydata = someFilter->GetOutput();
>>>
>>> anotherFilter->SetInputData(polydata)
>>> anotherFilter->Update();
>>>
>>> someFilter->Modified();
>>> anotherFilter->Update();
>>>
>>> Update() would not propagate a pipeline request to someFilter. So the
>>> output of anotherFilter will not change between the 2 Update() calls.
>>>
>>> 2)
>>>
>>> polydata = giveMePolyData();
>>>
>>> anotherFilter->SetInputData(polydata)
>>> anotherFilter->Update();
>>>
>>> // modify the polydata somehow
>>> polydata->Modified();
>>>
>>> anotherFilter->Update();
>>>
>>> In this case, because the polydata changed, the second Update() will
>>> actually have an effect and the output of anotherFilter will change after
>>> the 2nd Update.
>>>
>>>
>>> So the change to your code will depend on the nature of "polydata". Is
>>> it still the output of a filter? Then you must use SetInputConnection().
>>> Unfortunately, this sometimes means that you need to change function
>>> signatures to pass an (algorithm, port index) pair around instead of a data
>>> object.
>>>
>>> If polydata is a stand-alone data object that is modified directly by
>>> some code and as a result its mtime is updated, you can use SetInputData().
>>> Keep in mind that the producer of the data object is now completely out of
>>> the pipeline and will not see any pipeline updates.
>>>
>>> I don't know the details of how data is stored in MRML. If you add a
>>> polydata to a MRML node and expect it to represent the output port of a
>>> filter such that you can do this:
>>>
>>> vtkMRMLModelNode->SetAndObservePolyData(vtkTubeFilter->GetOutput())
>>>
>>> vtkTubeFilter->SetSomething();
>>>
>>> polydata = get_MRML_node_somehow();
>>> polydata->Update(); // should cause vtkTubeFilter to re-execute
>>>
>>> The MRML code will have to change to store the algorithm and output port
>>> index instead. There is no longer any way to get from a data object to its
>>> producer. In fact, vtkDataObject is now in a module (library) that doesn't
>>> know anything about algorithms or pipelines.
>>>
>>> Best,
>>> -berk
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Jul 22, 2014 at 7:07 PM, Laurent Chauvin <
>>> lchauvin at bwh.harvard.edu> wrote:
>>>
>>>> Hi Sam,
>>>>
>>>> Thank you for your answer.
>>>>
>>>> Here is my pipeline (just an overview):
>>>>
>>>> vtkSplineFilter->SetInputData(polydata)
>>>>
>>>> vtkTubeFilter->SetInputConnection(vtkSplineFilter->GetOutputPort())
>>>>
>>>> vtkMRMLModelNode->SetAndObservePolyData(vtkTubeFilter->GetOutput())
>>>>
>>>> I would like to have one vtkMRMLModelNode with one polydata.
>>>> The problem if I do what you suggested, is all my vtkMRMLModelNodes are
>>>> gonna observe TubeFilter. So when I will modify my polydata and call
>>>> vtkSplineFilter->Update() and vtkTubeFilter->Update(), all my
>>>> vtkMRMLModelNodes will be updated, but I only want the last one to be.
>>>> Should I do a copy of the output of vtkTubeFilter instead ? to avoid
>>>> they all change when I update the TubeFilter ?
>>>>
>>>> Thank you.
>>>> -Laurent
>>>>
>>>>
>>>>
>>>> On Tue, Jul 22, 2014 at 7:02 PM, Sam Raby <rabysam28 at gmail.com> wrote:
>>>>
>>>>> Hi Laurent,
>>>>>
>>>>> After feeding the vtkPolyData into the vtkSplineFilter by SetInputData
>>>>> and setting the parameters of the filter, did you try to manually update
>>>>> the vtkSplineFilter?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Jul 22, 2014 at 4:55 PM, Laurent Chauvin <
>>>>> lchauvin at bwh.harvard.edu> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I created a pipeline with a vtkSplineFilter, with a polydata as input.
>>>>>>  However, now that I try to make it compatible with VTK 6, it's not
>>>>>> working anymore.
>>>>>>
>>>>>> I replaced SetInput by SetInputData, and I read that SetInputData
>>>>>> doesn't create the pipeline. That's probably why now, when I update my
>>>>>> polydata, it's not updating the spline.
>>>>>> But I was wondering then how should I do to keep creating the
>>>>>> pipeline then ?
>>>>>>
>>>>>> I read to use SetInputConnection, but I think SetInputConnection take
>>>>>> as argument the OutputPort of another filter, but the spline is the 'entry
>>>>>> point' of my pipeline, taking a polydata as input, and applying some
>>>>>> filters on it.
>>>>>>
>>>>>> How could I do to update the pipeline when modifying the polydata ?
>>>>>>
>>>>>> Thank you.
>>>>>> -Laurent
>>>>>>
>>>>>> --
>>>>>> Laurent Chauvin, MS
>>>>>> Surgical Navigation and Robotics Laboratory, Radiology Department
>>>>>> Brigham And Women's Hospital, Harvard Medical School
>>>>>> http://wiki.ncigt.org/index.php/User:Lchauvin
>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>>>>>
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>>>
>>>>>>
>>>>>  The information in this e-mail is intended only for the person to
>>>>> whom it is
>>>>> addressed. If you believe this e-mail was sent to you in error and the
>>>>> e-mail
>>>>> contains patient information, please contact the Partners Compliance
>>>>> HelpLine at
>>>>> http://www.partners.org/complianceline . If the e-mail was sent to
>>>>> you in error
>>>>> but does not contain patient information, please contact the sender
>>>>> and properly
>>>>> dispose of the e-mail.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Laurent Chauvin, MS
>>>> Surgical Navigation and Robotics Laboratory, Radiology Department
>>>> Brigham And Women's Hospital, Harvard Medical School
>>>> http://wiki.ncigt.org/index.php/User:Lchauvin
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>
>>>>
>>>
>>
>>
>> --
>> Laurent Chauvin, MS
>> Surgical Navigation and Robotics Laboratory, Radiology Department
>> Brigham And Women's Hospital, Harvard Medical School
>> http://wiki.ncigt.org/index.php/User:Lchauvin
>>
>
>


-- 
Laurent Chauvin, MS
Surgical Navigation and Robotics Laboratory, Radiology Department
Brigham And Women's Hospital, Harvard Medical School
http://wiki.ncigt.org/index.php/User:Lchauvin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140722/c04196b9/attachment.html>


More information about the vtkusers mailing list