Page MenuHomePhabricator

0001-enhanced-planarcircle-so-that-a-min-and-max-value-ca.patch

Authored By
saruji
Sep 28 2011, 12:55 PM
Size
4 KB
Referenced Files
None
Subscribers
None

0001-enhanced-planarcircle-so-that-a-min-and-max-value-ca.patch

From f6e901a5580f1b2dd7219d10dbf026b48aa67b00 Mon Sep 17 00:00:00 2001
From: dsaruji <dsaruji@saruji.(none)>
Date: Wed, 28 Sep 2011 12:56:07 +0200
Subject: [PATCH] enhanced planarcircle so that a min and max value can be set for circles
---
.../DataManagement/mitkPlanarCircle.cpp | 53 +++++++++++++++++++-
.../PlanarFigure/DataManagement/mitkPlanarCircle.h | 39 ++++++++++++++
2 files changed, 91 insertions(+), 1 deletions(-)
diff --git a/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.cpp b/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.cpp
index 0c03bfe..40c078a 100644
--- a/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.cpp
+++ b/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.cpp
@@ -25,7 +25,10 @@ PURPOSE. See the above copyright notices for more information.
mitk::PlanarCircle::PlanarCircle()
: FEATURE_ID_RADIUS( this->AddFeature( "Radius", "mm" ) ),
FEATURE_ID_DIAMETER( this->AddFeature( "Diameter", "mm" ) ),
- FEATURE_ID_AREA( this->AddFeature( "Area", "mm2" ) )
+ FEATURE_ID_AREA( this->AddFeature( "Area", "mm2" ) ),
+ m_MinRadius(0),
+ m_MaxRadius(100),
+ m_MinMaxRadiusContraintsActive(false)
{
// Circle has two control points
this->ResetNumberOfControlPoints( 2 );
@@ -60,6 +63,54 @@ bool mitk::PlanarCircle::SetControlPoint( unsigned int index, const Point2D &poi
return false;
}
+mitk::Point2D mitk::PlanarCircle::ApplyControlPointConstraints(unsigned int index, const Point2D &point)
+{
+ if ( this->GetGeometry2D() == NULL )
+ {
+ return point;
+ }
+
+ Point2D indexPoint;
+ this->GetGeometry2D()->WorldToIndex( point, indexPoint );
+
+ BoundingBox::BoundsArrayType bounds = this->GetGeometry2D()->GetBounds();
+ if ( indexPoint[0] < bounds[0] ) { indexPoint[0] = bounds[0]; }
+ if ( indexPoint[0] > bounds[1] ) { indexPoint[0] = bounds[1]; }
+ if ( indexPoint[1] < bounds[2] ) { indexPoint[1] = bounds[2]; }
+ if ( indexPoint[1] > bounds[3] ) { indexPoint[1] = bounds[3]; }
+
+ Point2D constrainedPoint;
+ this->GetGeometry2D()->IndexToWorld( indexPoint, constrainedPoint );
+
+ if(m_MinMaxRadiusContraintsActive)
+ {
+ if( index != 0)
+ {
+ const Point2D &centerPoint = this->GetControlPoint(0);
+ double euclideanDinstanceFromCenterToPoint1 = centerPoint.EuclideanDistanceTo(point);
+
+ Vector2D vectorProjectedPoint;
+ vectorProjectedPoint = point - centerPoint;
+ vectorProjectedPoint.Normalize();
+
+ if( euclideanDinstanceFromCenterToPoint1 > m_MaxRadius )
+ {
+ vectorProjectedPoint *= m_MaxRadius;
+ constrainedPoint = centerPoint;
+ constrainedPoint += vectorProjectedPoint;
+ }
+ else if( euclideanDinstanceFromCenterToPoint1 < m_MinRadius )
+ {
+ vectorProjectedPoint *= m_MinRadius;
+ constrainedPoint = centerPoint;
+ constrainedPoint += vectorProjectedPoint;
+ }
+ }
+ }
+
+ return constrainedPoint;
+}
+
void mitk::PlanarCircle::GeneratePolyLine()
{
// TODO: start circle at specified boundary point...
diff --git a/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.h b/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.h
index eb692ad..17e59f7 100644
--- a/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.h
+++ b/Modules/PlanarFigure/DataManagement/mitkPlanarCircle.h
@@ -62,7 +62,38 @@ public:
return 2;
}
+ /** \brief Sets the minimum radius
+ */
+ void SetMinimumRadius( double radius )
+ {
+ m_MinRadius = radius;
+ }
+
+ /** \brief Gets the minimum radius
+ */
+ double GetMinimumRadius()
+ {
+ return m_MinRadius;
+ }
+
+ /** \brief Sets the maximum radius
+ */
+ void SetMaximumRadius( double radius )
+ {
+ m_MaxRadius = radius;
+ }
+ /** \brief Gets the minimum radius
+ */
+ double GetMaximumRadius()
+ {
+ return m_MaxRadius;
+ }
+
+ void ActivateMinMaxRadiusContstraints( bool active )
+ {
+ m_MinMaxRadiusContraintsActive = active;
+ }
protected:
PlanarCircle();
@@ -74,6 +105,9 @@ protected:
/** \brief Generates the poly-lines that should be drawn the same size regardless of zoom.*/
virtual void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight);
+ /** \brief Spatially constrain control points of second (orthogonal) line */
+ virtual Point2D ApplyControlPointConstraints( unsigned int index, const Point2D& point );
+
/** \brief Calculates feature quantities of the planar figure. */
virtual void EvaluateFeaturesInternal();
@@ -85,6 +119,11 @@ protected:
const unsigned int FEATURE_ID_DIAMETER;
const unsigned int FEATURE_ID_AREA;
+ //Member variables:
+ double m_MinRadius;
+ double m_MaxRadius;
+ bool m_MinMaxRadiusContraintsActive;
+
private:
};
--
1.7.0.4

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
704
Default Alt Text
0001-enhanced-planarcircle-so-that-a-min-and-max-value-ca.patch (4 KB)

Event Timeline

Patch for PlanarCircle enhancement