00001 #include "BboxUpdaterGeometry3DVisitor.h"
00002 #include "Box.h"
00003 #include "Cone.h"
00004 #include "Cylinder.h"
00005 #include "Sphere.h"
00006 #include "Bbox.h"
00007
00008 #include <iostream>
00009
00010 using namespace X3DTK;
00011 using namespace std;
00012
00013 BboxUpdaterGeometry3DVisitor::BboxUpdaterGeometry3DVisitor()
00014 : Geometry3DVisitor()
00015 {
00016
00017 defineNewEnterFunction<BboxUpdaterGeometry3DVisitor, Box>(&BboxUpdaterGeometry3DVisitor::enterBox);
00018 defineNewEnterFunction<BboxUpdaterGeometry3DVisitor, Cone>(&BboxUpdaterGeometry3DVisitor::enterCone);
00019 defineNewEnterFunction<BboxUpdaterGeometry3DVisitor, Cylinder>(&BboxUpdaterGeometry3DVisitor::enterCylinder);
00020 defineNewEnterFunction<BboxUpdaterGeometry3DVisitor, Sphere>(&BboxUpdaterGeometry3DVisitor::enterSphere);
00021
00022
00023
00024 globalVariables = GVManager::getInstanceOf<BboxUpdaterGlobalVariables>();
00025 }
00026
00027 BboxUpdaterGeometry3DVisitor::~BboxUpdaterGeometry3DVisitor()
00028 {
00029 }
00030
00031 void BboxUpdaterGeometry3DVisitor::enterBox(Box *B) const
00032 {
00033 Bbox *BB = globalVariables->getBbox(B);
00034 if (BB == 0)
00035 {
00036 BB = new Bbox(SFVec3f(0.0f, 0.0f, 0.0f), B->getSize());
00037 globalVariables->addBbox(B, BB);
00038 globalVariables->setShapeBbox(*BB);
00039 }
00040 }
00041
00042 void BboxUpdaterGeometry3DVisitor::enterCone(Cone *C) const
00043 {
00044 Bbox *BB = globalVariables->getBbox(C);
00045 if (BB == 0)
00046 {
00047 BB = new Bbox(SFVec3f(0.0f, 0.0f, 0.0f), SFVec3f(2.0f*C->getBottomRadius(), C->getHeight(), 2.0f*C->getBottomRadius()));
00048 globalVariables->addBbox(C, BB);
00049 globalVariables->setShapeBbox(*BB);
00050 }
00051 }
00052
00053 void BboxUpdaterGeometry3DVisitor::enterCylinder(Cylinder *C) const
00054 {
00055 Bbox *BB = globalVariables->getBbox(C);
00056 if (BB == 0)
00057 {
00058 BB = new Bbox(SFVec3f(0.0f, 0.0f, 0.0f), SFVec3f(2.0f*C->getRadius(), C->getHeight(), 2.0f*C->getRadius()));
00059 globalVariables->addBbox(C, BB);
00060 globalVariables->setShapeBbox(*BB);
00061 }
00062 }
00063
00064 void BboxUpdaterGeometry3DVisitor::enterSphere(Sphere *S) const
00065 {
00066 Bbox *BB = globalVariables->getBbox(S);
00067 if (BB == 0)
00068 {
00069 BB = new Bbox(SFVec3f(0.0f, 0.0f, 0.0f), SFVec3f(2.0f*S->getRadius(), 2.0f*S->getRadius(), 2.0f*S->getRadius()));
00070 globalVariables->addBbox(S, BB);
00071 globalVariables->setShapeBbox(*BB);
00072 }
00073 }
00074