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 "mitkPlanarFigure.h"
00020 #include "mitkGeometry2D.h"
00021 #include "mitkProperties.h"
00022
00023
00024 mitk::PlanarFigure::PlanarFigure()
00025 : m_FigurePlaced( false ),
00026 m_SelectedControlPoint( -1 ),
00027 m_Geometry2D( NULL ),
00028 m_FeaturesMTime( 0 )
00029 {
00030 m_ControlPoints = VertexContainerType::New();
00031 m_PolyLines = VertexContainerVectorType::New();
00032 m_HelperPolyLines = VertexContainerVectorType::New();
00033 m_HelperPolyLinesToBePainted = BoolContainerType::New();
00034
00035 this->SetProperty( "closed", mitk::BoolProperty::New( false ) );
00036
00037
00038 this->InitializeTimeSlicedGeometry( 1 );
00039 }
00040
00041
00042 mitk::PlanarFigure::~PlanarFigure()
00043 {
00044 }
00045
00046
00047 void mitk::PlanarFigure::SetGeometry2D( mitk::Geometry2D *geometry )
00048 {
00049 this->SetGeometry( geometry );
00050 m_Geometry2D = geometry;
00051 }
00052
00053
00054 const mitk::Geometry2D *mitk::PlanarFigure::GetGeometry2D() const
00055 {
00056 return m_Geometry2D;
00057 }
00058
00059
00060 bool mitk::PlanarFigure::IsClosed() const
00061 {
00062 mitk::BoolProperty* closed = dynamic_cast< mitk::BoolProperty* >( this->GetProperty( "closed" ).GetPointer() );
00063 if ( closed != NULL )
00064 {
00065 return closed->GetValue();
00066 }
00067 return false;
00068 }
00069
00070
00071 void mitk::PlanarFigure::PlaceFigure( const mitk::Point2D& point )
00072 {
00073 for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
00074 {
00075 m_ControlPoints->InsertElement( i, this->ApplyControlPointConstraints( i, point ) );
00076 }
00077
00078 m_FigurePlaced = true;
00079 m_SelectedControlPoint = 1;
00080 }
00081
00082
00083 bool mitk::PlanarFigure::AddControlPoint( const mitk::Point2D& point )
00084 {
00085 if ( m_NumberOfControlPoints < this->GetMaximumNumberOfControlPoints() )
00086 {
00087 m_ControlPoints->InsertElement( m_NumberOfControlPoints,
00088 this->ApplyControlPointConstraints( m_NumberOfControlPoints, point ) );
00089 ++m_NumberOfControlPoints;
00090 ++m_SelectedControlPoint;
00091 return true;
00092 }
00093 else
00094 {
00095 return false;
00096 }
00097 }
00098
00099
00100 bool mitk::PlanarFigure::SetControlPoint( unsigned int index, const Point2D& point, bool createIfDoesNotExist )
00101 {
00102 if (createIfDoesNotExist)
00103 {
00104 m_ControlPoints->InsertElement( index, this->ApplyControlPointConstraints( index, point ) );
00105 if ( m_NumberOfControlPoints <= index )
00106 {
00107 m_NumberOfControlPoints = index + 1;
00108 }
00109 return true;
00110 }
00111 else if ( index < m_NumberOfControlPoints )
00112 {
00113 m_ControlPoints->InsertElement( index, this->ApplyControlPointConstraints( index, point ) );
00114 return true;
00115 }
00116 else
00117 {
00118 return false;
00119 }
00120 }
00121
00122
00123 bool mitk::PlanarFigure::SetCurrentControlPoint( const Point2D& point )
00124 {
00125 if ( (m_SelectedControlPoint < 0) || (m_SelectedControlPoint >= (int)m_NumberOfControlPoints) )
00126 {
00127 return false;
00128 }
00129
00130 return this->SetControlPoint(m_SelectedControlPoint, point, false);
00131 }
00132
00133
00134 unsigned int mitk::PlanarFigure::GetNumberOfControlPoints() const
00135 {
00136 return m_NumberOfControlPoints;
00137 }
00138
00139
00140
00141
00142 bool mitk::PlanarFigure::SelectControlPoint( unsigned int index )
00143 {
00144 if ( index < this->GetNumberOfControlPoints() )
00145 {
00146 m_SelectedControlPoint = index;
00147 return true;
00148 }
00149 else
00150 {
00151 return false;
00152 }
00153 }
00154
00155
00156 void mitk::PlanarFigure::DeselectControlPoint()
00157 {
00158 m_SelectedControlPoint = -1;
00159 }
00160
00161
00162 const mitk::PlanarFigure::VertexContainerType *
00163 mitk::PlanarFigure::GetControlPoints() const
00164 {
00165 return m_ControlPoints;
00166 }
00167
00168
00169 mitk::PlanarFigure::VertexContainerType *
00170 mitk::PlanarFigure::GetControlPoints()
00171 {
00172 return m_ControlPoints;
00173 }
00174
00175
00176 mitk::Point2D& mitk::PlanarFigure::GetControlPoint( unsigned int index ) const
00177 {
00178 if ( index < m_NumberOfControlPoints )
00179 {
00180 return m_ControlPoints->ElementAt( index );
00181 }
00182
00183 itkExceptionMacro( << "GetControlPoint(): Invalid index!" );
00184 }
00185
00186
00187 mitk::Point3D mitk::PlanarFigure::GetWorldControlPoint( unsigned int index ) const
00188 {
00189 Point3D point3D;
00190 if ( (m_Geometry2D != NULL) && (index < m_NumberOfControlPoints) )
00191 {
00192 m_Geometry2D->Map( m_ControlPoints->ElementAt( index ), point3D );
00193 return point3D;
00194 }
00195
00196 itkExceptionMacro( << "GetWorldControlPoint(): Invalid index!" );
00197 }
00198
00199
00200 mitk::PlanarFigure::VertexContainerType *
00201 mitk::PlanarFigure::GetPolyLine(unsigned int index)
00202 {
00203 if ( !m_PolyLines->IndexExists( index ) || (m_PolyLines->ElementAt( index )->GetMTime() < m_ControlPoints->GetMTime()) )
00204 {
00205 this->GeneratePolyLine();
00206 }
00207
00208 return m_PolyLines->ElementAt( index );
00209 }
00210
00211
00212 const mitk::PlanarFigure::VertexContainerType *
00213 mitk::PlanarFigure::GetPolyLine(unsigned int index) const
00214 {
00215 return m_PolyLines->ElementAt( index );
00216 }
00217
00218
00219 const mitk::PlanarFigure::VertexContainerType *
00220 mitk::PlanarFigure::GetHelperPolyLine(unsigned int index, double mmPerDisplayUnit, unsigned int displayHeight)
00221 {
00222 if ((m_HelperPolyLines->ElementAt( index )) && (m_HelperPolyLines->ElementAt( index )->GetMTime() < m_ControlPoints->GetMTime()) )
00223 {
00224 this->GenerateHelperPolyLine(mmPerDisplayUnit, displayHeight);
00225 }
00226
00227 return m_HelperPolyLines->ElementAt( index );
00228 }
00229
00232 unsigned int mitk::PlanarFigure::GetNumberOfFeatures() const
00233 {
00234 return m_Features.size();
00235 }
00236
00237
00238 const char *mitk::PlanarFigure::GetFeatureName( unsigned int index ) const
00239 {
00240 if ( index < m_Features.size() )
00241 {
00242 return m_Features[index].Name.c_str();
00243 }
00244 else
00245 {
00246 return NULL;
00247 }
00248 }
00249
00250
00251 const char *mitk::PlanarFigure::GetFeatureUnit( unsigned int index ) const
00252 {
00253 if ( index < m_Features.size() )
00254 {
00255 return m_Features[index].Unit.c_str();
00256 }
00257 else
00258 {
00259 return NULL;
00260 }
00261 }
00262
00263
00264 double mitk::PlanarFigure::GetQuantity( unsigned int index ) const
00265 {
00266 if ( index < m_Features.size() )
00267 {
00268 return m_Features[index].Quantity;
00269 }
00270 else
00271 {
00272 return 0.0;
00273 }
00274 }
00275
00276
00277 bool mitk::PlanarFigure::IsFeatureActive( unsigned int index ) const
00278 {
00279 if ( index < m_Features.size() )
00280 {
00281 return m_Features[index].Active;
00282 }
00283 else
00284 {
00285 return false;
00286 }
00287 }
00288
00289
00290 void mitk::PlanarFigure::EvaluateFeatures()
00291 {
00292 if ( m_FeaturesMTime < m_ControlPoints->GetMTime() )
00293 {
00294 this->EvaluateFeaturesInternal();
00295
00296 m_FeaturesMTime = m_ControlPoints->GetMTime();
00297 }
00298 }
00299
00300
00301 void mitk::PlanarFigure::UpdateOutputInformation()
00302 {
00303
00304
00305 Superclass::UpdateOutputInformation();
00306 this->GetTimeSlicedGeometry()->UpdateInformation();
00307 }
00308
00309
00310 void mitk::PlanarFigure::SetRequestedRegionToLargestPossibleRegion()
00311 {
00312 }
00313
00314
00315 bool mitk::PlanarFigure::RequestedRegionIsOutsideOfTheBufferedRegion()
00316 {
00317 return false;
00318 }
00319
00320
00321 bool mitk::PlanarFigure::VerifyRequestedRegion()
00322 {
00323 return true;
00324 }
00325
00326
00327 void mitk::PlanarFigure::SetRequestedRegion( itk::DataObject * )
00328 {
00329
00330 }
00331
00332
00333 void mitk::PlanarFigure::ResetNumberOfControlPoints( int numberOfControlPoints )
00334 {
00335 m_NumberOfControlPoints = numberOfControlPoints;
00336 }
00337
00338
00339 mitk::Point2D mitk::PlanarFigure::ApplyControlPointConstraints( unsigned int , const Point2D& point )
00340 {
00341 if ( m_Geometry2D == NULL )
00342 {
00343 return point;
00344 }
00345
00346 Point2D indexPoint;
00347 m_Geometry2D->WorldToIndex( point, indexPoint );
00348
00349 BoundingBox::BoundsArrayType bounds = m_Geometry2D->GetBounds();
00350 if ( indexPoint[0] < bounds[0] ) { indexPoint[0] = bounds[0]; }
00351 if ( indexPoint[0] > bounds[1] ) { indexPoint[0] = bounds[1]; }
00352 if ( indexPoint[1] < bounds[2] ) { indexPoint[1] = bounds[2]; }
00353 if ( indexPoint[1] > bounds[3] ) { indexPoint[1] = bounds[3]; }
00354
00355 Point2D constrainedPoint;
00356 m_Geometry2D->IndexToWorld( indexPoint, constrainedPoint );
00357
00358 return constrainedPoint;
00359 }
00360
00361
00362 unsigned int mitk::PlanarFigure::AddFeature( const char *featureName, const char *unitName )
00363 {
00364 unsigned int index = m_Features.size();
00365
00366 Feature newFeature( featureName, unitName );
00367 m_Features.push_back( newFeature );
00368
00369 return index;
00370 }
00371
00372
00373 void mitk::PlanarFigure::SetFeatureName( unsigned int index, const char *featureName )
00374 {
00375 if ( index < m_Features.size() )
00376 {
00377 m_Features[index].Name = featureName;
00378 }
00379 }
00380
00381
00382 void mitk::PlanarFigure::SetFeatureUnit( unsigned int index, const char *unitName )
00383 {
00384 if ( index < m_Features.size() )
00385 {
00386 m_Features[index].Unit = unitName;
00387 }
00388 }
00389
00390
00391 void mitk::PlanarFigure::SetQuantity( unsigned int index, double quantity )
00392 {
00393 if ( index < m_Features.size() )
00394 {
00395 m_Features[index].Quantity = quantity;
00396 }
00397 }
00398
00399
00400 void mitk::PlanarFigure::ActivateFeature( unsigned int index )
00401 {
00402 if ( index < m_Features.size() )
00403 {
00404 m_Features[index].Active = true;
00405 }
00406 }
00407
00408
00409 void mitk::PlanarFigure::DeactivateFeature( unsigned int index )
00410 {
00411 if ( index < m_Features.size() )
00412 {
00413 m_Features[index].Active = false;
00414 }
00415 }
00416
00417
00418 void mitk::PlanarFigure::InitializeTimeSlicedGeometry( unsigned int timeSteps )
00419 {
00420 mitk::TimeSlicedGeometry::Pointer timeGeometry = this->GetTimeSlicedGeometry();
00421
00422 mitk::Geometry2D::Pointer geometry2D = mitk::Geometry2D::New();
00423 geometry2D->Initialize();
00424
00425 if ( timeSteps > 1 )
00426 {
00427 mitk::ScalarType timeBounds[] = {0.0, 1.0};
00428 geometry2D->SetTimeBounds( timeBounds );
00429 }
00430
00431
00432
00433 timeGeometry->InitializeEvenlyTimed( geometry2D, timeSteps );
00434 }
00435
00436
00437 void mitk::PlanarFigure::PrintSelf( std::ostream& os, itk::Indent indent) const
00438 {
00439 Superclass::PrintSelf( os, indent );
00440 os << indent << this->GetNameOfClass() << ":\n";
00441
00442 if (this->IsClosed())
00443 os << indent << "This figure is closed\n";
00444 else
00445 os << indent << "This figure is not closed\n";
00446 os << indent << "Minimum number of control points: " << this->GetMinimumNumberOfControlPoints() << std::endl;
00447 os << indent << "Maximum number of control points: " << this->GetMaximumNumberOfControlPoints() << std::endl;
00448 os << indent << "Current number of control points: " << this->GetNumberOfControlPoints() << std::endl;
00449 os << indent << "Control points:" << std::endl;
00450 mitk::PlanarFigure::VertexContainerType::ConstIterator it;
00451 for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
00452 {
00453 os << indent.GetNextIndent() << i << ": " << m_ControlPoints->ElementAt( i ) << std::endl;
00454 }
00455 os << indent << "Geometry:\n";
00456 this->GetGeometry2D()->Print(os, indent.GetNextIndent());
00457 }
00458
00459
00460 unsigned short mitk::PlanarFigure::GetPolyLinesSize()
00461 {
00462 if ( m_PolyLines->GetMTime() < m_ControlPoints->GetMTime() )
00463 {
00464 this->GeneratePolyLine();
00465 }
00466 return m_PolyLines->size();
00467 }
00468
00469
00470 unsigned short mitk::PlanarFigure::GetHelperPolyLinesSize()
00471 {
00472 return m_HelperPolyLines->size();
00473 }
00474
00475
00476 bool mitk::PlanarFigure::IsHelperToBePainted(unsigned int index)
00477 {
00478 return m_HelperPolyLinesToBePainted->GetElement( index );
00479 }
00480
00481
00482 bool mitk::PlanarFigure::ResetOnPointSelect()
00483 {
00484 return false;
00485 }
00486
00487 void mitk::PlanarFigure::RemoveLastControlPoint()
00488 {
00489 m_ControlPoints->DeleteIndex( this->GetNumberOfControlPoints()-1 );
00490 this->ResetNumberOfControlPoints( this->GetNumberOfControlPoints()-1 );
00491 this->GeneratePolyLine();
00492 }
00493
00494 void mitk::PlanarFigure::DeepCopy(Self::Pointer oldFigure)
00495 {
00496
00497
00498 if(typeid(*oldFigure) != typeid(*this))
00499 {
00500 itkExceptionMacro( << "DeepCopy(): Inconsistent type of source and destination figure!" );
00501 return;
00502 }
00503
00504
00505 SetPropertyList(oldFigure->GetPropertyList()->Clone());
00506
00508 m_FigurePlaced = oldFigure->m_FigurePlaced;
00509 m_SelectedControlPoint = oldFigure->m_SelectedControlPoint;
00510 m_FeaturesMTime = oldFigure->m_FeaturesMTime;
00511 m_Features = oldFigure->m_Features;
00512 m_NumberOfControlPoints = oldFigure->m_NumberOfControlPoints;
00513
00514
00515 SetGeometry2D((mitk::Geometry2D*)oldFigure->m_Geometry2D->Clone().GetPointer());
00516
00517 m_ControlPoints = VertexContainerType::New();
00518 for(unsigned long index=0; index < oldFigure->m_ControlPoints->Size(); index++)
00519 {
00520 m_ControlPoints->InsertElement(index, oldFigure->m_ControlPoints->ElementAt( index ));
00521 }
00522
00523
00524 this->GeneratePolyLine();
00525 }