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:
49 
52 
54  virtual ~SpatialObjectPoint() = default;
55 
56  virtual const char *
58  {
59  return "SpatialObjectPoint";
60  };
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  Self &
132  operator=(const SpatialObjectPoint & rhs);
133 
135  void
137  {
138  m_Color = color;
139  }
140 
141  ColorType
142  GetColor() const
143  {
144  return m_Color;
145  }
146 
148  void
149  SetColor(double r, double g, double b, double a = 1);
150 
152  void
153  SetRed(double r)
154  {
155  m_Color.SetRed(r);
156  }
157 
158  double
159  GetRed() const
160  {
161  return m_Color.GetRed();
162  }
163 
165  void
166  SetGreen(double g)
167  {
168  m_Color.SetGreen(g);
169  }
170 
171  double
172  GetGreen() const
173  {
174  return m_Color.GetGreen();
175  }
176 
178  void
179  SetBlue(double b)
180  {
181  m_Color.SetBlue(b);
182  }
183 
184  double
185  GetBlue() const
186  {
187  return m_Color.GetBlue();
188  }
189 
191  void
192  SetAlpha(double a)
193  {
194  m_Color.SetAlpha(a);
195  }
196 
197  double
198  GetAlpha() const
199  {
200  return m_Color.GetAlpha();
201  }
202 
204  void
205  Print(std::ostream & os) const
206  {
207  this->PrintSelf(os, 3);
208  }
209 
210 protected:
212  virtual void
213  PrintSelf(std::ostream & os, Indent indent) const;
214 
216  int m_Id;
217 
220 
223 
224  // The SpatialObjectPoint keeps a reference to its owning parent
225  // spatial object for its spatial context. A WeakPointer is used to
226  // avoid a memory leak.
228 };
229 
230 } // end of namespace itk
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 # include "itkSpatialObjectPoint.hxx"
234 #endif
235 
236 #endif // itkSpatialObjectPoint_h
itk::SpatialObjectPoint::m_Id
int m_Id
Definition: itkSpatialObjectPoint.h:216
itk::SpatialObjectPoint::Print
void Print(std::ostream &os) const
Definition: itkSpatialObjectPoint.h:205
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:153
itk::SpatialObjectPoint::GetGreen
double GetGreen() const
Definition: itkSpatialObjectPoint.h:172
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:198
itk::SpatialObjectPoint::GetColor
ColorType GetColor() const
Definition: itkSpatialObjectPoint.h:142
itk::SpatialObjectPoint::GetBlue
double GetBlue() const
Definition: itkSpatialObjectPoint.h:185
itk::SpatialObjectPoint::SetAlpha
void SetAlpha(double a)
Definition: itkSpatialObjectPoint.h:192
itk::SpatialObjectPoint::m_SpatialObject
WeakPointer< SpatialObjectType > m_SpatialObject
Definition: itkSpatialObjectPoint.h:227
itk::SpatialObjectPoint::SetColor
void SetColor(ColorType color)
Definition: itkSpatialObjectPoint.h:136
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:57
itk::SpatialObjectPoint::GetId
int GetId() const
Definition: itkSpatialObjectPoint.h:79
itk::SpatialObjectPoint::GetNameOfClass
virtual const char * GetNameOfClass() const
Definition: itkSpatialObjectPoint.h:57
itk::SpatialObjectPoint::SetGreen
void SetGreen(double g)
Definition: itkSpatialObjectPoint.h:166
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::m_PositionInObjectSpace
PointType m_PositionInObjectSpace
Definition: itkSpatialObjectPoint.h:219
itk::SpatialObjectPoint::GetPositionInObjectSpace
const PointType & GetPositionInObjectSpace() const
Definition: itkSpatialObjectPoint.h:103
itk::SpatialObjectPoint::SetBlue
void SetBlue(double b)
Definition: itkSpatialObjectPoint.h:179
itk::Point< double, TPointDimension >
itk::SpatialObjectPoint::VectorType
vnl_vector< double > VectorType
Definition: itkSpatialObjectPoint.h:67
itk::SpatialObjectPoint::m_Color
ColorType m_Color
Definition: itkSpatialObjectPoint.h:222
itk::SpatialObjectPoint::GetRed
double GetRed() const
Definition: itkSpatialObjectPoint.h:159
itk::SpatialObjectPoint
Point used for spatial objets.
Definition: itkSpatialObjectPoint.h:44