Implementation of PlanarFigure modeling a cross with two orthogonal lines on a plane. More...
#include <mitkPlanarCross.h>
Public Types | |
typedef PlanarCross | Self |
typedef PlanarFigure | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
void | SetSingleLineMode (bool singleLineMode) |
Indicates whether the PlanarFigure shall represent only a single line instead of an orthogonal cross. | |
bool | GetSingleLineMode () const |
Indicates whether the PlanarFigure shall represent only a single line instead of an orthogonal cross. | |
virtual void | SingleLineModeOn () |
Indicates whether the PlanarFigure shall represent only a single line instead of an orthogonal cross. | |
virtual void | SingleLineModeOff () |
unsigned int | GetMinimumNumberOfControlPoints () const |
PlanarCross has either two or four control points, depending on the operation mode. | |
unsigned int | GetMaximumNumberOfControlPoints () const |
PlanarCross has either two or four control points, depending on the operation mode. | |
virtual bool | ResetOnPointSelect () |
The cross shall be reset to a single line when a control point is selected. | |
virtual unsigned int | GetNumberOfFeatures () const |
Returns the number of features available for this PlanarCross (1 or 2). | |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
PlanarCross () | |
virtual | ~PlanarCross () |
virtual Point2D | ApplyControlPointConstraints (unsigned int index, const Point2D &point) |
Spatially constrain control points of second (orthogonal) line. | |
virtual void | GeneratePolyLine () |
Generates the poly-line representation of the planar figure. | |
virtual void | GenerateHelperPolyLine (double mmPerDisplayUnit, unsigned int displayHeight) |
Generates the poly-lines that should be drawn the same size regardless of zoom. | |
virtual void | EvaluateFeaturesInternal () |
Calculates feature quantities of the planar figure. | |
virtual void | PrintSelf (std::ostream &os, itk::Indent indent) const |
Protected Attributes | |
const unsigned int | FEATURE_ID_LONGESTDIAMETER |
const unsigned int | FEATURE_ID_SHORTAXISDIAMETER |
Implementation of PlanarFigure modeling a cross with two orthogonal lines on a plane.
The cross consists of two two orthogonal lines, which are defined by four control points lying on a plane. The two control points of the first line are freely placable within the bounds of the underlying 2D geometry, while the two control points of the second line are ensured to meet the following constraints:
1.) The lines must be orthogonal to each other 2.) The second line must lie within the 2D area defined by the first line 3.) The two lines must intersect (at least with their boundaries)
When placing the second line interactively, a graphical helper polyline is provided to the user to indicate the position and orthogonal orientation of the line if it would be placed at the current mouse position.
When modifying one of the lines by interactively moving its control points, the respective other line is deleted and the user is prompted to draw it again.
The class provide a special mode for drawing single lines (SingleLineModeOn/Off); in this case, interaction stops after the first line has been placed.
The class provides the lengths of both lines via the "feature" interface, ordered by size.
Definition at line 58 of file mitkPlanarCross.h.
typedef itk::SmartPointer<const Self> mitk::PlanarCross::ConstPointer |
Reimplemented from mitk::PlanarFigure.
Definition at line 61 of file mitkPlanarCross.h.
typedef itk::SmartPointer<Self> mitk::PlanarCross::Pointer |
Reimplemented from mitk::PlanarFigure.
Definition at line 61 of file mitkPlanarCross.h.
typedef PlanarCross mitk::PlanarCross::Self |
Reimplemented from mitk::PlanarFigure.
Definition at line 61 of file mitkPlanarCross.h.
Reimplemented from mitk::PlanarFigure.
Definition at line 61 of file mitkPlanarCross.h.
mitk::PlanarCross::PlanarCross | ( | ) | [protected] |
Definition at line 24 of file mitkPlanarCross.cpp.
References mitk::PlanarFigure::m_HelperPolyLines, mitk::PlanarFigure::m_HelperPolyLinesToBePainted, mitk::BoolProperty::New(), mitk::PlanarFigure::ResetNumberOfControlPoints(), and mitk::BaseData::SetProperty().
: FEATURE_ID_LONGESTDIAMETER( this->AddFeature( "Longest Axis", "mm" ) ), FEATURE_ID_SHORTAXISDIAMETER( this->AddFeature( "Short Axis", "mm" ) ) { // Cross has two control points at the beginning this->ResetNumberOfControlPoints( 2 ); // Create property for SingleLineMode (default: false) this->SetProperty( "SingleLineMode", mitk::BoolProperty::New( false ) ); // Create helper polyline object (for drawing the orthogonal orientation line) m_HelperPolyLines->InsertElement( 0, VertexContainerType::New()); m_HelperPolyLines->ElementAt( 0 )->Reserve( 2 ); m_HelperPolyLinesToBePainted->InsertElement( 0, false ); }
mitk::PlanarCross::~PlanarCross | ( | ) | [protected, virtual] |
Definition at line 41 of file mitkPlanarCross.cpp.
{ }
mitk::Point2D mitk::PlanarCross::ApplyControlPointConstraints | ( | unsigned int | index, |
const Point2D & | point | ||
) | [protected, virtual] |
Spatially constrain control points of second (orthogonal) line.
Reimplemented from mitk::PlanarFigure.
Definition at line 137 of file mitkPlanarCross.cpp.
{ // Apply spatial constraints from superclass and from this class until the resulting constrained // point converges. Although not an optimal implementation, this iterative approach // helps to respect both constraints from the superclass and from this class. Without this, // situations may occur where control points are constrained by the superclass, but again // moved out of the superclass bounds by the subclass, or vice versa. unsigned int count = 0; // ensures stop of approach if point does not converge in reasonable time Point2D confinedPoint = point; Point2D superclassConfinedPoint; do { superclassConfinedPoint = Superclass::ApplyControlPointConstraints( index, confinedPoint ); confinedPoint = this->InternalApplyControlPointConstraints( index, superclassConfinedPoint ); ++count; } while ( (confinedPoint.EuclideanDistanceTo( superclassConfinedPoint ) > mitk::eps) && (count < 32) ); return confinedPoint; }
void mitk::PlanarCross::EvaluateFeaturesInternal | ( | ) | [protected, virtual] |
Calculates feature quantities of the planar figure.
Implements mitk::PlanarFigure.
Definition at line 312 of file mitkPlanarCross.cpp.
{ // Calculate length of first line const Point3D &p0 = this->GetWorldControlPoint( 0 ); const Point3D &p1 = this->GetWorldControlPoint( 1 ); double l1 = p0.EuclideanDistanceTo( p1 ); // Calculate length of second line double l2 = 0.0; if ( !this->GetSingleLineMode() && (this->GetNumberOfControlPoints() > 3) ) { const Point3D &p2 = this->GetWorldControlPoint( 2 ); const Point3D &p3 = this->GetWorldControlPoint( 3 ); l2 = p2.EuclideanDistanceTo( p3 ); } double longestDiameter; double shortAxisDiameter; if ( l1 > l2 ) { longestDiameter = l1; shortAxisDiameter = l2; } else { longestDiameter = l2; shortAxisDiameter = l1; } this->SetQuantity( FEATURE_ID_LONGESTDIAMETER, longestDiameter ); this->SetQuantity( FEATURE_ID_SHORTAXISDIAMETER, shortAxisDiameter ); }
void mitk::PlanarCross::GenerateHelperPolyLine | ( | double | mmPerDisplayUnit, |
unsigned int | displayHeight | ||
) | [protected, virtual] |
Generates the poly-lines that should be drawn the same size regardless of zoom.
Implements mitk::PlanarFigure.
Definition at line 267 of file mitkPlanarCross.cpp.
{ // Generate helper polyline (orientation line orthogonal to first line) // if the third control point is currently being set if ( this->GetNumberOfControlPoints() != 3 ) { m_HelperPolyLinesToBePainted->SetElement( 0, false ); return; } m_HelperPolyLinesToBePainted->SetElement( 0, true ); // Calculate cross point of first line (p1 to p2) and orthogonal line through // the third control point (p3) const Point2D& p1 = m_ControlPoints->ElementAt( 0 ); const Point2D& p2 = m_ControlPoints->ElementAt( 1 ); const Point2D& p3 = m_ControlPoints->ElementAt( 2 ); Vector2D n1 = p2 - p1; n1.Normalize(); Vector2D v1 = p3 - p1; Point2D crossPoint = p1 + n1 * (n1 * v1); Vector2D v2 = crossPoint - p3; if ( v2.GetNorm() < 1.0 ) { // If third point is on the first line, draw orthogonal "infinite" line // through cross point on line Vector2D v0; v0[0] = n1[1]; v0[1] = -n1[0]; m_HelperPolyLines->ElementAt( 0 )->ElementAt( 0 ) = p3 - v0 * 10000.0; m_HelperPolyLines->ElementAt( 0 )->ElementAt( 1 ) = p3 + v0 * 10000.0; } else { // Else, draw orthogonal line starting from third point and crossing the // first line, open-ended only on the other side m_HelperPolyLines->ElementAt( 0 )->ElementAt( 0 ) = p3; m_HelperPolyLines->ElementAt( 0 )->ElementAt( 1 ) = p3 + v2 * 10000.0; } }
void mitk::PlanarCross::GeneratePolyLine | ( | ) | [protected, virtual] |
Generates the poly-line representation of the planar figure.
Implements mitk::PlanarFigure.
Definition at line 242 of file mitkPlanarCross.cpp.
{ m_PolyLines->Initialize(); m_PolyLines->InsertElement( 0, VertexContainerType::New() ); m_PolyLines->ElementAt( 0 )->Reserve( 2 ); if ( this->GetNumberOfControlPoints() > 2) { m_PolyLines->InsertElement( 1, VertexContainerType::New() ); m_PolyLines->ElementAt( 1 )->Reserve( this->GetNumberOfControlPoints() - 2 ); } for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i ) { if (i < 2) { m_PolyLines->ElementAt( 0 )->ElementAt( i ) = m_ControlPoints->ElementAt( i ); } if (i > 1) { m_PolyLines->ElementAt( 1 )->ElementAt( i-2 ) = m_ControlPoints->ElementAt( i ); } } }
virtual const char* mitk::PlanarCross::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::PlanarFigure.
unsigned int mitk::PlanarCross::GetMaximumNumberOfControlPoints | ( | ) | const [inline, virtual] |
PlanarCross has either two or four control points, depending on the operation mode.
Implements mitk::PlanarFigure.
Definition at line 85 of file mitkPlanarCross.h.
{ return this->GetSingleLineMode() ? 2 : 4; }
unsigned int mitk::PlanarCross::GetMinimumNumberOfControlPoints | ( | ) | const [inline, virtual] |
PlanarCross has either two or four control points, depending on the operation mode.
Implements mitk::PlanarFigure.
Definition at line 79 of file mitkPlanarCross.h.
{ return this->GetSingleLineMode() ? 2 : 4; }
unsigned int mitk::PlanarCross::GetNumberOfFeatures | ( | ) | const [virtual] |
Returns the number of features available for this PlanarCross (1 or 2).
Reimplemented from mitk::PlanarFigure.
Definition at line 124 of file mitkPlanarCross.cpp.
{ if ( this->GetSingleLineMode() || (this->GetNumberOfControlPoints() < 4) ) { return 1; } else { return 2; } }
bool mitk::PlanarCross::GetSingleLineMode | ( | ) | const |
Indicates whether the PlanarFigure shall represent only a single line instead of an orthogonal cross.
Definition at line 53 of file mitkPlanarCross.cpp.
References mitk::GenericProperty< T >::GetValue().
{ mitk::BoolProperty* singleLineMode = dynamic_cast< mitk::BoolProperty* >( this->GetProperty( "SingleLineMode" ).GetPointer() ); if ( singleLineMode != NULL ) { return singleLineMode->GetValue(); } return false; }
static Pointer mitk::PlanarCross::New | ( | ) | [static] |
void mitk::PlanarCross::PrintSelf | ( | std::ostream & | os, |
itk::Indent | indent | ||
) | const [protected, virtual] |
Reimplemented from mitk::PlanarFigure.
Definition at line 347 of file mitkPlanarCross.cpp.
{ Superclass::PrintSelf( os, indent ); }
bool mitk::PlanarCross::ResetOnPointSelect | ( | ) | [virtual] |
The cross shall be reset to a single line when a control point is selected.
Reimplemented from mitk::PlanarFigure.
Definition at line 66 of file mitkPlanarCross.cpp.
{ if ( this->GetSingleLineMode() ) { // In single line mode --> nothing to reset return false; } switch ( m_SelectedControlPoint ) { default: // Nothing selected --> nothing to reset return false; case 0: { // Control point 0 selected: exchange points 0 and 1 Point2D tmpPoint = m_ControlPoints->ElementAt( 0 ); m_ControlPoints->InsertElement( 0, m_ControlPoints->ElementAt( 1 ) ); m_ControlPoints->InsertElement( 1, tmpPoint ); // FALLS THROUGH! } case 1: { // Control point 0 or 1 selected: reset number of control points to two this->ResetNumberOfControlPoints( 2 ); this->SelectControlPoint( 1 ); return true; } case 2: { // Control point 2 selected: replace point 0 with point 3 and point 1 with point 2 m_ControlPoints->InsertElement( 0, m_ControlPoints->ElementAt( 3 ) ); m_ControlPoints->InsertElement( 1, m_ControlPoints->ElementAt( 2 ) ); // Adjust selected control point, reset number of control points to two this->ResetNumberOfControlPoints( 2 ); this->SelectControlPoint( 1 ); return true; } case 3: { // Control point 3 selected: replace point 0 with point 2 and point 1 with point 3 m_ControlPoints->InsertElement( 0, m_ControlPoints->ElementAt( 2 ) ); m_ControlPoints->InsertElement( 1, m_ControlPoints->ElementAt( 3 ) ); // Adjust selected control point, reset number of control points to two this->ResetNumberOfControlPoints( 2 ); this->SelectControlPoint( 1 ); return true; } } }
void mitk::PlanarCross::SetSingleLineMode | ( | bool | singleLineMode ) |
Indicates whether the PlanarFigure shall represent only a single line instead of an orthogonal cross.
Definition at line 46 of file mitkPlanarCross.cpp.
References mitk::BoolProperty::New().
{ this->SetProperty( "SingleLineMode", mitk::BoolProperty::New( singleLineMode ) ); this->Modified(); }
virtual void mitk::PlanarCross::SingleLineModeOff | ( | ) | [virtual] |
virtual void mitk::PlanarCross::SingleLineModeOn | ( | ) | [virtual] |
Indicates whether the PlanarFigure shall represent only a single line instead of an orthogonal cross.
const unsigned int mitk::PlanarCross::FEATURE_ID_LONGESTDIAMETER [protected] |
Definition at line 118 of file mitkPlanarCross.h.
const unsigned int mitk::PlanarCross::FEATURE_ID_SHORTAXISDIAMETER [protected] |
Definition at line 119 of file mitkPlanarCross.h.