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

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(New page: ==ReaderExample.cxx== <source lang="cpp"> #include <vtkSmartPointer.h> #include "vtkTestFilter.h" #include "vtkTestReader.h" #include "vtkTest.h" int main (int argc, char *argv[]) { i...)
 
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/PolyDataAlgorithmReader PolyDataAlgorithmReader] on the new [https://lorensen.github.io/VTKExamples/si...")
 
(15 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/PolyDataAlgorithmReader PolyDataAlgorithmReader] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
==ReaderExample.cxx==
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
 
 
#include "vtkTestFilter.h"
 
#include "vtkTestReader.h"
 
#include "vtkTest.h"
 
 
 
int main (int argc, char *argv[])
 
{
 
  if(argc != 2)
 
    {
 
    vtkstd::cout << "Required arguments: Filename" << vtkstd::endl;
 
    exit(-1);
 
    }
 
   
 
  vtkstd::string InputFilename = argv[1];
 
 
 
  vtkSmartPointer<vtkTestReader> reader = vtkSmartPointer<vtkTestReader>::New();
 
  reader->Update();
 
 
 
  //vtkTest* test = reader->GetOutput();
 
  //vtkTest* test = reader->GetOutputPort();
 
  vtkTest* test = reader->GetOutputPort(0);
 
  //vtkstd::cout << "Value: " << test->GetValue() << vtkstd::endl;
 
 
 
  return 0;
 
}
 
 
 
</source>
 
 
 
==vtkTestReader.h==
 
<source lang="cpp">
 
 
 
#ifndef __vtkTestReader_h
 
#define __vtkTestReader_h
 
 
 
#include "vtkAlgorithm.h"
 
 
 
class vtkTestReader : public vtkAlgorithm
 
{
 
public:
 
  vtkTypeRevisionMacro(vtkTestReader,vtkAlgorithm);
 
  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 "vtkTest.h"
 
 
 
#include "vtkObjectFactory.h"
 
#include "vtkStreamingDemandDrivenPipeline.h"
 
#include "vtkInformationVector.h"
 
#include "vtkInformation.h"
 
#include "vtkDataObject.h"
 
#include "vtkSmartPointer.h"
 
 
 
vtkCxxRevisionMacro(vtkTestReader, "$Revision: 1.70 $");
 
vtkStandardNewMacro(vtkTestReader);
 
 
 
vtkTestReader::vtkTestReader()
 
{
 
  this->FileName = NULL;
 
  this->SetNumberOfInputPorts(0);
 
  this->SetNumberOfOutputPorts(1);
 
}
 
 
 
vtkTestReader::~vtkTestReader()
 
{
 
 
 
}
 
 
 
int vtkTestReader::FillOutputPortInformation( int port, vtkInformation* info )
 
{
 
  if ( port == 0 )
 
  {
 
    info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkTest" );
 
   
 
    return 1;
 
  }
 
 
 
  return 0;
 
}
 
 
 
int vtkTestReader::RequestData(
 
  vtkInformation *vtkNotUsed(request),
 
  vtkInformationVector **vtkNotUsed(inputVector),
 
  vtkInformationVector *outputVector)
 
{
 
 
 
  // get the info object
 
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
 
 
 
  // get the ouptut
 
  vtkTest *output = vtkTest::SafeDownCast(
 
            outInfo->Get(vtkDataObject::DATA_OBJECT()));
 
 
 
  vtkSmartPointer<vtkTest> test = vtkSmartPointer<vtkTest>::New();
 
  test->SetValue(5.1) ;
 
 
 
  output = test;
 
   
 
  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>
 
 
 
==vtkTest.h==
 
<source lang="cpp">
 
 
 
#ifndef __vtkTest_h
 
#define __vtkTest_h
 
 
 
#include "vtkObject.h"
 
 
 
class vtkInformation;
 
class vtkInformationVector;
 
 
 
class vtkTest : public vtkObject
 
{
 
public:
 
  vtkTypeRevisionMacro(vtkTest,vtkObject);
 
  void PrintSelf(ostream& os, vtkIndent indent);
 
 
 
  static vtkTest *New();
 
 
 
  vtkSetMacro(Value,double);
 
  vtkGetMacro(Value,double);
 
protected:
 
  vtkTest();
 
  ~vtkTest();
 
 
 
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
 
 
 
private:
 
  vtkTest(const vtkTest&);  // Not implemented.
 
  void operator=(const vtkTest&);  // Not implemented.
 
 
 
  double Value;
 
};
 
 
 
#endif
 
 
 
</source>
 
 
 
==vtkTest.cxx==
 
<source lang="cpp">
 
#include "vtkTest.h"
 
 
 
#include "vtkObjectFactory.h"
 
#include "vtkStreamingDemandDrivenPipeline.h"
 
#include "vtkInformationVector.h"
 
#include "vtkInformation.h"
 
 
 
vtkCxxRevisionMacro(vtkTest, "$Revision: 1.70 $");
 
vtkStandardNewMacro(vtkTest);
 
 
 
vtkTest::vtkTest()
 
{
 
 
 
}
 
 
 
vtkTest::~vtkTest()
 
{
 
 
 
}
 
 
 
int vtkTest::RequestData(
 
  vtkInformation *vtkNotUsed(request),
 
  vtkInformationVector **vtkNotUsed(inputVector),
 
  vtkInformationVector *outputVector)
 
{
 
 
 
  // get the info object
 
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
 
 
 
  // get the ouptut
 
//  vtkPolyData *output = vtkPolyData::SafeDownCast(
 
//   outInfo->Get(vtkDataObject::DATA_OBJECT()));
 
 
 
  //output->ShallowCopy(polydata);
 
 
 
  return 1;
 
}
 
 
 
 
 
//----------------------------------------------------------------------------
 
void vtkTest::PrintSelf(ostream& os, vtkIndent indent)
 
{
 
  this->Superclass::PrintSelf(os,indent);
 
 
 
  os << indent << "Value: " << this->Value << "\n";
 
}
 
 
 
</source>
 
 
 
==CMakeLists.txt==
 
<source lang="text">
 
cmake_minimum_required(VERSION 2.6)
 
PROJECT(vtkPolyDataAlgorithmDemo)
 
 
 
FIND_PACKAGE(VTK REQUIRED)
 
INCLUDE(${VTK_USE_FILE})
 
 
 
ADD_EXECUTABLE(ReaderExample ReaderExample.cxx vtkTest.cxx vtkTestReader.cxx)
 
TARGET_LINK_LIBRARIES(ReaderExample vtkHybrid)
 
 
 
</source>
 

Latest revision as of 16:01, 12 April 2019

See PolyDataAlgorithmReader on the new VTKExamples website.