Changeset 170 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 07/12/05 21:08:40 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r162 r170 63 63 mMax += v; 64 64 mMin -= v; 65 } 66 67 void SetMin(const Vector3 &v) { 68 mMin = v; 69 } 70 71 void SetMax(const Vector3 &v) { 72 mMax = v; 65 73 } 66 74 -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r162 r170 1063 1063 1064 1064 1065 RegisterOption("Scene.filename", 1066 optString, 1067 "-scene_filename=", 1068 "soda.x3d"); 1069 1065 1070 RegisterOption("Unigraphics.meshGrouping", 1066 1071 optInt, … … 1099 1104 "0.1"); 1100 1105 1101 1102 RegisterOption("IFS.loadKDtree", optBool, NULL, "true"); 1103 RegisterOption("IFS.kdtree", optBool, NULL, "true"); 1104 RegisterOption("IFS.KDTree.minCost", optFloat, NULL, "20"); 1105 RegisterOption("IFS.KDTree.maxDepth", optInt, NULL, "12"); 1106 RegisterOption("IFS.KDTree.ct_div_ci", optFloat, NULL, "1"); 1107 RegisterOption("IFS.KDTree.tries", optFloat, NULL, "3"); 1108 RegisterOption("IFS.KDTree.minCostImprovement", optFloat, NULL, "1.0"); 1109 1110 RegisterOption("IFS.KDTree.buildCostCoef", optFloat, NULL, "2"); 1111 1112 RegisterOption("IFS.optimizeBuffers", optBool, NULL, "true"); 1113 RegisterOption("IFS.strips", optBool, NULL, "false"); 1114 RegisterOption("IFS.stripsRemap", optBool, NULL, "false"); 1115 RegisterOption("IFS.loadStrips", optBool, 1116 "loadStrips", "true"); 1117 1118 RegisterOption("World.loadTextures", optBool, 1119 "loadTextures", 1120 "true" ); 1121 1122 RegisterOption("World.loadTransparentTextures", optBool, 1123 "loadTransparentTextures", 1124 "true" ); 1125 1126 RegisterOption("World.loadLightmaps", optBool, 1127 "loadLightmaps", 1128 "true" ); 1129 1130 RegisterOption("World.loadImages", optBool, 1131 "loadImages", 1132 "true" ); 1106 1107 RegisterOption("KdTree.sahUseFaces", 1108 optBool, 1109 "-kd_sah_use_faces=", 1110 "true"); 1111 1112 1113 RegisterOption("MeshKdTree.Termination.minCost", 1114 optInt, 1115 "-kd_term_min_cost=", 1116 "10"); 1117 1118 RegisterOption("MeshKdTree.Termination.maxDepth", 1119 optInt, 1120 "-kd_term_max_depth=", 1121 "20"); 1122 1123 RegisterOption("MeshKdTree.Termination.maxCostRatio", 1124 optFloat, 1125 "-kd_term_max_cost_ratio=", 1126 "1.5"); 1127 1128 RegisterOption("MeshKdTree.Termination.ct_div_ci", 1129 optFloat, 1130 "-kd_term_ct_div_ci=", 1131 "1.0"); 1132 1133 RegisterOption("MeshKdTree.splitMethod", 1134 optString, 1135 "-kd_split_method=", 1136 "spatialMedian"); 1137 1138 RegisterOption("MeshKdTree.splitBorder", 1139 optFloat, 1140 "-kd_split_border=", 1141 "0.1"); 1142 1133 1143 1134 1144 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r165 r170 23 23 { 24 24 } 25 virtual ~Exporter() {} 25 26 26 27 virtual bool ExportScene(SceneGraphNode *node) = 0; … … 44 45 GetExporter(const string filename); 45 46 47 46 48 }; 47 49 -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
r165 r170 25 25 environment->GetFloatValue("KdTree.Termination.ct_div_ci", mCt_div_ci); 26 26 environment->GetFloatValue("KdTree.splitBorder", mSplitBorder); 27 28 environment->GetBoolValue("KdTree.sahUseFaces", mSahUseFaces); 27 29 28 30 char splitType[64]; … … 42 44 exit(1); 43 45 } 44 45 splitCandidates = new vector<SortableEntry>; 46 splitCandidates = NULL; 46 47 } 47 48 … … 49 50 KdTree::Construct() 50 51 { 52 if (!splitCandidates) 53 splitCandidates = new vector<SortableEntry>; 54 51 55 // first construct a leaf that will get subdivide 52 56 KdLeaf *leaf = (KdLeaf *) mRoot; … … 63 67 } 64 68 65 cout <<"box:"<< mBox<<endl; 66 67 69 cout <<"KdTree Root Box:"<< mBox<<endl; 68 70 mRoot = Subdivide(TraversalData(leaf, mBox, 0)); 71 72 // remove the allocated array 73 delete splitCandidates; 69 74 70 75 return true; … … 131 136 // cerr<<"\n OBJECTS="<<leaf->mObjects.size()<<endl; 132 137 return 133 (leaf->mObjects.size() < mTermMinCost) ||138 (leaf->mObjects.size() <= mTermMinCost) || 134 139 (leaf->mDepth >= mTermMaxDepth); 135 140 … … 424 429 // C = ct_div_ci + (ol + or)/queries 425 430 431 int totalFaces = 0; 432 vector<SortableEntry>::const_iterator ci; 433 434 for(ci = splitCandidates->begin(); 435 ci < splitCandidates->end(); 436 ci++) 437 if ((*ci).type == SortableEntry::MESH_MIN) { 438 Mesh *mesh = ((MeshInstance *)(*ci).data)->GetMesh(); 439 totalFaces += mesh->mFaces.size(); 440 } 441 442 int facesLeft = 0; 443 int facesRight = totalFaces; 444 426 445 int objectsLeft = 0, objectsRight = node->mObjects.size(); 427 446 428 447 float minBox = box.Min(axis); 429 448 float maxBox = box.Max(axis); 430 449 float boxArea = box.SurfaceArea(); 431 450 432 433 434 451 float minBand = minBox + mSplitBorder*(maxBox - minBox); 435 452 float maxBand = minBox + (1.0f - mSplitBorder)*(maxBox - minBox); … … 437 454 float minSum = 1e20; 438 455 439 for( vector<SortableEntry>::const_iteratorci = splitCandidates->begin();456 for(ci = splitCandidates->begin(); 440 457 ci < splitCandidates->end(); 441 458 ci++) { 442 459 Mesh *mesh = ((MeshInstance *)(*ci).data)->GetMesh(); 443 460 switch ((*ci).type) { 444 461 case SortableEntry::MESH_MIN: 445 462 objectsLeft++; 463 facesLeft += mesh->mFaces.size(); 446 464 break; 447 465 case SortableEntry::MESH_MAX: 448 466 objectsRight--; 467 facesRight -= mesh->mFaces.size(); 449 468 break; 450 469 } … … 456 475 rbox.SetMin(axis, (*ci).value); 457 476 458 float sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 477 float sum; 478 if (mSahUseFaces) 479 sum = facesLeft*lbox.SurfaceArea() + facesRight*rbox.SurfaceArea(); 480 else 481 sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 459 482 460 483 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; … … 471 494 } 472 495 473 float oldCost = node->mObjects.size();496 float oldCost = mSahUseFaces ? totalFaces : node->mObjects.size(); 474 497 float newCost = mCt_div_ci + minSum/boxArea; 475 498 float ratio = newCost/oldCost; 476 499 477 500 #if 0 478 501 cout<<"===================="<<endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h
r162 r170 449 449 float mCt_div_ci; 450 450 int mSplitMethod; 451 451 bool mSahUseFaces; 452 452 /// root of the tree 453 453 KdNode *mRoot; -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
r167 r170 1 1 #include "Ray.h" 2 2 #include "Mesh.h" 3 #include "MeshKdTree.h" 3 4 4 5 int MeshInstance::mailID = 21843194198; … … 15 16 16 17 mIsConvex = false; 17 } 18 18 19 if (mFaces.size() > 2*MeshKdTree::mTermMinCost) { 20 mKdTree = new MeshKdTree(this); 21 MeshKdLeaf *root = (MeshKdLeaf *)mKdTree->GetRoot(); 22 for (int i = 0; i < mFaces.size(); i++) 23 root->mFaces.push_back(i); 24 cout<<"KD"; 25 mKdTree->Construct(); 26 } 27 } 28 29 AxisAlignedBox3 30 Mesh::GetFaceBox(const int faceIndex) 31 { 32 Face *face = mFaces[faceIndex]; 33 AxisAlignedBox3 box; 34 box.SetMin( mVertices[face->mVertexIndices[0]] ); 35 box.SetMax(box.Min()); 36 for (int i = 1; i < face->mVertexIndices.size(); i++) { 37 box.Include(mVertices[face->mVertexIndices[i]]); 38 } 39 return box; 40 } 41 42 int 43 Mesh::CastRayToFace( 44 const int faceIndex, 45 Ray &ray, 46 float &nearestT, 47 int &nearestFace, 48 MeshInstance *instance 49 ) 50 { 51 float t; 52 int hit = 0; 53 if (RayFaceIntersection(faceIndex, ray, t, nearestT) == Ray::INTERSECTION) { 54 switch (ray.GetType()) { 55 case Ray::GLOBAL_RAY: 56 ray.intersections.push_back(Ray::RayIntersection(t, instance, faceIndex)); 57 hit++; 58 break; 59 case Ray::LOCAL_RAY: 60 nearestT = t; 61 nearestFace = faceIndex; 62 hit++; 63 break; 64 } 65 } 66 return hit; 67 } 19 68 20 69 int … … 24 73 ) 25 74 { 26 FaceContainer::const_iterator fi; 75 if (mKdTree) { 76 return mKdTree->CastRay(ray, instance); 77 } 78 27 79 int faceIndex = 0; 28 80 int hits = 0; 29 81 float nearestT = MAX_FLOAT; 30 float nearestFace;31 82 int nearestFace = -1; 83 32 84 if (ray.GetType() == Ray::LOCAL_RAY && ray.intersections.size()) 33 85 nearestT = ray.intersections[0].mT; 34 86 35 36 87 for ( ; 37 88 faceIndex < mFaces.size(); 38 89 faceIndex++) { 39 float t; 40 if (RayFaceIntersection(faceIndex, ray, t, nearestT) == Ray::INTERSECTION) { 41 switch (ray.GetType()) { 42 case Ray::GLOBAL_RAY: 43 ray.intersections.push_back(Ray::RayIntersection(t, instance, faceIndex)); 44 hits++; 45 break; 46 case Ray::LOCAL_RAY: 47 hits++; 48 nearestT = t; 49 nearestFace = faceIndex; 50 break; 51 } 52 } 90 hits += CastRayToFace(faceIndex, ray, nearestT, nearestFace, instance); 91 if (mIsConvex && nearestFace != -1) 92 break; 93 } 94 95 if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 96 if (ray.intersections.size()) 97 ray.intersections[0] = Ray::RayIntersection(nearestT, instance, nearestFace); 98 else 99 ray.intersections.push_back(Ray::RayIntersection(nearestT, instance, nearestFace)); 100 } 101 102 return hits; 103 } 104 105 int 106 Mesh::CastRayToSelectedFaces( 107 Ray &ray, 108 const vector<int> &faces, 109 MeshInstance *instance 110 ) 111 { 112 vector<int>::const_iterator fi; 113 int faceIndex = 0; 114 int hits = 0; 115 float nearestT = MAX_FLOAT; 116 int nearestFace = -1; 117 118 if (ray.GetType() == Ray::LOCAL_RAY && ray.intersections.size()) 119 nearestT = ray.intersections[0].mT; 120 121 for ( fi = faces.begin(); 122 fi != faces.end(); 123 fi++) { 124 hits += CastRayToFace(*fi, ray, nearestT, nearestFace, instance); 125 if (mIsConvex && nearestFace != -1) 126 break; 53 127 } 54 128 … … 143 217 144 218 145 mVertices[face->mVertexIndices[face->mVertexIndices.size() - 1]]. 219 int size = face->mVertexIndices.size(); 220 221 mVertices[face->mVertexIndices[size - 1]]. 146 222 ExtractVerts(&u1, &v1, paxis ); 147 148 if ( mIsConvex) {223 224 if (0 && size <= 4) { 149 225 // assume a convex face 150 for (i = 0; i < face->mVertexIndices.size(); i++) {226 for (i = 0; i < size; i++) { 151 227 mVertices[face->mVertexIndices[i]].ExtractVerts(&u2, &v2, paxis); 152 228 // line u1, v1, u2, v2 … … 164 240 // with a ray originating at the point of intersection and 165 241 // travelling in the positive X direction. 166 for (i = 0; i < face->mVertexIndices.size(); i++) {242 for (i = 0; i < size; i++) { 167 243 mVertices[face->mVertexIndices[i]].ExtractVerts(&u2, &v2, paxis); 168 244 count += (int_lineseg(u, v, u1, v1, u2, v2) != 0); … … 185 261 } 186 262 263 int 264 MeshInstance::CastRay( 265 Ray &ray, 266 const vector<int> &faces 267 ) 268 { 269 return mMesh->CastRayToSelectedFaces(ray, faces, this); 270 } 271 187 272 188 273 Plane3 … … 206 291 return res; 207 292 } 293 -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r162 r170 12 12 13 13 class MeshInstance; 14 class MeshKdTree; 14 15 15 16 /// default vertex container for Mesh … … 18 19 /// vertex index container 19 20 typedef std::vector<int> VertexIndexContainer; 20 21 21 22 22 … … 54 54 55 55 /// Default constructor 56 Mesh():mVertices(), mFaces(), mMaterial(NULL) {}56 Mesh():mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL) {} 57 57 58 58 /// Constructor with container preallocation … … 65 65 mFaces.reserve(faces); 66 66 } 67 67 68 68 ~Mesh() { 69 69 for (int i=0; i < mFaces.size(); i++) … … 75 75 mFaces.push_back(face); 76 76 } 77 77 78 78 void Preprocess(); 79 79 … … 86 86 /** Patches forming the mesh */ 87 87 FaceContainer mFaces; 88 88 89 89 /** Global mesh material */ 90 90 Material *mMaterial; 91 91 92 92 /** true if the mesh is a convex mesh */ 93 93 bool mIsConvex; 94 95 MeshKdTree *mKdTree; 94 96 95 97 int … … 99 101 ); 100 102 103 int 104 CastRayToSelectedFaces( 105 Ray &ray, 106 const vector<int> &faces, 107 MeshInstance *instance 108 ); 101 109 110 int 111 CastRayToFace( 112 const int faceIndex, 113 Ray &ray, 114 float &nearestT, 115 int &nearestFace, 116 MeshInstance *instance 117 ); 118 119 102 120 int 103 121 RayFaceIntersection(const int faceIndex, … … 106 124 const float nearestT 107 125 ); 108 126 109 127 Plane3 GetFacePlane(const int faceIndex); 110 128 129 AxisAlignedBox3 GetFaceBox(const int faceIndex); 130 111 131 }; 112 132 … … 139 159 ); 140 160 161 virtual int 162 CastRay( 163 Ray &ray, 164 const vector<int> &faces 165 ); 166 141 167 142 168 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r162 r170 2 2 #include "Exporter.h" 3 3 #include "UnigraphicsParser.h" 4 #include "X3dParser.h" 4 5 #include "Preprocessor.h" 5 6 … … 27 28 28 29 mSceneGraph = new SceneGraph; 29 Parser *parser = new UnigraphicsParser; 30 31 32 Parser *parser; 33 34 if (strstr(filename.c_str(), ".x3d")) 35 parser = new X3dParser; 36 else 37 parser = new UnigraphicsParser; 38 30 39 bool result = parser->ParseFile(filename, &mSceneGraph->mRoot); 31 40 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp
r162 r170 1 // --------------------------------------------------------------------------- 2 // Includes for all the program files to see 3 // --------------------------------------------------------------------------- 4 #include <string.h> 5 #include <stdlib.h> 6 #include <iostream> 7 using namespace std; 8 #include <xercesc/util/PlatformUtils.hpp> 9 10 // --------------------------------------------------------------------------- 11 // Includes 12 // --------------------------------------------------------------------------- 13 #include <xercesc/framework/StdInInputSource.hpp> 14 #include <xercesc/parsers/SAXParser.hpp> 15 #include <xercesc/util/OutOfMemoryException.hpp> 16 17 // --------------------------------------------------------------------------- 18 // Includes 19 // --------------------------------------------------------------------------- 20 #include <xercesc/sax/AttributeList.hpp> 21 #include <xercesc/sax/SAXParseException.hpp> 22 #include <xercesc/sax/SAXException.hpp> 1 23 2 24 #include "X3dParser.h" 25 26 #include "X3dParserXerces.h" 27 #include "Mesh.h" 28 #include "SceneGraph.h" 29 30 31 32 // --------------------------------------------------------------------------- 33 // Local data 34 // 35 // doNamespaces 36 // Indicates whether namespace processing should be enabled or not. 37 // The default is no, but -n overrides that. 38 // 39 // doSchema 40 // Indicates whether schema processing should be enabled or not. 41 // The default is no, but -s overrides that. 42 // 43 // schemaFullChecking 44 // Indicates whether full schema constraint checking should be enabled or not. 45 // The default is no, but -s overrides that. 46 // 47 // valScheme 48 // Indicates what validation scheme to use. It defaults to 'auto', but 49 // can be set via the -v= command. 50 // --------------------------------------------------------------------------- 51 static bool doNamespaces = false; 52 static bool doSchema = false; 53 static bool schemaFullChecking = false; 54 static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto; 55 56 57 58 59 60 // --------------------------------------------------------------------------- 61 // StdInParseHandlers: Constructors and Destructor 62 // --------------------------------------------------------------------------- 63 X3dParseHandlers::X3dParseHandlers(SceneGraphNode *root) : 64 fElementCount(0) 65 , fAttrCount(0) 66 , fCharacterCount(0) 67 , fSpaceCount(0) 68 { 69 currentNode = root; 70 } 71 72 X3dParseHandlers::~X3dParseHandlers() 73 { 74 } 75 76 77 // --------------------------------------------------------------------------- 78 // StdInParseHandlers: Implementation of the SAX DocumentHandler interface 79 // --------------------------------------------------------------------------- 80 void X3dParseHandlers::endElement(const XMLCh* const name) 81 { 82 StrX lname(name); 83 string element(lname.localForm()); 84 if (element == "Shape") 85 EndShape(); 86 } 87 88 void 89 X3dParseHandlers::EndShape() 90 { 91 currentMesh->Preprocess(); 92 // make an instance of this mesh 93 MeshInstance *mi = new MeshInstance(currentMesh); 94 currentNode->mGeometry.push_back(mi); 95 currentMesh = NULL; 96 } 97 98 void 99 X3dParseHandlers::StartIndexedFaceSet( 100 AttributeList& attributes) 101 { 102 int len = attributes.getLength(); 103 int i; 104 VertexIndexContainer vertices; 105 106 for (i=0; i < len; i++) { 107 string attrName(StrX(attributes.getName(i)).localForm()); 108 if (attrName == "coordIndex") { 109 StrX attrValue(attributes.getValue(i)); 110 // handle coordIndex 111 vertices.clear(); 112 const char *ptr = attrValue.localForm(); 113 char *endptr; 114 while(1) { 115 int index = strtol(ptr, &endptr, 10); 116 if (ptr == endptr || index == -1) { 117 if (vertices.size() > 2) { 118 Face *face = new Face(vertices); 119 currentMesh->mFaces.push_back(face); 120 } 121 vertices.clear(); 122 if (ptr == endptr) 123 break; 124 } else { 125 vertices.push_back(index); 126 } 127 ptr = endptr; 128 } 129 } 130 } 131 } 132 133 void 134 X3dParseHandlers::StartMaterial( 135 AttributeList& attributes) 136 { 137 int len = attributes.getLength(); 138 int i; 139 if (!currentMesh->mMaterial) 140 currentMesh->mMaterial = new Material; 141 for (i=0; i < len; i++) { 142 string attrName(StrX(attributes.getName(i)).localForm()); 143 StrX attrValue(attributes.getValue(i)); 144 const char *ptr = attrValue.localForm(); 145 if (attrName == "diffuseColor") { 146 float r, g, b; 147 if (sscanf(ptr, "%f %f %f", &r, &g, &b) == 3) 148 currentMesh->mMaterial->mDiffuseColor = RgbColor(r, g, b); 149 } 150 } 151 } 152 153 void 154 X3dParseHandlers::StartCoordinate( 155 AttributeList& attributes) 156 { 157 int len = attributes.getLength(); 158 int i; 159 VertexContainer vertices; 160 for (i=0; i < len; i++) { 161 string attrName(StrX(attributes.getName(i)).localForm()); 162 if (attrName == "point") { 163 StrX attrValue(attributes.getValue(i)); 164 const char *ptr = attrValue.localForm(); 165 char *endptr; 166 while(1) { 167 float x = strtod(ptr, &endptr); 168 if (ptr == endptr) 169 break; 170 ptr = endptr; 171 float y = strtod(ptr, &endptr); 172 if (ptr == endptr) 173 break; 174 ptr = endptr; 175 float z = strtod(ptr, &endptr); 176 if (ptr == endptr) 177 break; 178 ptr = endptr; 179 if (*ptr == ',') 180 ptr++; 181 Vector3 v(x, y, z); 182 vertices.push_back(v); 183 } 184 currentMesh->mVertices = vertices; 185 } 186 } 187 } 188 189 190 void 191 X3dParseHandlers::startElement(const XMLCh* const name, 192 AttributeList& attributes) 193 { 194 StrX lname(name); 195 string element(lname.localForm()); 196 197 if (element == "IndexedFaceSet") { 198 // create a new mesh node in the scene graph 199 StartIndexedFaceSet(attributes); 200 } 201 202 if (element == "Shape") { 203 cout<<"+"; 204 currentMesh = new Mesh; 205 } 206 207 if (element == "Coordinate") { 208 if (currentMesh) 209 StartCoordinate(attributes); 210 } 211 212 if (element == "Material") { 213 StartMaterial(attributes); 214 } 215 216 fElementCount++; 217 fAttrCount += attributes.getLength(); 218 } 219 220 void 221 X3dParseHandlers::characters(const XMLCh* const chars, 222 const unsigned int length) 223 { 224 fCharacterCount += length; 225 } 226 227 void 228 X3dParseHandlers::ignorableWhitespace(const XMLCh* const chars, 229 const unsigned int length) 230 { 231 fSpaceCount += length; 232 } 233 234 void 235 X3dParseHandlers::resetDocument() 236 { 237 fAttrCount = 0; 238 fCharacterCount = 0; 239 fElementCount = 0; 240 fSpaceCount = 0; 241 } 242 243 244 245 // --------------------------------------------------------------------------- 246 // StdInParseHandlers: Overrides of the SAX ErrorHandler interface 247 // --------------------------------------------------------------------------- 248 void 249 X3dParseHandlers::error(const SAXParseException& e) 250 { 251 XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId()) 252 << ", line " << e.getLineNumber() 253 << ", char " << e.getColumnNumber() 254 << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 255 } 256 257 void 258 X3dParseHandlers::fatalError(const SAXParseException& e) 259 { 260 XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId()) 261 << ", line " << e.getLineNumber() 262 << ", char " << e.getColumnNumber() 263 << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 264 } 265 266 void 267 X3dParseHandlers::warning(const SAXParseException& e) 268 { 269 XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId()) 270 << ", line " << e.getLineNumber() 271 << ", char " << e.getColumnNumber() 272 << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 273 } 3 274 4 275 … … 7 278 SceneGraphNode **root) 8 279 { 9 10 11 12 } 13 14 15 namespace X3DTK { 16 namespace MESH { 17 18 MyStructureComputer::MyStructureComputer() 19 { 20 setGraphTraversal(new DFSGraphTraversal()); 21 setComponentVisitor(new MyStructureComputerCoreVisitor()); 22 } 23 24 MyStructureComputer::~MyStructureComputer() 280 // Initialize the XML4C system 281 try { 282 XMLPlatformUtils::Initialize(); 283 } 284 285 catch (const XMLException& toCatch) 286 { 287 XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" 288 << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; 289 return false; 290 } 291 292 293 // 294 // Create a SAX parser object. Then, according to what we were told on 295 // the command line, set the options. 296 // 297 SAXParser* parser = new SAXParser; 298 parser->setValidationScheme(valScheme); 299 parser->setDoNamespaces(doNamespaces); 300 parser->setDoSchema(doSchema); 301 parser->setValidationSchemaFullChecking(schemaFullChecking); 302 303 304 // 305 // Create our SAX handler object and install it on the parser, as the 306 // document and error handler. We are responsible for cleaning them 307 // up, but since its just stack based here, there's nothing special 308 // to do. 309 // 310 *root = new SceneGraphNode; 311 X3dParseHandlers handler(*root); 312 parser->setDocumentHandler(&handler); 313 parser->setErrorHandler(&handler); 314 315 unsigned long duration; 316 int errorCount = 0; 317 // create a faux scope so that 'src' destructor is called before 318 // XMLPlatformUtils::Terminate 319 { 320 // 321 // Kick off the parse and catch any exceptions. Create a standard 322 // input input source and tell the parser to parse from that. 323 // 324 // StdInInputSource src; 325 try 25 326 { 26 Singleton<MyStructureComputerStateVariables>::removeInstance(); 27 } 28 29 MySimpleMesh *MyStructureComputer::compute(SFNode N) 327 const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); 328 parser->parse(filename.c_str()); 329 const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); 330 duration = endMillis - startMillis; 331 errorCount = parser->getErrorCount(); 332 } 333 catch (const OutOfMemoryException&) 30 334 { 31 Singleton<MyStructureComputerStateVariables>::getInstance()->init(); 32 traverse(N); 33 Singleton<MyStructureComputerStateVariables>::getInstance()->finish(); 34 35 return Singleton<MyStructureComputerStateVariables>::getInstance()->getMesh(); 36 } 37 38 39 MyStructureComputerCoreVisitor::MyStructureComputerCoreVisitor() 335 XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; 336 errorCount = 2; 337 return false; 338 } 339 catch (const XMLException& e) 40 340 { 41 // Enter functions. 42 define(Recorder<Mesh>::getEnterFunction(&MyStructureComputerCoreVisitor::enterMesh)); 43 define(Recorder<Transform>::getEnterFunction(&MyStructureComputerCoreVisitor::enterTransform)); 44 // Leave function. 45 define(Recorder<X3DGroupingNode>::getLeaveFunction(&MyStructureComputerCoreVisitor::leaveX3DGroupingNode)); 46 } 47 48 void MyStructureComputerCoreVisitor::enterMesh(Mesh *M) 49 { 50 // StateVariables assignation. 51 MyStructureComputerStateVariables *stateVariables = Singleton<MyStructureComputerStateVariables>::getInstance(); 52 53 SFMatrix34f T = stateVariables->getMatrix(); 54 55 // Beginning a new Mesh by memorizing the current vertex index. 56 stateVariables->beginNewMesh(); 57 58 // filling the vertices. 59 for (Mesh::MFVertex::const_iterator v = M->getVertices().begin(); v != M->getVertices().end(); ++v) 60 { 61 SFPoint3f P = T*(*v)->data().getPoint(); 62 stateVariables->addVertex(P.x, P.y, P.z); 63 } 64 65 // filling the faces. 66 for (Mesh::MFFace::const_iterator 67 f = M->getFaces().begin(); f != M->getFaces().end(); ++f) 68 { 69 const SFFace::MFEdge &edges = (*f)->getEdges(); 70 list<unsigned int> indexList; 71 for (SFFace::MFEdge::const_iterator e = edges.begin(); e != edges.end(); ++e) 72 indexList.push_back((*e)->getFromVertex()->getIndex()); 341 XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n" 342 << StrX(e.getMessage()) 343 << "\n" << XERCES_STD_QUALIFIER endl; 344 errorCount = 1; 345 return false; 346 } 73 347 74 stateVariables->addFace(indexList); 75 } 76 } 77 78 void MyStructureComputerCoreVisitor::enterTransform(Transform *T) 79 { 80 Singleton<MyStructureComputerStateVariables>::getInstance()->pushMatrix(T->getTransform()); 81 } 82 83 void MyStructureComputerCoreVisitor::leaveX3DGroupingNode(X3DGroupingNode *) 84 { 85 Singleton<MyStructureComputerStateVariables>::getInstance()->popMatrix(); 86 } 87 88 : StateVariables(), _mesh(0), _decal(0) 89 { 90 } 91 92 void MyStructureComputerStateVariables::init() 93 { 94 _mesh = new MySimpleMesh(); 95 _matrixStack.push_front(SFMatrix34f::identity); 96 } 97 98 void MyStructureComputerStateVariables::finish() 99 { 100 _matrixStack.clear(); 101 } 102 103 void MyStructureComputerStateVariables::beginNewMesh() 104 { 105 _decal = _mesh->getVertexArray().size(); 106 } 107 108 void MyStructureComputerStateVariables::addFace(const Face &face) 109 { 110 // MyFace decalFace = face; 111 // for (MyFace::iterator it = decalFace.begin(); it != decalFace.end(); ++it) 112 // *it = _decal + *it; 113 114 // _mesh->addFace(decalFace); 115 }; 116 117 void MyStructureComputerStateVariables::pushMatrix(const SFMatrix34f &transformation) 118 { 119 _matrixStack.push_front(_matrixStack.front()*transformation); 120 } 121 122 void MyStructureComputerStateVariables::popMatrix() 123 { 124 _matrixStack.pop_front(); 125 } 126 127 } 128 348 // Print out the stats that we collected and time taken 349 if (!errorCount) { 350 XERCES_STD_QUALIFIER cout << filename << ": " << duration << " ms (" 351 << handler.getElementCount() << " elems, " 352 << handler.getAttrCount() << " attrs, " 353 << handler.getSpaceCount() << " spaces, " 354 << handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; 355 } 356 } 357 358 // 359 // Delete the parser itself. Must be done prior to calling Terminate, below. 360 // 361 delete parser; 362 363 XMLPlatformUtils::Terminate(); 364 365 if (errorCount > 0) 366 return false; 367 else 368 return true; 369 } 370 371 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h
r162 r170 2 2 #define __X3DPARSER_H 3 3 4 #include "parser.h" 5 #include "mesh.h" 4 #include "Parser.h" 6 5 7 #include <X3DTK/MESH/scenegraph.h>8 #include <X3DTK/kernel.h>9 #include <X3DTK/MESH/scenegraph.h>10 6 11 7 class X3dParser : public Parser … … 14 10 X3dParser():Parser() {} 15 11 16 17 12 bool ParseFile(const string filename, SceneGraphNode **root); 18 13 19 14 }; 20 15 21 };22 23 24 namespace X3DTK {25 namespace MESH {26 27 class MyStructureComputerStateVariables : public StateVariables28 {29 public:30 MyStructureComputerStateVariables();31 32 void init();33 void finish();34 35 void beginNewMesh();36 inline void addVertex(float x, float y, float z) {37 //_mesh->addVertex(x, y, z);38 };39 40 void addFace(const Face &face);41 42 void pushMatrix(const SFMatrix34f &transformation);43 void popMatrix();44 45 inline Mesh *getMesh() const {return _mesh;};46 SFMatrix34f getMatrix() const {return _matrixStack.front();};47 48 private:49 Mesh *_mesh;50 unsigned int _decal;51 std::list<SFMatrix34f> _matrixStack;52 };53 54 // MyStructureComputer processor.55 56 class MyStructureComputer : public X3DOnePassProcessor57 {58 public:59 MyStructureComputer();60 virtual ~MyStructureComputer();61 62 virtual Mesh *compute(SFNode N);63 };64 65 class X3DGroupingNode;66 class Transform;67 68 /// Visitor for the Core component of the MyStructureComputer module.69 70 class MyStructureComputerCoreVisitor : public CoreVisitor71 {72 public:73 MyStructureComputerCoreVisitor();74 75 static void enterMesh(Mesh *M);76 static void enterTransform(Transform *T);77 static void leaveX3DGroupingNode(X3DGroupingNode *N);78 };79 80 }81 82 16 83 17 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r163 r170 3 3 # Jiri Bittner 2003 4 4 ############################################################################# 5 6 Scene { 7 8 # filename atlanta2.x3d 9 filename soda.dat 10 11 } 12 5 13 Limits { 6 14 … … 11 19 12 20 Unigraphics { 13 meshGrouping 1 21 meshGrouping 1000 14 22 } 15 23 16 24 KdTree { 25 sahUseFaces true 17 26 Termination { 18 minCost 627 minCost 2 19 28 maxDepth 18 20 maxCostRatio 1.521 ct_div_ci 129 maxCostRatio 0.9 30 ct_div_ci 0.5 22 31 } 23 32 24 33 # splitMethod spatialMedian 25 34 splitMethod SAH 26 splitBorder 0. 135 splitBorder 0.01 27 36 } 37 38 MeshKdTree { 39 Termination { 40 minCost 4 41 maxDepth 18 42 maxCostRatio 0.9 43 ct_div_ci 0.5 44 } 45 46 # splitMethod spatialMedian 47 splitMethod SAH 48 splitBorder 0.01 49 } -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r162 r170 3 3 #include "Parser.h" 4 4 #include "UnigraphicsParser.h" 5 #include "X3dParser.h" 5 6 #include "Environment.h" 6 7 #include "Camera.h" 8 #include "MeshKdTree.h" 7 9 8 10 #define USE_EXE_PATH false … … 15 17 environment = new Environment; 16 18 environment->Parse(argc, argv, USE_EXE_PATH); 19 MeshKdTree::ParseEnvironment(); 17 20 18 21 Preprocessor *p = 19 22 new SamplingPreprocessor(); 20 23 21 p->LoadScene("soda.dat"); 24 char buff[128]; 25 environment->GetStringValue("Scene.filename", buff); 26 string filename(buff); 27 28 p->LoadScene(filename); 22 29 p->BuildKdTree(); 23 30 p->KdTreeStatistics(cout); 24 31 25 32 // p->mSceneGraph->Export("soda.x3d"); 26 p->Export("soda.x3d", true, false); 27 p->Export("soda-kdtree.x3d", false, true); 28 33 if (1) { 34 p->Export(filename + "-out.x3d", true, false); 35 p->Export(filename + "-kdtree.x3d", false, true); 36 } 37 29 38 // p->LoadViewcells("viewcells.wrl"); 30 39 p->ComputeVisibility(); 31 40 p->ExportPreprocessedData("scene.vis"); 41 42 if (1) { 43 Camera camera; 44 camera.LookAtBox(p->mKdTree->GetBox()); 45 camera.SnapImage("camera.png", p->mKdTree); 46 47 camera.LookInBox(p->mKdTree->GetBox()); 48 camera.SetPosition(camera.mPosition - Vector3(0,100,0)); 49 camera.SnapImage("camera2.png", p->mKdTree); 50 } 32 51 33 Camera camera;34 camera.LookAtBox(p->mKdTree->GetBox());35 camera.SnapImage("camera.png", p->mKdTree);36 37 camera.LookInBox(p->mKdTree->GetBox());38 camera.SetPosition(camera.mPosition - Vector3(0,100,0));39 camera.SnapImage("camera2.png", p->mKdTree);40 52 41 53 return 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r163 r170 5 5 6 6 #win32:INCLUDEPATH += c:/STLport-4.6.2/stlport 7 INCLUDEPATH += ../src ../support/X3DToolKit/include ../support/zlib/include ../support/boost 7 8 INCLUDEPATH += ../src ../support/xerces/include ../support/zlib/include ../support/boost 9 10 win32:LIBPATH += ../support/expat/lib ../support/xerces/lib 8 11 9 12 #win32:LIBPATH += c:/STLport-4.6.2/lib … … 17 20 # DEPENDPATH = ../../include 18 21 22 win32:LIBS += xerces-c_2.lib 23 19 24 # Input 20 25 HEADERS += 21 26 22 27 23 28 SOURCES += \ 24 29 Preprocessor.cpp SamplingPreprocessor.cpp ExactPreprocessor.cpp \ … … 26 31 UnigraphicsParser.cpp X3dExporter.cpp SceneGraph.cpp Material.cpp \ 27 32 Matrix4x4.cpp Vector3.cpp AxisAlignedBox3.cpp Ray.cpp main.cpp Mesh.cpp \ 28 Exporter.cpp Camera.cpp 29 30 #X3dParser.cpp 33 Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp 31 34 32 35
Note: See TracChangeset
for help on using the changeset viewer.