Changeset 2575
- Timestamp:
- 01/03/08 15:53:44 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 73 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r2332 r2575 1 1 2 // GOLEM library3 #include <assert.h>4 2 #include <iostream> 5 3 #include "AxisAlignedBox3.h" … … 10 8 #include "Triangle3.h" 11 9 #include "VssRay.h" 10 11 12 13 #include <cassert> 12 14 13 15 … … 210 212 int 211 213 AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 212 213 214 float *tmin, 215 float *tmax) const 214 216 { 215 217 float minx, maxx, miny, maxy, minz, maxz; … … 302 304 int 303 305 AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 304 305 306 float *tmin, 307 float *tmax) const 306 308 { 307 309 const float dirEps = 1e-8f; … … 398 400 // the bounding box and 0 if it does not. 399 401 int AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax, 400 402 EFaces &entryFace, EFaces &exitFace) const 401 403 { 402 404 float minx, maxx, miny, maxy, minz, maxz; … … 1840 1842 int 1841 1843 AxisAlignedBox3::ComputeMinMaxT(const Vector3 &origin, 1842 const Vector3 &direction, 1843 float *tmin, 1844 float *tmax) const 1845 { 1846 1844 const Vector3 &direction, 1845 float *tmin, 1846 float *tmax) const 1847 { 1847 1848 register float minx, maxx; 1848 1849 … … 2235 2236 2236 2237 2238 void AxisAlignedBox3::EnlargeToMinSize() 2239 { 2240 const float epsMin = 1e-7; 2241 const float epsAdd = 1e-6; 2242 const float epsMul = 1.000005; 2243 float dir = mMax.x - mMin.x; 2244 assert(dir >= 0.f); 2245 if (dir < epsMin) { 2246 if (mMax.x > 0) { 2247 mMax.x *= epsMul; 2248 mMax.x += epsAdd; 2249 } 2250 else { 2251 mMin.x *= epsMul; 2252 mMin.x -= epsAdd; 2253 } 2254 assert(mMin.x < mMax.x); 2255 } 2256 dir = mMax.y - mMin.y; 2257 assert(dir >= 0.f); 2258 if (dir < epsMin) { 2259 if (mMax.y > 0) { 2260 mMax.y *= epsMul; 2261 mMax.y += epsAdd; 2262 } 2263 else { 2264 mMin.y *= epsMul; 2265 mMin.y -= epsAdd; 2266 } 2267 assert(mMin.y < mMax.y); 2268 } 2269 dir = mMax.z - mMin.z; 2270 assert(dir >= 0.f); 2271 if (dir < epsMin) { 2272 if (mMax.z > 0) { 2273 mMax.z *= epsMul; 2274 mMax.z += epsAdd; 2275 } 2276 else { 2277 mMin.z *= epsMul; 2278 mMin.z -= epsAdd; 2279 } 2280 assert(mMin.z < mMax.z); 2281 } 2282 } 2283 2237 2284 void AxisAlignedBox3::SetMin(const Vector3 &v) 2238 2285 { 2239 2286 mMin = v; 2240 2287 } 2241 2288 … … 2243 2290 void AxisAlignedBox3::SetMax(const Vector3 &v) 2244 2291 { 2245 2292 mMax = v; 2246 2293 } 2247 2294 -
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
r2176 r2575 61 61 void Enlarge (const Vector3 &v); 62 62 63 void EnlargeToMinSize(); 64 63 65 void SetMin(const Vector3 &v); 64 66 … … 232 234 233 235 int ComputeMinMaxT(const Vector3 &origin, 234 235 236 236 const Vector3 &direction, 237 float *tmin, 238 float *tmax) const; 237 239 238 240 // Compute tmin and tmax for a ray, whenever required .. need not pierce box … … 241 243 // Compute tmin and tmax for a ray, whenever required .. need not pierce box 242 244 int ComputeMinMaxT(const Ray &ray, 243 244 245 246 245 float *tmin, 246 float *tmax, 247 EFaces &entryFace, 248 EFaces &exitFace) const; 247 249 248 250 // If a ray pierces the box .. returns 1, otherwise 0. … … 251 253 // computes the signed distances for case: tmin < tmax and tmax > 0 252 254 int GetMinMaxT(const Ray &ray, float *tmin, float *tmax, 253 255 EFaces &entryFace, EFaces &exitFace) const; 254 256 255 257 // Writes a brief description of the object, indenting by the given -
GTP/trunk/Lib/Vis/Preprocessing/src/BitVectorPvs.h
r2530 r2575 79 79 class BitVectorPvs//: public PvsBase<T> 80 80 { 81 template<typename T, typename S> friend class BitVectorPvsIterator;81 template<typename T1, typename S1> friend class BitVectorPvsIterator; 82 82 83 83 public: … … 121 121 bool Find(T sample); 122 122 123 typenameBitVectorPvsIterator<T, S> GetIterator() const;123 BitVectorPvsIterator<T, S> GetIterator() const; 124 124 125 125 /** Compute continuous PVS difference … … 145 145 void MergeInPlace(const BitVectorPvs<T, S> &a) 146 146 { 147 cerr << "bitvector: merge in place not implemented yet" << endl; 147 std::cerr << "bitvector: merge in place not implemented yet" 148 << std::endl; 148 149 } 149 150 … … 167 168 int SubtractPvs(const BitVectorPvs<T, S> &pvs) 168 169 { 169 cerr << "not yet implemented" <<endl;170 170 std::cerr << "not yet implemented" << std::endl; 171 return 0; 171 172 } 172 173 … … 177 178 float &pvsEnlargement) 178 179 { 179 cerr << "not yet implemented" <<endl;180 std::cerr << "not yet implemented" << std::endl; 180 181 } 181 182 … … 284 285 285 286 template <typename T, typename S> 286 void BitVectorPvs<T, S>::Clear(const bool trim = true)287 void BitVectorPvs<T, S>::Clear(const bool trim) 287 288 { 288 289 bit_vector::iterator bit, bit_end = mEntries.end(); … … 309 310 310 311 template <typename T, typename S> 311 typename BitVectorPvsIterator<T, S> BitVectorPvs<T, S>::GetIterator() const 312 { 313 BitVectorPvsIterator<T, S> pit(mEntries.begin(), mEntries.end()); 314 315 return pit; 312 BitVectorPvsIterator<T, S> BitVectorPvs<T, S>::GetIterator() const 313 { 314 return BitVectorPvsIterator<T, S>(mEntries.begin(), mEntries.end()); 316 315 } 317 316 -
GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp
r1867 r2575 4 4 #include "SceneGraph.h" 5 5 #include "Preprocessor.h" 6 #include <boost/thread/thread.hpp> 6 7 // ??????????????? commented by VH ???????????? 8 //#include <boost/thread/thread.hpp> 7 9 8 10 namespace GtpVisibilityPreprocessor { 9 11 10 12 13 #ifdef THREADS1 14 11 15 BoostPreprocessorThread::BoostPreprocessorThread(Preprocessor *p): 12 16 PreprocessorThread(p), mThread(NULL) … … 51 55 } 52 56 57 #endif // THREADS1 58 59 53 60 } -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r2560 r2575 525 525 //TestEvaluation(sc); 526 526 527 #ifdef PERFTIMER 527 528 // fill view cells cache 528 529 mNodeTimer.Entry(); 530 #endif 529 531 530 532 const BvhTraversalData &tData = sc.mParentData; … … 634 636 UpdateViewCells(sc); 635 637 638 #ifdef PERFTIMER 636 639 mNodeTimer.Exit(); 637 640 #endif 641 638 642 // return the new interior node 639 643 return node; … … 647 651 ) 648 652 { 653 #ifdef PERFTIMER 649 654 mSubdivTimer.Entry(); 650 655 #endif 656 651 657 BvhSubdivisionCandidate *sc = 652 658 static_cast<BvhSubdivisionCandidate *>(splitCandidate); … … 718 724 } 719 725 726 #ifdef PERFTIMER 720 727 mSubdivTimer.Exit(); 721 728 #endif 729 722 730 return currentNode; 723 731 } … … 780 788 const bool preprocessViewCells) 781 789 { 782 mPlaneTimer.Entry(); 790 #ifdef PERFTIMER 791 mPlaneTimer.Entry(); 792 #endif 783 793 784 794 const BvhTraversalData &tData = splitCandidate.mParentData; … … 824 834 } 825 835 836 #ifdef PERFTIMER 826 837 mPlaneTimer.Exit(); 827 838 #endif 828 839 829 840 /////////////////// 830 841 842 #ifdef PERFTIMER 831 843 mEvalTimer.Entry(); 832 844 #endif 845 833 846 // mark view cells according to what part of the split they see 834 847 // and compute volume … … 984 997 #endif 985 998 999 #ifdef PERFTIMER 986 1000 mEvalTimer.Exit(); 1001 #endif 987 1002 } 988 1003 … … 1676 1691 const int axis) 1677 1692 { 1693 #ifdef PERFTIMER 1678 1694 mSortTimer.Entry(); 1679 1695 #endif 1680 1696 //-- insert object queries 1681 1697 ObjectContainer *objects = mUseGlobalSorting ? … … 1684 1700 CreateLocalSubdivisionCandidates(*objects, &mSubdivisionCandidates, !mUseGlobalSorting, axis); 1685 1701 1702 #ifdef PERFTIMER 1686 1703 mSortTimer.Exit(); 1704 #endif 1687 1705 } 1688 1706 … … 1840 1858 bool useVisibilityBasedHeuristics) 1841 1859 { 1860 #ifdef PERFTIMER 1842 1861 mSplitTimer.Entry(); 1843 1862 #endif 1863 1844 1864 if (mIsInitialSubdivision) 1845 1865 { … … 1925 1945 backObjects = nBackObjects[bestAxis]; 1926 1946 1947 #ifdef PERFTIMER 1927 1948 mSplitTimer.Exit(); 1928 1949 #endif 1950 1929 1951 //cout << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 1930 1952 return nCostRatio[bestAxis]; … … 2276 2298 //-- use view cells cache 2277 2299 2300 #ifdef PERFTIMER 2278 2301 mCollectTimer.Entry(); 2279 2302 #endif 2303 2280 2304 ViewCellContainer *objViewCells = obj->GetOrCreateViewCells(); 2281 2305 … … 2308 2332 } 2309 2333 2334 #ifdef PERFTIMER 2310 2335 mCollectTimer.Exit(); 2311 2336 #endif 2312 2337 return (int)objViewCells->size(); 2313 2338 } … … 2320 2345 const bool onlyUnmailedRays) 2321 2346 { 2347 #ifdef PERFTIMER 2322 2348 mCollectTimer.Entry(); 2349 #endif 2323 2350 VssRayContainer::const_iterator rit, rit_end = obj->GetOrCreateRays()->end(); 2324 2351 … … 2362 2389 } 2363 2390 2391 #ifdef PERFTIMER 2364 2392 mCollectTimer.Exit(); 2393 #endif 2365 2394 return numRays; 2366 2395 } … … 2436 2465 const bool onlyUnmailedRays) 2437 2466 { 2467 #ifdef PERFTIMER 2438 2468 mCollectTimer.Entry(); 2469 #endif 2439 2470 VssRayContainer::const_iterator rit, rit_end = obj->GetOrCreateRays()->end(); 2440 2471 … … 2478 2509 } 2479 2510 2511 #ifdef PERFTIMER 2480 2512 mCollectTimer.Exit(); 2513 #endif 2481 2514 return numRays; 2482 2515 } -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r2350 r2575 14 14 #include "IntersectableWrapper.h" 15 15 #include "HierarchyManager.h" 16 17 #ifdef PERFTIMER 16 18 #include "Timer/PerfTimer.h" 17 19 #endif // PERFTIMER 18 20 19 21 namespace GtpVisibilityPreprocessor { … … 213 215 214 216 int CastRay(Ray &ray) { return 0; } 217 int CastSimpleRay(const SimpleRay &ray) { return 0;} 218 int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;} 215 219 216 220 bool IsConvex() const { return true; } … … 677 681 void CreateUniqueObjectIds(); 678 682 683 #ifdef PERFTIMER 679 684 PerfTimer mNodeTimer; 680 685 PerfTimer mSubdivTimer; … … 684 689 PerfTimer mSortTimer; 685 690 PerfTimer mCollectTimer; 691 #endif 686 692 687 693 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp
r2176 r2575 5 5 #include <IL/ilu.h> 6 6 #include <IL/ilut.h> 7 #include <cassert> 7 8 8 9 #include "Camera.h" 9 10 #include "Ray.h" 11 #include "SimpleRay.h" 10 12 #include "KdTree.h" 11 13 #include "Mesh.h" 12 14 #include "Exporter.h" 13 15 #include "SceneGraph.h" 16 #include "Preprocessor.h" 17 #include "RayCaster.h" 18 19 #ifdef USE_HAVRAN_RAYCASTER 20 //#include "timer.h" 21 #include "raypack.h" 22 #endif 14 23 15 24 using namespace std; … … 36 45 bool 37 46 Camera::SnapImage(string filename, 38 39 40 47 KdTree *tree, 48 SceneGraph *sceneGraph 49 ) 41 50 { 42 51 int x; … … 167 176 } 168 177 169 } 178 179 void 180 Camera::SetupRay(SimpleRay &ray, const int x, const int y) 181 { 182 Vector3 xv = mRight*((x - mWidth/2)/(float)mWidth); 183 Vector3 yv = mUp*((y - mHeight/2)/(float)mHeight); 184 Vector3 target = xv + yv + mDirection; 185 Vector3 dir = target - mPosition; 186 dir.Normalize(); 187 188 ray.Set(mPosition, dir, 0, 189 1.0f, ~(SimpleRay::F_BIDIRECTIONAL)); 190 } 191 192 bool 193 Camera::SnapImage(string filename, 194 RayCaster *raycaster, 195 AxisAlignedBox3 &bbox, 196 SceneGraph *sceneGraph 197 ) 198 { 199 int x; 200 int y; 201 202 bool exportRays = false; 203 204 205 InitDevIl(); 206 int components = 4; 207 float *buffer = new float[components*mWidth*mHeight]; 208 assert(buffer); 209 float *pbuffer = buffer; 210 // - components*mWidth; 211 212 vector<Ray *> rays; 213 214 long t1 = GetTime(); 215 216 SimpleRay ray; 217 VssRayContainer vssRays; 218 219 //CTimer timer; 220 //timer.Start(); 221 222 for (y = 0; y < mHeight; y++) { 223 cout<<"+"; 224 for (x = 0; x < mWidth; x++) { 225 SetupRay(ray, mWidth - (x + 1), mHeight - (y + 1)); 226 227 bool debug = true; 228 // (y == mHeight/2) && (x== mWidth/3); 229 // MeshDebug = debug; 230 231 232 int res = raycaster->CastRay(ray, 233 vssRays, 234 bbox, 235 false, // castDoubleRay, 236 false); // pruneInvalidRays 237 238 if (res) { 239 Vector3 normal = raycaster->intersect.mNormal; 240 float v = 241 ray.mDirection.x * normal.x + 242 ray.mDirection.y * normal.y + 243 ray.mDirection.z * normal.z; 244 v *= 1.0f; 245 pbuffer[0] = v; 246 pbuffer[1] = v; 247 pbuffer[2] = v; 248 pbuffer[3] = 1.0f; 249 } 250 else { 251 pbuffer[0] = 0.0; 252 pbuffer[1] = 0.0; 253 pbuffer[2] = 0.0; 254 pbuffer[3] = 1.0f; 255 } 256 pbuffer+=components; 257 258 if (debug) { 259 Ray *nray = new Ray(ray.mOrigin, ray.mDirection, 260 Ray::LOCAL_RAY); 261 rays.push_back(nray); 262 } 263 } 264 // pbuffer-=2*components*mWidth; 265 } // for y 266 267 //timer.Stop(); 268 269 long t2 = GetTime(); 270 cout<<"\n#RAY_CAST_TIME = "; 271 cout << TimeDiff(t1, t2)<<" [mikrosec]\n"; 272 273 cout<<"Saving image"<<endl; 274 275 ilRegisterType(IL_FLOAT); 276 ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 277 ilSaveImage((char *const)filename.c_str()); 278 delete buffer; 279 280 cout<<"done."<<endl<<flush; 281 282 return true; 283 } 284 285 bool 286 Camera::SnapImagePacket(string filename, 287 RayCaster *raycaster, 288 AxisAlignedBox3 &bbox, 289 SceneGraph *sceneGraph 290 ) 291 { 292 #ifdef USE_HAVRAN_RAYCASTER 293 294 int x; 295 int y; 296 297 bool exportRays = false; 298 299 300 InitDevIl(); 301 int components = 4; 302 float *buffer = new float[components*mWidth*mHeight]; 303 assert(buffer); 304 float *pbuffer = buffer; 305 // - components*mWidth; 306 307 vector<Ray *> rays; 308 309 long t1 = GetTime(); 310 311 SimpleRay ray; 312 VssRayContainer vssRays; 313 314 //CTimer timer; 315 //timer.Start(); 316 317 RayPacket2x2 rp; 318 for (y = 0; y < mHeight-1; y+=2) { 319 float *pppbuffer = pbuffer; 320 cout<<"+"; 321 for (x = 0; x < mWidth-1; x+=2) { 322 int i = 0; 323 for (int yi = 0; yi < 2; yi++) { 324 for (int xi = 0; xi < 2; xi++) { 325 SetupRay(ray, mWidth - (x+xi + 1), mHeight - (y+yi + 1)); 326 rp.SetLoc(i, ray.mOrigin); 327 rp.SetDir(i, ray.mDirection); 328 i++; 329 } // for xi 330 } // for yi 331 332 raycaster->CastRaysPacket2x2(rp, false, false); 333 334 i = 0; 335 float *ppbuffer = pbuffer; 336 for (int yi = 0; yi < 2; yi++) { 337 for (int xi = 0; xi < 2; xi++) { 338 Intersectable* res = rp.GetObject(i); 339 if (res) { 340 pbuffer[0] = 1.0f; 341 pbuffer[1] = 1.0f; 342 pbuffer[2] = 1.0f; 343 pbuffer[3] = 1.0f; 344 } 345 else { 346 pbuffer[0] = 0.0; 347 pbuffer[1] = 0.0; 348 pbuffer[2] = 0.0; 349 pbuffer[3] = 1.0f; 350 } 351 i++; 352 ppbuffer += components; 353 } // xi 354 ppbuffer += components * (mWidth-2); 355 } // yi 356 357 pbuffer = ppbuffer + 2 * components; 358 } // for x 359 pbuffer = pppbuffer + mWidth * 2 * components; 360 pppbuffer = pbuffer; // for the next time; 361 } // for y 362 363 //timer.Stop(); 364 365 long t2 = GetTime(); 366 cout<<"\n#RAY_CAST_TIME = "; 367 cout << TimeDiff(t1, t2)<<" [mikrosec]\n"; 368 369 cout<<"Saving image"<<endl; 370 371 ilRegisterType(IL_FLOAT); 372 ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 373 ilSaveImage((char *const)filename.c_str()); 374 delete buffer; 375 #endif 376 cout<<"done."<<endl<<flush; 377 378 return true; 379 } 380 381 382 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Camera.h
r2176 r2575 9 9 class KdTree; 10 10 class SceneGraph; 11 11 class RayCaster; 12 12 13 13 class Camera … … 30 30 mFovy = 90.0f*(float)M_PI/180.0f; 31 31 } 32 33 Camera(int width, int height) { 34 mWidth = width; 35 mHeight = height; 36 mFovy = 90.0f*(float)M_PI/180.0f; 37 } 38 32 39 33 40 void Precompute() { … … 46 53 } 47 54 48 55 void SetDirection(const Vector3 &dir) { 49 56 mDirection = dir; 50 57 Precompute(); … … 53 60 void LookInBox(const AxisAlignedBox3 &box) 54 61 { 55 mDirection = Vector3(0,0,1); 62 mDirection = Vector3(0,0,1); 56 63 mPosition = box.Center(); 57 64 Precompute(); … … 67 74 68 75 bool 69 70 71 72 76 SnapImage(std::string filename, 77 KdTree *tree, 78 SceneGraph *sceneGraph 79 ); 73 80 81 bool 82 SnapImage(std::string filename, 83 RayCaster *raycaster, 84 AxisAlignedBox3 &bbox, 85 SceneGraph *sceneGraph 86 ); 87 88 bool 89 SnapImagePacket(std::string filename, 90 RayCaster *raycaster, 91 AxisAlignedBox3 &bbox, 92 SceneGraph *sceneGraph 93 ); 94 74 95 void SetupRay(Ray &ray, const int x, const int y); 75 96 97 void SetupRay(SimpleRay &ray, const int x, const int y); 76 98 }; 77 99 -
GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp
r2560 r2575 1 1 2 #include "SamplingStrategy.h" 2 3 #include "Intersectable.h" … … 5 6 #include "ViewCellsManager.h" 6 7 #include "Preprocessor.h" 8 #ifdef PERFTIMER 7 9 #include "Timer/PerfTimer.h" 8 10 #endif 9 11 10 12 #ifdef GTP_INTERNAL … … 12 14 #endif 13 15 16 17 #ifdef PERFTIMER 14 18 PerfTimer sFilterTimer; 15 19 #endif 16 20 17 21 namespace GtpVisibilityPreprocessor { … … 63 67 ObjectPvs filteredPvs; 64 68 69 70 #ifdef PERFTIMER 65 71 sFilterTimer.Entry(); 66 72 #endif 73 67 74 PvsFilterStatistics pvsStats = mPreprocessor. 68 75 mViewCellsManager->ApplyFilter2(vc, … … 71 78 filteredPvs); 72 79 80 #ifdef PERFTIMER 73 81 sFilterTimer.Exit(); 74 82 #endif 83 75 84 //mDifferencePvs.Clear(false); 76 85 //mDifferencePvs.Reserve(filteredPvs.GetSize()); -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r2542 r2575 519 519 bool 520 520 Environment::GetStringValue(const char *name, 521 522 521 char *value, 522 const bool isFatal) const 523 523 { 524 524 int i = FindOption(name, isFatal); … … 538 538 return true; 539 539 } 540 541 bool 542 Environment::GetStringValue(const char *name, 543 string &stringVariable, 544 const bool isFatal) const 545 { 546 int i = FindOption(name, isFatal); 547 548 if (i<0) 549 return false; 550 551 552 if (options[i].value != NULL) { 553 // option was not read, so use the default 554 stringVariable = options[i].value; 555 } 556 else { 557 // option was explicitly specified 558 stringVariable = options[i].defaultValue; 559 } 560 return true; 561 } 562 540 563 541 564 void … … 1069 1092 numParams = 0; 1070 1093 params = NULL; 1071 maxOptions = 500;1094 maxOptions = 600; 1072 1095 1073 1096 … … 2846 2869 "true"); 2847 2870 2848 ///////////////////////////////////////////////////////////////// 2849 2871 ///////////////////////////////////////////////////////////////// 2872 // By Vlastimil Havran 2873 RegisterOption("BSP.splitclip", optBool, 2874 "kd_splitclip=", "false"); 2875 RegisterOption("BSP.emptyCut", optBool, 2876 "kd_emptycut=", "true"); 2877 RegisterOption("BSP.termCrit", optString, 2878 "kd_termcrit=", "auto"); 2879 RegisterOption("BSP.maxDepthAllowed", optInt, 2880 "kd_maxDepth=", "16"); 2881 RegisterOption("BSP.maxEmptyCutDepth", optInt, 2882 "kd_maxEmptyCutDepth=", "4"); 2883 RegisterOption("BSP.absMaxAllowedDepth", optInt, 2884 "kd_absMaxAllowedDepth=", "20"); 2885 RegisterOption("BSP.maxListLength", optInt, 2886 "kd_maxListLength=", "16"); 2887 RegisterOption("BSP.useRadixSort", optBool, 2888 "kd_useRadixSort=", "false"); 2889 RegisterOption("BSP.printCuts", optBool, 2890 "kd_printCuts=", "false"); 2891 RegisterOption("BSP.algAutoTermination", optInt, 2892 "kd_algAutoTermination=", "0"); 2893 RegisterOption("BSP.axisSelectionAlg", optInt, 2894 "kd_axisSelectAlg=", "0"); 2895 2896 RegisterOption("BSP.decisionCost", optFloat, 2897 "kd_decCost=", "0.3"); 2898 RegisterOption("BSP.intersectionCost", optFloat, 2899 "kd_intersectCost=", "0.9"); 2900 RegisterOption("BSP.traversalCost", optFloat, 2901 "kd_travCost=", "0.2"); 2902 RegisterOption("BSP.biasFreeCuts", optFloat, 2903 "kd_biasFreeCuts=", "0.9"); 2904 2905 RegisterOption("BSP.minBoxes.use", optBool, 2906 "kd_minBoxesUse=", "false"); 2907 RegisterOption("BSP.minBoxes.tight", optBool, 2908 "kd_minBoxesTight=", "false"); 2909 RegisterOption("BSP.minBoxes.minObjects", optInt, 2910 "kd_minBoxesMinObjects=", "10"); 2911 RegisterOption("BSP.minBoxes.minDepthDistance", optInt, 2912 "kd_minBoxesMinDist=", "3"); 2913 RegisterOption("BSP.minBoxes.minSA2ratio", optFloat, 2914 "kd_minBoxesSA2ratio=", "1.0"); 2915 2916 // The object used for testing 2917 RegisterOption("Rays.file", 2918 optString, 2919 "rays_filename=", 2920 "data/fileRays_arena.txt"); 2921 RegisterOption("Rays.cnt", 2922 optInt, 2923 "rays_cnt=", "100000"); 2924 2925 RegisterOption("TestDoubleRays", optBool, 2926 "test_doublrays=", "false"); 2927 2928 ///////////////////////////////////////////////////////////////// 2850 2929 } 2851 2930 -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.h
r2176 r2575 17 17 18 18 #include "common.h" 19 #include <cstring> 20 19 21 20 22 namespace GtpVisibilityPreprocessor { 21 23 22 24 class Vector3; 23 24 25 25 26 /// Enumeration type used to distinguish the type of the environment variable … … 314 315 /// returns named option as a character string. 315 316 bool GetStringValue(const char *name, 316 char *value, 317 const bool isFatal = false) const; 317 char *value, 318 const bool isFatal = false) const; 319 320 bool GetStringValue(const char *name, 321 std::string &stringVariable, 322 const bool isFatal = false) const; 318 323 319 324 //@} -
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
r2394 r2575 8 8 #include "Polygon3.h" 9 9 #include "TraversalTree.h" 10 #include "Material.h" 10 11 11 12 … … 71 72 else 72 73 { 73 74 SetForcedMaterial(RandomMaterial()); 74 75 } 75 76 if (0) ExportGeometry(leaf->mObjects); -
GTP/trunk/Lib/Vis/Preprocessing/src/FromPointVisibilityTree.h
r1006 r2575 1 1 #ifndef _FromPointVisibilityTree_H__ 2 2 #define _FromPointVisibilityTree_H__ 3 4 #include <stack> 5 #include <fstream> 3 6 4 7 #include "Mesh.h" 5 8 #include "Containers.h" 6 9 #include "Polygon3.h" 7 #include <stack>8 10 #include "Statistics.h" 9 11 #include "VssRay.h" … … 256 258 */ 257 259 int CastRay(Ray &ray); 260 int CastSimpleRay(const SimpleRay &ray) { return 0;} 261 int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;} 258 262 259 263 /// bsp tree construction types … … 329 333 /** Writes tree to output stream 330 334 */ 331 bool Export(ofstream &stream);335 bool Export(std::ofstream &stream); 332 336 333 337 /** Casts beam, i.e. a 5D frustum of rays, into tree. … … 690 694 @note: should be implemented as visitor 691 695 */ 692 void ExportNode(BspNode *node,ofstream &stream);696 void ExportNode(BspNode *node, std::ofstream &stream); 693 697 694 698 /** Returns estimated memory usage of tree. … … 782 786 int mMaxViewCells; 783 787 784 788 std::ofstream mSubdivisionStats; 785 789 786 790 // if rays should be stored in leaves … … 812 816 //int mSplits; 813 817 /// subdivision stats output file 814 818 std::ofstream mSubdivsionStats; 815 819 /// if random split axis should be used 816 820 bool mUseRandomAxis; -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2572 r2575 5 5 #include "ViewCellsManager.h" 6 6 #include "SceneGraph.h" 7 #include "View cell.h"7 #include "ViewCell.h" 8 8 #include "Beam.h" 9 9 #include "KdTree.h" … … 126 126 void GlRenderer::RenderTriangle(TriangleIntersectable *object) 127 127 { 128 Triangle3 &t = object->GetItem();128 Triangle3 *t = &(object->GetItem()); 129 129 130 130 glBegin(GL_TRIANGLES); 131 Vector3 normal = t .GetNormal();131 Vector3 normal = t->GetNormal(); 132 132 glNormal3f(normal.x, normal.y, normal.z); 133 glVertex3f(t .mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z);134 glVertex3f(t .mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z);135 glVertex3f(t .mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z);133 glVertex3f(t->mVertices[0].x, t->mVertices[0].y, t->mVertices[0].z); 134 glVertex3f(t->mVertices[1].x, t->mVertices[1].y, t->mVertices[1].z); 135 glVertex3f(t->mVertices[2].x, t->mVertices[2].y, t->mVertices[2].z); 136 136 glEnd(); 137 137 } … … 420 420 if ((*oi)->Type() == Intersectable::TRIANGLE_INTERSECTABLE) { 421 421 TriangleIntersectable *object = (TriangleIntersectable *)*oi; 422 Triangle3 &t = object->GetItem();423 424 Vector3 normal = t .GetNormal();422 Triangle3 *t = &(object->GetItem()); 423 424 Vector3 normal = t->GetNormal(); 425 425 glNormal3f(normal.x, normal.y, normal.z); 426 glVertex3f(t .mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z);427 glVertex3f(t .mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z);428 glVertex3f(t .mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z);426 glVertex3f(t->mVertices[0].x, t->mVertices[0].y, t->mVertices[0].z); 427 glVertex3f(t->mVertices[1].x, t->mVertices[1].y, t->mVertices[1].z); 428 glVertex3f(t->mVertices[2].x, t->mVertices[2].y, t->mVertices[2].z); 429 429 430 430 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Halton.cpp
r2227 r2575 1 1 #include "Halton.h" 2 3 #ifdef PERFTIMER 2 4 #include "Timer/PerfTimer.h" 3 5 #endif 4 6 5 7 #define PREGENERATE_HALTON 0 … … 7 9 namespace GtpVisibilityPreprocessor { 8 10 11 12 #ifdef PERFTIMER 9 13 PerfTimer haltonTimer; 10 14 #endif 15 11 16 // global halton generator 12 17 … … 14 19 float Halton2::_invBases[2]; 15 20 16 float Halton<1>::_invBases[1]; 17 float Halton<2>::_invBases[2]; 18 float Halton<3>::_invBases[3]; 19 float Halton<4>::_invBases[4]; 20 float Halton<5>::_invBases[5]; 21 float Halton<6>::_invBases[6]; 21 //float Halton<6>::_invBases[6]; 22 22 23 23 template<int T> float Halton<T>::_invBases[T]; 24 24 25 Halton<1> dummmyHalton1(true); 25 26 Halton<2> dummmyHalton2(true); -
GTP/trunk/Lib/Vis/Preprocessing/src/Halton.h
r2176 r2575 6 6 namespace GtpVisibilityPreprocessor { 7 7 8 9 /** 10 * Assert whether the argument is a prime number. 11 * @param number the number to be checked 12 */ 13 inline bool IsPrime(const int number) { 14 bool isIt = true; 15 for(int i = 2; i < number; i++) { 16 if(number % i == 0) { 17 isIt = false; 18 break; 19 } 20 } 21 if(number == 2) { 22 isIt = false; 23 } 24 return isIt; 25 } 26 27 28 /** 29 * Find the nth prime number. 30 * @param index the ordinal position in the sequence 31 */ 32 inline int FindPrime(const int index) { 33 // if (index < 1) { 34 // cerr<<"FindPrime: The argument must be non-negative."<<endl; 35 // return -1; 36 // } 37 38 const int primes[] = {-1, 1, 3, 5, 7, 11, 13}; 39 if (index <= 6) 40 return primes[index]; 41 42 int prime = 1; 43 int found = 1; 44 while(found != index) { 45 prime += 2; 46 if(IsPrime(prime) == true) { 47 found++; 48 } 49 } 50 return prime; 51 } 52 53 8 54 inline float halton(float baseRec, float prev) { 9 55 // float r = 1 - prev - 1e-10f; … … 82 128 83 129 84 /** 85 * Assert whether the argument is a prime number. 86 * @param number the number to be checked 87 */ 88 inline bool IsPrime(const int number) { 89 bool isIt = true; 90 for(int i = 2; i < number; i++) { 91 if(number % i == 0) { 92 isIt = false; 93 break; 94 } 95 } 96 if(number == 2) { 97 isIt = false; 98 } 99 return isIt; 100 } 101 102 103 /** 104 * Find the nth prime number. 105 * @param index the ordinal position in the sequence 106 */ 107 inline int FindPrime(const int index) { 108 // if (index < 1) { 109 // cerr<<"FindPrime: The argument must be non-negative."<<endl; 110 // return -1; 111 // } 112 113 const int primes[] = {-1, 1, 3, 5, 7, 11, 13}; 114 if (index <= 6) 115 return primes[index]; 116 117 int prime = 1; 118 int found = 1; 119 while(found != index) { 120 prime += 2; 121 if(IsPrime(prime) == true) { 122 found++; 123 } 124 } 125 return prime; 126 } 127 130 128 131 struct HaltonSequence { 129 132 public: -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r2543 r2575 409 409 double sortTime, evalTime, nodeTime, splitTime, subdTime, planeTime, collectTime, viewCellsTime; 410 410 411 #ifdef PERFTIMER 411 412 sortTime = mBvHierarchy->mSortTimer.TotalTime(); 412 413 evalTime = mBvHierarchy->mEvalTimer.TotalTime(); … … 416 417 planeTime = mBvHierarchy->mPlaneTimer.TotalTime(); 417 418 collectTime = mBvHierarchy->mCollectTimer.TotalTime(); 418 419 #endif // #ifdef PERFTIMER 420 419 421 cout << "bvh times" 420 422 << " sort : " << sortTime … … 437 439 << endl; 438 440 441 #ifdef PERFTIMER 439 442 sortTime = mVspTree->mSortTimer.TotalTime(); 440 443 evalTime = mVspTree->mEvalTimer.TotalTime(); … … 444 447 planeTime = mVspTree->mPlaneTimer.TotalTime(); 445 448 viewCellsTime = mVspTree->mViewCellsTimer.TotalTime(); 446 449 #endif 450 447 451 cout << "vsp times" 448 452 << " sort : " << sortTime -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r2543 r2575 536 536 protected: 537 537 538 friend VspTree;539 friend OspTree;540 friend BvHierarchy;541 friend ViewCellsParseHandlers;538 friend class VspTree; 539 friend class OspTree; 540 friend class BvHierarchy; 541 friend class ViewCellsParseHandlers; 542 542 543 543 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r2574 r2575 14 14 15 15 FILE *fileOut = 0; 16 bool saveRays = true;17 16 bool saveRays = false; 17 const int saveRaysStart = 3000000; 18 18 int cntSavedRaysFLUSH = 0; 19 19 unsigned long int cntSavedRays = 0; 20 20 const int intSavedLIMIT = 1024; 21 21 22 void 22 23 InitSaving() … … 33 34 fclose(fileOut); 34 35 } 35 36 37 36 38 37 IntelRayCaster::IntelRayCaster(const Preprocessor &preprocessor, -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
r2105 r2575 22 22 23 23 int InternalRayCaster::CastRay(const SimpleRay &simpleRay, 24 25 26 27 24 VssRayContainer &vssRays, 25 const AxisAlignedBox3 &box, 26 const bool castDoubleRay, 27 const bool pruneInvalidRays) 28 28 { 29 29 if (simpleRay.mType == Ray::GLOBAL_RAY) 30 30 return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays); 31 31 32 32 //cout << "internal ray" << endl; … … 51 51 52 52 if (mPreprocessor.mKdTree->CastRay(ray)) { 53 54 55 56 53 hitA.mObject = ray.intersections[0].mObject; 54 hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 55 hitA.mNormal = ray.intersections[0].mNormal; 56 // cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 57 57 } 58 58 … … 61 61 62 62 if (castDoubleRay && mPreprocessor.mKdTree->CastRay(ray)) { 63 64 65 63 hitB.mObject = ray.intersections[0].mObject; 64 hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 65 hitB.mNormal = ray.intersections[0].mNormal; 66 66 } 67 67 68 68 return ProcessRay( 69 70 71 72 73 74 75 76 69 simpleRay, 70 hitA, 71 hitB, 72 vssRays, 73 box, 74 castDoubleRay, 75 pruneInvalidRays 76 ); 77 77 } 78 78 … … 80 80 int 81 81 InternalRayCaster::CastGlobalRay(const SimpleRay &simpleRay, 82 83 84 85 82 VssRayContainer &vssRays, 83 const AxisAlignedBox3 &box, 84 const bool pruneInvalidRays 85 ) 86 86 { 87 87 static Ray ray; … … 103 103 104 104 if (mPreprocessor.mKdTree->CastRay(ray)) { 105 // sort intersections 106 ray.SortIntersections(); 107 // cout<<"I="<<ray.intersections.size()<<endl; 108 109 110 Ray::Intersection &hit = ray.intersections[0]; 111 112 if (DotProd(hit.mNormal, ray.GetDir()) < 0) { 113 // cout<<"F:"<<tmin<<" "<<hit.mT<<endl; 114 // insert intial segment 105 // sort intersections 106 ray.SortIntersections(); 107 // cout<<"I="<<ray.intersections.size()<<endl; 108 109 110 Ray::Intersection &hit = ray.intersections[0]; 111 112 if (DotProd(hit.mNormal, ray.GetDir()) < 0) { 113 // cout<<"F:"<<tmin<<" "<<hit.mT<<endl; 114 // insert intial segment 115 vssRay = new VssRay( 116 ray.Extrap(tmin), 117 ray.Extrap(hit.mT), 118 NULL, 119 hit.mObject, 120 mPreprocessor.mPass, 121 1.0f //simpleRay.mPdf 122 ); 123 124 vssRay->mFlags |= VssRay::Valid; 125 vssRay->mDistribution = simpleRay.mDistribution; 126 vssRays.push_back(vssRay); 127 ++hits; 128 } 129 130 hit = ray.intersections[ray.intersections.size()-1]; 131 if (DotProd(hit.mNormal, ray.GetDir()) > 0) { 132 // cout<<"L:"<<tmax<<" "<<hit.mT<<endl; 133 134 // insert termination segment 135 vssRay = new VssRay( 136 ray.Extrap(tmax), 137 ray.Extrap(hit.mT), 138 NULL, 139 hit.mObject, 140 mPreprocessor.mPass, 141 1.0f //simpleRay.mPdf 142 ); 143 vssRay->mFlags |= VssRay::Valid; 144 vssRay->mDistribution = simpleRay.mDistribution; 145 vssRays.push_back(vssRay); 146 ++hits; 147 } 148 149 // insert the rest of segments 150 for (int i=0; i < ray.intersections.size() - 1; i++) { 151 Ray::Intersection &hitA = ray.intersections[i]; 152 Ray::Intersection &hitB = ray.intersections[i + 1]; 153 if (hitB.mT - hitA.mT > Limits::Small) { 154 if (DotProd(hitA.mNormal, ray.GetDir()) > 0 && 155 DotProd(hitB.mNormal, ray.GetDir()) < 0 156 ) { 157 115 158 vssRay = new VssRay( 116 ray.Extrap(tmin), 117 ray.Extrap(hit.mT), 118 NULL, 119 hit.mObject, 120 mPreprocessor.mPass, 121 1.0f //simpleRay.mPdf 122 ); 123 159 ray.Extrap(hitA.mT), 160 ray.Extrap(hitB.mT), 161 hitA.mObject, 162 hitB.mObject, 163 mPreprocessor.mPass, 164 1.0f //simpleRay.mPdf 165 ); 166 vssRay->mFlags |= VssRay::Valid; 167 vssRay->mDistribution = simpleRay.mDistribution; 168 vssRays.push_back(vssRay); 169 ++hits; 170 171 vssRay = new VssRay( 172 ray.Extrap(hitB.mT), 173 ray.Extrap(hitA.mT), 174 hitB.mObject, 175 hitA.mObject, 176 mPreprocessor.mPass, 177 1.0f //simpleRay.mPdf 178 ); 179 124 180 vssRay->mFlags |= VssRay::Valid; 125 181 vssRay->mDistribution = simpleRay.mDistribution; … … 127 183 ++hits; 128 184 } 129 130 hit = ray.intersections[ray.intersections.size()-1]; 131 if (DotProd(hit.mNormal, ray.GetDir()) > 0) { 132 // cout<<"L:"<<tmax<<" "<<hit.mT<<endl; 133 134 // insert termination segment 135 vssRay = new VssRay( 136 ray.Extrap(tmax), 137 ray.Extrap(hit.mT), 138 NULL, 139 hit.mObject, 140 mPreprocessor.mPass, 141 1.0f //simpleRay.mPdf 142 ); 143 vssRay->mFlags |= VssRay::Valid; 144 vssRay->mDistribution = simpleRay.mDistribution; 145 vssRays.push_back(vssRay); 146 ++hits; 147 } 148 149 // insert the rest of segments 150 for (int i=0; i < ray.intersections.size() - 1; i++) { 151 Ray::Intersection &hitA = ray.intersections[i]; 152 Ray::Intersection &hitB = ray.intersections[i + 1]; 153 if (hitB.mT - hitA.mT > Limits::Small) { 154 if (DotProd(hitA.mNormal, ray.GetDir()) > 0 && 155 DotProd(hitB.mNormal, ray.GetDir()) < 0 156 ) { 157 158 vssRay = new VssRay( 159 ray.Extrap(hitA.mT), 160 ray.Extrap(hitB.mT), 161 hitA.mObject, 162 hitB.mObject, 163 mPreprocessor.mPass, 164 1.0f //simpleRay.mPdf 165 ); 166 vssRay->mFlags |= VssRay::Valid; 167 vssRay->mDistribution = simpleRay.mDistribution; 168 vssRays.push_back(vssRay); 169 ++hits; 170 171 vssRay = new VssRay( 172 ray.Extrap(hitB.mT), 173 ray.Extrap(hitA.mT), 174 hitB.mObject, 175 hitA.mObject, 176 mPreprocessor.mPass, 177 1.0f //simpleRay.mPdf 178 ); 179 180 vssRay->mFlags |= VssRay::Valid; 181 vssRay->mDistribution = simpleRay.mDistribution; 182 vssRays.push_back(vssRay); 183 ++hits; 184 } 185 } 186 } 185 } 186 } 187 187 } 188 188 … … 192 192 193 193 void InternalRayCaster::CastRays16(SimpleRayContainer &rays, 194 195 196 197 194 VssRayContainer &vssRays, 195 const AxisAlignedBox3 &sbox, 196 const bool castDoubleRays, 197 const bool pruneInvalidRays) 198 198 { 199 199 #if DEBUG_RAYCAST 200 200 Debug << "C16 " << flush; 201 201 #endif 202 203 204 205 206 207 208 209 210 202 203 SimpleRayContainer::const_iterator sit, sit_end = rays.end(); 204 205 // no acceleration for ray bundles implemented right now 206 for (sit = rays.begin(); sit != sit_end; ++ sit) 207 { 208 CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays); 209 } 210 211 211 #if DEBUG_RAYCAST 212 212 Debug<<"C16F\n"<<flush; -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h
r2176 r2575 28 28 { 29 29 public: 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 30 /** Default constructor initialising e.g., KD tree 31 */ 32 InternalRayCaster(const Preprocessor &preprocessor); 33 virtual ~InternalRayCaster(); 34 35 int Type() const { return INTERNAL_RAYCASTER; } 36 37 virtual int CastRay( 38 const SimpleRay &simpleRay, 39 VssRayContainer &vssRays, 40 const AxisAlignedBox3 &box, 41 const bool castDoubleRay, 42 const bool pruneInvalidRays = true 43 ); 44 45 virtual void CastRays16(SimpleRayContainer &rays, 46 VssRayContainer &vssRays, 47 const AxisAlignedBox3 &sbox, 48 const bool castDoubleRay, 49 const bool pruneInvalidRays = true 50 ); 51 52 virtual int 53 CastGlobalRay( 54 const SimpleRay &simpleRay, 55 VssRayContainer &vssRays, 56 const AxisAlignedBox3 &box, 57 const bool pruneInvalidRays 58 ); 59 59 60 60 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.cpp
r2543 r2575 1 1 #include "Intersectable.h" 2 #include "SimpleRay.h" 3 //#include "ktbconf.h" 2 4 3 5 using namespace std; 4 6 7 #if _WIN32 8 #define ALIGN16 __declspec(align(16)) 9 #else 10 ALIGN16 GALIGN16 11 #endif 5 12 6 13 namespace GtpVisibilityPreprocessor { 7 14 15 16 // This is the result of computing intersection 17 // static data member 18 ALIGN16 IntersectionStr 19 SimpleRay::IntersectionRes[32]; 8 20 9 21 Intersectable::Intersectable(): … … 16 28 #endif 17 29 {} 30 18 31 19 32 -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r2543 r2575 21 21 struct FaceParentInfo 22 22 { 23 24 25 26 27 28 29 30 23 /// intersectable 24 Intersectable *mObject; 25 /// face index 26 int mFaceIndex; 27 28 FaceParentInfo(Intersectable *obj, const int fi): 29 mObject(obj), mFaceIndex(fi) 30 {} 31 31 }; 32 32 … … 89 89 virtual AxisAlignedBox3 GetBox() const = 0; 90 90 virtual int CastRay(Ray &ray) = 0; 91 virtual int CastSimpleRay(const SimpleRay &ray) = 0; 92 virtual int CastSimpleRay(const SimpleRay &ray, int indexRay) = 0; 91 93 92 94 virtual bool IsConvex() const = 0; … … 157 159 BvhLeaf *mBvhLeaf; 158 160 159 160 161 protected: 161 162 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
r2571 r2575 4 4 #include "KdTree.h" 5 5 #include "BvHierarchy.h" 6 #include "SimpleRay.h" 6 7 7 8 … … 11 12 AxisAlignedBox3 TriangleIntersectable::GetBox() const 12 13 { 13 return mItem.GetBoundingBox(); 14 } 15 16 14 return mItem.GetBoundingBox(); 15 } 16 17 18 int 19 TriangleIntersectable::CastSimpleRay(const SimpleRay &ray) 20 { 21 static Vector3 nearestNormal; 22 // std::cout << "To be done - ray triangle intersection\n" << std::endl; 23 const int hitCode = mItem.CastSimpleRay(ray, 24 SimpleRay::IntersectionRes[0].tdist, 25 SimpleRay::IntersectionRes[0].maxt); 26 if (hitCode == Ray::INTERSECTION) { 27 SimpleRay::IntersectionRes[0].intersectable = this; 28 SimpleRay::IntersectionRes[0].maxt = SimpleRay::IntersectionRes[0].tdist; 29 return 1; // intersection occured 30 } 31 return 0; // no intersection 32 } 33 34 int 35 TriangleIntersectable::CastSimpleRay(const SimpleRay &ray, int rayIndex) 36 { 37 const int hitCode = 38 mItem.CastSimpleRay(ray, 39 SimpleRay::IntersectionRes[rayIndex].tdist, 40 SimpleRay::IntersectionRes[rayIndex].maxt); 41 if (hitCode == Ray::INTERSECTION) { 42 SimpleRay::IntersectionRes[rayIndex].intersectable = this; 43 // we copy the closest distance so far - it prunes the search 44 // when more triangles in the same leaf and assures the 45 // correctness. 46 SimpleRay::IntersectionRes[rayIndex].maxt = 47 SimpleRay::IntersectionRes[rayIndex].tdist; 48 return 1; // intersection occured 49 } 50 return 0; // no intersection 51 } 52 53 17 54 int TriangleIntersectable::CastRay(Ray &ray) 18 55 { 19 float nearestT = MAX_FLOAT; 20 float t; 21 Vector3 nearestNormal; 22 23 if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) 24 nearestT = ray.intersections[0].mT; 56 float nearestT = MAX_FLOAT; 57 float t; 58 Vector3 nearestNormal; 59 60 if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) 61 nearestT = ray.intersections[0].mT; 62 63 const int hitCode = mItem.CastRay(ray, t, nearestT, nearestNormal); 64 65 nearestT = t; 66 67 if (hitCode == Ray::INTERSECTION) { 68 if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) { 69 ray.intersections[0] = Ray::Intersection(nearestT, 70 nearestNormal, 71 this, 72 0); 73 } 74 else { 75 ray.intersections.push_back(Ray::Intersection(nearestT, 76 nearestNormal, 77 this, 78 0)); 79 } 80 81 return 1; 82 } 83 84 return 0; 85 } 25 86 26 const int hitCode = mItem.CastRay(ray, t, nearestT, nearestNormal);27 28 nearestT = t;29 30 if (hitCode == Ray::INTERSECTION) {31 if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) {32 ray.intersections[0] = Ray::Intersection(nearestT,33 nearestNormal,34 this,35 0);36 }37 else {38 ray.intersections.push_back(Ray::Intersection(nearestT,39 nearestNormal,40 this,41 0));42 }43 44 return 1;45 }46 47 return 0;48 }49 50 87 51 88 int TriangleIntersectable::NumberOfFaces() const … … 55 92 56 93 57 Vector3 TriangleIntersectable::GetNormal(const int idx) const 58 { 59 return mItem.GetNormal(); 94 Vector3 95 TriangleIntersectable::GetNormal(const int idx) const 96 { 97 return mItem.GetNormal(); 60 98 } 61 99 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
r2569 r2575 40 40 41 41 int CastRay(Ray &ray); 42 int CastSimpleRay(const SimpleRay &ray) { return 0;} 43 int CastSimpleRay(const SimpleRay &ray, int RayIndex) { return 0;} 44 42 45 43 46 bool IsConvex() const; … … 193 196 194 197 int CastRay(Ray &ray); 198 199 int CastSimpleRay(const SimpleRay &ray); 200 int CastSimpleRay(const SimpleRay &ray, int rayIndex); 201 195 202 AxisAlignedBox3 GetBox() const; 196 203 int NumberOfFaces() const; 197 204 Vector3 GetNormal(const int idx) const; 205 Vector3 GetNormal() const { return mItem.GetNormal();} 198 206 199 207 float GetArea() const {return mItem.GetArea();} … … 207 215 208 216 int GetRandomSurfacePoint(const float u, 209 210 217 const float v, 218 Vector3 &point, Vector3 &normal); 211 219 212 220 213 221 int GetRandomVisibleSurfacePoint(Vector3 &point, 214 215 216 222 Vector3 &normal, 223 const Vector3 &viewpoint, 224 const int maxTries); 217 225 218 226 int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); … … 244 252 245 253 // hack 246 ContainerIntersectable::~ContainerIntersectable()254 ~ContainerIntersectable() 247 255 { 248 256 delete mItem; -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r2571 r2575 26 26 inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 27 27 { 28 28 return obj1->mId < obj2->mId; 29 29 } 30 30 … … 33 33 mParent(parent), mMailbox(0), mIntersectable(NULL) 34 34 { 35 36 37 38 35 if (parent) 36 mDepth = parent->mDepth+1; 37 else 38 mDepth = 0; 39 39 } 40 40 … … 42 42 KdInterior::~KdInterior() 43 43 { 44 45 46 44 // recursivly destroy children 45 DEL_PTR(mFront); 46 DEL_PTR(mBack); 47 47 } 48 48 … … 50 50 KdLeaf::~KdLeaf() 51 51 { 52 52 DEL_PTR(mViewCell); 53 53 } 54 54 … … 57 57 { 58 58 mRoot = new KdLeaf(NULL, 0); 59 Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxNodes", mTermMaxNodes); 60 Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxDepth", mTermMaxDepth); 61 Environment::GetSingleton()->GetIntValue("KdTree.Termination.minCost", mTermMinCost); 62 Environment::GetSingleton()->GetFloatValue("KdTree.Termination.maxCostRatio", mMaxCostRatio); 63 Environment::GetSingleton()->GetFloatValue("KdTree.Termination.ct_div_ci", mCt_div_ci); 64 Environment::GetSingleton()->GetFloatValue("KdTree.splitBorder", mSplitBorder); 65 Environment::GetSingleton()->GetFloatValue("KdTree.pvsArea", mKdPvsArea); 66 67 Environment::GetSingleton()->GetBoolValue("KdTree.sahUseFaces", mSahUseFaces); 59 Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxNodes", 60 mTermMaxNodes); 61 Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxDepth", 62 mTermMaxDepth); 63 Environment::GetSingleton()->GetIntValue("KdTree.Termination.minCost", 64 mTermMinCost); 65 Environment::GetSingleton()->GetFloatValue("KdTree.Termination.maxCostRatio", 66 mMaxCostRatio); 67 Environment::GetSingleton()->GetFloatValue("KdTree.Termination.ct_div_ci", 68 mCt_div_ci); 69 Environment::GetSingleton()->GetFloatValue("KdTree.splitBorder", 70 mSplitBorder); 71 Environment::GetSingleton()->GetFloatValue("KdTree.pvsArea", 72 mKdPvsArea); 73 74 Environment::GetSingleton()->GetBoolValue("KdTree.sahUseFaces", 75 mSahUseFaces); 68 76 69 77 char splitType[64]; … … 97 105 KdTree::Construct() 98 106 { 99 100 107 if (!splitCandidates) 101 108 splitCandidates = new vector<SortableEntry *>; … … 158 165 159 166 KdNode *node = SubdivideNode((KdLeaf *) data.mNode, 160 161 162 163 164 165 167 data.mBox, 168 backBox, 169 frontBox 170 ); 171 172 if (result == NULL) 166 173 result = node; 167 174 168 175 if (!node->IsLeaf()) { 169 170 176 KdInterior *interior = (KdInterior *) node; 171 177 // push the children on the stack … … 173 179 tStack.push(TraversalData(interior->mFront, frontBox, data.mDepth+1)); 174 180 175 } else { 181 } 182 else { 176 183 EvaluateLeafStats(data); 177 184 } … … 186 193 KdTree::TerminationCriteriaMet(const KdLeaf *leaf) 187 194 { 188 189 190 191 192 193 194 195 195 const bool criteriaMet = 196 ((int)leaf->mObjects.size() <= mTermMinCost) || 197 (leaf->mDepth >= mTermMaxDepth); 198 199 if (0 && criteriaMet) 200 cerr<<"\n OBJECTS="<<(int)leaf->mObjects.size()<<endl; 201 202 return criteriaMet; 196 203 } 197 204 … … 199 206 int 200 207 KdTree::SelectPlane(KdLeaf *leaf, 201 202 203 208 const AxisAlignedBox3 &box, 209 float &position 210 ) 204 211 { 205 212 int axis = -1; … … 217 224 bool mOnlyDrivingAxis = true; 218 225 219 if (mOnlyDrivingAxis) { 220 axis = box.Size().DrivingAxis(); 221 costRatio = BestCostRatio(leaf, 222 box, 223 axis, 224 position, 225 objectsBack, 226 objectsFront); 227 } else { 228 costRatio = MAX_FLOAT; 229 for (int i=0; i < 3; i++) { 230 float p; 231 float r = BestCostRatio(leaf, 232 box, 233 i, 234 p, 235 objectsBack, 236 objectsFront); 237 if (r < costRatio) { 238 costRatio = r; 239 axis = i; 240 position = p; 241 } 242 } 226 if (mOnlyDrivingAxis) { 227 axis = box.Size().DrivingAxis(); 228 costRatio = BestCostRatio(leaf, 229 box, 230 axis, 231 position, 232 objectsBack, 233 objectsFront); 234 } 235 else { 236 // for all 3 axes 237 costRatio = MAX_FLOAT; 238 for (int i=0; i < 3; i++) { 239 float p; 240 float r = BestCostRatio(leaf, 241 box, 242 i, 243 p, 244 objectsBack, 245 objectsFront); 246 if (r < costRatio) { 247 costRatio = r; 248 axis = i; 249 position = p; 250 } 251 } 243 252 } 244 253 245 254 if (costRatio > mMaxCostRatio) { 246 247 255 //cout<<"Too big cost ratio "<<costRatio<<endl; 256 axis = -1; 248 257 } 249 258 break; … … 254 263 } 255 264 256 KdNode 265 KdNode* 257 266 KdTree::SubdivideNode( 258 267 KdLeaf *leaf, … … 261 270 AxisAlignedBox3 &frontBBox 262 271 ) 263 { 264 272 { 265 273 if (TerminationCriteriaMet(leaf)) 266 274 return leaf; 267 275 268 276 float position; … … 275 283 } 276 284 277 mStat.nodes +=2;285 mStat.nodes += 2; 278 286 mStat.splits[axis]++; 279 287 … … 309 317 } 310 318 311 312 319 KdLeaf *back = new KdLeaf(node, objectsBack); 313 320 KdLeaf *front = new KdLeaf(node, objectsFront); 314 315 321 316 322 // replace a link from node's parent … … 336 342 337 343 338 339 344 if (box.Max(axis) >= position ) 345 { 340 346 front->mObjects.push_back(*mi); 341 342 347 //++ (*mi)->mReferences; 348 } 343 349 344 350 if (box.Min(axis) < position ) 345 351 { 346 352 back->mObjects.push_back(*mi); 347 348 349 353 // matt: no more ref 354 // ++ (*mi)->mReferences; 355 } 350 356 351 357 mStat.objectRefs -= (int)leaf->mObjects.size(); … … 353 359 } 354 360 355 356 357 358 359 360 361 361 // store objects referenced in more than one leaf 362 // for easy access 363 ProcessMultipleRefs(back); 364 ProcessMultipleRefs(front); 365 366 delete leaf; 367 return node; 362 368 } 363 369 … … 365 371 void KdTree::ProcessMultipleRefs(KdLeaf *leaf) const 366 372 { 367 368 369 370 371 372 373 // find objects from multiple kd-leaves 374 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 375 376 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 377 { 378 Intersectable *object = *oit; 373 379 374 // matt: no more ref 375 /*if (object->mReferences > 1) 376 { 377 leaf->mMultipleObjects.push_back(object); 378 }*/ 379 } 380 // matt: no more ref 381 /* 382 if (object->mReferences > 1) { 383 leaf->mMultipleObjects.push_back(object); 384 } 385 */ 386 } 380 387 } 381 388 … … 464 471 void 465 472 KdTree::SortSubdivisionCandidates( 466 467 468 469 { 470 471 472 473 474 475 476 477 478 479 473 KdLeaf *node, 474 const int axis 475 ) 476 { 477 CLEAR_CONTAINER(*splitCandidates); 478 //splitCandidates->clear(); 479 480 int requestedSize = 2*(int)node->mObjects.size(); 481 482 // creates a sorted split candidates array 483 if (splitCandidates->capacity() > 500000 && 484 requestedSize < (int)(splitCandidates->capacity()/10) ) { 485 delete splitCandidates; 486 splitCandidates = new vector<SortableEntry *>; 480 487 } 481 488 … … 487 494 mi++) 488 495 { 489 490 491 492 493 494 496 AxisAlignedBox3 box = (*mi)->GetBox(); 497 498 splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MIN, 499 box.Min(axis), 500 *mi) 501 ); 495 502 496 497 498 499 503 splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, 504 box.Max(axis), 505 *mi) 506 ); 500 507 } 501 508 … … 506 513 float 507 514 KdTree::BestCostRatio( 508 509 510 511 512 513 514 515 KdLeaf *node, 516 const AxisAlignedBox3 &box, 517 const int axis, 518 float &position, 519 int &objectsBack, 520 int &objectsFront 521 ) 515 522 { 516 523 … … 531 538 532 539 if (nodeId < 100) 533 540 costStream.open(filename); 534 541 535 542 #endif … … 577 584 intersectionsRight -= (*ci)->intersectable->IntersectionComplexity(); 578 585 break; 579 } 586 } // switch 580 587 581 588 if ((*ci)->value > minBand && (*ci)->value < maxBand) { … … 587 594 float sum; 588 595 if (mSahUseFaces) 589 596 sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 590 597 else 591 598 sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 592 599 593 600 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; … … 595 602 596 603 #if DEBUG_COST 597 if (nodeId < 100) {604 if (nodeId < 100) { 598 605 float oldCost = mSahUseFaces ? totalIntersections : node->mObjects.size(); 599 606 float newCost = mCt_div_ci + sum/boxArea; 600 607 float ratio = newCost/oldCost; 601 608 costStream<<(*ci)->value<<" "<<ratio<<endl; 602 }609 } 603 610 #endif 604 611 605 612 if (sum < minSum) { 606 607 608 609 610 611 } 612 } 613 } 613 minSum = sum; 614 position = (*ci)->value; 615 616 objectsBack = objectsLeft; 617 objectsFront = objectsRight; 618 } 619 } 620 } // for ci 614 621 615 622 float oldCost = mSahUseFaces ? totalIntersections : node->mObjects.size(); … … 627 634 int 628 635 KdTree::CastRay( 629 630 636 Ray &ray 637 ) 631 638 { 632 639 … … 666 673 667 674 if (entp[axis] <= position) { 668 if (extp[axis] <= position) { 669 node = in->mBack; 670 // cases N1,N2,N3,P5,Z2,Z3 671 continue; 672 } else { 673 // case N4 674 node = in->mBack; 675 farChild = in->mFront; 676 } 675 if (extp[axis] <= position) { 676 node = in->mBack; 677 // cases N1,N2,N3,P5,Z2,Z3 678 continue; 679 } 680 else { 681 // case N4 682 node = in->mBack; 683 farChild = in->mFront; 684 } 677 685 } 678 686 else { 679 if (position <= extp[axis]) { 680 node = in->mFront; 681 // cases P1,P2,P3,N5,Z1 682 continue; 683 } else { 684 node = in->mFront; 685 farChild = in->mBack; 686 // case P4 687 } 688 } 687 if (position <= extp[axis]) { 688 node = in->mFront; 689 // cases P1,P2,P3,N5,Z1 690 continue; 691 } 692 else { 693 node = in->mFront; 694 farChild = in->mBack; 695 // case P4 696 } 697 } 689 698 // $$ modification 3.5.2004 - hints from Kamil Ghais 690 699 // case N4 or P4 … … 693 702 extp = ray.GetLoc() + ray.GetDir()*tdist; 694 703 maxt = tdist; 695 } else { 696 // compute intersection with all objects in this leaf 697 KdLeaf *leaf = (KdLeaf *) node; 698 if (ray.mFlags & Ray::STORE_KDLEAVES) 699 ray.kdLeaves.push_back(leaf); 704 } 705 else { 706 // compute intersection with all objects in this leaf 707 KdLeaf *leaf = (KdLeaf *) node; 708 if (ray.mFlags & Ray::STORE_KDLEAVES) 709 ray.kdLeaves.push_back(leaf); 700 710 701 702 703 704 705 706 707 708 711 ObjectContainer::const_iterator mi; 712 for ( mi = leaf->mObjects.begin(); 713 mi != leaf->mObjects.end(); 714 mi++) { 715 Intersectable *object = *mi; 716 if (!object->Mailed() ) { 717 object->Mail(); 718 if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 709 719 ray.testedObjects.push_back(object); 710 720 711 static int oi=1; 712 if (MeshDebug) 713 cout<<"Object "<<oi++; 714 715 hits += object->CastRay(ray); 716 717 if (MeshDebug) { 718 if (!ray.intersections.empty()) 719 cout<<"nearest t="<<ray.intersections[0].mT<<endl; 720 else 721 cout<<"nearest t=-INF"<<endl; 722 } 723 } 724 } 721 static int oi=1; 722 if (MeshDebug) 723 cout<<"Object "<<oi++; 725 724 726 if (hits && ray.GetType() == Ray::LOCAL_RAY) 727 if (ray.intersections[0].mT <= maxt) 728 break; 725 hits += object->CastRay(ray); 729 726 730 // get the next node from the stack 731 if (tStack.empty()) 732 break; 727 if (MeshDebug) { 728 if (!ray.intersections.empty()) 729 cout<<"nearest t="<<ray.intersections[0].mT<<endl; 730 else 731 cout<<"nearest t=-INF"<<endl; 732 } 733 } 734 } 733 735 734 entp = extp; 735 mint = maxt; 736 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 737 break; 738 739 RayTraversalData &s = tStack.top(); 740 node = s.mNode; 741 extp = s.mExitPoint; 742 maxt = s.mMaxT; 743 tStack.pop(); 744 } 736 if (hits && ray.GetType() == Ray::LOCAL_RAY) 737 if (ray.intersections[0].mT <= maxt) 738 break; 739 740 // get the next node from the stack 741 if (tStack.empty()) 742 break; 743 744 entp = extp; 745 mint = maxt; 746 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 747 break; 748 749 RayTraversalData &s = tStack.top(); 750 node = s.mNode; 751 extp = s.mExitPoint; 752 maxt = s.mMaxT; 753 tStack.pop(); 754 } 745 755 } 746 756 return hits; … … 748 758 749 759 int KdTree::CastLineSegment(const Vector3 &origin, 750 const Vector3 &termination, 751 ViewCellContainer &viewcells) 752 { 753 int hits = 0; 754 755 float mint = 0.0f, maxt = 1.0f; 756 const Vector3 dir = termination - origin; 757 758 stack<RayTraversalData> tStack; 759 760 Intersectable::NewMail(); 761 762 //maxt += Limits::Threshold; 763 764 Vector3 entp = origin; 765 Vector3 extp = termination; 766 767 KdNode *node = mRoot; 768 KdNode *farChild; 769 770 float position; 771 int axis; 772 773 while (1) 760 const Vector3 &termination, 761 ViewCellContainer &viewcells) 762 { 763 int hits = 0; 764 765 float mint = 0.0f, maxt = 1.0f; 766 const Vector3 dir = termination - origin; 767 768 stack<RayTraversalData> tStack; 769 770 Intersectable::NewMail(); 771 772 //maxt += Limits::Threshold; 773 774 Vector3 entp = origin; 775 Vector3 extp = termination; 776 777 KdNode *node = mRoot; 778 KdNode *farChild; 779 780 float position; 781 int axis; 782 783 while (1) 784 { 785 if (!node->IsLeaf()) 786 { 787 KdInterior *in = static_cast<KdInterior *>(node); 788 position = in->mPosition; 789 axis = in->mAxis; 790 791 if (entp[axis] <= position) 792 { 793 if (extp[axis] <= position) 774 794 { 775 if (!node->IsLeaf()) 776 { 777 KdInterior *in = static_cast<KdInterior *>(node); 778 position = in->mPosition; 779 axis = in->mAxis; 780 781 if (entp[axis] <= position) 782 { 783 if (extp[axis] <= position) 784 { 785 node = in->mBack; 786 // cases N1,N2,N3,P5,Z2,Z3 787 continue; 788 } 789 else 790 { 791 // case N4 792 node = in->mBack; 793 farChild = in->mFront; 794 } 795 } 796 else 797 { 798 if (position <= extp[axis]) 799 { 800 node = in->mFront; 801 // cases P1,P2,P3,N5,Z1 802 continue; 803 } 804 else 805 { 806 node = in->mFront; 807 farChild = in->mBack; 808 // case P4 809 } 810 } 811 812 // $$ modification 3.5.2004 - hints from Kamil Ghais 813 // case N4 or P4 814 float tdist = (position - origin[axis]) / dir[axis]; 815 //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 816 extp = origin + dir * tdist; 817 maxt = tdist; 818 } 819 else 820 { 821 // compute intersection with all objects in this leaf 822 KdLeaf *leaf = static_cast<KdLeaf *>(node); 823 824 // add view cell to intersections 825 ViewCell *vc = leaf->mViewCell; 826 827 if (!vc->Mailed()) 828 { 829 vc->Mail(); 830 viewcells.push_back(vc); 831 ++ hits; 832 } 833 834 // get the next node from the stack 835 if (tStack.empty()) 836 break; 837 838 entp = extp; 839 mint = maxt; 840 841 RayTraversalData &s = tStack.top(); 842 node = s.mNode; 843 extp = s.mExitPoint; 844 maxt = s.mMaxT; 845 tStack.pop(); 846 } 847 } 848 849 return hits; 795 node = in->mBack; 796 // cases N1,N2,N3,P5,Z2,Z3 797 continue; 798 } 799 else 800 { 801 // case N4 802 node = in->mBack; 803 farChild = in->mFront; 804 } 805 } 806 else 807 { 808 if (position <= extp[axis]) 809 { 810 node = in->mFront; 811 // cases P1,P2,P3,N5,Z1 812 continue; 813 } 814 else 815 { 816 node = in->mFront; 817 farChild = in->mBack; 818 // case P4 819 } 820 } 821 822 // $$ modification 3.5.2004 - hints from Kamil Ghais 823 // case N4 or P4 824 float tdist = (position - origin[axis]) / dir[axis]; 825 //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 826 extp = origin + dir * tdist; 827 maxt = tdist; 828 } 829 else 830 { 831 // compute intersection with all objects in this leaf 832 KdLeaf *leaf = static_cast<KdLeaf *>(node); 833 834 // add view cell to intersections 835 ViewCell *vc = leaf->mViewCell; 836 837 if (!vc->Mailed()) 838 { 839 vc->Mail(); 840 viewcells.push_back(vc); 841 ++ hits; 842 } 843 844 // get the next node from the stack 845 if (tStack.empty()) 846 break; 847 848 entp = extp; 849 mint = maxt; 850 851 RayTraversalData &s = tStack.top(); 852 node = s.mNode; 853 extp = s.mExitPoint; 854 maxt = s.mMaxT; 855 tStack.pop(); 856 } 857 } 858 return hits; 850 859 } 851 860 852 861 void 853 862 KdTree::CollectKdObjects(const AxisAlignedBox3 &box, 854 855 863 ObjectContainer &objects 864 ) 856 865 { 857 866 stack<KdNode *> nodeStack; … … 862 871 KdNode *node = nodeStack.top(); 863 872 nodeStack.pop(); 864 if (node->IsLeaf() || node->mPvsTermination == 1) { 865 Intersectable *object = GetOrCreateKdIntersectable(node); 866 if (!node->Mailed()) { 867 node->Mail(); 868 objects.push_back(object); 869 } 870 } else { 873 if (node->IsLeaf() || node->mPvsTermination == 1) { 874 Intersectable *object = GetOrCreateKdIntersectable(node); 875 if (!node->Mailed()) { 876 node->Mail(); 877 objects.push_back(object); 878 } 879 } 880 else { 871 881 KdInterior *interior = (KdInterior *)node; 872 882 873 874 875 876 877 878 } 879 } 883 if ( box.Max()[interior->mAxis] > interior->mPosition ) 884 nodeStack.push(interior->mFront); 885 886 if (box.Min()[interior->mAxis] < interior->mPosition) 887 nodeStack.push(interior->mBack); 888 } 889 } // while 880 890 } 881 891 882 892 void 883 893 KdTree::CollectObjects(const AxisAlignedBox3 &box, 884 894 ObjectContainer &objects) 885 895 { 886 896 stack<KdNode *> nodeStack; … … 894 904 KdLeaf *leaf = (KdLeaf *)node; 895 905 for (int j=0; j < leaf->mObjects.size(); j++) { 896 897 898 899 900 906 Intersectable *object = leaf->mObjects[j]; 907 if (!object->Mailed() && Overlap(box, object->GetBox())) { 908 object->Mail(); 909 objects.push_back(object); 910 } 901 911 } 902 912 } else { 903 913 KdInterior *interior = (KdInterior *)node; 904 914 905 906 907 908 909 915 if ( box.Max()[interior->mAxis] > interior->mPosition ) 916 nodeStack.push(interior->mFront); 917 918 if (box.Min()[interior->mAxis] < interior->mPosition) 919 nodeStack.push(interior->mBack); 910 920 } 911 921 } … … 925 935 KdLeaf *leaf = (KdLeaf *)node; 926 936 for (int j=0; j < leaf->mObjects.size(); j++) { 927 928 929 930 931 937 Intersectable *object = leaf->mObjects[j]; 938 if (!object->Mailed()) { 939 object->Mail(); 940 objects.push_back(object); 941 } 932 942 } 933 943 } else { … … 942 952 KdNode * 943 953 KdTree::FindRandomNeighbor(KdNode *n, 944 945 954 bool onlyUnmailed 955 ) 946 956 { 947 957 stack<KdNode *> nodeStack; … … 997 1007 if ( node != n && (!onlyUnmailed || !node->Mailed()) ) 998 1008 neighbors.push_back(node); 999 } else { 1009 } 1010 else { 1000 1011 KdInterior *interior = (KdInterior *)node; 1001 1012 if (interior->mPosition > box.Max(interior->mAxis)) 1002 nodeStack.push(interior->mBack); 1003 else 1004 if (interior->mPosition < box.Min(interior->mAxis)) 1005 nodeStack.push(interior->mFront); 1006 else { 1007 // random decision 1008 nodeStack.push(interior->mBack); 1009 nodeStack.push(interior->mFront); 1010 } 1013 nodeStack.push(interior->mBack); 1014 else { 1015 if (interior->mPosition < box.Min(interior->mAxis)) 1016 nodeStack.push(interior->mFront); 1017 else { 1018 // random decision 1019 nodeStack.push(interior->mBack); 1020 nodeStack.push(interior->mFront); 1021 } 1022 } 1011 1023 } 1012 1024 } … … 1181 1193 void KdTree::ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf) 1182 1194 { 1183 ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 1195 ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 1196 1197 int type = TYPE_LEAF; 1198 int size = (int)leaf->mObjects.size(); 1199 1200 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 1201 stream.write(reinterpret_cast<char *>(&size), sizeof(int)); 1202 1203 for (it = leaf->mObjects.begin(); it != it_end; ++ it) 1204 { 1205 Intersectable *obj = *it; 1206 int id = obj->mId; 1207 1208 //stream.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 1209 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 1210 } 1211 } 1212 1213 1214 KdLeaf *KdTree::ImportBinLeaf(IN_STREAM &stream, 1215 KdInterior *parent, 1216 const ObjectContainer &objects) 1217 { 1218 int leafId = TYPE_LEAF; 1219 int objId = leafId; 1220 int size; 1221 1222 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 1223 KdLeaf *leaf = new KdLeaf(parent, size); 1224 1225 MeshInstance dummyInst(NULL); 1184 1226 1185 int type = TYPE_LEAF; 1186 int size = (int)leaf->mObjects.size(); 1187 1188 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 1189 stream.write(reinterpret_cast<char *>(&size), sizeof(int)); 1190 1191 for (it = leaf->mObjects.begin(); it != it_end; ++ it) 1192 { 1193 Intersectable *obj = *it; 1194 int id = obj->mId; 1195 1196 //stream.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 1197 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 1198 } 1199 } 1200 1201 1202 KdLeaf *KdTree::ImportBinLeaf(IN_STREAM &stream, 1203 KdInterior *parent, 1204 const ObjectContainer &objects) 1205 { 1206 int leafId = TYPE_LEAF; 1207 int objId = leafId; 1208 int size; 1209 1210 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 1211 KdLeaf *leaf = new KdLeaf(parent, size); 1212 1213 MeshInstance dummyInst(NULL); 1214 1215 // read object ids 1216 // note: this can also be done geometrically 1217 for (int i = 0; i < size; ++ i) 1218 { 1219 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 1220 dummyInst.SetId(objId); 1221 1222 ObjectContainer::const_iterator oit = 1223 lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 1224 1225 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 1226 leaf->mObjects.push_back(*oit); 1227 else 1228 Debug << "error: object with id " << objId << " does not exist" << endl; 1229 } 1230 1231 return leaf; 1227 // read object ids 1228 // note: this can also be done geometrically 1229 for (int i = 0; i < size; ++ i) 1230 { 1231 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 1232 dummyInst.SetId(objId); 1233 1234 ObjectContainer::const_iterator oit = 1235 lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 1236 1237 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 1238 leaf->mObjects.push_back(*oit); 1239 else 1240 Debug << "error: object with id " << objId << " does not exist" << endl; 1241 } 1242 1243 return leaf; 1232 1244 } 1233 1245 … … 1319 1331 bool KdTree::ImportBinTree(const string &filename, ObjectContainer &objects) 1320 1332 { 1321 1322 1323 1324 1325 1326 1327 1328 // if (!is_sorted(objects.begin(), objects.end(), ilt))1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1333 // export binary version of mesh 1334 queue<TraversalData> tStack; 1335 IN_STREAM stream(filename.c_str(), IN_BIN_MODE); 1336 1337 if (!stream.is_open()) return false; 1338 1339 // sort objects by their id 1340 // if (!is_sorted(objects.begin(), objects.end(), ilt)) 1341 sort(objects.begin(), objects.end(), ilt); 1342 1343 mBox.Initialize(); 1344 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1345 1346 /////////////////////////// 1347 //-- compute bounding box of object space 1348 1349 for (oit = objects.begin(); oit != oit_end; ++ oit) 1350 { 1351 const AxisAlignedBox3 box = (*oit)->GetBox(); 1352 mBox.Include(box); 1353 } 1354 1355 // hack: we make a new root 1356 DEL_PTR(mRoot); 1357 1358 mRoot = ImportNextNode(stream, NULL, objects); 1359 1360 tStack.push(TraversalData(mRoot, mBox, 0)); 1361 mStat.Reset(); 1362 mStat.nodes = 1; 1363 1364 while(!tStack.empty()) 1365 { 1366 TraversalData tData = tStack.front(); 1367 tStack.pop(); 1368 1369 KdNode *node = tData.mNode; 1370 1371 if (!node->IsLeaf()) 1372 { 1373 mStat.nodes += 2; 1374 1375 //Debug << "i" ; 1376 KdInterior *interior = static_cast<KdInterior *>(node); 1377 interior->mBox = tData.mBox; 1378 1379 KdNode *front = ImportNextNode(stream, interior, objects); 1380 KdNode *back = ImportNextNode(stream, interior, objects); 1381 1382 interior->SetupChildLinks(back, front); 1383 1384 ++ mStat.splits[interior->mAxis]; 1385 1386 // compute new bounding box 1387 AxisAlignedBox3 frontBox, backBox; 1388 1389 tData.mBox.Split(interior->mAxis, 1390 interior->mPosition, 1391 frontBox, 1392 backBox); 1393 1394 tStack.push(TraversalData(front, frontBox, tData.mDepth + 1)); 1395 tStack.push(TraversalData(back, backBox, tData.mDepth + 1)); 1396 } 1397 else 1398 { 1399 EvaluateLeafStats(tData); 1400 //cout << "l"; 1401 } 1402 } 1403 1404 float area = GetBox().SurfaceArea()*mKdPvsArea; 1405 1406 SetPvsTerminationNodes(area); 1407 1408 Debug << mStat << endl; 1409 1410 return true; 1399 1411 } 1400 1412 … … 1403 1415 KdTree::GetOrCreateKdIntersectable(KdNode *node) 1404 1416 { 1405 1406 1417 if (node == NULL) 1418 return NULL; 1407 1419 1408 1420 if (node->mIntersectable == NULL) … … 1415 1427 mKdIntersectables.push_back(kdObj); 1416 1428 kdObj->SetId(id); 1417 1418 1429 #ifdef USE_BIT_PVS 1419 1420 1430 // hack: for kd pvs the kd intersecables are the pvs objects 1431 ObjectPvsIterator::sObjects.push_back(kdObj); 1421 1432 #endif 1422 1423 1424 1433 } 1434 1435 return node->mIntersectable; 1425 1436 } 1426 1437 1427 1438 1428 1439 void 1429 KdTree::SetPvsTerminationNodes( 1430 const float maxArea) 1440 KdTree::SetPvsTerminationNodes(const float maxArea) 1431 1441 { 1432 1442 stack<KdNode *> nodeStack; … … 1440 1450 while (!nodeStack.empty()) { 1441 1451 KdNode *node = nodeStack.top(); 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 } 1457 } 1458 1452 nodeStack.pop(); 1453 1454 node->mPvsTermination = 0; 1455 if (node->IsLeaf() || (GetSurfaceArea(node) <= maxArea) ) { 1456 area += GetSurfaceArea(node); 1457 radius += GetBox(node).Radius(); 1458 nodes++; 1459 node->mPvsTermination = 1; 1460 // create dummy kd intersectable 1461 Intersectable *object = GetOrCreateKdIntersectable(node); 1462 } else { 1463 KdInterior *interior = (KdInterior *)node; 1464 nodeStack.push(interior->mFront); 1465 nodeStack.push(interior->mBack); 1466 } 1467 } 1468 1459 1469 if (nodes) { 1460 1461 1462 1463 1464 1465 1470 area /= nodes; 1471 radius /= nodes; 1472 cout<<"Number of nodes for storing in the PVS = "<<nodes<<endl; 1473 cout<<"Average rel. node area = "<<area/GetSurfaceArea(mRoot)<<endl; 1474 cout<<"Average rel. node radius = "<<radius/GetBox(mRoot).Radius()<<endl; 1475 cout<<"Avg node radius = "<<radius<<endl; 1466 1476 } 1467 1477 … … 1474 1484 1475 1485 while (node->mPvsTermination == 0 ) { 1476 1477 1478 1479 1480 1486 KdInterior *inter = (KdInterior *)node; 1487 if (point[inter->mAxis] < inter->mPosition) 1488 node = inter->mBack; 1489 else 1490 node = inter->mFront; 1481 1491 } 1482 1492 … … 1491 1501 1492 1502 while (!node->IsLeaf() && (GetSurfaceArea(node) > maxArea) ) { 1493 1494 1495 1496 1497 1503 KdInterior *inter = (KdInterior *)node; 1504 if (point[inter->mAxis] < inter->mPosition) 1505 node = inter->mBack; 1506 else 1507 node = inter->mFront; 1498 1508 } 1499 1509 … … 1503 1513 1504 1514 void KdTree::GetBoxIntersections(const AxisAlignedBox3 &box, 1505 vector<KdLeaf *> &leaves) 1506 { 1507 stack<KdNode *> tStack; 1508 1509 tStack.push(mRoot); 1510 1511 while (!tStack.empty()) 1515 vector<KdLeaf *> &leaves) 1516 { 1517 stack<KdNode *> tStack; 1518 1519 tStack.push(mRoot); 1520 1521 while (!tStack.empty()) 1522 { 1523 KdNode *node = tStack.top(); 1524 tStack.pop(); 1525 1526 if (node->IsLeaf()) 1512 1527 { 1513 KdNode *node = tStack.top(); 1514 tStack.pop(); 1515 1516 if (node->IsLeaf()) 1517 { 1518 leaves.push_back(static_cast<KdLeaf *>(node)); 1519 } 1520 else // interior 1521 { 1522 KdInterior *interior = static_cast<KdInterior *>(node); 1523 1524 if (box.Max(interior->mAxis) >= interior->mPosition) 1525 { 1526 tStack.push(interior->mFront); 1527 } 1528 1529 if (box.Min(interior->mAxis) < interior->mPosition) 1530 { 1531 tStack.push(interior->mBack); 1532 } 1533 } 1534 } 1535 } 1536 1537 1538 1539 } 1528 leaves.push_back(static_cast<KdLeaf *>(node)); 1529 } 1530 else // interior 1531 { 1532 KdInterior *interior = static_cast<KdInterior *>(node); 1533 1534 if (box.Max(interior->mAxis) >= interior->mPosition) 1535 { 1536 tStack.push(interior->mFront); 1537 } 1538 1539 if (box.Min(interior->mAxis) < interior->mPosition) 1540 { 1541 tStack.push(interior->mBack); 1542 } 1543 } 1544 } 1545 } 1546 1547 1548 1549 } -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r2539 r2575 9 9 #include "Ray.h" 10 10 //#include "ObjectPvs.h" 11 #include "View cell.h"11 #include "ViewCell.h" 12 12 #include "VssRay.h" 13 13 //#include "IntersectableWrapper.h" … … 96 96 /** Abstract class for kd-tree node */ 97 97 class KdNode { 98 public: 99 98 99 public: 100 100 static int sMailId; 101 101 static int sReservedMailboxes; … … 109 109 110 110 static void NewMail(const int reserve = 1) { 111 112 113 114 115 111 sMailId += sReservedMailboxes; 112 sReservedMailboxes = reserve; 113 } 114 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 115 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 116 116 117 117 virtual ~KdNode(){}; … … 183 183 public: 184 184 KdLeaf(KdInterior *parent, const int objects): 185 KdNode(parent), mViewCell(NULL), mVboId(-1), mIndexBufferStart(0), mIndexBufferSize(0) { 185 KdNode(parent), mViewCell(NULL), mVboId(-1), 186 mIndexBufferStart(0), mIndexBufferSize(0) { 186 187 mObjects.reserve(objects); 187 188 } … … 194 195 ~KdLeaf(); 195 196 196 197 198 199 197 void AddPassingRay2(const Ray &ray, 198 const int objects, 199 const int viewcells 200 ) { 200 201 mPassingRays.AddRay2(ray, objects, viewcells); 201 202 // Debug << "adding passing ray" << endl; … … 246 247 247 248 TraversalData(KdNode *n, 248 249 249 const AxisAlignedBox3 &b, 250 const int d): 250 251 mNode(n), mBox(b), mDepth(d) {} 251 252 252 253 253 bool operator<( 254 const TraversalData &b) const { 254 bool operator<(const TraversalData &b) const { 255 255 KdLeaf *leafa = (KdLeaf *) mNode; 256 256 KdLeaf *leafb = (KdLeaf *) b.mNode; 257 257 return 258 259 260 258 leafa->mObjects.size()*mBox.SurfaceArea() 259 < 260 leafb->mObjects.size()*b.mBox.SurfaceArea(); 261 261 } 262 262 … … 267 267 268 268 bool operator()(const TraversalData a, const TraversalData b) { 269 269 return a.mPriority < b.mPriority; 270 270 } 271 271 … … 329 329 */ 330 330 int CastLineSegment(const Vector3 &origin, 331 332 331 const Vector3 &termination, 332 vector<ViewCell *> &viewcells); 333 333 334 334 … … 351 351 void 352 352 CollectKdObjects(const AxisAlignedBox3 &box, 353 354 353 ObjectContainer &objects 354 ); 355 355 356 356 void … … 359 359 void 360 360 CollectObjects(const AxisAlignedBox3 &box, 361 361 ObjectContainer &objects); 362 362 363 363 void … … 388 388 389 389 float GetSurfaceArea(const KdNode *node) const { 390 390 return GetBox(node).SurfaceArea(); 391 391 } 392 392 … … 394 394 KdNode * 395 395 FindRandomNeighbor(KdNode *n, 396 397 396 bool onlyUnmailed 397 ); 398 398 399 399 KdNode * 400 KdTree::GetRandomLeaf(const Plane3 &halfspace);400 GetRandomLeaf(const Plane3 &halfspace); 401 401 402 402 KdNode * … … 408 408 409 409 void GetBoxIntersections(const AxisAlignedBox3 &box, 410 410 vector<KdLeaf *> &leaves); 411 411 412 412 int 413 413 FindNeighbors(KdNode *n, 414 415 416 414 vector<KdNode *> &neighbors, 415 bool onlyUnmailed 416 ); 417 417 418 418 bool ExportBinTree(const std::string &filename); … … 439 439 #if USE_FIXEDPOINT_T 440 440 #define FIXEDPOINT_ONE 0x7FFE 441 442 441 // tmax(0xFFFF) 442 tmax(FIXEDPOINT_ONE) 443 443 #else 444 444 tmax(1.0f) … … 531 531 532 532 SortableEntry() {} 533 SortableEntry(const int t, const float v, Intersectable *i): type(t),534 value(v), 535 intersectable(i) {}533 SortableEntry(const int t, const float v, Intersectable *i): 534 type(t), value(v), intersectable(i) 535 { } 536 536 537 537 bool operator<(const SortableEntry &b) const { … … 561 561 void 562 562 SortSubdivisionCandidates( 563 564 565 563 KdLeaf *node, 564 const int axis 565 ); 566 566 567 567 void … … 585 585 ); 586 586 587 588 589 590 591 592 593 594 595 587 /** does some post processing on the objects in the new child leaves. 588 */ 589 void ProcessMultipleRefs(KdLeaf *leaf) const; 590 591 592 ////////// 593 // binary import / export 594 595 void ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf); 596 596 597 void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 598 599 KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 597 void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 598 599 KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, 600 const ObjectContainer &objects); 600 601 601 KdInterior *ImportBinInterior(IN_STREAM &stream, KdInterior *parent); 602 KdInterior *ImportBinInterior(IN_STREAM &stream, KdInterior *parent); 603 604 KdNode *ImportNextNode(IN_STREAM &stream, KdInterior *parent, 605 const ObjectContainer &objects); 602 606 603 KdNode *ImportNextNode(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 604 605 /** Adds this objects to the kd leaf objects. 606 @warning: Can corrupt the tree 607 */ 608 void InsertObjects(KdNode *node, const ObjectContainer &objects); 607 /** Adds this objects to the kd leaf objects. 608 @warning: Can corrupt the tree 609 */ 610 void InsertObjects(KdNode *node, const ObjectContainer &objects); 609 611 610 612 int mTermMaxNodes; -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r2574 r2575 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: so 22. XII 21:22:31 20073 # Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 3. I 15:47:31 2008 4 4 # Project: preprocessor.pro 5 5 # Template: app -
GTP/trunk/Lib/Vis/Preprocessing/src/Material.cpp
r2515 r2575 3 3 4 4 namespace GtpVisibilityPreprocessor { 5 6 7 RgbColor 8 RandomColor(const float a, const float b) 9 { 10 return RgbColor(a + Random(b), 11 a + Random(b), 12 a + Random(b)); 13 } 5 14 6 15 … … 15 24 16 25 return m; 17 }18 19 20 RgbColor21 RandomColor(const float a, const float b)22 {23 return RgbColor(a + Random(b),24 a + Random(b),25 a + Random(b));26 26 } 27 27 -
GTP/trunk/Lib/Vis/Preprocessing/src/Material.h
r2173 r2575 30 30 }; 31 31 32 33 // Forward declarations 34 RgbColor RandomColor(const float a, const float b); 35 36 // Mapping from interval 0.0-1.0 to RGB using "rainbow" color map 37 // (range of hue from 0-240) 38 RgbColor RainbowColorMapping(const float value); 39 40 32 41 33 42 class Material … … 68 77 69 78 79 extern Material RandomMaterial(); 80 70 81 } 71 82 -
GTP/trunk/Lib/Vis/Preprocessing/src/Matrix4x4.h
r2176 r2575 103 103 }; 104 104 105 // forward declaration 106 Matrix4x4 IdentityMatrix(); 107 Matrix4x4 Invert(const Matrix4x4 &M); // Invert a given matrix 108 Matrix4x4 Transpose(const Matrix4x4 &M); // Transpose a given matrix 109 110 // Create various types of matrix. 111 Matrix4x4 IdentityMatrix(); 112 Matrix4x4 ZeroMatrix(); 113 Matrix4x4 TranslationMatrix(const Vector3 &Location); 114 Matrix4x4 RotationXMatrix(float Angle); 115 Matrix4x4 RotationYMatrix(float Angle); 116 Matrix4x4 RotationZMatrix(float Angle); 117 Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll); 118 // about axis 'axis' by angle 'Angle' 119 Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle); 120 // create the rotation matrix that rotates 'vecFrom' to 'vecTo' 121 Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom, 122 const Vector3 &vecTo); 123 124 Matrix4x4 ScaleMatrix(float X, float Y, float Z); 125 Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y, 126 const Vector3 &z); 127 Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e, 128 float f, float g, float h, float j, float k); 129 // returns matrix for transforming normal 130 Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M); 131 132 Matrix4x4 MirrorX(); 133 Matrix4x4 MirrorY(); 134 Matrix4x4 MirrorZ(); 135 Matrix4x4 RotationOnly(const Matrix4x4 &x); 136 137 // Binary operators 138 Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B); 139 Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B); 140 Matrix4x4 operator* (const Matrix4x4 &A, float B); 141 Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B); 142 143 // friends returning Vector3 144 Vector3 operator*(const Matrix4x4 &M, const Vector3 &v); 145 Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v); 146 Vector3 TransformNormal(const Matrix4x4 &M, const Vector3 &v); 147 Vector3 GetTranslation(const Matrix4x4 &M); 148 149 105 150 } 106 151 152 153 107 154 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
r2569 r2575 268 268 269 269 virtual int CastRay(Ray &ray); 270 virtual int CastSimpleRay(const SimpleRay &ray) { return 0;} 271 virtual int CastSimpleRay(const SimpleRay &ray, int IndexRay) 272 { return 0; } 270 273 271 274 virtual bool IsConvex() const { return mMesh->mIsConvex; } -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
r2539 r2575 209 209 const Vector3 cross_a_b = CrossProd(a, b); 210 210 211 if (SqrMagnitude(cross_a_b) <= 0.000001 * FLT_EPSILON * FLT_EPSILON) 211 #define SMALL_FLT 1e-5 212 213 if (SqrMagnitude(cross_a_b) <= 0.0001 * SMALL_FLT * SMALL_FLT) 212 214 { 213 215 // v0, v1 & v2 lies on a line (area == 0) … … 293 295 for (tit = triangles.begin(); tit != tit_end; ++ tit) 294 296 { 295 // test if it is a valid triangle 296 if (0 && !TriangleValid(*tit)) continue; 297 298 TriangleIntersectable *obj = new TriangleIntersectable(*tit); 299 root->mGeometry.push_back(obj); 297 // test if it is a valid triangle 298 if (!TriangleValid(*tit)) 299 continue; 300 301 TriangleIntersectable *obj = new TriangleIntersectable(*tit); 302 root->mGeometry.push_back(obj); 300 303 } 301 304 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjectPvs.cpp
r2332 r2575 1 1 #include <iostream> 2 2 #include <stack> 3 4 #include "Mesh.h" 3 5 #include "ObjectPvs.h" 4 6 #include "Intersectable.h" -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjectPvs.h
r2176 r2575 4 4 #include "common.h" 5 5 #include "PvsDefinitions.h" 6 #include "Intersectable.h" 6 7 7 8 // -
GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp
r2023 r2575 1 1 #include "OcclusionQuery.h" 2 2 #include <iostream> 3 4 5 #ifdef _WIN32 3 6 #include <glInterface.h> 4 7 #else 8 #include <GL/gl.h> 9 #include <GL/glu.h> 10 //#include <GL/glxext.h> 11 #include <SDL/SDL_opengl.h> 12 #endif 5 13 6 14 using namespace std; … … 17 25 if (sUseArbQueries) 18 26 { 19 glGenQueriesARB(1, &id); 27 #ifdef _ARBGL 28 // VH 29 glGenQueriesARB(1, &id); 30 #endif 20 31 } 21 32 else 22 33 { 34 #ifdef _ARBGL 35 // VH 23 36 glGenOcclusionQueriesNV(1, &id); 37 #endif 24 38 } 25 39 } … … 34 48 if (sUseArbQueries) 35 49 { 50 #ifdef _ARBGL 51 // VH 36 52 glDeleteQueriesARB(1, &mId); 53 #endif 37 54 } 38 55 else 39 56 { 57 #ifdef _ARBGL 58 // VH 40 59 glDeleteOcclusionQueriesNV(1, &mId); 60 #endif 41 61 } 42 62 … … 47 67 if (sUseArbQueries) 48 68 { 69 #ifdef _ARBGL 70 // VH 49 71 glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId); 72 #endif 50 73 } 51 74 else 52 75 { 76 #ifdef _ARBGL 77 // VH 53 78 glBeginOcclusionQueryNV(mId); 79 #endif 54 80 } 55 81 } … … 59 85 if (sUseArbQueries) 60 86 { 87 #ifdef _ARBGL 88 // VH 61 89 glEndQueryARB(GL_SAMPLES_PASSED_ARB); 90 #endif 62 91 } 63 92 else 64 93 { 94 #ifdef _ARBGL 95 // VH 65 96 glEndOcclusionQueryNV(); 97 #endif 66 98 } 67 99 } … … 79 111 if (sUseArbQueries) 80 112 { 113 #ifdef _ARBGL 114 // VH 81 115 //GLint available; 82 116 glGetQueryObjectuivARB(mId, 83 117 GL_QUERY_RESULT_AVAILABLE_ARB, 84 &available); 118 &available); 119 #endif 85 120 return available == GL_TRUE; 86 121 } 87 122 else 88 123 { 89 90 glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available); 91 124 #ifdef _ARBGL 125 // VH 126 glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available); 127 #endif 92 128 return available == GL_TRUE; 93 129 } … … 102 138 if (sUseArbQueries) 103 139 { 140 #ifdef _ARBGL 141 // VH 104 142 glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount); 143 #endif 105 144 return sampleCount; 106 145 } 107 146 else 108 147 { 109 148 #ifdef _ARBGL 149 // VH 110 150 glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount); 151 #endif 111 152 return sampleCount; 112 153 } … … 124 165 if (sUseArbQueries) 125 166 { 167 #ifdef _ARBGL 168 // VH 126 169 glGenQueriesARB(n, (unsigned int *)newQueries); 170 #endif 127 171 } 128 172 else 129 173 { 130 glGenOcclusionQueriesNV(n, (unsigned int *)newQueries); 174 #ifdef _ARBGL 175 // VH 176 glGenOcclusionQueriesNV(n, (unsigned int *)newQueries); 177 #endif 131 178 } 132 179 -
GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.cpp
r2124 r2575 42 42 const float det = md.Det3x3(); 43 43 44 if ( abs(det)<TRASH)44 if (fabs(det) < TRASH) 45 45 return false; 46 46 -
GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp
r2176 r2575 1 1 #include <iostream> 2 #include < ply.h>3 #include <stdio.h> 4 2 #include <cstdio> 3 4 #include "ply.h" 5 5 #include "PlyParser.h" 6 6 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2574 r2575 20 20 #include "VssRay.h" 21 21 #include "IntelRayCaster.h" 22 #include "HavranRayCaster.h" 22 23 #include "InternalRayCaster.h" 23 24 #include "GlobalLinesRenderer.h" … … 408 409 // intel ray caster can only trace triangles 409 410 int rayCastMethod; 410 Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 411 Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", 412 rayCastMethod); 413 411 414 vector<FaceParentInfo> *fi = 412 415 ((rayCastMethod == RayCaster::INTEL_RAYCASTER) && mLoadMeshes) ? … … 1044 1047 1045 1048 if (!mUseKdTree) { 1046 // create just a dummy KdTree 1047 mKdTree = new KdTree; 1048 return true; 1049 } 1049 // create just a dummy KdTree 1050 mKdTree = new KdTree; 1051 return true; 1052 } 1053 1054 int rayCastMethod; 1055 Environment::GetSingleton()-> 1056 GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 1057 1058 if (rayCastMethod == 2) { 1059 //HavranRayCaster *hr = 1060 // dynamic_cast<HavranRayCaster*>(mRayCaster); 1061 HavranRayCaster *hr = 1062 reinterpret_cast<HavranRayCaster*>(mRayCaster); 1063 hr->Build(this->mObjects); 1064 return true; 1065 } 1050 1066 1051 1067 // always try to load the kd tree … … 1117 1133 int rayCastMethod; 1118 1134 Environment::GetSingleton()-> 1119 1135 GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 1120 1136 1121 1137 if (rayCastMethod == 0) 1122 1138 { 1123 1124 1125 } 1126 else1139 cout << "ray cast method: internal" << endl; 1140 mRayCaster = new InternalRayCaster(*this); 1141 } 1142 if (rayCastMethod == 1) 1127 1143 { 1128 1144 #ifdef GTP_INTERNAL … … 1130 1146 mRayCaster = new IntelRayCaster(*this, externKdTree); 1131 1147 #endif 1148 } 1149 if (rayCastMethod == 2) 1150 { 1151 cout << "ray cast method: havran" << endl; 1152 mRayCaster = new HavranRayCaster(*this); 1132 1153 } 1133 1154 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r2574 r2575 49 49 friend class IntelRayCaster; 50 50 friend class InternalRayCaster; 51 friend class HavranRayCaster; 51 52 52 53 public: … … 193 194 194 195 static bool LoadObjects(const string &filename, 195 196 196 ObjectContainer &pvsObjects, 197 const ObjectContainer &preprocessorObject); 197 198 198 199 … … 275 276 bool ExportBinaryObj(const std::string &filename, SceneGraphNode *root); 276 277 277 void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const; 278 void SetupRay(Ray &ray, const Vector3 &point, 279 const Vector3 &direction) const; 278 280 279 281 void EvalPvsStat(); -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r2176 r2575 128 128 // Inititalize the ray again when already constructed 129 129 void Init(const Vector3 &wherefrom, 130 131 132 130 const Vector3 &whichdir, 131 const int _type, 132 bool dirNormalized = false) { 133 133 loc = wherefrom; 134 134 dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ; -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r2539 r2575 270 270 int 271 271 RayCaster::ProcessRay(const SimpleRay &simpleRay, 272 273 274 275 276 277 272 Intersection &hitA, 273 Intersection &hitB, 274 VssRayContainer &vssRays, 275 const AxisAlignedBox3 &box, 276 const bool castDoubleRay, 277 const bool pruneInvalidRays) 278 278 { 279 279 int hits = 0; … … 325 325 Debug<<"PR2"<<flush; 326 326 #endif 327 328 // VH - I do not know what this is for, commented out temporarily 329 // !!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!! 330 #if 1 327 331 const bool validSample = true; 328 332 if (validSample) { … … 363 367 { 364 368 VssRay *vssRay = RequestRay( 365 366 367 368 369 370 371 369 clipA, 370 hitB.mPoint, 371 hitA.mObject, 372 hitB.mObject, 373 mPreprocessor.mPass, 374 1.0f //simpleRay.mPdf 375 ); 372 376 373 377 if (validB) … … 383 387 Debug<<"PR4"<<flush; 384 388 #endif 385 } 389 } // validSample 390 #else 391 // Just pass if intersected or not 392 hits = (hitA.mObject != 0) ? 1 : 0; 393 intersect = hitA; 394 #endif 386 395 387 396 return hits; … … 391 400 void 392 401 RayCaster::CastRays( 393 394 395 396 397 398 { 399 400 401 402 403 404 405 406 407 408 409 } 410 } 411 412 413 } 402 SimpleRayContainer &rays, 403 VssRayContainer &vssRays, 404 const AxisAlignedBox3 &sbox, 405 const bool castDoubleRay, 406 const bool pruneInvalidRays ) 407 { 408 SimpleRayContainer::const_iterator rit, rit_end = rays.end(); 409 410 for (rit = rays.begin(); rit != rit_end; ++ rit) { 411 412 CastRay( 413 *rit, 414 vssRays, 415 sbox, 416 castDoubleRay, 417 pruneInvalidRays); 418 } 419 } 420 421 422 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r2571 r2575 20 20 class Preprocessor; 21 21 struct SimpleRay; 22 22 class RayPacket2x2; 23 23 24 24 /** This class provides an interface for ray casting. … … 29 29 public: 30 30 31 enum { 32 INTERNAL_RAYCASTER = 0, 33 INTEL_RAYCASTER 34 }; 35 36 RayCaster(const Preprocessor &preprocessor); 37 38 virtual ~RayCaster(); 39 40 virtual int Type() const = 0; 41 42 /** Wrapper for casting single ray. 43 @returns ray or NULL if invalid 44 */ 45 VssRay *CastRay(const SimpleRay &simpleRay, 46 const AxisAlignedBox3 &box, 47 const bool castDoubleRay); 48 49 virtual int CastRay(const SimpleRay &simpleRay, 50 VssRayContainer &vssRays, 51 const AxisAlignedBox3 &box, 52 const bool castDoubleRay, 53 const bool pruneInvalidRays = true) = 0; 54 55 virtual void CastRays16(SimpleRayContainer &rays, 56 VssRayContainer &vssRays, 57 const AxisAlignedBox3 &sbox, 58 const bool castDoubleRay, 59 const bool pruneInvalidRays = true) = 0; 60 31 enum { 32 INTERNAL_RAYCASTER = 0, 33 INTEL_RAYCASTER = 1, 34 HAVRAN_RAYCASTER = 2 35 }; 36 37 RayCaster(const Preprocessor &preprocessor); 38 39 virtual ~RayCaster(); 40 41 virtual int Type() const = 0; 42 43 /** Wrapper for casting single ray. 44 @returns ray or NULL if invalid 45 */ 46 VssRay *CastRay(const SimpleRay &simpleRay, 47 const AxisAlignedBox3 &box, 48 const bool castDoubleRay); 49 50 virtual int CastRay(const SimpleRay &simpleRay, 51 VssRayContainer &vssRays, 52 const AxisAlignedBox3 &box, 53 const bool castDoubleRay, 54 const bool pruneInvalidRays = true) = 0; 55 56 virtual void CastRays16(SimpleRayContainer &rays, 57 VssRayContainer &vssRays, 58 const AxisAlignedBox3 &sbox, 59 const bool castDoubleRay, 60 const bool pruneInvalidRays = true) = 0; 61 61 62 virtual void CastRays( 62 SimpleRayContainer &rays, 63 VssRayContainer &vssRays, 64 const AxisAlignedBox3 &sbox, 65 const bool castDoubleRay, 66 const bool pruneInvalidRays = true); 67 63 SimpleRayContainer &rays, 64 VssRayContainer &vssRays, 65 const AxisAlignedBox3 &sbox, 66 const bool castDoubleRay, 67 const bool pruneInvalidRays = true); 68 69 // Just for testing concept 70 virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack, 71 bool castDoubleRay, 72 const bool pruneInvalidRays = true) 73 { } 74 68 75 /*virtual void CastRaysEye4(SimpleRayContainer &rays, 69 70 71 72 73 */74 virtual void 75 SortRays(SimpleRayContainer &rays); 76 77 78 // pool of vss rays to be used in one pass of the sampling 79 struct VssRayPool 80 { 81 VssRayPool(): mRays(NULL), mIndex(0), mNumber(0) 82 {} 83 84 ~VssRayPool()85 { 86 DEL_PTR(mRays); 87 } 88 89 void Reserve(const int number)90 { 91 DEL_PTR(mRays); 92 mRays = new VssRay[number];93 mNumber = number;94 } 95 96 void Clear()97 { 98 mIndex = 0; 99 } 100 101 VssRay *Alloc()102 { 103 // reset pool 104 if (mIndex == mNumber) 105 mIndex = 0; 106 return mRays + mIndex ++;107 } 108 109 110 111 VssRay *mRays;112 int mIndex;113 int mNumber;114 }; 115 116 117 118 119 120 121 122 123 124 125 126 127 128 76 VssRayContainer &vssRays, 77 const AxisAlignedBox3 &sbox, 78 const bool castDoubleRay, 79 const bool pruneInvalidRays = true) = 0; 80 */ 81 82 virtual void 83 SortRays(SimpleRayContainer &rays); 84 85 86 // pool of vss rays to be used in one pass of the sampling 87 struct VssRayPool 88 { 89 VssRayPool(): mRays(NULL), mIndex(0), mNumber(0) 90 {} 91 92 ~VssRayPool() 93 { 94 delete []mRays; 95 } 96 97 void Reserve(const int number) 98 { 99 DEL_PTR(mRays); 100 mRays = new VssRay[number]; 101 mNumber = number; 102 } 103 104 void Clear() 105 { 106 mIndex = 0; 107 } 108 109 VssRay *Alloc() 110 { 111 // reset pool 112 if (mIndex == mNumber) 113 mIndex = 0; 114 return mRays + mIndex ++; 115 } 116 protected: 117 VssRay *mRays; 118 int mIndex; 119 int mNumber; 120 }; 121 122 123 VssRayPool mVssRayPool; 124 125 void ReserveVssRayPool(const int n) 126 { 127 mVssRayPool.Reserve(n); 128 } 129 130 void InitPass() 131 { 132 mVssRayPool.Clear(); 133 } 134 135 129 136 protected: 130 131 132 const Vector3 &termination,133 Intersectable *originObject,134 Intersectable *terminationObject,135 const int pass,136 const float pdf);137 138 139 const int l,140 const int r,141 const int depth,142 float box[12]);143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 const Preprocessor &mPreprocessor; 137 138 VssRay *RequestRay(const Vector3 &origin, 139 const Vector3 &termination, 140 Intersectable *originObject, 141 Intersectable *terminationObject, 142 const int pass, 143 const float pdf); 144 145 void _SortRays(SimpleRayContainer &rays, 146 const int l, 147 const int r, 148 const int depth, 149 float box[12]); 150 151 struct Intersection 152 { 153 Intersection(): mObject(NULL), mFaceId(0) 154 {} 155 156 Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): 157 mPoint(p), mNormal(n), mObject(o), mFaceId(f) 158 {} 159 160 Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) 161 {} 162 163 164 //////////// 165 166 Vector3 mPoint; 167 Vector3 mNormal; 168 Intersectable *mObject; 169 int mFaceId; 170 }; 171 172 173 int ProcessRay(const SimpleRay &ray, 174 Intersection &hitA, 175 Intersection &hitB, 176 VssRayContainer &vssRays, 177 const AxisAlignedBox3 &box, 178 const bool castDoubleRay, 179 const bool pruneInvalidRays = true); 180 181 /** Checks if ray is valid. 182 I.e., the ray is in valid view space. 183 @note: clamps the ray to valid view space. 184 */ 185 bool ValidateRay(const Vector3 &origin, 186 const Vector3 &direction, 187 const AxisAlignedBox3 &box, 188 Intersection &hit); 189 190 bool ClipToViewSpaceBox(const Vector3 &origin, 191 const Vector3 &termination, 192 Vector3 &clippedOrigin, 193 Vector3 &clippedTermination); 194 195 const Preprocessor &mPreprocessor; 196 #if 1 197 public: 198 // Added by VH for debugging 199 Intersection intersect; 200 #endif 194 201 }; 195 202 -
GTP/trunk/Lib/Vis/Preprocessing/src/Rectangle3.h
r2176 r2575 51 51 v += CrossProd(mVertices[i], mVertices[i+1]); 52 52 53 return 0.5f *abs(DotProd(GetNormal(), v));53 return 0.5f * fabs(DotProd(GetNormal(), v)); 54 54 } 55 55 -
GTP/trunk/Lib/Vis/Preprocessing/src/RenderTexture.cpp
r1940 r2575 240 240 { 241 241 // [Redge] 242 #if defined(_DEBUG) | defined(DEBUG)242 #if defined(_DEBUG) || defined(DEBUG) 243 243 fprintf(stderr, "Warning: OpenGL extension GL_ARB_depth_texture not available.\n" 244 244 " Using glReadPixels() to emulate behavior.\n"); … … 250 250 } 251 251 SetLastError(0); 252 #else 252 #else // _WIN32 253 253 if (!GLXEW_SGIX_pbuffer) 254 254 { … … 270 270 PrintExtensionError("Some GLX render texture extension"); 271 271 } 272 #endif 272 #endif // _WIN32 273 273 274 274 if (_bInitialized) … … 292 292 PrintExtensionError("NV_float_buffer or ATI_texture_float"); 293 293 } 294 #else 294 #else // _WIN32 295 295 if (_bFloat && _bIsTexture && !GLXEW_NV_float_buffer) 296 296 { … … 298 298 return false; 299 299 } 300 #endif 300 #endif // _WIN32 301 301 if (!_bFloat && !GLEW_NV_texture_rectangle) 302 302 { … … 461 461 } 462 462 } 463 #else if defined(DEBUG) || defined(_DEBUG) 463 #else // _WIN32 464 #if defined(DEBUG) || defined(_DEBUG) 464 465 printf("RenderTexture Error: Render-to-Texture not supported in Linux\n"); 465 #endif 466 #endif 467 #endif // _WIN32 466 468 } 467 469 } … … 850 852 _iBits[5] = (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) ? value : 0; 851 853 852 #if defined(_DEBUG) | defined(DEBUG)854 #if defined(_DEBUG) || defined(DEBUG) 853 855 fprintf(stderr, "Created a %dx%d RenderTexture with BPP(%d, %d, %d, %d)", 854 856 _iWidth, _iHeight, _iBits[0], _iBits[1], _iBits[2], _iBits[3]); … … 857 859 fprintf(stderr, "\n"); 858 860 #endif 859 #else 861 #else // _WIN32 860 862 _pDpy = glXGetCurrentDisplay(); 861 863 GLXContext context = glXGetCurrentContext(); … … 936 938 // XXX Query the color format 937 939 938 #endif 940 #endif // _WIN32 939 941 940 942 return true; … … 982 984 return true; 983 985 } 984 #else 986 #else // _WIN32 985 987 if ( _hPBuffer ) 986 988 { … … 992 994 return true; 993 995 } 994 #endif 996 #endif // _WIN32 995 997 return false; 996 998 } … … 1080 1082 return false; 1081 1083 } 1082 #else 1084 #else // _WIN32 1083 1085 _hPreviousContext = glXGetCurrentContext(); 1084 1086 _hPreviousDrawable = glXGetCurrentDrawable(); … … 1087 1089 return false; 1088 1090 } 1089 #endif 1091 #endif // _WIN32 1090 1092 1091 1093 return true; … … 1196 1198 } 1197 1199 } 1198 #else 1200 #else // _WIN32 1199 1201 assert(_bIsTexture); 1200 1202 glBindTexture(_iTextureTarget, _iTextureID); … … 1208 1210 } 1209 1211 } 1210 #endif 1212 #endif // _WIN32 1211 1213 return true; 1212 1214 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h
r2542 r2575 4 4 #include <vector> 5 5 #include <string> 6 #include <iterator> 7 #include <fstream> 8 #include <ostream> 9 #include <iostream> 6 10 7 11 //#include "Containers.h" … … 13 17 namespace GtpVisibilityPreprocessor { 14 18 19 using std::iterator; 20 using std::map; 21 15 22 16 23 /** Resource manager controlling loading and destroying of resources. … … 25 32 template <typename T> class ResourceManager 26 33 { 34 protected: 35 typedef map<unsigned int, T* > maptype; 27 36 37 /// the resource container 38 maptype mEntries; 39 28 40 public: 29 41 … … 65 77 T *FindEntry(const unsigned int id) const 66 78 { 67 std::map<unsigned int, T *>::const_iterator mit = mEntries.find(id);79 typename maptype::const_iterator mit = mEntries.find(id); 68 80 69 70 71 72 81 if (mit != mEntries.end()) 82 { 83 return (*mit).second; 84 } 73 85 74 86 return NULL; … … 95 107 bool ExportEntries(const std::string &filename) 96 108 { 97 ofstream stream(filename.c_str(),ios::binary);109 std::ofstream stream(filename.c_str(), std::ios::binary); 98 110 99 111 if (!stream.is_open()) 100 112 return false; 101 113 102 std::map<unsigned int, T *>::const_iterator mit, mit_end = mEntries.end();114 typename std::map<unsigned int, T *>::const_iterator mit, mit_end = mEntries.end(); 103 115 104 116 for (mit = mEntries.begin(); mit != mit_end; ++ mit) … … 130 142 ~ResourceManager<T>() 131 143 { 132 144 typename std::map<unsigned int, T *>::iterator mit, mit_end = mEntries.end(); 133 145 134 146 for (mit = mEntries.begin(); mit != mEntries.end(); ++ mit) … … 152 164 protected: 153 165 154 /// the resource container155 std::map<unsigned int, T *> mEntries;156 157 166 private: 158 167 -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r2130 r2575 1481 1481 void 1482 1482 RssTree::RemoveRay(VssRay *ray, 1483 1484 1485 1486 { 1487 1488 stack<RayTraversalData> tstack; 1489 1490 PushRoots(tstack, RssTreeLeaf::RayInfo(ray));1483 vector<RssTreeLeaf *> *affectedLeaves, 1484 const bool removeAllScheduledRays 1485 ) 1486 { 1487 TstackEntry tstack; 1488 1489 RssTreeNode::RayInfo ri(ray); 1490 PushRoots(tstack, ri); 1491 1491 1492 1492 RayTraversalData data; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
r2176 r2575 1099 1099 PushRoots(std::stack<RssTreeNode *> &st) const; 1100 1100 1101 void 1102 PushRoots(std::stack<RayTraversalData> &st, RssTreeNode::RayInfo &info) const; 1101 typedef std::stack<RayTraversalData> TstackEntry; 1102 1103 void 1104 PushRoots(TstackEntry &st, RssTreeNode::RayInfo &info) const; 1103 1105 1104 1106 void -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r2566 r2575 1 1 2 #include "SamplingStrategy.h" 2 3 #include "Ray.h" … … 7 8 #include "RssTree.h" 8 9 #include "Mutation.h" 10 #include "FilterBasedDistribution.h" 11 #include "DifferenceSampling.h" 12 13 14 #ifdef PERFTIMER 9 15 #include "Timer/PerfTimer.h" 10 #include "DifferenceSampling.h" 11 12 16 #endif 13 17 14 18 namespace GtpVisibilityPreprocessor { 15 19 20 21 #ifdef PERFTIMER 16 22 extern PerfTimer haltonTimer; 17 23 extern PerfTimer pvsTimer; 18 24 extern PerfTimer viewCellCastTimer; 19 25 #endif 26 20 27 //HaltonSequence SamplingStrategy::sHalton; 21 28 … … 221 228 r[4], 222 229 r[5]) 223 230 ) - origin; 224 231 225 232 const float c = Magnitude(direction); … … 591 598 if (1) 592 599 { 600 #ifdef PERFTIMER 593 601 const float vcTime = viewCellCastTimer.TotalTime(); 594 602 const float pvsTime = pvsTimer.TotalTime(); 595 603 const float haltonTime = haltonTimer.TotalTime(); 596 604 597 605 cout << "view cell cast time: " << vcTime << " s" << endl; 598 606 cout << "pvs time: " << pvsTime << " s" << endl; … … 602 610 Debug << "pvs time: " << pvsTime << " s" << endl; 603 611 Debug << "halton time: "<< haltonTime << " s" << endl; 612 #else 613 cout << "Timers not supported" << endl; 614 Debug << "Timers for PVS,Halton,Viewcell not supported" << endl; 615 #endif 604 616 } 605 617 } … … 712 724 if (strcmp(curr, "mutation")==0) { 713 725 mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 714 } 726 } else 727 if (strcmp(curr, "filter_based")==0) { 728 mDistributions.push_back(new FilterBasedDistribution(mPreprocessor)); 729 } 715 730 else if (strcmp(curr, "difference")==0) { 716 731 mDistributions.push_back(new DifferenceSampling(mPreprocessor)); 717 732 } 733 718 734 719 735 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r2548 r2575 48 48 HW_GLOBAL_LINES_DISTRIBUTION, 49 49 VIEWCELL_BASED_DISTRIBUTION, 50 FILTER_BASED_DISTRIBUTION, 50 51 DIFFERENCE_SAMPLING_BASED_DISTRIBUTION, 51 52 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/SimpleRay.h
r2176 r2575 5 5 using namespace std; 6 6 #include "Vector3.h" 7 #include "Ray.h" 7 8 8 9 namespace GtpVisibilityPreprocessor { 9 10 11 class Intersectable; 12 13 // This is the result of ray tracing with a simple ray 14 struct IntersectionStr { 15 Intersectable *intersectable; 16 float tdist; 17 float maxt; 18 int pad1; // aligned to 16 bytes 19 }; 20 10 21 struct SimpleRay 11 22 { 23 // This is stored result for the rays in the container 24 // having 16 rays - shooting rays in both directions 25 static IntersectionStr IntersectionRes[32]; 12 26 13 27 Vector3 mOrigin; … … 29 43 // 4B 30 44 31 // TOTAL = 40B 45 // TOTAL = 40B - aligned by 8 Bytes only! - it might be 46 // padding to 48 Bytes here ! 32 47 33 48 … … 39 54 40 55 SimpleRay(const Vector3 &o, 41 42 43 44 45 46 47 48 49 50 51 56 const Vector3 &d, 57 const unsigned char distribution, 58 const float weight, 59 const unsigned char flags = F_BIDIRECTIONAL 60 ): 61 mOrigin(o), 62 mDirection(d), 63 mFlags(flags), 64 mType(Ray::LOCAL_RAY), 65 mDistribution(distribution) 66 // , mWeight(weight) 52 67 { 53 68 // mId = sSimpleRayId++; 54 69 } 55 70 71 void 72 Set(const Vector3 &o, 73 const Vector3 &d, 74 const unsigned char distribution, 75 const float weight, 76 const unsigned char flags = F_BIDIRECTIONAL 77 ) 78 { 79 mOrigin = o; 80 mDirection = d, 81 mFlags = flags; 82 mType = Ray::LOCAL_RAY; 83 mDistribution = distribution; 84 // , mWeight(weight) 85 // mId = sSimpleRayId++; 86 } 87 56 88 bool IsBidirectional() const { return mFlags & F_BIDIRECTIONAL; } 57 89 58 90 void SetBidirectional(const bool b) { 59 60 61 62 91 if (b) 92 mFlags |= F_BIDIRECTIONAL; 93 else 94 mFlags &= ~F_BIDIRECTIONAL; 63 95 } 64 96 65 97 float GetParam(const int axis) const { 66 67 68 69 98 if (axis < 3) 99 return mOrigin[axis]; 100 else 101 return mDirection[axis-3]; 70 102 } 71 103 72 104 Vector3 Extrap(const float t) const { 73 105 return mOrigin + mDirection * t; 74 106 } 75 107 76 108 friend std::ostream &operator<<(std::ostream &s, const SimpleRay &r) 77 109 { 78 110 return s << "origin=" << r.mOrigin << " dir=" << r.mDirection; 79 111 }; 80 112 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp
r2347 r2575 50 50 * Gavin Bell 51 51 */ 52 #include < math.h>53 #include " trackball.h"52 #include <cmath> 53 #include "Trackball.h" 54 54 55 55 /* -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp
r2542 r2575 1 1 #include "Triangle3.h" 2 2 #include "Ray.h" 3 #include "SimpleRay.h" 3 4 #include "AxisAlignedBox3.h" 4 5 #include "Containers.h" … … 33 34 int 34 35 Triangle3::CastRay(const Ray &ray, 35 float &t, 36 const float nearestT, 37 Vector3 &normal) const 38 { 39 ////////////// 40 // specialised triangle ray casting version 41 // using ray-plane intersection 42 43 // get triangle edge vectors and plane normal 44 const Vector3 u = mVertices[0] - mVertices[1]; 45 const Vector3 v = mVertices[2] - mVertices[1]; 46 47 // cross product 48 normal = Normalize(CrossProd(v, u)); 49 50 // ray direction vector 51 const Vector3 dir = ray.GetDir(); 52 const Vector3 w0 = ray.GetLoc() - mVertices[1]; 53 54 // params to calc ray-plane intersect 55 const float a = -DotProd(normal, w0); 56 const float b = DotProd(normal, dir); 57 58 // check for division by zero 59 if (fabs(b) < Limits::Small) 60 { 61 // ray is parallel to triangle plane 62 if (a == 0) 63 { 64 // ray lies in triangle plane 65 return Ray::INTERSECTION_OUT_OF_LIMITS; 66 } 67 else 68 { 69 // ray disjoint from plane 70 return Ray::NO_INTERSECTION; 71 } 72 } 73 74 // distance from origin of ray to plane 75 t = a / b; 76 77 if (t <= Limits::Small) // ray goes away from triangle 78 { 36 float &t, 37 const float nearestT, 38 Vector3 &normal) const 39 { 40 ////////////// 41 // specialised triangle ray casting version 42 // using ray-plane intersection 43 44 // get triangle edge vectors and plane normal 45 const Vector3 u = mVertices[0] - mVertices[1]; 46 const Vector3 v = mVertices[2] - mVertices[1]; 47 48 // cross product 49 normal = Normalize(CrossProd(v, u)); 50 51 // ray direction vector 52 const Vector3 dir = ray.GetDir(); 53 const Vector3 w0 = ray.GetLoc() - mVertices[1]; 54 55 // params to calc ray-plane intersect 56 const float a = -DotProd(normal, w0); 57 const float b = DotProd(normal, dir); 58 59 // check for division by zero 60 if (fabs(b) < Limits::Small) 61 { 62 // ray is parallel to triangle plane 63 if (a == 0) 64 { 65 // ray lies in triangle plane 79 66 return Ray::INTERSECTION_OUT_OF_LIMITS; 80 67 } 81 // already found nearer intersection 82 else if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT)) 83 { 84 return Ray::NO_INTERSECTION; 85 } 86 87 ///////////////// 68 else 69 { 70 // ray disjoint from plane 71 return Ray::NO_INTERSECTION; 72 } 73 } 74 75 // distance from origin of ray to plane 76 t = a / b; 77 78 if (t <= Limits::Small) // ray goes away from triangle 79 { 80 return Ray::INTERSECTION_OUT_OF_LIMITS; 81 } 82 // already found nearer intersection 83 else if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT)) 84 { 85 return Ray::NO_INTERSECTION; 86 } 87 88 ///////////////// 88 89 //-- found intersection point 89 90 91 90 //-- check if it is inside triangle 91 92 const Vector3 pt = ray.GetLoc() + t * dir; 92 93 #if GTP_DEBUG 93 94 95 96 97 94 if (!pt.CheckValidity()) 95 { 96 cout << "tr: " << *this << endl; 97 cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl; 98 } 98 99 #endif 99 const Vector3 w = pt - mVertices[1]; 100 101 const float uu = DotProd(u, u); 102 const float uv = DotProd(u, v); 103 const float vv = DotProd(v, v); 100 const Vector3 w = pt - mVertices[1]; 101 102 const float uu = DotProd(u, u); 103 const float uv = DotProd(u, v); 104 const float vv = DotProd(v, v); 105 106 const float wu = DotProd(w, u); 107 const float wv = DotProd(w, v); 108 109 110 const float D = uv * uv - uu * vv; 111 112 // get and test parametric coords 113 const float s = (uv * wv - vv * wu) / D; 114 115 if ((s < -Limits::Small) || (s > 1.0f + Limits::Small)) // pt is outside triangle 116 { 117 return Ray::NO_INTERSECTION; 118 } 119 120 const float s2 = (uv * wu - uu * wv) / D; 121 122 if ((s2 < -Limits::Small) || ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle 123 { 124 return Ray::NO_INTERSECTION; 125 } 126 127 return Ray::INTERSECTION; // I is in T 128 } 129 130 131 int 132 Triangle3::CastSimpleRay(const SimpleRay &ray, 133 float &t, 134 const float nearestT) const 135 { 136 ////////////// 137 // specialised triangle ray casting version 138 // using ray-plane intersection 139 140 // get triangle edge vectors and plane normal 141 const Vector3 u = mVertices[0] - mVertices[1]; 142 const Vector3 v = mVertices[2] - mVertices[1]; 143 144 // cross product 145 const Vector3 normal = Normalize(CrossProd(v, u)); 146 147 // ray direction vector 148 const Vector3 dir = ray.mDirection; 149 const Vector3 w0 = ray.mOrigin - mVertices[1]; 150 151 // params to calc ray-plane intersect 152 const float a = -DotProd(normal, w0); 153 const float b = DotProd(normal, dir); 154 155 // check for division by zero 156 if (fabs(b) < Limits::Small) 157 { 158 // ray is parallel to triangle plane 159 if (a == 0) 160 { 161 // ray lies in triangle plane 162 return Ray::INTERSECTION_OUT_OF_LIMITS; 163 } 164 else { 165 // ray disjoint from plane 166 return Ray::NO_INTERSECTION; 167 } 168 } 169 170 // distance from origin of ray to plane 171 t = a / b; 172 173 if (t <= Limits::Small) // ray goes away from triangle 174 { 175 return Ray::INTERSECTION_OUT_OF_LIMITS; 176 } 177 178 // already found nearer intersection 179 if (t > nearestT + 1e-5) 180 { 181 return Ray::NO_INTERSECTION; 182 } 183 184 ///////////////// 185 //-- found intersection point 186 //-- check if it is inside triangle 187 188 const Vector3 pt = ray.mOrigin + t * dir; 189 #if GTP_DEBUG 190 if (!pt.CheckValidity()) 191 { 192 cout << "tr: " << *this << endl; 193 cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl; 194 } 195 #endif 196 const Vector3 w = pt - mVertices[1]; 197 198 const float uu = DotProd(u, u); 199 const float uv = DotProd(u, v); 200 const float vv = DotProd(v, v); 104 201 105 const float wu = DotProd(w, u); 106 const float wv = DotProd(w, v); 107 108 109 const float D = uv * uv - uu * vv; 110 111 // get and test parametric coords 112 const float s = (uv * wv - vv * wu) / D; 113 114 if ((s < -Limits::Small) || (s > 1.0f + Limits::Small)) // pt is outside triangle 115 { 116 return Ray::NO_INTERSECTION; 117 } 118 119 const float s2 = (uv * wu - uu * wv) / D; 120 121 if ((s2 < -Limits::Small) || ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle 122 { 123 return Ray::NO_INTERSECTION; 124 } 125 126 return Ray::INTERSECTION; // I is in T 127 } 128 202 const float wu = DotProd(w, u); 203 const float wv = DotProd(w, v); 204 205 206 const float D = uv * uv - uu * vv; 207 208 // get and test parametric coords 209 const float s = (uv * wv - vv * wu) / D; 210 211 if ((s < -Limits::Small) || 212 (s > 1.0f + Limits::Small)) // pt is outside triangle 213 { 214 return Ray::NO_INTERSECTION; 215 } 216 217 const float s2 = (uv * wu - uu * wv) / D; 218 219 if ((s2 < -Limits::Small) || 220 ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle 221 { 222 return Ray::NO_INTERSECTION; 223 } 224 225 return Ray::INTERSECTION; // I is in T 226 } 227 129 228 130 229 AxisAlignedBox3 Triangle3::GetBoundingBox() const … … 137 236 box.Include(mVertices[2]); 138 237 238 box.EnlargeToMinSize(); 239 139 240 return box; 140 241 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h
r2176 r2575 9 9 class AxisAlignedBox3; 10 10 class Ray; 11 class SimpleRay; 11 12 class Plane3; 12 13 … … 32 33 int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const; 33 34 35 int CastSimpleRay(const SimpleRay &ray, float &t, const float nearestT) const; 36 34 37 friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A); 35 38 friend std::istream& operator>> (std::istream &s, Triangle3 &A); -
GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.cpp
r1883 r2575 2 2 #include "Vector3.h" 3 3 #include "Halton.h" 4 #include "float.h" 5 4 #include <float.h> 6 5 7 6 namespace GtpVisibilityPreprocessor { … … 316 315 bool Vector3::CheckValidity() const 317 316 { 318 return !(_isnan(x) || _isnan(y) || _isnan(z)); 319 //return ((x != x) || (y != y) || (z != z)); 320 } 321 322 } 317 #ifdef _WIN32 318 return !(_isnan(x) || _isnan(y) || _isnan(z)); 319 #else 320 return !(isnan(x) || isnan(y) || isnan(z)); 321 #endif 322 //return ((x != x) || (y != y) || (z != z)); 323 } 324 325 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h
r2176 r2575 250 250 }; 251 251 252 // forward declaration 253 extern Vector3 UniformRandomVector(const Vector3 &normal); 254 extern Vector3 UniformRandomVector(); 255 extern Vector3 UniformRandomVector(const float r1, const float r2); 256 252 257 inline Vector3 253 258 ArbitraryNormal(const Vector3 &N) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r2569 r2575 3 3 #include <stack> 4 4 5 5 #include "Material.h" 6 6 #include "ViewCell.h" 7 7 #include "Mesh.h" … … 14 14 #include "Exporter.h" 15 15 #include "BvHierarchy.h" 16 17 #ifdef PERFTIMER 16 18 #include "Timer/PerfTimer.h" 17 19 #endif 18 20 19 21 namespace GtpVisibilityPreprocessor { … … 23 25 #define TYPE_LEAF -3 24 26 27 #ifdef PERFTIMER 25 28 static PerfTimer sPvsTimer; 26 29 static PerfTimer sSearchTimer; 27 28 30 #endif 29 31 30 32 static inline bool ilt(Intersectable *obj1, Intersectable *obj2) … … 45 47 46 48 typedef priority_queue<ViewCell *, vector<ViewCell *>, 47 48 49 int ViewCell::sMailId = 10000;//2147483647;50 int ViewCell::sReservedMailboxes = 1;49 myless<vector<ViewCell *>::value_type> > TraversalQueue; 50 51 int Intersectable::sMailId = 10000;//2147483647; 52 int Intersectable::sReservedMailboxes = 1; 51 53 52 54 float MergeCandidate::sRenderCostWeight = 0; … … 55 57 // pvs penalty can be different from pvs size 56 58 inline static float EvalPvsPenalty(const float pvs, 57 58 59 const float lower, 60 const float upper) 59 61 { 60 62 // clamp to minmax values … … 2686 2688 Intersectable *obj; 2687 2689 2690 #ifdef PERFTIMER 2688 2691 sPvsTimer.Entry(); 2689 2692 #endif 2690 2693 int pvsSize; 2691 2694 stream.read(reinterpret_cast<char *>(&pvsSize), sizeof(int)); … … 2703 2706 } 2704 2707 2708 #ifdef PERFTIMER 2705 2709 sPvsTimer.Exit(); 2710 #endif 2706 2711 2707 2712 return leaf; … … 2738 2743 queue<ViewCell *> tStack; 2739 2744 2745 #ifdef PERFTIMER 2740 2746 sPvsTimer.Start(); 2741 2747 #endif 2748 2742 2749 mPvsIds = new int[pvsObjects.size()]; 2743 2750 … … 2774 2781 } 2775 2782 2783 #ifdef PERFTIMER 2776 2784 Debug << "needed " << sPvsTimer.TotalTime() << " secs for pvs loading" << endl; 2777 2785 #endif 2786 2778 2787 delete mPvsIds; 2779 2788 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
r2176 r2575 303 303 /** Sets parent node. 304 304 */ 305 inline void BspNode::SetParent(BspInterior *parent)306 { 307 305 inline void SetParent(BspInterior *parent) 306 { 307 mParent = parent; 308 308 } 309 309 … … 375 375 /** Returns split plane. 376 376 */ 377 Plane3 BspInterior::GetPlane() const377 Plane3 GetPlane() const 378 378 { 379 379 return mPlane; … … 441 441 /** @return true since it is an interior node 442 442 */ 443 bool BspLeaf::IsLeaf() const443 bool IsLeaf() const 444 444 { 445 445 return true; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2571 r2575 24 24 #include "SamplingStrategy.h" 25 25 #include "SceneGraph.h" 26 27 #ifdef PERFTIMER 26 28 #include "Timer/PerfTimer.h" 27 29 #endif // PERFTIMER 28 30 29 31 #define USE_RAY_LENGTH_AS_CONTRIBUTION 0 … … 39 41 40 42 43 #ifdef PERFTIMER 41 44 PerfTimer viewCellCastTimer; 42 45 PerfTimer pvsTimer; 43 46 PerfTimer objTimer; 44 47 #endif 48 45 49 // HACK 46 50 const static bool SAMPLE_AFTER_SUBDIVISION = true; … … 66 70 }; 67 71 72 73 74 struct SortableViewCellEntry { 75 76 SortableViewCellEntry() {} 77 SortableViewCellEntry(const float v, ViewCell *cell):mValue(v), mViewCell(cell) {} 78 79 float mValue; 80 ViewCell *mViewCell; 81 82 friend bool operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b); 83 }; 84 85 86 inline bool 87 operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b) { 88 return a.mValue < b.mValue; 89 } 68 90 69 91 ViewCellsManager::ViewCellsManager(ViewCellsTree *viewCellsTree): … … 1059 1081 int id; 1060 1082 1083 #ifdef PERFTIMER 1061 1084 PerfTimer boxTimer; 1062 1085 1063 1086 boxTimer.Start(); 1064 1087 boxTimer.Entry(); 1065 1088 #endif 1066 1089 for (int i = 0; i < numBoxes; ++ i) 1067 1090 { … … 1074 1097 1075 1098 1099 #ifdef PERFTIMER 1076 1100 boxTimer.Exit(); 1077 1101 1078 1102 Debug << numBoxes << " boxes loaded in " << boxTimer.TotalTime() << " secs" << endl; 1103 #endif 1079 1104 } 1080 1105 … … 1699 1724 inline float EvalMergeCost(ViewCell *root, ViewCell *candidate) 1700 1725 { 1701 1726 return root->GetPvs().GetPvsHomogenity(candidate->GetPvs()); 1702 1727 } 1703 1728 … … 1773 1798 } 1774 1799 1775 1776 struct SortableViewCellEntry {1777 1778 SortableViewCellEntry() {}1779 SortableViewCellEntry(const float v, ViewCell *cell):mValue(v), mViewCell(cell) {}1780 1781 float mValue;1782 ViewCell *mViewCell;1783 1784 friend bool operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b) {1785 return a.mValue < b.mValue;1786 }1787 };1788 1800 1789 1801 … … 2114 2126 } 2115 2127 2128 #ifdef PERFTIMER 2116 2129 cout << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 2117 2130 Debug << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; … … 2119 2132 cout << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 2120 2133 Debug << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 2121 2134 #endif 2122 2135 return sum; 2123 2136 } … … 2869 2882 ViewCell::NewMail(); 2870 2883 2884 #ifdef PERFTIMER 2871 2885 viewCellCastTimer.Entry(); 2872 2886 #endif 2873 2887 static ViewCellContainer viewCells; 2874 2888 static VssRay *lastVssRay = NULL; … … 2889 2903 } 2890 2904 2905 #ifdef PERFTIMER 2891 2906 viewCellCastTimer.Exit(); 2892 2907 #endif 2893 2908 mSamplesStat.mViewCells += (int)viewCells.size(); 2894 2909 … … 2908 2923 Intersectable *terminationObj; 2909 2924 2925 #ifdef PERFTIMER 2910 2926 objTimer.Entry(); 2911 2927 #endif 2912 2928 // obtain pvs entry (can be different from hit object) 2913 2929 terminationObj = ray.mTerminationObject; 2914 2930 2931 #ifdef PERFTIMER 2915 2932 objTimer.Exit(); 2916 2933 2917 2934 pvsTimer.Entry(); 2918 2935 #endif 2936 2919 2937 ViewCellContainer::const_iterator it = viewCells.begin(); 2920 2938 … … 2929 2947 } 2930 2948 2949 #ifdef PERFTIMER 2931 2950 pvsTimer.Exit(); 2932 2951 #endif 2952 2933 2953 mSamplesStat.mPvsContributions += ray.mPvsContribution; 2934 2954 if (ray.mPvsContribution) … … 3460 3480 const float filterSize, 3461 3481 ObjectPvs &pvs, 3462 vector<AxisAlignedBox3> *filteredBoxes 3482 vector<AxisAlignedBox3> *filteredBoxes, 3483 const bool onlyNewObjects 3463 3484 ) 3464 3485 { … … 3480 3501 3481 3502 if (!mUseKdPvs) 3482 { // first mark all objects from this pvs 3483 while (pit.HasMoreEntries()) 3484 pit.Next()->Mail(); 3485 } 3486 3503 { 3504 // first mark all objects from this pvs 3505 while (pit.HasMoreEntries()) 3506 pit.Next()->Mail(); 3507 } 3508 3487 3509 int pvsSize = 0; 3488 3510 int nPvsSize = 0; … … 3548 3570 3549 3571 pit = basePvs.GetIterator(); 3550 3572 3573 if (onlyNewObjects) { 3574 while (pit.HasMoreEntries()) { 3575 // mail all objects from the original not to include them in the 3576 // resulting pvs 3577 Intersectable *obj = pit.Next(pvsData); 3578 obj->Mail(); 3579 } 3580 pit = basePvs.GetIterator(); 3581 } 3582 3551 3583 while (pit.HasMoreEntries()) 3552 3584 { … … 3631 3663 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 3632 3664 } 3633 3665 3634 3666 //Debug << " nPvs size = " << pvs.GetSize() << endl; 3635 3667 3636 if (!mUseKdPvs )3668 if (!mUseKdPvs && !onlyNewObjects) 3637 3669 { 3638 3670 PvsData pvsData; … … 7162 7194 CLEAR_CONTAINER(tmpRays); 7163 7195 7196 #ifdef PERFTIMER 7164 7197 cout << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 7165 7198 Debug << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 7166 7167 7199 cout << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 7168 7200 Debug << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 7201 #endif 7169 7202 7170 7203 return sum; … … 7174 7207 7175 7208 7176 ViewCellsManager *ViewCellsManager::LoadViewCellsBinary(const string &filename, 7177 ObjectContainer &pvsObjects, 7178 bool finalizeViewCells, 7179 BoundingBoxConverter *bconverter) 7180 { 7181 IN_STREAM stream(filename.c_str()); 7182 7183 if (!stream.is_open()) 7209 ViewCellsManager * 7210 ViewCellsManager::LoadViewCellsBinary(const string &filename, 7211 ObjectContainer &pvsObjects, 7212 bool finalizeViewCells, 7213 BoundingBoxConverter *bconverter) 7214 { 7215 IN_STREAM stream(filename.c_str()); 7216 7217 if (!stream.is_open()) 7184 7218 { 7185 7219 Debug << "View cells loading failed: could not open file" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r2574 r2575 364 364 /** Creates mesh for this view cell. 365 365 */ 366 virtual void CreateMesh(ViewCell *vc) = NULL;366 virtual void CreateMesh(ViewCell *vc) = 0; 367 367 /** Writes view cells to disc. 368 368 */ 369 369 virtual bool ExportViewCells(const string filename, 370 371 370 const bool exportPvs, 371 const ObjectContainer &objects); 372 372 /** Casts beam to collect view cells. 373 373 */ … … 626 626 const int maxRays, 627 627 const string &prefix, 628 VssRayContainer *visRays = NULL) = NULL;628 VssRayContainer *visRays = NULL) = 0; 629 629 630 630 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r2543 r2575 147 147 EndObjectSpaceHierarchy(); 148 148 Debug << "object space hierarchy parsed" << endl; 149 #ifdef PERFTIMER 149 150 mObjectTimer.Exit(); 151 #endif 150 152 } 151 153 // finished paring, create view cells manager … … 154 156 CreateViewCellsManager(); 155 157 158 #ifdef PERFTIMER 156 159 Debug << "pvs time: " << mPvsTimer.TotalTime() << endl; 157 160 Debug << "object time: " << mObjectTimer.TotalTime() << endl; 158 161 Debug << "box time: " << mBoxTimer.TotalTime() << endl; 159 162 #endif 160 163 } 161 164 else if (element == "Interior") … … 298 301 const long startTime = GetTime(); 299 302 303 #ifdef PERFTIMER 300 304 mBoxTimer.Entry(); 301 305 #endif 302 306 if (mBoundingBoxConverter) 303 307 { … … 320 324 << TimeDiff(startTime, GetTime()) * 1e-6 << " secs" << endl; 321 325 326 #ifdef PERFTIMER 322 327 mBoxTimer.Exit(); 328 #endif 323 329 } 324 330 … … 481 487 482 488 mCurrentState = PARSE_OBJECTSPACE_HIERARCHY; 489 #ifdef PERFTIMER 483 490 mObjectTimer.Entry(); 491 #endif 484 492 StartObjectSpaceHierarchy(attributes); 485 493 } … … 539 547 } 540 548 549 #ifdef PERFTIMER 541 550 mPvsTimer.Entry(); 542 551 #endif 543 552 Intersectable::NewMail(); 544 553 … … 582 591 } 583 592 593 #ifdef PERFTIMER 584 594 mPvsTimer.Exit(); 595 #endif 585 596 } 586 597 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
r2227 r2575 8 8 #include "Mesh.h" 9 9 #include "BoundingBoxConverter.h" 10 11 #ifdef __WINDOWS__ 10 12 #include <hash_map> 11 13 #else 14 #include <map> 15 #endif 16 17 #ifdef PERFTIMER 12 18 #include "Timer/PerfTimer.h" 19 #endif 13 20 14 21 namespace GtpVisibilityPreprocessor { … … 54 61 55 62 63 #ifdef __WINDOWS__ 56 64 typedef stdext::hash_map<int, Intersectable *> pvs_hash; 57 65 #else 66 typedef std::map<int, Intersectable *> pvs_hash; 67 #endif 58 68 59 69 class ViewCellsParseHandlers: public HandlerBase … … 158 168 int nObjects; 159 169 170 #ifdef PERFTIMER 160 171 PerfTimer mBoxTimer; 161 172 PerfTimer mPvsTimer; 162 173 PerfTimer mObjectTimer; 163 174 #endif 175 164 176 pvs_hash mHashPvs; 165 177 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r2347 r2575 3478 3478 BspInterior *in = static_cast<BspInterior *>(node); 3479 3479 3480 Plane3 &splitPlane = in->GetPlane();3480 Plane3 *splitPlane = &(in->GetPlane()); 3481 3481 3482 const int entSide = splitPlane .Side(entp, thresh);3483 const int extSide = splitPlane .Side(extp, thresh);3482 const int entSide = splitPlane->Side(entp, thresh); 3483 const int extSide = splitPlane->Side(extp, thresh); 3484 3484 3485 3485 if (entSide < 0) … … 3518 3518 3519 3519 // find intersection of ray segment with plane 3520 extp = splitPlane .FindIntersection(origin, extp, &t);3520 extp = splitPlane->FindIntersection(origin, extp, &t); 3521 3521 } 3522 3522 else -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r2547 r2575 709 709 const bool globalCriteriaMet) 710 710 { 711 #ifdef PERFTIMER 711 712 mSubdivTimer.Entry(); 712 713 #endif 714 713 715 // todo remove dynamic cast 714 716 VspSubdivisionCandidate *sc = … … 788 790 } 789 791 792 #ifdef PERFTIMER 790 793 mSubdivTimer.Exit(); 791 794 #endif 792 795 return newNode; 793 796 } … … 797 800 bool computeSplitPlane) 798 801 { 802 #ifdef PERFTIMER 799 803 mPlaneTimer.Entry(); 800 804 #endif 805 801 806 if (computeSplitPlane) 802 807 { … … 818 823 } 819 824 825 #ifdef PERFTIMER 820 826 mPlaneTimer.Exit(); 821 827 mEvalTimer.Entry(); 822 828 #endif 829 823 830 VspLeaf *leaf = static_cast<VspLeaf *>(splitCandidate.mParentData.mNode); 824 831 … … 917 924 918 925 //cout << "vsp render cost decrease=" << renderCostDecr << endl; 926 #ifdef PERFTIMER 919 927 mEvalTimer.Exit(); 928 #endif 920 929 } 921 930 … … 948 957 VspTraversalData &backData) 949 958 { 959 #ifdef PERFTIMER 950 960 mNodeTimer.Entry(); 951 961 #endif 952 962 VspLeaf *leaf = static_cast<VspLeaf *>(sc.mParentData.mNode); 953 963 … … 1042 1052 interior->mTimeStamp = mHierarchyManager->mTimeStamp ++; 1043 1053 1054 #ifdef PERFTIMER 1044 1055 mNodeTimer.Exit(); 1045 1056 #endif 1046 1057 return interior; 1047 1058 } … … 1103 1114 float maxBand) 1104 1115 { 1116 #ifdef PERFTIMER 1105 1117 mSortTimer.Entry(); 1106 1118 #endif 1107 1119 mLocalSubdivisionCandidates->clear(); 1108 1120 … … 1154 1166 sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 1155 1167 1168 #ifdef PERFTIMER 1156 1169 mSortTimer.Exit(); 1170 #endif 1157 1171 } 1158 1172 … … 1573 1587 float &pBack) 1574 1588 { 1589 #ifdef PERFTIMER 1575 1590 mSplitTimer.Entry(); 1576 1591 #endif 1577 1592 float nPosition[3]; 1578 1593 float nCostRatio[3]; … … 1670 1685 pBack = nProbBack[bestAxis]; 1671 1686 1687 #ifdef PERFTIMER 1672 1688 mSplitTimer.Exit(); 1673 1689 #endif 1674 1690 return nCostRatio[bestAxis]; 1675 1691 } … … 3158 3174 void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells) 3159 3175 { 3176 #ifdef PERFTIMER 3160 3177 mViewCellsTimer.Entry(); 3178 #endif 3161 3179 3162 3180 static Ray hray; … … 3175 3193 CastLineSegment(origin, termination, viewCells, false); 3176 3194 3195 #ifdef PERFTIMER 3177 3196 mViewCellsTimer.Exit(); 3197 #endif 3178 3198 } 3179 3199 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r2547 r2575 12 12 #include "SubdivisionCandidate.h" 13 13 #include "HierarchyManager.h" 14 #ifdef PERFTIMER 14 15 #include "Timer/PerfTimer.h" 16 #endif // PERFTIMER 15 17 16 18 … … 294 296 class VspLeaf: public VspNode 295 297 { 296 friendVspTree;298 friend class VspTree; 297 299 298 300 public: … … 670 672 //////////// 671 673 674 #ifdef PERFTIMER 672 675 PerfTimer mSortTimer; 673 676 PerfTimer mSplitTimer; … … 677 680 PerfTimer mPlaneTimer; 678 681 PerfTimer mViewCellsTimer; 679 682 #endif 683 680 684 protected: 681 685 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
r2353 r2575 151 151 float GetOpositeDirParametrization(const int axis) const; 152 152 153 static float VssRay::GetDirParam(const int axis, const Vector3 dir);154 static Vector3 VssRay::GetInvDirParam(const float alpha, const float beta);153 static float GetDirParam(const int axis, const Vector3 dir); 154 static Vector3 GetInvDirParam(const float alpha, const float beta); 155 155 156 156 float GetSize() const { return 1.0f/mInvSize; } -
GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp
r2105 r2575 1771 1771 1772 1772 sort(leaves.begin(), 1773 1774 1773 leaves.end(), 1774 GreaterContribution); 1775 1775 1776 1776 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.h
r2176 r2575 493 493 }; 494 494 495 friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) { 496 return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 497 } 495 friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b); 498 496 499 497 }; … … 504 502 parent(p), axis(-1), depth(p ? p->depth + 1 : 0) {} 505 503 506 504 inline bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) { 505 return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 506 } 507 507 508 508 509 // --------------------------------------------------------------- -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r2176 r2575 21 21 #include <limits.h> 22 22 23 23 // use perftimer 24 #define PERFTIMER 24 25 25 26 namespace GtpVisibilityPreprocessor { 26 27 28 27 29 28 30 … … 45 47 46 48 #if defined(__GNUC__) || defined(_MSC_VER) 47 #define DIRCAT '.'49 //#define DIRCAT '.' 48 50 #endif 49 51 -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r2569 r2575 6 6 7 7 #define NOMINMAX 8 #ifdef __WINDOWS__ 8 9 #include <windows.h> 9 #i nclude <stdio.h>10 #ifdef _CRT_SET 10 11 #include <crtdbg.h> 11 12 #endif // _CRT_SET 13 #endif 14 #include <cstdio> 15 16 #include "Camera.h" 12 17 #include "PreprocessorFactory.h" 13 18 #include "Parser.h" … … 20 25 #include "SceneGraph.h" 21 26 #include "GlobalLinesRenderer.h" 27 #include "RayCaster.h" 28 //#include "testrt.h" 22 29 23 30 #include "ViewCellsManager.h" … … 152 159 } 153 160 154 155 161 int 156 162 main(int argc, char **argv) 157 163 { 158 int returnCode = 0; 164 #if 0 165 // Test code by VH 166 //TestRTcamera(argc, argv); 167 //TestRTfromFile(argc, argv); 168 TestRTfromFilePackets(argc, argv); 169 return 0; 170 #endif 171 172 int returnCode = 0; 173 174 //Now just call this function at the start of your program and if you're 175 //compiling in debug mode (F5), any leaks will be displayed in the Output 176 //window when the program shuts down. If you're not in debug mode this will 177 //be ignored. Use it as you will! 178 //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 179 #ifdef _CRT_SET 180 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 181 _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 182 _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 183 #endif 159 184 160 185 //Now just call this function at the start of your program and if you're -
GTP/trunk/Lib/Vis/Preprocessing/src/ply.h
r749 r2575 132 132 133 133 /* memory allocation */ 134 extern char *my_alloc( );134 extern char *my_alloc(int,int,char *); 135 135 #define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__) 136 136 … … 202 202 extern int equal_strings(char *, char *); 203 203 204 205 204 #ifdef __cplusplus 206 205 } … … 208 207 #endif /* !__PLY_H__ */ 209 208 210 -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r2574 r2575 117 117 Timer/BenchTimer.cpp Timer/merror.cpp \ 118 118 Intersectable.cpp TraversalTree.cpp ObjectPvs.cpp ObjectsParser.cpp \ 119 FilterBasedDistribution.cpp DifferenceSampling.cpp 119 FilterBasedDistribution.cpp DifferenceSampling.cpp HavranRayCaster.cpp 120 120 121 121 -
GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
r2574 r2575 3 3 4 4 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+" 5 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer --preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=500000 -total_samples=6000000"5 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=500000 -total_samples=6000000" 6 6 7 7
Note: See TracChangeset
for help on using the changeset viewer.