Quantcast

Re: [vtk-developers] With VTK >= 6, how to "choose" between SetInputData() or SetInputConnection() ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [vtk-developers] With VTK >= 6, how to "choose" between SetInputData() or SetInputConnection() ?

Moreland, Kenneth
(Forwarding to vtk-users mailing list as this question is more appropriate there.)

With VTK >= 6, you should always prefer B->SetInputConnection(A->GetOutputPort()).

The SetInputData() method on vtkAlgorithm is mostly provided for backward compatibility. Internally, it is going to find the producer of the data set and then call SetInputConnection for the output port producing the data set. But SetInputConnection is preferred because it makes the pipeline connections more explicit.

The only reason to use SetInputData now is when you have a data set that you have created outside the pipeline. This is the case in the code you presented below with the spGrid object. Internally VTK will create a trivial producer object to be the connection in the pipeline, but doing that yourself is cumbersome.

The reason why the second example is giving a compile error is that spGrid (a vtkUnstructuredGrid) does not have a GetOutputPort() method because it is a data set, not a pipeline object.

-Ken

-----Original Message-----
From: vtk-developers [mailto:[hidden email]] On Behalf Of houssen
Sent: Wednesday, April 12, 2017 9:09 AM
To: [hidden email]
Subject: [EXTERNAL] [vtk-developers] With VTK >= 6, how to "choose" between SetInputData() or SetInputConnection() ?

With VTK >= 6, how to "choose" between SetInputData() or
SetInputConnection() ? How to know which one SHOULD be used ?

I read carefully this
http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput,
and, I digged several VTK examples
http://www.vtk.org/Wiki/VTK/Examples/Cxx... Lot of things clarified but I'am still confused in exercising this: I feel like I missed some major stuffs...

To make it quick, my understanding is that :
1. If I need B to be modified if A is changed, I NEED to do "B->SetInputConnection(A->GetOutputPort())".
2. Otherwise, "B->SetInputData(A)" is enough (A will be an input of B BUT no link will be set between A and B : changing A does not trigger update of B).

Up to here I guess (?) I'am right (at least for the big headlines)...
Stop me here if not !

Now, I want to have a source (grid) and I need to apply a filter on it.
Say that in a call back I modify the source: I want BOTH source and filter to be updated when call backs are modifying the source. Here is what I have:
vtkSmartPointer<vtkUnstructuredGrid> spGrid = vtkSmartPointer<vtkUnstructuredGrid>::New(); // Source // Fill the source with points and cells...
vtkSmartPointer<vtkVertexGlyphFilter> spVertexGlyphs = vtkSmartPointer<vtkVertexGlyphFilter>::New();
spVertexGlyphs->SetInputData(spGrid); // Case 2
vtkSmartPointer<vtkPolyDataMapper> spVertexGlyphMap = vtkSmartPointer<vtkPolyDataMapper>::New();
spVertexGlyphMap->SetInputConnection(spVertexGlyphs->GetOutputPort());
// Case 1 : the filter is updated if the source is modified.

This seems to works: the filter is updated if the source is modified.

But, this does NOT work: the source is NOT modified (= updated in the
VTK window) when the callback modify it (so the filter may OR NOT be
updated accordingly ?!).

I expected to be compelled to do:
vtkSmartPointer<vtkDataSetMapper> spGridMap =
vtkSmartPointer<vtkDataSetMapper>::New();
spGridMap->SetInputConnection(spGrid->GetOutputPort()); // Compilation
KO because there is not SetInputConnection or GetOutputPort ???
So I'am compelled to do (found lots of examples that do that):
spGridMap->SetInputData(spGrid);
... And I end up with a grid that does NOT update in the VTK window
when call back modify the source.
I found a way to update it: the callback modify the grid and, at the
end of the callback, I added "spGrid->Modified()", this triggers the
update of the source.

So basically, I did what I need ... But:
1. Is the "spGrid->Modified()" a hack ? Or is it the "right" way to do
? If yes, why (as it seems to bypass the update process) ?
2. Why is there no SetInputConnection on spGridMap ? Why is there no
GetOutputPort on vtkUnstructuredGrid ?

I just would like to understand the logic behind....

Franck
_______________________________________________
Powered by www.kitware.com

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

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [vtk-developers] With VTK >= 6, how to "choose" between SetInputData() or SetInputConnection() ?

Berk Geveci-2
> The SetInputData() method on vtkAlgorithm is mostly provided for backward compatibility. > Internally, it is going to find the producer of the data set and then call SetInputConnection > for the output port producing the data set. But SetInputConnection is preferred because it > makes the pipeline connections more explicit.

