VTK/Examples/Developers/vtkPolyDataAlgorithm Filter
From KitwarePublic
< VTK | Examples | Developers
This example demonstrates a filter named vtkTestFilter that takes a vtkPolyData as input and produces a vtkPolyData as output.
Contents |
FilterExample.cxx
#include <vtkSmartPointer.h> #include "vtkTestFilter.h" int main(int, char *[]) { vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); points->InsertNextPoint(0.0, 0.0, 0.0); vtkSmartPointer<vtkPolyData> inputPolydata = vtkSmartPointer<vtkPolyData>::New(); inputPolydata->SetPoints(points); std::cout << "Input points: " << inputPolydata->GetNumberOfPoints() << std::endl; vtkSmartPointer<vtkTestFilter> filter = vtkSmartPointer<vtkTestFilter>::New(); filter->SetInput(inputPolydata); filter->Update(); vtkPolyData* outputPolydata = filter->GetOutput(); std::cout << "Output points: " << outputPolydata->GetNumberOfPoints() << std::endl; return EXIT_SUCCESS; }
vtkTestFilter.h
#ifndef __vtkTestFilter_h #define __vtkTestFilter_h #include "vtkPolyDataAlgorithm.h" class vtkTestFilter : public vtkPolyDataAlgorithm { public: vtkTypeMacro(vtkTestFilter,vtkPolyDataAlgorithm); void PrintSelf(ostream& os, vtkIndent indent); 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" vtkStandardNewMacro(vtkTestFilter); vtkTestFilter::vtkTestFilter() { this->SetNumberOfInputPorts(1); this->SetNumberOfOutputPorts(1); } vtkTestFilter::~vtkTestFilter() { } int vtkTestFilter::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector) { // get the info objects vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); vtkInformation *outInfo = outputVector->GetInformationObject(0); // get the input and ouptut vtkPolyData *input = vtkPolyData::SafeDownCast( inInfo->Get(vtkDataObject::DATA_OBJECT())); vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT())); input->GetPoints()->InsertNextPoint(1.0, 1.0, 1.0); output->ShallowCopy(input); return 1; } //---------------------------------------------------------------------------- void vtkTestFilter::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); }
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)