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 "mitkPlanarAngle.h"
00020 #include "mitkGeometry2D.h"
00021
00022
00023 mitk::PlanarAngle::PlanarAngle()
00024 : FEATURE_ID_ANGLE( this->AddFeature( "Angle", "deg" ) )
00025 {
00026
00027 this->ResetNumberOfControlPoints( 2 );
00028
00029 m_PolyLines->InsertElement( 0, VertexContainerType::New());
00030 m_HelperPolyLines->InsertElement( 0, VertexContainerType::New());
00031 m_HelperPolyLinesToBePainted->InsertElement( 0, false );
00032 }
00033
00034
00035 mitk::PlanarAngle::~PlanarAngle()
00036 {
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 void mitk::PlanarAngle::GeneratePolyLine()
00068 {
00069
00070 m_PolyLines->ElementAt( 0 )->Reserve( m_ControlPoints->Size() );
00071
00072 for ( unsigned int i = 0; i < m_ControlPoints->Size(); ++i )
00073 {
00074 m_PolyLines->ElementAt( 0 )->ElementAt( i ) = m_ControlPoints->ElementAt( i );
00075 }
00076 }
00077
00078 void mitk::PlanarAngle::GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight)
00079 {
00080
00081 if ( m_ControlPoints->Size() < 3)
00082 {
00083 m_HelperPolyLinesToBePainted->SetElement(0, false);
00084 return;
00085 }
00086 m_HelperPolyLines->ElementAt( 0 )->Reserve( 3 );
00087 const Point2D ¢erPoint = m_ControlPoints->ElementAt( 1 );
00088 const Point2D &boundaryPointOne = m_ControlPoints->ElementAt( 0 );
00089 const Point2D &boundaryPointTwo = m_ControlPoints->ElementAt( 2 );
00090
00091 double radius = centerPoint.EuclideanDistanceTo( boundaryPointOne );
00092 if ( radius > centerPoint.EuclideanDistanceTo( boundaryPointTwo ) )
00093 {
00094 radius = centerPoint.EuclideanDistanceTo( boundaryPointTwo );
00095 }
00096
00097
00098 double nonScalingRadius = displayHeight * mmPerDisplayUnit * 0.05;
00099
00100 if (nonScalingRadius > radius)
00101 {
00102 m_HelperPolyLinesToBePainted->SetElement(0, false);
00103 return;
00104 }
00105
00106 m_HelperPolyLinesToBePainted->SetElement(0, true);
00107 radius = nonScalingRadius;
00108
00109 double angle = this->GetQuantity( FEATURE_ID_ANGLE );
00110
00111
00112
00113 Vector2D v0 = boundaryPointOne - centerPoint;
00114 Vector2D v1 = boundaryPointTwo - centerPoint;
00115 Vector2D v2;
00116 v2[0] = 1.0;
00117 v2[1] = 0.0;
00118
00119 v0[0] = v0[0] * cos( 0.001 ) - v0[1] * sin( 0.001 );
00120 v0[1] = v0[0] * sin( 0.001 ) + v0[1] * cos( 0.001 );
00121 v0.Normalize();
00122 v1.Normalize();
00123 double testAngle = acos( v0 * v1 );
00124
00125
00126 if( angle > testAngle )
00127 {
00128 v1[0] = v0[0] * cos( -0.001 ) - v0[1] * sin( -0.001 );
00129 v1[1] = v0[0] * sin( -0.001 ) + v0[1] * cos( -0.001 );
00130
00131
00132
00133 if ( acos( v0 * v2 ) > acos ( v1 * v2 ))
00134 {
00135 testAngle = acos( v1 * v2 );
00136 }
00137 else
00138 {
00139 testAngle = -acos( v1 * v2 );
00140 }
00141 }
00142 else
00143 {
00144 v0[0] = v1[0] * cos( -0.001 ) - v1[1] * sin( -0.001 );
00145 v0[1] = v1[0] * sin( -0.001 ) + v1[1] * cos( -0.001 );
00146
00147
00148 if ( acos( v0 * v2 ) < acos ( v1 * v2 ))
00149 {
00150 testAngle = acos( v1 * v2 );
00151 }
00152 else
00153 {
00154 testAngle = -acos( v1 * v2 );
00155 }
00156 }
00157
00158 m_HelperPolyLines->ElementAt( 0 )->Reserve( 16 );
00159 for ( int t = 0; t < 16; ++t )
00160 {
00161 double alpha = (double) t * angle / 15.0 + testAngle;
00162
00163 m_HelperPolyLines->ElementAt( 0 )->ElementAt( t )[0] = centerPoint[0] + radius * cos( alpha );
00164 m_HelperPolyLines->ElementAt( 0 )->ElementAt( t )[1] = centerPoint[1] + radius * sin( alpha );
00165 }
00166 }
00167
00168
00169 void mitk::PlanarAngle::EvaluateFeaturesInternal()
00170 {
00171 if ( this->GetNumberOfControlPoints() < 3 )
00172 {
00173
00174 return;
00175 }
00176
00177
00178 const Point2D &p0 = this->GetControlPoint( 0 );
00179 const Point2D &p1 = this->GetControlPoint( 1 );
00180 const Point2D &p2 = this->GetControlPoint( 2 );
00181
00182 Vector2D v0 = p1 - p0;
00183 Vector2D v1 = p1 - p2;
00184
00185 v0.Normalize();
00186 v1.Normalize();
00187 double angle = acos( v0 * v1 );
00188
00189 this->SetQuantity( FEATURE_ID_ANGLE, angle );
00190 }
00191
00192
00193 void mitk::PlanarAngle::PrintSelf( std::ostream& os, itk::Indent indent) const
00194 {
00195 Superclass::PrintSelf( os, indent );
00196 }