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 "mitkContourSet.h" 00020 00021 mitk::ContourSet::ContourSet() : 00022 m_ContourVector( ContourVectorType() ), 00023 m_NumberOfContours (0) 00024 { 00025 GetTimeSlicedGeometry()->Initialize(1); 00026 } 00027 00028 mitk::ContourSet::~ContourSet() 00029 { 00030 } 00031 00032 void mitk::ContourSet::AddContour(unsigned int index, mitk::Contour::Pointer contour) 00033 { 00034 m_ContourVector.insert(std::make_pair<unsigned long, mitk::Contour::Pointer>( index , contour) ); 00035 } 00036 00037 00038 void mitk::ContourSet::RemoveContour(unsigned long index) 00039 { 00040 m_ContourVector.erase( index ); 00041 } 00042 00043 void mitk::ContourSet::UpdateOutputInformation() 00044 { 00045 mitk::ContourSet::ContourVectorType contourVec = GetContours(); 00046 mitk::ContourSet::ContourIterator contoursIterator = contourVec.begin(); 00047 mitk::ContourSet::ContourIterator contoursIteratorEnd = contourVec.end(); 00048 00049 // initialize container 00050 mitk::BoundingBox::PointsContainer::Pointer pointscontainer=mitk::BoundingBox::PointsContainer::New(); 00051 00052 mitk::BoundingBox::PointIdentifier pointid=0; 00053 mitk::Point3D point; 00054 00055 mitk::AffineTransform3D* transform = GetTimeSlicedGeometry()->GetIndexToWorldTransform(); 00056 mitk::AffineTransform3D::Pointer inverse = mitk::AffineTransform3D::New(); 00057 transform->GetInverse(inverse); 00058 00059 // calculate a bounding box that includes all contours 00060 // \todo probably we should do this additionally for each time-step 00061 while (contoursIterator != contoursIteratorEnd) 00062 { 00063 const Geometry3D* geometry = (*contoursIterator).second->GetUpdatedTimeSlicedGeometry(); 00064 unsigned char i; 00065 for(i=0; i<8; ++i) 00066 { 00067 point = inverse->TransformPoint(geometry->GetCornerPoint(i)); 00068 if(point[0]*point[0]+point[1]*point[1]+point[2]*point[2] < mitk::large) 00069 pointscontainer->InsertElement( pointid++, point); 00070 else 00071 { 00072 itkGenericOutputMacro( << "Unrealistically distant corner point encountered. Ignored. BoundingObject: " << (*contoursIterator).second ); 00073 } 00074 } 00075 ++contoursIterator; 00076 } 00077 00078 mitk::BoundingBox::Pointer boundingBox = mitk::BoundingBox::New(); 00079 boundingBox->SetPoints(pointscontainer); 00080 boundingBox->ComputeBoundingBox(); 00081 00082 Geometry3D* geometry3d = GetGeometry(0); 00083 geometry3d->SetIndexToWorldTransform(transform); 00084 geometry3d->SetBounds(boundingBox->GetBounds()); 00085 00086 GetTimeSlicedGeometry()->InitializeEvenlyTimed(geometry3d, GetTimeSlicedGeometry()->GetTimeSteps()); 00087 } 00088 00089 void mitk::ContourSet::SetRequestedRegionToLargestPossibleRegion() 00090 { 00091 } 00092 00093 bool mitk::ContourSet::RequestedRegionIsOutsideOfTheBufferedRegion() 00094 { 00095 return true; 00096 } 00097 00098 bool mitk::ContourSet::VerifyRequestedRegion() 00099 { 00100 return true; 00101 } 00102 00103 void mitk::ContourSet::SetRequestedRegion(itk::DataObject*) 00104 { 00105 } 00106 00107 void mitk::ContourSet::Initialize() 00108 { 00109 m_ContourVector = ContourVectorType(); 00110 GetTimeSlicedGeometry()->Initialize(1); 00111 } 00112 00113 00114 unsigned int mitk::ContourSet::GetNumberOfContours() 00115 { 00116 return m_ContourVector.size(); 00117 } 00118 00119 mitk::ContourSet::ContourVectorType mitk::ContourSet::GetContours() 00120 { 00121 return m_ContourVector; 00122 }