00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #include "mitkContourSetMapper2D.h" 00020 #include "mitkBaseRenderer.h" 00021 #include "mitkPlaneGeometry.h" 00022 #include "mitkColorProperty.h" 00023 #include "mitkContourSet.h" 00024 #include "mitkProperties.h" 00025 #include <vtkLinearTransform.h> 00026 00027 #include "mitkGL.h" 00028 00029 mitk::ContourSetMapper2D::ContourSetMapper2D() 00030 { 00031 } 00032 00033 mitk::ContourSetMapper2D::~ContourSetMapper2D() 00034 { 00035 } 00036 00037 00038 void mitk::ContourSetMapper2D::Paint(mitk::BaseRenderer * renderer) 00039 { 00040 if(IsVisible(renderer)==false) return; 00041 00043 bool updateNeccesary=true; 00044 00045 if (updateNeccesary) 00046 { 00047 // ok, das ist aus GenerateData kopiert 00048 mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry(); 00049 assert(displayGeometry.IsNotNull()); 00050 00051 //apply color and opacity read from the PropertyList 00052 ApplyProperties(renderer); 00053 00054 mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet*>(this->GetInput()); 00055 mitk::ContourSet::ContourVectorType contourVec = input->GetContours(); 00056 mitk::ContourSet::ContourIterator contourIt = contourVec.begin(); 00057 00058 while ( contourIt != contourVec.end() ) 00059 { 00060 mitk::Contour::Pointer nextContour = (mitk::Contour::Pointer) (*contourIt).second; 00061 vtkLinearTransform* transform = GetDataNode()->GetVtkTransform(); 00062 00063 // Contour::OutputType point; 00064 Contour::BoundingBoxType::PointType point; 00065 00066 mitk::Point3D p, projected_p; 00067 float vtkp[3]; 00068 00069 glLineWidth( nextContour->GetWidth() ); 00070 00071 if (nextContour->GetClosed()) 00072 { 00073 glBegin (GL_LINE_LOOP); 00074 } 00075 else 00076 { 00077 glBegin (GL_LINE_STRIP); 00078 } 00079 00080 00081 //float rgba[4]={1.0f,1.0f,1.0f,1.0f}; 00082 //if ( nextContour->GetSelected() ) 00083 //{ 00084 // rgba[0] = 1.0; 00085 // rgba[1] = 0.0; 00086 // rgba[2] = 0.0; 00087 //} 00088 //glColor4fv(rgba); 00089 00090 mitk::Contour::PointsContainerPointer points = nextContour->GetPoints(); 00091 mitk::Contour::PointsContainerIterator pointsIt = points->Begin(); 00092 00093 while ( pointsIt != points->End() ) 00094 { 00095 point = pointsIt.Value(); 00096 00097 itk2vtk(point, vtkp); 00098 transform->TransformPoint(vtkp, vtkp); 00099 vtk2itk(vtkp,p); 00100 00101 displayGeometry->Project(p, projected_p); 00102 Vector3D diff=p-projected_p; 00103 if(diff.GetSquaredNorm()<1.0) 00104 { 00105 Point2D pt2d, tmp; 00106 displayGeometry->Map(projected_p, pt2d); 00107 displayGeometry->WorldToDisplay(pt2d, pt2d); 00108 glVertex2f(pt2d[0], pt2d[1]); 00109 } 00110 00111 pointsIt++; 00112 // idx += 1; 00113 } 00114 00115 00116 glEnd (); 00117 00118 glLineWidth(1.0); 00119 00120 contourIt++; 00121 } 00122 } 00123 } 00124 00125 const mitk::ContourSet* mitk::ContourSetMapper2D::GetInput(void) 00126 { 00127 return static_cast<const mitk::ContourSet * > ( GetData() ); 00128 }