VTK/Examples/Cxx/Developers/PolyDataAlgorithmReader

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Revision as of 20:00, 26 November 2009 by Daviddoria (talk | contribs) (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...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

ReaderExample.cxx

#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;
}

vtkTestReader.h

#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

vtkTestReader.cxx

#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";	
}

vtkTest.h

#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

vtkTest.cxx

#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";	
}

CMakeLists.txt

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)