VTK/Examples/Developers/MultipleOutputPorts

From KitwarePublic

Jump to: navigation, search

Contents

MultipleOutputPorts.cxx

#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
 
#include "vtkTestFilter.h"
 
int main (int, char *[])
{
  vtkSmartPointer<vtkSphereSource> sphereSource =
      vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();
 
  vtkSmartPointer<vtkTestFilter> filter =
      vtkSmartPointer<vtkTestFilter>::New();
  filter->SetInputConnection(sphereSource->GetOutputPort());
  filter->Update();
 
  std::cout << "Output0 has " << filter->GetOutput(0)->GetNumberOfPoints() << " points." << std::endl;
  std::cout << "Output1 has " << filter->GetOutput(1)->GetNumberOfPoints() << " points." << std::endl;
 
  return EXIT_SUCCESS;
}

vtkTestFilter.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 RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
 
private:
  vtkTestFilter(const vtkTestFilter&);  // Not implemented.
  void operator=(const vtkTestFilter&);  // Not implemented.
 
};
 
#endif

vtkTestFilter.cxx

#include "vtkTestFilter.h"
 
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformationVector.h"
#include "vtkInformation.h"
#include "vtkDataObject.h"
#include "vtkSmartPointer.h"
 
#include "vtkCubeSource.h"
 
vtkStandardNewMacro(vtkTestFilter);
 
vtkTestFilter::vtkTestFilter()
{
  this->SetNumberOfOutputPorts(2);
}
 
int vtkTestFilter::RequestData(vtkInformation *vtkNotUsed(request),
                                             vtkInformationVector **inputVector,
                                             vtkInformationVector *outputVector)
{
 
  // get the info objects
  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
 
  vtkInformation *outInfo0 = outputVector->GetInformationObject(0);
  vtkInformation *outInfo1 = outputVector->GetInformationObject(1);
 
  // get the input and ouptut
  vtkPolyData *input = vtkPolyData::SafeDownCast(
      inInfo->Get(vtkDataObject::DATA_OBJECT()));
 
  vtkPolyData *output0 = vtkPolyData::SafeDownCast(
    outInfo0->Get(vtkDataObject::DATA_OBJECT()));
 
  vtkPolyData *output1 = vtkPolyData::SafeDownCast(
    outInfo1->Get(vtkDataObject::DATA_OBJECT()));
 
  output0->ShallowCopy(input);
 
  vtkSmartPointer<vtkCubeSource> cubeSource =
    vtkSmartPointer<vtkCubeSource>::New();
  cubeSource->Update();
 
  output1->ShallowCopy(cubeSource->GetOutput());
 
  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