ITK  5.2.0
Insight Toolkit
itkSpatialObjectPoint.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkSpatialObjectPoint_h
19 #define itkSpatialObjectPoint_h
20 
21 #include "itkSpatialObject.h"
22 
23 #include "itkPoint.h"
24 #include "vnl/vnl_vector_fixed.h"
25 #include "itkRGBAPixel.h"
26 
27 
28 namespace itk
29 {
40 template <unsigned int TDimension, class TSpatialObjectPointType>
41 class PointBasedSpatialObject;
42 
43 template <unsigned int TPointDimension = 3>
44 class ITK_TEMPLATE_EXPORT SpatialObjectPoint
45 {
46 public:
47  using PointDimensionType = unsigned int;
48 
49  static constexpr PointDimensionType PointDimension = TPointDimension;
50 
53 
56 
58  virtual ~SpatialObjectPoint() = default;
59 
60  virtual const char *
62  {
63  return "SpatialObjectPoint";
64  };
65 
67 
69 
71  using VectorType = vnl_vector<double>;
73 
75  void
76  SetId(int id)
77  {
78  m_Id = id;
79  }
80 
82  int
83  GetId() const
84  {
85  return m_Id;
86  }
87 
89  void
90  SetPositionInObjectSpace(const PointType & newPositionInObjectSpace)
91  {
92  m_PositionInObjectSpace = newPositionInObjectSpace;
93  }
94 
95  template <typename... TCoordinate>
96  void
97  SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
98  {
99  static_assert((1 + sizeof...(otherCoordinate)) == TPointDimension,
100  "The number of coordinates must be equal to the dimensionality!");
101  const double coordinates[] = { firstCoordinate, static_cast<double>(otherCoordinate)... };
102  m_PositionInObjectSpace = coordinates;
103  }
104 
106  const PointType &
108  {
109  return m_PositionInObjectSpace;
110  }
111 
112  void
114  {
115  m_SpatialObject = so;
116  }
117 
118  SpatialObjectType *
120  {
121  return m_SpatialObject;
122  }
123 
126  void
127  SetPositionInWorldSpace(const PointType & point);
128 
131  PointType
132  GetPositionInWorldSpace() const;
133 
135  Self &
136  operator=(const SpatialObjectPoint & rhs);
137 
139  void
141  {
142  m_Color = color;
143  }
144 
145  ColorType
146  GetColor() const
147  {
148  return m_Color;
149  }
150 
152  void
153  SetColor(double r, double g, double b, double a = 1);
154 
156  void
157  SetRed(double r)
158  {
159  m_Color.SetRed(r);
160  }
161 
162  double
163  GetRed() const
164  {
165  return m_Color.GetRed();
166  }
167 
169  void
170  SetGreen(double g)
171  {
172  m_Color.SetGreen(g);
173  }
174 
175  double
176  GetGreen() const
177  {
178  return m_Color.GetGreen();
179  }
180 
182  void
183  SetBlue(double b)
184  {
185  m_Color.SetBlue(b);
186  }
187 
188  double
189  GetBlue() const
190  {
191  return m_Color.GetBlue();
192  }
193 
195  void
196  SetAlpha(double a)
197  {
198  m_Color.SetAlpha(a);
199  }
200 
201  double
202  GetAlpha() const
203  {
204  return m_Color.GetAlpha();
205  }
206 
207  void
208  SetTagScalarValue(const std::string & tag, double value);
209 
210  bool
211  GetTagScalarValue(const std::string & tag, double & value) const;
212 
213  double
214  GetTagScalarValue(const std::string & tag) const;
215 
216  std::map<std::string, double> &
217  GetTagScalarDictionary();
218 
219  const std::map<std::string, double> &
220  GetTagScalarDictionary() const;
221 
222  void
223  SetTagScalarDictionary(const std::map<std::string, double> & dict);
224 
226  void
227  Print(std::ostream & os) const
228  {
229  this->PrintSelf(os, 3);
230  }
231 
232 protected:
234  virtual void
235  PrintSelf(std::ostream & os, Indent indent) const;
236 
238  int m_Id;
239 
242 
245 
247  std::map<std::string, double> m_ScalarDictionary;
248 
249 
250  // The SpatialObjectPoint keeps a reference to its owning parent
251  // spatial object for its spatial context. A WeakPointer is used to
252  // avoid a memory leak.
254 };
255 
256 } // end of namespace itk
257 
258 #ifndef ITK_MANUAL_INSTANTIATION
259 # include "itkSpatialObjectPoint.hxx"
260 #endif
261 
262 #endif // itkSpatialObjectPoint_h
itk::SpatialObjectPoint::m_Id
int m_Id
Definition: itkSpatialObjectPoint.h:238
itk::SpatialObjectPoint::Print
void Print(std::ostream &os) const
Definition: itkSpatialObjectPoint.h:227
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
Definition: itkSpatialObjectPoint.h:97
itk::SpatialObjectPoint::SetRed
void SetRed(double r)
Definition: itkSpatialObjectPoint.h:157
itk::SpatialObjectPoint::GetGreen
double GetGreen() const
Definition: itkSpatialObjectPoint.h:176
itkSpatialObject.h
itkPoint.h
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const PointType &newPositionInObjectSpace)
Definition: itkSpatialObjectPoint.h:90
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SpatialObjectPoint::SetSpatialObject
void SetSpatialObject(SpatialObjectType *so)
Definition: itkSpatialObjectPoint.h:113
itkRGBAPixel.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SpatialObjectPoint::SetId
void SetId(int id)
Definition: itkSpatialObjectPoint.h:76
itk::SpatialObjectPoint::GetAlpha
double GetAlpha() const
Definition: itkSpatialObjectPoint.h:202
itk::SpatialObjectPoint::GetColor
ColorType GetColor() const
Definition: itkSpatialObjectPoint.h:146
itk::SpatialObjectPoint::GetBlue
double GetBlue() const
Definition: itkSpatialObjectPoint.h:189
itk::SpatialObjectPoint::PointDimensionType
unsigned int PointDimensionType
Definition: itkSpatialObjectPoint.h:47
itk::SpatialObjectPoint::SetAlpha
void SetAlpha(double a)
Definition: itkSpatialObjectPoint.h:196
itk::SpatialObjectPoint::m_SpatialObject
WeakPointer< SpatialObjectType > m_SpatialObject
Definition: itkSpatialObjectPoint.h:253
itk::SpatialObjectPoint::SetColor
void SetColor(ColorType color)
Definition: itkSpatialObjectPoint.h:140
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:57
itk::SpatialObjectPoint::GetId
int GetId() const
Definition: itkSpatialObjectPoint.h:83
itk::SpatialObjectPoint::GetNameOfClass
virtual const char * GetNameOfClass() const
Definition: itkSpatialObjectPoint.h:61
itk::SpatialObjectPoint::SetGreen
void SetGreen(double g)
Definition: itkSpatialObjectPoint.h:170
itk::SpatialObjectPoint::GetSpatialObject
SpatialObjectType * GetSpatialObject() const
Definition: itkSpatialObjectPoint.h:119
itk::WeakPointer
Implements a weak reference to an object.
Definition: itkWeakPointer.h:44
itk::RGBAPixel< double >
itk::SpatialObjectPoint::m_ScalarDictionary
std::map< std::string, double > m_ScalarDictionary
Definition: itkSpatialObjectPoint.h:247
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::SpatialObjectPoint::m_PositionInObjectSpace
PointType m_PositionInObjectSpace
Definition: itkSpatialObjectPoint.h:241
itk::SpatialObjectPoint::GetPositionInObjectSpace
const PointType & GetPositionInObjectSpace() const
Definition: itkSpatialObjectPoint.h:107
itk::SpatialObjectPoint::SetBlue
void SetBlue(double b)
Definition: itkSpatialObjectPoint.h:183
itk::Point< double, TPointDimension >
itk::SpatialObjectPoint::VectorType
vnl_vector< double > VectorType
Definition: itkSpatialObjectPoint.h:71
itk::SpatialObjectPoint::m_Color
ColorType m_Color
Definition: itkSpatialObjectPoint.h:244
itk::SpatialObjectPoint::GetRed
double GetRed() const
Definition: itkSpatialObjectPoint.h:163
itk::SpatialObjectPoint
Point used for spatial objets.
Definition: itkSpatialObjectPoint.h:44