[Paraview] filter with multiple input

Natalie Happenhofer nataliehapp at hotmail.com
Sun Nov 23 13:18:24 EST 2008


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! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20081123/284c71f8/attachment.htm>


More information about the ParaView mailing list