Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

BboxUpdaterGlobalVariables.cpp

Go to the documentation of this file.
00001 #include "BboxUpdaterGlobalVariables.h"
00002 
00003 using namespace X3DTK;
00004 using namespace std;
00005 
00006 BboxUpdaterGlobalVariables::BboxUpdaterGlobalVariables()
00007 : GlobalVariables(), _staticProcessing(true)
00008 {
00009 }
00010 
00011 BboxUpdaterGlobalVariables::~BboxUpdaterGlobalVariables()
00012 {
00013   //delete the Bbox
00014   for (list<pair<SFNode, Bbox *> >::iterator it = _BBList.begin(); it != _BBList.end(); ++it)
00015     delete (*it).second;
00016 }
00017 
00018 void BboxUpdaterGlobalVariables::finish()
00019 {
00020   for (list<pair<SFNode, Bbox *> >::iterator it = _BBList.begin(); it != _BBList.end(); ++it)
00021     delete (*it).second;
00022     
00023   _BBList.clear();
00024   _BBToMergeList.clear();
00025 }
00026 
00027 void BboxUpdaterGlobalVariables::setStaticProcessing(bool value)
00028 {
00029   _staticProcessing = value;
00030 }
00031 
00032 void BboxUpdaterGlobalVariables::addBbox(SFNode N, Bbox *BB)
00033 {
00034   _BBList.push_front(pair<SFNode, Bbox *>(N, BB));
00035 }
00036 
00037 void BboxUpdaterGlobalVariables::setShapeBbox(const Bbox &BB)
00038 {
00039   _shapeBbox = BB;
00040 }
00041 
00042 void BboxUpdaterGlobalVariables::addBboxToMergeList(const Bbox &BB)
00043 {
00044   _BBToMergeList.push_back(BB);
00045 }
00046 
00047 Bbox *BboxUpdaterGlobalVariables::getBbox(SFNode N) const
00048 {
00049   for (list<pair<SFNode, Bbox *> >::const_iterator it = _BBList.begin(); it != _BBList.end(); ++it)
00050     if ((*it).first == N)
00051       return (*it).second;  
00052       
00053   return 0;   
00054 }
00055 
00056 Bbox BboxUpdaterGlobalVariables::mergeBbox()
00057 {
00058   if (_BBToMergeList.empty())
00059     return Bbox(SFVec3f(0.0f, 0.0f, 0.0f), SFVec3f(-1.0f, -1.0f, -1.0f));
00060   
00061   Bbox BB = _BBToMergeList.front();
00062   SFVec3f min = BB.getCenter() - 0.5f*BB.getSize();
00063   SFVec3f max = BB.getCenter() + 0.5f*BB.getSize();
00064 
00065   //iterate mergingBboxStack
00066   for (list<Bbox>::const_iterator it = ++_BBToMergeList.begin(); it != _BBToMergeList.end(); ++it)
00067   {
00068     SFVec3f min2 = (*it).getCenter() - 0.5f*(*it).getSize();
00069     SFVec3f max2 = (*it).getCenter() + 0.5f*(*it).getSize();
00070     
00071     if (min2.x < min.x)
00072       min.x = min2.x;
00073     if (min2.y < min.y)
00074       min.y = min2.y;
00075     if (min2.z < min.z)
00076       min.z = min2.z;
00077   
00078     if (max2.x > max.x)
00079       max.x = max2.x;
00080     if (max2.y > max.y)
00081       max.y = max2.y;
00082     if (max2.z > max.z)
00083       max.z = max2.z;
00084   }
00085   
00086   //computing the new center
00087   SFVec3f center = 0.5f*(min + max);
00088   BB = Bbox(center, 2.0f*(max - center));
00089   
00090   //emptying the list.
00091   _BBToMergeList.clear();
00092   
00093   return BB;
00094 }

Generated on Wed May 14 10:03:07 2003 for X3DToolKit by doxygen1.3