00001 #include "BboxUpdaterRenderingVisitor.h"
00002 #include "Coordinate.h"
00003 #include "X3DGeometryNode.h"
00004
00005 #include <iostream>
00006
00007 using namespace std;
00008 using namespace X3DTK;
00009
00010 BboxUpdaterRenderingVisitor::BboxUpdaterRenderingVisitor()
00011 : RenderingVisitor()
00012 {
00013
00014 defineNewEnterFunction<BboxUpdaterRenderingVisitor, Coordinate>(&BboxUpdaterRenderingVisitor::enterCoordinate);
00015
00016
00017 defineNewWalkOnFunction<BboxUpdaterRenderingVisitor, X3DGeometryNode>(&BboxUpdaterRenderingVisitor::walkOnX3DGeometryNode);
00018
00019
00020
00021 globalVariables = GVManager::getInstanceOf<BboxUpdaterGlobalVariables>();
00022 }
00023
00024 BboxUpdaterRenderingVisitor::~BboxUpdaterRenderingVisitor()
00025 {
00026 }
00027
00028 void BboxUpdaterRenderingVisitor::enterCoordinate(Coordinate *C) const
00029 {
00030 Bbox *BB = globalVariables->getBbox(C);
00031 if (BB == 0)
00032 {
00033 MFVec3f &vertexArray = C->getPoint();
00034
00035 if (vertexArray.empty())
00036 {
00037 BB = new Bbox(SFVec3f(0.0f, 0.0f, 0.0f), SFVec3f(-1.0f, -1.0f, -1.0f));
00038 return;
00039 }
00040
00041 SFVec3f min = vertexArray[0];
00042 SFVec3f max = vertexArray[0];
00043
00044 for (MFVec3f::const_iterator itVertex = vertexArray.begin(); itVertex != vertexArray.end(); ++itVertex)
00045 {
00046 if ((*itVertex).x < min.x)
00047 min.x = (*itVertex).x;
00048 if ((*itVertex).y < min.y)
00049 min.y = (*itVertex).y;
00050 if ((*itVertex).z < min.z)
00051 min.z = (*itVertex).z;
00052
00053 if ((*itVertex).x > max.x)
00054 max.x = (*itVertex).x;
00055 if ((*itVertex).y > max.y)
00056 max.y = (*itVertex).y;
00057 if ((*itVertex).z > max.z)
00058 max.z = (*itVertex).z;
00059 }
00060
00061
00062 SFVec3f center = 0.5f*(min + max);
00063
00064 BB = new Bbox(center, 2.0f*(max - center));
00065 globalVariables->addBbox(C, BB);
00066 globalVariables->setShapeBbox(*BB);
00067 }
00068 }
00069
00070 bool BboxUpdaterRenderingVisitor::walkOnX3DGeometryNode(X3DGeometryNode *N, SFNode Child) const
00071 {
00072 return true;
00073 }
00074