Changeset 1486 for GTP/trunk/Lib
- Timestamp:
- 09/25/06 18:54:21 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 2 added
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
r938 r1486 75 75 { 76 76 ResetQueries(); 77 78 77 OGRE_DELETE(mSolidBoundingBox); 79 78 } … … 100 99 mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY); 101 100 mSceneManager->useRenderableViewProjModeWrapper(solidBox); 102 101 // HACK! (mySetPass should be setPass) 103 102 // set no depth write, no color, no lighting material 104 mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)105 //mSceneManager->_setPass(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)103 mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); 104 //mSceneManager->_setPass(solidBox->getTechnique()->getPass(0)); 106 105 //SetOcclusionPass(); 107 106 … … 130 129 mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem)); 131 130 } 131 132 std::stringstream d; 133 d << "resizing queries: " << (int)mOcclusionQueries.size() << endl; 134 LogManager::getSingleton().logMessage(d.str()); 132 135 133 136 return mOcclusionQueries[mCurrentTestIdx ++]; … … 186 189 if (mTestGeometryForVisibleLeaves && (mCamera == mCullCamera) && wasVisible && IsLeaf(node)) 187 190 { 188 //LogManager::getSingleton().logMessage("render node\n");189 191 RenderNode(node); 190 192 } … … 194 196 // must be treated differently to the scene geometry during rendering 195 197 mIsBoundingBoxQuery = true; 196 197 //LogManager::getSingleton().logMessage("render box\n");198 198 RenderBoundingBox(GetBoundingBox(node)); 199 199 … … 227 227 // get next available test id 228 228 GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery(); 229 229 230 //////// 230 231 //-- the actual query test 232 231 233 query->BeginQuery(); 232 233 234 RenderGeometry(mesh); 234 235 235 query->EndQuery(); 236 236 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp
r1175 r1486 16 16 { 17 17 // delete old queries (not needed for e.g., view frustum culling) 18 // note cannot be deleted because of new ogre occlusion query implementation 19 // there we cannot just delete the queries, so they would stay! 18 20 //mHierarchyInterface->ResetQueries(); 19 21 mVisibilityManager->SetCullingManager(*static_cast<const -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
r955 r1486 83 83 if (!mHierarchyInterface->CheckFrustumVisible(node, intersects)) 84 84 { 85 ++ mNumFrustumCulledNodes; 86 85 ++ mNumFrustumCulledNodes; 87 86 if (mVisualizeCulledNodes) 88 87 { … … 90 89 } 91 90 } 92 // 91 //-- if node intersects near plane, skip query because wrong results possible 93 92 else if (intersects) 94 93 { -
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r1415 r1486 2165 2165 2166 2166 2167 } 2167 void AxisAlignedBox3::Initialize() { 2168 mMin = Vector3(MAXFLOAT); 2169 mMax = Vector3(-MAXFLOAT); 2170 } 2171 2172 2173 Vector3 AxisAlignedBox3::Center() const 2174 { 2175 return 0.5 * (mMin + mMax); 2176 } 2177 2178 Vector3 AxisAlignedBox3::Diagonal() const 2179 { 2180 return (mMax -mMin); 2181 } 2182 2183 2184 float AxisAlignedBox3::Center(const int axis) const 2185 { 2186 return 0.5f * (mMin[axis] + mMax[axis]); 2187 } 2188 2189 2190 float AxisAlignedBox3::Min(const int axis) const 2191 { 2192 return mMin[axis]; 2193 } 2194 2195 float AxisAlignedBox3::Max(const int axis) const { 2196 return mMax[axis]; 2197 } 2198 2199 float AxisAlignedBox3::Size(const int axis) const { 2200 return Max(axis) - Min(axis); 2201 } 2202 2203 // Read-only const access tomMin and max vectors using references 2204 const Vector3& AxisAlignedBox3::Min() const 2205 { 2206 return mMin; 2207 } 2208 2209 2210 const Vector3& AxisAlignedBox3::Max() const 2211 { 2212 return mMax; 2213 } 2214 2215 2216 void AxisAlignedBox3::Enlarge (const Vector3 &v) 2217 { 2218 mMax += v; 2219 mMin -= v; 2220 } 2221 2222 2223 void AxisAlignedBox3::SetMin(const Vector3 &v) 2224 { 2225 mMin = v; 2226 } 2227 2228 2229 void AxisAlignedBox3::SetMax(const Vector3 &v) 2230 { 2231 mMax = v; 2232 } 2233 2234 2235 void AxisAlignedBox3::SetMin(int axis, const float value) 2236 { 2237 mMin[axis] = value; 2238 } 2239 2240 2241 void AxisAlignedBox3::SetMax(int axis, const float value) 2242 { 2243 mMax[axis] = value; 2244 } 2245 2246 // Decrease box by given splitting plane 2247 void AxisAlignedBox3::Reduce(int axis, int right, float value) 2248 { 2249 if ( (value >=mMin[axis]) && (value <= mMax[axis]) ) 2250 if (right) 2251 mMin[axis] = value; 2252 else 2253 mMax[axis] = value; 2254 } 2255 2256 2257 Vector3 AxisAlignedBox3::Size() const 2258 { 2259 return mMax - mMin; 2260 } 2261 2262 } -
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
r1415 r1486 35 35 /** initialization to the non existing bounding box 36 36 */ 37 void Initialize() { 38 mMin = Vector3(MAXFLOAT); 39 mMax = Vector3(-MAXFLOAT); 40 } 37 void Initialize(); 41 38 42 39 /** The center of the box 43 40 */ 44 Vector3 Center() const { return 0.5 * (mMin + mMax); }41 Vector3 Center() const; 45 42 46 43 /** The diagonal of the box 47 44 */ 48 Vector3 Diagonal() const { return (mMax -mMin); } 49 50 float Center(const int axis) const { 51 return 0.5f * (mMin[axis] + mMax[axis]); 52 } 53 54 float Min(const int axis) const { 55 return mMin[axis]; 56 } 57 58 float Max(const int axis) const { 59 return mMax[axis]; 60 } 61 62 float Size(const int axis) const { 63 return Max(axis) - Min(axis); 64 } 45 Vector3 Diagonal() const; 46 47 float Center(const int axis) const; 48 49 float Min(const int axis) const; 50 51 float Max(const int axis) const; 52 53 float Size(const int axis) const; 65 54 66 55 // Read-only const access tomMin and max vectors using references 67 const Vector3& Min() const { return mMin;} 68 const Vector3& Max() const { return mMax;} 69 70 void Enlarge (const Vector3 &v) { 71 mMax += v; 72 mMin -= v; 73 } 74 75 void SetMin(const Vector3 &v) { 76 mMin = v; 77 } 78 79 void SetMax(const Vector3 &v) { 80 mMax = v; 81 } 82 83 void SetMin(int axis, const float value) { 84 mMin[axis] = value; 85 } 86 87 void SetMax(int axis, const float value) { 88 mMax[axis] = value; 89 } 56 const Vector3& Min() const; 57 const Vector3& Max() const; 58 59 void Enlarge (const Vector3 &v); 60 61 void SetMin(const Vector3 &v); 62 63 void SetMax(const Vector3 &v); 64 65 void SetMin(int axis, const float value); 66 67 void SetMax(int axis, const float value); 90 68 91 69 // Decrease box by given splitting plane 92 void Reduce(int axis, int right, float value) { 93 if ( (value >=mMin[axis]) && (value <= mMax[axis]) ) 94 if (right) 95 mMin[axis] = value; 96 else 97 mMax[axis] = value; 98 } 99 70 void Reduce(int axis, int right, float value); 100 71 101 72 102 73 // the size of the box along all the axes 103 Vector3 Size() const { return mMax - mMin; }74 Vector3 Size() const; 104 75 105 76 // Return whether the box is unbounded. Unbounded boxes appear -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1449 r1486 263 263 264 264 265 static voidAssociateObjectsWithLeaf(BvhLeaf *leaf)265 void BvHierarchy::AssociateObjectsWithLeaf(BvhLeaf *leaf) 266 266 { 267 267 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); … … 272 272 } 273 273 274 274 275 static int CountRays(const ObjectContainer &objects) 275 276 { … … 285 286 return nRays; 286 287 } 288 287 289 288 290 BvhInterior *BvHierarchy::SubdivideNode(const BvhSubdivisionCandidate &sc, … … 1535 1537 { 1536 1538 // search nodes 1537 std::map<BvhNode *, BvhIntersectable *>:: 1538 const_iterator it= mBvhIntersectables.find(node);1539 std::map<BvhNode *, BvhIntersectable *>::const_iterator it 1540 = mBvhIntersectables.find(node); 1539 1541 1540 1542 if (it != mBvhIntersectables.end()) -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1449 r1486 650 650 void CreateRoot(const ObjectContainer &objects); 651 651 652 static void AssociateObjectsWithLeaf(BvhLeaf *leaf); 653 654 652 655 ///////////////////////////// 653 656 // Helper functions for local cost heuristics -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1458 r1486 1200 1200 RegisterOption("VssPreprocessor.initialSamples", 1201 1201 optInt, 1202 " initial_samples=",1202 "vss_initial_samples=", 1203 1203 "100000"); 1204 1204 1205 1205 RegisterOption("VssPreprocessor.testBeamSampling", 1206 1206 optBool, 1207 " beam_sampling",1207 "vss_beam_sampling=", 1208 1208 "false"); 1209 1209 … … 1220 1220 RegisterOption("VssPreprocessor.samplesPerPass", 1221 1221 optInt, 1222 " samples_per_pass=",1222 "vss_samples_per_pass=", 1223 1223 "100000"); 1224 1224 … … 1243 1243 "false"); 1244 1244 1245 1246 RegisterOption("VssPreprocessor.useViewSpaceBox", 1245 RegisterOption("VssPreprocessor.useViewSpaceBox", 1247 1246 optBool, 1248 1247 "vss_use_viewspace_box=", 1249 "false"); 1248 "false"); 1250 1249 1251 1250 1252 /************************************************************************************/ 1253 /* View cells related options */ 1254 /************************************************************************************/ 1251 1252 /************************************************************************************/ 1253 /* GvsPrerpocessor related options */ 1254 /************************************************************************************/ 1255 1256 1257 RegisterOption("GvsPreprocessor.totalSamples", 1258 optInt, 1259 "gvs_total_samples=", 1260 "1000000"); 1261 1262 RegisterOption("GvsPreprocessor.samplesPerPass", 1263 optInt, 1264 "gvs_samples_per_pass=", 1265 "100000"); 1266 1267 RegisterOption("GvsPreprocessor.initialSamples", 1268 optInt, 1269 "gvs_initial_samples=", 1270 "256"); 1271 1272 RegisterOption("GvsPreprocessor.epsilon", 1273 optFloat, 1274 "gvs_epsilon", 1275 "0.00001"); 1276 1277 1278 /***********************************************************************************/ 1279 /* View cells related options */ 1280 /***********************************************************************************/ 1255 1281 1256 1282 … … 1513 1539 1514 1540 1515 1516 /************************************************************************************/ 1517 /* Bsp tree related options */ 1518 /************************************************************************************/ 1541 /******************************************************************/ 1542 /* Bsp tree related options */ 1543 /******************************************************************/ 1519 1544 1520 1545 … … 1665 1690 RegisterOption("Preprocessor.loadMeshes", 1666 1691 optBool, 1667 " loadMeshes=",1692 "preprocessor_load_meshes=", 1668 1693 "true"); 1669 1694 … … 1794 1819 RegisterOption("RssPreprocessor.initialSamples", 1795 1820 optInt, 1796 " initial_samples=",1821 "rss_initial_samples=", 1797 1822 "100000"); 1798 1823 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1473 r1486 4 4 #include "VssRay.h" 5 5 #include "ViewCellsManager.h" 6 #include "Triangle3.h" 6 7 7 8 … … 13 14 GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0) 14 15 { 15 Environment::GetSingleton()->GetIntValue("RenderSampler.samples", mSamples); 16 //Environment::GetSingleton()->GetIntValue("Render.samples", mTotalSamples); 17 18 cout << "number of render samples: " << mSamples << endl; 19 } 20 21 22 int GvsPreprocessor::HandleRay(VssRay &ray) 23 { 24 int sampleContributions = 0; 25 26 if (mViewCellsManager->ComputeSampleContribution(ray, true, false)) 27 { 28 return AdaptiveBorderSampling(ray); 16 Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples); 17 Environment::GetSingleton()->GetIntValue("GvsPreprocessor.initialSamples", mInitialSamples); 18 Environment::GetSingleton()->GetIntValue("GvsPreprocessor.samplesPerPass", mSamplesPerPass); 19 Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.epsilon", mEps); 20 21 22 Debug << "Gvs preprocessor options" << endl; 23 Debug << "number of total samples: " << mTotalSamples << endl; 24 Debug << "number of initial samples: " << mInitialSamples << endl; 25 Debug << "number of samples per pass: " << mSamplesPerPass << endl; 26 27 mStats.open("gvspreprocessor.log"); 28 } 29 30 31 const bool GvsPreprocessor::DiscontinuityFound(const VssRay &ray) const 32 { 33 return false; 34 } 35 36 37 int GvsPreprocessor::HandleRay(const GvsRayInfo &gvsRay) 38 { 39 VssRay *ray = gvsRay.mRay; 40 41 if (!mViewCellsManager->ComputeSampleContribution(*ray, true, false)) 42 return 1; 43 44 if (gvsRay.mFoundDiscontinuity) 45 { 46 return ReverseSampling(*ray); 29 47 } 30 48 else 31 49 { 32 return ReverseSampling(ray); 33 } 34 } 35 36 37 int GvsPreprocessor::AdaptiveBorderSampling(VssRay &ray) 38 { 50 return AdaptiveBorderSampling(*ray); 51 } 52 } 53 54 55 void GvsPreprocessor::CreateNewSamples(VertexContainer &samples, 56 const VssRay &ray, 57 const Triangle3 &hitTriangle, 58 const int index, 59 const float eps) 60 { 61 const int indexU = (index + 1) % 3; 62 const int indexL = (index == 0) ? 2 : index - 1; 63 64 const Vector3 a = hitTriangle.mVertices[index] - ray.GetDir(); 65 const Vector3 b = hitTriangle.mVertices[indexU] - hitTriangle.mVertices[index]; 66 const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL]; 67 const float len = Magnitude(a); 68 69 // compute the new three hit points 70 // pi, i + 1 71 const Vector3 dir1 = CrossProd(a, b); //N((pi-xp)×(pi+1- pi)); 72 const Vector3 pt1 = hitTriangle.mVertices[index] + eps * len * dir1; //pi+ e·|pi-xp|·di, j 73 samples.push_back(pt1); 74 75 // pi, i - 1 76 const Vector3 dir2 = CrossProd(a, c); // N((pi-xp)×(pi- pi-1)) 77 const Vector3 pt2 = hitTriangle.mVertices[index] + eps * len * dir2; //pi+ e·|pi-xp|·di, j 78 samples.push_back(pt2); 79 80 // pi, i 81 const Vector3 dir3 = DotProd(dir1, dir2) > 0 ? 82 Normalize(dir2 + dir1) : Normalize(CrossProd(a, dir2) + CrossProd(dir1, a)); // N((pi-xp)×di,i-1+di,i+1×(pi-xp)) 83 const Vector3 pt3 = hitTriangle.mVertices[index] + eps * len * dir3; //pi+ e·|pi-xp|·di, j 84 samples.push_back(pt3); 85 } 86 87 88 int GvsPreprocessor::AdaptiveBorderSampling(const VssRay &ray) 89 { 90 cout << "a"; 91 //Intersectable *tObj = ray->GetTerminationObject; 92 Triangle3 hitTriangle; 93 vector<Vector3> samples; 94 samples.reserve(9); 95 96 CreateNewSamples(samples, ray, hitTriangle, 0, mEps); 97 CreateNewSamples(samples, ray, hitTriangle, 1, mEps); 98 CreateNewSamples(samples, ray, hitTriangle, 2, mEps); 99 100 VertexContainer::const_iterator vit, vit_end = samples.end(); 101 102 for (vit = samples.begin(); vit != vit_end; ++ vit) 103 { 104 VssRay *ray;// = CreateRay(*vit); 105 106 if (DiscontinuityFound(*ray)) 107 { 108 // schedule for reverse sampling 109 mRayQueue.push(GvsRayInfo(ray, true)); 110 } 111 else 112 { 113 // schedule for adaptive border sampling 114 mRayQueue.push(GvsRayInfo(ray, false)); 115 } 116 } 117 39 118 // TODO 40 return 0; 41 } 42 43 44 int GvsPreprocessor::ReverseSampling(VssRay &ray) 45 { 119 return 1; 120 } 121 122 123 int GvsPreprocessor::ReverseSampling(const VssRay &ray) 124 { 125 cout << "r" << endl; 46 126 // TODO 47 return 0;127 return 1; 48 128 } 49 129 … … 58 138 Debug << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 59 139 140 // cast the rays and optain hitpoints with geometry 60 141 VssRayContainer samples; 61 62 // cast the rays and optain hitpoints with geometry63 142 CastRays(simpleRays, samples); 143 64 144 Debug << "cast " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 65 145 66 // add to ray queue146 // add samples to ray queue 67 147 VssRayContainer::const_iterator vit, vit_end = samples.end(); 68 69 148 for (vit = samples.begin(); vit != vit_end; ++ vit) 70 149 { … … 76 155 77 156 78 int GvsPreprocessor::Pass( const int passSamples)157 int GvsPreprocessor::Pass() 79 158 { 80 159 int castSamples = 0; 81 const int uniformSamples = 1000; 82 83 while (castSamples < passSamples) 160 161 while (castSamples < mSamplesPerPass) 84 162 { 85 163 // Ray queue empty => 86 164 // cast a number of uniform samples to fill ray Queue 87 CastAvsSamples(uniformSamples, mSamplingType, mRayQueue); 88 castSamples += Pass(passSamples); 165 CastAvsSamples(mInitialSamples, mSamplingType, mRayQueue); 166 167 const int gvsSamples = RunSampling(); 168 castSamples += gvsSamples; 169 //cout << "\ngvs samples: " << gvsSamples << endl; 170 //cout << "cast " << castSamples << " of " << mSamplesPerPass << endl; 89 171 } 90 172 … … 116 198 const long startTime = GetTime(); 117 199 118 cout<<"Gvs Preprocessor started\n"<<flush; 119 120 /// construct the view cells first 121 ConstructViewCells(); 122 123 int samples = 0; 124 125 while (samples < mTotalSamples) 126 { 127 samples += Pass(mSamplesPerPass); 128 129 cout<<"+"; 130 131 // mVssRays.PrintStatistics(mStats); 200 mViewSpaceBox = mKdTree->GetBox(); 201 cout << "Gvs Preprocessor started\n" << flush; 202 203 if (!mLoadViewCells) 204 { /// construct the view cells from the scratch 205 ConstructViewCells(mViewSpaceBox); 206 cout << "view cells loaded" << endl; 207 } 208 209 int castSamples = 0; 210 211 while (castSamples < mTotalSamples) 212 { 213 const int passSamples = Pass(); 214 castSamples += passSamples; 215 cout << "+"; 216 cout << "\nsamples cast " << passSamples << " (=" << castSamples << " of " << mTotalSamples << ")" << endl; 217 //mVssRays.PrintStatistics(mStats); 132 218 //mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 133 219 // << "#TotalSamples\n" << samples << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1473 r1486 13 13 class VssRay; 14 14 15 16 typedef stack<VssRay *> RayQueue;17 15 18 16 /** Sampling based visibility preprocessing. The implementation is … … 31 29 protected: 32 30 31 struct GvsRayInfo 32 { 33 VssRay *mRay; 34 bool mFoundDiscontinuity; 35 } 36 37 38 typedef stack<GvsRayInfo> RayQueue; 39 33 40 /** Runs the adaptive sampling. The method starts with a number of random rays given 34 41 by the queue and continues as long it finds new visible geometry (i.e., the queue is … … 43 50 @returns the number of samples cast. 44 51 */ 45 int Pass( const int passSamples);52 int Pass(); 46 53 47 54 /** Generates the rays starting the adaptive visibility sampling process. … … 61 68 b) if triangle was found reverse sampling 62 69 */ 63 int HandleRay( VssRay&ray);70 int HandleRay(const GvsRayInfo &ray); 64 71 65 72 /** 66 73 */ 67 int AdaptiveBorderSampling( VssRay &ray);74 int AdaptiveBorderSampling(const VssRay &ray); 68 75 69 int ReverseSampling( VssRay &ray);76 int ReverseSampling(const VssRay &ray); 70 77 71 78 /** Cast samples according to a specific sampling strategy. … … 76 83 VssRayContainer &passSamples) const; 77 84 85 void CreateNewSamples( 86 VertexContainer &samples, 87 const VssRay &ray, 88 const Triangle3 &hitTriangle, 89 const int index, 90 const float eps); 91 92 const bool DiscontinuityFound(const VssRay &ray) const; 78 93 79 94 … … 81 96 82 97 ofstream mStats; 83 int mSamples; 98 84 99 int mSamplesPerPass; 85 100 RayQueue mRayQueue; 86 101 int mSamplingType; 87 102 int mTotalSamples; 103 int mInitialSamples; 104 AxisAlignedBox3 mViewSpaceBox; 105 float mEps; 88 106 }; 89 107 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1473 r1486 329 329 const ObjectContainer &objects) 330 330 { 331 cout << " starting view space hierarchy construction ... " << endl;331 cout << "\nstarting view space hierarchy construction ... " << endl; 332 332 333 333 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); … … 604 604 { 605 605 Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 606 cout << " resetting bv hierarchy" << endl;606 cout << "\nresetting bv hierarchy" << endl; 607 607 mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes; 608 608 mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses … … 856 856 { 857 857 case NO_OBJ_SUBDIV: 858 // potentially visible objects 859 return vc->AddPvsSample(obj, pdf, contribution); 858 { 859 // potentially visible objects 860 return vc->AddPvsSample(obj, pdf, contribution); 861 } 860 862 case KD_BASED_OBJ_SUBDIV: 861 863 { -
GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp
r1233 r1486 463 463 464 464 return result; 465 466 } 467 468 } 465 } 466 467 468 AxisAlignedBox3 MeshKdTree::GetBox() const 469 { 470 return mMesh->mBox; 471 } 472 473 474 MeshKdTree::~MeshKdTree() 475 { 476 if (mSubdivisionCandidates) 477 delete mSubdivisionCandidates; 478 479 if (mRoot) 480 delete mRoot; 481 } 482 483 484 MeshKdNode *MeshKdTree::GetRoot() const 485 { 486 return mRoot; 487 } 488 489 490 } -
GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.h
r1233 r1486 127 127 public: 128 128 129 enum {SPLIT_OBJECT_MEDIAN, 130 SPLIT_SPATIAL_MEDIAN, 131 SPLIT_SAH}; 129 enum { 130 SPLIT_OBJECT_MEDIAN, 131 SPLIT_SPATIAL_MEDIAN, 132 SPLIT_SAH}; 132 133 133 134 134 135 MeshKdTree(Mesh *mesh); 135 ~MeshKdTree() { 136 if (mSubdivisionCandidates) 137 delete mSubdivisionCandidates; 138 139 if (mRoot) 140 delete mRoot; 141 } 136 ~MeshKdTree(); 142 137 143 138 virtual bool Construct(); … … 155 150 virtual MeshKdNode *Subdivide(const TraversalData &tdata); 156 151 157 /** Get the root of the tree */ 158 MeshKdNode *GetRoot() const { 159 return mRoot; 160 } 161 162 AxisAlignedBox3 GetBox() const { return mMesh->mBox; } 152 /** Get the root of the tree 153 */ 154 MeshKdNode *GetRoot() const; 155 156 AxisAlignedBox3 GetBox() const; 163 157 164 158 int -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1421 r1486 327 327 Preprocessor::ExportPreprocessedData(const string filename) 328 328 { 329 330 mViewCellsManager->ExportViewCells(filename, true, mObjects); 331 332 return true; 333 } 329 mViewCellsManager->ExportViewCells(filename, true, mObjects); 330 return true; 331 } 332 334 333 335 334 bool … … 352 351 // export the preprocessed information to a file 353 352 if (mExportVisibility) 354 ExportPreprocessedData(mVisibilityFileName); 355 353 { 354 ExportPreprocessedData(mVisibilityFileName); 355 } 356 356 357 return true; 357 358 } … … 445 446 } 446 447 447 //-- parameters for render heuristics evaluation 448 //////// 449 //-- render heuristics evaluation 448 450 float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0; 449 451 … … 472 474 473 475 474 bool 475 Preprocessor::ConstructViewCells() 476 { 477 // if not already loaded, construct view cells from file 478 if (!mLoadViewCells) { 479 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 476 bool Preprocessor::ConstructViewCells(const AxisAlignedBox3 &viewSpaceBox) 477 { 478 mViewCellsManager->SetViewSpaceBox(viewSpaceBox); 480 479 481 480 // construct view cells using it's own set of samples 482 481 mViewCellsManager->Construct(this); 483 484 // -- severalvisualizations and statistics485 Debug << " view cells construction finished:" << endl;482 483 // visualizations and statistics 484 Debug << "finished view cells:" << endl; 486 485 mViewCellsManager->PrintStatistics(Debug); 487 } 488 486 487 return true; 489 488 } 490 489 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1421 r1486 88 88 bool PrepareViewCells(); 89 89 90 /** Construct viewcells (if not already loaded) */91 bool92 ConstructViewCells();90 /** Construct viewcells from the scratch 91 */ 92 bool ConstructViewCells(const AxisAlignedBox3 &viewSpaceBox); 93 93 94 94 /** Returns the specified sample strategy, NULL if no valid strategy. -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r1473 r1486 506 506 </File> 507 507 <File 508 RelativePath=".\PreprocessorFactory.cpp"> 509 </File> 510 <File 511 RelativePath=".\PreprocessorFactory.h"> 512 </File> 513 <File 508 514 RelativePath="..\src\PreprocessorThread.cpp"> 509 515 </File> -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
r1315 r1486 91 91 92 92 node->Mail(); 93 94 return (int) (((BvhLeaf *)node)->mObjects.size());93 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 94 return (int)leaf->mObjects.size(); 95 95 } 96 96 97 97 // compute leaf pvs 98 98 int pvs = 0; 99 100 99 stack<BvhNode *> tStack; 101 102 100 tStack.push(bvhobj->GetItem()); 103 101 … … 146 144 { 147 145 Intersectable *obj = (*it).first; 148 146 149 147 switch (obj->Type()) 150 148 { -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
r1292 r1486 124 124 if (!mLoadViewCells) 125 125 { 126 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 127 128 // construct view cells using it's own set of samples 129 mViewCellsManager->Construct(this); 130 131 //-- several visualizations and statistics 132 Debug << "view cells construction finished: " << endl; 133 mViewCellsManager->PrintStatistics(Debug); 126 ConstructViewCells(mKdTree->GetBox()); 134 127 } 135 128 -
GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp
r1379 r1486 175 175 } 176 176 177 if (currentMesh->mVertices.size()) {178 if (1) 179 177 if (currentMesh->mVertices.size()) 178 { 179 if (ROTATE_SCENE) RotateMesh(currentMesh); 180 180 181 182 183 181 currentMesh->Preprocess(); 182 MeshInstance *mi = new MeshInstance(currentMesh); 183 root->mGeometry.push_back(mi); 184 184 } 185 185 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1473 r1486 27 27 #define SAMPLE_ORIGIN_OBJECTS 0 28 28 29 30 31 29 32 namespace GtpVisibilityPreprocessor { 30 33 … … 32 35 // HACK 33 36 const static bool SAMPLE_AFTER_SUBDIVISION = true; 34 const static bool TEST_EMPTY_VIEW_CELLS = false; 35 37 const static bool CLAMP_TO_BOX = false; 36 38 37 39 template <typename T> class myless … … 223 225 CLEAR_CONTAINER(mViewCells); 224 226 } 225 //DEL_PTR(mViewCellsTree);226 227 } 227 228 … … 1872 1873 if (viewcell->GetValid()) 1873 1874 { 1874 // if ray not outside of view space 1875 1876 // add new object to the pvs 1875 // if view point is valid, add new object to the pvs 1877 1876 if (ray.mTerminationObject) 1878 1877 { … … 2737 2736 if (1) FinalizeViewCells(true); 2738 2737 2739 // write view cells to disc (this moved to preprocessor)2740 if ( 0&& mExportViewCells)2738 // write view cells to disc 2739 if (1 && mExportViewCells) 2741 2740 { 2742 2741 char filename[100]; … … 3906 3905 SimulationStatistics ss; 3907 3906 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 3908 3909 cout << ss << endl; 3907 cout << ss << endl; 3910 3908 3911 3909 … … 3935 3933 3936 3934 // write view cells to disc 3937 if ( 0&& mExportViewCells)3935 if (1 && mExportViewCells) 3938 3936 { 3939 3937 char filename[100]; … … 4903 4901 cout << ss << endl; 4904 4902 4903 4905 4904 /////////////// 4906 4905 //-- compression … … 4917 4916 } 4918 4917 4919 /////////////// 4920 //-- compute final meshes and volume / area 4918 ///////////// 4919 //-- some tasks still to do on the view cells: 4920 //-- Compute meshes from view cell geometry, evaluate volume and / or area 4921 4921 if (1) FinalizeViewCells(true); 4922 4922 4923 4923 // write out view cells (this moved to preprocessor) 4924 if ( 0&& mExportViewCells)4924 if (1 && mExportViewCells) 4925 4925 { 4926 4926 char filename[100]; … … 5093 5093 AxisAlignedBox3 bbox = mHierarchyManager->GetViewSpaceBox(); 5094 5094 bbox.Scale(Vector3(0.5, 1, 0.5)); 5095 5096 exporter->SetWireframe();5097 exporter->ExportBox(bbox);5098 exporter->SetFilled();5099 5095 5096 if (CLAMP_TO_BOX) 5097 { 5098 exporter->SetWireframe(); 5099 exporter->ExportBox(bbox); 5100 exporter->SetFilled(); 5101 } 5102 5103 /////////////////// 5104 5100 5105 if (0 && mExportGeometry) 5101 5106 { 5102 exporter->ExportGeometry(objects, true, &bbox);5107 exporter->ExportGeometry(objects, true, CLAMP_TO_BOX ? &bbox : NULL); 5103 5108 } 5104 5109 … … 5109 5114 } 5110 5115 5111 mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, &bbox, false);5112 ExportViewCellsForViz(exporter, &bbox, GetClipPlane());5116 mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL, false); 5117 ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, GetClipPlane()); 5113 5118 5114 5119 delete exporter; … … 5128 5133 const long starttime = GetTime(); 5129 5134 5130 // matt: hack 5135 // matt: hack for making visualization smaller in size 5131 5136 AxisAlignedBox3 bbox = mHierarchyManager->GetObjectSpaceBox(); 5132 5137 bbox.Scale(Vector3(0.5, 1, 0.5)); 5133 5138 5134 5139 cout << "exporting object space hierarchy ... "; 5135 mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, &bbox);5140 mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL); 5136 5141 5137 5142 delete exporter; … … 5304 5309 5305 5310 5306 /////////////// ///////////////////////////////////////////////5311 /////////////// 5307 5312 //-- export bounding boxes 5308 5313 //-- The bounding boxes are used to identify … … 5478 5483 // todo: maybe not correct for kd node pvs 5479 5484 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 5480 ray.mPdf, contribution))5485 ray.mPdf, contribution)) 5481 5486 { 5482 5487 ++ ray.mPvsContribution; … … 5541 5546 float &contribution) const 5542 5547 { 5548 // The hierarchy manager decides about the type of sample cast 5543 5549 return mHierarchyManager->AddSampleToPvs(obj, hitPoint, vc, pdf, contribution); 5544 5550 } … … 5609 5615 5610 5616 cout << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... "; 5611 5617 5612 5618 ComputeSampleContributions(evaluationSamples, true, false); 5613 5619 5614 5620 cout << "finished" << endl; 5615 5621 5616 5622 cout << "compute new statistics ... "; 5617 Debug << "compute new statistics ... "; 5618 5623 5619 5624 // propagate pvs or pvs size information 5620 5625 ObjectPvs pvs; 5621 5626 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 5622 5627 5623 /////////////////////////////////////// 5624 //-- temporary matt: test render cost 5628 5629 ///////////////////// 5630 // $§temporary matt: test render cost 5625 5631 5626 5632 sprintf(s, "-%09d-eval.log", castSamples); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1421 r1486 919 919 { 920 920 Debug << "creating view cells manager: VspBsp" << endl; 921 922 921 mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree); 923 922 } … … 925 924 { 926 925 Debug << "creating view cells manager: VspOsp" << endl; 927 // hack928 926 mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager); 929 927 } … … 998 996 999 997 //cout << "\nsearching view cell with id " << viewCellId << endl; 1000 1001 998 ViewCellContainer::iterator vit = 1002 999 lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); … … 1183 1180 1184 1181 leaf->mObjects = objects; 1182 BvHierarchy::AssociateObjectsWithLeaf(leaf); 1185 1183 } 1186 1184 … … 1190 1188 { 1191 1189 vector<int> objIndices; 1192 1193 1190 char *endptr; 1194 1191 … … 1221 1218 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 1222 1219 { 1223 objects.push_back(*oit); 1220 objects.push_back(*oit); 1224 1221 } 1225 1222 else -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h
r1404 r1486 26 26 class Beam; 27 27 class OspTree; 28 29 28 30 29 31 class VrmlExporter : public Exporter -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1418 r1486 24 24 25 25 VssPreprocessor::VssPreprocessor(): 26 mVssRays(), 27 mViewSpaceBox(NULL) 26 mVssRays() 28 27 { 29 28 // this should increase coherence of the samples … … 43 42 useViewspacePlane = mUseViewSpaceBox; //hack 44 43 44 mViewSpaceBox.Initialize(); 45 45 46 46 Debug << "*********** vss preprocessor options **************" << endl; … … 56 56 { 57 57 CLEAR_CONTAINER(mVssRays); 58 DEL_PTR(mViewSpaceBox); 59 } 60 61 62 63 58 } 64 59 65 60 … … 163 158 exporter->SetWireframe(); 164 159 165 if (mViewSpaceBox) { 166 exporter->SetForcedMaterial(RgbColor(1,0,1)); 167 exporter->ExportBox(*mViewSpaceBox); 168 exporter->ResetForcedMaterial(); 169 } 160 exporter->SetForcedMaterial(RgbColor(1,0,1)); 161 exporter->ExportBox(mViewSpaceBox); 162 exporter->ResetForcedMaterial(); 163 170 164 171 165 VssRayContainer rays; … … 207 201 exporter->ExportKdTree(*mKdTree); 208 202 209 if (mViewSpaceBox) { 210 exporter->SetForcedMaterial(RgbColor(1,0,0)); 211 exporter->ExportBox(*mViewSpaceBox); 212 exporter->ResetForcedMaterial(); 213 } 203 exporter->SetForcedMaterial(RgbColor(1,0,0)); 204 exporter->ExportBox(mViewSpaceBox); 205 exporter->ResetForcedMaterial(); 214 206 215 207 exporter->SetForcedMaterial(RgbColor(0,0,1)); … … 412 404 if (mUseViewSpaceBox) 413 405 { 414 //mViewSpaceBox = ConstructViewSpaceBox();415 416 406 if (!mEnlargeViewSpace) 417 407 { 418 mViewSpaceBox = newAxisAlignedBox3(box);408 mViewSpaceBox = AxisAlignedBox3(box); 419 409 } 420 410 else 421 411 { 422 mViewSpaceBox = newAxisAlignedBox3(mKdTree->GetBox());412 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 423 413 424 414 if (0) 425 415 { 426 416 // HACK: enlarge in y directon 427 Vector3 size = mViewSpaceBox ->Size();417 Vector3 size = mViewSpaceBox.Size(); 428 418 429 419 size[1] *= 1.25; … … 431 421 //Vector3 enlarge(size[0] * 4.0f, 0.0f, 0.0f); 432 422 433 mViewSpaceBox ->Enlarge(enlarge);434 mViewSpaceBox ->SetMax(mViewSpaceBox->Max() + enlarge);423 mViewSpaceBox.Enlarge(enlarge); 424 mViewSpaceBox.SetMax(mViewSpaceBox.Max() + enlarge); 435 425 } 436 426 else 437 427 { 438 AxisAlignedBox3 tbox(*mViewSpaceBox); 439 440 Vector3 size = mViewSpaceBox->Size(); 441 tbox.SetMax(0, mViewSpaceBox->Max(0) + size[0] * 0.5f); 442 tbox.SetMin(0, mViewSpaceBox->Min(0) + size[0]); 443 *mViewSpaceBox = tbox; 444 445 // $$ JB temporary 446 /*AxisAlignedBox3 tempbox = *mViewSpaceBox; 447 448 float s = tempbox.Size(0); 449 450 tempbox.Scale(0.8f); 451 tempbox.SetMax(0, box.Max(0) + s*0.8f); 452 tempbox.SetMin(0, box.Min(0) + s*0.8f); 453 *mViewSpaceBox = tempbox;*/ 428 AxisAlignedBox3 tbox(mViewSpaceBox); 429 430 Vector3 size = mViewSpaceBox.Size(); 431 tbox.SetMax(0, mViewSpaceBox.Max(0) + size[0] * 0.5f); 432 tbox.SetMin(0, mViewSpaceBox.Min(0) + size[0]); 433 mViewSpaceBox = tbox; 454 434 } 455 435 } 456 //Debug << "view space box: " << *mViewSpaceBox << endl;457 436 } 458 437 else 459 438 { 460 mViewSpaceBox = NULL; 461 } 462 463 AxisAlignedBox3 vbox = mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox(); 464 439 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 440 } 441 465 442 mSceneGraph->CollectObjects(&mObjects); 466 443 467 444 if (!mLoadViewCells) 468 445 { 469 //-- generate new view cells or reconstruct them446 //-- generate new view cells from the scratch 470 447 //-- for construction the manager uses it's own set of samples 471 mViewCellsManager->SetViewSpaceBox(vbox); 472 mViewCellsManager->Construct(this); 473 474 // output visualizations and statistics 475 Debug << "view cells construction finished: " << endl; 476 mViewCellsManager->PrintStatistics(Debug); 448 ConstructViewCells(mViewSpaceBox); 477 449 } 478 450 #if 0 … … 509 481 510 482 int s = Min(mSamplesPerPass, mInitialSamples); 511 for (int k=0; k < s; k++) {512 // changed by matt483 for (int k=0; k < s; k++) 484 { 513 485 Vector3 viewpoint; 514 // viewpoint = GetViewpoint(mViewSpaceBox);486 515 487 mViewCellsManager->GetViewPoint(viewpoint); 516 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);517 518 sampleContributions = CastRay(viewpoint, direction, 1, mVssRays, vbox);488 Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 489 490 sampleContributions = CastRay(viewpoint, direction, 1, mVssRays, mViewSpaceBox); 519 491 520 492 if (sampleContributions) { … … 589 561 // viewcells = Construct(mVssRays); 590 562 591 vssTree->Construct(mVssRays, mViewSpaceBox);563 vssTree->Construct(mVssRays, NULL); 592 564 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 593 565 … … 635 607 if (!mUseImportanceSampling) { 636 608 for (int j=0; j < num; j++) { 637 // changed by matt 638 //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 639 Vector3 viewpoint; 609 Vector3 viewpoint; 640 610 mViewCellsManager->GetViewPoint(viewpoint); 641 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);611 Vector3 direction = GetDirection(viewpoint, NULL); 642 612 rays.push_back(SimpleRay(viewpoint, direction)); 643 613 } … … 647 617 648 618 for (int i=0; i < rays.size(); i++) 649 CastRay(rays[i].mOrigin, rays[i].mDirection, 1, vssRays, vbox);619 CastRay(rays[i].mOrigin, rays[i].mDirection, 1, vssRays, mViewSpaceBox); 650 620 651 621 vssTree->AddRays(vssRays); … … 698 668 699 669 700 //////////////////// //////////////701 //-- render simulation after 670 //////////////////// 671 //-- render simulation after construction 702 672 703 673 mRenderSimulator->RenderScene(); -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h
r1281 r1486 26 26 bool mUseImportanceSampling; 27 27 bool mEnlargeViewSpace; 28 AxisAlignedBox3 *mViewSpaceBox;28 AxisAlignedBox3 mViewSpaceBox; 29 29 30 30 ofstream mStats; -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
r1404 r1486 26 26 27 27 } 28 28 29 29 30 X3dExporter::~X3dExporter() -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1457 r1486 18 18 #include <crtdbg.h> 19 19 20 #include "SamplingPreprocessor.h" 21 #include "VssPreprocessor.h" 22 #include "RssPreprocessor.h" 23 #include "ExactPreprocessor.h" 20 #include "PreprocessorFactory.h" 24 21 #include "Parser.h" 25 #include "UnigraphicsParser.h"26 #include "X3dParser.h"27 22 #include "Environment.h" 28 #include "Camera.h"29 23 #include "MeshKdTree.h" 30 #include "Exporter.h" 31 #include "ViewCell.h" 32 #include "SceneGraph.h" 24 #include "Preprocessor.h" 25 33 26 34 27 #include "PreprocessorThread.h" … … 37 30 #endif 38 31 39 #include "RenderSampler.h"40 32 #include "ResourceManager.h" 41 33 #include "GlRenderer.h" … … 115 107 string preprocessorType(buff); 116 108 117 if (preprocessorType == "vss") 118 { 119 preprocessor = new VssPreprocessor(); 120 } 121 else 122 { 123 if (preprocessorType == "rss") 124 { 125 preprocessor = new RssPreprocessor(); 126 } 127 else 128 { 129 if (preprocessorType == "exact") 130 { 131 preprocessor = new ExactPreprocessor(); 132 } 133 else 134 { 135 if (preprocessorType == "sampling") 136 { 137 preprocessor = new SamplingPreprocessor(); 138 } 139 else 140 { 141 if (preprocessorType == "render") 142 { 143 preprocessor = new RenderSampler(); 144 } 145 else 146 { 147 Environment::DelSingleton(); 148 cerr<<"Unknown preprocessor type"<<endl; 149 Debug<<"Unknown preprocessor type"<<endl; 150 exit(1); 151 } 152 } 153 } 154 } 109 if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType))) 110 { 111 Environment::DelSingleton(); 112 cerr << "Unknown preprocessor type" << endl; 113 exit(1); 155 114 } 156 115
Note: See TracChangeset
for help on using the changeset viewer.