OpenGL-based mapper to display a 2d cut through a poly data OpenGL-based mapper to display a 2D cut through a poly data. The result is normally a line. This class can be added to any data object, which is rendered in 3D via a vtkPolyData. More...
#include <mitkPolyDataGLMapper2D.h>
Public Types | |
typedef PolyDataGLMapper2D | Self |
typedef GLMapper2D | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | SetColorByCellData (bool _arg) |
virtual void | SetColorByPointData (bool _arg) |
virtual void | Paint (mitk::BaseRenderer *renderer) |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
PolyDataGLMapper2D () | |
virtual | ~PolyDataGLMapper2D () |
virtual vtkPolyDataMapper * | GetVtkPolyDataMapper () |
virtual vtkPolyData * | GetVtkPolyData () |
virtual vtkScalarsToColors * | GetVtkLUT () |
virtual bool | IsConvertibleToVtkPolyData () |
Protected Attributes | |
vtkPlane * | m_Plane |
vtkCutter * | m_Cutter |
bool | m_ColorByCellData |
bool | m_ColorByPointData |
OpenGL-based mapper to display a 2d cut through a poly data OpenGL-based mapper to display a 2D cut through a poly data. The result is normally a line. This class can be added to any data object, which is rendered in 3D via a vtkPolyData.
Definition at line 43 of file mitkPolyDataGLMapper2D.h.
typedef itk::SmartPointer<const Self> mitk::PolyDataGLMapper2D::ConstPointer |
Reimplemented from mitk::Mapper2D.
Definition at line 47 of file mitkPolyDataGLMapper2D.h.
typedef itk::SmartPointer<Self> mitk::PolyDataGLMapper2D::Pointer |
Reimplemented from mitk::Mapper2D.
Definition at line 47 of file mitkPolyDataGLMapper2D.h.
Reimplemented from mitk::Mapper2D.
Definition at line 47 of file mitkPolyDataGLMapper2D.h.
Reimplemented from mitk::Mapper2D.
Definition at line 47 of file mitkPolyDataGLMapper2D.h.
mitk::PolyDataGLMapper2D::PolyDataGLMapper2D | ( | ) | [protected] |
Definition at line 253 of file mitkPolyDataGLMapper2D.cpp.
{ m_Plane = vtkPlane::New(); m_Cutter = vtkCutter::New(); m_Cutter->SetCutFunction( m_Plane ); m_Cutter->GenerateValues( 1, 0, 1 ); m_ColorByCellData = false; m_ColorByPointData = false; //m_LUT = vtkLookupTable::New(); //m_LUT->SetTableRange( 0, 255 ); //m_LUT->SetNumberOfColors( 255 ); //m_LUT->SetRampToLinear (); //m_LUT->Build(); }
mitk::PolyDataGLMapper2D::~PolyDataGLMapper2D | ( | ) | [protected, virtual] |
Definition at line 273 of file mitkPolyDataGLMapper2D.cpp.
{}
virtual const char* mitk::PolyDataGLMapper2D::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::Mapper2D.
vtkScalarsToColors * mitk::PolyDataGLMapper2D::GetVtkLUT | ( | ) | [protected, virtual] |
Determines the LookupTable used by the associated vtkMapper. returns the LUT if possible, otherwise NULL.
Definition at line 238 of file mitkPolyDataGLMapper2D.cpp.
Referenced by Paint().
{ vtkPolyDataMapper * polyDataMapper = GetVtkPolyDataMapper(); if ( polyDataMapper == NULL ) return NULL; else return polyDataMapper->GetLookupTable(); }
vtkPolyData * mitk::PolyDataGLMapper2D::GetVtkPolyData | ( | ) | [protected, virtual] |
Determines the poly data object to be cut. returns the poly data if possible, otherwise NULL.
Definition at line 227 of file mitkPolyDataGLMapper2D.cpp.
Referenced by Paint().
{ vtkPolyDataMapper * polyDataMapper = GetVtkPolyDataMapper(); if ( polyDataMapper == NULL ) return NULL; else return polyDataMapper->GetInput(); }
vtkPolyDataMapper * mitk::PolyDataGLMapper2D::GetVtkPolyDataMapper | ( | ) | [protected, virtual] |
Determines, if the associated BaseData is mapped three-dimensionally (mapper-slot id 2) with a class convertable to vtkPolyDataMapper().
Definition at line 201 of file mitkPolyDataGLMapper2D.cpp.
{ return NULL; /* mitk::DataNode::ConstPointer node = this->GetDataNode(); if ( node.IsNull() ) return NULL; mitk::VtkMapper3D::Pointer mitkMapper = dynamic_cast< mitk::VtkMapper3D* > ( node->GetMapper( 2 ) ); if ( mitkMapper.IsNull() ) return NULL; mitkMapper->Update(NULL); vtkActor* actor = dynamic_cast<vtkActor*>( mitkMapper->GetVtkProp(0) ); if ( actor == NULL ) return NULL; return dynamic_cast<vtkPolyDataMapper*>( actor->GetMapper() ); */ }
bool mitk::PolyDataGLMapper2D::IsConvertibleToVtkPolyData | ( | ) | [protected, virtual] |
Checks if this mapper can be used to generate cuts through the associated base data.
Definition at line 248 of file mitkPolyDataGLMapper2D.cpp.
{ return ( GetVtkPolyDataMapper() != NULL ); }
static Pointer mitk::PolyDataGLMapper2D::New | ( | ) | [static] |
Referenced by mitk::CoreExtObjectFactory::CreateMapper().
void mitk::PolyDataGLMapper2D::Paint | ( | mitk::BaseRenderer * | renderer ) | [virtual] |
Renders a cut through a poly-data by lines.
renderer | the render to render in. |
Implements mitk::GLMapper2D.
Definition at line 48 of file mitkPolyDataGLMapper2D.cpp.
References mitk::GLMapper2D::ApplyProperties(), mitk::BaseRenderer::GetCurrentWorldGeometry2D(), mitk::Mapper::GetData(), mitk::Mapper::GetDataNode(), mitk::BaseRenderer::GetDisplayGeometry(), mitk::Geometry3D::GetOrigin(), GetVtkLUT(), GetVtkPolyData(), mitk::DataNode::GetVtkTransform(), GL_LINE_LOOP, glBegin(), glColor3f(), glEnd(), glVertex2f(), mitk::Mapper::IsVisible(), m_ColorByCellData, m_ColorByPointData, m_Cutter, and m_Plane.
{ if ( IsVisible( renderer ) == false ) return ; // ok, das ist aus GenerateData kopiert mitk::BaseData::Pointer input = const_cast<mitk::BaseData*>( GetData() ); assert( input ); input->Update(); vtkPolyData * vtkpolydata = this->GetVtkPolyData(); assert( vtkpolydata ); vtkLinearTransform * vtktransform = GetDataNode() ->GetVtkTransform(); if (vtktransform) { vtkLinearTransform * inversetransform = vtktransform->GetLinearInverse(); Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D(); PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const PlaneGeometry*>( worldGeometry.GetPointer() ); if ( vtkpolydata != NULL ) { Point3D point; Vector3D normal; if(worldPlaneGeometry.IsNotNull()) { // set up vtkPlane according to worldGeometry point=worldPlaneGeometry->GetOrigin(); normal=worldPlaneGeometry->GetNormal(); normal.Normalize(); m_Plane->SetTransform((vtkAbstractTransform*)NULL); } else { //@FIXME: does not work correctly. Does m_Plane->SetTransform really transforms a "plane plane" into a "curved plane"? return; AbstractTransformGeometry::ConstPointer worldAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(renderer->GetCurrentWorldGeometry2D()); if(worldAbstractGeometry.IsNotNull()) { // set up vtkPlane according to worldGeometry point=const_cast<mitk::BoundingBox*>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum(); FillVector3D(normal, 0, 0, 1); m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse()); } else return; } vtkFloatingPointType vp[ 3 ], vnormal[ 3 ]; vnl2vtk(point.Get_vnl_vector(), vp); vnl2vtk(normal.Get_vnl_vector(), vnormal); //normally, we would need to transform the surface and cut the transformed surface with the cutter. //This might be quite slow. Thus, the idea is, to perform an inverse transform of the plane instead. //@todo It probably does not work for scaling operations yet:scaling operations have to be //dealed with after the cut is performed by scaling the contour. inversetransform->TransformPoint( vp, vp ); inversetransform->TransformNormalAtPoint( vp, vnormal, vnormal ); m_Plane->SetOrigin( vp ); m_Plane->SetNormal( vnormal ); // set data into cutter m_Cutter->SetInput( vtkpolydata ); // m_Cutter->GenerateCutScalarsOff(); // m_Cutter->SetSortByToSortByCell(); // calculate the cut m_Cutter->Update(); // fetch geometry mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry(); assert( displayGeometry ); // float toGL=displayGeometry->GetSizeInDisplayUnits()[1]; //apply color and opacity read from the PropertyList ApplyProperties( renderer ); // traverse the cut contour vtkPolyData * contour = m_Cutter->GetOutput(); vtkPoints *vpoints = contour->GetPoints(); vtkCellArray *vpolys = contour->GetLines(); vtkPointData *vpointdata = contour->GetPointData(); vtkDataArray* vscalars = vpointdata->GetScalars(); vtkCellData *vcelldata = contour->GetCellData(); vtkDataArray* vcellscalars = vcelldata->GetScalars(); int i, numberOfCells = vpolys->GetNumberOfCells(); Point3D p; Point2D p2d, last, first; vpolys->InitTraversal(); vtkScalarsToColors* lut = GetVtkLUT(); assert ( lut != NULL ); for ( i = 0;i < numberOfCells;++i ) { vtkIdType *cell(NULL); vtkIdType cellSize(0); vpolys->GetNextCell( cellSize, cell ); if ( m_ColorByCellData ) { // color each cell according to cell data vtkFloatingPointType* color = lut->GetColor( vcellscalars->GetComponent( i, 0 ) ); glColor3f( color[ 0 ], color[ 1 ], color[ 2 ] ); } if ( m_ColorByPointData ) { vtkFloatingPointType* color = lut->GetColor( vscalars->GetComponent( cell[0], 0 ) ); glColor3f( color[ 0 ], color[ 1 ], color[ 2 ] ); } glBegin ( GL_LINE_LOOP ); for ( int j = 0;j < cellSize;++j ) { vpoints->GetPoint( cell[ j ], vp ); //take transformation via vtktransform into account vtktransform->TransformPoint( vp, vp ); vtk2itk( vp, p ); //convert 3D point (in mm) to 2D point on slice (also in mm) worldGeometry->Map( p, p2d ); //convert point (until now mm and in worldcoordinates) to display coordinates (units ) displayGeometry->WorldToDisplay( p2d, p2d ); //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left ) //p2d[1]=toGL-p2d[1]; //add the current vertex to the line glVertex2f( p2d[0], p2d[1] ); } glEnd (); } } } }
virtual void mitk::PolyDataGLMapper2D::SetColorByCellData | ( | bool | _arg ) | [virtual] |
Sets if the cut lines are colored by mapping cell data
virtual void mitk::PolyDataGLMapper2D::SetColorByPointData | ( | bool | _arg ) | [virtual] |
Sets if the cut lines are colored by mapping point data
bool mitk::PolyDataGLMapper2D::m_ColorByCellData [protected] |
Definition at line 103 of file mitkPolyDataGLMapper2D.h.
Referenced by Paint().
bool mitk::PolyDataGLMapper2D::m_ColorByPointData [protected] |
Definition at line 105 of file mitkPolyDataGLMapper2D.h.
Referenced by Paint().
vtkCutter* mitk::PolyDataGLMapper2D::m_Cutter [protected] |
Definition at line 101 of file mitkPolyDataGLMapper2D.h.
Referenced by Paint().
vtkPlane* mitk::PolyDataGLMapper2D::m_Plane [protected] |
Definition at line 99 of file mitkPolyDataGLMapper2D.h.
Referenced by Paint().