[Paraview] filter with multiple input
Utkarsh Ayachit
utkarsh.ayachit at kitware.com
Sun Nov 23 22:21:40 EST 2008
Hi Natalie,
There are problems with your filter code that accesses the inputs. You
are accessing information objects from multiple input ports when it
looks like you want to be looking at multiple input connections from
the same input port. Look at vtkAppendFilter or
vtkAppendPolyDataFilter for code that deals with multiple input
connections. From the description you are giving it looks like a
multiple input port filter might also solve your use-case. Look at
vtkProbeFilter or vtkStreamTracer for code for writing multiple input
port filters (looking at the xmls for the corresponding filters in
ServerManager/Resources/filters.xml should help you with writing the
xmls for each of the case).
The "eye" only control the visibility. It does not affect whether that
source becomes an input to a newly created filter. Only items
"selected" in the pipeline browser become the input. You can select
multiple sources by using "Ctrl" or "Shift" key when selecting in the
pipeline browser.
Utkarsh
On Sun, Nov 23, 2008 at 1:18 PM, Natalie Happenhofer
<nataliehapp at hotmail.com> wrote:
> Hi!
> I´m trying to write a filter with multiple input. Just for trying out, I
> want to add the scalar attribute data of two datasets (both should have the
> same structure) and have as an output one dataset with the same structure
> and the the added scalar data of the two input datasets.
> The header vtkDataCalculator.h looks like this:
>
> #ifndef __vtkDataCalculator_h
> #define __vtkDataCalculator_h
>
> #include "vtkDataSetAlgorithm.h"
>
> class VTK_EXPORT vtkDataCalculator: public vtkDataSetAlgorithm
> { public:
> static vtkDataCalculator *New();
>
> vtkTypeRevisionMacro(vtkDataCalculator,vtkDataSetAlgorithm);
> void PrintSelf(ostream& os, vtkIndent indent);
>
> protected:
> vtkDataCalculator(){};
> ~vtkDataCalculator(){};
>
> //virtual int FillInputPortInformation(int port, vtkInformation* info);
> virtual int RequestData(vtkInformation *, vtkInformationVector **,
> vtkInformationVector *);
> };
> #endif
>
>
> the vtkDataCalculator.cxx file:
> #include "vtkDataCalculator.h"
> #include "vtkDataSet.h"
> #include "vtkDataArray.h"
> #include "vtkObjectFactory.h"
> #include "vtkPointData.h"
> #include "vtkDoubleArray.h"
> #include "vtkAlgorithm.h"
> #include "vtkSmartPointer.h"
> #include "vtkInformation.h"
> #include "vtkInformationVector.h"
>
> vtkStandardNewMacro(vtkDataCalculator);
> //----------------------------------------------------------------------------
> vtkCxxRevisionMacro(vtkDataCalculator,"$Revision$");
> //----------------------------------------------------------------------------
> void vtkDataCalculator::PrintSelf(ostream& os, vtkIndent indent)
> {
> this->Superclass::PrintSelf(os,indent);
> }
>
> //----------------------------------------------------------------------------
>
>
> int vtkDataCalculator::RequestData(vtkInformation *vtkNotUsed(request),
> vtkInformationVector **inputVector,
> vtkInformationVector *outputVector)
> {
> // int numOfInputs = inputVector -> GetNumberOfInformationObjects();
> // if(numOfInputs != 2) vtkErrorMacro("Number of Inputs not equal 2");
> //Get the input and the output
> vtkDataSet* input1 = vtkDataSet::GetData(inputVector[0]);
> vtkDataSet* input2 = vtkDataSet::GetData(inputVector[1]);
> vtkDataSet* output = vtkDataSet::GetData(outputVector);
>
> //check if the same number of points
> int numOfTuples1 = input1 -> GetPointData() -> GetArray(0) ->
> GetNumberOfTuples();
> int numOfTuples2 = input2 -> GetPointData() -> GetArray(0) ->
> GetNumberOfTuples();
>
> vtkDoubleArray *scalars1 = vtkDoubleArray::New();
> input1 -> GetPointData() -> GetArray(0) ->
> GetData(0,numOfTuples1,0,0,scalars1);
>
> vtkDoubleArray *scalars2 = vtkDoubleArray::New();
> input2 -> GetPointData() -> GetArray(0) ->
> GetData(0,numOfTuples2,0,0,scalars2);
>
> vtkDoubleArray *summe = vtkDoubleArray::New();
> summe -> SetNumberOfComponents(1);
> summe -> SetNumberOfTuples(numOfTuples1);
>
> if(numOfTuples1 != numOfTuples2) {vtkErrorMacro("different Number of
> Tuples");
> return 0;
> }
> else { for(int index = 0; index < numOfTuples1; index++)
> { summe -> SetValue(index, (scalars1 -> GetValue(index)) +
> (scalars2 -> GetValue(index)));
> }
>
> output -> CopyStructure(input1);
> summe -> SetName("Summe");
> output -> GetPointData() -> AddArray(summe);
> output -> GetPointData() -> SetActiveScalars("Summe");
> output -> Squeeze();
> return 1;
> }
> }
>
>
> and now the corresponding ServerManager.xml file:
>
> <ServerManagerConfiguration>
> <ProxyGroup name="filters">
> <SourceProxy name="DataCalculator" class="vtkDataCalculator" label="Data
> Calculator">
> <Documentation>
> This filter adds the point data of their scalar attributes. The dimensions
> must coincide.
> </Documentation>
>
> <InputProperty name="Input" command="AddInputConnection"
> clean_command="RemoveAllInputs" multiple_input="1">
> <ProxyGroupDomain name="groups">
> <Group name="sources"/>
> <Group name="filters"/>
> </ProxyGroupDomain>
>
> <DataTypeDomain name="input_type">
> <DataType value="vtkDataSet"/>
> </DataTypeDomain>
>
> </InputProperty>
> </SourceProxy>
>
> </ProxyGroup>
> </ServerManagerConfiguration>
>
>
> Well, that´s my first try.. Paraview shuts down when I try to apply the
> filter, debugging I get the information that there is something wrong with
> the input (small wonder ;-) ). But it can also be the case that I just don´t
> know how to give two datasets to the filter, meaning that to apply the
> filter, I opened two files, so I had two of those "eye"-icons in paraview´s
> pipeline browser displayed and hoped that Paraview would recognize those
> datasets as the input to the filter.
>
> Thx for any piece of advice,
> Natalie
>
> ________________________________
> Express yourself instantly with MSN Messenger! MSN Messenger
> _______________________________________________
> ParaView mailing list
> ParaView at paraview.org
> http://www.paraview.org/mailman/listinfo/paraview
>
>
More information about the ParaView
mailing list