Changeset 1197 for GTP/trunk/Lib/Vis
- Timestamp:
- 08/11/06 03:05:12 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h
r1139 r1197 57 57 58 58 virtual bool 59 ExportKdTree(const KdTree &tree ) = 0;59 ExportKdTree(const KdTree &tree, const bool exportGeometry = false) = 0; 60 60 61 61 virtual bool -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1196 r1197 14 14 int KdNode::sMailId = 1; 15 15 int KdNode::sReservedMailboxes = 1; 16 17 inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 18 { 19 return obj1->mId < obj2->mId; 20 } 21 16 22 17 23 KdNode::KdNode(KdInterior *parent):mParent(parent), mMailbox(0) … … 1127 1133 #define TYPE_INTERIOR -2 1128 1134 #define TYPE_LEAF -3 1129 //#define LEAF_END_ID -4 1135 1130 1136 1131 1137 … … 1148 1154 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 1149 1155 } 1150 1151 // end leaf 1152 //int leafEndId = LEAF_END_ID; stream.write(reinterpret_cast<char *>(&leafEndId), sizeof(int)); 1153 } 1154 1155 1156 KdLeaf *KdTree::ImportBinLeaf(ifstream &stream, KdInterior *parent) 1156 } 1157 1158 1159 KdLeaf *KdTree::ImportBinLeaf(ifstream &stream, 1160 KdInterior *parent, 1161 const ObjectContainer &objects) 1157 1162 { 1158 1163 int leafId = TYPE_LEAF; … … 1161 1166 1162 1167 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 1163 1164 1168 KdLeaf *leaf = new KdLeaf(parent, size); 1165 1169 1166 Debug << "objects size: " << size << endl; 1170 MeshInstance dummyInst(NULL); 1171 //Debug << "objects size: " << size << endl; 1172 1167 1173 // read object ids 1168 1174 for (int i = 0; i < size; ++ i) 1169 1175 { 1170 1176 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 1171 //if (samplesIn.eof()) break; 1172 } 1177 dummyInst.SetId(objId); 1178 1179 ObjectContainer::const_iterator oit = 1180 lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 1181 1182 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 1183 { 1184 leaf->mObjects.push_back(*oit); 1185 } 1186 else 1187 { 1188 Debug << "error: object with id " << objId << " does not exist" << endl; 1189 } 1190 } 1173 1191 1174 1192 return leaf; … … 1214 1232 1215 1233 // export binary version of mesh 1216 stack<KdNode *> tStack;1234 queue<KdNode *> tStack; 1217 1235 tStack.push(mRoot); 1218 1236 1219 1237 while(!tStack.empty()) 1220 1238 { 1221 KdNode *node = tStack. top();1239 KdNode *node = tStack.front(); 1222 1240 tStack.pop(); 1223 1241 1224 1242 if (node->IsLeaf()) 1225 1243 { 1226 Debug << "l";1244 //Debug << "l"; 1227 1245 ExportBinLeaf(stream, dynamic_cast<KdLeaf *>(node)); 1228 1246 } 1229 1247 else 1230 1248 { 1231 Debug << "i";1249 //Debug << "i"; 1232 1250 KdInterior *interior = dynamic_cast<KdInterior *>(node); 1233 1251 1234 1252 ExportBinInterior(stream, interior); 1235 1253 1254 tStack.push(interior->mFront); 1236 1255 tStack.push(interior->mBack); 1237 tStack.push(interior->mFront);1238 }1239 1240 if (tStack.empty())1241 break;1242 1243 node = tStack.top();1244 tStack.pop();1245 1246 if (node->IsLeaf())1247 {1248 Debug << "l";1249 ExportBinLeaf(stream, dynamic_cast<KdLeaf *>(node));1250 }1251 else1252 {1253 Debug << "i";1254 KdInterior *interior = dynamic_cast<KdInterior *>(node);1255 1256 ExportBinInterior(stream, interior);1257 1258 tStack.push(interior->mBack);1259 tStack.push(interior->mFront);1260 1256 } 1261 1257 } … … 1265 1261 1266 1262 1267 KdNode *KdTree::LoadNextNode(ifstream &stream, KdInterior *parent) 1263 KdNode *KdTree::LoadNextNode(ifstream &stream, 1264 KdInterior *parent, 1265 const ObjectContainer &objects) 1268 1266 { 1269 1267 int nodeType; … … 1272 1270 if (nodeType == TYPE_LEAF) 1273 1271 { 1274 return ImportBinLeaf(stream, dynamic_cast<KdInterior *>(parent) );1272 return ImportBinLeaf(stream, dynamic_cast<KdInterior *>(parent), objects); 1275 1273 } 1276 1274 … … 1286 1284 1287 1285 1288 bool KdTree::LoadBinTree(const string &filename, constObjectContainer &objects)1286 bool KdTree::LoadBinTree(const string &filename, ObjectContainer &objects) 1289 1287 { 1290 1288 // export binary version of mesh 1291 stack<TraversalData> tStack;1289 queue<TraversalData> tStack; 1292 1290 ifstream stream(filename.c_str(), ios::binary); 1293 Debug << "here94" << endl; 1291 1294 1292 if (!stream.is_open()) 1295 1293 return false; 1296 1294 1295 std::stable_sort(objects.begin(), objects.end(), ilt); 1296 1297 1297 mBox.Initialize(); 1298 1299 1298 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1300 1299 … … 1309 1308 1310 1309 DEL_PTR(mRoot); // we make a new root 1311 Debug << "here44" << endl;1312 KdNode *node = LoadNextNode(stream, NULL );1310 1311 KdNode *node = LoadNextNode(stream, NULL, objects); 1313 1312 mRoot = node; 1314 1313 … … 1319 1318 while(!tStack.empty()) 1320 1319 { 1321 TraversalData tData = tStack. top();1320 TraversalData tData = tStack.front(); 1322 1321 tStack.pop(); 1323 1322 … … 1328 1327 mStat.nodes += 2; 1329 1328 1330 Debug << "i" ;1329 //Debug << "i" ; 1331 1330 KdInterior *interior = dynamic_cast<KdInterior *>(node); 1332 1331 interior->mBox = tData.mBox; 1333 1332 1334 KdNode *front = LoadNextNode(stream, interior );1335 KdNode *back = LoadNextNode(stream, interior );1333 KdNode *front = LoadNextNode(stream, interior, objects); 1334 KdNode *back = LoadNextNode(stream, interior, objects); 1336 1335 1337 1336 interior->SetupChildLinks(back, front); … … 1339 1338 ++ mStat.splits[interior->mAxis]; 1340 1339 1341 Debug << "plane: " << interior->mAxis << " " << interior->mPosition << endl;1342 Debug << "box: " << tData.mBox << endl;1340 //Debug << "plane: " << interior->mAxis << " " << interior->mPosition << endl; 1341 //Debug << "box: " << tData.mBox << endl; 1343 1342 1344 1343 // compute new bounding box … … 1350 1349 backBox); 1351 1350 1351 tStack.push(TraversalData(front, frontBox, tData.mDepth + 1)); 1352 1352 tStack.push(TraversalData(back, backBox, tData.mDepth + 1)); 1353 tStack.push(TraversalData(front, frontBox, tData.mDepth + 1));1354 1353 } 1355 1354 else 1356 1355 { 1357 1356 EvaluateLeafStats(tData); 1358 //dynamic_cast<KdLeaf *>(node)->mBox = tData.mBox; 1359 Debug << "l" << endl; 1360 } 1361 } 1362 1363 Debug << "\nhere85" << endl; 1357 //Debug << "l" << endl; 1358 } 1359 } 1360 1364 1361 Debug << mStat << endl; 1365 1362 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1196 r1197 392 392 393 393 bool ExportBinTree(const string &filename); 394 bool LoadBinTree(const string &filename, constObjectContainer &object);394 bool LoadBinTree(const string &filename, ObjectContainer &object); 395 395 396 396 protected: … … 559 559 void ExportBinLeaf(ofstream &stream, KdLeaf *leaf); 560 560 void ExportBinInterior(ofstream &stream, KdInterior *interior); 561 KdLeaf *ImportBinLeaf(ifstream &stream, KdInterior *parent );561 KdLeaf *ImportBinLeaf(ifstream &stream, KdInterior *parent, const ObjectContainer &objects); 562 562 KdInterior *ImportBinInterior(ifstream &stream, KdInterior *parent); 563 KdNode *LoadNextNode(ifstream &stream, KdInterior *parent );563 KdNode *LoadNextNode(ifstream &stream, KdInterior *parent, const ObjectContainer &objects); 564 564 565 565 int mTermMaxNodes; -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1194 r1197 478 478 479 479 480 bool Preprocessor::LoadKdTree() 481 { 482 return true; 483 } 484 485 bool Preprocessor::ExportKdTree() 486 { 487 return true; 488 } 489 490 480 491 bool Preprocessor::LoadSamples(VssRayContainer &samples, 481 492 ObjectContainer &objects) const -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1145 r1197 113 113 bool ExportSamples(const VssRayContainer &samples) const; 114 114 115 bool LoadKdTree(); 116 bool ExportKdTree(); 117 115 118 /** Get Sample rays of particular type, returns false if this 116 119 type of rays is not supported by the preprocessor -
GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h
r1141 r1197 91 91 } 92 92 93 bool ExportEntries(const string &filename) 94 { 95 ofstream stream(filename.c_str(), ios::binary); 96 97 if (!stream.is_open()) 98 return false; 99 100 std::map<unsigned int, T *>::const_iterator mit, mit_end = mEntries.end(); 101 102 for (mit = mEntries.begin(); mit != mit_end; ++ mit) 103 { 104 int id = (*mit).first; 105 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 106 } 107 108 return true; 109 } 93 110 94 111 /** Returns size of resource container. -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1194 r1197 62 62 63 63 64 inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 65 { 66 return obj1->mId < obj2->mId; 67 } 64 68 65 69 … … 83 87 , mBoundingBoxConverter(bconverter) 84 88 { 89 std::stable_sort(mObjects->begin(), mObjects->end(), ilt); 85 90 } 86 91 … … 283 288 284 289 285 inline bool ilt(Intersectable *obj1, Intersectable *obj2)286 {287 return obj1->mId < obj2->mId;288 }289 290 291 290 void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, 292 291 AttributeList& attributes) … … 331 330 332 331 ObjectContainer::iterator oit = 333 lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); 334 332 lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); 335 333 336 334 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) … … 501 499 502 500 BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit); 503 504 501 505 502 if (viewCell->GetId() == viewCellId) -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1168 r1197 605 605 606 606 607 bool VrmlExporter::ExportKdTree(const KdTree &tree )607 bool VrmlExporter::ExportKdTree(const KdTree &tree, const bool exportGeometry) 608 608 { 609 609 if (mExportRayDensity) … … 1304 1304 1305 1305 1306 1307 1306 void VrmlExporter::ExportBeam(const Beam &beam, const AxisAlignedBox3 &box) 1308 1307 { -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h
r1121 r1197 45 45 46 46 bool 47 ExportKdTree(const KdTree &tree );47 ExportKdTree(const KdTree &tree, const bool exportGeometry = false); 48 48 49 49 //bool ExportOspTree(const OspTree &tree); -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
r1178 r1197 594 594 595 595 596 bool X3dExporter::ExportKdTree(const KdTree &tree) 596 bool X3dExporter::ExportKdTree(const KdTree &tree, 597 const bool exportGeometry) 597 598 { 598 599 if (mExportRayDensity) { … … 630 631 tStack.push(interior->mBack); 631 632 } 633 else if (exportGeometry) 634 { 635 SetFilled(); 636 SetForcedMaterial(RandomMaterial()); 637 ExportGeometry(dynamic_cast<KdLeaf *>(node)->mObjects); 638 SetWireframe(); 639 } 632 640 } 633 641 … … 637 645 return true; 638 646 } 639 640 641 647 642 648 -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h
r1121 r1197 45 45 46 46 bool 47 ExportKdTree(const KdTree &tree );47 ExportKdTree(const KdTree &tree, const bool exportGeometry = false); 48 48 49 49 bool -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1196 r1197 162 162 preprocessor->mKdTree->ExportBinTree("kd.bin"); 163 163 164 MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 165 164 166 KdTree *kdTree2 = new KdTree; 165 167 kdTree2->LoadBinTree("kd.bin", preprocessor->mObjects); 166 168 Exporter *exporter = Exporter::GetExporter("testkd.x3d"); 167 169 170 MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 171 168 172 if (exporter) 169 173 { 170 174 exporter->SetWireframe(); 171 exporter->ExportKdTree(*kdTree2 );175 exporter->ExportKdTree(*kdTree2, true); 172 176 173 177 delete exporter;
Note: See TracChangeset
for help on using the changeset viewer.