Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkPlanarFigure.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkPlanarFigure_h
14 #define mitkPlanarFigure_h
15 
16 #include "mitkBaseData.h"
17 #include "mitkCommon.h"
19 
20 #include <deque>
21 
22 namespace mitk
23 {
24  class PlaneGeometry;
25 
51  {
52  public:
54  itkCloneMacro(Self);
55 
57 
58  typedef itk::VectorContainer<unsigned long, bool> BoolContainerType;
59 
60  typedef std::deque<Point2D> ControlPointListType;
61  typedef std::vector<PolyLineElement> PolyLineType;
62 
69  virtual void SetPlaneGeometry(mitk::PlaneGeometry *geometry);
70 
72  virtual const PlaneGeometry *GetPlaneGeometry() const;
73 
77  virtual bool IsClosed() const;
78 
81  virtual bool IsPlaced() const { return m_FigurePlaced; };
92  virtual void PlaceFigure(const Point2D &point);
93 
104  virtual bool AddControlPoint(const Point2D &point, int index = -1);
105 
106  virtual bool SetControlPoint(unsigned int index, const Point2D &point, bool createIfDoesNotExist = false);
107 
108  virtual bool SetCurrentControlPoint(const Point2D &point);
109 
111  unsigned int GetNumberOfControlPoints() const;
112 
118  virtual unsigned int GetMinimumNumberOfControlPoints() const = 0;
119 
125  virtual unsigned int GetMaximumNumberOfControlPoints() const = 0;
126 
128  virtual bool SelectControlPoint(unsigned int index);
129 
131  virtual bool DeselectControlPoint();
132 
134  virtual int GetSelectedControlPoint() const { return m_SelectedControlPoint; }
136  Point2D GetControlPoint(unsigned int index) const;
137 
142  virtual int GetControlPointForPolylinePoint(int indexOfPolylinePoint, int polyLineIndex) const;
143 
145  Point3D GetWorldControlPoint(unsigned int index) const;
146 
149  PolyLineType& GetPolyLine(unsigned int index);
150 
153  const PolyLineType& GetPolyLine(unsigned int index) const;
154 
157  const PolyLineType& GetHelperPolyLine(unsigned int index, double mmPerDisplayUnit, unsigned int displayHeight);
158 
160  void SetPreviewControlPoint(const Point2D &point);
161 
164 
167 
170 
173  virtual unsigned int GetNumberOfFeatures() const;
174 
176  const char *GetFeatureName(unsigned int index) const;
177 
179  const char *GetFeatureUnit(unsigned int index) const;
180 
183  double GetQuantity(unsigned int index) const;
184 
188  bool IsFeatureActive(unsigned int index) const;
189 
191  bool IsFeatureVisible(unsigned int index) const;
192 
195  void SetFeatureVisible(unsigned int index, bool visible);
196 
198  virtual void EvaluateFeatures();
199 
201  void UpdateOutputInformation() override;
202 
205 
208 
210  bool VerifyRequestedRegion() override;
211 
213  void SetRequestedRegion(const itk::DataObject *data) override;
214 
216  virtual unsigned short GetPolyLinesSize();
217 
219  virtual unsigned short GetHelperPolyLinesSize() const;
220 
222  virtual bool IsHelperToBePainted(unsigned int index) const;
223 
229  virtual bool ResetOnPointSelect();
230  virtual bool ResetOnPointSelectNeeded() const;
231 
233  virtual void RemoveControlPoint(unsigned int index);
234 
236  virtual void RemoveLastControlPoint();
237 
243  virtual Point2D ApplyControlPointConstraints(unsigned int /*index*/, const Point2D &point);
244 
249  virtual bool Equals(const mitk::PlanarFigure &other) const;
250 
252  void ResetNumberOfControlPoints(int numberOfControlPoints);
253 
254  protected:
256 
257  PlanarFigure(const Self &other);
258 
262  virtual unsigned int AddFeature(const char *featureName, const char *unitName);
263 
265  void SetFeatureName(unsigned int index, const char *featureName);
266 
268  void SetFeatureUnit(unsigned int index, const char *unitName);
269 
271  void SetQuantity(unsigned int index, double quantity);
272 
274  void ActivateFeature(unsigned int index);
275 
277  void DeactivateFeature(unsigned int index);
278 
281  virtual void GeneratePolyLine() = 0;
282 
285  virtual void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) = 0;
286 
289  virtual void EvaluateFeaturesInternal() = 0;
290 
294  void InitializeTimeGeometry(unsigned int timeSteps = 1) override;
295 
297  void SetNumberOfPolyLines(unsigned int numberOfPolyLines);
298 
300  void AppendPointToPolyLine(unsigned int index, PolyLineElement element);
301 
304 
306  void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines);
307 
309  void AppendPointToHelperPolyLine(unsigned int index, PolyLineElement element);
310 
313 
314  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
315 
318 
319  // Currently selected control point; -1 means no point selected
321 
322  std::vector<PolyLineType> m_PolyLines;
323  std::vector<PolyLineType> m_HelperPolyLines;
324  BoolContainerType::Pointer m_HelperPolyLinesToBePainted;
325 
326  // this point is used to store the coordinates an additional 'ControlPoint' that is rendered
327  // when the mouse cursor is above the figure (and not a control-point) and when the
328  // property 'planarfigure.isextendable' is set to true
331 
333 
334  private:
335  // not implemented to prevent PlanarFigure::New() calls which would create an itk::Object.
336  static Pointer New();
337 
338  struct Feature
339  {
340  Feature(const char *name, const char *unit) : Name(name), Unit(unit), Quantity(0.0), Active(true), Visible(true)
341  {
342  }
343 
344  std::string Name;
345  std::string Unit;
346  double Quantity;
347  bool Active;
348  bool Visible;
349  };
350 
351  itk::LightObject::Pointer InternalClone() const override = 0;
352 
353  bool m_PolyLineUpToDate;
354  bool m_HelperLinesUpToDate;
355  bool m_FeaturesUpToDate;
356 
357  // Vector of features available for this geometric figure
358  typedef std::vector<Feature> FeatureVectorType;
359  FeatureVectorType m_Features;
360 
361  unsigned long m_FeaturesMTime;
362 
363  // this pair is used to store the mmInDisplayUnits (m_DisplaySize.first) and the displayHeight
364  // (m_DisplaySize.second)
365  // that the helperPolyLines have been calculated for.
366  // It's used to determine whether or not GetHelperPolyLine() needs to recalculate the HelperPolyLines.
367  std::pair<double, unsigned int> m_DisplaySize;
368  };
369 
371  const mitk::PlanarFigure &rightHandSide,
372  ScalarType eps,
373  bool verbose);
374 
375 } // namespace mitk
376 
377 #endif
#define MITKPLANARFIGURE_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons,...
std::vector< PolyLineType > m_PolyLines
void AppendPointToPolyLine(unsigned int index, PolyLineElement element)
Append a point to the PolyLine # index.
virtual bool AddControlPoint(const Point2D &point, int index=-1)
Adds / inserts new control-points.
virtual bool IsPlaced() const
True if the planar figure has been placed (and can be displayed/interacted with).
unsigned int GetNumberOfControlPoints() const
Returns the current number of 2D control points defining this figure.
void SetPreviewControlPoint(const Point2D &point)
Sets the position of the PreviewControlPoint. Automatically sets it visible.
virtual bool IsClosed() const
True if the planar figure is closed.
virtual void EvaluateFeatures()
Calculates quantities of all features of this planar figure.
virtual int GetControlPointForPolylinePoint(int indexOfPolylinePoint, int polyLineIndex) const
Returns the id of the control-point that corresponds to the given polyline-point.
virtual void GeneratePolyLine()=0
Generates the poly-line representation of the planar figure. Must be implemented in sub-classes.
const char * GetFeatureUnit(unsigned int index) const
Returns the physical unit of the specified features.
virtual unsigned int GetNumberOfFeatures() const
Returns the number of features available for this PlanarFigure (such as, radius, area,...
void ClearPolyLines()
clears the list of PolyLines. Call before re-calculating a new Polyline.
void ActivateFeature(unsigned int index)
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Intherited from parent.
void SetFeatureUnit(unsigned int index, const char *unitName)
BoolContainerType::Pointer m_HelperPolyLinesToBePainted
virtual bool SetCurrentControlPoint(const Point2D &point)
virtual bool SelectControlPoint(unsigned int index)
Selects currently active control points.
void ClearHelperPolyLines()
clears the list of HelperPolyLines. Call before re-calculating a new HelperPolyline.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Point3D GetWorldControlPoint(unsigned int index) const
Returns specified control point in world coordinates.
void SetRequestedRegionToLargestPossibleRegion() override
Intherited from parent.
void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines)
defines the number of HelperPolyLines that will be available
virtual void RemoveControlPoint(unsigned int index)
removes the point with the given index from the list of controlpoints.
mitkClassMacro(PlanarFigure, BaseData)
unsigned int m_NumberOfControlPoints
bool IsFeatureVisible(unsigned int index) const
Returns true if the feature with the specified index exists and is set visible.
void AppendPointToHelperPolyLine(unsigned int index, PolyLineElement element)
Append a point to the HelperPolyLine # index.
const PolyLineType & GetPolyLine(unsigned int index) const
Returns the polyline representing the planar figure (for rendering, measurements, etc....
void ResetPreviewContolPoint()
Marks the PreviewControlPoint as invisible.
std::deque< Point2D > ControlPointListType
double GetQuantity(unsigned int index) const
bool IsPreviewControlPointVisible() const
Returns whether or not the PreviewControlPoint is visible.
virtual Point2D ApplyControlPointConstraints(unsigned int, const Point2D &point)
Allow sub-classes to apply constraints on control points.
Point2D GetPreviewControlPoint() const
Returns the coordinates of the PreviewControlPoint.
std::vector< PolyLineType > m_HelperPolyLines
void SetQuantity(unsigned int index, double quantity)
virtual const PlaneGeometry * GetPlaneGeometry() const
Returns (previously set) 2D geometry of this figure.
virtual bool DeselectControlPoint()
Deselect control point; no control point active.
virtual int GetSelectedControlPoint() const
Return currently selected control point.
PlanarFigure(const Self &other)
ControlPointListType m_ControlPoints
void SetFeatureVisible(unsigned int index, bool visible)
Defines if the feature with the specified index will be shown as an Annotation in the RenderWindow.
virtual bool IsHelperToBePainted(unsigned int index) const
Returns whether a helper polyline should be painted or not.
const PolyLineType & GetHelperPolyLine(unsigned int index, double mmPerDisplayUnit, unsigned int displayHeight)
Returns the polyline that should be drawn the same size at every scale (for text, angles,...
virtual bool Equals(const mitk::PlanarFigure &other) const
Compare two PlanarFigure objects Note: all subclasses have to implement the method on their own.
bool VerifyRequestedRegion() override
Intherited from parent.
virtual bool ResetOnPointSelectNeeded() const
void SetRequestedRegion(const itk::DataObject *data) override
Intherited from parent.
virtual unsigned int GetMaximumNumberOfControlPoints() const =0
Returns the maximum number of control points allowed for this figure (e.g. 3 for triangles).
void SetNumberOfPolyLines(unsigned int numberOfPolyLines)
defines the number of PolyLines that will be available
virtual void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight)=0
Generates the poly-lines that should be drawn the same size regardless of zoom. Must be implemented i...
std::vector< PolyLineElement > PolyLineType
virtual void RemoveLastControlPoint()
Removes last control point.
itk::VectorContainer< unsigned long, bool > BoolContainerType
const char * GetFeatureName(unsigned int index) const
Returns the name (identifier) of the specified features.
void DeactivateFeature(unsigned int index)
Point2D GetControlPoint(unsigned int index) const
Returns specified control point in 2D world coordinates.
void SetFeatureName(unsigned int index, const char *featureName)
virtual void EvaluateFeaturesInternal()=0
Calculates quantities of all features of this planar figure. Must be implemented in sub-classes.
bool IsFeatureActive(unsigned int index) const
Returns true if the feature with the specified index exists and is active (an inactive feature may e....
virtual unsigned int GetMinimumNumberOfControlPoints() const =0
Returns the minimum number of control points needed to represent this figure.
PolyLineType & GetPolyLine(unsigned int index)
Returns the polyline representing the planar figure (for rendering, measurements, etc....
void InitializeTimeGeometry(unsigned int timeSteps=1) override
Initializes the TimeGeometry describing the (time-resolved) geometry of this figure....
virtual unsigned short GetHelperPolyLinesSize() const
Returns the current number of helperpolylines
void ResetNumberOfControlPoints(int numberOfControlPoints)
Set the initial number of control points of the planar figure.
virtual bool ResetOnPointSelect()
Returns true if the planar figure is reset to "add points" mode when a point is selected.
void UpdateOutputInformation() override
Intherited from parent.
virtual bool SetControlPoint(unsigned int index, const Point2D &point, bool createIfDoesNotExist=false)
virtual void PlaceFigure(const Point2D &point)
Place figure at the given point (in 2D index coordinates) onto the given 2D geometry.
virtual void SetPlaneGeometry(mitk::PlaneGeometry *geometry)
Sets the 2D geometry on which this figure will be placed.
virtual unsigned short GetPolyLinesSize()
Returns the current number of polylines
virtual unsigned int AddFeature(const char *featureName, const char *unitName)
Describes a two-dimensional, rectangular plane.
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
double ScalarType
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.