Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkSplineMapper2D.h"
00020 #include "mitkSplineVtkMapper3D.h"
00021 #include <mitkPlaneGeometry.h>
00022 #include <mitkVector.h>
00023 #include <mitkGeometry2D.h>
00024 #include <mitkGL.h>
00025 #include <vtkLinearTransform.h>
00026 #include <vtkPoints.h>
00027 #include <vtkCellArray.h>
00028 #include <vtkPolyData.h>
00029
00030 void mitk::SplineMapper2D::Paint ( mitk::BaseRenderer * renderer )
00031 {
00032 Superclass::Paint ( renderer );
00033 if ( IsVisible ( renderer ) == false )
00034 return;
00035
00036
00037
00038
00039 mitk::SplineVtkMapper3D::Pointer mapper3D = dynamic_cast<mitk::SplineVtkMapper3D*> ( this->GetDataNode()->GetMapper ( 2 ) );
00040 if ( mapper3D.IsNull() )
00041 {
00042 itkWarningMacro ( "Mapper used for 3D mapping is not a mitk::SplineVtkMapper3D!" );
00043 return;
00044 }
00045
00046
00047
00048 if ( mapper3D->GetLastUpdateTime() < GetDataNode()->GetData()->GetMTime() )
00049 mapper3D->UpdateSpline();
00050 vtkPolyData* spline3D = NULL;
00051 if ( mapper3D->SplinesAreAvailable() )
00052 spline3D = mapper3D->GetSplinesPolyData();
00053 else
00054 return;
00055 if ( spline3D == NULL )
00056 {
00057 itkWarningMacro ( "3D spline is not available!" );
00058 return;
00059 }
00060
00061
00062
00063 vtkLinearTransform* transform = this->GetDataNode()->GetVtkTransform();
00064 if ( transform == NULL )
00065 {
00066 itkWarningMacro("transfrom is NULL");
00067 }
00068
00069
00070
00071
00072 mitk::Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D();
00073 if ( worldGeometry.IsNull() )
00074 {
00075 itkWarningMacro("worldGeometry is NULL!");
00076 return;
00077 }
00078 PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const mitk::PlaneGeometry*> ( worldGeometry.GetPointer() );
00079 if ( worldPlaneGeometry.IsNull() )
00080 {
00081 itkWarningMacro("worldPlaneGeometry is NULL!");
00082 return;
00083 }
00084
00085
00086
00087
00088 float color[3];
00089 this->GetDataNode()->GetColor ( color, renderer );
00090
00091
00092
00093
00094 vtkPoints *vpoints = spline3D->GetPoints();
00095 vtkCellArray *vlines = spline3D->GetLines();
00096 if (vpoints == NULL)
00097 {
00098 itkWarningMacro("points are NULL!");
00099 return;
00100 }
00101 if (vlines == NULL)
00102 {
00103 itkWarningMacro("lines are NULL!");
00104 return;
00105 }
00106
00107 mitk::Point3D currentPoint3D;
00108 mitk::Point2D currentPoint2D;
00109 vtkFloatingPointType currentPoint3DVtk[3];
00110
00111 vlines->InitTraversal();
00112 int numberOfLines = vlines->GetNumberOfCells();
00113 vtkFloatingPointType currentPointDistance;
00114 for ( int i = 0;i < numberOfLines; ++i )
00115 {
00116 bool previousPointOnPlane = false;
00117 bool currentPointOnPlane = false;
00118 vtkIdType* cell ( NULL );
00119 vtkIdType cellSize ( 0 );
00120 vlines->GetNextCell ( cellSize, cell );
00121 for ( int j = 0 ; j < cellSize; ++j )
00122 {
00123 vpoints->GetPoint ( cell[j], currentPoint3DVtk );
00124
00125
00126 transform->TransformPoint ( currentPoint3DVtk, currentPoint3DVtk );
00127 vtk2itk ( currentPoint3DVtk, currentPoint3D );
00128
00129
00130
00131 currentPointDistance = worldPlaneGeometry->DistanceFromPlane ( currentPoint3D );
00132
00133 if ( currentPointDistance < m_MaxProjectionDistance )
00134 {
00135 currentPointOnPlane = true;
00136
00137 worldGeometry->Map ( currentPoint3D, currentPoint2D );
00138
00139 renderer->GetDisplayGeometry()->WorldToDisplay ( currentPoint2D, currentPoint2D );
00140 }
00141 else
00142 currentPointOnPlane = false;
00143
00144
00145
00146
00147 if ( ( previousPointOnPlane == false ) && ( currentPointOnPlane == true ) )
00148 {
00149 glLineWidth ( m_LineWidth );
00150 glColor3f ( color[0], color[1], color[2] );
00151 glBegin ( GL_LINE_STRIP );
00152 }
00153 else if ( ( previousPointOnPlane == true ) && ( currentPointOnPlane == false ) )
00154 {
00155 glEnd ();
00156 glLineWidth ( 1.0 );
00157 }
00158
00159
00160 if ( currentPointOnPlane == true )
00161 {
00162 glVertex2f ( currentPoint2D[0], currentPoint2D[1] );
00163 }
00164 previousPointOnPlane = currentPointOnPlane;
00165 }
00166
00167
00168 if ( previousPointOnPlane == true )
00169 {
00170 glEnd ();
00171 glLineWidth ( 1.0 );
00172 }
00173 previousPointOnPlane = false;
00174 }
00175 }
00176
00177 void mitk::SplineMapper2D::ApplyProperties ( mitk::BaseRenderer* renderer )
00178 {
00179 Superclass::ApplyProperties ( renderer );
00180 }
00181
00182 mitk::SplineMapper2D::SplineMapper2D()
00183 {
00184 m_MaxProjectionDistance = 1;
00185 m_ShowDistantLines = false ;
00186 m_LineWidth = 1;
00187 }
00188
00189 mitk::SplineMapper2D::~SplineMapper2D()
00190 {}