// Woctreebranch.cpp: implementation of the Woctreebranch class. // ////////////////////////////////////////////////////////////////////// #include "dxstdafx.h" #include "Woctreebranch.h" #include "Wbucket.h" #include "Wsimplex.h" #include "Vector.hpp" ////////////////////////////////////////////////////////////////////// // ruction/Destruction ////////////////////////////////////////////////////////////////////// Woctreebranch::Woctreebranch() { for(int i=0;i<8;i++) subregion[i] = NULL; parent = NULL; x=y=z=0; rx=ry=rz=1; } Woctreebranch::~Woctreebranch() { for(int i=0;i<8;i++) if(subregion[i]) delete subregion[i]; } Woctree* Woctreebranch::add( Wsimplex* toadd,int maxObjsInBucket, double minBrick) { Vector* cc = toadd->getCircumcentre(); double radius = toadd->getRadius(); Woctree** ps = subregion+7; if(cc->x+radius > x && cc->y+radius > y && cc->z+radius > z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,7,this); ps--; if(cc->x-radius < x && cc->y+radius > y && cc->z+radius > z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,6,this); ps--; if(cc->x+radius > x && cc->y-radius < y && cc->z+radius > z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,5,this); ps--; if(cc->x-radius < x && cc->y-radius < y && cc->z+radius > z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,4,this); ps--; if(cc->x+radius > x && cc->y+radius > y && cc->z-radius < z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,3,this); ps--; if(cc->x-radius < x && cc->y+radius > y && cc->z-radius < z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,2,this); ps--; if(cc->x+radius > x && cc->y-radius < y && cc->z-radius < z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,1,this); ps--; if(cc->x-radius < x && cc->y-radius < y && cc->z-radius < z) if(*ps) *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick); else *ps = new Wbucket(toadd,0,this); return this; } Wsimplex* Woctreebranch::search(Vector *proxy) { return subregion[((proxy->x>x)?1:0) | ((proxy->y>y)?2:0) | ((proxy->z>z)?4:0)]->search(proxy); } Wsimplex* Woctreebranch::searchNeighbour(Wsimplex* proxy) { Vector* cc = proxy->getCircumcentre(); int subri = ((cc->x>x)?1:0) | ((cc->y>y)?2:0) | ((cc->z>z)?4:0); Wsimplex* ret = subregion[subri]->searchNeighbour(proxy); if(ret) return ret; for(int i = 0; i<7; i++, subri = (subri + 1) % 8) { ret = subregion[subri]->searchNeighbour(proxy); if(ret) return ret; } return NULL; } Woctreebranch::Woctreebranch(Wbucket *a, Woctreebranch *parent, int orientation) { for(int i=0;i<8;i++) subregion[i] = NULL; this->parent = parent; Vector* range = parent->getChildSize(); Vector* center = parent->getHalfer(); x = center->x + (orientation&1)?range->x:-range->x; y = center->y + (orientation&2)?range->y:-range->y; z = center->z + (orientation&4)?range->z:-range->z; delete range; delete center; ::std::vector::const_iterator b = a->simplexArray.begin(); while(b != a->simplexArray.end()) { add(*b); b++; } delete a; } Woctreebranch::Woctreebranch(double x, double y, double z, double rx, double ry, double rz) { for(int i=0;i<8;i++) subregion[i] = NULL; parent = NULL; this->x=x; this->y=y; this->z=z; this->rx=rx; this->ry=ry; this->rz=rz; } Woctreebranch::Woctreebranch(Woctreebranch *parent, int orientation) { for(int i=0;i<8;i++) subregion[i] = NULL; this->parent = parent; Vector* range = parent->getChildSize(); Vector* center = parent->getHalfer(); x = center->x + (orientation&1)?range->x:-range->x; y = center->y + (orientation&2)?range->y:-range->y; z = center->z + (orientation&4)?range->z:-range->z; } Vector* Woctreebranch::getHalfer() { return new Vector(x,y,z); } Vector* Woctreebranch::getChildSize() { return new Vector(rx/2,ry/2,rz/2); }