ITK  6.0.0
Insight Toolkit
itkOctree.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 itkOctree_h
19 #define itkOctree_h
20 
21 #include "itkOctreeNode.h"
22 #include "itkImage.h"
23 #include "itkCommonEnums.h"
24 
25 namespace itk
26 {
27 enum
28 {
32 };
33 
40 class ITKCommon_EXPORT OctreeBase : public Object
41 {
42 public:
43 
45  using Self = OctreeBase;
47 
49 
50 #if !defined(ITK_LEGACY_REMOVE)
51  // We need to expose the enum values at the class level
52  // for backwards compatibility
53  static constexpr OctreeEnum UNKNOWN_PLANE = OctreeEnum::UNKNOWN_PLANE;
54  static constexpr OctreeEnum SAGITAL_PLANE = OctreeEnum::SAGITAL_PLANE;
55  static constexpr OctreeEnum CORONAL_PLANE = OctreeEnum::CORONAL_PLANE;
56  static constexpr OctreeEnum TRANSVERSE_PLANE = OctreeEnum::TRANSVERSE_PLANE;
57 #endif
58 
63  virtual OctreeNode *
64  GetTree() = 0;
65 
70  virtual unsigned int
71  GetDepth() = 0;
72 
78  virtual unsigned int
79  GetWidth() = 0;
80 
82  virtual void
83  SetDepth(unsigned int depth) = 0;
84 
86  virtual void
87  SetWidth(unsigned int width) = 0;
88 
94  virtual void
95  BuildFromBuffer(const void * buffer,
96  const unsigned int xsize,
97  const unsigned int ysize,
98  const unsigned int zsize) = 0;
99 
110  virtual const OctreeNodeBranch *
111  GetColorTable() const = 0;
112 
114  virtual int
115  GetColorTableSize() const = 0;
116 };
117 
126 template <typename TPixel, unsigned int ColorTableSize, typename MappingFunctionType>
127 class ITK_TEMPLATE_EXPORT Octree : public OctreeBase
128 {
129 public:
130  ITK_DISALLOW_COPY_AND_MOVE(Octree);
131 
133  using Self = Octree;
138 
140  itkNewMacro(Self);
141 
143  itkOverrideGetNameOfClassMacro(Octree);
144 
146  GetImage();
147 
148  void
149  BuildFromBuffer(const void * frombuffer,
150  const unsigned int xsize,
151  const unsigned int ysize,
152  const unsigned int zsize) override;
153 
154  void
155  BuildFromImage(Image<TPixel, 3> * fromImage);
156 
157  Octree();
158  ~Octree() override;
159  void
160  SetColor(unsigned int color)
161  {
162  m_Tree.SetColor(color);
163  }
164  void
166  {
167  m_Tree.SetBranch(branch);
168  }
169  void
170  SetTrueDims(const unsigned int Dim0, const unsigned int Dim1, const unsigned int Dim2);
171 
172  int
173  GetValue(const unsigned int Dim0, const unsigned int Dim1, const unsigned int Dim2);
174 
175  void
176  SetWidth(unsigned int width) override;
177 
178  void
179  SetDepth(unsigned int depth) override;
180 
181  unsigned int
182  GetWidth() override;
183 
184  unsigned int
185  GetDepth() override;
186 
187  /***
188  * Exposes enum values for backwards compatibility
189  * */
190 #if !defined(ITK_LEGACY_REMOVE)
191  static constexpr OctreeEnum UNKNOWN_PLANE = OctreeEnum::UNKNOWN_PLANE;
192  static constexpr OctreeEnum SAGITAL_PLANE = OctreeEnum::SAGITAL_PLANE;
193  static constexpr OctreeEnum CORONAL_PLANE = OctreeEnum::CORONAL_PLANE;
194  static constexpr OctreeEnum TRANSVERSE_PLANE = OctreeEnum::TRANSVERSE_PLANE;
195 #endif
196 
197  OctreeNode *
198  GetTree() override;
199 
200  const OctreeNodeBranch *
201  GetColorTable() const override;
202 
203  int
204  GetColorTableSize() const override;
205 
206 private:
208  maskToOctree(const TPixel * Mask,
209  unsigned int width,
210  unsigned int x,
211  unsigned int y,
212  unsigned int z,
213  unsigned int xsize,
214  unsigned int ysize,
215  unsigned int zsize);
216 
217  OctreeEnum m_Plane{ OctreeEnum::UNKNOWN_PLANE }; // The orientation of the plane for this octree
218 
219  // The width of the Octree. This is always a power of 2,
220  // and large enough to contain MAX(DIMS[1,2,3])
221  unsigned int m_Width{ 0 };
222 
223  unsigned int m_Depth{ 0 }; // The depth of the Octree
224  unsigned int m_TrueDims[3]{}; // The true dimensions of the image
225  OctreeNodeBranch m_ColorTable[ColorTableSize];
226  OctreeNode m_Tree{};
227  MappingFunctionType m_MappingFunction{};
228 };
229 } // namespace itk
230 
231 #ifndef ITK_MANUAL_INSTANTIATION
232 # include "itkOctree.hxx"
233 #endif
234 
235 #endif // itkOctree_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itkOctreeNode.h
itk::B2_MASKFILE_GRAY
Definition: itkOctree.h:31
itk::OctreeBase
class ITK_FORWARD_EXPORT OctreeBase
Definition: itkOctreeNode.h:28
itk::Octree
Represent a 3D Image with an Octree data structure.
Definition: itkOctree.h:127
itkImage.h
itk::Octree::SetColor
void SetColor(unsigned int color)
Definition: itkOctree.h:160
itk::SmartPointer< Self >
itk::OctreeEnums::Octree
Octree
Definition: itkCommonEnums.h:215
itk::OctreeBase
Provides non-templated access to templated instances of Octree.
Definition: itkOctree.h:40
itk::B2_MASKFILE_BLACK
Definition: itkOctree.h:29
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::OctreeNodeBranch
Definition: itkOctreeNode.h:146
itk::B2_MASKFILE_WHITE
Definition: itkOctree.h:30
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkCommonEnums.h
itk::OctreeNode
A data structure representing a node in an Octree.
Definition: itkOctreeNode.h:46
itk::Octree::ImageTypePointer
typename ImageType::Pointer ImageTypePointer
Definition: itkOctree.h:137
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::Octree::SetTree
void SetTree(OctreeNodeBranch *branch)
Definition: itkOctree.h:165