174 template<
class Scalar,
int CAPACITY=4,
int SF=1,
int ALLOC_CHUNK_SIZE=1024,
175 class VECTOR_TYPE=FixedColVector<Scalar,2> >
180 typedef VECTOR_TYPE
Pt;
246 this->next = this->
points;
261 found.push_back((*p)/SF);
281 this->children[0].
init(
this,
AABB(
Pt(c[0]-half[0],c[1]-half[1]),half));
282 this->children[1].
init(
this,
AABB(
Pt(c[0]+half[0],c[1]-half[1]),half));
283 this->children[2].
init(
this,
AABB(
Pt(c[0]-half[0],c[1]+half[1]),half));
284 this->children[3].
init(
this,
AABB(
Pt(c[0]+half[0],c[1]+half[1]),half));
299 for(
int i=0;i<indent;++i) std::cout <<
" ";
301 std::cout <<
"Branch (";
303 std::cout <<
"Leaf (";
306 std::cout <<
"Content=" <<(int)(
next-
points) <<
"/" << CAPACITY;
309 std::cout <<
" {" << std::endl;
314 for(
int i=0;i<indent;++i) std::cout <<
" ";
315 std::cout <<
"}" << std::endl;;
317 else std::cout << std::endl;
354 if(
curr == ALLOC_CHUNK_SIZE)
grow();
366 std::vector<Pt>
all()
const{
368 for(
size_t i=0;i<
allocated.size()-1;++i){
371 for(
const Pt* p = ns[j].points; p != ns[j].
next;++p){
372 pts.push_back((*p)/SF);
377 for(
int i=0;i<
curr*4;++i){
378 for(
const Pt* p = ns[i].points; p != ns[i].
next;++p){
379 pts.push_back((*p)/SF);
397 QuadTree(
const Scalar &minX,
const Scalar &minY,
const Scalar &width,
const Scalar &height):
num(0){
398 this->root =
new Node(
AABB(
Pt(SF*minX+SF*width/2, SF*minY+SF*height/2),
399 Pt(SF*width/2,SF*height/2)));
410 this->root =
new Node(
AABB(
Pt(SF*bounds.x+SF*bounds.width/2, SF*bounds.y+SF*bounds.height/2),
411 Pt(SF*bounds.width/2,SF*bounds.height/2)));
416 this->root =
new Node(
AABB(
Pt(SF*width/2,SF*height/2),
417 Pt(SF*width/2,SF*height/2)));
457 for(
const Pt *x=n->
points; x < n->next; ++x){
459 if(dSqr < sqrMinDist){
464 currMinDist =
sqrt(sqrMinDist);
486 const Pt *currNN = 0;
512 std::vector<const Node*> stack;
514 stack.push_back(
root);
516 const Pt *currNN = 0;
521 const Node *n = stack.back();
524 const AABB b(p,
Pt(currMinDist,currMinDist));
532 for(
const Pt *x=n->
points; x < n->next; ++x){
534 if(dSqr < sqrMinDist){
539 currMinDist =
sqrt(sqrMinDist);
586 std::vector<Pt>
query(
const Scalar &minX,
const Scalar &minY,
587 const Scalar &width,
const Scalar &height)
const{
588 AABB range(
Pt(SF*minX+SF*width/2, SF*minY+SF*height/2),
589 Pt(SF*width/2,SF*height/2));
590 std::vector<Pt> found;
609 d.
color(0,100,255,255);
631 std::cout <<
"QuadTree{" << std::endl;
633 std::cout <<
"}" << std::endl;
std::vector< Pt > query(const Scalar &minX, const Scalar &minY, const Scalar &width, const Scalar &height) const
returns all contained points within the given rectangle
Definition: QuadTree.h:586
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
void clear()
removes all contained points and nodes
Definition: QuadTree.h:617
bool contains(const Pt &p) const
returns whether a given 2D point is contained
Definition: QuadTree.h:199
void insert(const utils::Point &p)
convenience wrapper for the Point instances
Definition: QuadTree.h:581
void clear()
deletes all allocated data chunks (except for the first)
Definition: QuadTree.h:344
int size() const
number of elments inserted
Definition: QuadTree.h:625
undocument this line if you encounter any issues!
Definition: Any.h:37
Pt center
center point
Definition: QuadTree.h:188
utils::VisualizationDescription vis() const
returns a visualization description for QuadTree structure (not for the contained points)
Definition: QuadTree.h:607
void init(Node *parent, const AABB &boundary)
initialization methods (with given boundary)
Definition: QuadTree.h:244
QuadTree(const Scalar &width, const Scalar &height)
creates a QuadTree for the given 2D Size (minX and minY are set to 0 here)
Definition: QuadTree.h:415
void vis(utils::VisualizationDescription &d) const
recursively grabs visualizations commands
Definition: QuadTree.h:288
Pt halfSize
half dimension
Definition: QuadTree.h:189
float y
y position of this point
Definition: Point32f.h:48
float y
!< x pos (upper left)
Definition: Rect32f.h:49
~Allocator()
frees all allocated data
Definition: QuadTree.h:359
QuadTree(const utils::Size32f &size)
convenience wrapper for given Size32f bounds
Definition: QuadTree.h:421
void split(Node *children)
creates the children for this node
Definition: QuadTree.h:276
QuadTree(const utils::Size &size)
convenience wrapper for given Size bounds
Definition: QuadTree.h:427
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: QuadTree.h:442
void grow()
allocates the next data chunk
Definition: QuadTree.h:338
Node * children
pointer to four child-nodes
Definition: QuadTree.h:232
VECTOR_TYPE Pt
Definition: QuadTree.h:180
float x
Definition: Rect32f.h:48
bool intersects(const AABB &o) const
returns whether the AABB intersects with another AABB
Definition: QuadTree.h:208
Inernally used block allocator.
Definition: QuadTree.h:326
Node(const AABB &boundary)
constructor from given AABB-boundary
Definition: QuadTree.h:239
int curr
current data
Definition: QuadTree.h:332
void rect(icl32f x, icl32f y, icl32f width, icl32f height)
add a rectangle
Definition: VisualizationDescription.h:202
AABB()
default constructor (does nothing)
Definition: QuadTree.h:192
Floating point precision implementation of the Rect class.
Definition: Rect32f.h:45
void printStructure()
prints the quad-tree structure hierachically (for debug purpose)
Definition: QuadTree.h:630
std::vector< Pt > query(const utils::Rect &r) const
convenience wrapper for Rect class
Definition: QuadTree.h:596
~QuadTree()
destructor
Definition: QuadTree.h:434
float height
!< width of the rect
Definition: Rect32f.h:51
Allocator()
allocates the first data chunk
Definition: QuadTree.h:335
std::vector< Node * > allocated
allocated data
Definition: QuadTree.h:329
Pt nn(const Pt &pIn) const
finds the nearest neighbor to the given node
Definition: QuadTree.h:510
Node()
empty default constructor (does nothing)
Definition: QuadTree.h:236
Generic QuadTree Implementation.
Definition: QuadTree.h:176
Size class of the ICL.
Definition: Size.h:61
QuadTree(const utils::Rect &bounds)
convenience constructor wrapper for given Rect32f bounds
Definition: QuadTree.h:409
AABB(const Pt ¢er, const Pt &halfSize)
constructor from given center and half size
Definition: QuadTree.h:195
Node * root
root node pointer
Definition: QuadTree.h:387
Pt * next
next node to fill
Definition: QuadTree.h:231
std::vector< Pt > queryAll() const
returns all contained points
Definition: QuadTree.h:602
int num
internal counter for the number of contained points
Definition: QuadTree.h:393
static T sqr(const T &x)
square template (faster than pow(x,2)
Definition: Macros.h:212
void insert(const utils::Point32f &p)
convenience wrapper for the Point32f instances
Definition: QuadTree.h:576
AABB boundary
node boundary
Definition: QuadTree.h:229
Internally used node structure.
Definition: QuadTree.h:228
std::vector< Pt > all() const
returns all contained points
Definition: QuadTree.h:366
Node * parent
Definition: QuadTree.h:233
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
QuadTree(const Scalar &minX, const Scalar &minY, const Scalar &width, const Scalar &height)
creates a QuadTree for the given 2D rectangle
Definition: QuadTree.h:397
Pt nn_approx(const Pt &p) const
returns an approximated nearst neighbour
Definition: QuadTree.h:484
Abstract class for visualization tasks.
Definition: VisualizationDescription.h:73
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
float x
x position of this point
Definition: Point32f.h:45
utils::Rect32f rect() const
Definition: QuadTree.h:219
Base class for Exception handling in the ICL.
Definition: Exception.h:42
const utils::Point nn(const utils::Point &p) const
convenience wrapper for the Point32f type
Definition: QuadTree.h:551
float width
!< y pos (upper left)
Definition: Rect32f.h:50
std::vector< Pt > query(const utils::Rect32f &r) const
convenience wrapper for Rect32f class
Definition: QuadTree.h:599
internally used axis-aligned bounding box
Definition: QuadTree.h:187
Size32f class of the ICL (float valued)
Definition: Size32f.h:40
void insert(const Pt &pIn)
inserts a node into the QuadTree
Definition: QuadTree.h:561
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
void query(const AABB &boundary, std::vector< Pt > &found) const
recursive getter function that queries all nodes within a given bounding box
Definition: QuadTree.h:255
void color(icl8u r, icl8u g, icl8u b)
sets the current draw color (no alpha)
Definition: VisualizationDescription.h:348
Allocator alloc
memory allocator for all children except for the root node
Definition: QuadTree.h:390
void fill(icl8u r, icl8u g, icl8u b)
sets the current fill color (no alpha)
Definition: VisualizationDescription.h:358
QuadTree(const utils::Rect32f &bounds)
convenience constructor wrapper for given Rect32f bounds
Definition: QuadTree.h:403
Pt points[CAPACITY]
contained nodes
Definition: QuadTree.h:230
const utils::Point32f nn(const utils::Point32f &p) const
convenience wrapper for the Point32f type
Definition: QuadTree.h:545
Node * next()
returns the next four Node instances (allocates new data on demand)
Definition: QuadTree.h:353
void printStructure(int indent)
Definition: QuadTree.h:298