Multiple input data in custom vtkPolydataFilter

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple input data in custom vtkPolydataFilter

BBerco
Hello all,
I'm working on a filter that produces luminosity curves from shape models.
I'm trying to extend its capability to the case of multiple-body systems,
for instance that of a binary asteroid featuring a primary around which
orbits a secondary object.

To this end, I would need to allow my filter (inheriting from
vtkPolyDataAlgorithm) to take in multiple polydata inputs (one for each
body, with the first one being the primary, the second one the secondary (if
any),...).

I naively tried
*
myfilter-> SetInputData(0,primary_polydata)
myfilter-> SetInputData(1,secondary_polydata)
*

but the method which I think should return the number of inputs
(GetNumberOfInputPorts()) still returns 1. Obviously I'm being confused
between the number of inputs and the number of input ports.

This example
<https://www.vtk.org/Wiki/VTK/Examples/Cxx/Developers/MultipleInputPorts>  
presents another approach that is not as flexible as I would like because it
relies on* SetInputConnection* and not * SetInputData*.

Any advice?



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Multiple input data in custom vtkPolydataFilter

David Gobbi
Hi Ben,

The filter has to be set up the same way regardless of whether you
intend to use SetInputConnection() or SetInputData().   After all,
SetInputData() always calls SetInputConnection() under the hood.
So the example that you linked is the way to go.

It looks like you want the second input to be optional.  Since the
port exists whether or not an input has been connected to it, what
you need to do is check whether someone has connected an input
to the port.  This works regardless of whether the connection was
done with SetInputConnection() or with SetInputData():

  if (this->GetNumberOfInputConnections(1) != 0) { ... }


The filter itself must set the second port as "optional" when it sets
up the properties of the ports:

  int vtkMyMultiInputFilter::FillInputPortInformation(int port, vtkInformation* info)
  {
    if (port == 0)
    {
      info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
    }
    else if (port == 1)
    {
      info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
      info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), true);
    }
    return 1;
  }

 - David


On Wed, Jun 27, 2018 at 10:59 AM, BBerco <[hidden email]> wrote:
Hello all,
I'm working on a filter that produces luminosity curves from shape models.
I'm trying to extend its capability to the case of multiple-body systems,
for instance that of a binary asteroid featuring a primary around which
orbits a secondary object.

To this end, I would need to allow my filter (inheriting from
vtkPolyDataAlgorithm) to take in multiple polydata inputs (one for each
body, with the first one being the primary, the second one the secondary (if
any),...).

I naively tried
*
myfilter-> SetInputData(0,primary_polydata)
myfilter-> SetInputData(1,secondary_polydata)
*

but the method which I think should return the number of inputs
(GetNumberOfInputPorts()) still returns 1. Obviously I'm being confused
between the number of inputs and the number of input ports.

This example
<https://www.vtk.org/Wiki/VTK/Examples/Cxx/Developers/MultipleInputPorts
presents another approach that is not as flexible as I would like because it
relies on* SetInputConnection* and not * SetInputData*.

Any advice?


_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Multiple input data in custom vtkPolydataFilter

BBerco
David, thanks for the quick reply! I'll give it a try



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Multiple input data in custom vtkPolydataFilter

David Gobbi
For the second port, you might want to set INPUT_IS_REPEATABLE()
in addition to INPUT_IS_OPTIONAL().

This will allow you to use AddInputData(1, data) to input as many
secondary objects to the port as you desire.  The number of input
ports for a VTK filter is fixed, but repeatable ports can accept any
number of inputs.

_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers