Changeset 2609 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 01/17/08 21:46:32 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/include/Mesh.h
r68 r2609 16 16 }; 17 17 18 /** Mesh containing polygonal patches */ 18 /** Mesh containing polygonal patches 19 */ 19 20 class Mesh { 20 21 public: -
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r2582 r2609 2238 2238 void AxisAlignedBox3::EnlargeToMinSize() 2239 2239 { 2240 const float epsMin = 1e-7 ;2241 const float epsAdd = 1e-6 ;2242 const float epsMul = 1.000005 ;2240 const float epsMin = 1e-7f; 2241 const float epsAdd = 1e-6f; 2242 const float epsMul = 1.000005f; 2243 2243 float dir = mMax.x - mMin.x; 2244 2244 2245 assert(dir >= 0.f); 2245 2246 if (dir < epsMin) { -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r2588 r2609 215 215 216 216 int CastRay(Ray &ray) { return 0; } 217 218 217 int CastSimpleRay(const SimpleRay &ray) { return 0;} 218 int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;} 219 219 220 220 bool IsConvex() const { return true; } -
GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h
r2176 r2609 10 10 namespace GtpVisibilityPreprocessor { 11 11 12 class TransformedMeshInstance; 12 13 class ViewCell; 13 14 class HierarchyNode; … … 71 72 typedef std::vector<int> VertexIndexContainer; 72 73 74 /// a container for dynamic objects 75 typedef std::vector<TransformedMeshInstance *> DynamicObjectsContainer; 76 77 73 78 } 74 79 -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2604 r2609 133 133 void GlRenderer::RenderTriangle(TriangleIntersectable *object) 134 134 { 135 135 Triangle3 *t = &(object->GetItem()); 136 136 137 137 glBegin(GL_TRIANGLES); … … 317 317 318 318 glPushMatrix(); 319 320 319 glMultMatrixf((float *)m.x); 321 320 … … 494 493 Intersectable::NewMail(); 495 494 495 Preprocessor *p = mViewCellsManager->GetPreprocessor(); 496 // handle dynamic objects 497 DynamicObjectsContainer::const_iterator dit, dit_end = p->mDynamicObjects.end(); 498 499 for (dit = p->mDynamicObjects.begin(); dit != dit_end; ++ dit) 500 { 501 RenderIntersectable(*dit); 502 } 503 496 504 #if 1 497 498 505 _RenderSceneTrianglesWithDrawArrays(); 499 506 -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r2176 r2609 56 56 57 57 }; 58 59 60 Mesh::Mesh(const int vertices, const int faces): 61 mFaces(), 62 mMaterial(NULL), 63 mKdTree(NULL), 64 mVertices(), 65 mIsConvex(false), 66 mIsWatertight(false), 67 mId(0) 68 { 69 mVertices.reserve(vertices); 70 mFaces.reserve(faces); 71 } 58 72 59 73 -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
r2575 r2609 62 62 63 63 /** Mesh containing polygonal patches */ 64 class Mesh { 64 class Mesh 65 { 65 66 66 67 public: 67 68 68 69 /// Default constructor 69 Mesh(): mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL), mId(0) {}70 Mesh(): mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL), mId(0) {} 70 71 71 72 /// Constructor with container preallocation 72 Mesh(const int vertices, const int faces): 73 mFaces(), 74 mMaterial(NULL), 75 mKdTree(NULL), 76 mVertices(), 77 mIsConvex(false), 78 mIsWatertight(false), 79 mId(0) 80 { 81 mVertices.reserve(vertices); 82 mFaces.reserve(faces); 83 } 84 73 Mesh(const int vertices, const int faces); 85 74 /** Constructor setting a unqiue mesh id. 86 75 */ 87 76 Mesh(const int id); 88 89 77 /** Setting unique mesh id and using preallocation. 90 78 */ 91 79 Mesh(const int id, const int vertices, const int faces); 92 93 80 /** Copy constructor making a deep copy of the faces. 94 81 */ 95 82 Mesh(const Mesh &rhs); 96 97 83 /** Assignement operator. 98 84 @note does not copy id … … 116 102 void AddFace(Face *face) 117 103 { 118 104 mFaces.push_back(face); 119 105 } 120 106 121 107 void ComputeBoundingBox(); 122 123 108 /** This function must be called after creating the mesh 124 109 because it creates the local kd tree and the bounding box. … … 132 117 void ApplyTransformation(const Matrix4x4 &m); 133 118 134 /** Axis aligned bounding box of the mesh in local mesh coordinates. 135 */ 136 AxisAlignedBox3 mBox; 137 138 /** Vertices forming the mesh. 139 */ 119 /// Axis aligned bounding box of the mesh in local mesh coordinates. 120 AxisAlignedBox3 mBox; 121 /// Vertices forming the mesh. 140 122 VertexContainer mVertices; 141 142 /** Patches forming the mesh. 143 */ 123 /// Patches forming the mesh. 144 124 FaceContainer mFaces; 145 146 /** Global mesh material. 147 */ 125 /// Global mesh material. 148 126 Material *mMaterial; 149 150 /** true if the mesh is a convex mesh. 151 */ 127 /// true if the mesh is a convex mesh. 152 128 bool mIsConvex; 153 154 /** true if the mesh is a convex mesh. 155 */ 129 /// true if the mesh is a convex mesh. 156 130 bool mIsWatertight; 157 131 … … 202 176 /** Returns unique mesh id. 203 177 */ 204 int GetId() const 205 { 206 return mId; 207 } 178 int GetId() const { return mId; } 208 179 209 180 … … 245 216 246 217 public: 247 MeshInstance(Mesh *mesh): Intersectable(), mMesh(mesh), mMaterial(NULL)218 MeshInstance(Mesh *mesh): Intersectable(), mMesh(mesh), mMaterial(NULL) 248 219 { 249 220 } … … 315 286 { 316 287 public: 317 TransformedMeshInstance(Mesh *mesh); 318 319 virtual AxisAlignedBox3 GetBox() const; 320 321 322 virtual int CastRay(Ray &ray); 323 324 virtual int CastRay(Ray &ray, const std::vector<int> &faces); 325 326 virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; } 327 328 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 329 330 /** Transforms this mesh instance by m. 331 */ 332 void ApplyWorldTransform(const Matrix4x4 &m); 333 334 /** Loads the transformation matrix into this mesh instance. 335 */ 336 void LoadWorldTransform(const Matrix4x4 &m); 337 338 /** The transformation is returned in m. 339 */ 340 void GetWorldTransform(Matrix4x4 &m) const; 341 342 /** Transforms a mesh according to the stored world transform. 343 @param transformedMesh returns the tranformed mesh. 344 */ 345 void GetTransformedMesh(Mesh &transformedMesh) const; 346 347 Vector3 GetNormal(const int idx) const; 288 TransformedMeshInstance(Mesh *mesh); 289 290 virtual AxisAlignedBox3 GetBox() const; 291 292 virtual int CastRay(Ray &ray); 293 294 virtual int CastRay(Ray &ray, const std::vector<int> &faces); 295 296 virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; } 297 298 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 299 300 /** Transforms this mesh instance by m. 301 */ 302 void ApplyWorldTransform(const Matrix4x4 &m); 303 /** Loads the transformation matrix into this mesh instance. 304 */ 305 void LoadWorldTransform(const Matrix4x4 &m); 306 /** The transformation is returned in m. 307 */ 308 void GetWorldTransform(Matrix4x4 &m) const; 309 /** Transforms a mesh according to the stored world transform. 310 @param transformedMesh returns the tranformed mesh. 311 */ 312 void GetTransformedMesh(Mesh &transformedMesh) const; 313 314 Vector3 GetNormal(const int idx) const; 348 315 349 316 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2606 r2609 115 115 DEL_PTR(mViewCellsManager); 116 116 cout << "done.\n"; 117 118 117 119 118 cout << "Deleting bsp tree ... \n"; … … 136 135 DEL_PTR(mRenderSimulator); 137 136 mRenderSimulator = NULL; 137 138 138 cout << "deleting renderer ... \n"; 139 139 DEL_PTR(renderer); 140 140 renderer = NULL; 141 141 142 cout << "deleting ray caster ... \n"; 142 143 DEL_PTR(mRayCaster); … … 1093 1094 const string &internKdTree) 1094 1095 { 1095 // always try to load the kd tree1096 /* cout << "loading kd tree file " << internKdTree << " ... " << endl;1097 1098 if (!LoadKdTree(internKdTree))1099 {1100 cout << "error loading kd tree with filename "1101 << internKdTree << ", rebuilding it instead ... " << endl;1102 // build new kd tree from scene geometry1103 BuildKdTree();1104 1105 // export kd tree?1106 const long startTime = GetTime();1107 cout << "exporting kd tree ... ";1108 1109 if (!ExportKdTree(internKdTree))1110 {1111 cout << " error exporting kd tree with filename "1112 << internKdTree << endl;1113 }1114 else1115 {1116 cout << "finished in "1117 << TimeDiff(startTime, GetTime()) * 1e-31118 << " secs" << endl;1119 }1120 }1121 1122 KdTreeStatistics(cout);1123 cout << mKdTree->GetBox() << endl;1124 */1125 1096 int rayCastMethod; 1126 1097 Environment::GetSingleton()-> … … 1204 1175 ) 1205 1176 { 1206 1207 1177 const long t1 = GetTime(); 1208 1178 … … 1234 1204 castDoubleRays, 1235 1205 pruneInvalidRays); 1206 1207 #if DYNAMIC_OBJECTS_HACK 1208 1209 static Ray hRay; 1210 1211 VssRayContainer::iterator vit, vit_end = vssRays.end(); 1212 1213 for (vit = vssRays.begin(); vit != vit_end; ++ vit) 1214 { 1215 VssRay *vssRay = *vit; 1216 hRay.Init(*vssRay); 1217 1218 DynamicObjectsContainer::const_iterator tit, tit_end = mDynamicObjects.end(); 1219 1220 bool foundIntersect = false; 1221 for (tit = mDynamicObjects.begin(); tit != tit_end; ++ tit) 1222 { 1223 TransformedMeshInstance *tmi = *tit; 1224 if (tmi->CastRay(hRay)) //cout << "z"; else cout<< "r"; 1225 { 1226 cout << "i: " << Intersectable::GetTypeName(hRay.intersections[0].mObject); 1227 foundIntersect = true; 1228 } 1229 } 1230 1231 if (foundIntersect) 1232 cout << "x: " << Intersectable::GetTypeName(hRay.intersections[0].mObject); 1233 1234 if (foundIntersect) 1235 // write new results back into vssRay 1236 vssRay->Init(hRay); 1237 1238 if (foundIntersect) 1239 cout << "y : " << Intersectable::GetTypeName(vssRay->mTerminationObject); 1240 1241 hRay.intersections.clear(); 1242 } 1243 #endif 1236 1244 } 1237 1245 … … 1595 1603 1596 1604 1597 bool Preprocessor::AddGeometry(const string &filename, 1598 ObjectContainer &pvsObjects, 1599 const ObjectContainer &preprocessorObjects) 1600 { 1601 // bool success = LoadBinaryObj(filename, mSceneGraph->GetRoot(), &mFaceParents); 1602 SceneGraphLeaf *leaf = new SceneGraphLeaf(); 1603 if (LoadBinaryObj(filename, leaf, NULL)) 1604 { 1605 Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename) 1606 { 1607 igzstream inStream(filename.c_str()); 1608 1609 if (!inStream.is_open()) 1610 return NULL; 1611 1612 cout << "binary obj dump available, loading " << filename.c_str() << endl; 1613 1614 // read in triangle size 1615 int numTriangles; 1616 1617 inStream.read(reinterpret_cast<char *>(&numTriangles), sizeof(int)); 1618 1619 cout << "loading " << numTriangles << " triangles into mesh" << endl; 1620 1621 int i = 0, j = 0; 1622 1623 Mesh *mesh = new Mesh(numTriangles * 3, numTriangles); 1624 1625 const int t = 500000; 1626 while (1) 1627 { 1628 Triangle3 tri; 1629 1630 inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i]), sizeof(Vector3)); 1631 inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i + 1]), sizeof(Vector3)); 1632 inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i + 2]), sizeof(Vector3)); 1633 1634 1635 mesh->mVertices[i].x += 20; 1636 mesh->mVertices[i + 1].x += 20; 1637 mesh->mVertices[i + 2].x += 20; 1638 1639 mesh->mVertices[i].z -= 10; 1640 mesh->mVertices[i + 1].z -= 10; 1641 mesh->mVertices[i + 2].z -= 10; 1642 1643 mesh->mVertices[i] *= 50; 1644 mesh->mVertices[i + 1] *= 50; 1645 mesh->mVertices[i + 2] *= 50; 1646 1647 mesh->AddFace(new Face(i + 0, i + 1, i + 2)); 1648 1649 // end of file reached 1650 if (inStream.eof()) 1651 break; 1652 1653 i += 3; 1654 if (((j ++) % t) == (t - 1)) 1655 cout<<"\r"<<i<<"/"<<numTriangles<<"\r"; 1656 } 1657 1658 if (j != numTriangles) 1659 { 1660 cout << "warning: triangle size does not match with loaded triangle size" << endl; 1661 return false; 1662 } 1663 1664 mesh->Preprocess(); 1665 cout << "loaded " << numTriangles << " triangles" << endl; 1666 1667 return mesh; 1668 } 1669 1670 1671 bool Preprocessor::LoadDynamicGeometry(const string &filename) 1672 { 1673 const bool dynamic = true; 1674 1675 Mesh *mesh = LoadBinaryObjIntoMesh(filename); 1676 1677 if (mesh) 1678 { 1679 SceneGraphLeaf *leaf = new SceneGraphLeaf(dynamic); 1680 1681 TransformedMeshInstance *tmi = new TransformedMeshInstance(mesh); 1682 leaf->mGeometry.push_back(tmi); 1683 1605 1684 mSceneGraph->GetRoot()->mChildren.push_back(leaf); 1685 //mDynamicObjects.push_back(leaf); 1686 mDynamicObjects.push_back(tmi); 1687 1606 1688 return true; 1607 1689 } 1608 1690 1691 1609 1692 return false; 1610 1693 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r2600 r2609 58 58 59 59 virtual ~Preprocessor(); 60 61 60 /** Load the input scene. 62 61 @param filename file to load … … 64 63 */ 65 64 virtual bool LoadScene(const string &filename); 66 67 65 /** Export all preprocessed data in a XML format understandable by the 68 66 PreprocessingInterface of the GtpVisibilityPreprocessor Module. … … 71 69 */ 72 70 virtual bool ExportPreprocessedData(const string &filename); 73 74 71 /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction 75 72 is driven by the environment settings, which also sais which of the three types of … … 77 74 */ 78 75 virtual bool BuildKdTree(); 79 80 76 /** Compute visibility method. This method has to be reimplemented by the actual 81 77 Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor, … … 83 79 */ 84 80 virtual bool ComputeVisibility() = 0; 85 86 81 /** Post Process the computed visibility. By default applys the visibility filter 87 82 (if specified in the environment and export the preprocessed data 88 83 */ 89 84 virtual bool PostProcessVisibility(); 90 91 85 /** View cells are either loaded or prepared for generation, according to the chosen environment 92 86 object. Important evironment options are, e.g, the view cell type. … … 94 88 */ 95 89 bool PrepareViewCells(); 96 97 90 /** Construct viewcells from the scratch 98 91 */ 99 92 bool ConstructViewCells(); 100 101 93 /** Returns the specified sample strategy, NULL if no valid strategy. 102 94 */ 103 95 SamplingStrategy *GenerateSamplingStrategy(const int strategyId); 104 105 96 /** Export preprocessor data. 106 97 */ … … 198 189 const ObjectContainer &preprocessorObject); 199 190 200 /** Adds new geometry to the existing one. 201 */ 202 bool AddGeometry(const string &filename, ObjectContainer &pvsObjects, const ObjectContainer &prepObjects); 191 /** Adds dynamic geometry 192 */ 193 bool LoadDynamicGeometry(const string &filename); 194 195 Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename); 196 203 197 204 198 ///////////////////////// … … 212 206 /// kD-tree organizing the scene graph (occluders + occludees) + viewcells 213 207 KdTree *mKdTree; 214 AxisAlignedBox3 sceneBox; 208 AxisAlignedBox3 sceneBox; 209 215 210 /// View space partition bsp tree 216 211 VspBspTree *mVspBspTree; … … 222 217 /// list of all loaded occludees 223 218 ObjectContainer mOccludees; 224 225 219 /// the view cells manager 226 220 ViewCellsManager *mViewCellsManager; 221 222 //SceneGraphNodeContainer mDynamicObjects; 223 DynamicObjectsContainer mDynamicObjects; 227 224 228 225 /// greedy optimized hierarchy for both objects and view cells -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
r2604 r2609 369 369 glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 370 370 glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); 371 } 372 373 374 void QtGlRendererWidget::_UpdatePvsIndices() 371 372 // handle dynamic objects 373 DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicObjects.end(); 374 375 for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit) 376 { 377 RenderIntersectable(*dit); 378 } 379 } 380 381 382 void QtGlRendererWidget::PreparePvs() 375 383 { 376 384 int indexBufferSize = 0; … … 381 389 mPvsSize = mPvsCache.mPvs.GetSize(); 382 390 391 mDynamicObjects.clear(); 392 383 393 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 384 394 … … 386 396 { 387 397 Intersectable *obj = it.Next(); 388 KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 389 390 _UpdatePvsIndices(node, indexBufferSize); 398 switch (obj->Type()) 399 { 400 case Intersectable::KD_INTERSECTABLE: 401 { 402 KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 403 _UpdatePvsIndices(node, indexBufferSize); 404 } 405 break; 406 case Intersectable::TRANSFORMED_MESH_INSTANCE: 407 mDynamicObjects.push_back(static_cast<TransformedMeshInstance *>(obj)); 408 break; 409 default: 410 cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl; 411 } 391 412 } 392 413 … … 421 442 static_cast<TriangleIntersectable *>(leaf->mObjects[i]); 422 443 423 // check if already rendered424 /*if (!obj->Mailed())425 {426 obj->Mail();427 428 mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;429 mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;430 mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;431 432 indexBufferSize += 3;433 }*/434 444 if (obj->mRenderedFrame != mCurrentFrame) 435 445 { … … 481 491 if (mUseSpatialFilter) 482 492 { 483 //ObjectPvs pvs;484 485 493 //mMutex.lock(); 486 494 // mSpatialFilter size is in range 0.001 - 0.1 … … 500 508 501 509 /// update the indices for rendering 502 _UpdatePvsIndices();510 PreparePvs(); 503 511 504 512 emit PvsUpdated(); 505 513 } 506 514 507 //Intersectable::NewMail();508 PvsData pvsData;509 515 510 516 // Render PVS … … 519 525 { 520 526 if (!mRenderVisibilityEstimates && !mUseRandomColorPerPvsObject) 521 {522 527 _RenderPvs(); 523 }524 528 else 525 { 526 mPvsSize = mPvsCache.mPvs.GetSize(); 527 528 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 529 530 while (it.HasMoreEntries()) 531 { 532 Intersectable *object = it.Next(pvsData); 533 534 RgbColor color; 535 536 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 537 // glColor3f(visibility, 0.0f, 0.0f); 538 //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 539 if (mUseRandomColorPerPvsObject) 540 { 541 KdIntersectable *kdint = static_cast<KdIntersectable *>(object); 542 543 if (kdint->mGenericIdx == -1) 544 { 545 kdint->mGenericIdx = (int)mColors.size(); 546 mColors.push_back(RandomColor()); 547 } 548 color = mColors[kdint->mGenericIdx]; 549 } 550 else 551 { 552 color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1)); 553 } 554 555 glColor3f(color.r, color.g, color.b); 556 557 mUseForcedColors = true; 558 RenderIntersectable(object); 559 mUseForcedColors = false; 560 } 561 } 529 _RenderColoredPvs(); 562 530 } 563 531 … … 587 555 RenderScene(); 588 556 } 589 590 //DisableDrawArrays();591 //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);592 557 } 593 558 … … 673 638 { 674 639 float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 675 float TURN_SENSITIVITY =0.1f;676 float TILT_SENSITIVITY =32.0 ;677 float TURN_ANGLE= M_PI /36.0 ;640 float TURN_SENSITIVITY = 0.1f; 641 float TILT_SENSITIVITY = 32.0 ; 642 float TURN_ANGLE= M_PI /36.0 ; 678 643 679 644 int x = e->pos().x(); … … 685 650 if (e->modifiers() & Qt::ControlModifier) 686 651 { 687 mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY /2.0;688 mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY /2.0;652 mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY / 2.0; 653 mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY / 2.0; 689 654 } 690 655 else … … 930 895 connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this, SLOT(SetRandomViewPoint())); 931 896 connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void))); 897 connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void))); 932 898 933 899 connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); … … 1029 995 } 1030 996 997 998 void QtGlRendererWidget::LoadObject() 999 { 1000 string filename("../data/bunny.bn"); 1001 1002 cout << "Loading model << " << filename << endl; 1003 1004 if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename)) 1005 cout << "Loading finished" << endl; 1006 else 1007 cerr << "Loading failed" << endl; 1008 1009 updateGL(); 1010 } 1011 1031 1012 void 1032 1013 QtGlRendererWidget::RenderRenderCost() … … 1176 1157 1177 1158 QFont font40; font40.setPointSize(30); 1178 s.sprintf(" pvs:%04d", mPvsSize);1159 s.sprintf("PVS: %04d", mPvsSize); 1179 1160 renderText(20, 40, s, font40); 1180 1161 } … … 1862 1843 QGroupBox *groupBox2 = CreateRenderCostPanel(hbox); 1863 1844 vh->addWidget(groupBox2, 0, 0); 1864 1865 1845 1866 1846 QGroupBox *groupBox3 = CreateRayVisualizationPanel(hbox); … … 1877 1857 1878 1858 vbox->resize(800,150); 1879 1880 1859 1881 1860 vbox = new QGroupBox("Rendering", this); … … 2034 2013 connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics())); 2035 2014 2015 button = new QPushButton("Load object", vbox); 2016 vbox->layout()->addWidget(button); 2017 connect(button, SIGNAL(clicked()), SIGNAL(LoadObject())); 2018 2036 2019 /*cb = new QCheckBox("Stats", vbox); 2037 2020 vbox->layout()->addWidget(cb); 2038 2021 cb->setChecked(false); 2039 connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics())); 2040 */ 2022 connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));*/ 2041 2023 if (0) 2042 2024 { … … 2207 2189 2208 2190 2209 } 2191 void QtGlRendererWidget::_RenderColoredPvs() 2192 { 2193 // note: could be done more efficiently using color buffers 2194 mPvsSize = mPvsCache.mPvs.GetSize(); 2195 2196 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 2197 2198 PvsData pvsData; 2199 2200 while (it.HasMoreEntries()) 2201 { 2202 Intersectable *object = it.Next(pvsData); 2203 2204 RgbColor color; 2205 2206 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 2207 // glColor3f(visibility, 0.0f, 0.0f); 2208 //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 2209 if (mUseRandomColorPerPvsObject) 2210 { 2211 KdIntersectable *kdint = static_cast<KdIntersectable *>(object); 2212 2213 if (kdint->mGenericIdx == -1) 2214 { 2215 kdint->mGenericIdx = (int)mColors.size(); 2216 mColors.push_back(RandomColor()); 2217 } 2218 color = mColors[kdint->mGenericIdx]; 2219 } 2220 else 2221 { 2222 color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1)); 2223 } 2224 2225 glColor3f(color.r, color.g, color.b); 2226 2227 mUseForcedColors = true; 2228 RenderIntersectable(object); 2229 mUseForcedColors = false; 2230 } 2231 } 2232 2233 } -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r2604 r2609 109 109 void SetRandomViewPoint(); 110 110 void StoreStatistics(); 111 void LoadObject(); 111 112 void UpdateAllPvs(); 112 113 void SetViewCellGranularity(int); … … 224 225 bool mUseRandomColorPerPvsObject; 225 226 227 DynamicObjectsContainer mDynamicObjects; 228 226 229 QtGlRendererWidget(SceneGraph *sceneGraph, 227 230 ViewCellsManager *viewcells, … … 270 273 SetupCameraProjection(const int w, const int h, const float angle = 70.0f); 271 274 272 void 273 RenderViewCells(); 274 275 276 virtual void Show() { 277 show(); 278 } 275 void RenderViewCells(); 276 277 virtual void Show() { show(); } 279 278 280 279 bool PvsChanged(ViewCell *viewcell) const; … … 300 299 301 300 ///////// 302 303 301 //QMutex mMutex; 304 302 … … 311 309 void SetRandomViewPoint(); 312 310 void StoreStatistics(); 311 void LoadObject(); 313 312 314 313 void SetRenderErrors(bool b) { … … 517 516 } 518 517 518 void PreparePvs(); 519 519 520 void _RenderPvs(); 520 521 void _UpdatePvsIndices(); 521 /** Render pvs using false colors. 522 */ 523 void _RenderColoredPvs(); 522 524 523 525 void _UpdatePvsIndices(KdNode *node, int &indexBufferSize); … … 569 571 570 572 #endif 571 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
r2605 r2609 177 177 178 178 glLoadIdentity(); 179 gluLookAt(0.0f, 0.0f, 1 0.0f, // eye is at (0,0,30)179 gluLookAt(0.0f, 0.0f, 15.0f, // eye is at (0,0,30) 180 180 0.0f, 0.0f, 0.0f, // center is at (0,0,0) 181 181 0.0f, 1.0f, 0.0f); // up is in positive Y direction … … 191 191 glTranslatef(t.x, t.y, t.z); 192 192 193 /*mDummyViewPoint = -t; 194 mDummyViewPoint /= s; 195 193 //mDummyViewPoint = -t; 194 //mDummyViewPoint /= s; 196 195 //glGetFloatv(GL_MODELVIEW_MATRIX, m1); 197 */ 196 198 197 m.Invert(); 199 198 … … 243 242 QtGlViewer::mouseMoveEvent(QMouseEvent *event) 244 243 { 245 int dx = event->x() +lastPos.x();246 int dy = event->y() +lastPos.y();244 int dx = event->x() - lastPos.x(); 245 int dy = event->y() - lastPos.y(); 247 246 248 247 if (event->modifiers() & Qt::CTRL) -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp
r2176 r2609 227 227 } 228 228 229 void 230 Ray::Init(const VssRay &vssRay)231 { 232 233 234 235 236 237 238 239 len = Limits::Small;240 241 242 243 244 if (vssRay.mTerminationObject) 245 i ntersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0));246 247 248 249 } 250 251 } 229 230 void Ray::Init(const VssRay &vssRay) 231 { 232 loc = vssRay.mOrigin; 233 sourceObject = Intersection(0, vssRay.GetDir(), vssRay.mOriginObject, 0); 234 mType = LOCAL_RAY; 235 236 float len = vssRay.Length(); 237 238 if (!len) 239 len = Limits::Small; 240 241 dir = vssRay.GetDir() / len; 242 243 intersections.clear(); 244 245 if (vssRay.mTerminationObject) 246 intersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0)); 247 248 Precompute(); 249 } 250 251 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r2575 r2609 38 38 struct Intersection 39 39 { 40 /// the point of intersection41 float mT;42 43 /// the normal of the intersection44 Vector3 mNormal;45 46 /// can be either mesh or a viewcell47 Intersectable *mObject;48 49 /// the face of the intersectable50 int mFace;51 52 40 Intersection(const float t, 53 41 const Vector3 &normal, … … 59 47 Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0) 60 48 {} 61 49 50 51 /// the point of intersection 52 float mT; 53 /// the normal of the intersection 54 Vector3 mNormal; 55 /// can be either mesh or a viewcell 56 Intersectable *mObject; 57 /// the face of the intersectable 58 int mFace; 59 60 62 61 bool operator<(const Intersection &b) const 63 62 { … … 69 68 // I should have some abstract cell data type !!! here 70 69 // corresponds to the spatial elementary cell 71 /** intersection with the source object if any */ 70 71 /// intersection with the source object if any 72 72 Intersection sourceObject; 73 73 74 74 std::vector<Intersection> intersections; 75 // std::vector<BspIntersection> bspIntersections;76 75 std::vector<KdLeaf *> kdLeaves; 77 76 std::vector<Intersectable *> testedObjects; … … 84 83 // constructors 85 84 Ray(const Vector3 &wherefrom, 86 const Vector3 &whichdir, 87 const int _type):mFlags(CULL_BACKFACES) { 88 loc = wherefrom; 89 if (_type == LINE_SEGMENT) 90 dir = whichdir; 91 else 92 dir = Normalize(whichdir); 93 mType = _type; 94 depth = 0; 95 Init(); 96 } 85 const Vector3 &whichdir, 86 const int _type): mFlags(CULL_BACKFACES) 87 { 88 loc = wherefrom; 89 if (_type == LINE_SEGMENT) 90 dir = whichdir; 91 else 92 dir = Normalize(whichdir); 93 mType = _type; 94 depth = 0; 95 Init(); 96 } 97 97 98 // dummy constructor 98 99 Ray() {} … … 100 101 /** Construct ray from a vss ray. 101 102 */ 102 Ray(const VssRay &vssRay) { 103 Init(vssRay); 104 mFlags |= CULL_BACKFACES; 103 Ray(const VssRay &vssRay) 104 { 105 Init(vssRay); 106 mFlags |= CULL_BACKFACES; 105 107 } 106 108 … … 130 132 const Vector3 &whichdir, 131 133 const int _type, 132 bool dirNormalized = false) { 133 loc = wherefrom; 134 dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ; 135 mType = _type; 136 depth = 0; 137 Init(); 138 Precompute(); 134 bool dirNormalized = false) 135 { 136 loc = wherefrom; 137 dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ; 138 mType = _type; 139 depth = 0; 140 Init(); 141 Precompute(); 139 142 } 140 143 … … 253 256 int mType; 254 257 255 256 258 // unique ID of a ray for the use in the mailboxes 257 259 int ID; -
GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
r2601 r2609 276 276 } 277 277 278 } 278 279 void SceneGraphLeaf::Transform(const Matrix4x4 &trafo) 280 { 281 mTrafo *= trafo; 282 } 283 284 } -
GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h
r2606 r2609 5 5 #include "Containers.h" 6 6 #include "AxisAlignedBox3.h" 7 7 #include "Matrix4x4.h" 8 8 9 9 namespace GtpVisibilityPreprocessor { … … 37 37 virtual void UpdateBox(); 38 38 39 ~SceneGraphInterior();40 41 39 //protected: 42 40 … … 51 49 public: 52 50 51 SceneGraphLeaf(bool isDynamic = false): 52 mIsDynamic(isDynamic){} 53 ~SceneGraphLeaf(); 54 55 virtual void Transform(const Matrix4x4 &trafo); 56 virtual bool IsDynamic() const { return mIsDynamic;} 53 57 virtual bool IsLeaf() const { return true; } 54 58 virtual void UpdateBox(); 55 59 56 ~SceneGraphLeaf();60 ObjectContainer mGeometry; 57 61 58 //protected:62 protected: 59 63 60 //MeshContainer mGeometry;61 ObjectContainer mGeometry;64 bool mIsDynamic; 65 Matrix4x4 mTrafo; 62 66 }; 63 67 64 68 65 69 66 /** Scene graph class */ 67 class SceneGraph { 70 /** Scene graph class 71 */ 72 class SceneGraph 73 { 68 74 69 75 public: … … 81 87 82 88 AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 83 84 89 /** Exports binary version of the scene. 85 90 */ 86 91 void ExportScene(const std::string filename); 87 88 92 /** Loads binary version of the scene. 89 93 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r2017 r2609 2822 2822 { 2823 2823 VssRay *ray = rays[i]; 2824 #if VSS_STORE_VIEWCELLS 2824 2825 2825 2826 // traverse leaves stored in the rays and compare and … … 2875 2876 candidates.push_back(mc); 2876 2877 2877 if (( (int)candidates.size() % 1000) == 0)2878 if ((candidates.size() % 1000) == 0) 2878 2879 { 2879 2880 cout << "collected " << (int)candidates.size() << " merge candidates" << endl; … … 2881 2882 } 2882 2883 } 2884 #endif 2883 2885 } 2884 2886 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2606 r2609 368 368 const bool isTermination) const 369 369 { 370 #if DYNAMIC_OBJECTS_HACK 371 if (ray.mTerminationObject->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 372 return ray.mTerminationObject; 373 #endif 370 374 if (mUseKdPvs) 371 375 { … … 2483 2487 const bool useHitObjects) 2484 2488 { 2485 if (!useHitObjects) 2486 { 2487 // store higher order object (e.g., bvh node) instead of object itself 2488 VssRayContainer::const_iterator it, it_end = rays.end(); 2489 2490 for (it = rays.begin(); it != it_end; ++ it) 2491 { 2492 VssRay *vssRay = *it; 2493 2494 // set only the termination object 2495 // if (vssRay->mTerminationObject == NULL) 2496 // cerr<<"Error NULL termination object!"<<endl; 2497 vssRay->mTerminationObject = GetIntersectable(*vssRay, true); 2489 if (!useHitObjects) 2490 { 2491 // store higher order object (e.g., bvh node) instead of object itself 2492 VssRayContainer::const_iterator it, it_end = rays.end(); 2493 2494 for (it = rays.begin(); it != it_end; ++ it) 2495 { 2496 VssRay *vssRay = *it; 2497 2498 // set only the termination object 2499 vssRay->mTerminationObject = GetIntersectable(*vssRay, true); 2498 2500 #if 0 2499 2501 if (vssRay->mTerminationObject == NULL) { -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r2575 r2609 3854 3854 { 3855 3855 VssRay *ray = rays[i]; 3856 3856 3857 #if VSS_STORE_VIEWCELLS 3857 3858 // traverse leaves stored in the rays and compare and 3858 3859 // merge consecutive leaves (i.e., the neighbors in the tree) … … 3913 3914 } 3914 3915 } 3916 #endif 3915 3917 } 3916 3918 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp
r2593 r2609 41 41 42 42 43 VssRay::VssRay(const Ray &ray): 44 mRefCount(0), 45 mFlags(0), 46 mMailbox(-1), 47 mOriginObject(ray.sourceObject.mObject), 48 mPass(0), 43 VssRay::VssRay(const Ray &ray) 44 { 45 Init(ray); 46 } 47 48 49 void VssRay::Init(const Ray &ray) 50 { 51 mRefCount = 0; 52 mFlags = 0; 53 mMailbox = -1; 54 mOriginObject = ray.sourceObject.mObject; 55 mPass = 0; 56 mPdf = 1.0f; 57 mTerminationNode = NULL; 58 mOriginNode = NULL; 59 mPvsContribution = 0; 60 49 61 #if VSS_STORE_VIEWCELLS 50 mViewCells(0), 51 #endif 52 mPdf(1.0f), 53 mTerminationNode(NULL), 54 mOriginNode(NULL), 55 mPvsContribution(0) 56 { 62 mViewCells.clear(); 63 #endif 64 57 65 if (ray.sourceObject.mObject) 58 66 mOrigin = ray.Extrap(ray.sourceObject.mT); … … 68 76 else 69 77 { 70 mTermination = ray.Extrap(1e6 ); //TODO: should be Limits::Infinity78 mTermination = ray.Extrap(1e6f); //TODO: should be Limits::Infinity 71 79 mTerminationObject = NULL; 72 80 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
r2593 r2609 20 20 21 21 #define ABS_CONTRIBUTION_WEIGHT 0.0f 22 #define VSS_STORE_VIEWCELLS 122 #define VSS_STORE_VIEWCELLS 0 23 23 24 24 … … 69 69 // sampling pass in which this ray was generated 70 70 short mPass; 71 72 71 /// Distribution used to generate this ray 73 72 short mDistribution; 74 75 73 /// number of cells where this ray made a contribution to the PVS 76 74 int mPvsContribution; 77 78 75 /// sum of relative ray contributions per object 79 76 float mRelativePvsContribution; 80 81 /// weighted contribution to the pvs (based on the pass the ray was casted at) 82 /// computed by the prperocessor77 /** weighted contribution to the pvs (based on the pass the ray was casted at) 78 ccomputed by the prperocessor 79 */ 83 80 float mWeightedPvsContribution; 84 85 81 /// probability of this ray 86 82 float mPdf; … … 107 103 VssRay(const Ray &ray); 108 104 109 105 void Init(const Ray &ray); 106 110 107 void Precompute(); 111 108 -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
r2600 r2609 234 234 { 235 235 /////////////////// 236 //-- load data as single trianglesinstead of whole meshes236 //-- load data as triangle soup instead of whole meshes 237 237 238 238 cout << "m"; -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r2603 r2609 23 23 #include <vector> 24 24 25 25 #define DYNAMIC_OBJECTS_HACK 1 26 26 #define USE_HAVRAN_RAYCASTER 27 27
Note: See TracChangeset
for help on using the changeset viewer.