diff --git a/vcg/space/index/octree.h b/vcg/space/index/octree.h index 3ed06532..5a2862e0 100644 --- a/vcg/space/index/octree.h +++ b/vcg/space/index/octree.h @@ -21,8 +21,8 @@ * * ****************************************************************************/ -#ifndef OCTREE_H -#define OCTREE_H +#ifndef VCG_SPACE_INDEX_OCTREE_H +#define VCG_SPACE_INDEX_OCTREE_H #include #include @@ -102,7 +102,7 @@ namespace vcg template < class OBJECT_TYPE, class SCALAR_TYPE> - class Octree : public OctreeTemplate< Voxel, SCALAR_TYPE >, public vcg::SpatialIndex< OBJECT_TYPE, SCALAR_TYPE > + class Octree : public vcg::OctreeTemplate< Voxel, SCALAR_TYPE >, public vcg::SpatialIndex< OBJECT_TYPE, SCALAR_TYPE > { public: typedef SCALAR_TYPE ScalarType; @@ -148,16 +148,16 @@ namespace vcg ObjectPlaceholder() { z_order = object_index = -1, leaf_pointer = NULL;} - ObjectPlaceholder(unsigned long long z_order, void* leaf_pointer, unsigned int object_index) + ObjectPlaceholder(ZOrderType z_order, void* leaf_pointer, unsigned int object_index) { this->z_order = z_order; this->leaf_pointer = leaf_pointer; this->object_index = object_index; } - unsigned long long z_order; - LeafPointer leaf_pointer; - unsigned int object_index; + ZOrderType z_order; + LeafPointer leaf_pointer; + unsigned int object_index; }; @@ -823,4 +823,4 @@ public: } //end of namespace vcg -#endif //OCTREE_H +#endif //VCG_SPACE_INDEX_OCTREE_H diff --git a/vcg/space/index/octree_template.h b/vcg/space/index/octree_template.h index 33c761da..19250166 100644 --- a/vcg/space/index/octree_template.h +++ b/vcg/space/index/octree_template.h @@ -22,8 +22,8 @@ ****************************************************************************/ -#ifndef OCTREETEMPLATE_H -#define OCTREETEMPLATE_H +#ifndef VCG_SPACE_INDEX_OCTREETEMPLATE_H +#define VCG_SPACE_INDEX_OCTREETEMPLATE_H #include #include @@ -56,6 +56,7 @@ protected: public: // Octree Type Definitions + typedef unsigned long long ZOrderType; typedef SCALAR_TYPE ScalarType; typedef typename VOXEL_TYPE VoxelType; typedef typename VOXEL_TYPE *VoxelPointer; @@ -201,21 +202,21 @@ public: // Return the center of the n-th node inline CenterType CenterInOctreeCoordinates(const NodePointer n) const { return n->center;} - // Return the center of the n-th node expressed in world-coordinate - inline CoordinateType CenterInWorldCoordinates(const NodePointer n) const + /*! + * Return the center of the n-th node expressed in world-coordinate + * \param NodePointer the pointer to the node whose center in world coordinate has to be computed + */ + inline void CenterInWorldCoordinates(const NodePointer n, CoordinateType &wc_Center) const { assert(0<=n && nlevel; - int shift = maxDepth-level+1; - CoordinateType wcCenter; + int shift = maximumDepth - n->level + 1; CoordinateType ocCenter = CenterInOctreeCoordinates(n); CoordinateType nodeSize = boundingBox.Dim()/float(1<>shift))); wcCenter.Y() = boundingBox.min.Y() + (nodeSize.Y()*(0.5f+(ocCenter.Y()>>shift))); wcCenter.Z() = boundingBox.min.Z() + (nodeSize.Z()*(0.5f+(ocCenter.Z()>>shift))); - return wcCenter - } + }; // Given a node (even not leaf) it returns the center of the box it represent. // the center is expressed not in world-coordinates. @@ -282,8 +283,6 @@ public: // Return the bounding-box of the n-th node expressed in world-coordinate BoundingBoxType BoundingBoxInWorldCoordinates(const NodePointer n) { - assert(0<=n && ncenter.X()>>shift)); + wc_bb.min.Y() = boundingBox.min.Y()+(node_dimension.Y()*(n->center.Y()>>shift)); + wc_bb.min.Z() = boundingBox.min.Z()+(node_dimension.Z()*(n->center.Z()>>shift)); + wc_bb.max = wc_bb.min+node_dimension; + }; + // Return one of the 8 subb box of a given box. BoundingBoxType SubBox(BoundingBoxType &lbb, int i) { @@ -408,6 +423,10 @@ public: return curNode; } + /*! + * Given a query point, compute the z_order of the leaf where this point would be contained. + * This leaf not necessarily must be exist! + */ // Convert the point p coordinates to the integer based representation // in the range 0..size, where size is 2^maxdepth CenterType Interize(const CoordinateType &pf) const @@ -445,13 +464,13 @@ public: // Compute the z-ordering integer value for a given node; // this value can be used to compute a complete ordering of the nodes of a given level of the octree. // It assumes that the octree has a max depth of 10. - unsigned long long ZOrder(NodePointer n) - { - unsigned long long finalPosition = 0; - unsigned long long currentPosition; - char level = Level(n); + ZOrderType ZOrder(NodePointer n) const { return ZOrder(GetPath(n), Level(n)); } + ZOrderType ComputeZOrder(const CoordinateType &query) const { return ZOrder(CenterType::Construct(Interize(query)), maximumDepth); }; - CenterType path = GetPath(n); + inline ZOrderType ZOrder(const CenterType &path, const char level) const + { + ZOrderType finalPosition = 0; + ZOrderType currentPosition; for(int i=0; i= finalLevel) + CenterType path = CenterType::Construct(Interize(p)); + while(shift >= 0) { int son = 0; if((path[0]>>shift)%2) son +=1; @@ -701,4 +718,4 @@ template const SCALAR_TYPE OctreeTemplate::EXPANSION_FACTOR = SCALAR_TYPE(0.035); } -#endif //OCTREETEMPLATE_H +#endif //VCG_SPACE_INDEX_OCTREETEMPLATE_H