ITK  5.1.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 
51  virtual ~SpatialObjectPoint() = default;
52 
53  virtual const char *
55  {
56  return "SpatialObjectPoint";
57  };
58 
60 
62 
64  using VectorType = vnl_vector<double>;
66 
68  void
69  SetId(int id)
70  {
71  m_Id = id;
72  }
73 
75  int
76  GetId() const
77  {
78  return m_Id;
79  }
80 
82  void
83  SetPositionInObjectSpace(const PointType & newPositionInObjectSpace)
84  {
85  m_PositionInObjectSpace = newPositionInObjectSpace;
86  }
87 
88  template <typename... TCoordinate>
89  void
90  SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
91  {
92  static_assert((1 + sizeof...(otherCoordinate)) == TPointDimension,
93  "The number of coordinates must be equal to the dimensionality!");
94  const double coordinates[] = { firstCoordinate, static_cast<double>(otherCoordinate)... };
95  m_PositionInObjectSpace = coordinates;
96  }
97 
99  const PointType &
101  {
102  return m_PositionInObjectSpace;
103  }
104 
105  void
107  {
108  m_SpatialObject = so;
109  }
110 
111  SpatialObjectType *
113  {
114  return m_SpatialObject;
115  }
116 
119  void
120  SetPositionInWorldSpace(const PointType & point);
121 
124  PointType
125  GetPositionInWorldSpace() const;
126 
128  Self &
129  operator=(const SpatialObjectPoint & rhs);
130 
132  void
134  {
135  m_Color = color;
136  }
137 
138  ColorType
139  GetColor() const
140  {
141  return m_Color;
142  }
143 
145  void
146  SetColor(double r, double g, double b, double a = 1);
147 
149  void
150  SetRed(double r)
151  {
152  m_Color.SetRed(r);
153  }
154 
155  double
156  GetRed() const
157  {
158  return m_Color.GetRed();
159  }
160 
162  void
163  SetGreen(double g)
164  {
165  m_Color.SetGreen(g);
166  }
167 
168  double
169  GetGreen() const
170  {
171  return m_Color.GetGreen();
172  }
173 
175  void
176  SetBlue(double b)
177  {
178  m_Color.SetBlue(b);
179  }
180 
181  double
182  GetBlue() const
183  {
184  return m_Color.GetBlue();
185  }
186 
188  void
189  SetAlpha(double a)
190  {
191  m_Color.SetAlpha(a);
192  }
193 
194  double
195  GetAlpha() const
196  {
197  return m_Color.GetAlpha();
198  }
199 
201  void
202  Print(std::ostream & os) const
203  {
204  this->PrintSelf(os, 3);
205  }
206 
207 protected:
209  virtual void
210  PrintSelf(std::ostream & os, Indent indent) const;
211 
213  int m_Id;
214 
217 
220 
221  // The SpatialObjectPoint keeps a reference to its owning parent
222  // spatial object for its spatial context. A WeakPointer is used to
223  // avoid a memory leak.
225 };
226 
227 } // end of namespace itk
228 
229 #ifndef ITK_MANUAL_INSTANTIATION
230 # include "itkSpatialObjectPoint.hxx"
231 #endif
232 
233 #endif // itkSpatialObjectPoint_h
itk::SpatialObjectPoint::m_Id
int m_Id
Definition: itkSpatialObjectPoint.h:213
itk::SpatialObjectPoint::Print
void Print(std::ostream &os) const
Definition: itkSpatialObjectPoint.h:202
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const double firstCoordinate, const TCoordinate... otherCoordinate)
Definition: itkSpatialObjectPoint.h:90
itk::SpatialObjectPoint::SetRed
void SetRed(double r)
Definition: itkSpatialObjectPoint.h:150
itk::SpatialObjectPoint::GetGreen
double GetGreen() const
Definition: itkSpatialObjectPoint.h:169
itkSpatialObject.h
itkPoint.h
itk::SpatialObjectPoint::SetPositionInObjectSpace
void SetPositionInObjectSpace(const PointType &newPositionInObjectSpace)
Definition: itkSpatialObjectPoint.h:83
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SpatialObjectPoint::SetSpatialObject
void SetSpatialObject(SpatialObjectType *so)
Definition: itkSpatialObjectPoint.h:106
itkRGBAPixel.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SpatialObjectPoint::SetId
void SetId(int id)
Definition: itkSpatialObjectPoint.h:69
itk::SpatialObjectPoint::GetAlpha
double GetAlpha() const
Definition: itkSpatialObjectPoint.h:195
itk::SpatialObjectPoint::GetColor
ColorType GetColor() const
Definition: itkSpatialObjectPoint.h:139
itk::SpatialObjectPoint::GetBlue
double GetBlue() const
Definition: itkSpatialObjectPoint.h:182
itk::SpatialObjectPoint::SetAlpha
void SetAlpha(double a)
Definition: itkSpatialObjectPoint.h:189
itk::SpatialObjectPoint::m_SpatialObject
WeakPointer< SpatialObjectType > m_SpatialObject
Definition: itkSpatialObjectPoint.h:224
itk::SpatialObjectPoint::SetColor
void SetColor(ColorType color)
Definition: itkSpatialObjectPoint.h:133
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:57
itk::SpatialObjectPoint::GetId
int GetId() const
Definition: itkSpatialObjectPoint.h:76
itk::SpatialObjectPoint::GetNameOfClass
virtual const char * GetNameOfClass() const
Definition: itkSpatialObjectPoint.h:54
itk::SpatialObjectPoint::SetGreen
void SetGreen(double g)
Definition: itkSpatialObjectPoint.h:163
itk::SpatialObjectPoint::GetSpatialObject
SpatialObjectType * GetSpatialObject() const
Definition: itkSpatialObjectPoint.h:112
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: itkArray.h:26
itk::SpatialObjectPoint::m_PositionInObjectSpace
PointType m_PositionInObjectSpace
Definition: itkSpatialObjectPoint.h:216
itk::SpatialObjectPoint::GetPositionInObjectSpace
const PointType & GetPositionInObjectSpace() const
Definition: itkSpatialObjectPoint.h:100
itk::SpatialObjectPoint::SetBlue
void SetBlue(double b)
Definition: itkSpatialObjectPoint.h:176
itk::Point< double, TPointDimension >
itk::SpatialObjectPoint::VectorType
vnl_vector< double > VectorType
Definition: itkSpatialObjectPoint.h:64
itk::SpatialObjectPoint::m_Color
ColorType m_Color
Definition: itkSpatialObjectPoint.h:219
itk::SpatialObjectPoint::GetRed
double GetRed() const
Definition: itkSpatialObjectPoint.h:156
itk::SpatialObjectPoint
Point used for spatial objets.
Definition: itkSpatialObjectPoint.h:44