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
28namespace itk
29{
40template <unsigned int TDimension, class TSpatialObjectPointType>
41class PointBasedSpatialObject;
42
43template <unsigned int TPointDimension = 3>
44class ITK_TEMPLATE_EXPORT SpatialObjectPoint
45{
46public:
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
125
130
132 Self &
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> &
215
216 const std::map<std::string, double> &
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
229protected:
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
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Point used for spatial objects.
const std::map< std::string, double > & GetTagScalarDictionary() const
void SetColor(ColorType color)
virtual ~SpatialObjectPoint()=default
bool GetTagScalarValue(const std::string &tag, double &value) const
double GetTagScalarValue(const std::string &tag) const
void SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
std::map< std::string, double > & GetTagScalarDictionary()
void SetTagScalarValue(const std::string &tag, double value)
void SetPositionInObjectSpace(const PointType &newPositionInObjectSpace)
void SetColor(double r, double g, double b, double a=1)
PointType GetPositionInWorldSpace() const
void Print(std::ostream &os) const
Self & operator=(const SpatialObjectPoint &rhs)
SpatialObjectPoint(const SpatialObjectPoint &other)
void SetPositionInWorldSpace(const PointType &point)
SpatialObjectType * GetSpatialObject() const
const PointType & GetPositionInObjectSpace() const
virtual void PrintSelf(std::ostream &os, Indent indent) const
void SetTagScalarDictionary(const std::map< std::string, double > &dict)
void SetSpatialObject(SpatialObjectType *so)
vnl_vector< double > VectorType
Implementation of the composite pattern.
Implements a weak reference to an object.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
*par Constraints *The filter 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