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 #include "mitkProperties.h"
00019
00020 #include "mitkPlanarRectangle.h"
00021 #include "mitkGeometry2D.h"
00022
00023
00024 mitk::PlanarRectangle::PlanarRectangle()
00025 : FEATURE_ID_CIRCUMFERENCE( this->AddFeature( "Circumference", "mm" ) ),
00026 FEATURE_ID_AREA( this->AddFeature( "Area", "mm^2" ) )
00027 {
00028
00029 this->ResetNumberOfControlPoints( 4 );
00030 this->SetProperty( "closed", mitk::BoolProperty::New(true) );
00031
00032 m_PolyLines->InsertElement( 0, VertexContainerType::New());
00033 }
00034
00035
00036 mitk::PlanarRectangle::~PlanarRectangle()
00037 {
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 bool mitk::PlanarRectangle::SetControlPoint( unsigned int index, const Point2D &point, bool createIfDoesNotExist )
00068 {
00069
00070
00071
00072
00073
00074
00075 bool set = false;
00076
00077 if (createIfDoesNotExist)
00078 {
00079 m_ControlPoints->InsertElement( index, point );
00080 set = true;
00081 }
00082 else if ( index < this->GetNumberOfControlPoints() )
00083 {
00084 m_ControlPoints->InsertElement( index, point );
00085 set = true;
00086 }
00087
00088 if(set)
00089 {
00090
00091 unsigned int horizontalCorrespondingPointIndex = 1;
00092 unsigned int verticalCorrespondingPointIndex = 3;
00093 if(index == 1)
00094 {
00095 horizontalCorrespondingPointIndex = 0;
00096 verticalCorrespondingPointIndex = 2;
00097 }
00098 else if(index == 2)
00099 {
00100 horizontalCorrespondingPointIndex = 3;
00101 verticalCorrespondingPointIndex = 1;
00102 }
00103 else if(index == 3)
00104 {
00105 horizontalCorrespondingPointIndex = 2;
00106 verticalCorrespondingPointIndex = 0;
00107 }
00108
00109 m_ControlPoints->ElementAt( verticalCorrespondingPointIndex ).SetElement(0, point[0]);
00110 m_ControlPoints->ElementAt( horizontalCorrespondingPointIndex ).SetElement(1, point[1]);
00111 }
00112
00113 return set;
00114 }
00115
00116 void mitk::PlanarRectangle::PlaceFigure( const mitk::Point2D &point )
00117 {
00118 for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
00119 {
00120 m_ControlPoints->InsertElement( i, point );
00121 }
00122
00123 m_FigurePlaced = true;
00124 m_SelectedControlPoint = 3;
00125 }
00126
00127 void mitk::PlanarRectangle::GeneratePolyLine()
00128 {
00129
00130 m_PolyLines->ElementAt( 0 )->Reserve( this->GetNumberOfControlPoints() );
00131 for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
00132 {
00133 m_PolyLines->ElementAt( 0 )->ElementAt( i ) = m_ControlPoints->ElementAt( i );
00134 }
00135 }
00136
00137 void mitk::PlanarRectangle::GenerateHelperPolyLine(double , unsigned int )
00138 {
00139
00140 }
00141
00142 void mitk::PlanarRectangle::EvaluateFeaturesInternal()
00143 {
00144
00145 double circumference = 0.0;
00146 unsigned int i;
00147 for ( i = 0; i < this->GetNumberOfControlPoints(); ++i )
00148 {
00149 circumference += this->GetWorldControlPoint( i ).EuclideanDistanceTo(
00150 this->GetWorldControlPoint( (i + 1) % this->GetNumberOfControlPoints() ) );
00151 }
00152
00153 this->SetQuantity( FEATURE_ID_CIRCUMFERENCE, circumference );
00154
00155
00156
00157 double area = 0.0;
00158 if ( this->GetGeometry2D() != NULL )
00159 {
00160 for ( i = 0; i < this->GetNumberOfControlPoints(); ++i )
00161 {
00162 Point2D p0 = this->GetControlPoint( i );
00163 Point2D p1 = this->GetControlPoint( (i + 1) % this->GetNumberOfControlPoints() );
00164
00165 area += p0[0] * p1[1] - p1[0] * p0[1];
00166 }
00167 area /= 2.0;
00168 }
00169
00170 this->SetQuantity( FEATURE_ID_AREA, abs(area) );
00171
00172 }
00173
00174
00175 void mitk::PlanarRectangle::PrintSelf( std::ostream& os, itk::Indent indent) const
00176 {
00177 Superclass::PrintSelf( os, indent );
00178
00179 os << indent << "Number of control points: " << this->GetNumberOfControlPoints() << std::endl;
00180
00181 os << indent << "Control points:" << std::endl;
00182
00183 mitk::PlanarFigure::VertexContainerType::ConstIterator it;
00184
00185 for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
00186 {
00187 os << indent << indent << i << ": " << m_ControlPoints->ElementAt( i ) << std::endl;
00188 }
00189 }