ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkOctree.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkOctree_h
00019 #define __itkOctree_h
00020 
00021 #include "itkOctreeNode.h"
00022 #include "itkImage.h"
00026 namespace itk
00027 {
00028 enum {
00029   B2_MASKFILE_BLACK = 0,
00030   B2_MASKFILE_WHITE = 1,
00031   B2_MASKFILE_GRAY = 2
00032   };
00033 
00037 enum OctreePlaneType {
00038 
00046   };
00047 
00054 class OctreeBase:public Object
00055 {
00056 public:
00057 
00059   typedef OctreeBase           Self;
00060   typedef SmartPointer< Self > Pointer;
00061 
00066   virtual OctreeNode * GetTree() = 0;
00067 
00072   virtual unsigned int GetDepth() = 0;
00073 
00079   virtual unsigned int GetWidth() = 0;
00080 
00082   virtual void SetDepth(unsigned int depth) = 0;
00083 
00085   virtual void SetWidth(unsigned int width) = 0;
00086 
00092   virtual void BuildFromBuffer(const void *buffer,
00093                                const int xsize, const int ysize, const int zsize) = 0;
00094 
00105   virtual const char * GetColorTable() const = 0;
00106 
00108   virtual int GetColorTableSize() const = 0;
00109 };
00110 
00119 template< class TPixel, unsigned int ColorTableSize, class MappingFunctionType >
00120 class Octree:public OctreeBase
00121 {
00122 public:
00123 
00125   typedef Octree                      Self;
00126   typedef OctreeBase                  Superclass;
00127   typedef SmartPointer< Self >        Pointer;
00128   typedef Image< TPixel, 3 >          ImageType;
00129   typedef typename ImageType::Pointer ImageTypePointer;
00130 
00132   itkNewMacro(Self);
00133 
00135   itkTypeMacro(Octree, Superclass);
00136 
00137   ImageTypePointer GetImage();
00138 
00139   virtual void BuildFromBuffer(const void *buffer, const int xsize, const int ysize, const int zsize);
00140 
00141   void BuildFromImage(Image< TPixel, 3 > *fromImage);
00142 
00143   Octree(void);
00144   ~Octree(void);
00145   void SetColor(unsigned int color) { m_Tree.SetColor(color); }
00146   void SetTree(OctreeNodeBranch *branch) { m_Tree.SetBranch(branch); }
00147   void SetTrueDims(const unsigned int Dim0, const unsigned int Dim1,
00148                    const unsigned int Dim2);
00149 
00150   unsigned int GetValue(const unsigned int Dim0, const unsigned int Dim1,
00151                         const unsigned int Dim2);
00152 
00153   virtual void SetWidth(unsigned int width);
00154 
00155   virtual void SetDepth(unsigned int depth);
00156 
00157   virtual unsigned int GetWidth();
00158 
00159   virtual unsigned int GetDepth();
00160 
00161   virtual OctreeNode * GetTree();
00162 
00163   virtual const char * GetColorTable() const;
00164 
00165   virtual int GetColorTableSize() const;
00166 
00167 private:
00168   Octree(const Self &);         // purposely not implemented
00169   void operator=(const Self &); // purposely not implemented
00170 
00171   OctreeNodeBranch * maskToOctree(const TPixel *Mask, unsigned width, unsigned x,
00172                                   unsigned y, unsigned z, unsigned xsize,
00173                                   unsigned ysize, unsigned zsize);
00174 
00175   enum OctreePlaneType m_Plane; // The orientation of the plane for this octree
00176   unsigned int         m_Width; // The width of the Octree
00177                                 // ( This is always a power of 2, and large
00178                                 // enough to contain MAX(DIMS[1,2,3]))
00179   unsigned int m_Depth;         // < The depth of the Octree
00180   unsigned int m_TrueDims[3];   // The true dimensions of the image
00181   char         m_ColorTable[ColorTableSize];
00182   OctreeNode   m_Tree;
00183   // OctreeColorMapFunction m_ColorMapFunction;
00184   MappingFunctionType m_MappingFunction;
00185 };
00186 }
00187 
00188 #ifndef ITK_MANUAL_INSTANTIATION
00189 #include "itkOctree.hxx"
00190 #endif
00191 
00192 #endif                          /* __itkOctree_h */
00193