ITK  6.0.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  ITK_DEFAULT_COPY_AND_MOVE(SpatialObjectPoint);
48 
49  using PointDimensionType = unsigned int;
50 
51  static constexpr PointDimensionType PointDimension = TPointDimension;
52 
55 
57  virtual ~SpatialObjectPoint() = default;
58 
60  itkVirtualGetNameOfClassMacro(SpatialObjectPoint);
61 
63 
65 
67  using VectorType = vnl_vector<double>;
69 
71  void
72  SetId(int id)
73  {
74  m_Id = id;
75  }
76 
78  int
79  GetId() const
80  {
81  return m_Id;
82  }
83 
85  void
86  SetPositionInObjectSpace(const PointType & newPositionInObjectSpace)
87  {
88  m_PositionInObjectSpace = newPositionInObjectSpace;
89  }
90 
91  template <typename... TCoordinate>
92  void
93  SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
94  {
95  static_assert((1 + sizeof...(otherCoordinate)) == TPointDimension,
96  "The number of coordinates must be equal to the dimensionality!");
97  const double coordinates[] = { firstCoordinate, static_cast<double>(otherCoordinate)... };
98  m_PositionInObjectSpace = coordinates;
99  }
100 
102  const PointType &
104  {
105  return m_PositionInObjectSpace;
106  }
107 
108  void
110  {
111  m_SpatialObject = so;
112  }
113 
114  SpatialObjectType *
116  {
117  return m_SpatialObject;
118  }
119 
122  void
123  SetPositionInWorldSpace(const PointType & point);
124 
127  PointType
128  GetPositionInWorldSpace() const;
129 
131  void
133  {
134  m_Color = color;
135  }
136 
137  ColorType
138  GetColor() const
139  {
140  return m_Color;
141  }
142 
144  void
145  SetColor(double r, double g, double b, double a = 1);
146 
148  void
149  SetRed(double r)
150  {
151  m_Color.SetRed(r);
152  }
153 
154  double
155  GetRed() const
156  {
157  return m_Color.GetRed();
158  }
159 
161  void
162  SetGreen(double g)
163  {
164  m_Color.SetGreen(g);
165  }
166 
167  double
168  GetGreen() const
169  {
170  return m_Color.GetGreen();
171  }
172 
174  void
175  SetBlue(double b)
176  {
177  m_Color.SetBlue(b);
178  }
179 
180  double
181  GetBlue() const
182  {
183  return m_Color.GetBlue();
184  }
185 
187  void
188  SetAlpha(double a)
189  {
190  m_Color.SetAlpha(a);
191  }
192 
193  double
194  GetAlpha() const
195  {
196  return m_Color.GetAlpha();
197  }
198 
199  void
200  SetTagScalarValue(const std::string & tag, double value);
201 
202  bool
203  GetTagScalarValue(const std::string & tag, double & value) const;
204 
205  double
206  GetTagScalarValue(const std::string & tag) const;
207 
208  std::map<std::string, double> &
209  GetTagScalarDictionary();
210 
211  const std::map<std::string, double> &
212  GetTagScalarDictionary() const;
213 
214  void
215  SetTagScalarDictionary(const std::map<std::string, double> & dict);
216 
218  void
219  Print(std::ostream & os) const
220  {
221  this->PrintSelf(os, 3);
222  }
223 
224 protected:
226  virtual void
227  PrintSelf(std::ostream & os, Indent indent) const;
228 
230  int m_Id{};
231 
233  PointType m_PositionInObjectSpace{};
234 
236  ColorType m_Color{};
237 
239  std::map<std::string, double> m_ScalarDictionary{};
240 
241 
242  // The SpatialObjectPoint keeps a reference to its owning parent
243  // spatial object for its spatial context. A WeakPointer is used to
244  // avoid a memory leak.
246 };
247 
248 } // end of namespace itk
249 
250 #ifndef ITK_MANUAL_INSTANTIATION
251 # include "itkSpatialObjectPoint.hxx"
252 #endif
253 
254 #endif // itkSpatialObjectPoint_h
itk::SpatialObjectPoint::Print
void Print(std::ostream &os) const
Definition: itkSpatialObjectPoint.h:219
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
Definition: itkSpatialObjectPoint.h:93
itk::SpatialObjectPoint::SetRed
void SetRed(double r)
Definition: itkSpatialObjectPoint.h:149
itk::SpatialObjectPoint::GetGreen
double GetGreen() const
Definition: itkSpatialObjectPoint.h:168
itkSpatialObject.h
itkPoint.h
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const PointType &newPositionInObjectSpace)
Definition: itkSpatialObjectPoint.h:86
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SpatialObjectPoint::SetSpatialObject
void SetSpatialObject(SpatialObjectType *so)
Definition: itkSpatialObjectPoint.h:109
itkRGBAPixel.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SpatialObjectPoint::SetId
void SetId(int id)
Definition: itkSpatialObjectPoint.h:72
itk::SpatialObjectPoint::GetAlpha
double GetAlpha() const
Definition: itkSpatialObjectPoint.h:194
itk::SpatialObjectPoint::GetColor
ColorType GetColor() const
Definition: itkSpatialObjectPoint.h:138
itk::SpatialObjectPoint::GetBlue
double GetBlue() const
Definition: itkSpatialObjectPoint.h:181
itk::SpatialObjectPoint::PointDimensionType
unsigned int PointDimensionType
Definition: itkSpatialObjectPoint.h:49
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:188
itk::SpatialObjectPoint::SetColor
void SetColor(ColorType color)
Definition: itkSpatialObjectPoint.h:132
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:58
itk::SpatialObjectPoint::GetId
int GetId() const
Definition: itkSpatialObjectPoint.h:79
itk::SpatialObjectPoint::SetGreen
void SetGreen(double g)
Definition: itkSpatialObjectPoint.h:162
itk::SpatialObjectPoint::GetSpatialObject
SpatialObjectType * GetSpatialObject() const
Definition: itkSpatialObjectPoint.h:115
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:103
itk::SpatialObjectPoint::SetBlue
void SetBlue(double b)
Definition: itkSpatialObjectPoint.h:175
itk::Point< double, TPointDimension >
itk::SpatialObjectPoint::VectorType
vnl_vector< double > VectorType
Definition: itkSpatialObjectPoint.h:67
itk::SpatialObjectPoint::GetRed
double GetRed() const
Definition: itkSpatialObjectPoint.h:155
itk::SpatialObjectPoint
Point used for spatial objects.
Definition: itkSpatialObjectPoint.h:44