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

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/PolyDataAlgorithmReader PolyDataAlgorithmReader] on the new [https://lorensen.github.io/VTKExamples/si...")
 
Line 1: Line 1:
This example demonstrates a reader that takes nothing as input and produces a vtkPolyData as output.
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/PolyDataAlgorithmReader PolyDataAlgorithmReader] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
 
 
==PolyDataAlgorithmReader.cxx==
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkPolyData.h>
 
 
 
#include "vtkTestReader.h"
 
 
 
int main (int, char *[])
 
{
 
  vtkSmartPointer<vtkTestReader> reader =
 
    vtkSmartPointer<vtkTestReader>::New();
 
  reader->Update();
 
 
 
  vtkPolyData* polydata = reader->GetOutput();
 
  polydata->Print(std::cout);
 
 
 
  return EXIT_SUCCESS;
 
}
 
</source>
 
 
 
==vtkTestReader.h==
 
<source lang="cpp">
 
#ifndef __vtkTestReader_h
 
#define __vtkTestReader_h
 
 
 
#include "vtkPolyDataAlgorithm.h"
 
 
 
class vtkTestReader : public vtkPolyDataAlgorithm
 
{
 
public:
 
  vtkTypeMacro(vtkTestReader,vtkPolyDataAlgorithm);
 
  void PrintSelf(ostream& os, vtkIndent indent);
 
 
 
  static vtkTestReader *New();
 
 
protected:
 
  vtkTestReader();
 
  ~vtkTestReader();
 
 
 
  int FillOutputPortInformation( int port, vtkInformation* info );
 
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
 
 
 
private:
 
  vtkTestReader(const vtkTestReader&);  // Not implemented.
 
  void operator=(const vtkTestReader&);  // Not implemented.
 
 
 
  char* FileName;
 
};
 
 
 
#endif
 
 
 
</source>
 
 
 
==vtkTestReader.cxx==
 
<source lang="cpp">
 
#include "vtkTestReader.h"
 
 
 
#include "vtkObjectFactory.h"
 
#include "vtkStreamingDemandDrivenPipeline.h"
 
#include "vtkInformationVector.h"
 
#include "vtkInformation.h"
 
#include "vtkDataObject.h"
 
#include "vtkNew.h"
 
 
 
vtkStandardNewMacro(vtkTestReader);
 
 
 
vtkTestReader::vtkTestReader()
 
{
 
  this->FileName = NULL;
 
  this->SetNumberOfInputPorts(0);
 
  this->SetNumberOfOutputPorts(1);
 
}
 
 
 
vtkTestReader::~vtkTestReader()
 
{
 
 
 
}
 
 
 
// This override is not needed as the FillOutputPortInformation on vtkPolyDataAlgorithm
 
// does this.  Override this if you need something different from one output that
 
// is a vtkPolyData
 
int vtkTestReader::FillOutputPortInformation( int port, vtkInformation* info )
 
{
 
  if ( port == 0 )
 
  {
 
    info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData" );
 
   
 
    return 1;
 
  }
 
 
 
  return 0;
 
}
 
 
 
int vtkTestReader::RequestData(
 
  vtkInformation *vtkNotUsed(request),
 
  vtkInformationVector **vtkNotUsed(inputVector),
 
  vtkInformationVector *outputVector)
 
{
 
 
 
  // Get the output
 
  vtkPolyData *output = vtkPolyData::GetData(outputVector,0)
 
 
 
  vtkNew<vtkPolyData> polydata;
 
  vtkNew<vtkPoints> points;
 
  points->InsertNextPoint(0.0, 0.0, 0.0);
 
  polydata->SetPoints(points.GetPointer());
 
 
 
  //output = polydata.GetPointer(); //doesn't work
 
  output->ShallowCopy(polydata.GetPointer());
 
   
 
  return 1;
 
}
 
 
 
 
 
//----------------------------------------------------------------------------
 
void vtkTestReader::PrintSelf(ostream& os, vtkIndent indent)
 
{
 
  this->Superclass::PrintSelf(os,indent);
 
 
 
  os << indent << "File Name: "
 
      << (this->FileName ? this->FileName : "(none)") << "\n";
 
}
 
 
 
 
 
</source>
 
 
 
==CMakeLists.txt==
 
<source lang="cmake">
 
cmake_minimum_required(VERSION 2.6)
 
project(PolyDataAlgorithmReader)
 
 
 
find_package(VTK REQUIRED)
 
include(${VTK_USE_FILE})
 
 
 
ADD_EXECUTABLE(PolyDataAlgorithmReader PolyDataAlgorithmReader.cxx vtkTestReader.cxx)
 
 
 
if(VTK_LIBRARIES)
 
  target_link_libraries(PolyDataAlgorithmReader ${VTK_LIBRARIES})
 
else()
 
  target_link_libraries(PolyDataAlgorithmReader vtkHybrid)
 
endif()
 
 
 
</source>
 

Latest revision as of 17:01, 12 April 2019

See PolyDataAlgorithmReader on the new VTKExamples website.