- Timestamp:
- 08/10/06 09:23:38 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1184 r1194 1125 1125 1126 1126 1127 } 1127 #define INTERIOR_START_ID -2 1128 #define LEAF_START_ID -3 1129 #define LEAF_END_ID -4 1130 1131 1132 void KdTree::ExportBinLeaf(ofstream &stream, KdLeaf *leaf) 1133 { 1134 ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 1135 1136 int leafStartId = LEAF_START_ID; 1137 stream.write(reinterpret_cast<char *>(&leafStartId), sizeof(int)); 1138 for (it = leaf->mObjects.begin(); it != it_end; ++ it) 1139 { 1140 Intersectable *obj = *it; 1141 1142 int id = obj->mId; 1143 1144 //stream.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 1145 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 1146 } 1147 1148 // end leaf 1149 int leafEndId = LEAF_END_ID; 1150 stream.write(reinterpret_cast<char *>(&leafEndId), sizeof(int)); 1151 } 1152 1153 1154 void KdTree::ImportBinLeaf(ifstream &stream, KdLeaf *leaf) 1155 { 1156 ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 1157 1158 int leafId = LEAF_START_ID; 1159 int objId = leafId; 1160 1161 while (objId != LEAF_END_ID) 1162 { 1163 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 1164 //if (samplesIn.eof()) break; 1165 } 1166 } 1167 1168 1169 void KdTree::ExportBinInterior(ofstream &stream, KdInterior *interior) 1170 { 1171 int interiorid = INTERIOR_START_ID; 1172 stream.write(reinterpret_cast<char *>(&interiorid), sizeof(int)); 1173 1174 int axis = interior->mAxis; 1175 Vector3 pos = interior->mPosition; 1176 1177 stream.write(reinterpret_cast<char *>(&axis), sizeof(int)); 1178 stream.write(reinterpret_cast<char *>(&pos), sizeof(Vector3)); 1179 } 1180 1181 1182 void KdTree::ImportBinInterior(ifstream &stream, KdInterior *interior) 1183 { 1184 int interiorid = -2; 1185 stream.read(reinterpret_cast<char *>(&interiorid), sizeof(int)); 1186 1187 int axis = interior->mAxis; 1188 Vector3 pos = interior->mPosition; 1189 1190 stream.read(reinterpret_cast<char *>(&axis), sizeof(int)); 1191 stream.read(reinterpret_cast<char *>(&pos), sizeof(Vector3)); 1192 } 1193 1194 1195 bool KdTree::ExportBinTree(const string &filename) 1196 { 1197 ofstream stream(filename.c_str(), ios::binary); 1198 1199 if (!stream.is_open()) 1200 return false; 1201 1202 // export binary version of mesh 1203 stack<KdNode *> tStack; 1204 1205 tStack.push(mRoot); 1206 1207 while(!tStack.empty()) 1208 { 1209 KdNode *node = tStack.top(); 1210 1211 if (node->IsLeaf()) 1212 { 1213 ExportBinLeaf(stream, dynamic_cast<KdLeaf *>(node)); 1214 } 1215 else 1216 { 1217 KdInterior *interior = dynamic_cast<KdInterior *>(node); 1218 1219 ExportBinInterior(stream, interior); 1220 1221 tStack.push(interior->mFront); 1222 tStack.push(interior->mBack); 1223 } 1224 } 1225 1226 return true; 1227 } 1228 1229 1230 bool KdTree::LoadBinTree(const string &filename) 1231 { 1232 ofstream stream(filename.c_str(), ios::binary); 1233 1234 if (!stream.is_open()) 1235 return false; 1236 1237 // export binary version of mesh 1238 stack<KdNode *> tStack; 1239 1240 tStack.push(mRoot); 1241 1242 while(!tStack.empty()) 1243 { 1244 KdNode *node = tStack.top(); 1245 1246 if (node->IsLeaf()) 1247 { 1248 ExportBinLeaf(stream, dynamic_cast<KdLeaf *>(node)); 1249 } 1250 else 1251 { 1252 KdInterior *interior = dynamic_cast<KdInterior *>(node); 1253 1254 ExportBinInterior(stream, interior); 1255 1256 tStack.push(interior->mFront); 1257 tStack.push(interior->mBack); 1258 } 1259 } 1260 1261 return true; 1262 } 1263 1264 1265 } -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1184 r1194 391 391 CollectLeafPvs(); 392 392 393 bool ExportBinTree(const string &filename); 394 bool LoadBinTree(const string &filename); 395 393 396 protected: 394 397 … … 553 556 */ 554 557 void ProcessMultipleRefs(KdLeaf *leaf) const; 558 559 void ExportBinLeaf(ofstream &stream, KdLeaf *leaf); 560 void ExportBinInterior(ofstream &stream, KdInterior *interior); 561 void ImportBinLeaf(ifstream &stream, KdLeaf *leaf); 562 void ImportBinInterior(ifstream &stream, KdInterior *interior); 555 563 556 564 int mTermMaxNodes; -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1174 r1194 609 609 #endif 610 610 samplesOut.close(); 611 611 612 return true; 612 613 } -
GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
r1166 r1194 155 155 void SceneGraph::ExportScene(const string filename) 156 156 { 157 // export binary version of mesh157 158 158 } 159 159 160 160 161 void SceneGraph::LoadScene(const string filename) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1143 r1194 289 289 290 290 291 void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, AttributeList& attributes) 291 void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, 292 AttributeList& attributes) 292 293 { 293 294 int len = attributes.getLength(); -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1181 r1194 161 161 preprocessor->BuildKdTree(); 162 162 preprocessor->KdTreeStatistics(cout); 163 163 preprocessor->mKdTree->ExportBinTree("kd.bin"); 164 164 // parse view cells related options 165 165 preprocessor->PrepareViewCells();
Note: See TracChangeset
for help on using the changeset viewer.