// Wbucket.cpp: implementation of the Wbucket class. // ////////////////////////////////////////////////////////////////////// #include "dxstdafx.h" #include "Wbucket.h" #include "Wsimplex.h" #include "Woctreebranch.h" #include "Vector.hpp" ////////////////////////////////////////////////////////////////////// // ruction/Destruction ////////////////////////////////////////////////////////////////////// Wbucket::Wbucket() { } Wbucket::~Wbucket() { ::std::vector::const_iterator a = simplexArray.begin(); while(a != simplexArray.end()) { (*a)->cutlinkback(this); a++; } } Woctree* Wbucket::add( Wsimplex *toadd,int maxObjsInBucket, double minBrick) { simplexArray.push_back(toadd); toadd->linkback(this); if(simplexArray.size() > maxObjsInBucket && parent->getChildSize()->x>minBrick) { return new Woctreebranch(this, parent, whereami); } return this; //WARNING Woctreebracjj constructor deleted this bucket } Wbucket::Wbucket( Wsimplex* founder, int orientation, Woctreebranch* parent) { this->parent = parent; simplexArray.push_back(founder); founder->linkback(this); whereami = orientation; } Wsimplex* Wbucket::search(Vector *proxy) { ::std::vector::const_iterator a = simplexArray.begin(); while(a != simplexArray.end()) { if((*a)->inCircle(proxy)) return *a; a++; } //NEVER HAPPENS IN A CORRECT MESH return NULL; } Wsimplex* Wbucket::searchNeighbour(Wsimplex *proxy) { Wsimplex* ret = NULL; float distance2 = FLT_MAX; ::std::vector::iterator a = simplexArray.begin(); while(a != simplexArray.end()) { if(*a != proxy) { Vector diff = *proxy->getCircumcentre(); diff -= *(*a)->getCircumcentre(); float cd2 = diff.norm2(); if(cd2 < distance2) { distance2 = cd2; ret = *a; } } a++; } return ret; } void Wbucket::eliminate(Wsimplex *dieing) { ::std::vector::iterator a = simplexArray.begin(); while(a < simplexArray.end()) { if(*a == dieing) simplexArray.erase(a); else a++; } } int Wbucket::getCount() { return simplexArray.size(); }