Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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:
53  mitkClassMacro(PlanarFigure, BaseData) itkCloneMacro(Self)
54 
56 
57  typedef itk::VectorContainer<unsigned long, bool> BoolContainerType;
58 
59  typedef std::deque<Point2D> ControlPointListType;
60  typedef std::vector<PolyLineElement> PolyLineType;
61 
68  virtual void SetPlaneGeometry(mitk::PlaneGeometry *geometry);
69 
71  virtual const PlaneGeometry *GetPlaneGeometry() const;
72 
76  virtual bool IsClosed() const;
77 
80  virtual bool IsPlaced() const { return m_FigurePlaced; };
91  virtual void PlaceFigure(const Point2D &point);
92 
103  virtual bool AddControlPoint(const Point2D &point, int index = -1);
104 
105  virtual bool SetControlPoint(unsigned int index, const Point2D &point, bool createIfDoesNotExist = false);
106 
107  virtual bool SetCurrentControlPoint(const Point2D &point);
108 
110  unsigned int GetNumberOfControlPoints() const;
111 
117  virtual unsigned int GetMinimumNumberOfControlPoints() const = 0;
118 
124  virtual unsigned int GetMaximumNumberOfControlPoints() const = 0;
125 
127  virtual bool SelectControlPoint(unsigned int index);
128 
130  virtual bool DeselectControlPoint();
131 
133  virtual int GetSelectedControlPoint() const { return m_SelectedControlPoint; }
135  Point2D GetControlPoint(unsigned int index) const;
136 
141  virtual int GetControlPointForPolylinePoint(int indexOfPolylinePoint, int polyLineIndex) const;
142 
144  Point3D GetWorldControlPoint(unsigned int index) const;
145 
148  const PolyLineType GetPolyLine(unsigned int index);
149 
152  const PolyLineType GetPolyLine(unsigned int index) const;
153 
156  const PolyLineType GetHelperPolyLine(unsigned int index, double mmPerDisplayUnit, unsigned int displayHeight);
157 
159  void SetPreviewControlPoint(const Point2D &point);
160 
162  void ResetPreviewContolPoint();
163 
165  bool IsPreviewControlPointVisible() const;
166 
168  Point2D GetPreviewControlPoint() const;
169 
172  virtual unsigned int GetNumberOfFeatures() const;
173 
175  const char *GetFeatureName(unsigned int index) const;
176 
178  const char *GetFeatureUnit(unsigned int index) const;
179 
182  double GetQuantity(unsigned int index) const;
183 
187  bool IsFeatureActive(unsigned int index) const;
188 
190  bool IsFeatureVisible(unsigned int index) const;
191 
194  void SetFeatureVisible(unsigned int index, bool visible);
195 
197  virtual void EvaluateFeatures();
198 
200  void UpdateOutputInformation() override;
201 
203  void SetRequestedRegionToLargestPossibleRegion() override;
204 
206  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
207 
209  bool VerifyRequestedRegion() override;
210 
212  void SetRequestedRegion(const itk::DataObject *data) override;
213 
215  virtual unsigned short GetPolyLinesSize();
216 
218  virtual unsigned short GetHelperPolyLinesSize() const;
219 
221  virtual bool IsHelperToBePainted(unsigned int index) const;
222 
228  virtual bool ResetOnPointSelect();
229  virtual bool ResetOnPointSelectNeeded() const;
230 
232  virtual void RemoveControlPoint(unsigned int index);
233 
235  virtual void RemoveLastControlPoint();
236 
242  virtual Point2D ApplyControlPointConstraints(unsigned int /*index*/, const Point2D &point);
243 
248  virtual bool Equals(const mitk::PlanarFigure &other) const;
249 
251  void ResetNumberOfControlPoints(int numberOfControlPoints);
252 
253  protected:
254  PlanarFigure();
255 
256  PlanarFigure(const Self &other);
257 
261  virtual unsigned int AddFeature(const char *featureName, const char *unitName);
262 
264  void SetFeatureName(unsigned int index, const char *featureName);
265 
267  void SetFeatureUnit(unsigned int index, const char *unitName);
268 
270  void SetQuantity(unsigned int index, double quantity);
271 
273  void ActivateFeature(unsigned int index);
274 
276  void DeactivateFeature(unsigned int index);
277 
280  virtual void GeneratePolyLine() = 0;
281 
284  virtual void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) = 0;
285 
288  virtual void EvaluateFeaturesInternal() = 0;
289 
293  void InitializeTimeGeometry(unsigned int timeSteps = 1) override;
294 
296  void SetNumberOfPolyLines(unsigned int numberOfPolyLines);
297 
299  void AppendPointToPolyLine(unsigned int index, PolyLineElement element);
300 
302  void ClearPolyLines();
303 
305  void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines);
306 
308  void AppendPointToHelperPolyLine(unsigned int index, PolyLineElement element);
309 
311  void ClearHelperPolyLines();
312 
313  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
314 
317 
318  // Currently selected control point; -1 means no point selected
320 
321  std::vector<PolyLineType> m_PolyLines;
322  std::vector<PolyLineType> m_HelperPolyLines;
323  BoolContainerType::Pointer m_HelperPolyLinesToBePainted;
324 
325  // this point is used to store the coordiantes an additional 'ControlPoint' that is rendered
326  // when the mouse cursor is above the figure (and not a control-point) and when the
327  // property 'planarfigure.isextendable' is set to true
330 
332 
333  private:
334  // not implemented to prevent PlanarFigure::New() calls which would create an itk::Object.
335  static Pointer New();
336 
337  struct Feature
338  {
339  Feature(const char *name, const char *unit) : Name(name), Unit(unit), Quantity(0.0), Active(true), Visible(true)
340  {
341  }
342 
343  std::string Name;
344  std::string Unit;
345  double Quantity;
346  bool Active;
347  bool Visible;
348  };
349 
350  itk::LightObject::Pointer InternalClone() const override = 0;
351 
352  PlaneGeometry *m_PlaneGeometry;
353 
354  bool m_PolyLineUpToDate;
355  bool m_HelperLinesUpToDate;
356  bool m_FeaturesUpToDate;
357 
358  // Vector of features available for this geometric figure
359  typedef std::vector<Feature> FeatureVectorType;
360  FeatureVectorType m_Features;
361 
362  unsigned long m_FeaturesMTime;
363 
364  // this pair is used to store the mmInDisplayUnits (m_DisplaySize.first) and the displayHeight
365  // (m_DisplaySize.second)
366  // that the helperPolyLines have been calculated for.
367  // It's used to determine whether or not GetHelperPolyLine() needs to recalculate the HelperPolyLines.
368  std::pair<double, unsigned int> m_DisplaySize;
369  };
370 
371  MITKPLANARFIGURE_EXPORT bool Equal(const mitk::PlanarFigure &leftHandSide,
372  const mitk::PlanarFigure &rightHandSide,
373  ScalarType eps,
374  bool verbose);
375 
376 } // namespace mitk
377 
378 #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
STL namespace.
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
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.