19 #ifndef OST_GFX_IMPL_MAP_OCTREE_HH
20 #define OST_GFX_IMPL_MAP_OCTREE_HH
29 namespace ost {
namespace gfx {
namespace impl {
49 first_child_(first_child), branch_x_(branch_x),
50 branch_y_(branch_y), branch_z_(branch_z), is_leaf_(false),
54 branch_x_(false), branch_y_(false), branch_z_(false), is_leaf_(false),
77 assert(0 &&
"what the heck?");
84 float GetMin()
const {
return min_; }
85 float GetMax()
const {
return max_; }
86 bool IsLeaf()
const {
return is_leaf_; }
118 template <
typename F>
121 if (levels_.empty()) {
127 assert(levels_[0].size()==1);
128 if (f.VisitNode(levels_[0][0], 0, ext)) {
129 this->VisitDFRec<F>(levels_[0][0], f, 1, ext, map);
136 for (
char i=15; i>=0; --i) {
145 template <
typename F>
161 uint16_t bit_mask=1<<(LastSetBit(ems));
163 range_x[0][1]=range_x[0][0]+bit_mask-1;
164 range_x[1][0]=ext.
GetEnd()[0]-(ems & ~bit_mask);
165 range_x[1][1]=ext.
GetEnd()[0];
168 range_x[0][1]=ext.
GetEnd()[0];
172 uint16_t bit_mask=1<<(LastSetBit(ems));
174 range_y[0][1]=range_y[0][0]+bit_mask-1;
175 range_y[1][0]=ext.
GetEnd()[1]-(ems & ~bit_mask);
176 range_y[1][1]=ext.
GetEnd()[1];
179 range_y[0][1]=ext.
GetEnd()[1];
183 uint16_t bit_mask=1<<(LastSetBit(ems));
185 range_z[0][1]=range_z[0][0]+bit_mask-1;
186 range_z[1][0]=ext.
GetEnd()[2]-(ems & ~bit_mask);
187 range_z[1][1]=ext.
GetEnd()[2];
190 range_z[0][1]=ext.
GetEnd()[2];
192 for (
int i=0; i<cx; ++i) {
193 for (
int j=0; j<cy; ++j) {
194 for (
int k=0; k<cz; ++k, ++c) {
196 f.VisitLeaf(map,
img::Point(range_x[i][0], range_y[j][0],
204 if (f.VisitNode(cn, level, ext)) {
205 this->VisitDFRec<F>(cn, f, level+1, ext, map);
214 std::pair<float, float> BuildOctreeRec(
const OcRangeVector& range_vec,
221 std::vector<OcNodeEntryList> levels_;
Octree datastructure for 3D images.
MapOctree(const img::ImageHandle &map)
static int LastSetBit(uint16_t ch)
static bool IsMapManageable(const img::ImageHandle ih)
uint32_t GetNumNodesForLevel(uint8_t level) const
void SetNewMap(const img::ImageHandle &ih)
void VisitDF(F &f) const
depth-first visit of octree nodes
void VisitDFRec(const OctreeNode &node, F &f, uint8_t level, const img::Extent &ext, img::RealSpatialImageState *map) const
bool BranchInX() const
whether the node branches in x direction
bool BranchInY() const
whether the node branches in y direction
uint8_t GetChildCount() const
get number of children
bool BranchInZ() const
whether the node branches in z direction
OctreeNode(uint32_t first_child, bool branch_x, bool branch_y, bool branch_z)
uint32_t GetFirstChild() const
Defines lower and upper valid indices.
const Point & GetEnd() const
Return upper/right/back corner.
const Point & GetStart() const
Return lower/left/front corner.
Manage shared instances of images.
class encapsulating 1D to 3D point
#define DLLEXPORT_OST_GFX
std::vector< OctreeNode > OcNodeEntryList
ImageStateImpl< Real, SpatialDomain > RealSpatialImageState
OcRangeVector(uint16_t px, uint16_t py, uint16_t pz)