Medical Imaging Interaction Toolkit  2026.06.00
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 
58 
60  typedef itk::VectorContainer<unsigned long, bool> BoolContainerType;
61 
63  typedef std::deque<Point2D> ControlPointListType;
65  typedef std::vector<PolyLineElement> PolyLineType;
66 
73  virtual void SetPlaneGeometry(mitk::PlaneGeometry *geometry);
74 
76  virtual const PlaneGeometry *GetPlaneGeometry() const;
77 
81  virtual bool IsClosed() const;
82 
85  virtual bool IsPlaced() const { return m_FigurePlaced; };
96  virtual void PlaceFigure(const Point2D &point);
97 
108  virtual bool AddControlPoint(const Point2D &point, int index = -1);
109 
119  virtual bool SetControlPoint(unsigned int index, const Point2D &point, bool createIfDoesNotExist = false);
120 
127  virtual bool SetCurrentControlPoint(const Point2D &point);
128 
130  unsigned int GetNumberOfControlPoints() const;
131 
137  virtual unsigned int GetMinimumNumberOfControlPoints() const = 0;
138 
144  virtual unsigned int GetMaximumNumberOfControlPoints() const = 0;
145 
147  virtual bool SelectControlPoint(unsigned int index);
148 
150  virtual bool DeselectControlPoint();
151 
153  virtual int GetSelectedControlPoint() const { return m_SelectedControlPoint; }
155  Point2D GetControlPoint(unsigned int index) const;
156 
161  virtual int GetControlPointForPolylinePoint(int indexOfPolylinePoint, int polyLineIndex) const;
162 
164  Point3D GetWorldControlPoint(unsigned int index) const;
165 
174  PolyLineType& GetPolyLine(unsigned int index);
175 
182  const PolyLineType& GetPolyLine(unsigned int index) const;
183 
195  const PolyLineType& GetHelperPolyLine(unsigned int index, double mmPerDisplayUnit, unsigned int displayHeight);
196 
198  void SetPreviewControlPoint(const Point2D &point);
199 
202 
205 
208 
216  virtual unsigned int GetNumberOfFeatures() const;
217 
224  const char *GetFeatureName(unsigned int index) const;
225 
232  const char *GetFeatureUnit(unsigned int index) const;
233 
240  double GetQuantity(unsigned int index) const;
241 
251  bool IsFeatureActive(unsigned int index) const;
252 
259  bool IsFeatureVisible(unsigned int index) const;
260 
268  void SetFeatureVisible(unsigned int index, bool visible);
269 
271  virtual void EvaluateFeatures();
272 
274  void UpdateOutputInformation() override;
275 
278 
281 
283  bool VerifyRequestedRegion() override;
284 
289  void SetRequestedRegion(const itk::DataObject *data) override;
290 
292  virtual unsigned short GetPolyLinesSize();
293 
295  virtual unsigned short GetHelperPolyLinesSize() const;
296 
298  virtual bool IsHelperToBePainted(unsigned int index) const;
299 
305  virtual bool ResetOnPointSelect();
306  virtual bool ResetOnPointSelectNeeded() const;
307 
313  virtual void RemoveControlPoint(unsigned int index);
314 
316  virtual void RemoveLastControlPoint();
317 
330  virtual Point2D ApplyControlPointConstraints(unsigned int index, const Point2D &point);
331 
341  virtual bool Equals(const mitk::PlanarFigure &other) const;
342 
348  void ResetNumberOfControlPoints(int numberOfControlPoints);
349 
350  protected:
352 
353  PlanarFigure(const Self &other);
354 
358  virtual unsigned int AddFeature(const char *featureName, const char *unitName);
359 
361  void SetFeatureName(unsigned int index, const char *featureName);
362 
364  void SetFeatureUnit(unsigned int index, const char *unitName);
365 
367  void SetQuantity(unsigned int index, double quantity);
368 
370  void ActivateFeature(unsigned int index);
371 
373  void DeactivateFeature(unsigned int index);
374 
377  virtual void GeneratePolyLine() = 0;
378 
381  virtual void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) = 0;
382 
385  virtual void EvaluateFeaturesInternal() = 0;
386 
390  void InitializeTimeGeometry(unsigned int timeSteps = 1) override;
391 
393  void SetNumberOfPolyLines(unsigned int numberOfPolyLines);
394 
396  void AppendPointToPolyLine(unsigned int index, PolyLineElement element);
397 
400 
402  void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines);
403 
405  void AppendPointToHelperPolyLine(unsigned int index, PolyLineElement element);
406 
409 
410  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
411 
414 
415  // Currently selected control point; -1 means no point selected
417 
418  std::vector<PolyLineType> m_PolyLines;
419  std::vector<PolyLineType> m_HelperPolyLines;
420  BoolContainerType::Pointer m_HelperPolyLinesToBePainted;
421 
422  // this point is used to store the coordinates an additional 'ControlPoint' that is rendered
423  // when the mouse cursor is above the figure (and not a control-point) and when the
424  // property 'planarfigure.isextendable' is set to true
427 
429 
430  private:
431  // not implemented to prevent PlanarFigure::New() calls which would create an itk::Object.
432  static Pointer New();
433 
434  struct Feature
435  {
436  Feature(const char *name, const char *unit) : Name(name), Unit(unit), Quantity(0.0), Active(true), Visible(true)
437  {
438  }
439 
440  std::string Name;
441  std::string Unit;
442  double Quantity;
443  bool Active;
444  bool Visible;
445  };
446 
447  bool m_PolyLineUpToDate;
448  bool m_HelperLinesUpToDate;
449  bool m_FeaturesUpToDate;
450 
451  // Vector of features available for this geometric figure
452  typedef std::vector<Feature> FeatureVectorType;
453  FeatureVectorType m_Features;
454 
455  unsigned long m_FeaturesMTime;
456 
457  // this pair is used to store the mmInDisplayUnits (m_DisplaySize.first) and the displayHeight
458  // (m_DisplaySize.second)
459  // that the helperPolyLines have been calculated for.
460  // It's used to determine whether or not GetHelperPolyLine() needs to recalculate the HelperPolyLines.
461  std::pair<double, unsigned int> m_DisplaySize;
462  };
463 
474  const mitk::PlanarFigure &rightHandSide,
475  ScalarType eps,
476  bool verbose);
477 
478 } // namespace mitk
479 
480 #endif
#define MITKPLANARFIGURE_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
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 feature.
virtual unsigned int GetNumberOfFeatures() const
Returns the number of features available for this PlanarFigure.
void ClearPolyLines()
clears the list of PolyLines. Call before re-calculating a new Polyline.
void ActivateFeature(unsigned int index)
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Inherited from BaseData. Checks if the requested region is outside the buffered region.
void SetFeatureUnit(unsigned int index, const char *unitName)
BoolContainerType::Pointer m_HelperPolyLinesToBePainted
virtual bool SetCurrentControlPoint(const Point2D &point)
Sets the position of the currently selected control 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
Inherited from BaseData. Sets the requested region to the largest possible.
void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines)
defines the number of HelperPolyLines that will be available
virtual void RemoveControlPoint(unsigned int index)
Removes the control point at the given index.
mitkClassMacro(PlanarFigure, BaseData)
unsigned int m_NumberOfControlPoints
bool IsFeatureVisible(unsigned int index) const
Returns whether the specified feature is set to 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 (const version).
void ResetPreviewContolPoint()
Marks the PreviewControlPoint as invisible.
std::deque< Point2D > ControlPointListType
Type for the list of control points defining the figure.
double GetQuantity(unsigned int index) const
Returns the quantity of the specified feature.
bool IsPreviewControlPointVisible() const
Returns whether or not the PreviewControlPoint is visible.
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)
Sets the visibility of the specified feature for annotation display.
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 a helper polyline that should be drawn at a fixed size regardless of zoom.
virtual bool Equals(const mitk::PlanarFigure &other) const
Compares this PlanarFigure with another for equality.
bool VerifyRequestedRegion() override
Inherited from BaseData. Verifies the requested region.
virtual bool ResetOnPointSelectNeeded() const
void SetRequestedRegion(const itk::DataObject *data) override
Inherited from BaseData. Sets the requested region from another data object.
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
Type for a polyline (vector of 2D points).
virtual void RemoveLastControlPoint()
Removes the last control point from the figure.
itk::VectorContainer< unsigned long, bool > BoolContainerType
Container type for boolean values, used for helper polyline paint flags.
const char * GetFeatureName(unsigned int index) const
Returns the name (identifier) of the specified feature.
void DeactivateFeature(unsigned int index)
virtual Point2D ApplyControlPointConstraints(unsigned int index, const Point2D &point)
Applies spatial constraints to a control point position.
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 whether the specified feature is active.
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 (mutable version).
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)
Resets the number of control points to the specified count.
virtual bool ResetOnPointSelect()
Returns true if the planar figure is reset to "add points" mode when a point is selected.
void UpdateOutputInformation() override
Inherited from BaseData. Updates geometry information.
Point2D PolyLineElement
Type for individual elements of a polyline (2D points).
virtual bool SetControlPoint(unsigned int index, const Point2D &point, bool createIfDoesNotExist=false)
Sets the position of an existing control point, optionally creating it if missing.
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 the geometry of a plane object.
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
double ScalarType
Scalar type used throughout MITK for geometric computations.
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.