#include "X3D_BBoxUpdaterStateVariables.h" using namespace std; namespace X3DTK { namespace X3D { BBoxUpdaterStateVariables::BBoxUpdaterStateVariables() : StateVariables(), _staticProcessing(true) { } BBoxUpdaterStateVariables::~BBoxUpdaterStateVariables() { //delete the BBox for (list >::iterator it = _BBList.begin(); it != _BBList.end(); ++it) delete (*it).second; } void BBoxUpdaterStateVariables::finish() { for (list >::iterator it = _BBList.begin(); it != _BBList.end(); ++it) delete (*it).second; _BBList.clear(); _BBToMergeList.clear(); } void BBoxUpdaterStateVariables::setStaticProcessing(bool value) { _staticProcessing = value; } void BBoxUpdaterStateVariables::addBBox(SFNode N, BBox *BB) { _BBList.push_front(pair(N, BB)); } void BBoxUpdaterStateVariables::setShapeBBox(const BBox &BB) { _shapeBBox = BB; } void BBoxUpdaterStateVariables::addBBoxToMergeList(const BBox &BB) { _BBToMergeList.push_back(BB); } BBox *BBoxUpdaterStateVariables::getBBox(SFNode N) const { for (list >::const_iterator it = _BBList.begin(); it != _BBList.end(); ++it) if ((*it).first == N) return (*it).second; return 0; } BBox BBoxUpdaterStateVariables::mergeBBox() { if (_BBToMergeList.empty()) return BBox(SFVec3f(0.0f, 0.0f, 0.0f), SFVec3f(-1.0f, -1.0f, -1.0f)); BBox BB = _BBToMergeList.front(); SFVec3f min = BB.getCenter() - 0.5f*BB.getSize(); SFVec3f max = BB.getCenter() + 0.5f*BB.getSize(); //iterate mergingBBoxStack for (list::const_iterator it = ++_BBToMergeList.begin(); it != _BBToMergeList.end(); ++it) { SFVec3f min2 = (*it).getCenter() - 0.5f*(*it).getSize(); SFVec3f max2 = (*it).getCenter() + 0.5f*(*it).getSize(); if (min2.x < min.x) min.x = min2.x; if (min2.y < min.y) min.y = min2.y; if (min2.z < min.z) min.z = min2.z; if (max2.x > max.x) max.x = max2.x; if (max2.y > max.y) max.y = max2.y; if (max2.z > max.z) max.z = max2.z; } //computing the new center SFVec3f center = 0.5f*(min + max); BB = BBox(center, 2.0f*(max - center)); //emptying the list. _BBToMergeList.clear(); return BB; } } }