PolyDataFilter
vtk-examples/Cxx/Developers/PolyDataFilter
Description¶
This example demonstrates a filter named vtkTestPolyDataFilter that takes a vtkPolyData as input and produces a vtkPolyData as output.
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
PolyDataFilter.cxx
#include <vtkSmartPointer.h>
#include <vtkTestPolyDataFilter.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<vtkTestPolyDataFilter> filter =
vtkSmartPointer<vtkTestPolyDataFilter>::New();
filter->SetInputData(inputPolydata);
filter->Update();
vtkPolyData* outputPolydata = filter->GetOutput();
std::cout << "Output points: " << outputPolydata->GetNumberOfPoints()
<< std::endl;
return EXIT_SUCCESS;
}
vtkTestPolyDataFilter.h
#ifndef __vtkTestPolyDataFilter_h
#define __vtkTestPolyDataFilter_h
#include <vtkPolyDataAlgorithm.h>
class vtkTestPolyDataFilter : public vtkPolyDataAlgorithm
{
public:
vtkTypeMacro(vtkTestPolyDataFilter,vtkPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
static vtkTestPolyDataFilter *New();
protected:
vtkTestPolyDataFilter();
~vtkTestPolyDataFilter();
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
private:
vtkTestPolyDataFilter(const vtkTestPolyDataFilter&); // Not implemented.
void operator=(const vtkTestPolyDataFilter&); // Not implemented.
};
#endif
vtkTestPolyDataFilter.cxx
#include <vtkTestPolyDataFilter.h>
#include <vtkObjectFactory.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkInformationVector.h>
#include <vtkInformation.h>
#include <vtkDataObject.h>
#include <vtkSmartPointer.h>
vtkStandardNewMacro(vtkTestPolyDataFilter);
vtkTestPolyDataFilter::vtkTestPolyDataFilter()
{
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
}
vtkTestPolyDataFilter::~vtkTestPolyDataFilter()
{
}
int vtkTestPolyDataFilter::RequestData(vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the input and output
vtkPolyData* input = vtkPolyData::GetData(inputVector[0],0);
vtkPolyData* output = vtkPolyData::GetData(outputVector,0);
input->GetPoints()->InsertNextPoint(1.0, 1.0, 1.0);
output->ShallowCopy(input);
return 1;
}
//----------------------------------------------------------------------------
void vtkTestPolyDataFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(PolyDataFilter)
find_package(VTK COMPONENTS
vtkCommonCore
QUIET
)
if (NOT VTK_FOUND)
message("Skipping PolyDataFilter: ${VTK_NOT_FOUND_MESSAGE}")
return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
include(${VTK_USE_FILE})
add_executable(PolyDataFilter MACOSX_BUNDLE PolyDataFilter.cxx )
target_link_libraries(PolyDataFilter PRIVATE ${VTK_LIBRARIES})
else ()
# include all components
add_executable(PolyDataFilter MACOSX_BUNDLE PolyDataFilter.cxx )
target_link_libraries(PolyDataFilter PRIVATE ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS PolyDataFilter
MODULES ${VTK_LIBRARIES}
)
endif ()
Download and Build PolyDataFilter¶
Click here to download PolyDataFilter and its CMakeLists.txt file. Once the tarball PolyDataFilter.tar has been downloaded and extracted,
cd PolyDataFilter/build
If VTK is installed:
cmake ..
If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..
Build the project:
make
and run it:
./PolyDataFilter
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.