Changeset 2115
- Timestamp:
- 02/12/07 19:00:37 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
r2113 r2115 39 39 }; 40 40 41 41 42 /** Class which converts preprocessor types to OGRE types 42 43 */ … … 121 122 122 123 list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 124 123 125 // find the bbox which is closest to the current bbox 124 126 for (sit = sceneNodeList.begin(); sit != sit_end; ++ sit) … … 247 249 for (iit = iboxes.begin(); iit != iit_end; ++ iit) 248 250 { 251 const GtpVisibilityPreprocessor::AxisAlignedBox3 pbox = (*iit).second; 252 const int id = (*iit).first; 253 249 254 const AxisAlignedBox box = 250 OgreTypeConverter::ConvertToOgre( (*iit).second);251 252 EntityContainer *entryObjects = new EntityContainer();255 OgreTypeConverter::ConvertToOgre(pbox); 256 257 EntityContainer entryObjects; 253 258 254 259 // find all objects that intersect the bounding box 255 FindIntersectingObjects(box, *entryObjects); 256 260 FindIntersectingObjects(box, entryObjects); 261 262 // TODO: can actually just put single objects into pvs with same id, 263 // this can be sorted out later!! 264 #if 1 265 EntityContainer::const_iterator eit, eit_end = entryObjects.end(); 266 267 for (eit = entryObjects.begin(); eit != eit_end; ++ eit) 268 { 269 Entity *ent = *eit; 270 271 // warning: multiple ids possible 272 OgreMeshInstance *omi = new OgreMeshInstance(ent); 273 omi->SetId(id); 274 objects.push_back(omi); 275 } 276 #else 257 277 EngineIntersectable *entry = 258 278 new EngineIntersectable(entryObjects); 259 279 260 entry->SetId((*iit).first); 261 280 entry->SetId(id); 262 281 objects.push_back(entry); 282 #endif 263 283 } 264 284 265 285 return true; 266 286 } 287 267 288 #else 289 268 290 //------------------------------------------------------------------------- 269 291 template<typename T> -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreMeshInstance.h
r2069 r2115 49 49 const int maxTries); 50 50 51 int GetRandomEdgePoint(GtpVisibilityPreprocessor::Vector3 &point, 52 GtpVisibilityPreprocessor::Vector3 &normal); 53 51 54 ostream &Describe(ostream &s); 52 55 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp
r2114 r2115 1325 1325 GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes; 1326 1326 BvhBoundingBoxConverter bconverter(this); 1327 GtpVisibilityPreprocessor::ObjectContainer dummys; 1327 1328 1328 // load the view cells and assigns the objects in the pvs to 1329 1329 // the scene objects using the bounding boxes 1330 1330 mViewCellsManager = 1331 1331 GtpVisibilityPreprocessor::ViewCellsManager:: 1332 LoadViewCells(filename, mObjects, dummys,false, &bconverter);1332 LoadViewCells(filename, mObjects, false, &bconverter); 1333 1333 1334 1334 return (mViewCellsManager != NULL); -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
r2114 r2115 1325 1325 GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes; 1326 1326 KdTreeBoundingBoxConverter bconverter(this); 1327 GtpVisibilityPreprocessor::ObjectContainer dummys; 1327 1328 1328 // load the view cells assigning the found objects to the pvss 1329 1329 mViewCellsManager = 1330 1330 GtpVisibilityPreprocessor::ViewCellsManager:: 1331 LoadViewCells(filename, mObjects, dummys,false, &bconverter);1331 LoadViewCells(filename, mObjects, false, &bconverter); 1332 1332 1333 1333 return (mViewCellsManager != NULL); … … 1344 1344 // representing unbounded space then 1345 1345 SetObjectsVisible(true); 1346 1346 1347 return; 1347 1348 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreMeshInstance.cpp
r2066 r2115 55 55 56 56 int OgreMeshInstance::GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 57 GtpVisibilityPreprocessor::Vector3 &normal)57 GtpVisibilityPreprocessor::Vector3 &normal) 58 58 { 59 59 return 0; 60 60 } 61 61 62 int OgreMeshInstance::GetRandomEdgePoint(GtpVisibilityPreprocessor::Vector3 &point, 63 GtpVisibilityPreprocessor::Vector3 &normal) 64 { 65 return 0; 66 } 67 62 68 int OgreMeshInstance::GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 63 69 GtpVisibilityPreprocessor::Vector3 &normal, … … 67 73 return 0; 68 74 } 69 75 70 76 ostream &OgreMeshInstance::Describe(ostream &s) 71 77 { -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
r2114 r2115 403 403 // show current view cell geometry 404 404 if (mCurrentViewCell && mCurrentViewCell->GetMesh()) 405 { 405 {/* 406 406 //const bool showSingleViewCell = true; 407 407 if (mViewCellsGeometryLoaded) … … 427 427 } 428 428 } 429 430 429 */ 431 430 ////////// 432 431 //-- set PVS of view cell visible 433 432 434 GtpVisibilityPreprocessor::ObjectPvsIterator pit = 435 mCurrentViewCell->GetPvs().GetIterator(); 433 GtpVisibilityPreprocessor::ObjectPvsIterator pit = mCurrentViewCell->GetPvs().GetIterator(); 436 434 437 435 while (pit.HasMoreEntries()) … … 440 438 GtpVisibilityPreprocessor::Intersectable *obj = entry.mObject; 441 439 442 if (obj->Type() != 443 GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE) 444 continue; 445 446 EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj); 447 448 EntityContainer *entries = oi->GetItem(); 449 EntityContainer::const_iterator eit, eit_end = entries->end(); 450 451 for (eit = entries->begin(); eit != eit_end; ++ eit) 452 { 453 (*eit)->setUserAny(Any((int)0)); 454 } 455 } 456 457 pit = mCurrentViewCell->GetPvs().GetIterator(); 458 459 while (pit.HasMoreEntries()) 460 { 461 GtpVisibilityPreprocessor::ObjectPvsEntry entry = pit.Next(); 462 GtpVisibilityPreprocessor::Intersectable *obj = entry.mObject; 463 464 switch (obj->Type()) 465 { 466 case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE: 467 { 468 OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj); 469 omi->GetEntity()->_updateRenderQueue(getRenderQueue()); 470 } 471 break; 472 473 case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE: 474 { 475 EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj); 476 477 EntityContainer *entries = oi->GetItem(); 478 EntityContainer::const_iterator eit, eit_end = entries->end(); 479 480 for (eit = entries->begin(); eit != eit_end; ++ eit) 481 { 482 483 Entity *ent = *eit; 484 Any newAny = ent->getUserAny(); 485 486 int flt = any_cast<int>(newAny); 487 488 if (any_cast<int>(newAny) == 0) 489 { 490 ent->setUserAny(Any((int)1)); 491 ent->_updateRenderQueue(getRenderQueue()); 492 } 493 494 } 495 } 496 break; 497 default: 498 break; 499 } 500 } 440 OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj); 441 omi->GetEntity()->_updateRenderQueue(getRenderQueue()); 442 } 443 501 444 } 502 445 /* … … 1414 1357 GtpVisibilityPreprocessor::Intersectable *entry = *it; 1415 1358 1416 switch (entry->Type()) 1417 { 1418 case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE: 1419 { 1420 OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(entry); 1421 omi->GetEntity()->setVisible(visible); 1422 //GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl; 1423 } 1424 break; 1425 case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE: 1426 { 1427 EngineIntersectable *oi = static_cast<EngineIntersectable *>(entry); 1428 1429 EntityContainer *entries = oi->GetItem(); 1430 EntityContainer::const_iterator eit, 1431 eit_end = entries->end(); 1432 for (eit = entries->begin(); eit != eit_end; ++ eit) 1433 { 1434 Entity *ent = *eit; 1435 ent->setVisible(visible); 1436 } 1437 } 1438 break; 1439 default: 1440 break; 1441 } 1359 OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(entry); 1360 omi->GetEntity()->setVisible(visible); 1361 //GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl; 1442 1362 } 1443 1363 } … … 1459 1379 const bool finalizeViewCells = false; 1460 1380 1461 GtpVisibilityPreprocessor::ObjectContainer dummys;1462 1381 // load the view cells assigning the found objects to the pvss 1463 1382 mViewCellsManager = 1464 1383 GtpVisibilityPreprocessor::ViewCellsManager:: 1465 LoadViewCells(filename, mObjects, dummys,false, &bconverter);1384 LoadViewCells(filename, mObjects, false, &bconverter); 1466 1385 1467 1386 Ogre::LogManager::getSingleton().logMessage("******** view cells loaded *********"); … … 1508 1427 if (!obj) continue; 1509 1428 1510 switch (obj->Type()) 1511 { 1512 case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE: 1513 { 1514 OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj); 1515 omi->GetEntity()->setVisible(load); 1516 } 1517 break; 1518 case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE: 1519 { 1520 EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj); 1521 1522 EntityContainer *entries = oi->GetItem(); 1523 1524 EntityContainer::const_iterator eit, eit_end = entries->end(); 1525 1526 for (eit = entries->begin(); eit != eit_end; ++ eit) 1527 { 1528 Entity *ent = *eit; 1529 ent->setVisible(load); 1530 } 1531 } 1532 break; 1533 default: 1534 LogManager::getSingleton().logMessage("error: should not come here"); 1535 break; 1536 } 1429 OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj); 1430 omi->GetEntity()->setVisible(load); 1537 1431 } 1538 1432 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h
r2112 r2115 31 31 32 32 const std::vector<Ogre::Entity *> &GetObjects() const; 33 34 Ogre::Entity *CreateEntity(const std::string &name); 33 35 34 36 protected: -
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
r2112 r2115 57 57 58 58 59 #if TODO 60 61 Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr, 62 std::string name, 63 ObjMeshData *mData, 64 Ogre::Vector3 *translation) 59 Ogre::Entity *ObjReader::CreateEntity(const std::string &name) 60 // ObjMeshData *mData, 61 // Ogre::Vector3 *translation) 65 62 { 66 63 using namespace Ogre; 64 Entity *entity; 67 65 66 68 67 std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh"; 69 68 std::string entityName = name + "/Entity"; 70 69 71 Mesh* pMesh = NULL; 72 if ((pMesh = (Mesh *) MeshManager::getSingleton().getByName(meshName).getPointer()) == NULL) 70 MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup"); 71 SubMesh* submesh = mesh->createSubMesh(); 72 int nbVertices = 99992; 73 // We must create the vertex data, indicating how many vertices there will be 74 submesh->useSharedVertices = false; 75 submesh->vertexData = new VertexData(); 76 submesh->vertexData->vertexStart = 0; 77 submesh->vertexData->vertexCount = nbVertices; 78 79 static const unsigned short source = 0; 80 size_t offset = 0; 81 82 VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); 83 84 offset += declaration->addElement(source,offset,VET_FLOAT3,VES_POSITION).getSize(); 85 // offset += declaration->addElement(source,offset,VET_FLOAT3,VES_NORMAL).getSize(); 86 // offset += declaration->addElement(source,offset,VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize(); 87 88 89 int numVertices = 0; 90 91 HardwareVertexBufferSharedPtr vbuffer = 92 HardwareBufferManager::getSingleton().createVertexBuffer(declaration->getVertexSize(source), // size of one whole vertex 93 submesh->vertexData->vertexCount, // number of vertices 94 HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage 95 false); // no shadow buffer 96 97 98 // No we get access to the buffer to fill it. During so we record the bounding box. 99 AxisAlignedBox aabox; 100 101 float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD)); 102 103 for (size_t i = 0; i < nbVertices; ++ i) 73 104 { 105 // Position 106 Vector3 position;// = 20.0f*positions[i]; 107 *vdata++ = position.x; 108 *vdata++ = position.y; 109 *vdata++ = position.z; 110 aabox.merge(position); 111 // Normal 112 Vector3 normal = position.normalisedCopy(); 113 *vdata++ = normal.x; 114 *vdata++ = normal.y; 115 *vdata++ = normal.z; 74 116 75 ObjMeshData *data = mData->expand(); 117 // Texture coordinate 118 Vector2 tcoordinate;// = tcoordinates[i]; 119 *vdata ++ = tcoordinate.x; 76 120 77 ObjManualMeshLoader *loader = new ObjManualMeshLoader(data);121 *vdata ++ = tcoordinate.y; 78 122 79 if (translation != NULL) *translation = data->boundingBox->getCenter();80 81 addMeshToList(meshName, loader);82 83 Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "IVGroup", loader).getPointer();84 85 pMesh->load();86 pMesh->touch();87 }88 else89 {90 if (translation != NULL)91 {92 *translation = meshList->getManualMeshLoader(meshName)->getBoundingBox()->getCenter();93 }94 123 } 95 124 96 Entity *pEntity = sceneMgr->createEntity(entityName, meshName);125 vbuffer->unlock(); 97 126 127 // We must indicate the bounding box 128 //mesh->_setBounds(aabox); 98 129 99 if (0) pEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN);130 //mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); 100 131 101 return pEntity; 132 mesh->load(); 133 134 // Create an entity with the mesh 135 //entity = mSceneManager->createEntity(meshName, entityName); 136 137 return entity; 102 138 } 103 104 105 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r2093 r2115 201 201 float GetMergeCost() {return (float)-mTimeStamp; } 202 202 203 virtual int GetRandomEdgePoint(Vector3 &point, 204 Vector3 &normal); 203 virtual int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); 205 204 206 205 inline int GetTimeStamp() const { return mTimeStamp; } … … 221 220 int NumberOfFaces() const { return 6; }; 222 221 223 222 int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 224 223 GtpVisibilityPreprocessor::Vector3 &normal) 225 224 { -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.cpp
r2114 r2115 13 13 // Includes 14 14 // --------------------------------------------------------------------------- 15 15 16 #include <xercesc/framework/StdInInputSource.hpp> 16 17 #include <xercesc/parsers/SAXParser.hpp> … … 20 21 // Includes 21 22 // --------------------------------------------------------------------------- 23 22 24 #include <xercesc/sax/AttributeList.hpp> 23 25 #include <xercesc/sax/SAXParseException.hpp> 24 26 #include <xercesc/sax/SAXException.hpp> 25 27 26 #include " ViewCellsParser.h"27 28 #include " ViewCellsParserXerces.h"28 #include "ObjectsParser.h" 29 30 #include "ObjectsParserXerces.h" 29 31 #include "Mesh.h" 30 #include "VspBspTree.h"31 #include "ViewCellBsp.h"32 32 #include "ViewCellsManager.h" 33 33 #include "GzFileInputSource.h" 34 #include "OspTree.h"35 #include "VspTree.h"36 #include "KdTree.h"37 34 #include "BvHierarchy.h" 38 #include "HierarchyManager.h"39 35 40 36 … … 61 57 // can be set via the -v= command. 62 58 // --------------------------------------------------------------------------- 59 63 60 static bool doNamespaces = false; 64 61 static bool doSchema = false; … … 66 63 static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto; 67 64 68 // hack for loading bvh nodes69 #define PVS_HACK 070 65 71 66 inline static bool ilt(Intersectable *obj1, Intersectable *obj2) … … 78 73 // StdInParseHandlers: Constructors and Destructor 79 74 // --------------------------------------------------------------------------- 80 ViewCellsParseHandlers::ViewCellsParseHandlers(ObjectContainer &pvsObjects, 81 ObjectContainer &preprocessorObjects, 82 BoundingBoxConverter *bconverter83 75 76 ObjectsParseHandlers::ObjectsParseHandlers(ObjectContainer &pvsObjects, 77 const ObjectContainer &preprocessorObjects 78 ): 84 79 mElementCount(0) 85 80 , mAttrCount(0) 86 81 , mCharacterCount(0) 87 82 , mSpaceCount(0) 88 , mViewCellsManager(NULL)89 , mVspBspTree(NULL)90 , mBspTree(NULL)91 , mViewCellsTree(NULL)92 , mCurrentState(PARSE_OPTIONS)93 , mCurrentViewCell(NULL)94 , mCurrentBspNode(NULL)95 , mCurrentVspNode(NULL)96 , mCurrentOspNode(NULL)97 , mCurrentBvhNode(NULL)98 83 , mPvsObjects(pvsObjects) 99 84 , mPreprocessorObjects(preprocessorObjects) 100 , mBoundingBoxConverter(bconverter) 101 , mHierarchyManager(NULL) 102 , nViewCells(0) 103 , nObjects(0) 104 { 105 mCreatePvsObjects = mPvsObjects.empty(); 106 85 , mIsObjectSpaceHierarchy(false) 86 { 107 87 // sort objects so we can search in them 108 88 //if (!is_sorted(mPvsObjects.begin(), mPvsObjects.end(), ilt)) … … 110 90 111 91 //if (!is_sorted(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt)) 112 sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt);113 } 114 115 116 ViewCellsParseHandlers::~ViewCellsParseHandlers()92 //sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt); 93 } 94 95 96 ObjectsParseHandlers::~ObjectsParseHandlers() 117 97 { 118 98 } … … 124 104 125 105 126 void ViewCellsParseHandlers::endElement(const XMLCh* const name)106 void ObjectsParseHandlers::endElement(const XMLCh* const name) 127 107 { 128 108 StrX lname(name); 129 109 string element(lname.LocalForm()); 130 110 131 if (element == "BoundingBoxes")132 {133 EndBoundingBoxes();134 }135 136 if (element == "ViewCells")137 {138 EndViewCells();139 }140 141 111 if (element == "ObjectSpaceHierarchy") 142 112 { 143 113 EndObjectSpaceHierarchy(); 144 114 } 145 146 // finished, create view cells manager 147 if (element == "VisibilitySolution") 148 { 149 CreateViewCellsManager(); 150 } 151 152 if (element == "Interior") 153 { 154 switch (mCurrentState) 155 { 156 case PARSE_VIEWCELLS: 157 EndViewCellInterior(); 158 break; 159 case PARSE_OBJECTSPACE_HIERARCHY: 160 EndObjectSpaceHierarchyInterior(); 161 break; 162 case PARSE_VIEWSPACE_HIERARCHY: 163 EndViewSpaceHierarchyInterior(); 164 break; 165 default: 166 break; 167 } 168 } 169 } 170 171 172 void ViewCellsParseHandlers::EndObjectSpaceHierarchy() 173 { 174 if (mObjectSpaceHierarchyType == OSP) 175 { 176 // for a spatial subdivision, it is not necessary to store 177 // the objects with the leaves, they can be classified geometrically 178 mHierarchyManager->mOspTree-> 179 InsertObjects(mHierarchyManager->mOspTree->mRoot, mPvsObjects); 180 } 181 } 182 183 184 void ViewCellsParseHandlers::EndViewSpaceHierarchyInterior() 185 { 186 switch (mViewSpaceHierarchyType) 187 { 188 case BSP: 189 EndBspInterior(); 190 break; 191 case VSP: 192 EndVspInterior(); 193 break; 194 default: 195 Debug << "not implemented view space hierarchy type " << mViewSpaceHierarchyType << endl; 196 break; 197 } 198 } 199 200 201 void ViewCellsParseHandlers::EndObjectSpaceHierarchyInterior() 202 { 203 switch (mObjectSpaceHierarchyType) 204 { 205 case OSP: 206 EndOspInterior(); 207 break; 208 case BVH: 209 EndBvhInterior(); 210 break; 211 default: 212 Debug << "not implemented object space hierarchy type " << mViewSpaceHierarchyType << endl; 213 break; 214 } 215 } 216 217 218 void ViewCellsParseHandlers::EndBspInterior() 219 { 220 // go one up in the tree 221 if (mCurrentBspNode->GetParent()) 222 { //cout << "]"; 223 mCurrentBspNode = mCurrentBspNode->GetParent(); 224 } 225 } 226 227 228 void ViewCellsParseHandlers::EndBvhInterior() 229 { 230 // go one up in the tree 231 if (mCurrentBvhNode->GetParent()) 232 { //cout << "]"; 233 mCurrentBvhNode = mCurrentBvhNode->GetParent(); 234 } 235 } 236 237 238 void ViewCellsParseHandlers::EndOspInterior() 239 { 240 // go one up in the tree 241 if (mCurrentOspNode->mParent) 242 { 243 //cout << "]"; 244 mCurrentOspNode = mCurrentOspNode->mParent; 245 } 246 } 247 248 249 void ViewCellsParseHandlers::EndVspInterior() 250 { 251 // go one up in the tree 252 if (mCurrentVspNode->GetParent()) 253 { 254 //cout << "]"; 255 mCurrentVspNode = mCurrentVspNode->GetParent(); 256 } 257 } 258 259 260 void ViewCellsParseHandlers::EndViewCellInterior() 261 { 262 // go one up in the tree 263 if (mCurrentViewCell->GetParent()) 264 { 265 //cout << "]"; 266 mCurrentViewCell = mCurrentViewCell->GetParent(); 267 } 115 } 116 117 118 void ObjectsParseHandlers::EndObjectSpaceHierarchy() 119 { 120 mIsObjectSpaceHierarchy = false; 268 121 } 269 122 … … 275 128 276 129 277 void ViewCellsParseHandlers::EndViewCells() 278 { 279 // sort view cells to help associating view cells according to their id 280 stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 281 282 // not parsing view cells anymore 283 mCurrentState = PARSE_OPTIONS; 284 } 285 286 287 void ViewCellsParseHandlers::EndBoundingBoxes() 288 { 289 // all bounding boxes gathered in this step => 290 // associate object ids with bounding boxes 291 const long startTime = GetTime(); 292 293 if (mBoundingBoxConverter) 294 { 295 mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, mPvsObjects); 296 } 297 298 Debug << "\nconverted bounding boxes to objects in " 299 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 300 } 301 302 303 void ViewCellsParseHandlers::StartBspElement(string element, 304 AttributeList& attributes) 305 { 306 if (element == "Interior") 307 { 308 //cout << "["; 309 StartBspInterior(attributes); 310 } 311 312 if (element == "Leaf") 313 { 314 //cout << "l"; 315 StartBspLeaf(attributes); 316 } 317 } 318 319 320 void ViewCellsParseHandlers::StartVspElement(string element, 321 AttributeList& attributes) 322 { 323 if (element == "Interior") 324 { 325 //cout << "["; 326 StartVspInterior(attributes); 327 } 328 if (element == "Leaf") 329 { 330 //cout << "l"; 331 StartVspLeaf(attributes); 332 } 333 } 334 335 336 void ViewCellsParseHandlers::StartOspElement(string element, 337 AttributeList& attributes) 338 { 339 if (element == "Interior") 340 { 341 //cout << "["; 342 StartOspInterior(attributes); 343 } 344 345 if (element == "Leaf") 346 { 347 //cout << "l"; 348 StartOspLeaf(attributes); 349 } 350 } 351 352 353 void ViewCellsParseHandlers::StartBvhElement(string element, 354 AttributeList& attributes) 355 { 356 if (element == "Interior") 357 { 358 //cout << "["; 359 StartBvhInterior(attributes); 360 } 361 130 void ObjectsParseHandlers::StartBvhElement(string element, 131 AttributeList& attributes) 132 { 362 133 if (element == "Leaf") 363 134 { … … 368 139 369 140 370 void ViewCellsParseHandlers::StartViewSpaceHierarchyElement(const std::string &element,141 void ObjectsParseHandlers::StartObjectSpaceHierarchyElement(const std::string &element, 371 142 AttributeList& attributes) 372 143 { 373 144 //-- use cell type according to the chosen method 374 switch (mViewSpaceHierarchyType) 375 { 376 case BSP: 377 StartBspElement(element, attributes); 378 break; 379 case VSP: 380 StartVspElement(element, attributes); 381 break; 382 default: 383 Debug << "not implemented" << endl; 384 break; 385 } 386 } 387 388 389 void ViewCellsParseHandlers::StartObjectSpaceHierarchyElement(const std::string &element, 390 AttributeList& attributes) 391 { 392 //-- use cell type according to the chosen method 393 switch (mObjectSpaceHierarchyType) 394 { 395 case OSP: 396 StartOspElement(element, attributes); 397 break; 398 case BVH: 399 StartBvhElement(element, attributes); 400 break; 401 default: 402 Debug << "not implemented" << endl; 403 break; 404 } 405 } 406 407 408 void ViewCellsParseHandlers::ReplaceBvhPvs(ViewCell *vc) 409 { 410 //cout << "exchanging pvs" << endl; 411 ObjectPvs newPvs; 412 413 ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 414 415 BvhLeaf *dummyInst = new BvhLeaf(AxisAlignedBox3()); 416 417 ObjectContainer oldIntersectables; 418 419 // output PVS of view cell 420 while (pit.HasMoreEntries()) 421 { 422 ObjectPvsEntry entry = pit.Next(); 423 424 Intersectable *intersect = entry.mObject; 425 oldIntersectables.push_back(intersect); 426 427 DummyIntersectable *dummyIntersect = static_cast<DummyIntersectable *>(intersect); 428 429 const int objId = dummyIntersect->GetItem(); 430 dummyInst->SetId(objId); 431 432 vector<BvhLeaf *>::iterator oit = 433 lower_bound(mBvhLeaves.begin(), 434 mBvhLeaves.end(), 435 dummyInst, ilt); 436 437 if ((oit != mBvhLeaves.end()) && ((*oit)->GetId() == objId)) 438 { 439 // $$JB we should store a float a per object which corresponds 440 // to sumof pdfs, i.e. its relative visibility 441 // temporarily set to 1.0f 442 //cout << (*oit)->GetId() << " "; 443 444 newPvs.AddSample(*oit, 1.0f); 445 } 446 else 447 { 448 Debug << "exchangePvs error: object with id " << objId << " does not exist" << endl; 449 } 450 } 451 452 //newPvs.SimpleSort(); 453 delete dummyInst; 454 vc->SetPvs(newPvs); 455 456 CLEAR_CONTAINER(oldIntersectables); 457 } 458 459 460 void ViewCellsParseHandlers::ReplacePvs() 461 { 462 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 463 464 sort(mBvhLeaves.begin(), mBvhLeaves.end(), ilt); 465 466 //cout << "viewcells : " << mViewCells.size() << endl; 467 for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 468 { 469 ReplaceBvhPvs(*vit); 470 } 471 } 472 473 474 void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element, 475 AttributeList& attributes) 476 { 477 // interiors + leaves interpreted view cells else 478 if (element == "Interior") 479 { 480 //cout << "["; 481 StartViewCell(attributes, false); 482 } 483 484 if (element == "Leaf") 485 { 486 //cout << "l"; 487 StartViewCell(attributes, true); 488 } 489 } 490 491 492 void ViewCellsParseHandlers::startElement(const XMLCh* const name, 493 AttributeList& attributes) 145 StartBvhElement(element, attributes); 146 } 147 148 149 void ObjectsParseHandlers::startElement(const XMLCh* const name, 150 AttributeList& attributes) 494 151 { 495 152 StrX lname(name); 496 153 string element(lname.LocalForm()); 497 154 498 if (element == "ViewCells")499 {500 cout << "\nparsing view cells" << endl;501 Debug << "\nparsing view cells" << endl;502 503 mCurrentState = PARSE_VIEWCELLS;504 505 // create new view cells hierarchy506 mViewCellsTree = new ViewCellsTree();507 }508 509 // decides about the view cell hierarchy510 if (element == "ViewSpaceHierarchy")511 {512 Debug << "\nparsing view space hierarchy" << endl;513 cout << "\nparsing view space hierarchy" << endl;514 mCurrentState = PARSE_VIEWSPACE_HIERARCHY;515 StartViewSpaceHierarchy(attributes);516 }517 518 155 // decides about the view cell hierarchy 519 156 if (element == "ObjectSpaceHierarchy") … … 522 159 Debug << "\nparsing object space hierarchy" << endl; 523 160 524 mCurrentState = PARSE_OBJECTSPACE_HIERARCHY; 525 StartObjectSpaceHierarchy(attributes); 161 mIsObjectSpaceHierarchy = true; 526 162 } 527 163 528 // decides the used view cell hierarchy529 if (element == "BoundingBox")530 {531 // cout << "b";532 StartBoundingBox(attributes);533 }534 535 164 // parse view space hierarchy 536 switch (mCurrentState) 537 { 538 case PARSE_VIEWSPACE_HIERARCHY: 539 if ((++ nViewCells % 1000) == 0) 540 cout<<"\r"<<nViewCells<<" view cells parsed\r"; 541 542 StartViewSpaceHierarchyElement(element, attributes); 543 break; 544 case PARSE_OBJECTSPACE_HIERARCHY: 545 if ((++ nObjects % 1000) == 0) 546 cout<<"\r"<< nObjects <<" objects parsed\r"; 547 165 if (mIsObjectSpaceHierarchy) 166 { 548 167 StartObjectSpaceHierarchyElement(element, attributes); 549 break; 550 case PARSE_VIEWCELLS: 551 StartViewCellHierarchyElement(element, attributes); 552 break; 553 default: 554 break; 555 } 556 168 } 169 557 170 ++ mElementCount; 558 171 mAttrCount += attributes.getLength(); … … 560 173 561 174 562 void ViewCellsParseHandlers::StartViewCellPvs(ObjectPvs &pvs, const char *ptr) 563 { 564 // handle obect indices 175 176 void ObjectsParseHandlers::characters(const XMLCh* const chars, 177 const unsigned int length) 178 { 179 mCharacterCount += length; 180 } 181 182 183 void ObjectsParseHandlers::ignorableWhitespace(const XMLCh* const chars, 184 const unsigned int length) 185 { 186 mSpaceCount += length; 187 } 188 189 190 void ObjectsParseHandlers::resetDocument() 191 { 192 mAttrCount = 0; 193 mCharacterCount = 0; 194 mElementCount = 0; 195 mSpaceCount = 0; 196 } 197 198 void ObjectsParseHandlers::StartBvhLeaf(AttributeList& attributes) 199 { 200 const int len = attributes.getLength(); 201 Vector3 minBox, maxBox; 202 203 ObjectContainer objects; 204 205 for (int i = 0; i < len; ++ i) 206 { 207 string attrName(StrX(attributes.getName(i)).LocalForm()); 208 StrX attrValue(attributes.getValue(i)); 209 const char *ptr = attrValue.LocalForm(); 210 211 if (attrName == "min") 212 { 213 sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 214 } 215 if (attrName == "max") 216 { 217 sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 218 } 219 /*if (attrName == "objects") 220 { 221 StartBvhLeafObjects(objects, ptr); 222 }*/ 223 } 224 225 AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox); 226 227 BvhLeaf *leaf = new BvhLeaf(box, NULL, (int)objects.size()); 228 229 //leaf->mObjects = objects; 230 //BvHierarchy::AssociateObjectsWithLeaf(leaf); 231 232 // new pvs object 233 mPvsObjects.push_back(leaf); 234 } 235 236 237 void ObjectsParseHandlers::StartBvhLeafObjects(ObjectContainer &objects, 238 const char *ptr) 239 { 565 240 vector<int> objIndices; 566 241 char *endptr; 567 242 568 243 while (1) 569 { // read object ids244 { 570 245 const int index = strtol(ptr, &endptr, 10); 571 if (ptr == endptr) 572 break; 246 if (ptr == endptr) break; 247 573 248 objIndices.push_back(index); 574 249 ptr = endptr; 575 250 } 576 251 577 // TODO:578 // 1) find objects and add them to pvs579 // 2) get view cell with specified id580 252 MeshInstance dummyInst(NULL); 581 253 582 254 vector<int>::const_iterator it, it_end = objIndices.end(); 255 583 256 for (it = objIndices.begin(); it != it_end; ++ it) 584 257 { 585 #if PVS_HACK586 //cout << "u";587 pvs.AddSample(new DummyIntersectable(*it), 1);588 #else589 258 const int objId = *it; 590 259 dummyInst.SetId(objId); 591 260 592 ObjectContainer::iterator oit = 593 lower_bound(mPvsObjects.begin(), 594 mPvsObjects.end(), 595 (Intersectable *)&dummyInst, ilt); 596 597 if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) 598 { 599 // $$JB we should store a float a per object which corresponds 600 // to sumof pdfs, i.e. its relative visibility 601 // temporarily set to 1.0f 602 pvs.AddSample(*oit, 1.0f); 603 //Debug << "y"; 604 } 605 else 606 { 607 Debug << "x"; 608 //Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl; 609 } 610 #endif 611 } 612 } 613 614 615 void ViewCellsParseHandlers::StartViewSpaceHierarchy(AttributeList& attributes) 616 { 617 int len = attributes.getLength(); 618 619 Vector3 bmin, bmax; 620 621 for (int i = 0; i < len; ++ i) 622 { 623 string attrName(StrX(attributes.getName(i)).LocalForm()); 624 StrX attrValue(attributes.getValue(i)); 625 const char *ptr = attrValue.LocalForm(); 626 627 // hierarchy type 628 if (attrName == "type") 629 { 630 if (strcmp(ptr, "bsp") == 0) 631 { 632 Debug << "\nview space hierarchy: Bsp" << endl; 633 mViewSpaceHierarchyType = BSP; 634 } 635 else if (strcmp(ptr, "vsp") == 0) 636 { 637 Debug << "\nview space hierarchy: Vsp" << endl; 638 mViewSpaceHierarchyType = VSP; 639 } 640 } 641 else if (attrName == "min") // the view space extent 642 { 643 sscanf(ptr, "%f %f %f", 644 &bmin.x, &bmin.y, &bmin.z); 645 } 646 else if (attrName == "max") 647 { 648 sscanf(ptr, "%f %f %f", 649 &bmax.x, &bmax.y, &bmax.z); 650 } 651 } 652 653 mViewSpaceBox = AxisAlignedBox3(bmin, bmax); 654 655 // create the hierarchy based on this information 656 CreateViewSpaceHierarchy(); 657 } 658 659 660 void ViewCellsParseHandlers::StartObjectSpaceHierarchy(AttributeList& attributes) 661 { 662 const int len = attributes.getLength(); 663 Vector3 bmin, bmax; 664 665 for (int i = 0; i < len; ++ i) 666 { 667 string attrName(StrX(attributes.getName(i)).LocalForm()); 668 StrX attrValue(attributes.getValue(i)); 669 const char *ptr = attrValue.LocalForm(); 670 671 // hierarchy type 672 if (attrName == "type") 673 { 674 if (strcmp(ptr, "osp") == 0) 675 { 676 Debug << "\nobject space hierarchy: Osp" << endl; 677 678 mHierarchyManager = 679 new HierarchyManager(HierarchyManager::KD_BASED_OBJ_SUBDIV); 680 681 DEL_PTR(mHierarchyManager->mVspTree); 682 mHierarchyManager->mVspTree = mVspTree; 683 684 mObjectSpaceHierarchyType = OSP; 685 686 //std::stable_sort(objects.begin(), objects.end(), ilt); 687 mHierarchyManager->mOspTree->mBoundingBox.Initialize(); 688 ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end(); 689 690 //-- compute bounding box 691 for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit) 692 { 693 Intersectable *obj = *oit; 694 // compute bounding box of view space 695 mHierarchyManager->mOspTree->mBoundingBox.Include(obj->GetBox()); 696 } 697 } 698 else if (strcmp(ptr, "bvh") == 0) 699 { 700 Debug << "\nobject space hierarchy: Bvh" << endl; 701 mObjectSpaceHierarchyType = BVH; 702 mHierarchyManager = 703 new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV); 704 705 DEL_PTR(mHierarchyManager->mVspTree); 706 mHierarchyManager->mVspTree = mVspTree; 707 } 708 } 709 } 710 } 711 712 713 void ViewCellsParseHandlers::StartBoundingBox(AttributeList& attributes) 714 { 715 int len = attributes.getLength(); 716 717 Vector3 bmin, bmax; 718 int id; 719 720 for (int i = 0; i < len; ++ i) 721 { 722 string attrName(StrX(attributes.getName(i)).LocalForm()); 723 StrX attrValue(attributes.getValue(i)); 724 const char *ptr = attrValue.LocalForm(); 725 726 if (attrName == "id") 727 { 728 sscanf(ptr, "%d", &id); 729 } 730 if (attrName == "min") 731 { 732 sscanf(ptr, "%f %f %f", &bmin.x, &bmin.y, &bmin.z); 733 } 734 else if (attrName == "max") 735 { 736 sscanf(ptr, "%f %f %f", &bmax.x, &bmax.y, &bmax.z); 737 } 738 } 739 740 AxisAlignedBox3 box(bmin, bmax); 741 mIBoundingBoxes.push_back(IndexedBoundingBox(id, box)); 742 //Debug << "bbox: " << box << endl; 743 } 744 745 746 void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes) 747 { 748 BspLeaf * leaf; 749 750 if (mCurrentBspNode) // replace front or (if not NULL) back child 751 { 752 BspInterior *interior = static_cast<BspInterior *>(mCurrentBspNode); 753 754 leaf = new BspLeaf(interior); 755 interior->ReplaceChildLink(NULL, leaf); 756 } 757 else 758 { 759 leaf = new BspLeaf(); 760 mVspBspTree->mRoot = leaf; 761 } 762 763 /////////// 764 //-- find associated view cell 765 766 int viewCellId; 767 const int len = attributes.getLength(); 768 769 for (int i = 0; i < len; ++ i) 770 { 771 string attrName(StrX(attributes.getName(i)).LocalForm()); 772 StrX attrValue(attributes.getValue(i)); 773 774 const char *ptr = attrValue.LocalForm(); 775 char *endptr = NULL; 776 777 if (attrName == "viewCellId") 778 { 779 viewCellId = strtol(ptr, &endptr, 10); 780 } 781 } 782 783 if (viewCellId >= 0) // valid view cell found 784 { 785 // TODO: get view cell with specified id 786 ViewCellInterior dummyVc; 787 dummyVc.SetId(viewCellId); 788 789 ViewCellContainer::iterator vit = 790 lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 791 792 //ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 793 // BspViewCell *viewCell = static_cast<BspViewCell *>((*vit).second); 794 795 BspViewCell *viewCell = static_cast<BspViewCell *>(*vit); 796 if (viewCell->GetId() == viewCellId) 797 { 798 // create new view cell for bsp nodes 799 leaf->SetViewCell(viewCell); 800 viewCell->mLeaves.push_back(leaf); 801 } 802 else 803 { 804 cerr << "error: view cell does not exist" << endl; 805 } 806 } 807 else 808 { 809 // add to invalid view space 810 leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); 811 leaf->SetTreeValid(false); 812 mVspBspTree->PropagateUpValidity(leaf); 813 } 814 } 815 816 817 void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes) 818 { 819 Plane3 plane; 820 int len = attributes.getLength(); 821 822 for (int i = 0; i < len; ++ i) 823 { 824 string attrName(StrX(attributes.getName(i)).LocalForm()); 825 StrX attrValue(attributes.getValue(i)); 826 const char *ptr = attrValue.LocalForm(); 827 828 if (attrName == "plane") 829 { 830 sscanf(ptr, "%f %f %f %f", 831 &plane.mNormal.x, &plane.mNormal.y, &plane.mNormal.z, &plane.mD); 832 } 833 } 834 835 BspInterior* interior = new BspInterior(plane); 836 837 if (mCurrentBspNode) // replace NULL child of parent with current node 838 { 839 BspInterior *parent = static_cast<BspInterior *>(mCurrentBspNode); 840 841 parent->ReplaceChildLink(NULL, interior); 842 interior->SetParent(parent); 843 } 844 else 845 { 846 mVspBspTree->mRoot = interior; 847 } 848 849 mCurrentBspNode = interior; 850 } 851 852 853 void ViewCellsParseHandlers::StartViewCell(AttributeList& attributes, const bool isLeaf) 854 { 855 ViewCell *viewCell = NULL; 856 857 const int len = attributes.getLength(); 858 float mergeCost; 859 860 if (isLeaf) 861 { 862 viewCell = new ViewCellLeaf(); 863 } 864 else 865 { 866 viewCell = new ViewCellInterior(); 867 } 868 869 for (int i = 0; i < len; ++ i) 870 { 871 const string attrName(StrX(attributes.getName(i)).LocalForm()); 872 873 if (attrName == "id") 874 { 875 const StrX attrValue(attributes.getValue(i)); 876 const char *ptr = attrValue.LocalForm(); 877 char *endptr = NULL; 878 const int id = strtol(ptr, &endptr, 10); 879 880 // create new view cell, otherwise use reference. 881 viewCell->SetId(id); 882 883 if (mCurrentViewCell) // replace front or (if not NULL) back child 884 { 885 ViewCellInterior *interior = 886 static_cast<ViewCellInterior *>(mCurrentViewCell); 887 interior->SetupChildLink(viewCell); 888 } 889 else 890 { // set the new root 891 mViewCellsTree->SetRoot(viewCell); 892 } 893 894 if (!isLeaf) 895 { 896 mCurrentViewCell = viewCell; 897 } 898 } 899 if (attrName == "pvs") 900 { 901 StrX attrValue(attributes.getValue(i)); 902 const char *ptr = attrValue.LocalForm(); 903 904 // note: id must come before pvs! 905 // otherwise view cell is undefined 906 907 // hack: assume that view cell comes before pvs 908 StartViewCellPvs(viewCell->GetPvs(), ptr); 909 //StartViewCellPvs(pvs, ptr); 910 } 911 else if (attrName == "active") 912 { 913 StrX attrValue(attributes.getValue(i)); 914 const char *ptr = attrValue.LocalForm(); 915 char *endptr = NULL; 916 const bool isActive = (bool)strtol(ptr, &endptr, 10); 917 918 if (isActive) 919 { 920 // TODO 921 } 922 } 923 else if (attrName == "mergecost") 924 { 925 StrX attrValue(attributes.getValue(i)); 926 927 const char *ptr = attrValue.LocalForm(); 928 char *endptr = NULL; 929 mergeCost = (float)strtod(ptr, &endptr); 930 } 931 } 932 933 viewCell->SetMergeCost(mergeCost); 934 //viewCell->SetPvs(pvs); 935 mViewCells.push_back(viewCell); 936 } 937 938 939 void ViewCellsParseHandlers::CreateViewSpaceHierarchy() 940 { 941 if (mViewSpaceHierarchyType == BSP) 942 { 943 Debug << "hierarchy type: Bsp" << endl; 944 mVspBspTree = new VspBspTree(); 945 946 // set view space box 947 mVspBspTree->mBoundingBox = mViewSpaceBox; 948 949 //ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 950 ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 951 952 int i = 0; 953 // remove view cells and exchange them with the 954 // view cells specialized for the current hierarchy node type 955 for (vit = mViewCells.begin(); vit != vit_end; ++ vit, ++ i) 956 { 957 //if ((i % 1000) == 0) 958 // Debug << "\n exchanged " << i << " boxes" << endl; 959 ViewCell *vc = (*vit); 960 961 if (!vc->IsLeaf()) // exchange only leaves 962 continue; 963 964 BspViewCell *bspVc = new BspViewCell(); 965 966 bspVc->SetId(vc->GetId()); 967 //bspVc->GetPvs().reserve(vc->GetPvs().size()); 968 bspVc->SetPvs(vc->GetPvs()); 969 970 if (vc->IsRoot()) 971 { 972 mViewCellsTree->mRoot = bspVc; 973 } 974 else 975 { 976 vc->GetParent()->ReplaceChildLink(vc, bspVc); 977 } 978 979 // delete old view cell 980 DEL_PTR(vc); 981 982 // (*vit).second = bspVc; 983 (*vit) = bspVc; 984 } 985 cout << "finished creating view space hierarchy" << endl; 986 } 987 else if (mViewSpaceHierarchyType == VSP) 988 { 989 Debug << "hierarchy type: Vsp" << endl; 990 mVspTree = new VspTree(); 991 992 // set view space box 993 mVspTree->mBoundingBox = mViewSpaceBox; 994 995 // ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 996 ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 997 998 // reset view cells using the current node type 999 for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 1000 { 1001 //ViewCell *vc = (*vit).second; 1002 ViewCell *vc = (*vit); 1003 1004 if (!vc->IsLeaf()) // exchange only leaves 1005 continue; 1006 1007 VspViewCell *vspVc = new VspViewCell(); 1008 1009 vspVc->SetPvs(vc->GetPvs()); 1010 vspVc->SetId(vc->GetId()); 1011 1012 if (vc->IsRoot()) 1013 { 1014 mViewCellsTree->mRoot = vspVc; 1015 } 1016 else 1017 { 1018 vc->GetParent()->ReplaceChildLink(vc, vspVc); 1019 } 1020 1021 // exchange view cell with new one 1022 DEL_PTR(vc); 1023 1024 //(*vit).second = vspVc; 1025 (*vit) = vspVc; 1026 } 1027 1028 if (mHierarchyManager) 1029 { 1030 // come here only if object space hierarchy already constructed 1031 mHierarchyManager->mVspTree = mVspTree; 1032 mVspTree->mHierarchyManager = mHierarchyManager; 1033 } 1034 } 1035 } 1036 1037 1038 void ViewCellsParseHandlers::CreateViewCellsManager() 1039 { 1040 if (mViewSpaceHierarchyType == BSP) 1041 { 1042 Debug << "\ncreating view cells manager: VspBsp" << endl; 1043 mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree); 1044 } 1045 else if (mViewSpaceHierarchyType == VSP) 1046 { 1047 Debug << "\ncreating view cells manager: VspOsp" << endl; 1048 mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager); 1049 } 1050 1051 mViewCellsManager->SetViewSpaceBox(mViewSpaceBox); 1052 } 1053 1054 1055 void ViewCellsParseHandlers::characters(const XMLCh* const chars, 1056 const unsigned int length) 1057 { 1058 mCharacterCount += length; 1059 } 1060 1061 1062 void ViewCellsParseHandlers::ignorableWhitespace(const XMLCh* const chars, 1063 const unsigned int length) 1064 { 1065 mSpaceCount += length; 1066 } 1067 1068 1069 void ViewCellsParseHandlers::resetDocument() 1070 { 1071 mAttrCount = 0; 1072 mCharacterCount = 0; 1073 mElementCount = 0; 1074 mSpaceCount = 0; 1075 } 1076 1077 1078 void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes) 1079 { 1080 VspLeaf * leaf; 1081 1082 if (mCurrentVspNode) // replace front or (if not NULL) back child 1083 { 1084 VspInterior *interior = static_cast<VspInterior *>(mCurrentVspNode); 1085 leaf = new VspLeaf(interior); 1086 interior->ReplaceChildLink(NULL, leaf); 1087 } 1088 else 1089 { 1090 leaf = new VspLeaf(); 1091 mVspTree->mRoot = leaf; 1092 } 1093 1094 ///////////// 1095 //-- find view cell associated with the id 1096 1097 int viewCellId; 1098 const int len = attributes.getLength(); 1099 1100 for (int i = 0; i < len; ++ i) 1101 { 1102 string attrName(StrX(attributes.getName(i)).LocalForm()); 1103 StrX attrValue(attributes.getValue(i)); 1104 1105 const char *ptr = attrValue.LocalForm(); 1106 char *endptr = NULL; 1107 1108 if (attrName == "viewCellId") 1109 { 1110 viewCellId = strtol(ptr, &endptr, 10); 1111 } 1112 } 1113 1114 if (viewCellId >= 0) // valid view cell found 1115 { 1116 // TODO: get view cell with specified id 1117 ViewCellInterior dummyVc; 1118 dummyVc.SetId(viewCellId); 1119 1120 ViewCellContainer::iterator vit = 1121 lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 1122 1123 //ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 1124 if (vit == mViewCells.end()) 1125 Debug << "error: view cell " << viewCellId << " not found" << endl; 1126 1127 //VspViewCell *viewCell = static_cast<VspViewCell *>((*vit).second); 1128 VspViewCell *viewCell = static_cast<VspViewCell *>(*vit); 1129 1130 if (viewCell->GetId() == viewCellId) 1131 { 1132 leaf->SetViewCell(viewCell); 1133 viewCell->mLeaves.push_back(leaf); 1134 } 1135 else 1136 { 1137 Debug << "error: view cell does not exist" << endl; 1138 } 1139 } 1140 else 1141 { 1142 // add to invalid view space 1143 leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell()); 1144 leaf->SetTreeValid(false); 1145 mVspTree->PropagateUpValidity(leaf); 1146 } 1147 } 1148 1149 1150 void ViewCellsParseHandlers::StartVspInterior(AttributeList& attributes) 1151 { 1152 AxisAlignedPlane plane; 1153 const int len = attributes.getLength(); 1154 1155 for (int i = 0; i < len; ++ i) 1156 { 1157 string attrName(StrX(attributes.getName(i)).LocalForm()); 1158 StrX attrValue(attributes.getValue(i)); 1159 const char *ptr = attrValue.LocalForm(); 1160 1161 if (attrName == "plane") 1162 { 1163 sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis); 1164 } 1165 } 1166 1167 VspInterior* interior = new VspInterior(plane); 1168 1169 if (mCurrentVspNode) // replace NULL child of parent with current node 1170 { 1171 VspInterior *parent = static_cast<VspInterior *>(mCurrentVspNode); 1172 1173 parent->ReplaceChildLink(NULL, interior); 1174 interior->SetParent(parent); 1175 1176 AxisAlignedBox3 frontBox, backBox; 1177 1178 parent->GetBoundingBox().Split( 1179 parent->GetPlane().mAxis, 1180 parent->GetPlane().mPosition, 1181 frontBox, 1182 backBox); 1183 1184 if (parent->GetFront() == interior) 1185 interior->SetBoundingBox(frontBox); 1186 else 1187 interior->SetBoundingBox(backBox); 1188 } 1189 else 1190 { 1191 mVspTree->mRoot = interior; 1192 interior->SetBoundingBox(mVspTree->GetBoundingBox()); 1193 } 1194 1195 mCurrentVspNode = interior; 1196 } 1197 1198 1199 void ViewCellsParseHandlers::StartOspInterior(AttributeList& attributes) 1200 { 1201 AxisAlignedPlane plane; 1202 int len = attributes.getLength(); 1203 1204 for (int i = 0; i < len; ++ i) 1205 { 1206 string attrName(StrX(attributes.getName(i)).LocalForm()); 1207 StrX attrValue(attributes.getValue(i)); 1208 const char *ptr = attrValue.LocalForm(); 1209 1210 if (attrName == "plane") 1211 { 1212 sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis); 1213 } 1214 } 1215 1216 KdInterior* interior = new KdInterior(NULL); 1217 1218 interior->mAxis = plane.mAxis; 1219 interior->mPosition = plane.mPosition; 1220 1221 if (mCurrentOspNode) // replace NULL child of parent with current node 1222 { 1223 KdInterior *parent = static_cast<KdInterior *>(mCurrentOspNode); 1224 parent->ReplaceChildLink(NULL, interior); 1225 interior->mParent = parent; 1226 1227 AxisAlignedBox3 frontBox, backBox; 1228 1229 parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox); 1230 1231 if (parent->mFront == interior) 1232 interior->mBox = frontBox; 1233 else 1234 interior->mBox = backBox; 1235 } 1236 else 1237 { 1238 mHierarchyManager->mOspTree->mRoot = interior; 1239 interior->mBox = mHierarchyManager->mOspTree->mBoundingBox; 1240 } 1241 1242 mCurrentOspNode = interior; 1243 } 1244 1245 1246 void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes) 1247 { 1248 KdLeaf * leaf = new KdLeaf(static_cast<KdInterior *>(mCurrentOspNode), NULL); 1249 1250 if (mCurrentOspNode) 1251 { 1252 // replace front or (if not NULL) back child 1253 static_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf); 1254 } 1255 else 1256 { 1257 mHierarchyManager->mOspTree->mRoot = leaf; 1258 } 1259 } 1260 1261 1262 void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes) 1263 { 1264 const int len = attributes.getLength(); 1265 Vector3 minBox, maxBox; 1266 1267 ObjectContainer objects; 1268 1269 for (int i = 0; i < len; ++ i) 1270 { 1271 string attrName(StrX(attributes.getName(i)).LocalForm()); 1272 StrX attrValue(attributes.getValue(i)); 1273 const char *ptr = attrValue.LocalForm(); 1274 1275 if (attrName == "min") 1276 { 1277 sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 1278 } 1279 if (attrName == "max") 1280 { 1281 sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 1282 } 1283 if (attrName == "objects") 1284 { 1285 StartBvhLeafObjects(objects, ptr); 1286 } 1287 } 1288 1289 AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox); 1290 1291 BvhLeaf *leaf; 1292 1293 if (mCurrentBvhNode) // replace front or (if not NULL) back child 1294 { 1295 BvhInterior *interior = static_cast<BvhInterior *>(mCurrentBvhNode); 1296 leaf = new BvhLeaf(box, interior, (int)objects.size()); 1297 interior->ReplaceChildLink(NULL, leaf); 1298 } 1299 else 1300 { 1301 leaf = new BvhLeaf(box, NULL, (int)objects.size()); 1302 mHierarchyManager->mBvHierarchy->mRoot = leaf; 1303 } 1304 1305 leaf->mObjects = objects; 1306 BvHierarchy::AssociateObjectsWithLeaf(leaf); 1307 1308 if (PVS_HACK) 1309 { 1310 if (0) // Temp matt: should already have right id 1311 leaf->SetId((int)mBvhLeaves.size()); 1312 1313 mBvhLeaves.push_back(leaf); 1314 } 1315 } 1316 1317 1318 void ViewCellsParseHandlers::StartBvhLeafObjects(ObjectContainer &objects, 1319 const char *ptr) 1320 { 1321 vector<int> objIndices; 1322 char *endptr; 1323 1324 while (1) 1325 { 1326 const int index = strtol(ptr, &endptr, 10); 1327 if (ptr == endptr) break; 1328 1329 objIndices.push_back(index); 1330 ptr = endptr; 1331 } 1332 1333 MeshInstance dummyInst(NULL); 1334 1335 vector<int>::const_iterator it, it_end = objIndices.end(); 1336 1337 for (it = objIndices.begin(); it != it_end; ++ it) 1338 { 1339 const int objId = *it; 1340 dummyInst.SetId(objId); 1341 1342 ObjectContainer::iterator oit = 1343 lower_bound(mPvsObjects.begin(), 1344 mPvsObjects.end(), 261 ObjectContainer::const_iterator oit = 262 lower_bound(mPreprocessorObjects.begin(), 263 mPreprocessorObjects.end(), 1345 264 (Intersectable *)&dummyInst, 1346 265 ilt); 1347 266 1348 if ((oit != mP vsObjects.end()) && ((*oit)->GetId() == objId))267 if ((oit != mPreprocessorObjects.end()) && ((*oit)->GetId() == objId)) 1349 268 { 1350 269 objects.push_back(*oit); … … 1360 279 1361 280 1362 void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes)1363 {1364 const int len = attributes.getLength();1365 Vector3 minBox, maxBox;1366 1367 for (int i = 0; i < len; ++ i)1368 {1369 string attrName(StrX(attributes.getName(i)).LocalForm());1370 StrX attrValue(attributes.getValue(i));1371 const char *ptr = attrValue.LocalForm();1372 1373 if (attrName == "min")1374 {1375 sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z);1376 }1377 if (attrName == "max")1378 {1379 sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z);1380 }1381 }1382 1383 BvhInterior* interior = new BvhInterior(AxisAlignedBox3(minBox, maxBox));1384 1385 if (mCurrentBvhNode) // replace NULL child of parent with current node1386 {1387 BvhInterior *parent = static_cast<BvhInterior *>(mCurrentBvhNode);1388 parent->ReplaceChildLink(NULL, interior);1389 interior->SetParent(parent);1390 }1391 else1392 {1393 mHierarchyManager->mBvHierarchy->mRoot = interior;1394 }1395 1396 mCurrentBvhNode = interior;1397 }1398 1399 281 1400 282 // --------------------------------------------------------------------------- … … 1404 286 1405 287 void 1406 ViewCellsParseHandlers::error(const SAXParseException& e)288 ObjectsParseHandlers::error(const SAXParseException& e) 1407 289 { 1408 290 XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId()) … … 1413 295 1414 296 void 1415 ViewCellsParseHandlers::fatalError(const SAXParseException& e)297 ObjectsParseHandlers::fatalError(const SAXParseException& e) 1416 298 { 1417 299 XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId()) … … 1422 304 1423 305 void 1424 ViewCellsParseHandlers::warning(const SAXParseException& e)306 ObjectsParseHandlers::warning(const SAXParseException& e) 1425 307 { 1426 308 XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId()) … … 1431 313 1432 314 1433 bool ViewCellsParser::ParseViewCellsFile(const string &filename, 1434 ViewCellsManager **viewCells, 1435 ObjectContainer &pvsObjects, 1436 ObjectContainer &preprocessorObjects, 1437 BoundingBoxConverter *bconverter) 1438 { 1439 // Initialize the XML4C system 1440 try { 1441 XMLPlatformUtils::Initialize(); 1442 } 1443 1444 catch (const XMLException& toCatch) 1445 { 1446 XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" 1447 << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; 1448 return false; 1449 } 1450 1451 // cout<<"parsing started"<<endl<<flush; 1452 1453 // 1454 // Create a SAX parser object. Then, according to what we were told on 1455 // the command line, set the options. 1456 // 1457 SAXParser* parser = new SAXParser; 1458 parser->setValidationScheme(valScheme); 1459 parser->setDoNamespaces(doNamespaces); 1460 parser->setDoSchema(doSchema); 1461 parser->setValidationSchemaFullChecking(schemaFullChecking); 1462 1463 1464 // 1465 // Create our SAX handler object and install it on the parser, as the 1466 // document and error handler. We are responsible for cleaning them 1467 // up, but since its just stack based here, there's nothing special 1468 // to do. 1469 // 1470 ViewCellsParseHandlers handler(pvsObjects, preprocessorObjects, bconverter); 1471 parser->setDocumentHandler(&handler); 1472 parser->setErrorHandler(&handler); 1473 1474 unsigned long duration; 1475 int errorCount = 0; 1476 // create a faux scope so that 'src' destructor is called before 1477 // XMLPlatformUtils::Terminate 1478 { 1479 // 1480 // Kick off the parse and catch any exceptions. Create a standard 1481 // input input source and tell the parser to parse from that. 1482 // 1483 // StdInInputSource src; 1484 try 1485 { 1486 const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); 315 bool ObjectsParser::ParseObjects(const string &filename, 316 ObjectContainer &pvsObjects, 317 const ObjectContainer &preprocessorObjects) 318 { 319 // Initialize the XML4C system 320 try { 321 XMLPlatformUtils::Initialize(); 322 } 323 324 catch (const XMLException& toCatch) 325 { 326 XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" 327 << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; 328 return false; 329 } 330 331 // cout<<"parsing started"<<endl<<flush; 332 333 // 334 // Create a SAX parser object. Then, according to what we were told on 335 // the command line, set the options. 336 // 337 SAXParser* parser = new SAXParser; 338 parser->setValidationScheme(valScheme); 339 parser->setDoNamespaces(doNamespaces); 340 parser->setDoSchema(doSchema); 341 parser->setValidationSchemaFullChecking(schemaFullChecking); 342 343 344 // 345 // Create our SAX handler object and install it on the parser, as the 346 // document and error handler. We are responsible for cleaning them 347 // up, but since its just stack based here, there's nothing special 348 // to do. 349 // 350 ObjectsParseHandlers handler(pvsObjects, preprocessorObjects); 351 parser->setDocumentHandler(&handler); 352 parser->setErrorHandler(&handler); 353 354 unsigned long duration; 355 int errorCount = 0; 356 // create a faux scope so that 'src' destructor is called before 357 // XMLPlatformUtils::Terminate 358 { 359 // 360 // Kick off the parse and catch any exceptions. Create a standard 361 // input input source and tell the parser to parse from that. 362 // 363 // StdInInputSource src; 364 try 365 { 366 const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); 1487 367 1488 368 #if USE_GZLIB 1489 XMLCh *myFilePath = XMLString::transcode(filename.c_str());1490 1491 GzFileInputSource isource(myFilePath);1492 parser->parse(isource);369 XMLCh *myFilePath = XMLString::transcode(filename.c_str()); 370 371 GzFileInputSource isource(myFilePath); 372 parser->parse(isource); 1493 373 #else 1494 parser->parse(filename.c_str());374 parser->parse(filename.c_str()); 1495 375 1496 376 #endif 1497 377 1498 if (1 && PVS_HACK) 1499 handler.ReplacePvs(); 1500 1501 const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); 1502 duration = endMillis - startMillis; 1503 errorCount = parser->getErrorCount(); 1504 } 1505 catch (const OutOfMemoryException&) 1506 { 1507 XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; 1508 errorCount = 2; 1509 return false; 1510 } 1511 catch (const XMLException& e) 1512 { 378 const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); 379 duration = endMillis - startMillis; 380 errorCount = parser->getErrorCount(); 381 } 382 catch (const OutOfMemoryException&) 383 { 384 XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; 385 errorCount = 2; 386 return false; 387 } 388 catch (const XMLException& e) 389 { 1513 390 XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n" 1514 1515 391 << StrX(e.getMessage()) 392 << "\n" << XERCES_STD_QUALIFIER endl; 1516 393 errorCount = 1; 1517 394 return false; 1518 } 1519 1520 1521 // Print out the stats that we collected and time taken 1522 if (!errorCount) { 1523 XERCES_STD_QUALIFIER cerr << filename << ": " << duration << " ms (" 395 } 396 397 398 // Print out the stats that we collected and time taken 399 if (!errorCount) 400 { 401 XERCES_STD_QUALIFIER cerr << filename << ": " << duration << " ms (" 1524 402 << handler.GetElementCount() << " elems, " 1525 403 << handler.GetAttrCount() << " attrs, " 1526 404 << handler.GetSpaceCount() << " spaces, " 1527 405 << handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; 1528 1529 1530 1531 cout<<"parsed - will delete the parser"<<endl<<flush;1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 } 1547 1548 } 406 } 407 } 408 409 cout << "parsed - will delete the parser" << endl << flush; 410 // 411 // Delete the parser itself. Must be done prior to calling Terminate, below. 412 // 413 delete parser; 414 415 XMLPlatformUtils::Terminate(); 416 417 //-- assign new view cells manager 418 //*viewCells = handler.mViewCellsManager; 419 420 if (errorCount > 0) 421 return false; 422 else 423 return true; 424 } 425 426 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.h
r2113 r2115 1 #ifndef __ VIEWCELLSDPARSER_H2 #define __ VIEWCELLSDPARSER_H1 #ifndef __OBJECTSPARSER_H 2 #define __OBJECTSPARSER_H 3 3 4 4 #include "Parser.h" … … 12 12 class Environment; 13 13 14 class ViewCellsParser: public Parser14 class ObjectsParser: public Parser 15 15 { 16 16 public: 17 ViewCellsParser():Parser() {}17 ObjectsParser(): Parser() {} 18 18 19 bool ParseViewCellsFile(const string &filename, 20 ViewCellsManager **viewCells, 21 ObjectContainer &pvsObjects, 22 ObjectContainer &preprocessorObjects, 23 BoundingBoxConverter *bconverter); 19 bool ParseObjects(const string &filename, 20 ObjectContainer &pvsObjects, 21 const ObjectContainer &preprocessorObjects); 24 22 }; 25 23 -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParserXerces.h
r2114 r2115 1 #ifndef _ X3D_PARSER_XERCES__H2 #define _ X3D_PARSER_XERCES__H1 #ifndef _OBJECTS_PARSER_XERCES__H 2 #define _OBJECTS_PARSER_XERCES__H 3 3 4 4 // --------------------------------------------------------------------------- … … 17 17 XERCES_CPP_NAMESPACE_END 18 18 19 class VspBspTree; 20 class BspTree; 21 class ViewCellsManager; 22 class ViewCellsTree; 23 class VspTree; 24 class OspTree; 25 class VspNode; 19 26 20 class BvhNode; 27 21 class BvHierarchy; 28 class HierarchyManager;29 22 30 23 … … 32 25 { 33 26 public: 34 // ----------------------------------------------------------------------- 35 // Constructors and Destructor 36 // ----------------------------------------------------------------------- 37 ObjectsParseHandlers(ObjectContainer &pvsObjects, 38 ObjectContainer &preprocessorObjects, 39 BoundingBoxConverter *bconverter); 40 ~ObjectsParseHandlers(); 41 42 43 // ----------------------------------------------------------------------- 44 // Getter methods 45 // ----------------------------------------------------------------------- 46 unsigned int GetElementCount() 47 { 48 return mElementCount; 49 } 50 51 unsigned int GetAttrCount() 52 { 53 return mAttrCount; 54 } 55 56 unsigned int GetCharacterCount() 57 { 58 return mCharacterCount; 59 } 60 61 unsigned int GetSpaceCount() 62 { 63 return mSpaceCount; 64 } 27 28 // ----------------------------------------------------------------------- 29 // Constructors and Destructor 30 // ----------------------------------------------------------------------- 31 32 ObjectsParseHandlers(ObjectContainer &pvsObjects, 33 const ObjectContainer &preprocessorObjects); 34 35 ~ObjectsParseHandlers(); 65 36 66 37 67 // ----------------------------------------------------------------------- 68 // Handlers for the SAX DocumentHandler interface 69 // ----------------------------------------------------------------------- 70 void endElement(const XMLCh* const name); 71 void startElement(const XMLCh* const name, AttributeList& attributes); 72 void characters(const XMLCh* const chars, const unsigned int length); 73 void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); 74 void resetDocument(); 38 // ----------------------------------------------------------------------- 39 // Getter methods 40 // ----------------------------------------------------------------------- 75 41 76 ///////////////////////// 42 unsigned int GetElementCount() 43 { 44 return mElementCount; 45 } 77 46 78 int mUniqueObjectId; 79 vector<BvhLeaf *> mBvhLeaves; 80 ObjectContainer &mPreprocessorObjects; 47 unsigned int GetAttrCount() 48 { 49 return mAttrCount; 50 } 81 51 82 /// current state of the parser 83 int mCurrentState; 84 85 enum {, BVH}; 52 unsigned int GetCharacterCount() 53 { 54 return mCharacterCount; 55 } 86 56 87 int mViewSpaceHierarchyType; 88 int mObjectSpaceHierarchyType; 89 int nViewCells; 90 int nObjects; 91 92 93 //////////////////////////////// 57 unsigned int GetSpaceCount() 58 { 59 return mSpaceCount; 60 } 94 61 95 62 96 // Handlers for X3D 97 98 void StartObjectSpaceHierarchy(AttributeList& attributes); 63 // ----------------------------------------------------------------------- 64 // Handlers for the SAX DocumentHandler interface 65 // ----------------------------------------------------------------------- 99 66 100 void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes); 67 void endElement(const XMLCh* const name); 68 void startElement(const XMLCh* const name, AttributeList& attributes); 69 void characters(const XMLCh* const chars, const unsigned int length); 70 void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); 71 void resetDocument(); 101 72 102 void StartBvhLeaf(AttributeList& attributes); 103 void StartBvhInterior(AttributeList& attributes); 104 void StartBvhElement(string element, AttributeList& attributes); 73 void StartObjectSpaceHierarchyElement(const std::string &element, 74 AttributeList& attributes); 105 75 106 void EndObjectSpaceHierarchyInterior(); 76 ///////////////////////// 107 77 108 void EndBvhInterior(); 109 void EndOspInterior(); 78 int mUniqueObjectId; 110 79 111 void EndObjectSpaceHierarchy();80 vector<BvhLeaf *> mBvhLeaves; 112 81 113 void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr); 82 const ObjectContainer &mPreprocessorObjects; 83 ObjectContainer &mPvsObjects; 114 84 115 // ----------------------------------------------------------------------- 116 // Handlers for the SAX ErrorHandler interface 117 // ----------------------------------------------------------------------- 85 /// current state of the parser 86 bool mIsObjectSpaceHierarchy; 118 87 119 void warning(const SAXParseException& exc); 120 void error(const SAXParseException& exc); 121 void fatalError(const SAXParseException& exc); 122 123 88 enum {BVH}; 89 90 //////////// 91 //-- Handlers for X3D 92 93 void StartBvhLeaf(AttributeList& attributes); 94 void StartBvhElement(string element, AttributeList& attributes); 95 96 void EndObjectSpaceHierarchy(); 97 98 void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr); 99 100 // ----------------------------------------------------------------------- 101 // Handlers for the SAX ErrorHandler interface 102 // ----------------------------------------------------------------------- 103 104 void warning(const SAXParseException& exc); 105 void error(const SAXParseException& exc); 106 void fatalError(const SAXParseException& exc); 107 108 124 109 private: 125 126 127 128 129 130 131 132 133 134 135 136 137 138 110 // ----------------------------------------------------------------------- 111 // Private data members 112 // 113 // fAttrCount 114 // fCharacterCount 115 // fElementCount 116 // fSpaceCount 117 // These are just counters that are run upwards based on the input 118 // from the document handlers. 119 // ----------------------------------------------------------------------- 120 unsigned int mAttrCount; 121 unsigned int mCharacterCount; 122 unsigned int mElementCount; 123 unsigned int mSpaceCount; 139 124 }; 140 125 … … 146 131 { 147 132 public : 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 133 // ----------------------------------------------------------------------- 134 // Constructors and Destructor 135 // ----------------------------------------------------------------------- 136 StrX(const XMLCh* const toTranscode) 137 { 138 // Call the private transcoding method 139 mLocalForm = XMLString::transcode(toTranscode); 140 } 141 142 ~StrX() 143 { 144 XMLString::release(&mLocalForm); 145 } 146 147 // ----------------------------------------------------------------------- 148 // Getter methods 149 // ----------------------------------------------------------------------- 150 const char* LocalForm() const 151 { 152 return mLocalForm; 153 } 154 170 155 private : 171 172 173 174 175 176 177 156 // ----------------------------------------------------------------------- 157 // Private data members 158 // 159 // fLocalForm 160 // This is the local code page form of the string. 161 // ----------------------------------------------------------------------- 162 char* mLocalForm; 178 163 }; 179 164 … … 181 166 operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump) 182 167 { 183 184 168 target << toDump.LocalForm(); 169 return target; 185 170 } 186 171 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2113 r2115 22 22 #include "InternalRayCaster.h" 23 23 #include "GlobalLinesRenderer.h" 24 #include "ObjectsParser.h" 24 25 25 26 … … 730 731 if (mLoadViewCells) 731 732 { 732 Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf); 733 cout << "loading view cells from " << buf << endl<<flush; 733 Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf); 734 735 cout << "loading objects from " << buf << endl; 736 737 // load objects which will be used as pvs entries 738 ObjectContainer pvsObjects; 739 740 LoadObjects(buf, pvsObjects, mObjects); 741 742 cout << "loading view cells from " << buf << endl; 734 743 735 744 mViewCellsManager = ViewCellsManager::LoadViewCells(buf, 736 mObjects,745 pvsObjects, 737 746 mObjects, 738 747 true, … … 1626 1635 1627 1636 1628 } 1637 bool Preprocessor::LoadObjects(const string &filename, 1638 ObjectContainer &pvsObjects, 1639 const ObjectContainer &preprocessorObjects) 1640 { 1641 ObjectsParser parser; 1642 1643 const bool success = parser.ParseObjects(filename, 1644 pvsObjects, 1645 preprocessorObjects); 1646 1647 if (!success) 1648 { 1649 Debug << "Error: loading objects failed!" << endl; 1650 } 1651 1652 // hack: no bvh object could be found => take preprocessor objects 1653 if (!pvsObjects.empty()) 1654 { 1655 pvsObjects = preprocessorObjects; 1656 } 1657 1658 return success; 1659 } 1660 1661 1662 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r2111 r2115 191 191 virtual void DeterminePvsObjects(VssRayContainer &rays); 192 192 193 static bool LoadObjects(const string &filename, 194 ObjectContainer &pvsObjects, 195 const ObjectContainer &preprocessorObject); 193 196 194 197 //////////////////////////////////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r2113 r2115 581 581 </File> 582 582 <File 583 RelativePath=".\ObjectsParser.cpp"> 584 </File> 585 <File 586 RelativePath=".\ObjectsParser.h"> 587 </File> 588 <File 589 RelativePath=".\ObjectsParserXerces.h"> 590 </File> 591 <File 583 592 RelativePath=".\ObjExporter.cpp"> 584 593 </File> -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2113 r2115 27 27 #include "PerfTimer.h" 28 28 29 //#include "HashPvs.h"30 31 32 29 33 30 #define USE_RAY_LENGTH_AS_CONTRIBUTION 0 … … 173 170 } 174 171 175 Debug << "casting strategies: "; 172 Debug << "casting initial strategies: "; 173 176 174 for (int i = 0; i < (int)mStrategies.size(); ++ i) 177 175 Debug << mStrategies[i] << " "; … … 1020 1018 1021 1019 1020 ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename, 1021 ObjectContainer &pvsObjects, 1022 bool finalizeViewCells, 1023 BoundingBoxConverter *bconverter) 1024 1025 { 1026 ObjectContainer dummys; 1027 1028 return LoadViewCells(filename, 1029 pvsObjects, 1030 dummys, 1031 finalizeViewCells, 1032 bconverter); 1033 } 1022 1034 1023 1035 … … 1047 1059 } 1048 1060 1049 //cout << "viewcells parsed " <<endl;1050 1051 1061 if (0) 1052 1062 { … … 1117 1127 if (mUseKdPvs) 1118 1128 { 1119 vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 1129 vector<KdIntersectable *>::iterator kit, kit_end = 1130 GetPreprocessor()->mKdTree->mKdIntersectables.end(); 1120 1131 1121 1132 int id = 0; … … 1127 1138 obj->SetId(id); 1128 1139 1129 stream << "<BoundingBox" << " id=\"" << id<< "\""1130 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""1131 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;1140 stream << "<BoundingBox" << " id=\"" << id << "\"" 1141 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 1142 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 1132 1143 } 1133 1144 } … … 1143 1154 //-- the bounding boxes 1144 1155 1145 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId()<< "\""1146 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""1147 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;1156 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 1157 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 1158 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 1148 1159 } 1149 1160 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r2113 r2115 562 562 @param filename the filename of the view cells 563 563 @param objects the scene objects 564 @param finalizeViewCells if the view cells should be post processed, i.e. 564 @param finalizeViewCells if the view cells should be post processed, i.e., 565 565 a mesh is created representing the geometry 566 566 @param bconverter a conversion routine working with the similarities of bounding … … 576 576 BoundingBoxConverter *bconverter = NULL); 577 577 578 static ViewCellsManager *LoadViewCells(const string &filename, 579 ObjectContainer &pvsObjects, 580 bool finalizeViewCells = false, 581 BoundingBoxConverter *bconverter = NULL); 578 582 579 583 /////////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r2114 r2115 103 103 , nObjects(0) 104 104 { 105 // pvs objects empty => have to create new ones 106 mCreatePvsObjects = mPvsObjects.empty(); 107 105 // q: can we assume that the objects are sorted? 106 108 107 // sort objects so we can search in them 109 108 //if (!is_sorted(mPvsObjects.begin(), mPvsObjects.end(), ilt)) … … 111 110 112 111 //if (!is_sorted(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt)) 113 sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt);112 // sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt); 114 113 } 115 114 … … 407 406 408 407 409 void ViewCellsParseHandlers::ReplaceBvhPvs(ViewCell *vc)410 {411 //cout << "exchanging pvs" << endl;412 ObjectPvs newPvs;413 414 ObjectPvsIterator pit = vc->GetPvs().GetIterator();415 416 BvhLeaf *dummyInst = new BvhLeaf(AxisAlignedBox3());417 418 ObjectContainer oldIntersectables;419 420 // output PVS of view cell421 while (pit.HasMoreEntries())422 {423 ObjectPvsEntry entry = pit.Next();424 425 Intersectable *intersect = entry.mObject;426 oldIntersectables.push_back(intersect);427 428 DummyIntersectable *dummyIntersect = static_cast<DummyIntersectable *>(intersect);429 430 const int objId = dummyIntersect->GetItem();431 dummyInst->SetId(objId);432 433 vector<BvhLeaf *>::iterator oit =434 lower_bound(mBvhLeaves.begin(),435 mBvhLeaves.end(),436 dummyInst, ilt);437 438 if ((oit != mBvhLeaves.end()) && ((*oit)->GetId() == objId))439 {440 // $$JB we should store a float a per object which corresponds441 // to sumof pdfs, i.e. its relative visibility442 // temporarily set to 1.0f443 //cout << (*oit)->GetId() << " ";444 445 newPvs.AddSample(*oit, 1.0f);446 }447 else448 {449 Debug << "exchangePvs error: object with id " << objId << " does not exist" << endl;450 }451 }452 453 //newPvs.SimpleSort();454 delete dummyInst;455 vc->SetPvs(newPvs);456 457 CLEAR_CONTAINER(oldIntersectables);458 }459 460 461 void ViewCellsParseHandlers::ReplacePvs()462 {463 // sort the pvs entries464 sort(mPvsObjects.begin(), mPvsObjects.end(), ilt);465 466 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end();467 468 //cout << "viewcells : " << mViewCells.size() << endl;469 for (vit = mViewCells.begin(); vit != vit_end; ++ vit)470 {471 ReplaceBvhPvs(*vit);472 }473 }474 475 476 408 void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element, 477 409 AttributeList& attributes) … … 513 445 { 514 446 Debug << "\nparsing view space hierarchy" << endl; 515 cout << "\nparsing view space hierarchy" << endl; 447 cout << "\nparsing view space hierarchy" << endl; 448 516 449 mCurrentState = PARSE_VIEWSPACE_HIERARCHY; 517 450 StartViewSpaceHierarchy(attributes); … … 521 454 if (element == "ObjectSpaceHierarchy") 522 455 { 523 cout << "\nparsing object space hierarchy" << endl;456 cout << "\nparsing object space hierarchy" << endl; 524 457 Debug << "\nparsing object space hierarchy" << endl; 525 458 … … 540 473 case PARSE_VIEWSPACE_HIERARCHY: 541 474 if ((++ nViewCells % 1000) == 0) 542 cout <<"\r"<<nViewCells<<" view cells parsed\r";475 cout << "\r" << nViewCells << " view cells parsed\r"; 543 476 544 477 StartViewSpaceHierarchyElement(element, attributes); … … 546 479 case PARSE_OBJECTSPACE_HIERARCHY: 547 480 if ((++ nObjects % 1000) == 0) 548 cout<<"\r"<< nObjects <<" objects parsed\r";481 cout <<"\r" << nObjects << " objects parsed\r"; 549 482 550 483 StartObjectSpaceHierarchyElement(element, attributes); … … 577 510 } 578 511 512 #if 1 579 513 // TODO: 580 514 // 1) find objects and add them to pvs … … 583 517 584 518 vector<int>::const_iterator it, it_end = objIndices.end(); 519 520 pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result; 521 585 522 for (it = objIndices.begin(); it != it_end; ++ it) 586 523 { 587 if (mCreatePvsObjects) 588 { 589 // pvs entries will be created => just use dummy proxy 590 pvs.AddSample(new DummyIntersectable(*it), 1); 524 const int objId = *it; 525 dummyInst.SetId(objId); 526 527 // equal indeces possible! 528 result = equal_range(mPvsObjects.begin(), 529 mPvsObjects.end(), 530 (Intersectable *)&dummyInst, 531 ilt); 532 533 ObjectContainer::const_iterator eit = result.first; 534 535 for (; eit != result.second; ++ eit) 536 { 537 pvs.AddSample(*eit, 1.0f); 538 } 539 } 540 541 #else 542 543 // TODO: 544 // 1) find objects and add them to pvs 545 // 2) get view cell with specified id 546 MeshInstance dummyInst(NULL); 547 548 vector<int>::const_iterator it, it_end = objIndices.end(); 549 for (it = objIndices.begin(); it != it_end; ++ it) 550 { 551 const int objId = *it; 552 dummyInst.SetId(objId); 553 554 ObjectContainer::iterator oit = 555 lower_bound(mPvsObjects.begin(), 556 mPvsObjects.end(), 557 (Intersectable *)&dummyInst, ilt); 558 559 if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) 560 { 561 // $$JB we should store a float a per object which corresponds 562 // to sumof pdfs, i.e. its relative visibility 563 // temporarily set to 1.0f 564 pvs.AddSample(*oit, 1.0f); 591 565 } 592 566 else 593 567 { 594 const int objId = *it; 595 dummyInst.SetId(objId); 596 597 ObjectContainer::iterator oit = 598 lower_bound(mPvsObjects.begin(), 599 mPvsObjects.end(), 600 (Intersectable *)&dummyInst, ilt); 601 602 if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) 603 { 604 // $$JB we should store a float a per object which corresponds 605 // to sumof pdfs, i.e. its relative visibility 606 // temporarily set to 1.0f 607 pvs.AddSample(*oit, 1.0f); 608 } 609 else 610 { 611 //Debug << "x"; 612 //Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl; 613 } 614 } 615 } 568 Debug << "x"; 569 //Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl; 570 } 571 } 572 #endif 616 573 } 617 574 … … 1287 1244 if (attrName == "objects") 1288 1245 { 1289 StartBvhLeafObjects(objects, ptr); 1246 if (!mPreprocessorObjects.empty()) 1247 StartBvhLeafObjects(objects, ptr); 1290 1248 } 1291 1249 } … … 1298 1256 { 1299 1257 BvhInterior *interior = static_cast<BvhInterior *>(mCurrentBvhNode); 1258 1300 1259 leaf = new BvhLeaf(box, interior, (int)objects.size()); 1301 1260 interior->ReplaceChildLink(NULL, leaf); … … 1309 1268 leaf->mObjects = objects; 1310 1269 BvHierarchy::AssociateObjectsWithLeaf(leaf); 1311 1312 if (mCreatePvsObjects)1313 {1314 // Temp matt: leaves should already have right id1315 if (0) leaf->SetId((int)mBvhLeaves.size());1316 1317 mPvsObjects.push_back(leaf);1318 }1319 1270 } 1320 1271 … … 1336 1287 1337 1288 MeshInstance dummyInst(NULL); 1338 1339 1289 vector<int>::const_iterator it, it_end = objIndices.end(); 1340 1290 … … 1344 1294 dummyInst.SetId(objId); 1345 1295 1346 ObjectContainer:: iterator oit =1347 lower_bound(mP vsObjects.begin(),1348 mP vsObjects.end(),1296 ObjectContainer::const_iterator oit = 1297 lower_bound(mPreprocessorObjects.begin(), 1298 mPreprocessorObjects.end(), 1349 1299 (Intersectable *)&dummyInst, 1350 1300 ilt); 1351 1301 1352 if ((oit != mP vsObjects.end()) && ((*oit)->GetId() == objId))1302 if ((oit != mPreprocessorObjects.end()) && ((*oit)->GetId() == objId)) 1353 1303 { 1354 1304 objects.push_back(*oit); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
r2114 r2115 1 #ifndef _ X3D_PARSER_XERCES__H2 #define _ X3D_PARSER_XERCES__H1 #ifndef _VIEWCELLS_PARSER_XERCES__H 2 #define _VIEWCELLS_PARSER_XERCES__H 3 3 4 4 // --------------------------------------------------------------------------- … … 74 74 void resetDocument(); 75 75 76 void CreateViewCellsManager(/*const char *name*/); 77 78 void ReplacePvs(); 79 void ReplaceBvhPvs(ViewCell *vc); 76 void CreateViewCellsManager(); 80 77 81 78 … … 109 106 110 107 ObjectContainer &mPvsObjects; 111 ObjectContainer &mPreprocessorObjects; 112 113 bool mCreatePvsObjects; 108 const ObjectContainer &mPreprocessorObjects; 114 109 115 110 BoundingBoxConverter *mBoundingBoxConverter; -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r2053 r2115 345 345 346 346 bool guiSupported = false; 347 348 347 bool useRendererBuffer = true; 349 348
Note: See TracChangeset
for help on using the changeset viewer.