Changeset 2538 for GTP/trunk/Lib/Vis
- Timestamp:
- 07/09/07 09:58:07 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h
r2455 r2538 98 98 virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0; 99 99 100 /** Collects leaves that are visible by some algorithm, e.g., view frustum culling. 101 */ 102 virtual void CollectVisibleLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0; 103 100 104 virtual void RenderNodeRecursive(HierarchyNode *node) = 0; 101 105 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp
r2532 r2538 106 106 int nodesTested = 0; 107 107 108 // use different algorithm for findingrandom candidates108 // use different algorithm to find random candidates 109 109 #if 1 110 110 HierarchyNodeContainer mynodes; -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r2530 r2538 1417 1417 "50"); 1418 1418 1419 RegisterOption("ViewCells.renderCostEvaluationType",1420 optString,1421 "view_cells_render_cost_evaluation=",1422 "perobject");1423 1424 1419 RegisterOption("ViewCells.active", 1425 1420 optInt, -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2530 r2538 33 33 const int depthMapSize = 512; 34 34 35 35 36 static void InitExtensions() 36 37 { … … 49 50 if (GLEW_NV_occlusion_query) 50 51 nvQuerySupport = true; 51 52 52 53 53 if (!arbQuerySupport && !nvQuerySupport) … … 55 55 cout << "I require the GL_ARB_occlusion_query or the GL_NV_occlusion_query OpenGL extension to work.\n"; 56 56 exit(1); 57 } 58 59 if (!GLEW_ARB_vertex_buffer_object) 60 { 61 cout << "vbos not supported" << endl; 62 } 63 else 64 { 65 cout << "vbos supported" << endl; 57 66 } 58 67 } … … 64 73 Renderer(sceneGraph, viewCellsManager), 65 74 mKdTree(tree), 66 mUseFalseColors(false) 75 mUseFalseColors(false), 76 mVboId(-1), 77 mData(NULL), 78 mIndices(NULL), 79 mUseVbos(true) 80 //mUseVbos(false) 67 81 { 68 82 mSceneGraph->CollectObjects(&mObjects); … … 90 104 mUseForcedColors = false; 91 105 mRenderBoxes = false; 92 //mUseGlLists = true;93 mUseGlLists = false;106 mUseGlLists = true; 107 //mUseGlLists = false; 94 108 95 109 if (mViewCellsManager->GetViewCellPoints()->size()) … … 103 117 } 104 118 119 105 120 GlRenderer::~GlRenderer() 106 121 { 107 122 cerr<<"gl renderer destructor..\n"; 108 123 109 //CLEAR_CONTAINER(sQueries);110 124 CLEAR_CONTAINER(mOcclusionQueries); 111 125 126 DeleteVbos(); 127 128 if (mData) delete [] mData; 129 if (mIndices) delete [] mIndices; 130 131 glDeleteBuffersARB(1, &mVboId); 112 132 cerr<<"done."<<endl; 113 133 } … … 338 358 339 359 OcclusionQuery::GenQueries(mOcclusionQueries, 10); 360 361 CreateVertexArrays(); 340 362 } 341 363 … … 373 395 GlRenderer::_RenderScene() 374 396 { 375 ObjectContainer::const_iterator oi = mObjects.begin(); 376 for (; oi != mObjects.end(); oi++) 377 RenderIntersectable(*oi); 378 } 379 380 void 381 GlRenderer::_RenderSceneTriangles() 382 { 383 glBegin(GL_TRIANGLES); 384 385 ObjectContainer::const_iterator oi = mObjects.begin(); 386 for (; oi != mObjects.end(); oi++) { 387 388 if ((*oi)->Type() == Intersectable::TRIANGLE_INTERSECTABLE) { 389 TriangleIntersectable *object = (TriangleIntersectable *)*oi; 390 Triangle3 &t = object->GetItem(); 391 392 Vector3 normal = t.GetNormal(); 393 glNormal3f(normal.x, normal.y, normal.z); 394 glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 395 glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 396 glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 397 398 } 399 } 400 401 glEnd(); 402 403 } 397 ObjectContainer::const_iterator oi = mObjects.begin(); 398 for (; oi != mObjects.end(); oi++) 399 RenderIntersectable(*oi); 400 } 401 402 void GlRenderer::_RenderSceneTrianglesWithDrawArrays() 403 { 404 EnableDrawArrays(); 405 406 if (mUseVbos) 407 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 408 409 int offset = mObjects.size() * 3; 410 char *arrayPtr = mUseVbos ? NULL : (char *)mData; 411 412 glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr); 413 glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 414 415 glDrawArrays(GL_TRIANGLES, 0, mObjects.size() * 3); 416 //DisableDrawArrays(); 417 } 418 419 420 void GlRenderer::_RenderSceneTriangles() 421 { 422 glBegin(GL_TRIANGLES); 423 424 ObjectContainer::const_iterator oi = mObjects.begin(); 425 for (; oi != mObjects.end(); oi++) { 426 427 if ((*oi)->Type() == Intersectable::TRIANGLE_INTERSECTABLE) { 428 TriangleIntersectable *object = (TriangleIntersectable *)*oi; 429 Triangle3 &t = object->GetItem(); 430 431 Vector3 normal = t.GetNormal(); 432 glNormal3f(normal.x, normal.y, normal.z); 433 glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 434 glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 435 glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 436 437 } 438 } 439 440 glEnd(); 441 } 442 404 443 405 444 bool … … 407 446 { 408 447 Intersectable::NewMail(); 448 449 #if 1 450 451 _RenderSceneTrianglesWithDrawArrays(); 452 453 #else 409 454 static int glList = -1; 410 455 if (mUseGlLists) { … … 420 465 _RenderSceneTriangles(); 421 466 422 467 #endif 423 468 return true; 424 469 } … … 426 471 427 472 void 428 GlRendererBuffer::EvalQueryWithItemBuffer( 429 //RenderCostSample &sample 430 ) 473 GlRendererBuffer::EvalQueryWithItemBuffer() 431 474 { 432 475 // read back the texture … … 466 509 KdTree *tree): 467 510 GlRenderer(sceneGraph, viewcells, tree) 468 { 469 470 mPixelBuffer = NULL; 471 511 { 512 mPixelBuffer = NULL; 472 513 // implement width and height in subclasses 473 514 } … … 683 724 RenderBvhNode(in->GetFront()); 684 725 } 685 686 //cout << "leaf obj " << i << endl;687 688 726 } 689 727 … … 691 729 GlRenderer::RenderKdNode(KdNode *node) 692 730 { 693 if (node->IsLeaf()) { 694 KdLeaf *leaf = (KdLeaf *) node; 695 for (int i=0; i < leaf->mObjects.size(); i++) { 696 RenderIntersectable(leaf->mObjects[i]); 697 } 698 } else { 699 KdInterior *in = (KdInterior *)node; 700 RenderKdNode(in->mBack); 701 RenderKdNode(in->mFront); 702 } 703 704 } 705 706 707 731 if (node->IsLeaf()) 732 { 733 #if 1 734 RenderKdLeaf(static_cast<KdLeaf *>(node)); 735 #else 736 KdLeaf *leaf = (KdLeaf *)node; 737 for (int i=0; i < leaf->mObjects.size(); i++) 738 { 739 RenderIntersectable(leaf->mObjects[i]); 740 } 741 #endif 742 } 743 else 744 { 745 KdInterior *in = (KdInterior *)node; 746 RenderKdNode(in->mBack); 747 RenderKdNode(in->mFront); 748 } 749 } 708 750 709 751 … … 814 856 #endif 815 857 #endif 858 816 859 } 817 860 … … 1126 1169 { 1127 1170 mOcclusionQueries[queryIdx ++]->BeginQuery(); 1128 1129 1171 RenderIntersectable(*vit); 1130 1131 1172 mOcclusionQueries[queryIdx]->EndQuery(); 1132 1173 … … 1519 1560 GlRenderer::RenderViewPoint() 1520 1561 { 1521 mWireFrame = true; 1522 glPushMatrix(); 1523 glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 1524 glScalef(5.0f,5.0f,5.0f); 1525 glPushAttrib(GL_CURRENT_BIT); 1526 glColor3f(1.0f, 0.0f, 0.0f); 1527 gluSphere((::GLUquadric *)mSphere, 1528 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 1529 glPopAttrib(); 1530 glPopMatrix(); 1531 mWireFrame = false; 1532 } 1533 1534 1535 1536 1537 1538 } 1562 mWireFrame = true; 1563 glPushMatrix(); 1564 glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 1565 glScalef(5.0f,5.0f,5.0f); 1566 glPushAttrib(GL_CURRENT_BIT); 1567 glColor3f(1.0f, 0.0f, 0.0f); 1568 gluSphere((::GLUquadric *)mSphere, 1569 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 1570 glPopAttrib(); 1571 glPopMatrix(); 1572 mWireFrame = false; 1573 } 1574 1575 1576 void GlRenderer::EnableDrawArrays() 1577 { 1578 glEnableClientState(GL_VERTEX_ARRAY); 1579 glEnableClientState(GL_NORMAL_ARRAY); 1580 } 1581 1582 1583 void GlRenderer::DisableDrawArrays() 1584 { 1585 glDisableClientState(GL_VERTEX_ARRAY); 1586 glDisableClientState(GL_NORMAL_ARRAY); 1587 } 1588 1589 1590 #if 0 1591 1592 void GlRenderer::RenderKdLeaf(KdLeaf *leaf) 1593 { 1594 int bufferSize = 0; 1595 1596 // count #new triangles 1597 for (size_t i = 0; i < leaf->mObjects.size(); ++ i) 1598 { 1599 TriangleIntersectable *obj = static_cast<TriangleIntersectable *>(leaf->mObjects[i]); 1600 1601 // check if already rendered 1602 if (!obj->Mailed()) 1603 bufferSize += 3; 1604 //else cout << obj->mMailbox << " " << obj->sMailId << " "; 1605 } 1606 1607 Vector3 *vertices = new Vector3[bufferSize]; 1608 Vector3 *normals = new Vector3[bufferSize]; 1609 1610 int j = 0; 1611 1612 for (size_t i = 0; i < leaf->mObjects.size(); ++ i) 1613 { 1614 TriangleIntersectable *obj = static_cast<TriangleIntersectable *>(leaf->mObjects[i]); 1615 1616 // check if already rendered 1617 if (obj->Mailed()) 1618 continue; 1619 1620 obj->Mail(); 1621 1622 Triangle3 tri = obj->GetItem(); 1623 1624 vertices[j * 3 + 0] = tri.mVertices[0]; 1625 vertices[j * 3 + 1] = tri.mVertices[1]; 1626 vertices[j * 3 + 2] = tri.mVertices[2]; 1627 1628 Vector3 n = tri.GetNormal(); 1629 1630 normals[j * 3 + 0] = n; 1631 normals[j * 3 + 1] = n; 1632 normals[j * 3 + 2] = n; 1633 1634 ++ j; 1635 } 1636 1637 glVertexPointer(3, GL_FLOAT, 0, vertices); 1638 glNormalPointer(GL_FLOAT, 0, normals); 1639 1640 glDrawArrays(GL_TRIANGLES, 0, bufferSize); 1641 1642 DEL_PTR(vertices); 1643 DEL_PTR(normals); 1644 } 1645 1646 #else 1647 1648 void GlRenderer::RenderKdLeaf(KdLeaf *leaf) 1649 { 1650 if (!leaf->mIndexBufferSize) 1651 return; 1652 1653 unsigned int offset = mObjects.size() * 3; 1654 char *arrayPtr = mUseVbos ? NULL : (char *)mData; 1655 1656 glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr); 1657 glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 1658 1659 glDrawElements(GL_TRIANGLES, leaf->mIndexBufferSize, GL_UNSIGNED_INT, mIndices + leaf->mIndexBufferStart); 1660 } 1661 1662 #endif 1663 1664 void GlRenderer::CreateVertexArrays() 1665 { 1666 mData = new Vector3[mObjects.size() * 6]; 1667 mIndices = new unsigned int[mObjects.size() * 3]; 1668 1669 const int offset = mObjects.size() * 3; 1670 1671 for (size_t i = 0; i < mObjects.size(); ++ i) 1672 { 1673 TriangleIntersectable *obj = static_cast<TriangleIntersectable *>(mObjects[i]); 1674 1675 Triangle3 tri = obj->GetItem(); 1676 const Vector3 n = tri.GetNormal(); 1677 1678 mData[i * 3 + 0] = tri.mVertices[0]; 1679 mData[i * 3 + 1] = tri.mVertices[1]; 1680 mData[i * 3 + 2] = tri.mVertices[2]; 1681 1682 mData[offset + i * 3 + 0] = n; 1683 mData[offset + i * 3 + 1] = n; 1684 mData[offset + i * 3 + 2] = n; 1685 } 1686 1687 if (mUseVbos) 1688 { 1689 EnableDrawArrays(); 1690 1691 glGenBuffersARB(1, &mVboId); 1692 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 1693 1694 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 1695 glNormalPointer(GL_FLOAT, 0, (char *)NULL + offset * sizeof(Vector3)); 1696 1697 glBufferDataARB(GL_ARRAY_BUFFER_ARB, mObjects.size() * 6 * sizeof(Vector3), mData, GL_STATIC_DRAW_ARB); 1698 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 1699 1700 DisableDrawArrays(); 1701 1702 delete [] mData; 1703 } 1704 1705 cout << "\n**************\ndraw arrays created\n" << endl; 1706 } 1707 1708 1709 void GlRenderer::DeleteVbos() 1710 { 1711 glDeleteBuffersARB(1, &mVboId); 1712 1713 /* 1714 KdLeafContainer leaves; 1715 mKdTree->CollectLeaves(leaves); 1716 1717 KdLeafContainer::const_iterator kit, kit_end = leaves.end(); 1718 1719 for (kit = leaves.begin(); kit != kit_end; ++ kit) 1720 { 1721 KdLeaf *leaf = *kit; 1722 1723 if (leaf->mVboId == -1) 1724 { 1725 // delete old vbo 1726 glDeleteBuffersARB(1, &leaf->mVboId); 1727 leaf->mVboId = -1; 1728 } 1729 } 1730 */ 1731 } 1732 1733 1734 1735 } -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
r2176 r2538 59 59 60 60 struct PvsCache { 61 PvsCache():mViewCell(NULL) {} 62 void Reset() { mViewCell = NULL; mPvs.Clear(); filteredBoxes.clear(); } 61 62 PvsCache():mViewCell(NULL), mUnfilteredPvsSize(0) {} 63 64 void Reset() 65 { 66 mViewCell = NULL; mPvs.Clear(); 67 filteredBoxes.clear(); 68 mUnfilteredPvsSize = 0; 69 } 70 63 71 ViewCell *mViewCell; 64 72 ObjectPvs mPvs; 73 int mUnfilteredPvsSize; 65 74 vector<AxisAlignedBox3> filteredBoxes; 66 75 }; … … 94 103 class GlRenderer: public Renderer 95 104 { 105 friend class GlobalLinesRenderer; 106 friend class ViewCellsManager; 96 107 97 108 public: … … 141 152 _RenderSceneTriangles(); 142 153 154 void _RenderSceneTrianglesWithDrawArrays(); 155 143 156 void 144 157 RenderViewPoint(); … … 197 210 Vector3 mDirection; 198 211 }; 199 friend class GlobalLinesRenderer;200 friend class ViewCellsManager;201 212 202 213 vector<PvsErrorEntry> mPvsErrorBuffer; … … 204 215 protected: 205 216 206 207 208 PvsCache mPvsCache; 209 210 vector<OcclusionQuery *> mOcclusionQueries; 211 212 ObjectContainer mObjects; 213 214 Vector3 mViewPoint; 215 Vector3 mViewDirection; 216 217 int timerId; 218 bool mUseFalseColors; 219 bool mUseForcedColors; 220 221 HaltonSequence halton; 222 223 224 bool mDetectEmptyViewSpace; 225 bool mSnapErrorFrames; 226 227 bool mRenderBoxes; 228 229 bool mUseGlLists; 230 231 std::string mSnapPrefix; 232 233 GLUquadric *mSphere; 234 235 KdTree *mKdTree; 236 237 }; 217 void CreateVertexArrays(); 218 void DeleteVbos(); 219 void EnableDrawArrays(); 220 void DisableDrawArrays(); 221 222 void RenderKdLeaf(KdLeaf *leaf); 223 224 225 ////////////////// 226 227 PvsCache mPvsCache; 228 229 unsigned int mVboId; 230 vector<OcclusionQuery *> mOcclusionQueries; 231 232 ObjectContainer mObjects; 233 234 Vector3 mViewPoint; 235 Vector3 mViewDirection; 236 237 int timerId; 238 bool mUseFalseColors; 239 bool mUseForcedColors; 240 241 HaltonSequence halton; 242 243 244 bool mDetectEmptyViewSpace; 245 bool mSnapErrorFrames; 246 247 bool mRenderBoxes; 248 249 bool mUseGlLists; 250 251 std::string mSnapPrefix; 252 253 GLUquadric *mSphere; 254 255 KdTree *mKdTree; 256 257 Vector3 *mData; 258 unsigned int *mIndices; 259 260 bool mUseVbos; 261 }; 262 238 263 239 264 /* Class implementing an OpenGl render buffer. … … 268 293 */ 269 294 virtual void SampleRenderCost(const int numSamples, 270 vector<RenderCostSample> &samples, 271 const bool useOcclusionQueries, 272 const int threshold = 0); 273 274 295 vector<RenderCostSample> &samples, 296 const bool useOcclusionQueries, 297 const int threshold = 0); 275 298 /** Implerment in subclasses. 276 299 */ … … 288 311 289 312 virtual void SampleBeamContributions( 290 Intersectable *sourceObject, 291 Beam &beam, 292 const int samples, 293 BeamSampleStatistics &stat 294 ); 295 296 virtual void 297 SampleViewpointContributions( 298 Intersectable *sourceObject, 299 const Vector3 viewPoint, 300 Beam &beam, 301 const int desiredSamples, 302 BeamSampleStatistics &stat 303 ); 313 Intersectable *sourceObject, 314 Beam &beam, 315 const int samples, 316 BeamSampleStatistics &stat 317 ); 318 319 virtual void SampleViewpointContributions( 320 Intersectable *sourceObject, 321 const Vector3 viewPoint, 322 Beam &beam, 323 const int desiredSamples, 324 BeamSampleStatistics &stat 325 ); 304 326 305 327 virtual void InitGL(); 306 307 328 /** Computes rays from information gained with hw sampling- 308 329 */ … … 321 342 322 343 virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint, 323 const Beam &beam, 324 325 Intersectable *sourceObject); 326 344 const Beam &beam, 345 Intersectable *sourceObject); 327 346 /** Evaluates query for one direction using item buffer. 328 347 */ 329 348 virtual void EvalQueryWithItemBuffer(); 330 331 349 /** Evaluates query for one direction using occlusion queries. 332 350 */ 333 351 virtual void EvalQueryWithOcclusionQueries(); 334 335 public:336 // matt: remove qt dependencies337 // signals:338 // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);339 352 }; 340 353 … … 353 366 354 367 virtual ~GlRendererWidget() {} 355 356 //virtual void Create() {} 368 357 369 virtual void Show() {} 358 359 360 protected: 361 362 363 // SceneGraph *mSceneGraph; 364 // ViewCellsManager *mViewCellsManager; 365 // KdTree *mKdTree; 366 }; 367 368 //extern GlRendererWidget *rendererWidget; 370 }; 371 369 372 370 373 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.cpp
r2231 r2538 28 28 { 29 29 case MESH_INSTANCE: 30 return "mesh_instance\n"; 31 30 return "mesh instance"; 32 31 case TRANSFORMED_MESH_INSTANCE: 33 return "transformed_mesh_instance\n"; 34 32 return "transformed mesh instance"; 35 33 case SPHERE: 36 return "sphere\n"; 37 34 return "sphere"; 38 35 case VIEW_CELL: 39 return "view cell\n"; 40 36 return "view cell"; 41 37 case OGRE_MESH_INSTANCE: 42 return "ogre_mesh_instance\n"; 43 38 return "ogre_mesh_instance"; 44 39 case KD_INTERSECTABLE: 45 return "kd_intersectable\n"; 46 40 return "kd"; 41 case TRIANGLE_INTERSECTABLE: 42 return "triangle"; 43 case BVH_INTERSECTABLE: 44 return "bvh"; 47 45 default: 48 return "unknown \n";46 return "unknown"; 49 47 } 50 48 } -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
r2176 r2538 160 160 { 161 161 public: 162 AxisAlignedBox3 mBox;163 164 162 KdIntersectable(KdNode *item, const AxisAlignedBox3 &box); 165 163 … … 173 171 return mBox; 174 172 } 173 174 /// the bounding box of this intersectable 175 AxisAlignedBox3 mBox; 175 176 }; 176 177 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r2524 r2538 183 183 public: 184 184 KdLeaf(KdInterior *parent, const int objects): 185 KdNode(parent), mViewCell(NULL) {185 KdNode(parent), mViewCell(NULL), mVboId(-1), mIndexBufferStart(0), mIndexBufferSize(0) { 186 186 mObjects.reserve(objects); 187 187 } … … 209 209 /// pointers to occluders contained in this node 210 210 ObjectContainer mObjects; 211 212 211 /// Ray set description of the rays passing through this node 213 212 PassingRaySet mPassingRays; 214 215 /// PVS consisting of visible KdTree nodes216 //KdPvs mKdPvs;217 218 /// pvs of view cells seeing this node.219 SubdivisionCandidate *mSubdivisionCandidate;220 221 213 /// pointer to view cell. 222 214 KdViewCell *mViewCell; 223 215 /// rays intersecting this leaf 224 216 VssRayContainer mVssRays; 225 226 217 /// Objects that are referenced in more than one leaf. 227 218 ObjectContainer mMultipleObjects; 228 229 219 /// universal counter 230 220 int mCounter; 221 222 /// hack 223 unsigned int mVboId; 224 225 unsigned int mIndexBufferStart; 226 unsigned int mIndexBufferSize; 231 227 }; 232 228 … … 342 338 343 339 /** Returns or creates a new intersectable for use in a kd based pvs. 344 The OspTree is responsible for destruction of the intersectable.345 340 */ 346 341 KdIntersectable *GetOrCreateKdIntersectable(KdNode *node); … … 348 343 349 344 void 350 SetPvsTerminationNodes( 351 const float maxArea); 345 SetPvsTerminationNodes(const float maxArea); 352 346 353 347 KdNode * -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h
r2224 r2538 377 377 const Vector3 &termination, 378 378 ViewCellContainer &viewcells); 379 380 379 /** Sets pointer to view cells manager. 381 380 */ 382 381 void SetViewCellsManager(ViewCellsManager *vcm); 383 384 382 /** Writes tree to output stream 385 383 */ 386 384 bool Export(OUT_STREAM &stream); 387 388 385 /** Returns or creates a new intersectable for use in a kd based pvs. 389 386 The OspTree is responsible for destruction of the intersectable. 390 387 */ 391 388 KdIntersectable *GetOrCreateKdIntersectable(KdNode *node); 392 393 389 /** Collects rays stored in the leaves. 394 390 */ 395 391 void CollectRays(VssRayContainer &rays); 396 397 392 /** Intersects box with the tree and returns the number of intersected boxes. 398 393 @returns number of view cells found -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r2530 r2538 123 123 EnableFiberSafeOptimizations="TRUE" 124 124 WholeProgramOptimization="FALSE" 125 OptimizeForProcessor=" 3"125 OptimizeForProcessor="2" 126 126 OptimizeForWindowsApplication="TRUE" 127 127 AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;"$(QTDIR)\include\QtCore";"$(QTDIR)\include\QtGui";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";"$(CG_INC_PATH)";Timer;..\src\sparsehash\src\google\sparsehash;..\src\sparsehash\src\windows;..\src\sparsehash\src\google;..\src\sparsehash\src;..\src\ootl\;..\src\ootl\src\;..\src\ootl\src\cpp;..\src\ootl\src\cpp\include\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;..\src\ootl\src\cpp\include\ootl\mswin" -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
r2530 r2538 15 15 #include "QtPreprocessorThread.h" 16 16 #include "Material.h" 17 #include "IntersectableWrapper.h" 18 17 19 18 20 #define USE_CG 1 … … 109 111 110 112 ObjectPvs pvs; 111 if (1) { 112 pvs = viewcell->GetPvs(); 113 } else { 114 mViewCellsManager->ApplyFilter2(viewcell, 115 false, 116 1.0f, 117 pvs); 118 } 113 114 if (1) 115 pvs = viewcell->GetPvs(); 116 else 117 mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs); 119 118 120 119 // cout<<"pvs size"<<pvs.GetSize()<<endl<<flush; … … 128 127 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 129 128 130 // //Render PVS129 // Render PVS 131 130 ObjectPvsIterator it = pvs.GetIterator(); 132 131 … … 349 348 350 349 351 352 void 353 QtGlRendererWidget::RenderPvs() 354 { 350 bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const 351 { 352 if (viewCell != mPvsCache.mViewCell) 353 return true; 354 355 if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize) 356 return true; 357 358 return false; 359 } 360 361 362 void QtGlRendererWidget::_RenderPvs() 363 { 364 mUseFalseColors = false; 365 366 int offset = mObjects.size() * 3; 367 char *arrayPtr = mUseVbos ? NULL : (char *)mData; 355 368 356 Intersectable::NewMail(); 357 358 ViewCell *viewcell = NULL; 359 360 if (mDetectEmptyViewSpace) 361 glEnable( GL_CULL_FACE ); 362 else 363 glDisable( GL_CULL_FACE ); 364 365 viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 366 367 if (viewcell) { 368 // copy the pvs so that it can be filtered... 369 370 // mPvsCache.mPvs; 371 372 if (mPvsCache.mViewCell != viewcell) { 373 mPvsCache.Reset(); 374 mPvsCache.mViewCell = viewcell; 375 376 if (mUseSpatialFilter) { 377 // 9.11. 2006 -> experiment with new spatial filter 369 glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr); 370 glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 371 glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); 372 } 373 374 375 void QtGlRendererWidget::_UpdatePvsIndices() 376 { 377 mIndexBufferSize = 0; 378 KdNode::NewMail(); 379 380 mPvsSize = mPvsCache.mPvs.GetSize(); 381 382 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 383 384 for (; it.HasMoreEntries(); ) 385 { 386 Intersectable *obj = it.Next(); 387 KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 388 _UpdatePvsIndices(node); 389 } 390 } 391 392 393 void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node) 394 { 395 if (node->Mailed()) 396 return; 397 398 node->Mail(); 399 400 if (!node->IsLeaf()) 401 { 402 KdInterior *in = static_cast<KdInterior *>(node); 403 404 _UpdatePvsIndices(in->mBack); 405 _UpdatePvsIndices(in->mFront); 406 } 407 else 408 { 409 KdLeaf *leaf = static_cast<KdLeaf *>(node); 410 411 leaf->mIndexBufferStart = mIndexBufferSize; 412 413 for (size_t i = 0; i < leaf->mObjects.size(); ++ i) 414 { 415 TriangleIntersectable *obj = 416 static_cast<TriangleIntersectable *>(leaf->mObjects[i]); 417 418 // check if already rendered 419 if (!obj->Mailed()) 420 { 421 obj->Mail(); 422 423 mIndices[mIndexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; 424 mIndices[mIndexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; 425 mIndices[mIndexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; 426 427 mIndexBufferSize += 3; 428 } 429 } 430 431 leaf->mIndexBufferSize = mIndexBufferSize - leaf->mIndexBufferStart; 432 } 433 } 434 435 436 void QtGlRendererWidget::RenderPvs() 437 { 438 if (mUseVbos) 439 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 440 441 EnableDrawArrays(); 442 443 Intersectable::NewMail(); 444 ViewCell *viewcell = NULL; 445 446 if (mDetectEmptyViewSpace) 447 glEnable(GL_CULL_FACE); 448 else 449 glDisable(GL_CULL_FACE); 450 451 viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 452 453 if (viewcell) 454 { 455 // copy the pvs so that it can be filtered... 456 if (PvsChanged(viewcell)) 457 { 458 mPvsCache.Reset(); 459 mPvsCache.mViewCell = viewcell; 460 mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize(); 461 462 if (mUseSpatialFilter) 463 { 464 // 9.11. 2006 -> experiment with new spatial filter 378 465 #if 0 379 mViewCellsManager->ApplySpatialFilter(mKdTree,380 381 382 466 mViewCellsManager->ApplySpatialFilter(mKdTree, 467 mSpatialFilterSize* 468 Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 469 mPvsCache.mPvs); 383 470 #else 384 // mSpatialFilter size is in range 0.001 - 0.1 385 mViewCellsManager->ApplyFilter2(viewcell, 386 mUseFilter, 387 100*mSpatialFilterSize, 388 mPvsCache.mPvs, 389 &mPvsCache.filteredBoxes 390 ); 471 //cout<<"updating filter" << endl; 472 // mSpatialFilter size is in range 0.001 - 0.1 473 mViewCellsManager->ApplyFilter2(viewcell, 474 mUseFilter, 475 100 * mSpatialFilterSize, 476 mPvsCache.mPvs, 477 &mPvsCache.filteredBoxes 478 ); 391 479 #endif 392 } else 393 mPvsCache.mPvs = viewcell->GetPvs(); 394 395 emit PvsUpdated(); 480 } 481 else 482 { 483 mPvsCache.mPvs = viewcell->GetPvs(); 484 } 485 486 /// update the indices for rendering 487 _UpdatePvsIndices(); 488 489 emit PvsUpdated(); 490 } 491 492 Intersectable::NewMail(); 493 PvsData pvsData; 494 495 // Render PVS 496 if (mUseSpatialFilter && mRenderBoxes) 497 { 498 for (int i=0; i < mPvsCache.filteredBoxes.size(); i++) 499 RenderBox(mPvsCache.filteredBoxes[i]); 500 } 501 else 502 { 503 if (!mRenderVisibilityEstimates) 504 { 505 _RenderPvs(); 506 } 507 else 508 { 509 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 510 511 mPvsSize = mPvsCache.mPvs.GetSize(); 512 for (; it.HasMoreEntries(); ) 513 { 514 Intersectable *object = it.Next(pvsData); 515 516 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 517 // glColor3f(visibility, 0.0f, 0.0f); 518 //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 519 RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1)); 520 glColor3f(color.r, color.g, color.b); 521 522 mUseForcedColors = true; 523 RenderIntersectable(object); 524 mUseForcedColors = false; 525 } 526 } 527 } 528 529 if (mRenderFilter) 530 { 531 mWireFrame = true; 532 RenderIntersectable(viewcell); 533 glPushMatrix(); 534 glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 535 glScalef(5.0f,5.0f,5.0f); 536 glPushAttrib(GL_CURRENT_BIT); 537 glColor3f(1.0f, 0.0f, 0.0f); 538 // gluSphere((::GLUquadric *)mSphere, 539 // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 540 glPopAttrib(); 541 glPopMatrix(); 542 mWireFrame = false; 543 } 544 } 545 else 546 { 547 /*ObjectContainer::const_iterator oi = mObjects.begin(); 548 for (; oi != mObjects.end(); oi++) 549 RenderIntersectable(*oi);*/ 550 RenderScene(); 396 551 } 397 552 398 Intersectable::NewMail(); 399 400 PvsData pvsData; 401 402 // Render PVS 403 if (mUseSpatialFilter && mRenderBoxes) { 404 for (int i=0; i < mPvsCache.filteredBoxes.size(); i++) 405 RenderBox(mPvsCache.filteredBoxes[i]); 406 } else { 407 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 408 409 mPvsSize = mPvsCache.mPvs.GetSize(); 410 for (; it.HasMoreEntries(); ) { 411 Intersectable *object = it.Next(pvsData); 412 413 if (mRenderVisibilityEstimates) { 414 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 415 // glColor3f(visibility, 0.0f, 0.0f); 416 //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 417 RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1)); 418 glColor3f(color.r, color.g, color.b); 419 420 mUseForcedColors = true; 421 RenderIntersectable(object); 422 mUseForcedColors = false; 423 } else { 424 mUseForcedColors = false; 425 RenderIntersectable(object); 426 } 427 } 428 } 429 430 if (mRenderFilter) { 431 mWireFrame = true; 432 RenderIntersectable(viewcell); 433 glPushMatrix(); 434 glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 435 glScalef(5.0f,5.0f,5.0f); 436 glPushAttrib(GL_CURRENT_BIT); 437 glColor3f(1.0f, 0.0f, 0.0f); 438 // gluSphere((::GLUquadric *)mSphere, 439 // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 440 glPopAttrib(); 441 glPopMatrix(); 442 mWireFrame = false; 443 } 444 } else { 445 ObjectContainer::const_iterator oi = mObjects.begin(); 446 for (; oi != mObjects.end(); oi++) 447 RenderIntersectable(*oi); 448 } 553 //DisableDrawArrays(); 554 //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 449 555 } 450 556 … … 466 572 glColor3f(0.0f, 0.8f, 0.2f); 467 573 468 // //Render PVS574 // Render PVS 469 575 RenderPvs(); 470 576 471 577 glEnable(GL_STENCIL_TEST); 472 578 473 // 579 //mUseFalseColors = true; 474 580 475 581 glDisable(GL_LIGHTING); … … 501 607 int pixelCount = query->GetQueryResult(); 502 608 pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 503 cout<<"error pixels="<<pixelCount<<endl;609 if (0) cout<<"error pixels="<<pixelCount<<endl; 504 610 505 611 mRenderError = pErrorPixels; … … 509 615 510 616 511 void 512 QtGlRendererWidget::mousePressEvent(QMouseEvent *e) 617 void QtGlRendererWidget::timerEvent(QTimerEvent *event) 618 { 619 //std::cout << "Timer ID:" << event->timerId(); 620 update(); 621 } 622 623 624 void QtGlRendererWidget::mousePressEvent(QMouseEvent *e) 513 625 { 514 626 int x = e->pos().x(); … … 523 635 QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e) 524 636 { 525 float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 526 float TURN_SENSITIVITY=0.1f; 527 float TILT_SENSITIVITY=32.0 ; 528 float TURN_ANGLE= M_PI/36.0 ; 529 530 int x = e->pos().x(); 531 int y = e->pos().y(); 532 533 int diffx = -(mousePoint.x - x); 534 int diffy = -(mousePoint.y - y); 535 536 if (e->modifiers() & Qt::ControlModifier) { 537 mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 538 mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 539 } else { 540 mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 541 float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 542 float angle = atan2(mViewDirection.x, mViewDirection.z); 543 mViewDirection.x = sin(angle+adiff); 544 mViewDirection.z = cos(angle+adiff); 545 } 546 547 mousePoint.x = x; 548 mousePoint.y = y; 549 550 updateGL(); 637 float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 638 float TURN_SENSITIVITY=0.1f; 639 float TILT_SENSITIVITY=32.0 ; 640 float TURN_ANGLE= M_PI/36.0 ; 641 642 int x = e->pos().x(); 643 int y = e->pos().y(); 644 645 int diffx = -(mousePoint.x - x); 646 int diffy = -(mousePoint.y - y); 647 648 if (e->modifiers() & Qt::ControlModifier) 649 { 650 mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 651 mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 652 } 653 else 654 { 655 mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 656 float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 657 float angle = atan2(mViewDirection.x, mViewDirection.z); 658 mViewDirection.x = sin(angle + adiff); 659 mViewDirection.z = cos(angle + adiff); 660 } 661 662 mousePoint.x = x; 663 mousePoint.y = y; 664 665 updateGL(); 551 666 } 552 667 … … 554 669 QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *) 555 670 { 556 557 558 671 } 559 672 … … 584 697 RenderInfo(); 585 698 586 mFrame ++;699 mFrame ++; 587 700 588 701 } … … 707 820 mRenderVisibilityEstimates = false; 708 821 mTransferFunction = 0.2f; 822 mIndexBufferSize = 0; 823 824 const int delay = 500; // half a second 825 timerId = startTimer(delay); 709 826 710 827 bool tmp; … … 825 942 currentCost = costFunction[currentPos]; 826 943 #if 1 827 cout<<"costFunction.size()="<< costFunction.size()<<endl;944 cout<<"costFunction.size()="<<(int)costFunction.size()<<endl; 828 945 cout<<"CP="<<currentPos<<endl; 829 946 cout<<"MC="<<maxCost<<endl; … … 913 1030 int vc = 0; 914 1031 if (mViewCellsManager) 915 vc = mViewCellsManager->GetViewCells().size();1032 vc = (int)mViewCellsManager->GetViewCells().size(); 916 1033 917 1034 int filter = 0; … … 1070 1187 1071 1188 1072 1073 1074 /***********************************************************************/ 1075 /* QtGlDebuggerWidget implementation */ 1076 /***********************************************************************/ 1189 /*********************************************************************/ 1190 /* QtGlDebuggerWidget implementation */ 1191 /*********************************************************************/ 1077 1192 1078 1193 … … 1094 1209 DEL_PTR(mRenderBuffer); 1095 1210 } 1096 1097 1211 1098 1212 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r1997 r2538 148 148 float mTransferFunction; 149 149 150 unsigned int mIndexBufferSize; 150 151 151 152 QtRendererControlWidget *mControlWidget; … … 177 178 void resizeGL(int w, int h); 178 179 void paintGL(); 179 void timerEvent(QTimerEvent *) { 180 update(); 181 } 182 180 void timerEvent(QTimerEvent *event); 183 181 void mousePressEvent(QMouseEvent *); 184 182 void mouseReleaseEvent(QMouseEvent *); 185 183 void mouseMoveEvent(QMouseEvent *); 186 184 187 void keyPressEvent ( QKeyEvent * e ) ; 188 189 void 190 RenderPvs(); 191 192 float 193 RenderErrors(); 194 void 195 RenderInfo(); 185 void keyPressEvent(QKeyEvent * e); 186 187 void RenderPvs(); 188 189 float RenderErrors(); 190 void RenderInfo(); 196 191 197 192 virtual int GetWidth() const { return width(); } … … 211 206 show(); 212 207 } 208 209 bool PvsChanged(ViewCell *viewcell) const; 210 213 211 214 212 public slots: … … 306 304 updateGL(); 307 305 } 306 307 void _RenderPvs(); 308 309 void _UpdatePvsIndices(); 310 void _UpdatePvsIndices(KdNode *node); 308 311 309 312 signals: -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
r1997 r2538 100 100 QtGlViewer::paintGL() 101 101 { 102 103 102 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 103 glLoadIdentity(); 104 104 105 105 float m[4][4]; 106 106 107 glLoadIdentity(); 108 gluLookAt(0.0, 0.0, 1.0, /* eye is at (0,0,30) */ 109 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 110 0.0, 1.0, 0.); /* up is in positive Y direction */ 111 112 build_rotmatrix(m, manipulatorLastQuat); 113 glMultMatrixf(&m[0][0]); 107 glLoadIdentity(); 108 gluLookAt(0.0, 0.0, 1.0, /* eye is at (0,0,30) */ 109 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 110 0.0, 1.0, 0.); /* up is in positive Y direction */ 114 111 115 float s = scale*20.0f/Magnitude(mRenderer->mSceneGraph->GetBox().Diagonal()); 116 glScalef(s, s, s); 117 118 Vector3 t = -mRenderer->mSceneGraph->GetBox().Center(); 119 glTranslatef(t.x, t.y, t.z); 112 build_rotmatrix(m, manipulatorLastQuat); 113 glMultMatrixf(&m[0][0]); 114 115 float s = scale*20.0f/Magnitude(mRenderer->mSceneGraph->GetBox().Diagonal()); 116 glScalef(s, s, s); 117 118 Vector3 t = -mRenderer->mSceneGraph->GetBox().Center(); 119 glTranslatef(t.x, t.y, t.z); 120 120 121 121 RenderScene(); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2530 r2538 47 47 48 48 49 int ViewCellsManager::sRenderCostEvaluationType = 0;50 51 49 52 50 template <typename T> class myless … … 156 154 Environment::GetSingleton()->GetIntValue("ViewCells.Filter.maxSize", mMaxFilterSize); 157 155 Environment::GetSingleton()->GetFloatValue("ViewCells.Filter.width", mFilterWidth); 158 Environment::GetSingleton()->GetIntValue("ViewCells.renderCostEvaluationType", sRenderCostEvaluationType);159 156 160 157 Environment::GetSingleton()->GetBoolValue("ViewCells.exportBboxesForPvs", mExportBboxesForPvs); … … 251 248 } 252 249 253 Environment::GetSingleton()->GetStringValue("ViewCells.renderCostEvaluationType", buf); 254 255 if (strcmp(buf, "perobject") == 0) 256 { 257 sRenderCostEvaluationType = ViewCellsManager::PER_OBJECT; 258 } 259 else if (strcmp(buf, "pertriangle") == 0) 260 { 261 sRenderCostEvaluationType = ViewCellsManager::PER_TRIANGLE; 262 } 263 else 264 { 265 Debug << "error! wrong sampling type" << endl; 266 exit(0); 267 } 268 269 Environment::GetSingleton()->GetStringValue("ViewCells.Visualization.colorCode", buf); 250 251 /** The color code used during visualization. 252 */ 253 Environment::GetSingleton()->GetStringValue("ViewCells.Visualization.colorCode", buf); 270 254 271 255 if (strcmp(buf, "PVS") == 0) … … 300 284 Debug << "evaluate view cells: " << mEvaluateViewCells << endl; 301 285 Debug << "sampling type: " << mSamplingType << endl; 302 Debug << "render cost evaluation type: " << sRenderCostEvaluationType << endl;303 286 Debug << "evaluation sampling type: " << mEvaluationSamplingType << endl; 304 287 Debug << "show visualization: " << mShowVisualization << endl; … … 686 669 687 670 688 Intersectable * 689 ViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 671 Intersectable *ViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 690 672 { 691 673 if (mUseKdPvs) … … 693 675 KdNode *node = GetPreprocessor()-> 694 676 mKdTree->GetPvsNode(isTermination ? ray.mTermination : ray.mOrigin); 695 return GetPreprocessor()->mKdTree->GetOrCreateKdIntersectable(node); 677 678 return GetPreprocessor()->mKdTree->GetOrCreateKdIntersectable(node); 696 679 } 697 680 else 698 681 { 699 682 return isTermination ? ray.mTerminationObject : ray.mOriginObject; 700 } 701 } 702 703 704 void 705 ViewCellsManager::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 683 } 684 } 685 686 687 void ViewCellsManager::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 706 688 { 707 689 GetPreprocessor()->mKdTree->CollectObjects(box, objects); 708 690 } 709 691 692 710 693 AxisAlignedBox3 ViewCellsManager::GetViewCellBox(ViewCell *vc) 711 694 { 712 Mesh *m = vc->GetMesh(); 713 714 if (m) 715 { 716 m->ComputeBoundingBox(); 717 return m->mBox; 718 } 719 720 AxisAlignedBox3 box; 721 box.Initialize(); 722 723 if (!vc->IsLeaf()) { 724 ViewCellInterior *vci = (ViewCellInterior *) vc; 725 726 ViewCellContainer::iterator it = vci->mChildren.begin(); 727 for (; it != vci->mChildren.end(); ++it) { 728 box.Include(GetViewCellBox(*it)); 729 } 730 } 731 732 return box; 695 Mesh *m = vc->GetMesh(); 696 697 if (m) 698 { 699 m->ComputeBoundingBox(); 700 return m->mBox; 701 } 702 703 AxisAlignedBox3 box; 704 box.Initialize(); 705 706 if (!vc->IsLeaf()) 707 { 708 ViewCellInterior *vci = (ViewCellInterior *) vc; 709 710 ViewCellContainer::iterator it = vci->mChildren.begin(); 711 for (; it != vci->mChildren.end(); ++it) 712 { 713 box.Include(GetViewCellBox(*it)); 714 } 715 } 716 717 return box; 733 718 } 734 719 … … 744 729 745 730 simpleRays.reserve(samplesPerPass); 746 passSamples.reserve(samplesPerPass * 2); // always creates double rays 731 // reserve 2 times the size because always creates double rays 732 passSamples.reserve(samplesPerPass * 2); 747 733 748 734 // create one third of each type … … 3313 3299 3314 3300 while (pit.HasMoreEntries()) 3315 {3316 3301 pit.Next()->Mail(); 3317 }3318 3302 3319 3303 ObjectPvs nPvs; … … 3392 3376 ) 3393 3377 { 3394 PvsFilterStatistics stats; 3395 3396 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 3397 Vector3 center = vbox.Center(); 3398 // copy the PVS 3399 Intersectable::NewMail(); 3400 ObjectPvs basePvs = viewCell->GetPvs(); 3401 ObjectPvsIterator pit = basePvs.GetIterator(); 3402 3403 pvs.Reserve(viewCell->GetFilteredPvsSize()); 3404 3405 if (!mUseKdPvs) 3406 { 3407 // first mark all objects from this pvs 3408 while (pit.HasMoreEntries()) 3409 { 3410 pit.Next()->Mail(); 3411 } 3412 } 3413 3414 int pvsSize = 0; 3415 int nPvsSize = 0; 3416 float samples = (float)basePvs.GetSamples(); 3417 3418 Debug<<"f #s="<<samples<<" pvs size = "<<basePvs.GetSize(); 3419 // cout<<"Filter size = "<<filterSize<<endl; 3420 // cout<<"vbox = "<<vbox<<endl; 3421 // cout<<"center = "<<center<<endl; 3422 3423 3424 // Minimal number of local samples to take into account 3425 // the local sampling density. 3426 // The size of the filter is a minimum of the conservative 3427 // local sampling density estimate (#rays intersecting teh viewcell and 3428 // the object) 3429 // and gobal estimate for the view cell 3430 // (total #rays intersecting the viewcell) 3431 int minLocalSamples = 2; 3432 3433 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 3434 3435 // now compute the filter box around the current viewCell 3436 3437 if (useViewSpaceFilter) { 3438 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 3439 float radius = viewCellRadius/100.0f; 3440 vbox.Enlarge(radius); 3441 cout<<"vbox = "<<vbox<<endl; 3442 ViewCellContainer viewCells; 3443 ComputeBoxIntersections(vbox, viewCells); 3444 3445 ViewCellContainer::const_iterator it = viewCells.begin(), 3446 it_end = viewCells.end(); 3447 int i = 0; 3448 for (i=0; it != it_end; ++ it, ++ i) 3449 if ((*it) != viewCell) { 3450 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 3451 basePvs.MergeInPlace((*it)->GetPvs()); 3452 } 3453 3454 // update samples and globalC 3455 samples = (float)pvs.GetSamples(); 3456 // cout<<"neighboring viewcells = "<<i-1<<endl; 3457 // cout<<"Samples' = "<<samples<<endl; 3458 } 3459 3460 // Minimal number of samples so that filtering takes place 3378 PvsFilterStatistics stats; 3379 3380 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 3381 Vector3 center = vbox.Center(); 3382 // copy the PVS 3383 Intersectable::NewMail(); 3384 ObjectPvs basePvs = viewCell->GetPvs(); 3385 ObjectPvsIterator pit = basePvs.GetIterator(); 3386 3387 pvs.Reserve(viewCell->GetFilteredPvsSize()); 3388 3389 if (!mUseKdPvs) 3390 { 3391 // first mark all objects from this pvs 3392 while (pit.HasMoreEntries()) 3393 pit.Next()->Mail(); 3394 } 3395 3396 int pvsSize = 0; 3397 int nPvsSize = 0; 3398 float samples = (float)basePvs.GetSamples(); 3399 3400 Debug<<"f #s="<<samples<<" pvs size = "<<basePvs.GetSize(); 3401 // cout<<"Filter size = "<<filterSize<<endl; 3402 // cout<<"vbox = "<<vbox<<endl; 3403 // cout<<"center = "<<center<<endl; 3404 3405 3406 // Minimal number of local samples to take into account 3407 // the local sampling density. 3408 // The size of the filter is a minimum of the conservative 3409 // local sampling density estimate (#rays intersecting teh viewcell and 3410 // the object) 3411 // and gobal estimate for the view cell 3412 // (total #rays intersecting the viewcell) 3413 int minLocalSamples = 2; 3414 3415 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 3416 3417 // now compute the filter box around the current viewCell 3418 3419 if (useViewSpaceFilter) 3420 { 3421 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 3422 float radius = viewCellRadius/100.0f; 3423 vbox.Enlarge(radius); 3424 cout<<"vbox = "<<vbox<<endl; 3425 ViewCellContainer viewCells; 3426 ComputeBoxIntersections(vbox, viewCells); 3427 3428 ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end(); 3429 3430 for (int i = 0; it != it_end; ++ it, ++ i) 3431 { 3432 3433 if ((*it) != viewCell) 3434 { 3435 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 3436 basePvs.MergeInPlace((*it)->GetPvs()); 3437 } 3438 3439 // update samples and globalC 3440 samples = (float)pvs.GetSamples(); 3441 // cout<<"neighboring viewcells = "<<i-1<<endl; 3442 // cout<<"Samples' = "<<samples<<endl; 3443 } 3444 } 3445 3446 // Minimal number of samples so that filtering takes place 3461 3447 #define MIN_SAMPLES 50 3462 3463 if (samples > MIN_SAMPLES) { 3464 float globalC = 2.0f*filterSize/sqrt(samples); 3465 3466 pit = basePvs.GetIterator(); 3467 3468 ObjectContainer objects; 3469 3470 PvsData pvsData; 3471 3472 while (pit.HasMoreEntries()) { 3473 Intersectable *object = pit.Next(pvsData); 3474 3475 // compute filter size based on the distance and the numebr of samples 3476 AxisAlignedBox3 box = object->GetBox(); 3477 3478 float distance = Distance(center, box.Center()); 3479 float globalRadius = distance*globalC; 3480 3481 int objectSamples = (int)pvsData.mSumPdf; 3482 float localRadius = MAX_FLOAT; 3483 3484 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 3485 sqrt((float)objectSamples); 3486 3487 // cout<<"os="<<objectSamples<<" lr="<<localRadius<<" gr="<<globalRadius<<endl; 3488 3489 // now compute the filter size 3490 float radius; 3491 3448 3449 if (samples > MIN_SAMPLES) 3450 { 3451 float globalC = 2.0f * filterSize / sqrt(samples); 3452 3453 ObjectContainer objects; 3454 PvsData pvsData; 3455 3456 pit = basePvs.GetIterator(); 3457 3458 while (pit.HasMoreEntries()) 3459 { 3460 Intersectable *object = pit.Next(pvsData); 3461 3462 // compute filter size based on the distance and the numebr of samples 3463 AxisAlignedBox3 box = object->GetBox(); 3464 3465 float distance = Distance(center, box.Center()); 3466 float globalRadius = distance*globalC; 3467 3468 int objectSamples = (int)pvsData.mSumPdf; 3469 float localRadius = MAX_FLOAT; 3470 3471 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 3472 sqrt((float)objectSamples); 3473 3474 // cout<<"os="<<objectSamples<<" lr="<<localRadius<<" gr="<<globalRadius<<endl; 3475 3476 // now compute the filter size 3477 float radius; 3478 3492 3479 #if 0 3493 if (objectSamples <= 1) { 3494 if (localRadius > globalRadius) { 3495 radius = 0.5flRadius; 3496 stats.mLocalFilterCount++; 3497 } else { 3498 radius = globalRadius; 3499 stats.mGlobalFilterCount++; 3500 } 3501 } else { 3502 radius = localRadius; 3503 stats.mLocalFilterCount++; 3504 } 3480 if (objectSamples <= 1) 3481 { 3482 if (localRadius > globalRadius) 3483 { 3484 radius = 0.5flRadius; 3485 stats.mLocalFilterCount++; 3486 } 3487 else 3488 { 3489 radius = globalRadius; 3490 stats.mGlobalFilterCount++; 3491 } 3492 } 3493 else 3494 { 3495 radius = localRadius; 3496 stats.mLocalFilterCount++; 3497 } 3505 3498 #else 3506 3499 3507 //radius = 0.5f*globalRadius + 0.5f*localRadius;3508 3509 3510 3511 stats.mLocalFilterCount++;3512 3513 stats.mGlobalFilterCount++;3500 // radius = 0.5f*globalRadius + 0.5f*localRadius; 3501 radius = Min(globalRadius, localRadius); 3502 3503 if (localRadius > globalRadius) 3504 ++ stats.mLocalFilterCount; 3505 else 3506 ++ stats.mGlobalFilterCount; 3514 3507 #endif 3515 3516 stats.mAvgFilterRadius += radius; 3517 3518 // cout<<"box = "<<box<<endl; 3519 // cout<<"distance = "<<distance<<endl; 3520 // cout<<"radiues = "<<radius<<endl; 3521 3522 box.Enlarge(Vector3(radius)); 3523 3524 if (filteredBoxes) 3525 filteredBoxes->push_back(box); 3526 3527 objects.clear(); 3528 // $$ warning collect objects takes only unmailed ones! 3529 if (mUseKdPvsAfterFiltering) { 3530 GetPreprocessor()->mKdTree->CollectKdObjects(box, objects); 3531 } else 3532 CollectObjects(box, objects); 3533 3534 // cout<<"collected objects="<<objects.size()<<endl; 3535 ObjectContainer::const_iterator noi = objects.begin(); 3536 for (; noi != objects.end(); ++ noi) { 3537 Intersectable *o = *noi; 3538 // $$ JB warning: pdfs are not correct at this point! 3539 pvs.AddSampleDirty(o, Limits::Small); 3540 } 3541 } 3542 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 3543 } 3544 3545 Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 3546 3547 if (!mUseKdPvs) 3548 { 3549 PvsData pvsData; 3550 3551 // copy the base pvs to the new pvs 3552 pit = basePvs.GetIterator(); 3553 while (pit.HasMoreEntries()) 3554 { 3555 Intersectable *obj = pit.Next(pvsData); 3556 pvs.AddSampleDirty(obj, pvsData.mSumPdf); 3557 } 3558 } 3559 3560 pvs.SimpleSort(); 3561 viewCell->SetFilteredPvsSize(pvs.GetSize()); 3562 3563 Intersectable::NewMail(); 3564 return stats; 3508 3509 stats.mAvgFilterRadius += radius; 3510 3511 // cout<<"box = "<<box<<endl; 3512 // cout<<"distance = "<<distance<<endl; 3513 // cout<<"radiues = "<<radius<<endl; 3514 3515 box.Enlarge(Vector3(radius)); 3516 3517 if (filteredBoxes) 3518 filteredBoxes->push_back(box); 3519 3520 objects.clear(); 3521 3522 // $$ warning collect objects takes only unmailed ones! 3523 if (mUseKdPvs) 3524 GetPreprocessor()->mKdTree->CollectKdObjects(box, objects); 3525 else 3526 CollectObjects(box, objects); 3527 3528 // cout<<"collected objects="<<objects.size()<<endl; 3529 ObjectContainer::const_iterator noi = objects.begin(); 3530 for (; noi != objects.end(); ++ noi) 3531 { 3532 Intersectable *o = *noi; 3533 // $$ JB warning: pdfs are not correct at this point! 3534 pvs.AddSampleDirty(o, Limits::Small); 3535 } 3536 } 3537 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 3538 } 3539 3540 Debug << " nPvs size = " << pvs.GetSize() << endl; 3541 3542 if (!mUseKdPvs) 3543 { 3544 PvsData pvsData; 3545 3546 // copy the base pvs to the new pvs 3547 pit = basePvs.GetIterator(); 3548 while (pit.HasMoreEntries()) 3549 { 3550 Intersectable *obj = pit.Next(pvsData); 3551 pvs.AddSampleDirty(obj, pvsData.mSumPdf); 3552 } 3553 } 3554 3555 pvs.SimpleSort(); 3556 viewCell->SetFilteredPvsSize(pvs.GetSize()); 3557 3558 Intersectable::NewMail(); 3559 return stats; 3565 3560 } 3566 3561 … … 5898 5893 { 5899 5894 if (mUseKdPvs) 5900 {5901 5895 return ViewCellsManager::GetIntersectable(ray, isTermination); 5902 }5903 5896 else 5904 {5905 5897 return mHierarchyManager->GetIntersectable(ray, isTermination); 5906 }5907 5898 } 5908 5899 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r2530 r2538 862 862 /// if view cells should be exported 863 863 bool mExportViewCells; 864 865 864 // if only valid view cells should be considered for processing 866 865 bool mOnlyValidViewCells; 867 868 866 /// if rays should be used to collect merge candidates 869 867 bool mUseRaysForMerge; 870 871 868 /// if there should be an additional merge step after the subdivision 872 869 bool mMergeViewCells; 873 874 870 /// the width of the box filter 875 871 float mFilterWidth; 876 872 /// Maximal size of the filter in terms of contributing view cells 877 873 int mMaxFilterSize; 878 879 // only for debugging 874 /// only for debugging: stores some rays used during view cell construction 880 875 VssRayContainer storedRays; 881 876 /// if kd node based pvs is used for preprocessing 882 877 bool mUseKdPvs; 883 bool mUseKdPvsAfterFiltering; 884 878 /// types of distributions used for sampling 885 879 MixtureDistribution *mMixtureDistribution; 886 880 … … 900 894 bool mExportPvs; 901 895 902 static int sRenderCostEvaluationType;903 904 896 /// if view cells geometry should be used from other sources 905 897 bool mUsePredefinedViewCells; 906 898 /// the weight for one triangle in the heuristics 907 899 float mTriangleWeight; 900 /// the weight for one object (= one entity issued with one draw call) in the heuristics 908 901 float mObjectWeight; 909 902 -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r2452 r2538 365 365 #endif 366 366 367 if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)367 if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger) 368 368 { 369 369 #ifdef USE_QT 370 cout << "using gl widget" << endl; 371 // create and run the preprocessor application in a parallel thread 372 373 pt->InitThread(); 374 pt->RunThread(); 375 376 // display the render widget 377 if (!rendererWidget) 378 { 379 380 if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) { 381 QMessageBox::information(0, "OpenGL pbuffers", 382 "This system does not support OpenGL/pbuffers.", 383 QMessageBox::Ok); 384 return NULL; 385 } 386 387 rendererWidget = 388 new QtGlRendererWidget(preprocessor->mSceneGraph, 389 preprocessor->mViewCellsManager, 390 preprocessor->mKdTree); 391 392 rendererWidget->Show(); 393 394 QtGlViewer *viewer = 395 new QtGlViewer(NULL, (QtGlRendererWidget *)rendererWidget); 396 397 viewer->show(); 398 guiSupported = true; 399 } 400 401 402 bool exportRandomViewCells; 403 Environment::GetSingleton()->GetBoolValue("ViewCells.exportRandomViewCells", 404 exportRandomViewCells); 405 406 if (exportRandomViewCells) 407 { 408 cout << "exporting random view cells" << endl; 409 preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile); 410 cout << "finished" << endl; 411 } 412 413 /*bool evaluatePixelError; 414 Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", evaluatePixelError); 415 416 if (evaluatePixelError) 417 { 418 cout << "evaluating pixel error" << endl; 419 preprocessor->ComputeRenderError(); 420 }*/ 421 422 qApp->exec(); 423 #endif 424 } 425 426 // no gui available 427 if (!guiSupported) 428 { 429 if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger) 430 cout << "warning: gui not supported!" << endl; 431 432 preprocessor->mUseGlRenderer = false; 433 preprocessor->mUseGlDebugger = false; 434 } 435 436 if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) 437 { 438 cout << "executing main thread" << endl; 439 // just call the mail method -> will be executed in the main thread 440 pt->Main(); 441 } 442 #endif 443 444 // release memory 445 Cleanup(); 446 447 delete pt; 448 449 return returnCode; 370 371 //////// 372 // create and run the preprocessor application in a parallel thread 373 374 cout << "using gl widget" << endl; 375 376 pt->InitThread(); 377 pt->RunThread(); 378 379 // display the render widget 380 if (!rendererWidget) 381 { 382 383 if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) { 384 QMessageBox::information(0, "OpenGL pbuffers", 385 "This system does not support OpenGL/pbuffers.", 386 QMessageBox::Ok); 387 return NULL; 388 } 389 390 rendererWidget = 391 new QtGlRendererWidget(preprocessor->mSceneGraph, 392 preprocessor->mViewCellsManager, 393 preprocessor->mKdTree); 394 395 rendererWidget->Show(); 396 397 if (0) 398 { 399 QtGlViewer *viewer = 400 new QtGlViewer(NULL, (QtGlRendererWidget *)rendererWidget); 401 viewer->show(); 402 } 403 404 guiSupported = true; 405 } 406 407 408 bool exportRandomViewCells; 409 Environment::GetSingleton()->GetBoolValue("ViewCells.exportRandomViewCells", 410 exportRandomViewCells); 411 412 if (exportRandomViewCells) 413 { 414 cout << "exporting random view cells" << endl; 415 preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile); 416 cout << "finished" << endl; 417 } 418 419 /*bool evaluatePixelError; 420 Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", evaluatePixelError); 421 422 if (evaluatePixelError) 423 { 424 cout << "evaluating pixel error" << endl; 425 preprocessor->ComputeRenderError(); 426 }*/ 427 428 qApp->exec(); 429 #endif 430 } 431 432 // no gui available 433 if (!guiSupported) 434 { 435 if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger) 436 cout << "warning: gui not supported!" << endl; 437 438 preprocessor->mUseGlRenderer = false; 439 preprocessor->mUseGlDebugger = false; 440 } 441 442 if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) 443 { 444 cout << "executing main thread" << endl; 445 // just call the mail method -> will be executed in the main thread 446 pt->Main(); 447 } 448 #endif 449 450 // release memory 451 Cleanup(); 452 453 delete pt; 454 455 return returnCode; 450 456 } 451 457
Note: See TracChangeset
for help on using the changeset viewer.