File: ImageAnnotationData.h

package info (click to toggle)
itksnap 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,132 kB
  • sloc: cpp: 91,089; ansic: 1,994; sh: 327; makefile: 16
file content (181 lines) | stat: -rw-r--r-- 4,313 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#ifndef IMAGEANNOTATIONDATA_H
#define IMAGEANNOTATIONDATA_H

#include "SNAPCommon.h"
#include <utility>
#include <string>
#include <list>
#include "itkDataObject.h"
#include "itkObjectFactory.h"

class Registry;

namespace annot
{

typedef Vector3d Point;

/**
 * @brief Slices where the annotation is displayed
 */
enum VisSlice {
  SINGLE_SLICE = 0, ALL_SLICES
};

/**
 * @brief Parent class for annotations
 */
class AbstractAnnotation : public itk::DataObject
{
public:
  irisITKAbstractObjectMacro(AbstractAnnotation, itk::DataObject)

  /** Whether this annotation is currently selected */
  irisGetSetMacro(Selected, bool)

  /** Whether this annotation is visible in all slices or just its own slice */
  irisGetSetMacro(VisibleInAllSlices, bool)

  /** Whether this annotation is visible in all ortho planes or just its own plane */
  irisGetSetMacro(VisibleInAllPlanes, bool)

  /** The image dimension to which this annotation belongs, or -1 if it's non-planar */
  irisGetSetMacro(Plane, int)

  /** Get the color of the annotation */
  irisGetSetMacro(Color, const Vector3d &)

  /** Test whether the annotation is visible in the current plane and given slice */
  bool IsVisible(int plane, int slice) const;

  /** Test whether the annotation is visible in the current plane in some slice */
  bool IsVisible(int plane) const;

  /** Get the slice this annotation belongs to for a particular plane */
  virtual int GetSliceIndex(int plane) const = 0;

  /** Get the anchor point for the annotation in a given plane - used for sorting */
  virtual Vector3d GetAnchorPoint(int plane) const = 0;

  /** Move the annotation by given amount in physical space */
  virtual void MoveBy(const Vector3d &offset) = 0;

  /** Save the annotation data to registry */
  virtual void Save(Registry &folder);

  /** Load from the registry */
  virtual void Load(Registry &folder);

protected:

  AbstractAnnotation() {}
  ~AbstractAnnotation() {}

  bool m_Selected;
  bool m_VisibleInAllSlices;
  bool m_VisibleInAllPlanes;

  Vector3d m_Color;

  int m_Plane;
};

/** A simple line segment */
typedef std::pair<Vector3d,Vector3d>           LineSegment;

class LineSegmentAnnotation : public AbstractAnnotation
{
public:
  irisITKObjectMacro(LineSegmentAnnotation, AbstractAnnotation)

  typedef LineSegment                   ObjectType;

  irisGetSetMacro(Segment, const LineSegment &)

  virtual void Save(Registry &folder);
  virtual void Load(Registry &folder);

  virtual void MoveBy(const Vector3d &offset);

protected:

  virtual int GetSliceIndex(int plane) const;

  virtual Vector3d GetAnchorPoint(int plane) const;

  LineSegment m_Segment;
};

/**
 * @brief Text with location
 */
struct Landmark
{
  std::string Text;
  Vector3d Pos;
  Vector2d Offset;
};

class LandmarkAnnotation : public AbstractAnnotation
{
public:
  irisITKObjectMacro(LandmarkAnnotation, AbstractAnnotation)

  typedef Landmark                   ObjectType;

  irisGetSetMacro(Landmark, const Landmark &)


protected:

  virtual int GetSliceIndex(int plane) const;
  virtual Vector3d GetAnchorPoint(int plane) const;

  virtual void MoveBy(const Vector3d &offset);

  virtual void Save(Registry &folder);
  virtual void Load(Registry &folder);

  Landmark m_Landmark;
};

}


/**
 * This class describes a collection of image annotations
 *
 * Image annotations are defined in voxel coordinate space. This helps keep the
 * annotations in place when header information changes. It also makes the internal
 * logic simpler.
 */
class ImageAnnotationData : public itk::DataObject
{
public:
  typedef annot::AbstractAnnotation AbstractAnnotation;
  typedef SmartPtr<AbstractAnnotation> AnnotationPtr;
  typedef std::list<AnnotationPtr> AnnotationList;
  typedef AnnotationList::iterator AnnotationIterator;
  typedef AnnotationList::const_iterator AnnotationConstIterator;

  irisITKObjectMacro(ImageAnnotationData, itk::DataObject)

  irisGetMacro(Annotations, const AnnotationList &)

  AnnotationList &GetAnnotations() { return m_Annotations; }

  void AddAnnotation(AbstractAnnotation *annot);

  void Reset();

  void SaveAnnotations(Registry &reg);
  void LoadAnnotations(Registry &reg);

protected:
  ImageAnnotationData() {}
  ~ImageAnnotationData() {}

  AnnotationList m_Annotations;
};

#endif // IMAGEANNOTATIONDATA_H