VTK/Examples/Developers/vtkObject

From KitwarePublic

Jump to: navigation, search

An object class should be derived from vtkObject. It should provide a PrintSelf function, use vtkSet/Get macros for mutators/accessors, use vtkStandardNewMacro for it's only allowed constructor, and forcefully omit the copy constructor and assignment operator.

An example header file is:

#ifndef __vtkLidarPoint_h
#define __vtkLidarPoint_h
 
#include "vtkPoints.h"
 
#include <iostream>
#include <string>
 
class vtkLidarPoint : public vtkObject
{
	public:
		static vtkLidarPoint *New();
		void PrintSelf(ostream &os, vtkIndent indent);
		double Coordinate[3];//(x,y,z) coords of point in scanner centered coordinates
		double Direction[3];//the direction from which the point was scanned
		bool Hit;//hit or miss? (i.e. is the point valid?)
		double Normal[3]; //the normal of the triangle that was intersected
 
		////////// Accessors ///////////
		vtkGetVector3Macro(Coordinate,double);
		vtkGetVector3Macro(Direction,double);
		vtkGetVector3Macro(Normal,double);
		vtkGetMacro(Hit, bool);
 
 
		/////////// Mutators ///////////
		vtkSetVector3Macro(Coordinate,double);
		vtkSetVector3Macro(Direction,double);
		vtkSetVector3Macro(Normal,double);
		vtkSetMacro(Hit,bool);
 
	protected:
 
		vtkLidarPoint();
		~vtkLidarPoint();
	private:
		vtkLidarPoint(const vtkLidarPoint&);  // Not implemented.
		void operator=(const vtkLidarPoint&);  // Not implemented.
};
 
#endif

along with it's example implementation file:

#include "vtkLidarPoint.h"
#include "vtkObjectFactory.h" //for new() macro
 
vtkStandardNewMacro(vtkLidarPoint);
 
vtkLidarPoint::vtkLidarPoint()
{
	Hit = false;
}
 
vtkLidarPoint::~vtkLidarPoint() 
{
}
 
void vtkLidarPoint::PrintSelf(ostream &os, vtkIndent indent)
{
	if(Hit)
	{
	os << "Coordinate: " << Coordinate[0] << " " << Coordinate[1] << " " << Coordinate[2] << std::endl
			<< "Direction: " << Direction[0] << " " << Direction[1] << " " << Direction[2] << std::endl
			<< "Normal: " << Normal[0] << " " << Normal[1] << " " << Normal[2] << std::endl;
	}
	else
	{
		os << "Invalid!" << std::endl;
	}
 
}
Personal tools