Medical Imaging Interaction Toolkit  2018.4.99-07c45cb1
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 _MITK_PLANAR_FIGURE_H_
14 #define _MITK_PLANAR_FIGURE_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 
56  typedef Point2D PolyLineElement;
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  const 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 
163  void ResetPreviewContolPoint();
164 
166  bool IsPreviewControlPointVisible() const;
167 
169  Point2D GetPreviewControlPoint() const;
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 
204  void SetRequestedRegionToLargestPossibleRegion() override;
205 
207  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
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:
255  PlanarFigure();
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 
303  void ClearPolyLines();
304 
306  void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines);
307 
309  void AppendPointToHelperPolyLine(unsigned int index, PolyLineElement element);
310 
312  void ClearHelperPolyLines();
313 
314  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
315 
316  ControlPointListType m_ControlPoints;
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 coordiantes 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  PlaneGeometry *m_PlaneGeometry;
354 
355  bool m_PolyLineUpToDate;
356  bool m_HelperLinesUpToDate;
357  bool m_FeaturesUpToDate;
358 
359  // Vector of features available for this geometric figure
360  typedef std::vector<Feature> FeatureVectorType;
361  FeatureVectorType m_Features;
362 
363  unsigned long m_FeaturesMTime;
364 
365  // this pair is used to store the mmInDisplayUnits (m_DisplaySize.first) and the displayHeight
366  // (m_DisplaySize.second)
367  // that the helperPolyLines have been calculated for.
368  // It's used to determine whether or not GetHelperPolyLine() needs to recalculate the HelperPolyLines.
369  std::pair<double, unsigned int> m_DisplaySize;
370  };
371 
372  MITKPLANARFIGURE_EXPORT bool Equal(const mitk::PlanarFigure &leftHandSide,
373  const mitk::PlanarFigure &rightHandSide,
374  ScalarType eps,
375  bool verbose);
376 
377 } // namespace mitk
378 
379 #endif //_MITK_PLANAR_FIGURE_H_
Base of all data objects.
Definition: mitkBaseData.h:37
void RemoveControlPoint(const SemanticTypes::CaseID &caseID, const SemanticTypes::ControlPoint &controlPoint)
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
itk::VectorContainer< unsigned long, bool > BoolContainerType
void AddControlPoint(const SemanticTypes::CaseID &caseID, const SemanticTypes::ControlPoint &controlPoint)
std::deque< Point2D > ControlPointListType
virtual bool IsPlaced() const
True if the planar figure has been placed (and can be displayed/interacted with). ...
std::vector< PolyLineType > m_HelperPolyLines
ControlPointListType m_ControlPoints
unsigned int m_NumberOfControlPoints
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
bool verbose(false)
#define MITKPLANARFIGURE_EXPORT
virtual int GetSelectedControlPoint() const
Return currently selected control point.
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.
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons...
BoolContainerType::Pointer m_HelperPolyLinesToBePainted
MITKCORE_EXPORT const ScalarType eps
std::vector< PolyLineElement > PolyLineType
std::vector< PolyLineType > m_PolyLines
Describes a two-dimensional, rectangular plane.