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 "mitkContourMapper2D.h"
00020 #include "mitkBaseRenderer.h"
00021 #include "mitkPlaneGeometry.h"
00022 #include "mitkColorProperty.h"
00023 #include "mitkProperties.h"
00024 #include "mitkContour.h"
00025 #include <vtkLinearTransform.h>
00026
00027 #include "mitkGL.h"
00028
00029 mitk::ContourMapper2D::ContourMapper2D()
00030 {
00031 }
00032
00033 mitk::ContourMapper2D::~ContourMapper2D()
00034 {
00035 }
00036
00037
00038 void mitk::ContourMapper2D::Paint(mitk::BaseRenderer * renderer)
00039 {
00040 if(IsVisible(renderer)==false) return;
00041
00043 bool updateNeccesary=true;
00044
00045 if (updateNeccesary)
00046 {
00047 mitk::Contour::Pointer input = const_cast<mitk::Contour*>(this->GetInput());
00048
00049
00050 mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
00051 assert(displayGeometry.IsNotNull());
00052
00053
00054 ApplyProperties(renderer);
00055
00056 vtkLinearTransform* transform = GetDataNode()->GetVtkTransform();
00057
00058
00059 Contour::BoundingBoxType::PointType point;
00060
00061 mitk::Point3D p, projected_p;
00062 float vtkp[3];
00063 float lineWidth = 3.0;
00064
00065 if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("Width")) != NULL)
00066 lineWidth = dynamic_cast<mitk::FloatProperty*>(this->GetDataNode()->GetProperty("Width"))->GetValue();
00067 glLineWidth(lineWidth);
00068
00069 if (input->GetClosed())
00070 {
00071 glBegin (GL_LINE_LOOP);
00072 }
00073 else
00074 {
00075 glBegin (GL_LINE_STRIP);
00076 }
00077
00078
00079
00080
00081 mitk::Contour::PointsContainerPointer points = input->GetPoints();
00082 mitk::Contour::PointsContainerIterator pointsIt = points->Begin();
00083
00084
00085
00086 while ( pointsIt != points->End() )
00087 {
00088
00089
00090
00091 point = pointsIt.Value();
00092
00093 itk2vtk(point, vtkp);
00094 transform->TransformPoint(vtkp, vtkp);
00095 vtk2itk(vtkp,p);
00096
00097 displayGeometry->Project(p, projected_p);
00098 bool projectmode=false;
00099 GetDataNode()->GetVisibility(projectmode, renderer, "project");
00100 bool drawit=false;
00101 if(projectmode)
00102 drawit=true;
00103 else
00104 {
00105 Vector3D diff=p-projected_p;
00106 if(diff.GetSquaredNorm()<1.0)
00107 drawit=true;
00108 }
00109 if(drawit)
00110 {
00111 Point2D pt2d, tmp;
00112 displayGeometry->Map(projected_p, pt2d);
00113 displayGeometry->WorldToDisplay(pt2d, pt2d);
00114 glVertex2f(pt2d[0], pt2d[1]);
00115 }
00116
00117 pointsIt++;
00118
00119 }
00120 glEnd ();
00121
00122 glLineWidth(1.0);
00123
00124 }
00125 }
00126
00127 const mitk::Contour* mitk::ContourMapper2D::GetInput(void)
00128 {
00129 return static_cast<const mitk::Contour * > ( GetData() );
00130 }