59 template<
class Scalar,
int CAPACITY=16,
int SF=1,
class Pt=FixedColVector<Scalar,4>,
int ALLOC_CHUNK_SIZE=1024>
113 this->next = this->
points;
124 this->next = this->
points;
145 for(
int i=0;i<8;++i){
159 this->children[0].
init(
this,
AABB(Pt(c[0]-half[0],c[1]-half[1], c[2]-half[2]),half));
160 this->children[1].
init(
this,
AABB(Pt(c[0]+half[0],c[1]-half[1], c[2]-half[2]),half));
161 this->children[2].
init(
this,
AABB(Pt(c[0]-half[0],c[1]+half[1], c[2]-half[2]),half));
162 this->children[3].
init(
this,
AABB(Pt(c[0]+half[0],c[1]+half[1], c[2]-half[2]),half));
164 this->children[4].
init(
this,
AABB(Pt(c[0]-half[0],c[1]-half[1], c[2]+half[2]),half));
165 this->children[5].
init(
this,
AABB(Pt(c[0]+half[0],c[1]-half[1], c[2]+half[2]),half));
166 this->children[6].
init(
this,
AABB(Pt(c[0]-half[0],c[1]+half[1], c[2]+half[2]),half));
167 this->children[7].
init(
this,
AABB(Pt(c[0]+half[0],c[1]+half[1], c[2]+half[2]),half));
203 if(
curr == ALLOC_CHUNK_SIZE)
grow();
215 std::vector<Pt>
all()
const{
217 for(
size_t i=0;i<
allocated.size()-1;++i){
219 for(
size_t j=0;j<ALLOC_CHUNK_SIZE*8;++j){
220 for(
const Pt* p = ns[j].points; p != ns[j].
next;++p){
226 for(
int i=0;i<
curr*4;++i){
227 for(
const Pt* p = ns[i].points; p != ns[i].
next;++p){
247 if(SF == 1)
return p;
256 if(SF == 1)
return p;
273 Octree(
const Scalar &minX,
const Scalar &minY,
const Scalar &minZ,
274 const Scalar &width,
const Scalar &height,
const Scalar &
depth):
num(0){
275 this->root =
new Node(AABB(
scale_up(Pt(minX+width/2, minY+height/2, minZ+
depth/2)),
281 this->root =
new Node(AABB(
scale_up(Pt(min+len/2, min+len/2, min+len/2)),
297 const Node *n =
root;
300 + (p[0] > n->boundary.center[0])
301 + 2 * (p[1] > n->boundary.center[1])
302 + 4 * (p[2] > n->boundary.center[2]));
306 if(n->next == n->points){
313 for(
const Pt *x=n->points; x < n->next; ++x){
314 Scalar dSqr = (
utils::sqr(x->operator[](0)-p[0])
317 if(dSqr < sqrMinDist){
322 currMinDist =
sqrt(sqrMinDist);
346 const Pt *currNN = 0;
370 Pt
nn(
const Pt &pIn)
const {
372 std::vector<const Node*> stack;
374 stack.push_back(
root);
376 const Pt *currNN = 0;
381 const Node *n = stack.back();
384 const AABB b(p, Pt(currMinDist,currMinDist,currMinDist));
385 for(
int i=0;i<8;++i){
386 if(b.intersects(n->children[i].boundary)) stack.push_back(n->children+i);
391 for(
const Pt *x=n->points; x < n->next; ++x){
392 Scalar dSqr = (
utils::sqr(x->operator[](0)-p[0]) +
395 if(dSqr < sqrMinDist){
400 currMinDist =
sqrt(sqrMinDist);
409 template<
class OtherVectorType>
419 if(n->next != n->points+CAPACITY){
425 + (p[0] > n->boundary.center[0])
426 + 2 * (p[1] > n->boundary.center[1])
427 + 4 * (p[2] > n->boundary.center[2]));
434 template<
class ForwardIterator>
435 void assign(ForwardIterator begin, ForwardIterator end){
437 for(; begin != end; ++begin){
444 std::vector<Pt>
query(
const Scalar &minX,
const Scalar &minY,
const Scalar &minZ,
445 const Scalar &width,
const Scalar &height,
const Scalar &
depth)
const{
446 AABB range(
scale_up(Pt(minX+width/2, minY+height/2, minZ+
depth/2)),
448 std::vector<Pt> found;
ICLQt_API ImgQ sqrt(const ImgQ &image)
calls sqrt( each pixel)
class representing a range defined by min and max value
Definition: Range.h:49
Octree(const Scalar &min, const Scalar &len)
creates a QuadTree for the given 2D rectangle
Definition: Octree.h:280
bool intersects(const AABB &o) const
returns whether the AABB intersects with another AABB
Definition: Octree.h:88
undocument this line if you encounter any issues!
Definition: Any.h:37
void grow()
allocates the next data chunk
Definition: Octree.h:187
void clear()
removes all contained points and nodes
Definition: Octree.h:471
void insert(const OtherVectorType &pIn)
inserts a node into the QuadTree
Definition: Octree.h:410
static Pt scale_down(const Pt &p)
Definition: Octree.h:255
float radius
aabb radius (can be used for bounding sphere tests)
Definition: Octree.h:105
std::vector< Pt > query(const Scalar &minX, const Scalar &minY, const Scalar &minZ, const Scalar &width, const Scalar &height, const Scalar &depth) const
returns all contained points within the given rectangle
Definition: Octree.h:444
Allocator alloc
memory allocator for all children except for the root node
Definition: Octree.h:241
internally used axis-aligned bounding box
Definition: Octree.h:66
Inernally used block allocator.
Definition: Octree.h:175
Node * parent
parent node
Definition: Octree.h:104
int size() const
number of elments inserted
Definition: Octree.h:479
Generic Octree Implementation.
Definition: Octree.h:60
Pt * next
next node to fill
Definition: Octree.h:102
Node * next()
returns the next four Node instances (allocates new data on demand)
Definition: Octree.h:202
AABB(const Pt ¢er, const Pt &halfSize)
constructor from given center and half size
Definition: Octree.h:74
void query(const AABB &boundary, std::vector< Pt > &found) const
recursive getter function that queries all nodes within a given bounding box
Definition: Octree.h:134
std::vector< Node * > allocated
allocated data
Definition: Octree.h:178
std::vector< Pt > all() const
returns all contained points
Definition: Octree.h:215
bool contains(const Pt &p) const
returns whether a given 2D point is contained
Definition: Octree.h:78
~Allocator()
frees all allocated data
Definition: Octree.h:208
Pt nn_approx(const Pt &p) const
returns an approximated nearst neighbour
Definition: Octree.h:344
Node * children
pointer to four child-nodes
Definition: Octree.h:103
Pt points[CAPACITY]
contained nodes
Definition: Octree.h:101
Internally used node structure.
Definition: Octree.h:99
std::vector< Pt > queryAll() const
returns all contained points
Definition: Octree.h:454
static T sqr(const T &x)
square template (faster than pow(x,2)
Definition: Macros.h:212
Node(const AABB &boundary)
constructor from given AABB-boundary
Definition: Octree.h:111
Pt halfSize
half dimension
Definition: Octree.h:68
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
Allocator()
allocates the first data chunk
Definition: Octree.h:184
void clear()
deletes all allocated data chunks (except for the first)
Definition: Octree.h:193
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
int curr
current data
Definition: Octree.h:181
static Pt scale_down_1(const Pt &p)
Definition: Octree.h:264
AABB()
default constructor (does nothing)
Definition: Octree.h:71
Octree(const Scalar &minX, const Scalar &minY, const Scalar &minZ, const Scalar &width, const Scalar &height, const Scalar &depth)
creates a QuadTree for the given 2D rectangle
Definition: Octree.h:273
Pt center
center point
Definition: Octree.h:67
Base class for Exception handling in the ICL.
Definition: Exception.h:42
static Pt scale_up(const Pt &p)
Definition: Octree.h:246
Pt nn(const Pt &pIn) const
finds the nearest neighbor to the given node
Definition: Octree.h:370
AABB boundary
node boundary
Definition: Octree.h:100
const Pt & nn_approx_internal(const Pt &p, double &currMinDist, const Pt *&currNN) const
internal utility method that is used to find an approximated nearest neighbour
Definition: Octree.h:295
~Octree()
destructor
Definition: Octree.h:287
void split(Node *children)
creates the children for this node
Definition: Octree.h:154
const AABB & getRootAABB() const
returs the Octree's top-level bounding box
Definition: Octree.h:332
void init(Node *parent, const AABB &boundary)
initialization methods (with given boundary)
Definition: Octree.h:122
Node()
empty default constructor (does nothing)
Definition: Octree.h:108
Node * root
root node pointer
Definition: Octree.h:238
int num
internal counter for the number of contained points
Definition: Octree.h:244
void assign(ForwardIterator begin, ForwardIterator end)
utilty method to assign new data
Definition: Octree.h:435