octree_poisson.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2009-2012, Willow Garage, Inc.
00006  *  Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho,
00007  *                      Johns Hopkins University
00008  *
00009  *  All rights reserved.
00010  *
00011  *  Redistribution and use in source and binary forms, with or without
00012  *  modification, are permitted provided that the following conditions
00013  *  are met:
00014  *
00015  *   * Redistributions of source code must retain the above copyright
00016  *     notice, this list of conditions and the following disclaimer.
00017  *   * Redistributions in binary form must reproduce the above
00018  *     copyright notice, this list of conditions and the following
00019  *     disclaimer in the documentation and/or other materials provided
00020  *     with the distribution.
00021  *   * Neither the name of Willow Garage, Inc. nor the names of its
00022  *     contributors may be used to endorse or promote products derived
00023  *     from this software without specific prior written permission.
00024  *
00025  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00028  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00029  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00030  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00031  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00032  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00034  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00035  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  *  POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * $Id: octree_poisson.h 5531 2012-04-08 09:14:33Z aichim $
00039  *
00040  */
00041 #ifndef PCL_POISSON_OCTREE_POISSON_H_
00042 #define PCL_POISSON_OCTREE_POISSON_H_
00043 
00044 #include "allocator.h"
00045 #include "binary_node.h"
00046 #include "marching_cubes_poisson.h"
00047 
00048 #define DIMENSION 3
00049 
00050 namespace pcl 
00051 {
00052   namespace poisson 
00053   {
00054 
00055     template<class NodeData,class Real=float>
00056     class OctNode
00057     {
00058       private:
00059         static int UseAlloc;
00060 
00061         class AdjacencyCountFunction
00062         {
00063           public:
00064             int count;
00065             void Function(const OctNode<NodeData,Real>* node1,const OctNode<NodeData,Real>* node2);
00066         };
00067 
00068         template<class NodeAdjacencyFunction>
00069         void __processNodeFaces (OctNode* node,
00070                                  NodeAdjacencyFunction* F,
00071                                  const int& cIndex1, const int& cIndex2, const int& cIndex3, const int& cIndex4);
00072         template<class NodeAdjacencyFunction>
00073         void __processNodeEdges (OctNode* node,
00074                                  NodeAdjacencyFunction* F,
00075                                  const int& cIndex1, const int& cIndex2);
00076         template<class NodeAdjacencyFunction>
00077         void __processNodeNodes (OctNode* node, NodeAdjacencyFunction* F);
00078         template<class NodeAdjacencyFunction>
00079         static void __ProcessNodeAdjacentNodes (const int& dx, const int& dy, const int& dz,
00080                                                 OctNode* node1, const int& radius1,
00081                                                 OctNode* node2, const int& radius2,
00082                                                 const int& cWidth2,
00083                                                 NodeAdjacencyFunction* F);
00084         template<class TerminatingNodeAdjacencyFunction>
00085         static void __ProcessTerminatingNodeAdjacentNodes(const int& dx, const int& dy, const int& dz,
00086                                                           OctNode* node1, const int& radius1,
00087                                                           OctNode* node2, const int& radius2,
00088                                                           const int& cWidth2,
00089                                                           TerminatingNodeAdjacencyFunction* F);
00090         template<class PointAdjacencyFunction>
00091         static void __ProcessPointAdjacentNodes (const int& dx, const int& dy, const int& dz,
00092                                                  OctNode* node2, const int& radius2,
00093                                                  const int& cWidth2,
00094                                                  PointAdjacencyFunction* F);
00095         template<class NodeAdjacencyFunction>
00096         static void __ProcessFixedDepthNodeAdjacentNodes (const int& dx, const int& dy, const int& dz,
00097                                                           OctNode* node1, const int& radius1,
00098                                                           OctNode* node2, const int& radius2,
00099                                                           const int& cWidth2,
00100                                                           const int& depth,
00101                                                           NodeAdjacencyFunction* F);
00102         template<class NodeAdjacencyFunction>
00103         static void __ProcessMaxDepthNodeAdjacentNodes (const int& dx, const int& dy, const int& dz,
00104                                                         OctNode* node1, const int& radius1,
00105                                                         OctNode* node2, const int& radius2,
00106                                                         const int& cWidth2,
00107                                                         const int& depth,
00108                                                         NodeAdjacencyFunction* F);
00109 
00110         // This is made private because the division by two has been pulled out.
00111         static inline int Overlap (const int& c1, const int& c2, const int& c3, const int& dWidth);
00112         inline static int ChildOverlap (const int& dx, const int& dy, const int& dz, const int& d, const int& cRadius2);
00113 
00114         const OctNode* __faceNeighbor (const int& dir, const int& off) const;
00115         const OctNode* __edgeNeighbor (const int& o, const int i[2], const int idx[2]) const;
00116         OctNode* __faceNeighbor (const int& dir, const int& off, const int& forceChildren);
00117         OctNode* __edgeNeighbor (const int& o, const int i[2], const int idx[2], const int& forceChildren);
00118       public:
00119         static const int DepthShift,OffsetShift,OffsetShift1,OffsetShift2,OffsetShift3;
00120         static const int DepthMask,OffsetMask;
00121 
00122         static Allocator<OctNode> AllocatorOctNode;
00123         static int UseAllocator (void);
00124         static void SetAllocator (int blockSize);
00125 
00126         OctNode* parent;
00127         OctNode* children;
00128         short d,off[3];
00129         NodeData nodeData;
00130 
00131 
00132         OctNode (void);
00133         ~OctNode (void);
00134         int initChildren (void);
00135 
00136         void depthAndOffset (int& depth, int offset[3]) const;
00137         int depth (void) const;
00138         static inline void DepthAndOffset (const long long& index, int& depth, int offset[3]);
00139         static inline void CenterAndWidth (const long long& index, Point3D<Real>& center, Real& width);
00140         static inline int Depth (const long long& index);
00141         static inline void Index (const int& depth, const int offset[3], short& d, short off[3]);
00142         void centerAndWidth (Point3D<Real>& center, Real& width) const;
00143 
00144         int leaves (void) const;
00145         int maxDepthLeaves (const int& maxDepth) const;
00146         int nodes (void) const;
00147         int maxDepth (void) const;
00148 
00149         const OctNode* root (void) const;
00150 
00151         const OctNode* nextLeaf (const OctNode* currentLeaf = NULL) const;
00152         OctNode* nextLeaf (OctNode* currentLeaf = NULL);
00153         const OctNode* nextNode (const OctNode* currentNode = NULL) const;
00154         OctNode* nextNode (OctNode* currentNode = NULL);
00155         const OctNode* nextBranch (const OctNode* current) const;
00156         OctNode* nextBranch (OctNode* current);
00157 
00158         void setFullDepth (const int& maxDepth);
00159 
00160         void printLeaves (void) const;
00161         void printRange (void) const;
00162 
00163         template<class NodeAdjacencyFunction>
00164         void processNodeFaces (OctNode* node,NodeAdjacencyFunction* F, const int& fIndex, const int& processCurrent = 1);
00165         template<class NodeAdjacencyFunction>
00166         void processNodeEdges (OctNode* node, NodeAdjacencyFunction* F, const int& eIndex, const int& processCurrent = 1);
00167         template<class NodeAdjacencyFunction>
00168         void processNodeCorners (OctNode* node, NodeAdjacencyFunction* F, const int& cIndex, const int& processCurrent = 1);
00169         template<class NodeAdjacencyFunction>
00170         void processNodeNodes (OctNode* node, NodeAdjacencyFunction* F, const int& processCurrent=1);
00171 
00172         template<class NodeAdjacencyFunction>
00173         static void ProcessNodeAdjacentNodes (const int& maxDepth,
00174                                               OctNode* node1, const int& width1,
00175                                               OctNode* node2, const int& width2,
00176                                               NodeAdjacencyFunction* F,
00177                                               const int& processCurrent=1);
00178         template<class NodeAdjacencyFunction>
00179         static void ProcessNodeAdjacentNodes (const int& dx, const int& dy, const int& dz,
00180                                               OctNode* node1, const int& radius1,
00181                                               OctNode* node2, const int& radius2,
00182                                               const int& width2,
00183                                               NodeAdjacencyFunction* F,
00184                                               const int& processCurrent = 1);
00185         template<class TerminatingNodeAdjacencyFunction>
00186         static void ProcessTerminatingNodeAdjacentNodes (const int& maxDepth,
00187                                                          OctNode* node1, const int& width1,
00188                                                          OctNode* node2, const int& width2,
00189                                                          TerminatingNodeAdjacencyFunction* F,
00190                                                          const int& processCurrent = 1);
00191         template<class TerminatingNodeAdjacencyFunction>
00192         static void ProcessTerminatingNodeAdjacentNodes (const int& dx, const int& dy, const int& dz,
00193                                                          OctNode* node1, const int& radius1,
00194                                                          OctNode* node2, const int& radius2,
00195                                                          const int& width2,
00196                                                          TerminatingNodeAdjacencyFunction* F,
00197                                                          const int& processCurrent = 1);
00198         template<class PointAdjacencyFunction>
00199         static void ProcessPointAdjacentNodes (const int& maxDepth,
00200                                                const int center1[3],
00201                                                OctNode* node2, const int& width2,
00202                                                PointAdjacencyFunction* F,
00203                                                const int& processCurrent = 1);
00204         template<class PointAdjacencyFunction>
00205         static void ProcessPointAdjacentNodes (const int& dx, const int& dy, const int& dz,
00206                                                OctNode* node2, const int& radius2, const int& width2,
00207                                                PointAdjacencyFunction* F,
00208                                                const int& processCurrent = 1);
00209         template<class NodeAdjacencyFunction>
00210         static void ProcessFixedDepthNodeAdjacentNodes (const int& maxDepth,
00211                                                         OctNode* node1, const int& width1,
00212                                                         OctNode* node2, const int& width2,
00213                                                         const int& depth,
00214                                                         NodeAdjacencyFunction* F,
00215                                                         const int& processCurrent = 1);
00216         template<class NodeAdjacencyFunction>
00217         static void ProcessFixedDepthNodeAdjacentNodes (const int& dx, const int& dy, const int& dz,
00218                                                         OctNode* node1, const int& radius1,
00219                                                         OctNode* node2, const int& radius2,
00220                                                         const int& width2,
00221                                                         const int& depth,
00222                                                         NodeAdjacencyFunction* F,
00223                                                         const int& processCurrent = 1);
00224         template<class NodeAdjacencyFunction>
00225         static void ProcessMaxDepthNodeAdjacentNodes (const int& maxDepth,
00226                                                       OctNode* node1, const int& width1,
00227                                                       OctNode* node2, const int& width2,
00228                                                       const int& depth,
00229                                                       NodeAdjacencyFunction* F,
00230                                                       const int& processCurrent = 1);
00231         template<class NodeAdjacencyFunction>
00232         static void ProcessMaxDepthNodeAdjacentNodes (const int& dx, const int& dy, const int& dz,
00233                                                       OctNode* node1, const int& radius1,
00234                                                       OctNode* node2, const int& radius2,
00235                                                       const int& width2,
00236                                                       const int& depth,
00237                                                       NodeAdjacencyFunction* F,
00238                                                       const int& processCurrent = 1);
00239 
00240         static int CornerIndex (const Point3D<Real>& center, const Point3D<Real> &p);
00241 
00242         OctNode* faceNeighbor (const int& faceIndex, const int& forceChildren = 0);
00243         const OctNode* faceNeighbor (const int& faceIndex) const;
00244         OctNode* edgeNeighbor (const int& edgeIndex, const int& forceChildren = 0);
00245         const OctNode* edgeNeighbor (const int& edgeIndex) const;
00246         OctNode* cornerNeighbor (const int& cornerIndex, const int& forceChildren = 0);
00247         const OctNode* cornerNeighbor (const int& cornerIndex) const;
00248 
00249         OctNode* getNearestLeaf (const Point3D<Real>& p);
00250         const OctNode* getNearestLeaf (const Point3D<Real>& p) const;
00251 
00252         static int CommonEdge (const OctNode* node1, const int& eIndex1,
00253                                const OctNode* node2, const int& eIndex2);
00254         static int CompareForwardDepths (const void* v1, const void* v2);
00255         static int CompareForwardPointerDepths (const void* v1, const void* v2);
00256         static int CompareBackwardDepths (const void* v1, const void* v2);
00257         static int CompareBackwardPointerDepths (const void* v1, const void* v2);
00258 
00259 
00260         template<class NodeData2>
00261         OctNode& operator = (const OctNode<NodeData2, Real>& node);
00262 
00263         static inline int Overlap2 (const int &depth1,
00264                                     const int offSet1[DIMENSION],
00265                                     const Real& multiplier1,
00266                                     const int &depth2,
00267                                     const int offSet2[DIMENSION],
00268                                     const Real& multiplier2);
00269 
00270 
00271         int write (const char* fileName) const;
00272         int write (FILE* fp) const;
00273         int read (const char* fileName);
00274         int read (FILE* fp);
00275 
00276         class Neighbors{
00277         public:
00278           OctNode* neighbors[3][3][3];
00279           Neighbors (void);
00280           void clear (void);
00281         };
00282         class NeighborKey{
00283         public:
00284           Neighbors* neighbors;
00285 
00286           NeighborKey (void);
00287           ~NeighborKey (void);
00288 
00289           void set (const int& depth);
00290           Neighbors& setNeighbors (OctNode* node);
00291           Neighbors& getNeighbors (OctNode* node);
00292         };
00293         class Neighbors2{
00294         public:
00295           const OctNode* neighbors[3][3][3];
00296           Neighbors2 (void);
00297           void clear (void);
00298         };
00299         class NeighborKey2{
00300         public:
00301           Neighbors2* neighbors;
00302 
00303           NeighborKey2 (void);
00304           ~NeighborKey2 (void);
00305 
00306           void set (const int& depth);
00307           Neighbors2& getNeighbors (const OctNode* node);
00308         };
00309 
00310         void centerIndex (const int& maxDepth, int index[DIMENSION]) const;
00311         int width (const int& maxDepth) const;
00312     };
00313 
00314   }
00315 }
00316 
00317 
00318 #include <pcl/surface/impl/poisson/octree_poisson.hpp>
00319 
00320 #endif /* PCL_POISSON_OCTREE_POISSON_H_ */


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:15:58