Actually, SetInputData() does not set a pipeline connection. The reason behind the API change was that data objects no longer store any information about their produces and hence it is not possible to create a pipeline connection when the only information provided is the data object itself.

So SetInputData() should be used when:

* assigning a stand-along data object as input to a filter,
* wanting to process a data object but not connect the filter to its producer.

The second use case comes handy when filters pass their input to internal filter chains. In the past, one would have to create a shallow copy to avoid pipeline connections. Now, SetInputData() can be used directly.

Best,
-berk

On Wed, Apr 12, 2017 at 11:41 AM, Moreland, Kenneth <[hidden email]> wrote:
(Forwarding to vtk-users mailing list as this question is more appropriate there.)

With VTK >= 6, you should always prefer B->SetInputConnection(A->GetOutputPort()).

The SetInputData() method on vtkAlgorithm is mostly provided for backward compatibility. Internally, it is going to find the producer of the data set and then call SetInputConnection for the output port producing the data set. But SetInputConnection is preferred because it makes the pipeline connections more explicit.

The only reason to use SetInputData now is when you have a data set that you have created outside the pipeline. This is the case in the code you presented below with the spGrid object. Internally VTK will create a trivial producer object to be the connection in the pipeline, but doing that yourself is cumbersome.

The reason why the second example is giving a compile error is that spGrid (a vtkUnstructuredGrid) does not have a GetOutputPort() method because it is a data set, not a pipeline object.

-Ken

-----Original Message-----
From: vtk-developers [mailto:[hidden email]] On Behalf Of houssen
Sent: Wednesday, April 12, 2017 9:09 AM
To: [hidden email]
Subject: [EXTERNAL] [vtk-developers] With VTK >= 6, how to "choose" between SetInputData() or SetInputConnection() ?

With VTK >= 6, how to "choose" between SetInputData() or
SetInputConnection() ? How to know which one SHOULD be used ?

I read carefully this
http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput,
and, I digged several VTK examples
http://www.vtk.org/Wiki/VTK/Examples/Cxx... Lot of things clarified but I'am still confused in exercising this: I feel like I missed some major stuffs...

To make it quick, my understanding is that :
1. If I need B to be modified if A is changed, I NEED to do "B->SetInputConnection(A->GetOutputPort())".
2. Otherwise, "B->SetInputData(A)" is enough (A will be an input of B BUT no link will be set between A and B : changing A does not trigger update of B).

Up to here I guess (?) I'am right (at least for the big headlines)...
Stop me here if not !

Now, I want to have a source (grid) and I need to apply a filter on it.
Say that in a call back I modify the source: I want BOTH source and filter to be updated when call backs are modifying the source. Here is what I have:
vtkSmartPointer<vtkUnstructuredGrid> spGrid = vtkSmartPointer<vtkUnstructuredGrid>::New(); // Source // Fill the source with points and cells...
vtkSmartPointer<vtkVertexGlyphFilter> spVertexGlyphs = vtkSmartPointer<vtkVertexGlyphFilter>::New();
spVertexGlyphs->SetInputData(spGrid); // Case 2
vtkSmartPointer<vtkPolyDataMapper> spVertexGlyphMap = vtkSmartPointer<vtkPolyDataMapper>::New();
spVertexGlyphMap->SetInputConnection(spVertexGlyphs->GetOutputPort());
// Case 1 : the filter is updated if the source is modified.

This seems to works: the filter is updated if the source is modified.

But, this does NOT work: the source is NOT modified (= updated in the
VTK window) when the callback modify it (so the filter may OR NOT be
updated accordingly ?!).

I expected to be compelled to do:
vtkSmartPointer<vtkDataSetMapper> spGridMap =
vtkSmartPointer<vtkDataSetMapper>::New();
spGridMap->SetInputConnection(spGrid->GetOutputPort()); // Compilation
KO because there is not SetInputConnection or GetOutputPort ???
So I'am compelled to do (found lots of examples that do that):
spGridMap->SetInputData(spGrid);
... And I end up with a grid that does NOT update in the VTK window
when call back modify the source.
I found a way to update it: the callback modify the grid and, at the
end of the callback, I added "spGrid->Modified()", this triggers the
update of the source.

So basically, I did what I need ... But:
1. Is the "spGrid->Modified()" a hack ? Or is it the "right" way to do
? If yes, why (as it seems to bypass the update process) ?
2. Why is there no SetInputConnection on spGridMap ? Why is there no
GetOutputPort on vtkUnstructuredGrid ?

I just would like to understand the logic behind....

Franck
_______________________________________________
Powered by www.kitware.com

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

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

_______________________________________________
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


_______________________________________________
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
Loading...