ITK  5.4.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  * https://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 
61  itkVirtualGetNameOfClassMacro(SpatialObjectPoint);
62 
64 
66 
68  using VectorType = vnl_vector<double>;
70 
72  void
73  SetId(int id)
74  {
75  m_Id = id;
76  }
77 
79  int
80  GetId() const
81  {
82  return m_Id;
83  }
84 
86  void
87  SetPositionInObjectSpace(const PointType & newPositionInObjectSpace)
88  {
89  m_PositionInObjectSpace = newPositionInObjectSpace;
90  }
91 
92  template <typename... TCoordinate>
93  void
94  SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
95  {
96  static_assert((1 + sizeof...(otherCoordinate)) == TPointDimension,
97  "The number of coordinates must be equal to the dimensionality!");
98  const double coordinates[] = { firstCoordinate, static_cast<double>(otherCoordinate)... };
99  m_PositionInObjectSpace = coordinates;
100  }
101 
103  const PointType &
105  {
106  return m_PositionInObjectSpace;
107  }
108 
109  void
111  {
112  m_SpatialObject = so;
113  }
114 
115  SpatialObjectType *
117  {
118  return m_SpatialObject;
119  }
120 
123  void
124  SetPositionInWorldSpace(const PointType & point);
125 
128  PointType
129  GetPositionInWorldSpace() const;
130 
132  Self &
133  operator=(const SpatialObjectPoint & rhs);
134 
136  void
138  {
139  m_Color = color;
140  }
141 
142  ColorType
143  GetColor() const
144  {
145  return m_Color;
146  }
147 
149  void
150  SetColor(double r, double g, double b, double a = 1);
151 
153  void
154  SetRed(double r)
155  {
156  m_Color.SetRed(r);
157  }
158 
159  double
160  GetRed() const
161  {
162  return m_Color.GetRed();
163  }
164 
166  void
167  SetGreen(double g)
168  {
169  m_Color.SetGreen(g);
170  }
171 
172  double
173  GetGreen() const
174  {
175  return m_Color.GetGreen();
176  }
177 
179  void
180  SetBlue(double b)
181  {
182  m_Color.SetBlue(b);
183  }
184 
185  double
186  GetBlue() const
187  {
188  return m_Color.GetBlue();
189  }
190 
192  void
193  SetAlpha(double a)
194  {
195  m_Color.SetAlpha(a);
196  }
197 
198  double
199  GetAlpha() const
200  {
201  return m_Color.GetAlpha();
202  }
203 
204  void
205  SetTagScalarValue(const std::string & tag, double value);
206 
207  bool
208  GetTagScalarValue(const std::string & tag, double & value) const;
209 
210  double
211  GetTagScalarValue(const std::string & tag) const;
212 
213  std::map<std::string, double> &
214  GetTagScalarDictionary();
215 
216  const std::map<std::string, double> &
217  GetTagScalarDictionary() const;
218 
219  void
220  SetTagScalarDictionary(const std::map<std::string, double> & dict);
221 
223  void
224  Print(std::ostream & os) const
225  {
226  this->PrintSelf(os, 3);
227  }
228 
229 protected:
231  virtual void
232  PrintSelf(std::ostream & os, Indent indent) const;
233 
235  int m_Id{};
236 
238  PointType m_PositionInObjectSpace{};
239 
241  ColorType m_Color{};
242 
244  std::map<std::string, double> m_ScalarDictionary{};
245 
246 
247  // The SpatialObjectPoint keeps a reference to its owning parent
248  // spatial object for its spatial context. A WeakPointer is used to
249  // avoid a memory leak.
251 };
252 
253 } // end of namespace itk
254 
255 #ifndef ITK_MANUAL_INSTANTIATION
256 # include "itkSpatialObjectPoint.hxx"
257 #endif
258 
259 #endif // itkSpatialObjectPoint_h
itk::SpatialObjectPoint::Print
void Print(std::ostream &os) const
Definition: itkSpatialObjectPoint.h:224
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
Definition: itkSpatialObjectPoint.h:94
itk::SpatialObjectPoint::SetRed
void SetRed(double r)
Definition: itkSpatialObjectPoint.h:154
itk::SpatialObjectPoint::GetGreen
double GetGreen() const
Definition: itkSpatialObjectPoint.h:173
itkSpatialObject.h
itkPoint.h
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const PointType &newPositionInObjectSpace)
Definition: itkSpatialObjectPoint.h:87
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SpatialObjectPoint::SetSpatialObject
void SetSpatialObject(SpatialObjectType *so)
Definition: itkSpatialObjectPoint.h:110
itkRGBAPixel.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SpatialObjectPoint::SetId
void SetId(int id)
Definition: itkSpatialObjectPoint.h:73
itk::SpatialObjectPoint::GetAlpha
double GetAlpha() const
Definition: itkSpatialObjectPoint.h:199
itk::SpatialObjectPoint::GetColor
ColorType GetColor() const
Definition: itkSpatialObjectPoint.h:143
itk::SpatialObjectPoint::GetBlue
double GetBlue() const
Definition: itkSpatialObjectPoint.h:186
itk::SpatialObjectPoint::PointDimensionType
unsigned int PointDimensionType
Definition: itkSpatialObjectPoint.h:47
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
itk::SpatialObjectPoint::SetAlpha
void SetAlpha(double a)
Definition: itkSpatialObjectPoint.h:193
itk::SpatialObjectPoint::SetColor
void SetColor(ColorType color)
Definition: itkSpatialObjectPoint.h:137
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:58
itk::SpatialObjectPoint::GetId
int GetId() const
Definition: itkSpatialObjectPoint.h:80
itk::SpatialObjectPoint::SetGreen
void SetGreen(double g)
Definition: itkSpatialObjectPoint.h:167
itk::SpatialObjectPoint::GetSpatialObject
SpatialObjectType * GetSpatialObject() const
Definition: itkSpatialObjectPoint.h:116
itk::WeakPointer
Implements a weak reference to an object.
Definition: itkWeakPointer.h:44
itk::RGBAPixel< double >
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::SpatialObjectPoint::GetPositionInObjectSpace
const PointType & GetPositionInObjectSpace() const
Definition: itkSpatialObjectPoint.h:104
itk::SpatialObjectPoint::SetBlue
void SetBlue(double b)
Definition: itkSpatialObjectPoint.h:180
itk::Point< double, TPointDimension >
itk::SpatialObjectPoint::VectorType
vnl_vector< double > VectorType
Definition: itkSpatialObjectPoint.h:68
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::SpatialObjectPoint::GetRed
double GetRed() const
Definition: itkSpatialObjectPoint.h:160
itk::SpatialObjectPoint
Point used for spatial objects.
Definition: itkSpatialObjectPoint.h:44