VTK/Examples/Developers/MultipleInputPorts

From KitwarePublic

Jump to: navigation, search

Contents

FilterExample.cxx

#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
 
#include "vtkTestFilter.h"
 
int main (int argc, char *argv[])
{
  vtkSmartPointer<vtkSphereSource> sphereSource1 =
      vtkSmartPointer<vtkSphereSource>::New();
  sphereSource1->SetThetaResolution(5);
  sphereSource1->Update();
 
  vtkSmartPointer<vtkSphereSource> sphereSource2 =
      vtkSmartPointer<vtkSphereSource>::New();
  sphereSource2->SetThetaResolution(10);
  sphereSource2->Update();
 
  vtkSmartPointer<vtkTestFilter> filter =
      vtkSmartPointer<vtkTestFilter>::New();
  filter->SetInputConnection(0, sphereSource1->GetOutputPort());
  filter->SetInputConnection(1, sphereSource2->GetOutputPort());
  filter->Update();
 
  return EXIT_SUCCESS;
}

TestFilter.h

// .NAME vtkTestFilter
// .SECTION Description
// vtkTestFilter
 
#ifndef __vtkTestFilter_h
#define __vtkTestFilter_h
 
#include "vtkPolyDataAlgorithm.h"
 
class vtkTestFilter : public vtkPolyDataAlgorithm
{
public:
  vtkTypeMacro(vtkTestFilter,vtkPolyDataAlgorithm);
  static vtkTestFilter *New();
 
protected:
  vtkTestFilter();
  ~vtkTestFilter(){}
 
  int FillInputPortInformation( int port, vtkInformation* info );
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
 
private:
  vtkTestFilter(const vtkTestFilter&);  // Not implemented.
  void operator=(const vtkTestFilter&);  // Not implemented.
 
};
 
#endif

TestFilter.cxx

#include "vtkTestFilter.h"
 
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformationVector.h"
#include "vtkInformation.h"
#include "vtkDataObject.h"
#include "vtkSmartPointer.h"
 
vtkStandardNewMacro(vtkTestFilter);
 
vtkTestFilter::vtkTestFilter()
{
  this->SetNumberOfInputPorts(2);
}
 
int vtkTestFilter::FillInputPortInformation( int port, vtkInformation* info )
{
  if ( port == 0 )
    {
    info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData" );
    return 1;
    }
  else if(port == 1)
    {
    info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData" );
    return 1;
    }
 
  return 0;
}
 
int vtkTestFilter::RequestData(vtkInformation *vtkNotUsed(request),
                                             vtkInformationVector **inputVector,
                                             vtkInformationVector *outputVector)
{
 
  // get the info objects
  vtkInformation *inInfo0 = inputVector[0]->GetInformationObject(0);
  vtkInformation *inInfo1 = inputVector[1]->GetInformationObject(0);
 
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
 
 
  // get the input and ouptut
  vtkPolyData *input0 = vtkPolyData::SafeDownCast(
      inInfo0->Get(vtkDataObject::DATA_OBJECT()));
 
  std::cout << "input0 has " << input0->GetNumberOfPoints() << " points." << std::endl;
 
  vtkPolyData *input1 = vtkPolyData::SafeDownCast(
      inInfo1->Get(vtkDataObject::DATA_OBJECT()));
 
  std::cout << "input1 has " << input1->GetNumberOfPoints() << " points." << std::endl;
 
  vtkPolyData *output = vtkPolyData::SafeDownCast(
      outInfo->Get(vtkDataObject::DATA_OBJECT()));
 
  output->ShallowCopy(input0);
 
  return 1;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
PROJECT(vtkPolyDataAlgorithmDemo)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(FilterExample FilterExample.cxx vtkTestFilter.cxx)
TARGET_LINK_LIBRARIES(FilterExample vtkHybrid)
Personal tools