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

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to navigationJump to search
Line 1: Line 1:
 
This example demonstrates a reader that takes nothing as input and produces a vtkPolyData as output.
 
This example demonstrates a reader that takes nothing as input and produces a vtkPolyData as output.
 
It is currently not working.
 
  
 
==ReaderExample.cxx==
 
==ReaderExample.cxx==
 
<source lang="cpp">
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkSmartPointer.h>
 +
#include <vtkPolyData.h>
  
#include "vtkTestFilter.h"
 
 
#include "vtkTestReader.h"
 
#include "vtkTestReader.h"
#include "vtkTest.h"
 
  
 
int main (int argc, char *argv[])
 
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();
 
   vtkSmartPointer<vtkTestReader> reader = vtkSmartPointer<vtkTestReader>::New();
 
   reader->Update();
 
   reader->Update();
 
    
 
    
   //vtkTest* test = reader->GetOutput();
+
   vtkPolyData* polydata = reader->GetOutput();
  //vtkTest* test = reader->GetOutputPort();
+
 
  vtkTest* test = reader->GetOutputPort(0);
 
  //vtkstd::cout << "Value: " << test->GetValue() << vtkstd::endl;
 
 
 
 
   return 0;
 
   return 0;
 
}
 
}
Line 36: Line 22:
 
==vtkTestReader.h==
 
==vtkTestReader.h==
 
<source lang="cpp">
 
<source lang="cpp">
 
 
#ifndef __vtkTestReader_h
 
#ifndef __vtkTestReader_h
 
#define __vtkTestReader_h
 
#define __vtkTestReader_h
  
#include "vtkAlgorithm.h"
+
#include "vtkPolyDataAlgorithm.h"
  
class vtkTestReader : public vtkAlgorithm
+
class vtkTestReader : public vtkPolyDataAlgorithm
 
{
 
{
 
public:
 
public:
   vtkTypeRevisionMacro(vtkTestReader,vtkAlgorithm);
+
   vtkTypeRevisionMacro(vtkTestReader,vtkPolyDataAlgorithm);
 
   void PrintSelf(ostream& os, vtkIndent indent);
 
   void PrintSelf(ostream& os, vtkIndent indent);
  
Line 71: Line 56:
 
<source lang="cpp">
 
<source lang="cpp">
 
#include "vtkTestReader.h"
 
#include "vtkTestReader.h"
#include "vtkTest.h"
 
  
 
#include "vtkObjectFactory.h"
 
#include "vtkObjectFactory.h"
Line 99: Line 83:
 
   if ( port == 0 )
 
   if ( port == 0 )
 
   {
 
   {
     info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkTest" );
+
     info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData" );
 
      
 
      
 
     return 1;
 
     return 1;
Line 117: Line 101:
 
    
 
    
 
   // get the ouptut
 
   // get the ouptut
   vtkTest *output = vtkTest::SafeDownCast(
+
   vtkPolyData *output = vtkPolyData::SafeDownCast(
 
             outInfo->Get(vtkDataObject::DATA_OBJECT()));
 
             outInfo->Get(vtkDataObject::DATA_OBJECT()));
 
    
 
    
   vtkSmartPointer<vtkTest> test = vtkSmartPointer<vtkTest>::New();
+
   vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
   test->SetValue(5.1) ;
+
   vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
 +
  points->InsertNextPoint(0.0, 0.0, 0.0);
 +
  polydata->SetPoints(points);
 
    
 
    
   output = test;
+
   output = polydata;
 
      
 
      
 
   return 1;
 
   return 1;
Line 149: Line 135:
 
INCLUDE(${VTK_USE_FILE})
 
INCLUDE(${VTK_USE_FILE})
  
ADD_EXECUTABLE(ReaderExample ReaderExample.cxx vtkTest.cxx vtkTestReader.cxx)
+
ADD_EXECUTABLE(ReaderExample ReaderExample.cxx vtkTestReader.cxx)
 
TARGET_LINK_LIBRARIES(ReaderExample vtkHybrid)
 
TARGET_LINK_LIBRARIES(ReaderExample vtkHybrid)
  
 
</source>
 
</source>

Revision as of 20:13, 26 November 2009

This example demonstrates a reader that takes nothing as input and produces a vtkPolyData as output.

ReaderExample.cxx

#include <vtkSmartPointer.h>
#include <vtkPolyData.h>

#include "vtkTestReader.h"

int main (int argc, char *argv[])
{
  vtkSmartPointer<vtkTestReader> reader = vtkSmartPointer<vtkTestReader>::New();
  reader->Update();
  
  vtkPolyData* polydata = reader->GetOutput();

  return 0;
}

vtkTestReader.h

#ifndef __vtkTestReader_h
#define __vtkTestReader_h

#include "vtkPolyDataAlgorithm.h"

class vtkTestReader : public vtkPolyDataAlgorithm 
{
public:
  vtkTypeRevisionMacro(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

vtkTestReader.cxx

#include "vtkTestReader.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(), "vtkPolyData" );
    
    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
   vtkPolyData *output = vtkPolyData::SafeDownCast(
            outInfo->Get(vtkDataObject::DATA_OBJECT()));
  
  vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  points->InsertNextPoint(0.0, 0.0, 0.0);
  polydata->SetPoints(points);
  
  output = polydata;
    
  return 1;
}


//----------------------------------------------------------------------------
void vtkTestReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "File Name: " 
      << (this->FileName ? this->FileName : "(none)") << "\n";	
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
PROJECT(vtkPolyDataAlgorithmDemo)

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(ReaderExample ReaderExample.cxx vtkTestReader.cxx)
TARGET_LINK_LIBRARIES(ReaderExample vtkHybrid)