- Timestamp:
- 08/21/07 19:37:28 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 1 added
- 1 deleted
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
r2353 r2543 291 291 FindIntersectingObjects(box, *entryObjects); 292 292 293 /*stringstream d; 294 d << "identified: " << entryObjects->size() << " objects \n"; 295 LogManager::getSingleton().logMessage(d.str()); 296 */ 293 297 AddToObjects(entryObjects, objects, id); 294 298 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
r2505 r2543 1686 1686 const bool finalizeViewCells = false; 1687 1687 1688 // load the view cells assigning the found objects to the pvss 1689 mViewCellsManager = 1690 GtpVisibilityPreprocessor::ViewCellsManager:: 1688 ///////////// 1689 //-- load the view cells assigning the found objects to the pvss 1690 1691 if (!strstr(filename.c_str(), ".bn")) 1692 { 1693 LogManager::getSingleton().logMessage("*** loading xml view cells ***"); 1694 1695 mViewCellsManager = GtpVisibilityPreprocessor::ViewCellsManager:: 1691 1696 LoadViewCells(filename, mObjects, finalizeViewCells, &bconverter); 1692 1693 LogManager::getSingleton().logMessage("******** view cells loaded *********"); 1694 1695 // objects are set to invisible initially 1696 //SetObjectsVisible(false); 1697 1698 if (finalizeViewCells) 1699 CreateViewCellsGeometry(); 1700 1701 return (mViewCellsManager != NULL); 1697 } 1698 else 1699 { 1700 LogManager::getSingleton().logMessage("*** loading binary view cells ***"); 1701 mViewCellsManager = 1702 LoadViewCellsBinary(filename, mObjects, finalizeViewCells, &bconverter); 1703 } 1704 1705 if (mViewCellsManager) 1706 { 1707 // objects are set to invisible initially 1708 if (0) SetObjectsVisible(false); 1709 1710 if (finalizeViewCells) 1711 CreateViewCellsGeometry(); 1712 1713 LogManager::getSingleton().logMessage("******** view cells loaded *********"); 1714 return true; 1715 } 1716 else 1717 { 1718 LogManager::getSingleton().logMessage("******** loading view cells failed! *********"); 1719 return false; 1720 } 1702 1721 } 1703 1722 //------------------------------------------------------------------------- -
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h
r2538 r2543 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.100 /** Collects only leaves that are found visible by view frustum culling. 101 101 */ 102 virtual void CollectVisibleLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;102 //virtual void CollectVisibleLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0; 103 103 104 104 virtual void RenderNodeRecursive(HierarchyNode *node) = 0; -
GTP/trunk/Lib/Vis/Preprocessing/scripts/gi_final.env
r2535 r2543 266 266 Construction { 267 267 268 samples 6000000 268 #samples 6000000 269 samples 300000 269 270 270 271 # type 0 = sequential computation, 1 = interleaved, 2 = gradient … … 288 289 Termination { 289 290 # maximal number of leaves 290 maxLeaves 200000291 maxLeaves 1000 291 292 # maximal memory in MB 292 #maxMemory 4293 #maxMemory 4 293 294 maxMemory 35 294 295 # minimum ratio of global cost decrease -
GTP/trunk/Lib/Vis/Preprocessing/scripts/gi_final.sh
r2539 r2543 11 11 EXT=obj 12 12 13 #SCENE=vienna_cropped 14 #SCENE_PATH=../data/vienna 15 13 16 SCENE=arena-high-lods 14 17 SCENE_PATH=../data/Arena 15 18 16 ENVIRONMENT=generate_viewcells.env 17 LOG_PREFIX=../scripts/$SCENE 19 #SCENE=PompeiiOne 20 #SCENE_PATH=../data/pompeii 21 22 #SCENE=soda 23 #SCENE_PATH=../data/soda 24 25 ENVIRONMENT=gi_final.env 26 LOG_PREFIX=../scripts/tests/gi/$SCENE 18 27 19 28 echo "starting $TARGET mode for $SCENE scene ($PROGRAM)" … … 21 30 SCENE_FILENAME=$SCENE_PATH/$SCENE.$EXT 22 31 23 OBJ_WEIGHT=20 24 25 ####################################################### 26 27 NODES=30000 28 USE_HEUR=false 29 METHOD=seq-$NODES-$USE_HEUR-$OBJ_WEIGHT 30 31 echo "$SCENE $METHOD" 32 $PROGRAM $ENVIRONMENT \ 33 -scene_filename=$SCENE_FILENAME \ 34 -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 35 -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 36 -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \ 37 -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \ 38 -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \ 39 -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 40 -hierarchy_construction_type=0 \ 41 -view_cells_triangle_weight=1.0 \ 42 -view_cells_object_weight=$OBJ_WEIGHT \ 43 -vsp_use_cost_heuristics=$USE_HEUR \ 44 -bvh_term_max_leaves=$NODES 45 46 sh movefiles.sh $LOG_PREFIX-$METHOD 32 OBJ_WEIGHT=10 47 33 48 34 … … 70 56 sh movefiles.sh $LOG_PREFIX-$METHOD 71 57 58 72 59 ####################################################### 73 60 74 NODES= 100061 NODES=60000 75 62 USE_HEUR=false 76 63 METHOD=seq-$NODES-$USE_HEUR-$OBJ_WEIGHT … … 146 133 147 134 sh movefiles.sh $LOG_PREFIX-$METHOD 148 149 150 #######################################################151 152 NODES=60000153 USE_HEUR=false154 METHOD=seq-$NODES-$USE_HEUR-$OBJ_WEIGHT155 156 echo "$SCENE $METHOD"157 $PROGRAM $ENVIRONMENT \158 -scene_filename=$SCENE_FILENAME \159 -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \160 -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \161 -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \162 -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \163 -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \164 -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \165 -hierarchy_construction_type=0 \166 -view_cells_triangle_weight=1.0 \167 -view_cells_object_weight=$OBJ_WEIGHT \168 -vsp_use_cost_heuristics=$USE_HEUR \169 -bvh_term_max_leaves=$NODES170 171 sh movefiles.sh $LOG_PREFIX-$METHOD172 -
GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility_internal.sh
r2228 r2543 13 13 export PATH=$PATH:../bin 14 14 15 NUM_SAMPLE_RAYS=200000000 16 #NUM_SAMPLE_RAYS=50000000 15 #NUM_SAMPLE_RAYS=200000000 16 #NUM_SAMPLE_RAYS=10000000 17 NUM_SAMPLE_RAYS=10000 17 18 18 19 $PREPROCESSOR -total_samples=$NUM_SAMPLE_RAYS \ … … 20 21 -preprocessor_ray_cast_method=1 \ 21 22 -samples_per_pass=1000000 \ 22 -view_cells_use_kd_pvs - -af_use_kd_pvs-\23 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ \ 23 24 -mutation_silhouette_prob=0.5 \ 24 25 -mutation_reverse_samples_distance=1.0 \ -
GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocessor.sh
r2075 r2543 1 1 #!sh 2 2 export PATH=$PATH:../bin 3 3 4 ../bin/release/preprocessor.exe $* 5 #../bin/debug/preprocessor.exe $* -
GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena
r2534 r2543 16 16 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ \ 17 17 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \ 18 -preprocessor_ray_cast_method=1 \ 18 19 -preprocessor_stats=$PREFIX-i-mixed-b1-n4a.log \ 19 20 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4a.hlog \ 20 21 demo1.env 21 -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r2530 r2543 29 29 30 30 31 //int BvhNode::sMailId = 10000;32 //int BvhNode::sReservedMailboxes = 1;33 34 31 BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL; 35 32 … … 59 56 mTimeStamp(0), 60 57 mRenderCost(-1) 61 62 { 63 58 { 64 59 } 65 60 -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2539 r2543 5 5 #include "ViewCellsManager.h" 6 6 #include "SceneGraph.h" 7 //#include "ObjectPvs.h"8 7 #include "Viewcell.h" 9 8 #include "Beam.h" … … 71 70 ViewCellsManager *viewCellsManager, 72 71 KdTree *tree): 73 Renderer(sceneGraph, viewCellsManager), 74 mKdTree(tree), 75 mUseFalseColors(false), 76 mVboId(-1), 77 mData(NULL), 78 mIndices(NULL), 79 mUseVbos(true) 80 //mUseVbos(false) 81 { 82 mSceneGraph->CollectObjects(&mObjects); 83 84 // mViewCellsManager->GetViewPoint(mViewPoint); 85 86 viewCellsManager->GetViewPoint(mViewPoint); 87 //mSceneGraph->GetBox().Center(); 88 mViewDirection = Vector3(0,0,1); 89 90 // mViewPoint = Vector3(991.7, 187.8, -271); 91 // mViewDirection = Vector3(0.9, 0, -0.4); 92 93 // timerId = startTimer(10); 94 // debug coords for atlanta 95 // mViewPoint = Vector3(3473, 6.778, -1699); 96 // mViewDirection = Vector3(-0.2432, 0, 0.97); 97 98 mFrame = 0; 99 mWireFrame = false; 100 Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", 101 mDetectEmptyViewSpace); 102 mSnapErrorFrames = true; 103 mSnapPrefix = "snap/"; 104 mUseForcedColors = false; 105 mRenderBoxes = false; 106 mUseGlLists = true; 107 //mUseGlLists = false; 108 109 if (mViewCellsManager->GetViewCellPoints()->size()) 110 mPvsStatFrames = (int)mViewCellsManager->GetViewCellPoints()->size(); 111 else 112 Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 113 114 115 mPvsErrorBuffer.resize(mPvsStatFrames); 116 ClearErrorBuffer(); 72 Renderer(sceneGraph, viewCellsManager), 73 mKdTree(tree), 74 mUseFalseColors(false), 75 mVboId(-1), 76 mData(NULL), 77 mIndices(NULL), 78 mUseVbos(true), 79 mCurrentFrame(-1) 80 { 81 mSceneGraph->CollectObjects(&mObjects); 82 83 viewCellsManager->GetViewPoint(mViewPoint); 84 85 mViewDirection = Vector3(0,0,1); 86 87 mFrame = 0; 88 mWireFrame = false; 89 Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", 90 mDetectEmptyViewSpace); 91 mSnapErrorFrames = true; 92 mSnapPrefix = "snap/"; 93 mUseForcedColors = false; 94 mRenderBoxes = false; 95 //mUseGlLists = true; 96 mUseGlLists = false; 97 98 if (mViewCellsManager->GetViewCellPoints()->size()) 99 mPvsStatFrames = (int)mViewCellsManager->GetViewCellPoints()->size(); 100 else 101 Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 102 103 104 mPvsErrorBuffer.resize(mPvsStatFrames); 105 ClearErrorBuffer(); 117 106 } 118 107 … … 120 109 GlRenderer::~GlRenderer() 121 110 { 122 cerr<<"gl renderer destructor..\n"; 123 124 CLEAR_CONTAINER(mOcclusionQueries); 125 126 DeleteVbos(); 127 128 if (mData) delete [] mData; 129 if (mIndices) delete [] mIndices; 130 131 glDeleteBuffersARB(1, &mVboId); 132 cerr<<"done."<<endl; 133 } 134 135 136 void 137 GlRenderer::RenderTriangle(TriangleIntersectable *object) 138 { 139 Triangle3 &t = object->GetItem(); 140 141 glBegin(GL_TRIANGLES); 142 Vector3 normal = t.GetNormal(); 143 glNormal3f(normal.x, normal.y, normal.z); 144 glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 145 glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 146 glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 147 glEnd(); 148 } 149 150 void 151 GlRenderer::RenderIntersectable(Intersectable *object) 152 { 153 if (!object) 154 return; 155 156 if (object->Mailed()) 157 return; 158 159 object->Mail(); 160 161 glPushAttrib(GL_CURRENT_BIT); 162 if (mUseFalseColors) 163 SetupFalseColor(object->mId); 164 165 switch (object->Type()) { 166 case Intersectable::MESH_INSTANCE: 167 RenderMeshInstance((MeshInstance *)object); 168 break; 169 case Intersectable::VIEW_CELL: 170 RenderViewCell(static_cast<ViewCell *>(object)); 171 break; 172 case Intersectable::TRANSFORMED_MESH_INSTANCE: 173 RenderTransformedMeshInstance(static_cast<TransformedMeshInstance *>(object)); 174 break; 175 case Intersectable::TRIANGLE_INTERSECTABLE: 176 RenderTriangle(static_cast<TriangleIntersectable *>(object)); 177 break; 178 case Intersectable::BVH_INTERSECTABLE: { 179 180 BvhNode *node = static_cast<BvhNode *>(object); 181 182 if (mRenderBoxes) 183 RenderBox(node->GetBoundingBox()); 184 else 185 RenderBvhNode(node); 186 break; 187 } 188 case Intersectable::KD_INTERSECTABLE: { 189 KdNode *node = (static_cast<KdIntersectable *>(object))->GetItem(); 190 191 if (mRenderBoxes) 192 RenderBox(mKdTree->GetBox(node)); 193 else 194 RenderKdNode(node); 195 break; 196 } 197 198 default: 199 cerr<<"Rendering this object not yet implemented\n"; 200 break; 201 } 202 203 glPopAttrib(); 204 } 205 206 void 207 GlRenderer::RenderRays(const VssRayContainer &rays) 208 { 209 VssRayContainer::const_iterator it = rays.begin(), it_end = rays.end(); 210 211 glBegin(GL_LINES); 212 for (; it != it_end; ++it) { 213 VssRay *ray = *it; 214 float importance = log10(1e3*ray->mWeightedPvsContribution)/3.0f; 215 // cout<<"w="<<ray->mWeightedPvsContribution<<" r="<<ray->mWeightedPvsContribution; 216 glColor3f(importance, importance, importance); 217 glVertex3fv(&ray->mOrigin.x); 218 glVertex3fv(&ray->mTermination.x); 219 } 220 glEnd(); 221 } 222 223 224 225 void 226 GlRenderer::RenderViewCell(ViewCell *vc) 227 { 228 if (vc->GetMesh()) { 229 230 if (!mUseFalseColors) { 231 if (vc->GetValid()) 232 glColor3f(0,1,0); 233 else 234 glColor3f(0,0,1); 235 } 236 237 RenderMesh(vc->GetMesh()); 238 } else { 239 // render viewcells in the subtree 240 if (!vc->IsLeaf()) { 241 ViewCellInterior *vci = (ViewCellInterior *) vc; 242 243 ViewCellContainer::iterator it = vci->mChildren.begin(); 244 for (; it != vci->mChildren.end(); ++it) { 245 RenderViewCell(*it); 246 } 247 } else { 248 // cerr<<"Empty viewcell mesh\n"; 249 } 250 } 111 cerr<<"gl renderer destructor..\n"; 112 113 CLEAR_CONTAINER(mOcclusionQueries); 114 115 DeleteVbos(); 116 117 if (mData) delete [] mData; 118 if (mIndices) delete [] mIndices; 119 120 glDeleteBuffersARB(1, &mVboId); 121 cerr<<"done."<<endl; 122 } 123 124 125 void GlRenderer::RenderTriangle(TriangleIntersectable *object) 126 { 127 Triangle3 &t = object->GetItem(); 128 129 glBegin(GL_TRIANGLES); 130 Vector3 normal = t.GetNormal(); 131 glNormal3f(normal.x, normal.y, normal.z); 132 glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 133 glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 134 glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 135 glEnd(); 136 } 137 138 139 void GlRenderer::RenderIntersectable(Intersectable *object) 140 { 141 if (!object) 142 return; 143 144 if (object->mRenderedFrame == mCurrentFrame) 145 return; 146 147 object->mRenderedFrame = mCurrentFrame; 148 149 //if (object->Mailed()) return; 150 //object->Mail(); 151 152 glPushAttrib(GL_CURRENT_BIT); 153 154 if (mUseFalseColors) 155 SetupFalseColor(object->mId); 156 157 switch (object->Type()) 158 { 159 case Intersectable::MESH_INSTANCE: 160 RenderMeshInstance((MeshInstance *)object); 161 break; 162 case Intersectable::VIEW_CELL: 163 RenderViewCell(static_cast<ViewCell *>(object)); 164 break; 165 case Intersectable::TRANSFORMED_MESH_INSTANCE: 166 RenderTransformedMeshInstance(static_cast<TransformedMeshInstance *>(object)); 167 break; 168 case Intersectable::TRIANGLE_INTERSECTABLE: 169 RenderTriangle(static_cast<TriangleIntersectable *>(object)); 170 break; 171 case Intersectable::BVH_INTERSECTABLE: 172 { 173 BvhNode *node = static_cast<BvhNode *>(object); 174 175 if (mRenderBoxes) 176 RenderBox(node->GetBoundingBox()); 177 else 178 RenderBvhNode(node); 179 break; 180 } 181 case Intersectable::KD_INTERSECTABLE: 182 { 183 KdNode *node = (static_cast<KdIntersectable *>(object))->GetItem(); 184 185 if (mRenderBoxes) 186 RenderBox(mKdTree->GetBox(node)); 187 else 188 RenderKdNode(node); 189 break; 190 } 191 192 default: 193 cerr<<"Rendering this object not yet implemented\n"; 194 break; 195 } 196 197 glPopAttrib(); 198 } 199 200 201 void GlRenderer::RenderRays(const VssRayContainer &rays) 202 { 203 VssRayContainer::const_iterator it = rays.begin(), it_end = rays.end(); 204 205 glBegin(GL_LINES); 206 207 for (; it != it_end; ++it) 208 { 209 VssRay *ray = *it; 210 const float importance = log10(1e3*ray->mWeightedPvsContribution)/3.0f; 211 212 glColor3f(importance, importance, importance); 213 glVertex3fv(&ray->mOrigin.x); 214 glVertex3fv(&ray->mTermination.x); 215 } 216 217 glEnd(); 218 } 219 220 221 void GlRenderer::RenderViewCell(ViewCell *vc) 222 { 223 if (vc->GetMesh()) 224 { 225 if (!mUseFalseColors) 226 { 227 if (vc->GetValid()) 228 glColor3f(0,1,0); 229 else 230 glColor3f(0,0,1); 231 } 232 233 RenderMesh(vc->GetMesh()); 234 } 235 else 236 { 237 // render viewcells in the subtree 238 if (!vc->IsLeaf()) 239 { 240 ViewCellInterior *vci = (ViewCellInterior *) vc; 241 242 ViewCellContainer::iterator it = vci->mChildren.begin(); 243 for (; it != vci->mChildren.end(); ++it) 244 { 245 RenderViewCell(*it); 246 } 247 } 248 else 249 { 250 // cerr<<"Empty viewcell mesh\n"; 251 } 252 } 251 253 } 252 254 … … 266 268 267 269 glPushMatrix(); 268 /* cout << "\n";269 for (int i = 0; i < 4; ++ i)270 for (int j = 0; j < 4; ++ j)271 cout << m.x[i][j] << " "; cout << "\n"*/272 270 273 271 glMultMatrixf((float *)m.x); 274 272 275 /*GLfloat dummy[16];276 glGetFloatv(GL_MODELVIEW_MATRIX, dummy);277 for (int i = 0; i < 16; ++ i)278 cout << dummy[i] << " ";279 cout << endl;*/280 273 RenderMesh(mi->GetMesh()); 281 274 … … 308 301 309 302 310 void 311 GlRenderer::RenderMesh(Mesh *mesh) 312 { 313 int i = 0; 314 315 if (!mUseFalseColors && !mUseForcedColors) 316 SetupMaterial(mesh->mMaterial); 317 318 for (i=0; i < mesh->mFaces.size(); i++){319 if (mWireFrame)320 321 else322 323 324 Face *face = mesh->mFaces[i];325 for (int j = 0; j < face->mVertexIndices.size(); j++) {326 327 }328 glEnd();329 303 void GlRenderer::RenderMesh(Mesh *mesh) 304 { 305 int i = 0; 306 307 if (!mUseFalseColors && !mUseForcedColors) 308 SetupMaterial(mesh->mMaterial); 309 310 for (i=0; i < mesh->mFaces.size(); i++) 311 { 312 if (mWireFrame) 313 glBegin(GL_LINE_LOOP); 314 else 315 glBegin(GL_POLYGON); 316 317 Face *face = mesh->mFaces[i]; 318 for (int j = 0; j < face->mVertexIndices.size(); j++) { 319 glVertex3fv(&mesh->mVertices[face->mVertexIndices[j]].x); 320 } 321 glEnd(); 322 } 330 323 } 331 324 … … 758 751 ) 759 752 { 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 { 782 783 784 } 785 786 787 788 789 790 791 792 753 // choose a random view point 754 mViewCellsManager->GetViewPoint(mViewPoint); 755 sample.mPosition = mViewPoint; 756 //cout << "viewpoint: " << mViewPoint << endl; 757 758 // take a render cost sample by rendering a cube 759 Vector3 directions[6]; 760 761 directions[0] = Vector3(1,0,0); 762 directions[1] = Vector3(0,1,0); 763 directions[2] = Vector3(0,0,1); 764 directions[3] = Vector3(-1,0,0); 765 directions[4] = Vector3(0,-1,0); 766 directions[5] = Vector3(0,0,-1); 767 768 sample.mVisibleObjects = 0; 769 770 // reset object counters 771 ObjectContainer::const_iterator it, it_end = mObjects.end(); 772 773 for (it = mObjects.begin(); it != it_end; ++ it) 774 { 775 (*it)->mCounter = 0; 776 777 } 778 779 ++ mFrame; 780 781 //glCullFace(GL_FRONT); 782 glCullFace(GL_BACK); 783 glDisable(GL_CULL_FACE); 784 785 793 786 // query all 6 directions for a full point sample 794 795 { 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 787 for (int i = 0; i < 6; ++ i) 788 { 789 mViewDirection = directions[i]; 790 SetupCamera(); 791 792 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 793 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 794 //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); 795 glDepthFunc(GL_LESS); 796 797 mUseFalseColors = true; 798 799 // the actual scene rendering fills the depth (for occlusion queries) 800 // and the frame buffer (for item buffer) 801 RenderScene(); 802 803 804 if (0) 812 805 { 813 814 815 816 817 } 818 819 820 806 char filename[256]; 807 sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 808 // QImage im = toImage(); 809 // im.save(filename, "PNG"); 810 } 811 812 // evaluate the sample 813 if (useOcclusionQueries) 821 814 { 822 823 } 824 815 EvalQueryWithOcclusionQueries(); 816 } 817 else 825 818 { 826 819 EvalQueryWithItemBuffer(); 827 820 } 828 821 } 829 830 831 832 833 834 835 { 836 837 822 823 // now evaluate the statistics over that sample 824 // currently only the number of visible objects is taken into account 825 sample.Reset(); 826 827 for (it = mObjects.begin(); it != it_end; ++ it) 828 { 829 Intersectable *obj = *it; 830 if (obj->mCounter >= threshold) 838 831 { 839 840 841 } 842 } 843 844 832 ++ sample.mVisibleObjects; 833 sample.mVisiblePixels += obj->mCounter; 834 } 835 } 836 837 //cout << "RS=" << sample.mVisibleObjects << " "; 845 838 } 846 839 … … 856 849 #endif 857 850 #endif 858 851 859 852 } 860 853 … … 867 860 ) 868 861 { 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 } 900 862 MakeCurrent(); 863 864 if (mPixelBuffer == NULL) 865 mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 866 867 // using 90 degree projection to capture 360 view with 6 samples 868 SetupProjection(GetHeight(), GetHeight(), 90.0f); 869 870 //samples.resize(numSamples); 871 halton.Reset(); 872 873 // the number of queries queried in batch mode 874 const int numQ = 500; 875 876 //const int numQ = (int)mObjects.size(); 877 if (useOcclusionQueries) 878 { 879 cout << "\ngenerating " << numQ << " queries ... "; 880 OcclusionQuery::GenQueries(mOcclusionQueries, numQ); 881 cout << "finished" << endl; 882 } 883 884 // sampling queries 885 for (int i = 0; i < numSamples; ++ i) 886 { 887 cout << "."; 888 EvalRenderCostSample(samples[i], useOcclusionQueries, threshold); 889 } 890 891 DoneCurrent(); 892 } 893 901 894 902 895 … … 1500 1493 GlRenderer::ValidViewPoint() 1501 1494 { 1502 1495 //cout<<"VV4 "; 1503 1496 if (!mDetectEmptyViewSpace) 1504 1497 return true; 1505 1498 //cout << "vp: " << mViewPoint << " dir: " << mViewDirection << endl; 1506 1499 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 return false; // backfacing polygon found -> not a valid viewspace sample1549 1550 1551 } 1552 1553 float 1554 GlRenderer::GetPixelError(int &pvsSize)1500 OcclusionQuery *query = mOcclusionQueries[0]; 1501 1502 // now check whether any backfacing polygon would pass the depth test 1503 SetupCamera(); 1504 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1505 glEnable( GL_CULL_FACE ); 1506 glCullFace(GL_BACK); 1507 1508 //cout<<"VV1 "; 1509 RenderScene(); 1510 1511 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 1512 glDepthMask(GL_FALSE); 1513 glDisable( GL_CULL_FACE ); 1514 1515 query->BeginQuery(); 1516 1517 // cout<<"VV2 "; 1518 RenderScene(); 1519 // cout<<"VV3 "; 1520 1521 query->EndQuery(); 1522 1523 // at this point, if possible, go and do some other computation 1524 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 1525 glDepthMask(GL_TRUE); 1526 glEnable( GL_CULL_FACE ); 1527 1528 // int wait = 0; 1529 // while (!query.ResultAvailable()) { 1530 // wait++; 1531 // } 1532 1533 // reenable other state 1534 unsigned int pixelCount = query->GetQueryResult(); 1535 // cout<<"VV4 "; 1536 1537 //cout<<"count: " << pixelCount<<endl; 1538 1539 if (pixelCount > 0) 1540 { 1541 return false; // backfacing polygon found -> not a valid viewspace sample 1542 } 1543 return true; 1544 } 1545 1546 1547 float GlRenderer::GetPixelError(int &pvsSize) 1555 1548 { 1556 1549 return -1.0f; 1557 1550 } 1558 1551 1559 void 1560 GlRenderer::RenderViewPoint()1552 1553 void GlRenderer::RenderViewPoint() 1561 1554 { 1562 1555 mWireFrame = true; -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
r2538 r2543 192 192 193 193 virtual float GetMaxPixelError() { 194 return mPvsStat.GetMaxError()*GetWidth()*GetHeight();194 return mPvsStat.GetMaxError()*GetWidth()*GetHeight(); 195 195 } 196 196 197 197 public: 198 198 199 int mFrame; 200 bool mWireFrame; 201 202 PvsRenderStatistics mPvsStat; 203 204 int mPvsStatFrames; 205 struct PvsErrorEntry { 206 PvsErrorEntry() {} 207 float mError; 208 int mPvsSize; 209 Vector3 mPosition; 210 Vector3 mDirection; 211 }; 212 213 vector<PvsErrorEntry> mPvsErrorBuffer; 199 int mCurrentFrame; 200 int mFrame; 201 bool mWireFrame; 202 203 PvsRenderStatistics mPvsStat; 204 205 int mPvsStatFrames; 206 struct PvsErrorEntry { 207 PvsErrorEntry() {} 208 float mError; 209 int mPvsSize; 210 Vector3 mPosition; 211 Vector3 mDirection; 212 }; 213 214 vector<PvsErrorEntry> mPvsErrorBuffer; 214 215 215 216 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r2542 r2543 68 68 69 69 70 HierarchyManager::HierarchyManager(KdTree *kdTree):71 mObjectSpaceSubdivisionType(KD_BASED_OBJ_SUBDIV),72 mBvHierarchy(NULL)73 {74 mOspTree = new OspTree(*kdTree);75 mOspTree->mVspTree = mVspTree;76 77 mVspTree = new VspTree();78 mVspTree->mHierarchyManager = this;79 80 mViewSpaceSubdivisionType = KD_BASED_VIEWSPACE_SUBDIV;81 ParseEnvironment();82 }83 84 85 70 void HierarchySubdivisionStats::Print(ostream &app) const 86 71 { … … 252 237 253 238 239 void HierarchyManager::SetVspTree(VspTree *vspTree) 240 { 241 mVspTree = vspTree; 242 mVspTree->mHierarchyManager = this; 243 } 244 245 254 246 VspTree *HierarchyManager::GetVspTree() 255 247 { 256 248 return mVspTree; 257 249 } 258 259 /*260 AxisAlignedBox3 HierarchyManager::GetViewSpaceBox() const261 {262 return mVspTree->mBoundingBox;263 }*/264 250 265 251 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r2530 r2543 197 197 */ 198 198 HierarchyManager(const int objectSpaceHierarchyType); 199 /** Hack: OspTree will copy the content from this kd tree.200 Only view space hierarchy will be constructed.201 */202 HierarchyManager(KdTree *kdTree);203 199 /** Deletes space partition and view space partition. 204 200 */ … … 239 235 */ 240 236 void SetViewCellsTree(ViewCellsTree *vcTree); 237 /** Sets a pointer to the vsp tree. 238 */ 239 void SetVspTree(VspTree *vspTree); 241 240 /** Exports the object hierarchy to disc. 242 241 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.cpp
r2538 r2543 10 10 mMailbox(0), 11 11 mBvhLeaf(0), 12 mVssRays(NULL) 12 mVssRays(NULL), 13 mRenderedFrame(0) 13 14 #if STORE_VIEWCELLS_WITH_BVH 14 15 , mViewCells(NULL) -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r2199 r2543 35 35 { 36 36 public: 37 38 /// unique object Id39 int mId;40 37 41 /// universal counter 42 int mCounter; 38 /////////////////////// 43 39 44 /// pointer to the containing bvh leaf 45 BvhLeaf *mBvhLeaf; 46 47 /////////////////////// 40 enum {MESH_INSTANCE, 41 TRANSFORMED_MESH_INSTANCE, 42 SPHERE, 43 VIEW_CELL, 44 OGRE_MESH_INSTANCE, 45 KD_INTERSECTABLE, 46 BVH_INTERSECTABLE, 47 TRIANGLE_INTERSECTABLE, 48 DUMMY_INTERSECTABLE, 49 ENGINE_INTERSECTABLE, 50 CONTAINER_INTERSECTABLE 51 }; 48 52 49 enum { MESH_INSTANCE, 50 TRANSFORMED_MESH_INSTANCE, 51 SPHERE, 52 VIEW_CELL, 53 OGRE_MESH_INSTANCE, 54 KD_INTERSECTABLE, 55 BVH_INTERSECTABLE, 56 TRIANGLE_INTERSECTABLE, 57 DUMMY_INTERSECTABLE, 58 ENGINE_INTERSECTABLE, 59 CONTAINER_INTERSECTABLE 60 }; 61 62 Intersectable(); 53 Intersectable(); 63 54 64 55 virtual ~Intersectable(); 65 56 66 inline void SetId(const int id) { mId = id; } 67 inline int GetId() { return mId; } 68 69 ///////////// 70 // Mailing stuff 71 72 static void NewMail(const int reserve = 1) 73 { 74 sMailId += sReservedMailboxes; 75 sReservedMailboxes = reserve; 76 } 77 78 void Mail() { mMailbox = sMailId; } 79 bool Mailed() const { return mMailbox == sMailId; } 80 81 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 82 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 83 84 int IncMail() { return ++ mMailbox - sMailId; } 57 inline void SetId(const int id) { mId = id; } 58 inline int GetId() { return mId; } 85 59 86 // last mail id -> warning not thread safe! 87 // both mailId and mailbox should be unique for each thread!!! 88 static int sMailId; 89 static int sReservedMailboxes; 60 ///////////// 61 // Mailing stuff 90 62 91 /// Mailbox used for traversals 92 int mMailbox; 93 63 static void NewMail(const int reserve = 1) 64 { 65 sMailId += sReservedMailboxes; 66 sReservedMailboxes = reserve; 67 } 94 68 95 //////////////// 96 // virtual interface 69 void Mail() { mMailbox = sMailId; } 70 bool Mailed() const { return mMailbox == sMailId; } 97 71 98 virtual AxisAlignedBox3 GetBox() const = 0; 99 virtual int CastRay(Ray &ray) = 0; 100 101 virtual bool IsConvex() const = 0; 102 virtual bool IsWatertight() const = 0; 103 virtual float IntersectionComplexity() = 0; 104 105 virtual int NumberOfFaces() const = 0; 106 virtual int Type() const = 0; 107 108 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 109 110 virtual int GetRandomEdgePoint(Vector3 &point, 111 Vector3 &normal) = 0; 72 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 73 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 112 74 113 virtual int GetRandomVisibleSurfacePoint(Vector3 &point, 114 Vector3 &normal, 115 const Vector3 &viewpoint, 116 const int maxTries) = 0; 75 int IncMail() { return ++ mMailbox - sMailId; } 117 76 118 // virtual int GetRandomPoint(Vector3 &point, 119 // vector3 &normal) = 0; 77 // last mail id -> warning not thread safe! 78 // both mailId and mailbox should be unique for each thread!!! 79 static int sMailId; 80 static int sReservedMailboxes; 120 81 121 virtual std::ostream &Describe(std::ostream &s) = 0; 122 123 ////////////////////////////////////// 82 /// Mailbox used for traversals 83 int mMailbox; 124 84 125 85 126 virtual int GenerateSilhouetteRays(const int nrays, 127 const AxisAlignedBox3 &originBox, 128 const AxisAlignedBox3 &directionBox, 129 VssRayContainer &rays); 130 131 virtual int GetRandomSurfacePoint(const float u, 132 const float v, 133 Vector3 &point, 134 Vector3 &normal); 86 //////////////// 87 // virtual interface 135 88 136 virtual float GetArea() const; 89 virtual AxisAlignedBox3 GetBox() const = 0; 90 virtual int CastRay(Ray &ray) = 0; 137 91 138 static bool GreaterCounter(const Intersectable *a, 139 const Intersectable *b); 140 141 /** Returns the name of the type of this intersectable 142 */ 143 static std::string GetTypeName(Intersectable *obj); 92 virtual bool IsConvex() const = 0; 93 virtual bool IsWatertight() const = 0; 94 virtual float IntersectionComplexity() = 0; 144 95 145 /** Returns normal from the face with the specified index. 146 PROBLEM: Does not fit to all intersectable types (e.g., spheres) 147 */ 148 virtual Vector3 GetNormal(const int idx) const; 96 virtual int NumberOfFaces() const = 0; 97 virtual int Type() const = 0; 149 98 150 /** Returns rays stored with this intersectable. 151 */ 152 VssRayContainer *GetOrCreateRays(); 99 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 153 100 154 /** Deletes the rays associated with this intersectable. 155 */ 156 void DelRayRefs(); 101 virtual int GetRandomEdgePoint(Vector3 &point, 102 Vector3 &normal) = 0; 103 104 virtual int GetRandomVisibleSurfacePoint(Vector3 &point, 105 Vector3 &normal, 106 const Vector3 &viewpoint, 107 const int maxTries) = 0; 108 109 // virtual int GetRandomPoint(Vector3 &point, 110 // vector3 &normal) = 0; 111 112 virtual std::ostream &Describe(std::ostream &s) = 0; 113 114 ////////////////////////////////////// 115 116 117 virtual int GenerateSilhouetteRays(const int nrays, 118 const AxisAlignedBox3 &originBox, 119 const AxisAlignedBox3 &directionBox, 120 VssRayContainer &rays); 121 122 virtual int GetRandomSurfacePoint(const float u, 123 const float v, 124 Vector3 &point, 125 Vector3 &normal); 126 127 virtual float GetArea() const; 128 129 static bool GreaterCounter(const Intersectable *a, 130 const Intersectable *b); 131 132 /** Returns the name of the type of this intersectable 133 */ 134 static std::string GetTypeName(Intersectable *obj); 135 /** Returns normal from the face with the specified index. 136 PROBLEM: Does not fit to all intersectable types (e.g., spheres) 137 */ 138 virtual Vector3 GetNormal(const int idx) const; 139 /** Returns rays stored with this intersectable. 140 */ 141 VssRayContainer *GetOrCreateRays(); 142 143 /** Deletes the rays associated with this intersectable. 144 */ 145 void DelRayRefs(); 146 147 /// hack 148 int mRenderedFrame; 149 150 /////////// 151 152 /// unique object Id 153 int mId; 154 /// universal counter 155 int mCounter; 156 /// pointer to the containing bvh leaf 157 BvhLeaf *mBvhLeaf; 157 158 158 159 159 160 protected: 161 160 162 /// some rays piercing this intersectable 161 163 VssRayContainer *mVssRays; 162 164 165 163 166 #if STORE_VIEWCELLS_WITH_BVH 164 167 public: 165 166 167 168 /** Returns rays stored with this intersectable. 169 */ 170 ViewCellContainer *GetOrCreateViewCells(); 168 171 169 172 void DelViewCells(); 170 173 171 174 protected: 172 175 ViewCellContainer *mViewCells; 173 176 #endif 174 177 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
r2538 r2543 211 211 212 212 int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); 213 214 213 }; 215 214 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r2539 r2543 864 864 if (node->IsLeaf() || node->mPvsTermination == 1) { 865 865 Intersectable *object = GetOrCreateKdIntersectable(node); 866 if (! object->Mailed()) {867 object->Mail();866 if (!node->Mailed()) { 867 node->Mail(); 868 868 objects.push_back(object); 869 869 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2542 r2543 630 630 bool Preprocessor::PrepareViewCells() 631 631 { 632 // load the view cells assigning the found objects to the pvss 633 #if 1 634 cerr << "loading binary view cells" << endl; 635 ViewCellsManager *dummyViewCellsManager = 636 LoadViewCellsBinary("test.vc", mObjects, false, NULL); 637 638 //cerr << "reexporting the binary view cells" << endl; 639 //dummyViewCellsManager->ExportViewCellsBinary("outvc.xml.gz", true, mObjects); 640 641 return false; 642 #endif 643 632 644 /////// 633 645 //-- parse view cells construction method … … 673 685 else 674 686 { 675 // parse type of view cell container687 // parse type of view cells manager 676 688 Environment::GetSingleton()->GetStringValue("ViewCells.type", buf); 677 689 mViewCellsManager = CreateViewCellsManager(buf); -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
r2542 r2543 90 90 QtGlRendererBuffer::GetPixelError(int &pvsSize) 91 91 { 92 float pErrorPixels = -1.0f; 93 94 95 mUseFalseColors = false; 96 unsigned int pixelCount; 97 98 99 ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); 100 // cout<<"View cell"<<viewcell<<endl; 101 if (viewcell == NULL) 102 return 0.0f; 103 104 // ViewCell *viewcell = NULL; 105 106 // PrVs prvs; 107 108 // mViewCellsManager->SetMaxFilterSize(0); 109 // mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth()); 110 // viewcell = prvs.mViewCell; 111 112 ObjectPvs pvs; 113 114 if (1) 115 pvs = viewcell->GetPvs(); 116 else 117 mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs); 118 119 // cout<<"pvs size"<<pvs.GetSize()<<endl<<flush; 120 121 SetupCamera(); 122 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 123 glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 124 125 126 glStencilFunc(GL_EQUAL, 0x0, 0x1); 127 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 128 129 // Render PVS 130 ObjectPvsIterator it = pvs.GetIterator(); 131 132 pvsSize = pvs.GetSize(); 133 Intersectable::NewMail(); 134 for (; it.HasMoreEntries(); ) { 135 RenderIntersectable(it.Next()); 136 } 137 138 139 // glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); 140 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 141 glEnable(GL_STENCIL_TEST); 142 143 mUseFalseColors = true; 144 145 OcclusionQuery *query = mOcclusionQueries[0]; 146 147 148 query->BeginQuery(); 149 150 SetupCamera(); 151 152 RenderScene(); 153 154 query->EndQuery(); 155 glDisable(GL_STENCIL_TEST); 156 // reenable other state 157 // int wait=0; 158 // while (!query.ResultAvailable()) { 159 // wait++; 160 // } 161 162 163 pixelCount = query->GetQueryResult(); 164 165 pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 166 167 168 if (mSnapErrorFrames && pErrorPixels >= 0.01f) { 169 glReadBuffer(GL_BACK); 170 171 char filename[256]; 172 sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels); 173 QImage im = toImage(); 174 string str = mSnapPrefix + filename; 175 QString qstr(str.c_str()); 176 177 im.save(qstr, "PNG"); 178 if (1) { //0 && mFrame == 1543) { 179 int x,y; 180 int lastIndex = -1; 181 for (y=0; y < im.height(); y++) 182 for (x=0; x < im.width(); x++) { 183 QRgb p = im.pixel(x,y); 184 int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16); 185 if (qGreen(p) != 255 && index!=0) { 186 if (index != lastIndex) { 187 // Debug<<"ei="<<index<<" "; 188 lastIndex = index; 189 } 190 } 92 float pErrorPixels = -1.0f; 93 94 95 mUseFalseColors = false; 96 unsigned int pixelCount; 97 98 99 ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); 100 // cout<<"View cell"<<viewcell<<endl; 101 if (viewcell == NULL) 102 return 0.0f; 103 104 105 ObjectPvs pvs; 106 107 if (1) 108 pvs = viewcell->GetPvs(); 109 else 110 mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs); 111 112 SetupCamera(); 113 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 114 glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 115 116 117 glStencilFunc(GL_EQUAL, 0x0, 0x1); 118 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 119 120 // Render PVS 121 ObjectPvsIterator it = pvs.GetIterator(); 122 123 pvsSize = pvs.GetSize(); 124 125 Intersectable::NewMail(); 126 while (it.HasMoreEntries()) 127 { 128 RenderIntersectable(it.Next()); 129 } 130 131 132 // glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); 133 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 134 glEnable(GL_STENCIL_TEST); 135 136 mUseFalseColors = true; 137 138 OcclusionQuery *query = mOcclusionQueries[0]; 139 140 141 query->BeginQuery(); 142 143 SetupCamera(); 144 145 RenderScene(); 146 147 query->EndQuery(); 148 glDisable(GL_STENCIL_TEST); 149 // reenable other state 150 // int wait=0; 151 // while (!query.ResultAvailable()) { 152 // wait++; 153 // } 154 155 156 pixelCount = query->GetQueryResult(); 157 158 pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 159 160 161 if (mSnapErrorFrames && pErrorPixels >= 0.01f) { 162 glReadBuffer(GL_BACK); 163 164 char filename[256]; 165 sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels); 166 QImage im = toImage(); 167 string str = mSnapPrefix + filename; 168 QString qstr(str.c_str()); 169 170 im.save(qstr, "PNG"); 171 if (1) { //0 && mFrame == 1543) { 172 int x,y; 173 int lastIndex = -1; 174 for (y=0; y < im.height(); y++) 175 for (x=0; x < im.width(); x++) { 176 QRgb p = im.pixel(x,y); 177 int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16); 178 if (qGreen(p) != 255 && index!=0) { 179 if (index != lastIndex) { 180 // Debug<<"ei="<<index<<" "; 181 lastIndex = index; 182 } 183 } 184 } 191 185 } 192 } 193 194 195 mUseFalseColors = false; 196 glPushAttrib(GL_CURRENT_BIT); 197 glColor3f(0,1,0); 186 187 188 mUseFalseColors = false; 189 glPushAttrib(GL_CURRENT_BIT); 190 glColor3f(0,1,0); 191 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 192 SetupCamera(); 193 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 194 195 // Render PVS 196 Intersectable::NewMail(); 197 198 ObjectPvsIterator it = pvs.GetIterator(); 199 for (; it.HasMoreEntries(); ) 200 { 201 RenderIntersectable(it.Next()); 202 } 203 204 im = toImage(); 205 sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels); 206 str = mSnapPrefix + filename; 207 qstr = str.c_str(); 208 im.save(qstr, "PNG"); 209 glPopAttrib(); 210 } 211 198 212 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 199 SetupCamera(); 200 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 201 202 // Render PVS 203 Intersectable::NewMail(); 204 205 ObjectPvsIterator it = pvs.GetIterator(); 206 for (; it.HasMoreEntries(); ) { 207 RenderIntersectable(it.Next()); 208 } 209 210 im = toImage(); 211 sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels); 212 str = mSnapPrefix + filename; 213 qstr = str.c_str(); 214 im.save(qstr, "PNG"); 215 glPopAttrib(); 216 } 217 218 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 219 220 return pErrorPixels; 213 214 return pErrorPixels; 221 215 } 222 216 … … 234 228 235 229 Intersectable *obj = NULL; 236 230 237 231 for (int x = 0; x < image.width(); ++ x) 238 232 { … … 246 240 ObjectContainer::iterator oit = 247 241 lower_bound(objects.begin(), objects.end(), &dummy, ilt); 248 249 242 243 250 244 if (//(oit != oit.end()) && 251 245 ((*oit)->GetId() == id) && … … 263 257 } 264 258 265 /////////////////////////////////////////////////////////////// 266 /////////////////////////////////////////////////////////////// 267 /////////////////////////////////////////////////////////////// 268 /////////////////////////////////////////////////////////////// 269 270 271 void 272 QtGlRendererWidget::InitGL() 273 { 274 GlRenderer::InitGL(); 275 276 GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; 277 /* mat_specular and mat_shininess are NOT default values */ 278 GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; 279 GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 }; 280 GLfloat mat_shininess[] = { 1.0 }; 281 282 GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; 283 GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 }; 284 GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 }; 285 286 GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; 287 288 289 // default Material 290 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); 291 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 292 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 293 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 294 295 // a light 296 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 297 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 298 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 299 300 glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); 301 glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); 302 glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); 303 304 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 305 306 glEnable(GL_LIGHTING); 307 glEnable(GL_LIGHT0); 308 glEnable(GL_LIGHT1); 309 310 311 // set position of the light 312 GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 }; 313 glLightfv (GL_LIGHT0, GL_POSITION, infinite_light); 314 315 // set position of the light2 316 GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 }; 317 glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2); 318 319 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 320 // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR); 321 glEnable(GL_COLOR_MATERIAL); 322 323 glShadeModel( GL_FLAT ); 259 260 void QtGlRendererWidget::InitGL() 261 { 262 GlRenderer::InitGL(); 263 264 GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; 265 /* mat_specular and mat_shininess are NOT default values */ 266 GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; 267 GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 }; 268 GLfloat mat_shininess[] = { 1.0 }; 269 270 GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; 271 GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 }; 272 GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 }; 273 274 GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; 275 276 277 // default Material 278 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); 279 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 280 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 281 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 282 283 // a light 284 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 285 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 286 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 287 288 glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); 289 glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); 290 glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); 291 292 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 293 294 glEnable(GL_LIGHTING); 295 glEnable(GL_LIGHT0); 296 glEnable(GL_LIGHT1); 297 298 299 // set position of the light 300 GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 }; 301 glLightfv (GL_LIGHT0, GL_POSITION, infinite_light); 302 303 // set position of the light2 304 GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 }; 305 glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2); 306 307 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 308 // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR); 309 glEnable(GL_COLOR_MATERIAL); 310 311 glShadeModel( GL_FLAT ); 324 312 } 325 313 … … 328 316 QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle) 329 317 { 330 331 int ww = w;332 int hh = h;333 glViewport(0, 0, ww, hh);334 glMatrixMode(GL_PROJECTION);335 glLoadIdentity();336 gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));337 glMatrixMode(GL_MODELVIEW);338 339 int ww = w;340 int hh = h;341 glViewport(0, 0, ww, hh);342 glMatrixMode(GL_PROJECTION);343 glLoadIdentity();344 gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));345 glMatrixMode(GL_MODELVIEW);346 318 if (!mTopView) { 319 int ww = w; 320 int hh = h; 321 glViewport(0, 0, ww, hh); 322 glMatrixMode(GL_PROJECTION); 323 glLoadIdentity(); 324 gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 325 glMatrixMode(GL_MODELVIEW); 326 } else { 327 int ww = w; 328 int hh = h; 329 glViewport(0, 0, ww, hh); 330 glMatrixMode(GL_PROJECTION); 331 glLoadIdentity(); 332 gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 333 glMatrixMode(GL_MODELVIEW); 334 } 347 335 } 348 336 … … 364 352 mUseFalseColors = false; 365 353 366 int offset = mObjects.size() * 3;354 int offset = (int)mObjects.size() * 3; 367 355 char *arrayPtr = mUseVbos ? NULL : (char *)mData; 368 356 369 357 glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr); 370 358 glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); … … 375 363 void QtGlRendererWidget::_UpdatePvsIndices() 376 364 { 377 mIndexBufferSize = 0; 365 int indexBufferSize = 0; 366 378 367 KdNode::NewMail(); 368 //Intersectable::NewMail(); 379 369 380 370 mPvsSize = mPvsCache.mPvs.GetSize(); … … 382 372 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 383 373 384 for (; it.HasMoreEntries();)374 while (it.HasMoreEntries()) 385 375 { 386 376 Intersectable *obj = it.Next(); 387 377 KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 388 _UpdatePvsIndices(node); 389 } 390 } 391 392 393 void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node) 378 379 _UpdatePvsIndices(node, indexBufferSize); 380 } 381 382 mIndexBufferSize = indexBufferSize; 383 } 384 385 386 void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node, int &indexBufferSize) 394 387 { 395 388 if (node->Mailed()) … … 398 391 node->Mail(); 399 392 393 // if (mObjects.size() * 3 < indexBufferSize) cerr << "problem: " << mObjects.size() * 3 << " < " << indexBufferSize << endl; 400 394 if (!node->IsLeaf()) 401 395 { 402 KdInterior * in= static_cast<KdInterior *>(node);403 404 _UpdatePvsIndices( in->mBack);405 _UpdatePvsIndices( in->mFront);396 KdInterior *kdInterior = static_cast<KdInterior *>(node); 397 398 _UpdatePvsIndices(kdInterior->mBack, indexBufferSize); 399 _UpdatePvsIndices(kdInterior->mFront, indexBufferSize); 406 400 } 407 401 else … … 409 403 KdLeaf *leaf = static_cast<KdLeaf *>(node); 410 404 411 leaf->mIndexBufferStart = mIndexBufferSize;405 leaf->mIndexBufferStart = indexBufferSize; 412 406 413 407 for (size_t i = 0; i < leaf->mObjects.size(); ++ i) … … 417 411 418 412 // check if already rendered 419 if (!obj->Mailed())413 /*if (!obj->Mailed()) 420 414 { 421 415 obj->Mail(); 422 416 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; 417 mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; 418 mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; 419 mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; 420 421 indexBufferSize += 3; 422 }*/ 423 if (obj->mRenderedFrame != mCurrentFrame) 424 { 425 obj->mRenderedFrame = mCurrentFrame; 426 427 mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; 428 mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; 429 mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; 430 431 indexBufferSize += 3; 428 432 } 429 433 } 430 434 431 leaf->mIndexBufferSize = mIndexBufferSize - leaf->mIndexBufferStart; 432 } 435 leaf->mIndexBufferSize = indexBufferSize - leaf->mIndexBufferStart; 436 } 437 438 //cout << "id: " << indexBufferSize << endl; 433 439 } 434 440 … … 439 445 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 440 446 447 ++ mCurrentFrame; 448 441 449 EnableDrawArrays(); 442 450 443 Intersectable::NewMail(); 444 ViewCell *viewcell = NULL; 445 451 //Intersectable::NewMail(); 452 446 453 if (mDetectEmptyViewSpace) 447 454 glEnable(GL_CULL_FACE); … … 449 456 glDisable(GL_CULL_FACE); 450 457 458 ViewCell *viewcell = NULL; 451 459 viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 452 460 453 461 if (viewcell) 454 462 { 455 // copy the pvs so that it can be filtered ...463 // copy the pvs so that it can be filtered ... 456 464 if (PvsChanged(viewcell)) 457 465 { … … 462 470 if (mUseSpatialFilter) 463 471 { 472 //ObjectPvs pvs; 473 474 //mMutex.lock(); 464 475 // mSpatialFilter size is in range 0.001 - 0.1 465 476 mViewCellsManager->ApplyFilter2(viewcell, 466 477 mUseFilter, 467 100 * mSpatialFilterSize, 468 mPvsCache.mPvs, 469 &mPvsCache.filteredBoxes); 478 100.0f * mSpatialFilterSize, 479 //pvs, 480 mPvsCache.mPvs, 481 &mPvsCache.filteredBoxes); 482 //mPvsCache.mPvs = pvs; 483 //mMutex.unlock(); 470 484 } 471 485 else … … 480 494 } 481 495 482 Intersectable::NewMail();496 //Intersectable::NewMail(); 483 497 PvsData pvsData; 484 498 … … 540 554 /*ObjectContainer::const_iterator oi = mObjects.begin(); 541 555 for (; oi != mObjects.end(); oi++) 542 556 RenderIntersectable(*oi);*/ 543 557 RenderScene(); 544 558 } … … 551 565 QtGlRendererWidget::RenderErrors() 552 566 { 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 567 float pErrorPixels = -1.0f; 568 569 SetupCamera(); 570 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 571 572 glPushAttrib(GL_ENABLE_BIT); 573 574 glStencilFunc(GL_EQUAL, 0x0, 0x1); 575 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 576 577 mUseForcedColors = true; 578 579 glColor3f(0.0f, 0.8f, 0.2f); 580 581 // Render PVS 582 RenderPvs(); 583 584 glEnable(GL_STENCIL_TEST); 585 586 //mUseFalseColors = true; 587 588 glDisable(GL_LIGHTING); 589 590 OcclusionQuery *query = mOcclusionQueries[0]; 591 query->BeginQuery(); 592 593 SetupCamera(); 594 595 glColor3f(1.0f, 0.0f, 0.0f); 596 597 RenderScene(); 598 599 mUseForcedColors = false; 600 601 query->EndQuery(); 602 603 glDisable(GL_STENCIL_TEST); 604 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 605 606 glPopAttrib(); 607 608 // reenable other state 609 // int wait=0; 610 // while (!query.ResultAvailable()) { 611 // wait++; 612 // } 613 614 int pixelCount = query->GetQueryResult(); 615 pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 616 if (0) cout<<"error pixels="<<pixelCount<<endl; 617 618 mRenderError = pErrorPixels; 619 620 return pErrorPixels; 607 621 } 608 622 … … 617 631 void QtGlRendererWidget::mousePressEvent(QMouseEvent *e) 618 632 { 619 620 621 622 623 624 633 int x = e->pos().x(); 634 int y = e->pos().y(); 635 636 mousePoint.x = x; 637 mousePoint.y = y; 638 625 639 } 626 640 … … 667 681 QtGlRendererWidget::resizeGL(int w, int h) 668 682 { 669 670 683 SetupCameraProjection(w, h); 684 updateGL(); 671 685 } 672 686 … … 674 688 QtGlRendererWidget::paintGL() 675 689 { 676 677 678 679 SetupCameraProjection(width(), height());680 SetupCamera();681 682 if (mRenderErrors) {683 684 } else {685 686 687 }688 689 690 691 692 693 690 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 691 692 if (1) { 693 SetupCameraProjection(width(), height()); 694 SetupCamera(); 695 696 if (mRenderErrors) { 697 RenderErrors(); 698 } else { 699 glColor3f(0.6f, 0.6f, 0.6f); 700 RenderPvs(); 701 } 702 } 703 704 RenderInfo(); 705 706 mFrame ++; 707 694 708 } 695 709 … … 698 712 QtGlRendererWidget::SetupCamera() 699 713 { 700 701 GlRenderer::SetupCamera();702 703 if (0) {704 705 706 707 708 709 710 711 712 713 714 if (!mTopView) 715 GlRenderer::SetupCamera(); 716 else { 717 if (0) { 718 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; 719 Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, 720 -1, 721 mViewDirection.y); 722 723 Vector3 target = mViewPoint + dist*mViewDirection; 724 Vector3 up(0,1,0); 725 726 glLoadIdentity(); 727 gluLookAt(pos.x, pos.y, pos.z, 714 728 target.x, target.y, target.z, 715 729 up.x, up.y, up.z); 716 } else {717 718 719 720 721 722 723 724 725 726 730 } else { 731 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance; 732 Vector3 pos = mViewPoint + dist*Vector3(0, 733 1, 734 0); 735 736 Vector3 target = mViewPoint; 737 Vector3 up(mViewDirection.x, 0, mViewDirection.z); 738 739 glLoadIdentity(); 740 gluLookAt(pos.x, pos.y, pos.z, 727 741 target.x, target.y, target.z, 728 742 up.x, up.y, up.z); 729 730 }731 743 744 } 745 } 732 746 733 747 } … … 737 751 QtGlRendererWidget::keyPressEvent ( QKeyEvent * e ) 738 752 { 739 740 753 switch (e->key()) { 754 case Qt::Key_T: 741 755 mTopView = !mTopView; 742 756 SetupCameraProjection(width(), height()); 743 757 updateGL(); 744 758 break; 745 759 case Qt::Key_V: 746 760 mRenderViewCells = !mRenderViewCells; 747 761 updateGL(); 748 762 break; 749 763 case Qt::Key_P: 750 764 // set random viewpoint 751 765 mViewCellsManager->GetViewPoint(mViewPoint); 752 766 updateGL(); 753 767 break; 754 768 case Qt::Key_S: { 755 769 // set view poitn and direction 756 770 QString text; … … 758 772 text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z); 759 773 text = QInputDialog::getText(this, 760 761 762 763 764 774 "Enter a view point", 775 "", 776 QLineEdit::Normal, 777 text, 778 &ok); 765 779 if (!ok) 766 767 780 break; 781 768 782 if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) { 769 770 771 772 773 774 775 776 777 break;778 779 780 updateGL();781 782 783 } 784 785 783 text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z); 784 text = QInputDialog::getText(this, 785 "Enter a direction", 786 "", 787 QLineEdit::Normal, 788 text, 789 &ok); 790 if (!ok) 791 break; 792 if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x, 793 &mViewDirection.y, &mViewDirection.z) == 3) { 794 updateGL(); 795 } 796 break; 797 } 798 } 799 default: 786 800 e->ignore(); 787 801 break; 788 789 } 790 791 802 } 803 } 804 805 792 806 793 807 QtGlRendererWidget::QtGlRendererWidget( … … 799 813 Qt::WFlags f 800 814 ) 801 : 802 GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f) 803 { 804 mPreprocessorThread = NULL; 805 mTopView = false; 806 mRenderViewCells = false; 807 mTopDistance = 1.0f; 808 mCutViewCells = false; 809 mCutScene = false; 810 mRenderErrors = false; 811 mRenderBoxes = false; 812 mRenderFilter = true; 813 mRenderVisibilityEstimates = false; 814 mTransferFunction = 0.2f; 815 mIndexBufferSize = 0; 816 817 const int delay = 500; // half a second 818 timerId = startTimer(delay); 819 820 bool tmp; 821 822 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); 823 mUseFilter = tmp; 824 825 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 826 tmp ); 827 mUseSpatialFilter = tmp; 828 829 mShowRenderCost = false; 830 mShowPvsSizes = false; 831 mSpatialFilterSize = 0.01; 832 mPvsSize = 0; 833 mRenderError = 0.0f; 834 mShowRays = false; 835 836 mControlWidget = new QtRendererControlWidget(NULL); 837 838 connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 839 connect(mControlWidget, 840 SIGNAL(SetTransferFunction(int)), 841 this, 842 SLOT(SetTransferFunction(int))); 843 connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs())); 844 connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility())); 845 connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation())); 846 connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this, 847 SLOT(SetRandomViewPoint())); 848 849 connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 850 connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 851 852 connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int))); 853 connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int))); 854 855 connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 856 connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool))); 857 connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool))); 858 connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 859 connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 860 connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 861 connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool))); 862 connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool))); 863 connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool))); 864 connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), 865 this, SLOT(SetRenderVisibilityEstimates(bool))); 866 connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool))); 867 connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), 868 this, SLOT(SetUseSpatialFilter(bool))); 869 870 connect(mControlWidget, 871 SIGNAL(SetShowRays(bool)), 872 this, 873 SLOT(SetShowRays(bool))); 874 875 resize(1000, 500); 876 mControlWidget->show(); 815 : 816 GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f) 817 { 818 mPreprocessorThread = NULL; 819 mTopView = false; 820 mRenderViewCells = false; 821 mTopDistance = 1.0f; 822 mCutViewCells = false; 823 mCutScene = false; 824 mRenderErrors = false; 825 mRenderBoxes = false; 826 mRenderFilter = true; 827 mRenderVisibilityEstimates = false; 828 mTransferFunction = 0.2f; 829 mIndexBufferSize = 0; 830 831 //mCurrentFrame = 0; 832 833 const int delay = 500; // half a second 834 timerId = startTimer(delay); 835 836 bool tmp; 837 838 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); 839 mUseFilter = tmp; 840 841 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 842 tmp ); 843 mUseSpatialFilter = tmp; 844 845 mShowRenderCost = false; 846 mShowPvsSizes = false; 847 mSpatialFilterSize = 0.01; 848 mPvsSize = 0; 849 mRenderError = 0.0f; 850 mShowRays = false; 851 852 mControlWidget = new QtRendererControlWidget(NULL); 853 854 connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 855 connect(mControlWidget, 856 SIGNAL(SetTransferFunction(int)), 857 this, 858 SLOT(SetTransferFunction(int))); 859 connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs())); 860 connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility())); 861 connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation())); 862 connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this, 863 SLOT(SetRandomViewPoint())); 864 865 connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 866 connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 867 868 connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int))); 869 connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int))); 870 871 connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 872 connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool))); 873 connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool))); 874 connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 875 connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 876 connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 877 connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool))); 878 connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool))); 879 connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool))); 880 connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), 881 this, SLOT(SetRenderVisibilityEstimates(bool))); 882 connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool))); 883 connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), 884 this, SLOT(SetUseSpatialFilter(bool))); 885 886 connect(mControlWidget, 887 SIGNAL(SetShowRays(bool)), 888 this, 889 SLOT(SetShowRays(bool))); 890 891 resize(1000, 500); 892 mControlWidget->show(); 877 893 } 878 894 … … 880 896 QtGlRendererWidget::UpdateAllPvs() 881 897 { 882 883 884 898 // $$ does not work so far:( 899 mViewCellsManager->UpdatePvsForEvaluation(); 900 // mViewCellsManager->FinalizeViewCells(false); 885 901 } 886 902 … … 888 904 QtGlRendererWidget::ComputeVisibility() 889 905 { 890 891 892 mPreprocessorThread->RunThread();906 cerr<<"Compute Visibility called!\n"<<endl; 907 if (!mPreprocessorThread->isRunning()) 908 mPreprocessorThread->RunThread(); 893 909 } 894 910 … … 896 912 QtGlRendererWidget::StopComputation() 897 913 { 898 899 914 cerr<<"stop computation called!\n"<<endl; 915 mViewCellsManager->GetPreprocessor()->mStopComputation = true; 900 916 } 901 917 … … 903 919 QtGlRendererWidget::SetRandomViewPoint() 904 920 { 905 906 907 921 cerr<<"stop computation called!\n"<<endl; 922 mViewCellsManager->GetViewPoint(mViewPoint); 923 updateGL(); 908 924 } 909 925 … … 914 930 static float maxCost = -1; 915 931 if (costFunction.size()==0) { 916 ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree(); 917 if (tree) { 918 tree->GetCostFunction(costFunction); 919 maxCost = -1; 920 for (int i=0; i < costFunction.size(); i++) { 921 // cout<<i<<":"<<costFunction[i]<<" "; 922 // update cost function to an absolute value based on the total geometry count 923 costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size(); 924 if (costFunction[i] > maxCost) 925 maxCost = costFunction[i]; 932 ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree(); 933 if (tree) { 934 tree->GetCostFunction(costFunction); 935 maxCost = -1; 936 for (int i=0; i < costFunction.size(); i++) { 937 // cout<<i<<":"<<costFunction[i]<<" "; 938 // update cost function to an absolute value based on the total geometry count 939 costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size(); 940 if (costFunction[i] > maxCost) 941 maxCost = costFunction[i]; 942 } 926 943 } 927 } 928 } 929 930 944 } 945 946 931 947 int currentPos = (int)mViewCellsManager->GetViewCells().size(); 932 948 float currentCost= -1; 933 949 934 950 if (currentPos < costFunction.size()) 935 951 currentCost = costFunction[currentPos]; 936 952 #if 1 937 953 cout<<"costFunction.size()="<<(int)costFunction.size()<<endl; … … 941 957 #endif 942 958 if (costFunction.size()) { 943 float scaley = 1.0f/log10(maxCost); 944 float scalex = 1.0f/(float)costFunction.size(); 945 946 glDisable(GL_DEPTH_TEST); 947 // init ortographic projection 948 glMatrixMode(GL_PROJECTION); 949 950 glPushMatrix(); 951 952 glLoadIdentity(); 953 gluOrtho2D(0, 1.0f, 0, 1.0f); 954 955 glTranslatef(0.1f, 0.1f, 0.0f); 956 glScalef(0.8f, 0.8f, 1.0f); 957 glMatrixMode(GL_MODELVIEW); 958 glLoadIdentity(); 959 960 glColor3f(1.0f,0,0); 961 glBegin(GL_LINE_STRIP); 962 // glVertex3f(0,0,0); 963 964 for (int i=0; i < costFunction.size(); i++) { 965 float x = i*scalex; 966 float y = log10(costFunction[i])*scaley; 967 glVertex3f(x,y,0.0f); 968 } 969 glEnd(); 970 971 glColor3f(1.0f,0,0); 972 glBegin(GL_LINES); 973 float x = currentPos*scalex; 974 glVertex3f(x,0.0,0.0f); 975 glVertex3f(x,1.0f,0.0f); 976 glEnd(); 977 978 glColor3f(0.0f,0,0); 979 // show a grid 980 glBegin(GL_LINE_LOOP); 981 glVertex3f(0,0,0.0f); 982 glVertex3f(1,0,0.0f); 983 glVertex3f(1,1,0.0f); 984 glVertex3f(0,1,0.0f); 985 glEnd(); 986 987 glBegin(GL_LINES); 988 for (int i=0; i < costFunction.size(); i += 1000) { 989 float x = i*scalex; 959 float scaley = 1.0f/log10(maxCost); 960 float scalex = 1.0f/(float)costFunction.size(); 961 962 glDisable(GL_DEPTH_TEST); 963 // init ortographic projection 964 glMatrixMode(GL_PROJECTION); 965 966 glPushMatrix(); 967 968 glLoadIdentity(); 969 gluOrtho2D(0, 1.0f, 0, 1.0f); 970 971 glTranslatef(0.1f, 0.1f, 0.0f); 972 glScalef(0.8f, 0.8f, 1.0f); 973 glMatrixMode(GL_MODELVIEW); 974 glLoadIdentity(); 975 976 glColor3f(1.0f,0,0); 977 glBegin(GL_LINE_STRIP); 978 // glVertex3f(0,0,0); 979 980 for (int i=0; i < costFunction.size(); i++) { 981 float x = i*scalex; 982 float y = log10(costFunction[i])*scaley; 983 glVertex3f(x,y,0.0f); 984 } 985 glEnd(); 986 987 glColor3f(1.0f,0,0); 988 glBegin(GL_LINES); 989 float x = currentPos*scalex; 990 990 glVertex3f(x,0.0,0.0f); 991 991 glVertex3f(x,1.0f,0.0f); 992 } 993 994 for (int i=0; pow(10.0f, i) < maxCost; i+=1) { 995 float y = i*scaley; 996 // QString s; 997 // s.sprintf("%d", (int)pow(10,i)); 998 // renderText(width()/2+5, y*height(), s); 999 glVertex3f(0.0f, y, 0.0f); 1000 glVertex3f(1.0f, y, 0.0f); 1001 } 1002 1003 glEnd(); 1004 1005 1006 // restore the projection matrix 1007 glMatrixMode(GL_PROJECTION); 1008 glPopMatrix(); 1009 glMatrixMode(GL_MODELVIEW); 1010 glEnable(GL_DEPTH_TEST); 1011 1012 } 1013 992 glEnd(); 993 994 glColor3f(0.0f,0,0); 995 // show a grid 996 glBegin(GL_LINE_LOOP); 997 glVertex3f(0,0,0.0f); 998 glVertex3f(1,0,0.0f); 999 glVertex3f(1,1,0.0f); 1000 glVertex3f(0,1,0.0f); 1001 glEnd(); 1002 1003 glBegin(GL_LINES); 1004 for (int i=0; i < costFunction.size(); i += 1000) { 1005 float x = i*scalex; 1006 glVertex3f(x,0.0,0.0f); 1007 glVertex3f(x,1.0f,0.0f); 1008 } 1009 1010 for (int i=0; pow(10.0f, i) < maxCost; i+=1) { 1011 float y = i*scaley; 1012 // QString s; 1013 // s.sprintf("%d", (int)pow(10,i)); 1014 // renderText(width()/2+5, y*height(), s); 1015 glVertex3f(0.0f, y, 0.0f); 1016 glVertex3f(1.0f, y, 0.0f); 1017 } 1018 1019 glEnd(); 1020 1021 1022 // restore the projection matrix 1023 glMatrixMode(GL_PROJECTION); 1024 glPopMatrix(); 1025 glMatrixMode(GL_MODELVIEW); 1026 glEnable(GL_DEPTH_TEST); 1027 1028 } 1029 1014 1030 1015 1031 … … 1019 1035 QtGlRendererWidget::RenderInfo() 1020 1036 { 1021 1022 1023 1024 1025 vc = (int)mViewCellsManager->GetViewCells().size();1026 1027 1028 1029 filter = mViewCellsManager->GetMaxFilterSize();1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%",1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1037 1038 QString s; 1039 int vc = 0; 1040 if (mViewCellsManager) 1041 vc = (int)mViewCellsManager->GetViewCells().size(); 1042 1043 int filter = 0; 1044 if (mViewCellsManager) 1045 filter = mViewCellsManager->GetMaxFilterSize(); 1046 1047 glColor3f(1.0f,1.0f,1.0f); 1048 1049 s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)", 1050 mFrame, 1051 mViewPoint.x, 1052 mViewPoint.y, 1053 mViewPoint.z, 1054 mViewDirection.x, 1055 mViewDirection.y, 1056 mViewDirection.z 1057 ); 1058 1059 renderText(20,20,s); 1060 1061 s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %", 1062 vc, 1063 filter, 1064 mPvsSize, 1065 mRenderError*100.0f); 1066 1067 1068 renderText(20,40,s); 1069 1070 1071 1072 1057 1073 } 1058 1074 … … 1061 1077 QtGlRendererWidget::SetViewCellGranularity(int number) 1062 1078 { 1063 1064 // mViewCellsManager->SetMaxFilterSize(number);1065 1066 // $$ tmp off1067 mViewCellsManager->CollectViewCells(number);1068 1069 // $$ does not work so far:(1070 // mViewCellsManager->UpdatePvsForEvaluation();1071 // mViewCellsManager->FinalizeViewCells(false);1072 1073 1079 if (mViewCellsManager) { 1080 // mViewCellsManager->SetMaxFilterSize(number); 1081 1082 // $$ tmp off 1083 mViewCellsManager->CollectViewCells(number); 1084 1085 // $$ does not work so far:( 1086 // mViewCellsManager->UpdatePvsForEvaluation(); 1087 // mViewCellsManager->FinalizeViewCells(false); 1088 } 1089 updateGL(); 1074 1090 } 1075 1091 … … 1077 1093 QtGlRendererWidget::SetVisibilityFilterSize(int number) 1078 1094 { 1079 1080 1081 1082 1095 if (mViewCellsManager) 1096 mViewCellsManager->SetMaxFilterSize(number); 1097 mPvsCache.Reset(); 1098 updateGL(); 1083 1099 } 1084 1100 … … 1086 1102 QtGlRendererWidget::SetSpatialFilterSize(int number) 1087 1103 { 1088 1089 1090 1104 mSpatialFilterSize = 1e-3*number; 1105 mPvsCache.Reset(); 1106 updateGL(); 1091 1107 } 1092 1108 … … 1094 1110 QtGlRendererWidget::SetSceneCut(int number) 1095 1111 { 1096 // assume the cut plane can only be aligned with xz plane 1097 // shift it along y according to number, which is percentage of the bounding 1098 // box position 1099 if (mViewCellsManager) { 1100 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 1101 Vector3 p = box.Min() + (number/1000.0f)*box.Max(); 1102 mSceneCutPlane.mNormal = Vector3(0,-1,0); 1103 mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p); 1112 // assume the cut plane can only be aligned with xz plane 1113 // shift it along y according to number, which is percentage of the bounding 1114 // box position 1115 if (mViewCellsManager) { 1116 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 1117 Vector3 p = box.Min() + (number/1000.0f)*box.Max(); 1118 mSceneCutPlane.mNormal = Vector3(0,-1,0); 1119 mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p); 1120 updateGL(); 1121 } 1122 } 1123 1124 void 1125 QtGlRendererWidget::SetTopDistance(int number) 1126 { 1127 mTopDistance = number/1000.0f; 1104 1128 updateGL(); 1105 }1106 }1107 1108 void1109 QtGlRendererWidget::SetTopDistance(int number)1110 {1111 mTopDistance = number/1000.0f;1112 updateGL();1113 1129 } 1114 1130 … … 1116 1132 QtGlRendererWidget::RenderViewCells() 1117 1133 { 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 glClipPlane(GL_CLIP_PLANE0, eq);1134 glEnable(GL_CLIP_PLANE0);1135 1136 1137 1138 1139 1140 1141 1142 ViewCell *vc = viewcells[i];1143 1144 //const int p = vc->GetPvs().CountObjectsInPvs();1145 const int p = vc->GetPvs().GetSize();1146 if (p > maxPvs)1147 1148 1149 1150 1151 1152 ViewCell *vc = viewcells[i];1153 // Mesh *m = vc->GetMesh();1154 1155 RgbColor c;1156 1157 if (!mShowPvsSizes) {1158 1159 1160 } else {1161 1162 1163 ((float)vc->GetPvs().GetSize() / (float)maxPvs);1164 1165 1166 1167 }1168 glColor3f(c.r, c.g, c.b);1169 1170 RenderViewCell(vc);1171 1172 1173 1174 1175 1176 1177 1134 mUseFalseColors = true; 1135 1136 glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT); 1137 1138 glEnable(GL_CULL_FACE); 1139 glCullFace(GL_FRONT); 1140 1141 glDisable(GL_CULL_FACE); 1142 double eq[4]; 1143 eq[0] = mSceneCutPlane.mNormal.x; 1144 eq[1] = mSceneCutPlane.mNormal.y; 1145 eq[2] = mSceneCutPlane.mNormal.z; 1146 eq[3] = mSceneCutPlane.mD; 1147 1148 if (mCutViewCells) { 1149 glClipPlane(GL_CLIP_PLANE0, eq); 1150 glEnable(GL_CLIP_PLANE0); 1151 } 1152 1153 int i; 1154 ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 1155 int maxPvs = -1; 1156 for (i=0; i < viewcells.size(); i++) 1157 { 1158 ViewCell *vc = viewcells[i]; 1159 1160 //const int p = vc->GetPvs().CountObjectsInPvs(); 1161 const int p = vc->GetPvs().GetSize(); 1162 if (p > maxPvs) 1163 maxPvs = p; 1164 } 1165 1166 1167 for (i=0; i < viewcells.size(); i++) { 1168 ViewCell *vc = viewcells[i]; 1169 // Mesh *m = vc->GetMesh(); 1170 1171 RgbColor c; 1172 1173 if (!mShowPvsSizes) { 1174 mWireFrame = true; 1175 c = vc->GetColor(); 1176 } else { 1177 // const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs); 1178 const float importance = 5.0f*mTransferFunction * 1179 ((float)vc->GetPvs().GetSize() / (float)maxPvs); 1180 // c = RgbColor(importance, 1.0f - importance, 0.0f); 1181 c = RainbowColorMapping(importance); 1182 1183 } 1184 glColor3f(c.r, c.g, c.b); 1185 1186 RenderViewCell(vc); 1187 } 1188 1189 mUseFalseColors = false; 1190 mWireFrame = false; 1191 1192 glPopAttrib(); 1193 1178 1194 } 1179 1195 … … 1186 1202 1187 1203 QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent) 1188 1204 : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf) 1189 1205 { 1190 1206 // create the pbuffer 1191 1192 1193 1207 //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this); 1208 timerId = startTimer(20); 1209 setWindowTitle(("OpenGL pbuffers")); 1194 1210 } 1195 1211 … … 1197 1213 QtGlDebuggerWidget::~QtGlDebuggerWidget() 1198 1214 { 1199 1200 1201 1202 1215 mRenderBuffer->releaseFromDynamicTexture(); 1216 glDeleteTextures(1, &dynamicTexture); 1217 1218 DEL_PTR(mRenderBuffer); 1203 1219 } 1204 1220 1205 1221 1206 1222 QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f): 1207 QWidget(parent, f) 1208 { 1209 1210 QVBoxLayout *vl = new QVBoxLayout; 1211 setLayout(vl); 1212 1213 QWidget *vbox = new QGroupBox("ViewCells", this); 1214 layout()->addWidget(vbox); 1215 1216 vl = new QVBoxLayout; 1217 vbox->setLayout(vl); 1218 1219 QLabel *label = new QLabel("Granularity"); 1220 vbox->layout()->addWidget(label); 1221 1222 QSlider *slider = new QSlider(Qt::Horizontal, vbox); 1223 vl->addWidget(slider); 1224 slider->show(); 1225 slider->setRange(1, 10000); 1226 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1227 slider->setValue(200); 1228 1229 1230 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); 1231 1232 label = new QLabel("Transfer function"); 1233 vbox->layout()->addWidget(label); 1234 1235 slider = new QSlider(Qt::Horizontal, vbox); 1236 vl->addWidget(slider); 1237 slider->show(); 1238 slider->setRange(1, 10000); 1239 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1240 slider->setValue(100); 1241 1242 1243 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int))); 1244 1245 { 1246 QPushButton *button = new QPushButton("Update all PVSs", vbox); 1247 vbox->layout()->addWidget(button); 1248 connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs())); 1249 } 1250 1251 1252 label = new QLabel("Filter size"); 1253 vbox->layout()->addWidget(label); 1254 1255 slider = new QSlider(Qt::Horizontal, vbox); 1256 vbox->layout()->addWidget(slider); 1257 slider->show(); 1258 slider->setRange(1, 100); 1259 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1260 slider->setValue(3); 1261 1262 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int))); 1263 1264 1265 label = new QLabel("Spatial Filter size"); 1266 vbox->layout()->addWidget(label); 1267 1268 slider = new QSlider(Qt::Horizontal, vbox); 1269 vbox->layout()->addWidget(slider); 1270 slider->show(); 1271 slider->setRange(1, 100); 1272 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1273 slider->setValue(10); 1274 1275 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int))); 1276 1277 1278 1279 QWidget *hbox = new QWidget(vbox); 1280 vl->addWidget(hbox); 1281 QHBoxLayout *hlayout = new QHBoxLayout; 1282 hbox->setLayout(hlayout); 1283 1284 QCheckBox *cb = new QCheckBox("Show viewcells", hbox); 1285 hlayout->addWidget(cb); 1286 cb->setChecked(false); 1287 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 1288 1289 cb = new QCheckBox("Render cost curve", hbox); 1290 hlayout->addWidget(cb); 1291 cb->setChecked(false); 1292 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool))); 1293 1294 cb = new QCheckBox("Show render cost", hbox); 1295 hlayout->addWidget(cb); 1296 cb->setChecked(false); 1297 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); 1298 1299 cb = new QCheckBox("Show rays", hbox); 1300 hlayout->addWidget(cb); 1301 cb->setChecked(false); 1302 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool))); 1303 1304 vbox->resize(800,100); 1305 1306 1307 vbox = new QGroupBox("Rendering", this); 1308 layout()->addWidget(vbox); 1309 1310 vl = new QVBoxLayout; 1311 vbox->setLayout(vl); 1312 1313 1314 1315 cb = new QCheckBox("Cut view cells", vbox); 1316 vbox->layout()->addWidget(cb); 1317 cb->setChecked(false); 1318 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); 1319 1320 1321 slider = new QSlider(Qt::Horizontal, vbox); 1322 vbox->layout()->addWidget(slider); 1323 slider->show(); 1324 slider->setRange(0, 1000); 1325 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1326 slider->setValue(1000); 1327 1328 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 1329 1330 1331 cb = new QCheckBox("Cut scene", vbox); 1332 vbox->layout()->addWidget(cb); 1333 cb->setChecked(false); 1334 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); 1335 1336 cb = new QCheckBox("Render boxes", vbox); 1337 vbox->layout()->addWidget(cb); 1338 cb->setChecked(false); 1339 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool))); 1340 1341 cb = new QCheckBox("Render visibility estimates", vbox); 1342 vbox->layout()->addWidget(cb); 1343 cb->setChecked(false); 1344 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool))); 1345 1346 1347 cb = new QCheckBox("Render errors", vbox); 1348 vbox->layout()->addWidget(cb); 1349 cb->setChecked(false); 1350 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 1351 1352 1353 bool tmp; 1354 1355 cb = new QCheckBox("Use filter", vbox); 1356 vbox->layout()->addWidget(cb); 1357 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); 1358 cb->setChecked(tmp); 1359 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool))); 1360 1361 1362 cb = new QCheckBox("Use spatial filter", vbox); 1363 vbox->layout()->addWidget(cb); 1364 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 1365 tmp ); 1366 cb->setChecked(tmp); 1367 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool))); 1368 1369 cb = new QCheckBox("Render filter", vbox); 1370 vbox->layout()->addWidget(cb); 1371 cb->setChecked(true); 1372 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool))); 1373 1374 1375 1376 1377 slider = new QSlider(Qt::Horizontal, vbox); 1378 vbox->layout()->addWidget(slider); 1379 slider->show(); 1380 slider->setRange(1, 1000); 1381 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1382 slider->setValue(500); 1383 1384 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); 1385 1386 cb = new QCheckBox("Top View", vbox); 1387 vbox->layout()->addWidget(cb); 1388 cb->setChecked(false); 1389 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 1390 1391 1392 1393 vbox = new QGroupBox("PVS Errors", this); 1394 layout()->addWidget(vbox); 1395 1396 vl = new QVBoxLayout; 1397 vbox->setLayout(vl); 1398 1399 QPushButton *button = new QPushButton("Compute Visibility", vbox); 1400 vbox->layout()->addWidget(button); 1401 connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility())); 1402 1403 button = new QPushButton("Stop Computation", vbox); 1404 vbox->layout()->addWidget(button); 1405 connect(button, SIGNAL(clicked()), SLOT(StopComputation())); 1406 1407 button = new QPushButton("Set Random View Point", vbox); 1408 vbox->layout()->addWidget(button); 1409 connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint())); 1410 1411 1412 if (0) { 1223 QWidget(parent, f) 1224 { 1225 1226 QVBoxLayout *vl = new QVBoxLayout; 1227 setLayout(vl); 1228 1229 QWidget *vbox = new QGroupBox("ViewCells", this); 1230 layout()->addWidget(vbox); 1231 1232 vl = new QVBoxLayout; 1233 vbox->setLayout(vl); 1234 1235 QLabel *label = new QLabel("Granularity"); 1236 vbox->layout()->addWidget(label); 1237 1238 QSlider *slider = new QSlider(Qt::Horizontal, vbox); 1239 vl->addWidget(slider); 1240 slider->show(); 1241 slider->setRange(1, 10000); 1242 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1243 slider->setValue(200); 1244 1245 1246 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); 1247 1248 label = new QLabel("Transfer function"); 1249 vbox->layout()->addWidget(label); 1250 1251 slider = new QSlider(Qt::Horizontal, vbox); 1252 vl->addWidget(slider); 1253 slider->show(); 1254 slider->setRange(1, 10000); 1255 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1256 slider->setValue(100); 1257 1258 1259 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int))); 1260 1261 { 1262 QPushButton *button = new QPushButton("Update all PVSs", vbox); 1263 vbox->layout()->addWidget(button); 1264 connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs())); 1265 } 1266 1267 1268 label = new QLabel("Filter size"); 1269 vbox->layout()->addWidget(label); 1270 1271 slider = new QSlider(Qt::Horizontal, vbox); 1272 vbox->layout()->addWidget(slider); 1273 slider->show(); 1274 slider->setRange(1, 100); 1275 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1276 slider->setValue(3); 1277 1278 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int))); 1279 1280 1281 label = new QLabel("Spatial Filter size"); 1282 vbox->layout()->addWidget(label); 1283 1284 slider = new QSlider(Qt::Horizontal, vbox); 1285 vbox->layout()->addWidget(slider); 1286 slider->show(); 1287 slider->setRange(1, 100); 1288 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1289 slider->setValue(10); 1290 1291 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int))); 1292 1293 1294 1295 QWidget *hbox = new QWidget(vbox); 1296 vl->addWidget(hbox); 1297 QHBoxLayout *hlayout = new QHBoxLayout; 1298 hbox->setLayout(hlayout); 1299 1300 QCheckBox *cb = new QCheckBox("Show viewcells", hbox); 1301 hlayout->addWidget(cb); 1302 cb->setChecked(false); 1303 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 1304 1305 cb = new QCheckBox("Render cost curve", hbox); 1306 hlayout->addWidget(cb); 1307 cb->setChecked(false); 1308 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool))); 1309 1310 cb = new QCheckBox("Show render cost", hbox); 1311 hlayout->addWidget(cb); 1312 cb->setChecked(false); 1313 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); 1314 1315 cb = new QCheckBox("Show rays", hbox); 1316 hlayout->addWidget(cb); 1317 cb->setChecked(false); 1318 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool))); 1319 1320 vbox->resize(800,100); 1321 1322 1323 vbox = new QGroupBox("Rendering", this); 1324 layout()->addWidget(vbox); 1325 1326 vl = new QVBoxLayout; 1327 vbox->setLayout(vl); 1328 1329 1330 1331 cb = new QCheckBox("Cut view cells", vbox); 1332 vbox->layout()->addWidget(cb); 1333 cb->setChecked(false); 1334 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); 1335 1336 1337 slider = new QSlider(Qt::Horizontal, vbox); 1338 vbox->layout()->addWidget(slider); 1339 slider->show(); 1340 slider->setRange(0, 1000); 1341 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1342 slider->setValue(1000); 1343 1344 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 1345 1346 1347 cb = new QCheckBox("Cut scene", vbox); 1348 vbox->layout()->addWidget(cb); 1349 cb->setChecked(false); 1350 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); 1351 1352 cb = new QCheckBox("Render boxes", vbox); 1353 vbox->layout()->addWidget(cb); 1354 cb->setChecked(false); 1355 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool))); 1356 1357 cb = new QCheckBox("Render visibility estimates", vbox); 1358 vbox->layout()->addWidget(cb); 1359 cb->setChecked(false); 1360 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool))); 1361 1362 1363 cb = new QCheckBox("Render errors", vbox); 1364 vbox->layout()->addWidget(cb); 1365 cb->setChecked(false); 1366 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 1367 1368 1369 bool tmp; 1370 1371 cb = new QCheckBox("Use filter", vbox); 1372 vbox->layout()->addWidget(cb); 1373 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); 1374 cb->setChecked(tmp); 1375 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool))); 1376 1377 1378 cb = new QCheckBox("Use spatial filter", vbox); 1379 vbox->layout()->addWidget(cb); 1380 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 1381 tmp ); 1382 cb->setChecked(tmp); 1383 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool))); 1384 1385 cb = new QCheckBox("Render filter", vbox); 1386 vbox->layout()->addWidget(cb); 1387 cb->setChecked(true); 1388 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool))); 1389 1390 1391 1392 1393 slider = new QSlider(Qt::Horizontal, vbox); 1394 vbox->layout()->addWidget(slider); 1395 slider->show(); 1396 slider->setRange(1, 1000); 1397 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 1398 slider->setValue(500); 1399 1400 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); 1401 1402 cb = new QCheckBox("Top View", vbox); 1403 vbox->layout()->addWidget(cb); 1404 cb->setChecked(false); 1405 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 1406 1407 1408 1413 1409 vbox = new QGroupBox("PVS Errors", this); 1414 1410 layout()->addWidget(vbox); 1415 1411 1416 1412 vl = new QVBoxLayout; 1417 1413 vbox->setLayout(vl); 1418 1419 mPvsErrorWidget = new QListWidget(vbox); 1420 vbox->layout()->addWidget(mPvsErrorWidget); 1421 1422 connect(mPvsErrorWidget, 1414 1415 QPushButton *button = new QPushButton("Compute Visibility", vbox); 1416 vbox->layout()->addWidget(button); 1417 connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility())); 1418 1419 button = new QPushButton("Stop Computation", vbox); 1420 vbox->layout()->addWidget(button); 1421 connect(button, SIGNAL(clicked()), SLOT(StopComputation())); 1422 1423 button = new QPushButton("Set Random View Point", vbox); 1424 vbox->layout()->addWidget(button); 1425 connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint())); 1426 1427 1428 if (0) { 1429 vbox = new QGroupBox("PVS Errors", this); 1430 layout()->addWidget(vbox); 1431 1432 vl = new QVBoxLayout; 1433 vbox->setLayout(vl); 1434 1435 mPvsErrorWidget = new QListWidget(vbox); 1436 vbox->layout()->addWidget(mPvsErrorWidget); 1437 1438 connect(mPvsErrorWidget, 1423 1439 SIGNAL(doubleClicked(const QModelIndex &)), 1424 1440 this, 1425 1441 SLOT(PvsErrorClicked(const QModelIndex &))); 1426 1427 QPushButton *button = new QPushButton("Next Error Frame", vbox);1428 vbox->layout()->addWidget(button);1429 connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));1430 1431 1432 1433 1442 1443 QPushButton *button = new QPushButton("Next Error Frame", vbox); 1444 vbox->layout()->addWidget(button); 1445 connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void))); 1446 } 1447 1448 setWindowTitle("Preprocessor Control Widget"); 1449 adjustSize(); 1434 1450 } 1435 1451 … … 1440 1456 QtRendererControlWidget::FocusNextPvsErrorFrame(void) 1441 1457 { 1442 1443 1458 1459 1444 1460 } 1445 1461 1446 1462 void 1447 1463 QtRendererControlWidget::UpdatePvsErrorItem(int row, 1448 1449 { 1450 1451 1452 1453 1454 1455 i->setText(s);1456 1457 new QListWidgetItem(s, mPvsErrorWidget);1458 1459 1464 GlRendererBuffer::PvsErrorEntry &pvsErrorEntry) 1465 { 1466 1467 QListWidgetItem *i = mPvsErrorWidget->item(row); 1468 QString s; 1469 s.sprintf("%5.5f", pvsErrorEntry.mError); 1470 if (i) { 1471 i->setText(s); 1472 } else { 1473 new QListWidgetItem(s, mPvsErrorWidget); 1474 } 1475 mPvsErrorWidget->update(); 1460 1476 } 1461 1477 … … 1488 1504 // draw a spinning cube into the pbuffer.. 1489 1505 mRenderBuffer->makeCurrent(); 1490 1506 1491 1507 BeamSampleStatistics stats; 1492 1508 mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats); … … 1495 1511 1496 1512 // rendering directly to a texture is not supported on X11, unfortunately 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1513 mRenderBuffer->updateDynamicTexture(dynamicTexture); 1514 1515 // and use the pbuffer contents as a texture when rendering the 1516 // background and the bouncing cubes 1517 makeCurrent(); 1518 glBindTexture(GL_TEXTURE_2D, dynamicTexture); 1519 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1520 1521 // draw the background 1522 glMatrixMode(GL_MODELVIEW); 1523 glPushMatrix(); 1524 glLoadIdentity(); 1525 glMatrixMode(GL_PROJECTION); 1526 glPushMatrix(); 1527 glLoadIdentity(); 1528 1529 glPopMatrix(); 1514 1530 glMatrixMode(GL_MODELVIEW); 1515 1531 glPopMatrix(); … … 1520 1536 { 1521 1537 // set up the pbuffer context 1522 1538 mRenderBuffer->makeCurrent(); 1523 1539 /*mRenderBuffer->InitGL(); 1524 1540 … … 1532 1548 1533 1549 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/ 1534 1550 1535 1551 // generate a texture that has the same size/format as the pbuffer 1536 1552 dynamicTexture = mRenderBuffer->generateDynamicTexture(); 1537 1553 1538 1554 // bind the dynamic texture to the pbuffer - this is a no-op under X11 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r2538 r2543 4 4 #include <QtOpenGL> 5 5 #include <QWaitCondition> 6 7 //#include <QGLPixelBuffer> 6 #include <QMutex> 8 7 9 8 #include "Vector3.h" … … 14 13 #include "Beam.h" 15 14 #include "QtPreprocessorThread.h" 15 16 16 17 class QWidget; 17 //class QtPreprocessorThread; 18 19 18 20 19 21 namespace GtpVisibilityPreprocessor { … … 119 121 class QtGlRendererWidget : public QGLWidget, public GlRendererWidget 120 122 { 121 Q_OBJECT 122 public: 123 124 // point of the last mouse click used for movement in the scene 125 Vector3 mousePoint; 126 127 bool mTopView; 128 bool mRenderViewCells; 129 bool mCutViewCells; 130 bool mCutScene; 131 bool mRenderErrors; 132 bool mRenderFilter; 133 bool mRenderVisibilityEstimates; 134 bool mUseFilter; 135 bool mUseSpatialFilter; 136 bool mShowRenderCost; 137 bool mShowRays; 138 139 bool mShowPvsSizes; 140 float mSpatialFilterSize; 141 142 Plane3 mSceneCutPlane; 143 float mTopDistance; 144 145 // some statistics 146 int mPvsSize; 147 float mRenderError; 148 float mTransferFunction; 149 150 unsigned int mIndexBufferSize; 151 152 QtRendererControlWidget *mControlWidget; 153 154 QtPreprocessorThread *mPreprocessorThread; 155 156 QtGlRendererWidget(SceneGraph *sceneGraph, 157 ViewCellsManager *viewcells, 158 KdTree *tree, 159 QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0 160 ); 161 162 QtGlRendererWidget() {}; 163 164 void SetThread(QtPreprocessorThread *t) { 165 mPreprocessorThread = t; 166 } 167 void 168 RenderRenderCost(); 169 170 virtual void SetupCamera(); 171 172 void initializeGL() { 173 InitGL(); 174 } 175 176 virtual void InitGL(); 177 178 void resizeGL(int w, int h); 179 void paintGL(); 180 void timerEvent(QTimerEvent *event); 181 void mousePressEvent(QMouseEvent *); 182 void mouseReleaseEvent(QMouseEvent *); 183 void mouseMoveEvent(QMouseEvent *); 184 185 void keyPressEvent(QKeyEvent * e); 186 187 void RenderPvs(); 188 189 float RenderErrors(); 190 void RenderInfo(); 191 192 virtual int GetWidth() const { return width(); } 193 virtual int GetHeight() const { return height(); } 194 195 // virtual void 196 // SetupProjection(const int w, const int h, const float angle = 70.0f); 197 198 virtual void 199 SetupCameraProjection(const int w, const int h, const float angle = 70.0f); 200 201 void 202 RenderViewCells(); 203 204 205 virtual void Show() { 206 show(); 207 } 208 209 bool PvsChanged(ViewCell *viewcell) const; 210 211 212 public slots: 213 214 void UpdateAllPvs(); 215 void ComputeVisibility(); 216 void StopComputation(); 217 void SetRandomViewPoint(); 218 219 void SetRenderErrors(bool b) { 220 mRenderErrors = b; 221 updateGL(); 222 } 223 224 void SetRenderBoxes(bool b) { 225 mRenderBoxes = b; 226 updateGL(); 227 } 228 229 void SetRenderFilter(bool b) { 230 mRenderFilter = b; 231 updateGL(); 232 } 233 234 void SetRenderVisibilityEstimates(bool b) { 235 mRenderVisibilityEstimates = b; 236 updateGL(); 237 } 238 239 void SetUseFilter(bool b) { 240 mUseFilter = b; 241 mPvsCache.Reset(); 242 updateGL(); 243 } 244 245 void SetUseSpatialFilter(bool b) { 246 mUseSpatialFilter = b; 247 mPvsCache.Reset(); 248 updateGL(); 249 } 250 251 252 void 253 SetViewCellGranularity(int number); 254 255 void 256 SetTransferFunction(int number) { 257 mTransferFunction = number/1000.0f; 258 updateGL(); 259 } 260 261 void 262 SetVisibilityFilterSize(int number); 263 264 void 265 SetSpatialFilterSize(int number); 266 267 void 268 SetSceneCut(int cut); 269 270 void 271 SetTopDistance(int dist); 272 273 void SetShowViewCells(bool b) { 274 mRenderViewCells = b; 275 updateGL(); 276 } 277 278 void SetShowRays(bool b) { 279 mShowRays = b; 280 updateGL(); 281 } 282 283 void SetShowRenderCost(bool b) { 284 mShowRenderCost = b; 285 updateGL(); 286 } 287 288 void SetShowPvsSizes(bool b) { 289 mShowPvsSizes = b; 290 updateGL(); 291 } 292 293 void SetTopView(bool b) { 294 mTopView = b; 295 updateGL(); 296 } 297 298 void SetCutViewCells(bool b) { 299 mCutViewCells = b; 300 updateGL(); 301 } 302 void SetCutScene(bool b) { 303 mCutScene = b; 304 updateGL(); 305 } 306 307 void _RenderPvs(); 308 309 void _UpdatePvsIndices(); 310 void _UpdatePvsIndices(KdNode *node); 311 312 signals: 313 void PvsUpdated(); 123 Q_OBJECT 124 public: 125 126 // point of the last mouse click used for movement in the scene 127 Vector3 mousePoint; 128 129 bool mTopView; 130 bool mRenderViewCells; 131 bool mCutViewCells; 132 bool mCutScene; 133 bool mRenderErrors; 134 bool mRenderFilter; 135 bool mRenderVisibilityEstimates; 136 bool mUseFilter; 137 bool mUseSpatialFilter; 138 bool mShowRenderCost; 139 bool mShowRays; 140 141 bool mShowPvsSizes; 142 float mSpatialFilterSize; 143 144 Plane3 mSceneCutPlane; 145 float mTopDistance; 146 147 // some statistics 148 int mPvsSize; 149 float mRenderError; 150 float mTransferFunction; 151 152 unsigned int mIndexBufferSize; 153 154 QtRendererControlWidget *mControlWidget; 155 156 QtPreprocessorThread *mPreprocessorThread; 157 158 QtGlRendererWidget(SceneGraph *sceneGraph, 159 ViewCellsManager *viewcells, 160 KdTree *tree, 161 QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0 162 ); 163 164 QtGlRendererWidget() {}; 165 166 void SetThread(QtPreprocessorThread *t) { 167 mPreprocessorThread = t; 168 } 169 void 170 RenderRenderCost(); 171 172 virtual void SetupCamera(); 173 174 void initializeGL() { 175 InitGL(); 176 } 177 178 virtual void InitGL(); 179 180 void resizeGL(int w, int h); 181 void paintGL(); 182 void timerEvent(QTimerEvent *event); 183 void mousePressEvent(QMouseEvent *); 184 void mouseReleaseEvent(QMouseEvent *); 185 void mouseMoveEvent(QMouseEvent *); 186 187 void keyPressEvent(QKeyEvent * e); 188 189 void RenderPvs(); 190 191 float RenderErrors(); 192 void RenderInfo(); 193 194 virtual int GetWidth() const { return width(); } 195 virtual int GetHeight() const { return height(); } 196 197 // virtual void 198 // SetupProjection(const int w, const int h, const float angle = 70.0f); 199 200 virtual void 201 SetupCameraProjection(const int w, const int h, const float angle = 70.0f); 202 203 void 204 RenderViewCells(); 205 206 207 virtual void Show() { 208 show(); 209 } 210 211 bool PvsChanged(ViewCell *viewcell) const; 212 213 ///////// 214 215 //QMutex mMutex; 216 217 218 public slots: 219 220 void UpdateAllPvs(); 221 void ComputeVisibility(); 222 void StopComputation(); 223 void SetRandomViewPoint(); 224 225 void SetRenderErrors(bool b) { 226 mRenderErrors = b; 227 updateGL(); 228 } 229 230 void SetRenderBoxes(bool b) { 231 mRenderBoxes = b; 232 updateGL(); 233 } 234 235 void SetRenderFilter(bool b) { 236 mRenderFilter = b; 237 updateGL(); 238 } 239 240 void SetRenderVisibilityEstimates(bool b) { 241 mRenderVisibilityEstimates = b; 242 updateGL(); 243 } 244 245 void SetUseFilter(bool b) { 246 mUseFilter = b; 247 mPvsCache.Reset(); 248 updateGL(); 249 } 250 251 void SetUseSpatialFilter(bool b) { 252 mUseSpatialFilter = b; 253 mPvsCache.Reset(); 254 updateGL(); 255 } 256 257 258 void 259 SetViewCellGranularity(int number); 260 261 void SetTransferFunction(int number) 262 { 263 mTransferFunction = number/1000.0f; 264 updateGL(); 265 } 266 267 void SetVisibilityFilterSize(int number); 268 269 void 270 SetSpatialFilterSize(int number); 271 272 void 273 SetSceneCut(int cut); 274 275 void 276 SetTopDistance(int dist); 277 278 void SetShowViewCells(bool b) { 279 mRenderViewCells = b; 280 updateGL(); 281 } 282 283 void SetShowRays(bool b) { 284 mShowRays = b; 285 updateGL(); 286 } 287 288 void SetShowRenderCost(bool b) { 289 mShowRenderCost = b; 290 updateGL(); 291 } 292 293 void SetShowPvsSizes(bool b) { 294 mShowPvsSizes = b; 295 updateGL(); 296 } 297 298 void SetTopView(bool b) { 299 mTopView = b; 300 updateGL(); 301 } 302 303 void SetCutViewCells(bool b) { 304 mCutViewCells = b; 305 updateGL(); 306 } 307 void SetCutScene(bool b) { 308 mCutScene = b; 309 updateGL(); 310 } 311 312 void _RenderPvs(); 313 314 void _UpdatePvsIndices(); 315 316 void _UpdatePvsIndices(KdNode *node, int &indexBufferSize); 317 318 319 320 ///////// 321 322 signals: 323 void PvsUpdated(); 314 324 }; 315 325 … … 339 349 340 350 private: 351 341 352 GLuint dynamicTexture; 342 353 int timerId; 343 354 }; 344 355 356 345 357 extern QtGlDebuggerWidget *debuggerWidget; 346 358 -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r2187 r2543 77 77 78 78 79 80 81 VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)82 {}79 // pool of vss rays to be used in one pass of the sampling 80 struct VssRayPool { 81 VssRayPool(): mRays(NULL), mIndex(0), mNumber(0) 82 {} 83 83 84 ~VssRayPool() 85 { 86 DEL_PTR(mRays); 84 ~VssRayPool() 85 { 86 DEL_PTR(mRays); 87 } 88 89 void Reserve(const int number) { 90 DEL_PTR(mRays); 91 mRays = new VssRay[number]; 92 mNumber = number; 93 } 94 95 void Clear() { 96 mIndex = 0; 97 } 98 VssRay *Alloc() { 99 // reset pool 100 if (mIndex == mNumber) 101 mIndex = 0; 102 return mRays + mIndex ++; 103 } 104 protected: 105 VssRay *mRays; 106 int mIndex; 107 int mNumber; 108 }; 109 110 VssRayPool mVssRayPool; 111 112 void ReserveVssRayPool(const int n) { 113 mVssRayPool.Reserve(n); 87 114 } 88 89 void Reserve(const int number) { 90 DEL_PTR(mRays); 91 mRays = new VssRay[number]; 92 mNumber = number; 115 116 void InitPass() { 117 mVssRayPool.Clear(); 93 118 } 94 95 void Clear() {96 mIndex = 0;97 }98 VssRay *Alloc() {99 // reset pool100 if (mIndex == mNumber)101 mIndex = 0;102 return mRays + mIndex ++;103 }104 protected:105 VssRay *mRays;106 int mIndex;107 int mNumber;108 };109 110 VssRayPool mVssRayPool;111 112 void ReserveVssRayPool(const int n) {113 mVssRayPool.Reserve(n);114 }115 116 void InitPass() {117 mVssRayPool.Clear();118 }119 119 120 120 … … 122 122 123 123 VssRay *RequestRay(const Vector3 &origin, 124 125 126 127 128 124 const Vector3 &termination, 125 Intersectable *originObject, 126 Intersectable *terminationObject, 127 const int pass, 128 const float pdf); 129 129 130 void _SortRays(SimpleRayContainer &rays, 131 const int l, 132 const int r, 133 const int depth, 134 float box[12]); 135 136 struct Intersection 137 { 138 Intersection(): mObject(NULL), mFaceId(0) 139 {} 130 void _SortRays(SimpleRayContainer &rays, 131 const int l, 132 const int r, 133 const int depth, 134 float box[12]); 140 135 141 Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): 142 mPoint(p), mNormal(n), mObject(o), mFaceId(f) 143 {} 136 struct Intersection 137 { 138 Intersection(): mObject(NULL), mFaceId(0) 139 {} 144 140 145 Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) 146 {} 147 Vector3 mPoint; 148 Vector3 mNormal; 149 Intersectable *mObject; 150 int mFaceId; 151 }; 141 Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): 142 mPoint(p), mNormal(n), mObject(o), mFaceId(f) 143 {} 144 145 Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) 146 {} 152 147 153 148 154 int ProcessRay(const SimpleRay &ray, 155 Intersection &hitA, 156 Intersection &hitB, 157 VssRayContainer &vssRays, 158 const AxisAlignedBox3 &box, 159 const bool castDoubleRay, 160 const bool pruneInvalidRays = true); 149 //////////// 161 150 162 /** Checks if ray is valid. 163 I.e., the ray is in valid view space. 164 @note: clamps the ray to valid view space. 165 */ 166 bool ValidateRay(const Vector3 &origin, 167 const Vector3 &direction, 168 const AxisAlignedBox3 &box, 169 Intersection &hit); 151 Vector3 mPoint; 152 Vector3 mNormal; 153 Intersectable *mObject; 154 int mFaceId; 155 }; 170 156 171 bool 172 ClipToViewSpaceBox(const Vector3 &origin, 173 const Vector3 &termination, 174 Vector3 &clippedOrigin, 175 Vector3 &clippedTermination); 157 158 int ProcessRay(const SimpleRay &ray, 159 Intersection &hitA, 160 Intersection &hitB, 161 VssRayContainer &vssRays, 162 const AxisAlignedBox3 &box, 163 const bool castDoubleRay, 164 const bool pruneInvalidRays = true); 165 166 /** Checks if ray is valid. 167 I.e., the ray is in valid view space. 168 @note: clamps the ray to valid view space. 169 */ 170 bool ValidateRay(const Vector3 &origin, 171 const Vector3 &direction, 172 const AxisAlignedBox3 &box, 173 Intersection &hit); 174 175 bool ClipToViewSpaceBox(const Vector3 &origin, 176 const Vector3 &termination, 177 Vector3 &clippedOrigin, 178 Vector3 &clippedTermination); 176 179 177 180 … … 180 183 181 184 182 185 const Preprocessor &mPreprocessor; 183 186 }; 184 187 -
GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h
r2227 r2543 29 29 30 30 virtual ~SubdivisionCandidate() {}; 31 32 31 /** Evaluate this subdivision candidate. 33 32 */ 34 33 virtual void EvalCandidate(bool computeSplitplane = true) = 0; 35 36 34 /** Returns type of this subdivision candidate. 37 35 */ 38 36 virtual int Type() const = 0; 39 40 37 /** Evaluate this candidate and put results into queue for further traversal. 41 38 */ … … 43 40 bool terminationCriteriaMet, 44 41 SubdivisionCandidateContainer &dirtyList) = 0; 45 46 42 /** Returns true of the global termination criteria of this split were met, 47 43 false otherwise. 48 44 */ 49 45 virtual bool GlobalTerminationCriteriaMet() const = 0; 50 51 46 /** Collects subdivision candidates that were affected by the 52 47 application of this one. … … 54 49 virtual void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList, 55 50 const bool onlyUnmailed) = 0; 56 57 51 /** Set render cost decrease achieved through this split. 58 52 */ … … 61 55 mRenderCostDecrease = renderCostDecr; 62 56 } 63 64 57 inline float GetRenderCostDecrease() const 65 58 { 66 59 return mRenderCostDecrease; 67 60 } 68 69 61 /** The average ray contribution of this candidate . 70 62 This is somewhat of a confidence value into the computed values. If … … 75 67 mAvgRayContribution = rayContri; 76 68 } 77 78 69 /** The average ray contribution of this candidate . 79 70 This is somewhat of a confidence value into the computed values. If … … 89 80 return mAvgRayContribution; 90 81 } 91 92 82 /** Returns average rays per object. 93 83 */ … … 96 86 return (float)mAvgRaysPerObject; 97 87 } 98 99 88 /** Position in queue. 100 89 */ … … 103 92 return mPosition; 104 93 } 105 94 106 95 inline void SetSplitAxis(const int splitAxis) 107 96 { … … 144 133 } 145 134 135 146 136 ////////// 147 137 //-- mailing stuff … … 161 151 int IncMail() { return ++ mMailbox - sMailId; } 162 152 163 164 153 // last mail id -> warning not thread safe! 165 // both mailId and mailbox should be unique for each thread!!!166 154 static int sMailId; 167 155 static int sReservedMailboxes; 168 156 169 void *mEvaluationHack; 157 // note: both mailId and mailbox should be unique for each thread!!! 158 170 159 171 160 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r2539 r2543 38 38 LinkIncremental="2" 39 39 AdditionalLibraryDirectories="..\include;..\src\GL;"..\lib\$(ConfigurationName)";..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib" 40 GenerateDebugInformation=" FALSE"40 GenerateDebugInformation="TRUE" 41 41 ProgramDatabaseFile="$(OutDir)/TestPreprocessor.pdb" 42 42 SubSystem="1" … … 164 164 LinkIncremental="1" 165 165 AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;"$(QTDIR)\lib";.\QtInterface\Release;"$(CG_LIB_PATH)"" 166 GenerateDebugInformation=" FALSE"166 GenerateDebugInformation="TRUE" 167 167 SubSystem="1" 168 168 LargeAddressAware="2" -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r2542 r2543 2589 2589 2590 2590 /////////////////// 2591 //-- Binary export2591 //-- binary export functions 2592 2592 2593 2593 void ViewCellsTree::ExportBinInterior(OUT_STREAM &stream, ViewCellInterior *interior) 2594 2594 { 2595 int interiorid= TYPE_INTERIOR;2596 stream.write(reinterpret_cast<char *>(& interiorid), sizeof(int));2595 int type = TYPE_INTERIOR; 2596 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 2597 2597 } 2598 2598 … … 2602 2602 int type = TYPE_LEAF; 2603 2603 2604 int id = leaf->GetId();2605 2606 2604 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 2607 stream.write(reinterpret_cast<char *>(&id), sizeof(int));2608 2605 2609 2606 int pvsSize = leaf->GetPvs().GetSize(); … … 2615 2612 while (pit.HasMoreEntries()) 2616 2613 { 2617 Intersectable *intersect = pit.Next(); 2618 id = intersect->GetId(); 2619 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 2614 Intersectable *obj = pit.Next(); 2615 2616 int objId = obj->GetId(); 2617 stream.write(reinterpret_cast<char *>(&objId), sizeof(int)); 2620 2618 } 2621 2619 } … … 2624 2622 bool ViewCellsTree::ExportBinary(OUT_STREAM &stream) 2625 2623 { 2626 2627 2624 // export binary version of mesh 2628 2625 queue<ViewCell *> tStack; … … 2660 2657 2661 2658 ////////////////// 2662 //-- import binary2659 //-- binary import methods 2663 2660 2664 2661 ViewCellInterior *ViewCellsTree::ImportBinInterior(IN_STREAM &stream, ViewCellInterior *parent) … … 2675 2672 int leafId = TYPE_LEAF; 2676 2673 int objId = leafId; 2677 int size;2678 2679 stream.read(reinterpret_cast<char *>(& size), sizeof(int));2674 int pvsSize; 2675 2676 stream.read(reinterpret_cast<char *>(&pvsSize), sizeof(int)); 2680 2677 VspViewCell *leaf = new VspViewCell(); 2681 2678 2679 //cerr << "\npvs size: " << pvsSize << endl; 2680 2682 2681 MeshInstance dummyInst(NULL); 2683 2682 2684 2683 // read object ids 2685 for (int i = 0; i < size; ++ i)2684 for (int i = 0; i < pvsSize; ++ i) 2686 2685 { 2687 2686 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 2687 2688 // load the object 2688 2689 dummyInst.SetId(objId); 2689 2690 … … 2692 2693 2693 2694 if ((oit != pvsObjects.end()) && ((*oit)->GetId() == objId)) 2695 { 2696 //cerr << "o"; 2694 2697 leaf->GetPvs().AddSample(*oit, 0); 2698 } 2695 2699 else 2696 Debug << "error: object with id " << objId << " does not exist" << endl; 2700 { 2701 cerr << "x " << objId << " ";//error: object with id " << objId << " does not exist" << endl; 2702 } 2697 2703 } 2698 2704 … … 2709 2715 2710 2716 if (nodeType == TYPE_LEAF) 2717 { 2718 //cerr << "l"; 2711 2719 return ImportBinLeaf(stream, static_cast<ViewCellInterior *>(parent), objects); 2720 } 2712 2721 2713 2722 if (nodeType == TYPE_INTERIOR) 2723 { 2724 //cerr << "i"; 2714 2725 return ImportBinInterior(stream, static_cast<ViewCellInterior *>(parent)); 2715 2716 Debug << "error! loading failed!" << endl; 2726 } 2727 2728 cerr << "error! loading view cell failed!" << endl; 2717 2729 return NULL; 2718 2730 } … … 2721 2733 bool ViewCellsTree::ImportBinary(IN_STREAM &stream, const ObjectContainer &pvsObjects) 2722 2734 { 2723 // export binary version of mesh2735 // export view cells in binary mode 2724 2736 queue<ViewCell *> tStack; 2725 2737 2726 2738 // hack: we make a new root 2727 2739 DEL_PTR(mRoot); 2728 2740 // import root 2729 2741 mRoot = ImportNextNode(stream, NULL, pvsObjects); 2730 2742 2743 cerr << "root: " << mRoot << endl; 2731 2744 tStack.push(mRoot); 2732 2745 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2542 r2543 528 528 SimpleRay &ray) 529 529 { 530 // do not use this function since it could return different viewpoints for 531 // different executions of the algorithm 530 // do not use this function since it could return different 531 // viewpoints for different executions of the algorithm 532 532 533 int tries = 0; 533 534 Vector3 viewPoint, direction; … … 542 543 Mesh *mesh = viewCell->GetMesh(); 543 544 AxisAlignedBox3 box = mesh->mBox; 544 //cout <<"box: " << box << endl; 545 /*Vector3 pVector = Vector3(halton.GetNumber(1), 546 halton.GetNumber(2), 547 halton.GetNumber(3));*/ 548 545 549 546 Vector3 pVector = Vector3(Random(1.0f), 550 547 Random(1.0f), … … 553 550 viewPoint = box.GetPoint(pVector); 554 551 555 //const Vector3 dVector = Vector3(2 * M_PI * halton.GetNumber(4), M_PI*halton.GetNumber(5),0.0f);556 552 const Vector3 dVector = Vector3(2 * M_PI * Random(1.0f), M_PI * Random(1.0f), 0.0f); 557 553 direction = Normalize(Vector3(sin(dVector.x), 0.0f, cos(dVector.x))); 558 //halton.GenerateNext();559 554 560 555 ViewCell *v = GetViewCell(viewPoint); … … 564 559 mPreprocessor->GetRenderer()->mViewPoint = viewPoint; 565 560 mPreprocessor->GetRenderer()->mViewDirection = direction; 566 //mPreprocessor->GetRenderer()->EvalPvsStat(); 567 561 568 562 if (mPreprocessor->GetRenderer()->ValidViewPoint()) 569 563 { … … 574 568 } 575 569 576 // generate a new vector577 //halton.GenerateNext();578 579 //if (!box.IsInside(viewPoint))580 // cout << "error!" << endl;581 570 if (++ tries > maxTries) 582 571 { … … 672 661 673 662 DEL_PTR(mMixtureDistribution); 674 675 663 CLEAR_CONTAINER(mViewCellPoints); 676 664 } … … 829 817 830 818 // mix of sampling strategies 819 #if 0 831 820 vector<int>dummy; 832 //dummy.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);833 //dummy.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);834 //dummy.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);835 821 dummy.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 822 dummy.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 823 dummy.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 824 #endif 836 825 CastPassSamples(mInitialSamples, mStrategies, initialSamples); 837 826 … … 1032 1021 if (!Debug.is_open()) Debug.open("debug.log"); 1033 1022 1023 Debug << "here23" << endl; 1034 1024 // give just an empty container as parameter: 1035 1025 // this loading function is used in the engine, thus it … … 1045 1035 1046 1036 1047 void ViewCellsManager::LoadIndexedBoundingBoxes(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes) 1048 { 1049 Vector3 bmin; 1050 Vector3 bmax; 1051 int id; 1052 1053 stream.read(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 1054 stream.read(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 1055 stream.read(reinterpret_cast<char *>(&id), sizeof(int)); 1056 1057 AxisAlignedBox3 box(bmin, bmax); 1058 1059 iboxes.push_back(IndexedBoundingBox(id, box)); 1060 //Debug << "bbox: " << box << endl; 1061 } 1062 1063 1064 ViewCellsManager *ViewCellsManager::LoadViewCellsBin(const string &filename, 1065 ObjectContainer &pvsObjects, 1066 ObjectContainer &preprocessorObjects, 1067 bool finalizeViewCells, 1068 BoundingBoxConverter *bconverter) 1069 { 1070 IN_STREAM stream(filename.c_str()); 1071 1072 IndexedBoundingBoxContainer iboxes; 1073 LoadIndexedBoundingBoxes(stream, iboxes); 1074 1075 if (bconverter) 1076 { 1077 // all bounding boxes gathered in this step => 1078 // associate object ids with bounding boxes 1079 bconverter->IdentifyObjects(iboxes, pvsObjects); 1080 } 1081 1082 // sort objects by id 1083 sort(pvsObjects.begin(), pvsObjects.end(), ilt); 1084 1085 ViewCellsTree *vcTree = new ViewCellsTree(); 1086 VspTree *vspTree = new VspTree(); 1087 1088 HierarchyManager *hm = new HierarchyManager(0); 1089 1090 vspTree->ImportBinary(stream, pvsObjects); 1091 1092 VspOspViewCellsManager *vcm = new VspOspViewCellsManager(vcTree, hm); 1093 1094 return vcm; 1037 void ViewCellsManager::LoadIndexedBoundingBoxesBinary(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes) 1038 { 1039 int numBoxes; 1040 stream.read(reinterpret_cast<char *>(&numBoxes), sizeof(int)); 1041 1042 for (int i = 0; i < numBoxes; ++ i) 1043 { 1044 Vector3 bmin; 1045 Vector3 bmax; 1046 int id; 1047 1048 stream.read(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 1049 stream.read(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 1050 stream.read(reinterpret_cast<char *>(&id), sizeof(int)); 1051 1052 AxisAlignedBox3 box(bmin, bmax); 1053 iboxes.push_back(IndexedBoundingBox(id, box)); 1054 } 1095 1055 } 1096 1056 … … 1100 1060 ObjectContainer &preprocessorObjects, 1101 1061 bool finalizeViewCells, 1102 BoundingBoxConverter *bconverter) 1103 1062 BoundingBoxConverter *bconverter) 1104 1063 { 1105 1064 ViewCellsParser parser; … … 1145 1104 if (finalizeViewCells) 1146 1105 { 1106 // do some final computations, e.g., 1147 1107 // create the meshes and compute view cell volumes 1148 1108 const bool createMeshes = true; … … 1250 1210 } 1251 1211 1212 1252 1213 void ViewCellsManager::EvalViewCellHistogram(const string filename, 1253 1214 const int nViewCells) … … 1257 1218 1258 1219 ViewCellContainer viewCells; 1259 // $$ JB hack - the collect best viewcells does not work?1260 #if 1 1220 1221 // the collect best viewcells does not work? 1261 1222 mViewCellsTree->CollectBestViewCellSet(viewCells, nViewCells); 1262 #else1263 viewCells = mViewCells;1264 #endif1265 1223 1266 1224 float maxRenderCost, minRenderCost; … … 3192 3150 if (boxesIn.eof()) 3193 3151 break; 3194 3195 3152 3196 3153 AxisAlignedBox3 box(bmin, bmax); 3197 3154 MeshInstance *mi = new MeshInstance(NULL); 3198 3155 3199 // HACK: set bounding box to new box3200 //mi->mBox = box;3201 //boxes.push_back(mi);3202 3156 boxes.push_back(IndexedBoundingBox(id, box)); 3203 3157 } … … 3256 3210 return; 3257 3211 3258 if (viewSpaceFilterSize >= 0.0f) {3259 3212 if (viewSpaceFilterSize >= 0.0f) 3213 { 3260 3214 const bool usePrVS = false; 3261 3215 3262 if (!usePrVS) { 3216 if (!usePrVS) 3217 { 3263 3218 AxisAlignedBox3 box = GetViewCellBox(viewCell); 3264 3219 box.Enlarge(Vector3(viewSpaceFilterSize/2)); … … 3278 3233 pvs = interPvs; 3279 3234 } 3280 } else 3235 } 3236 else 3281 3237 { 3282 3238 PrVs prvs; … … 3349 3305 ) 3350 3306 { 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3307 // now compute a new Pvs by including also objects intersecting the 3308 // extended boxes of visible objects 3309 Intersectable::NewMail(); 3310 3311 ObjectPvsIterator pit = pvs.GetIterator(); 3312 3313 while (pit.HasMoreEntries()) 3314 pit.Next()->Mail(); 3315 3316 ObjectPvs nPvs; 3317 int nPvsSize = 0; 3318 3319 ObjectPvsIterator pit2 = pvs.GetIterator(); 3320 3321 while (pit2.HasMoreEntries()) 3322 { 3323 // now go through the pvs again 3324 Intersectable *object = pit2.Next(); 3325 3326 // Vector3 center = object->GetBox().Center(); 3327 // AxisAlignedBox3 box(center - Vector3(spatialFilterSize/2), 3328 // center + Vector3(spatialFilterSize/2)); 3329 3330 AxisAlignedBox3 box = object->GetBox(); 3331 box.Enlarge(Vector3(spatialFilterSize/2)); 3332 3333 ObjectContainer objects; 3334 3335 // $$ warning collect objects takes only unmailed ones! 3336 kdTree->CollectObjects(box, objects); 3337 // cout<<"collected objects="<<objects.size()<<endl; 3338 ObjectContainer::const_iterator noi = objects.begin(); 3339 for (; noi != objects.end(); ++ noi) 3340 { 3341 Intersectable *o = *noi; 3342 cout<<"w"; 3343 // $$ JB warning: pdfs are not correct at this point! 3344 nPvs.AddSample(o, Limits::Small); 3345 nPvsSize ++; 3346 } 3347 } 3348 3349 // cout<<"nPvs size = "<<nPvsSize<<endl; 3350 pvs.MergeInPlace(nPvs); 3395 3351 } 3396 3352 … … 3433 3389 ) 3434 3390 { 3391 pvs.Reserve(viewCell->GetFilteredPvsSize()); 3392 3435 3393 PvsFilterStatistics stats; 3436 3394 3437 3395 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 3438 Vector3 center = vbox.Center(); 3396 const Vector3 center = vbox.Center(); 3397 3439 3398 // copy the PVS 3440 Intersectable::NewMail(); 3399 if (!mUseKdPvs) 3400 Intersectable::NewMail(); 3401 else 3402 KdNode::NewMail(); 3403 3441 3404 ObjectPvs basePvs = viewCell->GetPvs(); 3442 3405 ObjectPvsIterator pit = basePvs.GetIterator(); 3443 3406 3444 pvs.Reserve(viewCell->GetFilteredPvsSize());3445 3446 3407 if (!mUseKdPvs) 3447 { 3448 // first mark all objects from this pvs 3408 { // first mark all objects from this pvs 3449 3409 while (pit.HasMoreEntries()) 3450 3410 pit.Next()->Mail(); … … 3453 3413 int pvsSize = 0; 3454 3414 int nPvsSize = 0; 3455 float samples = (float)basePvs.GetSamples(); 3456 3457 Debug<<"f #s="<<samples<<" pvs size = "<<basePvs.GetSize(); 3415 3416 //Debug<<"f #s="<<samples<<" pvs size = "<<basePvs.GetSize(); 3458 3417 // cout<<"Filter size = "<<filterSize<<endl; 3459 3418 // cout<<"vbox = "<<vbox<<endl; … … 3468 3427 // and gobal estimate for the view cell 3469 3428 // (total #rays intersecting the viewcell) 3470 int minLocalSamples = 2; 3471 3472 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 3473 3474 // now compute the filter box around the current viewCell 3429 const int minLocalSamples = 2; 3430 const float viewCellRadius = 0.5f * Magnitude(vbox.Diagonal()); 3431 3432 float samples = (float)basePvs.GetSamples(); 3433 3434 ////////// 3435 //-- now compute the filter box around the current viewCell 3475 3436 3476 3437 if (useViewSpaceFilter) 3477 3438 { 3478 // 3479 float radius = viewCellRadius /100.0f;3439 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 3440 float radius = viewCellRadius / 100.0f; 3480 3441 vbox.Enlarge(radius); 3481 3442 cout<<"vbox = "<<vbox<<endl; 3443 3482 3444 ViewCellContainer viewCells; 3483 3445 ComputeBoxIntersections(vbox, viewCells); … … 3487 3449 for (int i = 0; it != it_end; ++ it, ++ i) 3488 3450 { 3489 3490 3451 if ((*it) != viewCell) 3491 3452 { … … 3592 3553 } 3593 3554 } 3555 3594 3556 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 3595 3557 } … … 3613 3575 viewCell->SetFilteredPvsSize(pvs.GetSize()); 3614 3576 3615 Intersectable::NewMail(); 3577 //cout << "pvssize: " << pvs.GetSize() << endl; 3578 // warning: not thread-safe! 3579 if (!mUseKdPvs) 3580 Intersectable::NewMail(); 3581 3616 3582 return stats; 3617 3583 } … … 3735 3701 Intersectable::NewMail(); 3736 3702 3703 3737 3704 /////////// 3738 3705 //-- merge pvss 3739 3706 3707 PvsData pvsData; 3708 3740 3709 vector<ObjectPvs>::iterator oit = pvsList.begin(); 3741 3742 PvsData pvsData;3743 3710 3744 3711 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit) … … 4786 4753 exporter->SetWireframe(); 4787 4754 4788 // matt: we do n't have nokd pvs4755 // matt: we do not use kd pvs 4789 4756 #if 0 4790 4757 KdPvsMap::iterator kit = object->mKdPvs.mEntries.begin(); … … 5919 5886 { 5920 5887 Environment::GetSingleton()->GetIntValue("Hierarchy.Construction.samples", mInitialSamples); 5921 5922 5888 Environment::GetSingleton()->GetBoolValue("ViewCells.compressObjects", mCompressObjects); 5923 5889 … … 5926 5892 5927 5893 mHierarchyManager = CreateHierarchyManager(hierarchyType); 5894 5928 5895 mHierarchyManager->SetViewCellsManager(this); 5929 5896 mHierarchyManager->SetViewCellsTree(mViewCellsTree); … … 6247 6214 ) const 6248 6215 { 6216 Plane3 plane; 6217 if (clipPlane) 6218 { 6219 // arbitrary plane definition 6220 plane = clipPlane->GetPlane(); 6221 } 6222 6249 6223 ViewCellContainer leaves; 6250 6224 mViewCellsTree->CollectLeaves(vc, leaves); 6225 6251 6226 ViewCellContainer::const_iterator it, it_end = leaves.end(); 6252 6253 Plane3 plane;6254 if (clipPlane)6255 {6256 // arbitrary plane definition6257 plane = clipPlane->GetPlane();6258 }6259 6227 6260 6228 for (it = leaves.begin(); it != it_end; ++ it) … … 6522 6490 { 6523 6491 Material m; 6524 6525 6492 Intersectable::NewMail(); 6526 6493 … … 6636 6603 return false; 6637 6604 6638 cout << "exporting binary" << endl; 6639 string fname("test.vc"); 6640 return ExportBinaryViewCells(fname, exportPvs, objects); 6605 /*if (strstr(filename.c_str(), ".bn")) 6606 { 6607 cout << "exporting view cells to binary format" << endl; 6608 return ExportViewCellsBinary(filename, exportPvs, objects); 6609 }*/ 6610 6611 cout << "exporting binary" << endl; string fname("test.vc"); return ExportViewCellsBinary(fname, exportPvs, objects); 6641 6612 6642 6613 const long starttime = GetTime(); … … 6662 6633 6663 6634 int id = 0; 6664 6665 6635 vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 6666 6636 … … 6697 6667 6698 6668 6699 ///////////////// /////6669 ///////////////// 6700 6670 //-- export the view space hierarchy 6701 6671 … … 6707 6677 stream << "</ViewSpaceHierarchy>" << endl; 6708 6678 6709 ///////////////// /////6710 //-- export the object space partition6679 ///////////////// 6680 //-- export the object space hierarchy 6711 6681 6712 6682 mHierarchyManager->ExportObjectSpaceHierarchy(stream); … … 6720 6690 6721 6691 6722 bool VspOspViewCellsManager::Export BinaryViewCells(const string filename,6692 bool VspOspViewCellsManager::ExportViewCellsBinary(const string filename, 6723 6693 const bool exportPvs, 6724 6694 const ObjectContainer &objects) … … 6736 6706 CreateUniqueViewCellIds(); 6737 6707 6738 int numBo undingBoxes = mPreprocessor->mKdTree->mKdIntersectables.size();6739 stream.write(reinterpret_cast<char *>(&numBo undingBoxes), sizeof(int));6708 int numBoxes = mPreprocessor->mKdTree->mKdIntersectables.size(); 6709 stream.write(reinterpret_cast<char *>(&numBoxes), sizeof(int)); 6740 6710 6741 6711 … … 6751 6721 { 6752 6722 Intersectable *obj = (*kit); 6723 // set the kd node id to identify the kd node as a pvs entry 6724 obj->SetId(id); 6725 6753 6726 const AxisAlignedBox3 &box = obj->GetBox(); 6754 6755 // setting the kd node id important to identify the kd node as pvs entry6756 obj->SetId(id);6757 6758 6727 Vector3 bmin = box.Min(); 6759 6728 Vector3 bmax = box.Max(); … … 6764 6733 } 6765 6734 6735 cout << "written " << numBoxes << " kd nodes" << endl; 6766 6736 6767 6737 /////////////// 6768 6738 //-- export the view cells and the pvs 6769 6739 6770 int numViewCells = m CurrentViewCellsStats.viewCells;6740 int numViewCells = mViewCells.size(); 6771 6741 stream.write(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 6772 6742 … … 6777 6747 stream.write(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 6778 6748 6779 // todo 6749 6750 ////////// 6751 //-- export binary view cells 6752 6780 6753 mViewCellsTree->ExportBinary(stream); 6781 6754 6782 6755 6783 ///////// /////////////6756 ///////// 6784 6757 //-- export the view space hierarchy 6785 6758 6786 6759 mHierarchyManager->GetVspTree()->ExportBinary(stream); 6787 6760 6761 6762 //////// 6763 //-- export the object space hierarchy 6764 6765 //mHierarchyManager->ExportObjectSpaceHierarchyBinary(); 6766 6788 6767 stream.close(); 6789 6768 6769 mHierarchyManager->GetVspTree()->TestOutput("output.txt"); 6770 6790 6771 cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3 << " secs" << endl; 6791 6772 return true; … … 6888 6869 if (!(ViewCellsTreeConstructed() && mCompressViewCells)) 6889 6870 return; 6871 6890 6872 6891 6873 //////////// … … 7042 7024 cout << "computing histogram for " << pass << " view cells" << endl; 7043 7025 7044 /////////////////// //////////7026 /////////////////// 7045 7027 //-- evaluate histogram for pvs size 7046 7028 … … 7060 7042 7061 7043 if (mHierarchyManager->mUseTraversalTree) 7062 { 7063 // create a traversal tree for optimal view cell casting 7044 { // create a traversal tree for optimal view cell casting 7064 7045 mHierarchyManager->CreateTraversalTree(); 7065 7046 } … … 7097 7078 { 7098 7079 ComputeSampleContribution(*tmpRays[i], addContributions, true, useHitObjects); 7099 7100 //////////7101 7080 // compare results 7102 cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " << (int)packet.mViewCells[i].size() << endl; 7081 cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " 7082 << (int)packet.mViewCells[i].size() << endl; 7103 7083 } 7104 7084 … … 7127 7107 BoundingBoxConverter *bconverter) 7128 7108 { 7129 ViewCellsParser parser; 7130 ViewCellsManager *vm = NULL; 7109 if (!Debug.is_open()) Debug.open("debug.log"); 7110 7111 IN_STREAM stream(filename.c_str()); 7112 7113 if (!stream.is_open()) 7114 { 7115 Debug << "View cells loading failed: could not open file" << endl; 7116 return NULL; 7117 } 7118 7119 Debug << "loading boxes" << endl; 7131 7120 7132 7121 const long startTime = GetTime(); 7133 const bool success = false; 7134 7135 if (!success) 7136 { 7137 Debug << "Error: loading view cells failed!" << endl; 7138 DEL_PTR(vm); 7139 7122 7123 IndexedBoundingBoxContainer iboxes; 7124 ViewCellsManager::LoadIndexedBoundingBoxesBinary(stream, iboxes); 7125 7126 Debug << (int)iboxes.size() << " boxes loaded" << endl; 7127 7128 /*IndexedBoundingBoxContainer::const_iterator bit, bit_end = iboxes.end(); 7129 for (bit = iboxes.begin(); bit != bit_end; ++ bit) 7130 { 7131 IndexedBoundingBox ibox = *bit; 7132 cerr << "box: " << ibox.first << " " << ibox.second << endl; 7133 }*/ 7134 7135 7136 if (bconverter) 7137 { 7138 // all bounding boxes gathered in this step => 7139 // associate object ids with bounding boxes 7140 bconverter->IdentifyObjects(iboxes, pvsObjects); 7141 } 7142 7143 // sort objects by id 7144 sort(pvsObjects.begin(), pvsObjects.end(), ilt); 7145 7146 7147 ///////////// 7148 //-- load the view cells 7149 7150 int numViewCells; 7151 stream.read(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 7152 7153 Debug << "loading " << numViewCells << " view cells " << endl; 7154 7155 Vector3 vmin, vmax; 7156 7157 stream.read(reinterpret_cast<char *>(&vmin), sizeof(Vector3)); 7158 stream.read(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 7159 7160 AxisAlignedBox3 viewSpaceBox(vmin, vmax); 7161 7162 Debug << "view space box: " << viewSpaceBox << endl; 7163 7164 ViewCellsTree *vcTree = new ViewCellsTree(); 7165 7166 if (!vcTree->ImportBinary(stream, pvsObjects)) 7167 { 7168 Debug << "Error: loading view cells tree failed!" << endl; 7169 delete vcTree; 7170 7140 7171 return NULL; 7141 7172 } 7142 7143 ViewCellContainer leaves; 7173 7174 Debug << "loading the view space partition tree" << endl; 7175 VspTree *vspTree = new VspTree(); 7176 7177 vspTree->mBoundingBox = viewSpaceBox; 7178 7179 if (!vspTree->ImportBinary(stream, pvsObjects)) 7180 { 7181 Debug << "Error: loading vsp tree failed!" << endl; 7182 delete vcTree; delete vspTree; 7183 7184 return NULL; 7185 } 7186 7187 7188 HierarchyManager * hm = 7189 new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV); 7190 7191 hm->SetVspTree(vspTree); 7192 7193 7194 ///////// 7195 //-- create view cells manager 7196 7197 VspOspViewCellsManager *vm = new VspOspViewCellsManager(vcTree, hm); 7198 7199 7200 7201 ////////////// 7202 //-- do some more preparation 7144 7203 7145 7204 vm->mViewCells.clear(); 7146 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 7147 7148 ViewCellContainer::const_iterator it, it_end = leaves.end(); 7149 7150 for (it = leaves.begin(); it != it_end; ++ it) 7151 { 7152 vm->mViewCells.push_back(*it); 7153 } 7205 7206 ViewCellContainer viewCells; 7207 vcTree->CollectLeaves(vcTree->GetRoot(), viewCells); 7208 7209 ViewCellContainer::const_iterator cit, cit_end = viewCells.end(); 7210 7211 for (cit = viewCells.begin(); cit != cit_end; ++ cit) 7212 { 7213 vm->mViewCells.push_back(*cit); 7214 } 7215 7216 7217 ////////////// 7218 //-- associate view cells with vsp leaves 7219 7220 vector<VspLeaf *> vspLeaves; 7221 vspTree->CollectLeaves(vspLeaves); 7222 7223 vector<VspLeaf *>::const_iterator vit, vit_end = vspLeaves.end(); 7224 cit = viewCells.begin(); 7225 7226 for (vit = vspLeaves.begin(); vit != vit_end; ++ vit, ++ cit) 7227 { 7228 VspLeaf *leaf = *vit; 7229 VspViewCell *vc = static_cast<VspViewCell *>(*cit); 7230 7231 leaf->SetViewCell(vc); 7232 vc->mLeaves.push_back(leaf); 7233 } 7234 7154 7235 7155 7236 vm->mViewCellsFinished = true; … … 7163 7244 } 7164 7245 7165 cout << (int)vm->mViewCells.size() << " view cells loaded in "7166 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl;7167 7168 7246 Debug << (int)vm->mViewCells.size() << " view cells loaded in " 7169 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 7170 7247 << TimeDiff(startTime, GetTime()) * 1e-6f << " secs" << endl; 7248 7249 vspTree->TestOutput("input.txt"); 7250 7171 7251 return vm; 7172 7252 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r2542 r2543 527 527 BoundingBoxConverter *bconverter = NULL); 528 528 529 ViewCellsManager *LoadViewCellsBin(const string &filename,530 ObjectContainer &pvsObjects,531 ObjectContainer &preprocessorObjects,532 bool finalizeViewCells,533 BoundingBoxConverter *bconverter);534 535 529 536 530 /////////////////////// … … 670 664 */ 671 665 void EvaluateViewCellsStats(); 672 /** This helper function loads the bounding boxes for a binary solution. 673 */ 674 void LoadIndexedBoundingBoxes(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes); 675 666 676 667 677 668 /////////////////////// … … 721 712 */ 722 713 void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs); 723 714 /** Export statistics of the view cells tree. 715 */ 724 716 virtual void ExportStats(const string &mergeStats); 725 717 … … 728 720 bool finalizeViewCells, 729 721 BoundingBoxConverter *bconverter); 730 731 732 //////////////////////////////////////////////// 733 722 /** This helper function loads the bounding boxes for a binary solution. 723 */ 724 static void LoadIndexedBoundingBoxesBinary(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes); 725 726 727 728 /////////// 729 //-- members 734 730 735 731 ofstream mStats; … … 1217 1213 virtual void FinalizeViewCells(const bool createMesh); 1218 1214 1219 bool Export BinaryViewCells(const string filename,1215 bool ExportViewCellsBinary(const string filename, 1220 1216 const bool exportPvs, 1221 1217 const ObjectContainer &objects); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r2542 r2543 672 672 { 673 673 Debug << "\nobject space hierarchy: Bvh" << endl; 674 674 675 mObjectSpaceHierarchyType = BVH; 675 676 mHierarchyManager = … … 990 991 // exchange view cell with new one 991 992 DEL_PTR(vc); 992 993 993 //(*vit).second = vspVc; 994 994 (*vit) = vspVc; … … 997 997 if (mHierarchyManager) 998 998 { 999 // come here only if object space hierarchyalready constructed999 // do this only if object hierarchy was already constructed 1000 1000 mHierarchyManager->mVspTree = mVspTree; 1001 1001 mVspTree->mHierarchyManager = mHierarchyManager; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r2542 r2543 3854 3854 void VspTree::ExportBinInterior(OUT_STREAM &stream, VspInterior *interior) 3855 3855 { 3856 int interiorid= TYPE_INTERIOR;3857 stream.write(reinterpret_cast<char *>(& interiorid), sizeof(int));3856 int type = TYPE_INTERIOR; 3857 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 3858 3858 3859 3859 int axis = interior->GetAxis(); … … 3867 3867 void VspTree::ExportBinLeaf(OUT_STREAM &stream, VspLeaf *leaf) 3868 3868 { 3869 ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());3870 3871 3869 int type = TYPE_LEAF; 3872 3873 int id = -1;3874 if (viewCell != mOutOfBoundsCell)3875 id = viewCell->GetId();3876 3877 3870 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 3878 stream.write(reinterpret_cast<char *>(&id), sizeof(int));3879 3880 int pvsSize = viewCell->GetPvs().GetSize();3881 stream.write(reinterpret_cast<char *>(&pvsSize), sizeof(int));3882 3883 ObjectPvsIterator pit = viewCell->GetPvs().GetIterator();3884 3885 // write PVS of view cell3886 while (pit.HasMoreEntries())3887 {3888 Intersectable *intersect = pit.Next();3889 id = intersect->GetId();3890 stream.write(reinterpret_cast<char *>(&id), sizeof(int));3891 }3892 3871 } 3893 3872 … … 3943 3922 const ObjectContainer &pvsObjects) 3944 3923 { 3945 #if TODO3946 3924 int leafId = TYPE_LEAF; 3947 3925 int objId = leafId; 3948 int size; 3949 3950 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 3951 KdLeaf *leaf = new KdLeaf(parent, size); 3952 3953 MeshInstance dummyInst(NULL); 3954 3955 // read object ids 3956 // note: could also do this geometrically 3957 for (int i = 0; i < size; ++ i) 3958 { 3959 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 3960 dummyInst.SetId(objId); 3961 3962 ObjectContainer::const_iterator oit = 3963 lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 3964 3965 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 3966 leaf->mObjects.push_back(*oit); 3967 else 3968 Debug << "error: object with id " << objId << " does not exist" << endl; 3969 } 3926 3927 VspLeaf *leaf = new VspLeaf(parent); 3928 3929 // pvs is loaded by view cell 3970 3930 return leaf; 3971 #endif3972 return NULL;3973 3931 } 3974 3932 … … 3982 3940 3983 3941 if (nodeType == TYPE_LEAF) 3942 { 3943 //cerr << "l"; 3984 3944 return ImportBinLeaf(stream, static_cast<VspInterior *>(parent), objects); 3945 } 3985 3946 3986 3947 if (nodeType == TYPE_INTERIOR) 3948 { 3949 //cerr << "i"; 3987 3950 return ImportBinInterior(stream, static_cast<VspInterior *>(parent)); 3988 3989 Debug << "error! loading failed!" << endl; 3951 } 3952 3953 cerr << "error! loading vsp node failed!" << endl; 3990 3954 return NULL; 3991 3955 } … … 4024 3988 // hack: we make a new root 4025 3989 DEL_PTR(mRoot); 4026 4027 3990 mRoot = ImportNextNode(stream, NULL, pvsObjects); 4028 3991 … … 4042 4005 mVspStats.nodes += 2; 4043 4006 4044 //Debug << "i" ;4045 4007 VspInterior *interior = static_cast<VspInterior *>(node); 4046 4008 interior->SetBoundingBox(tData.mBox); … … 4070 4032 } 4071 4033 } 4034 4072 4035 return true; 4073 4036 } 4074 4037 4075 4038 4076 } 4039 void VspTree::TestOutput(const std::string &filename) 4040 { 4041 ofstream str(filename.c_str()); 4042 4043 vector<VspLeaf *> vspLeaves; 4044 CollectLeaves(vspLeaves); 4045 4046 vector<VspLeaf *>::const_iterator vit, vit_end = vspLeaves.end(); 4047 4048 for (vit = vspLeaves.begin(); vit != vit_end; ++ vit) 4049 { 4050 VspLeaf *leaf = *vit; 4051 ViewCell *vc = leaf->GetViewCell(); 4052 4053 str << "\nleaf: " << GetBoundingBox(leaf) << endl; 4054 4055 ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 4056 4057 while (pit.HasMoreEntries()) 4058 { 4059 Intersectable *obj = pit.Next(); 4060 str << obj->GetId() << " "; 4061 } 4062 } 4063 } 4064 4065 4066 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r2539 r2543 43 43 class VspTree; 44 44 class KdTreeStatistics; 45 45 class BoundingBoxConverter; 46 46 47 47 … … 663 663 bool ImportBinary(IN_STREAM &stream, ObjectContainer &pvsObjects); 664 664 665 void TestOutput(const std::string &filename); 665 666 666 667 //////////// … … 1013 1014 int TraverseRayPacket(RayPacket &rp, const bool useMailboxing); 1014 1015 1016 1015 1017 #ifdef USE_SSE 1016 1018 struct PacketTraversalData … … 1084 1086 #endif 1085 1087 1088 1089 friend ViewCellsManager *LoadViewCellsBinary(const std::string &filename, 1090 ObjectContainer &pvsObjects, 1091 bool finalizeViewCells, 1092 BoundingBoxConverter *bconverter); 1086 1093 1087 1094 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r2538 r2543 171 171 Debug.open("debug.log"); 172 172 173 #if 0174 cout<<"Allocating 1.5GB..."<<endl;175 176 177 for (int i=0; i < 1000; i++) {178 void *p = malloc(1250000000);179 if (p != NULL) {180 cout<<"success"<<(i+1)*1000<<"MB"<<endl;181 }182 else {183 cout<<"fail"<<endl;184 exit(1);185 }186 }187 #endif188 189 173 Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH); 190 174 MeshKdTree::ParseEnvironment(); … … 264 248 265 249 if (success) 266 {267 250 cout << "finished exporting obj" << endl; 268 }269 251 else 270 {271 252 cerr << "error exporting " << objname << endl; 272 }273 253 } 274 254 } … … 348 328 #ifdef USE_QT 349 329 350 if ( importRandomViewCells || frames)351 330 if (0 && preprocessor->mUseGlRenderer && (importRandomViewCells || frames)) 331 { 352 332 QGLFormat f; 353 333 f.setStencil(true); … … 358 338 // $$matt 359 339 preprocessor->renderer = 360 361 362 preprocessor->mViewCellsManager,363 preprocessor->mKdTree);364 340 new QtGlRendererBuffer(1024, 1024, 341 preprocessor->mSceneGraph, 342 preprocessor->mViewCellsManager, 343 preprocessor->mKdTree); 344 } 365 345 #endif 366 346 … … 390 370 rendererWidget = 391 371 new QtGlRendererWidget(preprocessor->mSceneGraph, 392 preprocessor->mViewCellsManager,393 preprocessor->mKdTree);372 preprocessor->mViewCellsManager, 373 preprocessor->mKdTree); 394 374 395 375 rendererWidget->Show(); … … 450 430 // release memory 451 431 Cleanup(); 452 453 432 delete pt; 454 433
Note: See TracChangeset
for help on using the changeset viewer.