Difference between revisions of "VTK/Examples/Cxx/Developers/PolyDataFilter"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/PolyDataFilter PolyDataFilter] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples we...")
 
Line 1: Line 1:
This example demonstrates a filter named vtkTestPolyDataFilter that takes a vtkPolyData as input and produces a vtkPolyData as output.
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/PolyDataFilter PolyDataFilter] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
 
 
==PolyDataFilter.cxx==
 
<source lang="cpp">
 
#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();
 
#if VTK_MAJOR_VERSION <= 5
 
  filter->SetInput(inputPolydata);
 
#else
 
  filter->SetInputData(inputPolydata);
 
#endif
 
  filter->Update();
 
 
 
  vtkPolyData* outputPolydata = filter->GetOutput();
 
 
 
  std::cout << "Output points: " << outputPolydata->GetNumberOfPoints()
 
            << std::endl;
 
 
 
  return EXIT_SUCCESS;
 
}
 
 
 
</source>
 
 
 
==vtkTestPolyDataFilter.h==
 
<source lang="cpp">
 
 
 
#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
 
 
 
</source>
 
 
 
==vtkTestPolyDataFilter.cxx==
 
<source lang="cpp">
 
 
 
#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);
 
}
 
</source>
 
 
 
{{VTKCMakeListsMultiple|{{SUBPAGENAME}}|vtkTestPolyDataFilter}}
 

Latest revision as of 17:02, 12 April 2019

See PolyDataFilter on the new VTKExamples website.