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

Moreland, Kenneth kmorel at sandia.gov
Wed Apr 12 11:41:41 EDT 2017


(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:vtk-developers-bounces at vtk.org] On Behalf Of houssen
Sent: Wednesday, April 12, 2017 9:09 AM
To: vtk-developers at vtk.org
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



More information about the vtkusers mailing list