Changeset 2629 for GTP/trunk/Lib/Vis/Preprocessing/src/havran
- Timestamp:
- 01/23/08 00:21:50 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src/havran
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/havran/configh.h
r2610 r2629 13 13 #ifndef __CONFIGH_H__ 14 14 #define __CONFIGH_H__ 15 16 17 #if defined(_MSC_VER)18 // use perftimer only on msvc19 // define __SSE__ macro as it is not defined under MSVC20 #define __SSE__21 // If we support the use of SSE instructions for ray shooting22 //#define _USE_HAVRAN_SSE23 #endif24 15 25 16 #ifndef USE_GOLEM_NAMESPACE -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbai.cpp
r2592 r2629 218 218 219 219 // Maximum depth of the tree is set and stack is allocated 220 maxTreeDepth = 50;221 stackDepth = 2*maxTreeDepth;220 maxTreeDepth = MAX_HEIGHT; 221 stackDepth = maxTreeDepth + 2; 222 222 stackID = new GALIGN16 SInputData[stackDepth]; 223 223 assert(stackID); … … 1149 1149 int estHeight = (int)(log((float)initcnt)/log((float)2.0) + 0.9); 1150 1150 // cout << "EstHeight=" << estHeight << endl; 1151 maxDepthAllowed = (int)((float)estHeight * 1.2 + 2.0);1151 maxDepthAllowed = (int)((float)estHeight * 1.2f + 2.0f); 1152 1152 1153 1153 // maximum number of trials to further subdivide … … 1205 1205 } 1206 1206 } 1207 else { 1208 if (maxDepthAllowed >= MAX_HEIGHT) 1209 maxDepthAllowed = MAX_HEIGHT - 1; 1210 } 1207 1211 1208 1212 if (verbose) … … 1221 1225 if (objlist.size() == 0) 1222 1226 return 0; // nothing 1227 1228 // --------------------------------------------------- 1229 // Rewriting the triangles to the just wrappers to save 1230 // the memory during building!!!! 1231 bool useWrappers = false; 1232 if (useWrappers) { 1233 cout << "WARNING: using only wrappers, not objects to save the memory!" 1234 << endl; 1235 cout << "Size of(AxisAlignedBox3Intersectable) = " << sizeof(AxisAlignedBox3Intersectable) << endl; 1236 cout << "Size of(TriangleIntersectable) = " << sizeof(TriangleIntersectable) << endl; 1237 for (ObjectContainer::iterator it = objlist.begin(); 1238 it != objlist.end(); it++) { 1239 // take the triangle 1240 Intersectable *i = *it; 1241 // store the properties to new variables 1242 AxisAlignedBox3 b = i->GetBox(); 1243 int mId = i->mId; 1244 // delete the triangle 1245 delete i; 1246 // create the wrapper with the same box as triangle 1247 AxisAlignedBox3Intersectable *a = new AxisAlignedBox3Intersectable(b); 1248 a->mId = mId; 1249 // and put it back to the list of objects 1250 *it = a; 1251 } // for 1252 cout << "Rewriting to wrappers is finished!" << endl; 1253 } // if 1254 // --------------------------------------------------- 1255 1223 1256 // cerr<<"hh44"<<endl; 1224 1257 // initialize the whole box of the kd-tree and sort -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbai.h
r2582 r2629 20 20 #include "ktb8b.h" 21 21 #include "Containers.h" 22 #include "IntersectableWrapper.h" 22 23 23 24 namespace GtpVisibilityPreprocessor { … … 42 43 #endif 43 44 45 class AxisAlignedBox3Intersectable: 46 public IntersectableWrapper<AxisAlignedBox3> 47 { 48 public: 49 AxisAlignedBox3Intersectable(const AxisAlignedBox3 &item): 50 IntersectableWrapper<AxisAlignedBox3>(item) { } 51 52 AxisAlignedBox3 GetBox() const { return mItem;} 53 54 int Type() const 55 { 56 // This is not ture, but for our purposes it is OK 57 return Intersectable::TRIANGLE_INTERSECTABLE; 58 } 59 60 }; 61 62 // --------------------------------------------------------------- 44 63 // The base class for KD-tree with irregular change of axes, where 45 64 // the splitting plane can be positioned. … … 216 235 void Check1List(SInputData *data, int axis, int countExpected); 217 236 218 //---------------------------------------------------------------- ------237 //---------------------------------------------------------------- 219 238 // Termination criteria and fixing the splitting plane orientation 220 239 … … 230 249 CKTBAxes::Axes reqAxis; 231 250 232 // -------------- AUTOMATIC TERMINATION CRITERIA ---------------- -----251 // -------------- AUTOMATIC TERMINATION CRITERIA ---------------- 233 252 // the ratio of improvement for the cost by subdivision and not-subdividing 234 253 // for the previous subdivision … … 578 597 int startEmptyCutDepth; 579 598 599 // Biasing the empty cuts (no objects are split). The cost is multiplied 600 // by the coefficient which is assumed to be 0.8-0.9 601 float biasFreeCuts; 602 580 603 // ---------- Special improvements on the kd-tree construction -------- 581 604 // flag if to split bounding boxes during splitting … … 588 611 int minObjectsToCreateMinBox, minDepthDistanceBetweenMinBoxes; 589 612 float minSA2ratioMinBoxes; 590 // Biasing the empty cuts (no objects are split). The cost is multiplied591 // by the coefficient which is assumed to be 0.8-0.9592 float biasFreeCuts;593 613 // Make min box here 594 614 bool makeMinBoxHere; -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp
r2608 r2629 11 11 12 12 // GOLEM library 13 #include "ktbconf.h"14 13 #include "ktb.h" 15 14 #include "ktbai.h" 15 #include "ktbs.h" 16 16 #include "ktball.h" 17 17 #include "ktbtrav.h" … … 61 61 { 62 62 CKTBAllocManPredecessor *bc = 0; 63 bool useArray = true;63 bool useArray = false; 64 64 65 65 // this should be already initialised, but we want to be sure 66 66 if (useArray) { 67 cout << "Using kbt-tree based on arrays" << endl; 67 68 // the implementation based on arrays 68 69 bc = new CKTBABuildUp(); // file ktbai.cpp 69 70 } 70 71 else { 71 // the implementation based on lists 72 // bc = new CKTBBuildUp(); // file ktbi.cpp 72 cout << "Using kbt-tree based on sampling" << endl; 73 // the implementation based on sampling 74 bc = new CKTBSBuildUp(); // file ktbs.cpp 73 75 } 74 76 … … 425 427 void 426 428 CKTB::FindNearestI(RayPacket2x2 &raypack, 427 428 429 const Vector3 &boxmin, 430 const Vector3 &boxmax) 429 431 { 430 432 if (!makeMinBoxes) … … 766 768 } 767 769 768 770 771 static int 772 cntInterior = 0; 773 774 static int 775 cntInteriorA[4] = {0, 0, 0, 0}; 776 777 static int 778 cntLeaves = 0; 779 780 static int 781 cntEmptyLeaves = 0; 782 783 static int 784 objReferences = 0; 785 769 786 SKTBNodeT* 770 787 CKTB::ImportBinLeaf(IN_STREAM &stream, … … 775 792 int objId = leafId; 776 793 int size; 794 795 cntLeaves++; 777 796 778 797 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); … … 782 801 SKTBNodeT* leaf = buildClass->AllocLeaf(0); 783 802 *nodeToLink = buildClass->nodeToLink; 803 cntEmptyLeaves++; 784 804 return leaf; 785 805 } … … 790 810 791 811 ObjectContainer *newobjlist = new ObjectContainer; 812 813 objReferences += size; 792 814 793 815 // read object ids … … 826 848 } 827 849 828 829 850 SKTBNodeT * 830 851 CKTB::ImportBinInterior(IN_STREAM &stream, SKTBNodeT **nodeToLink) … … 839 860 buildClass->AllocInteriorNode(axis, pos, 0, 0); 840 861 *nodeToLink = buildClass->nodeToLink; 841 862 863 cntInterior++; 864 assert( (axis >= 0) && (axis < 3)); 865 cntInteriorA[axis]++; 866 842 867 return interiorNode; 843 868 } … … 928 953 929 954 if (!stream.is_open()) { 930 cerr << "Kd-tree description file (.k dh) cannot be opened for reading\n";955 cerr << "Kd-tree description file (.kbt) cannot be opened for reading\n"; 931 956 return true; // error 932 957 } … … 963 988 bc->InitAux(0, CKTBNodeAbstract::MAX_HEIGHT - 1, maxItemsAtOnce); 964 989 990 for(int i = 0; i < 4; i++) 991 cntInteriorA[i] = 0; 992 965 993 // Compute the box from all objects 966 994 bbox.Initialize(); … … 1040 1068 builtUp = true; 1041 1069 1070 cout << "Importing ktb-tree cntInterior = " 1071 << cntInterior << " cntLeaves = " << cntLeaves 1072 << " cntEmptyLeaves = " << cntEmptyLeaves << endl; 1073 1074 cout << "X-splits = " << cntInteriorA[0] << " Y-splits = " << cntInteriorA[1] 1075 << " Z-splits = " << cntInteriorA[2] << "\nref_to_objs/full_leaf = " 1076 << (float)objReferences/(cntLeaves - cntEmptyLeaves) << endl; 1077 1042 1078 return false; // OK 1043 1079 } -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.h
r2608 r2629 16 16 // GOLEM headers 17 17 #include "configh.h" 18 #include "ktbconf.h"19 18 //#include "ktbi.h" 20 19 #include "ktbai.h" … … 155 154 156 155 // allocate new build class and return it 157 staticCKTBAllocManPredecessor* AllocBuildClass();156 CKTBAllocManPredecessor* AllocBuildClass(); 158 157 159 158 CKTBNodeIteratorPredecessor* GetTraversalClass() { -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbconf.h
r2608 r2629 23 23 #endif 24 24 25 // If we support the use of SSE instructions for ray shooting 26 #define _USE_HAVRAN_SSE 25 27 26 28 namespace GtpVisibilityPreprocessor { -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbf2trv.cpp
r2608 r2629 57 57 results[i].intersectable; 58 58 SimpleRay::IntersectionRes[i + copyOffset].tdist = 59 SimpleRay::IntersectionRes[i + copyOffset].maxt = 59 60 results[i].tdist; 60 61 } // for i … … 204 205 FindNearestI(ray); 205 206 rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 206 rp.SetT(i, SimpleRay::IntersectionRes[0]. tdist);207 rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 207 208 // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 208 209 } // for … … 403 404 FindNearestI(ray); 404 405 rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 405 rp.SetT(i, SimpleRay::IntersectionRes[0]. tdist);406 rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 406 407 // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 407 408 } // for … … 414 415 void 415 416 CKTBTraversal::FindNearestI(RayPacket2x2 &rp, 416 417 417 const Vector3 &boxmin, 418 const Vector3 &boxmax) 418 419 { 419 420 static AxisAlignedBox3 localbox; … … 606 607 FindNearestI(ray, localbox); 607 608 rp.SetObject(i, SimpleRay::IntersectionRes[0].intersectable); 608 rp.SetT(i, SimpleRay::IntersectionRes[0]. tdist);609 rp.SetT(i, SimpleRay::IntersectionRes[0].maxt); 609 610 // SimpleRay::IntersectionRes[0].intersectable->GetNormal(0); 610 611 } // for -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbftrav.cpp
r2602 r2629 166 166 cout << "Full leaf HIT " << endl; 167 167 #endif 168 168 SimpleRay::IntersectionRes[0].tdist = 169 SimpleRay::IntersectionRes[0].maxt; 169 170 #ifdef __TRAVERSAL_STATISTICS 170 171 _allNodesTraversed += allNodesTraversed; … … 372 373 cout << "Full leaf HIT " << endl; 373 374 #endif 375 SimpleRay::IntersectionRes[0].tdist = 376 SimpleRay::IntersectionRes[0].maxt; 374 377 375 378 #ifdef __TRAVERSAL_STATISTICS … … 381 384 // We have to add the distance from the original ray origin 382 385 SimpleRay::IntersectionRes[0].tdist += tminOffset; 386 SimpleRay::IntersectionRes[0].maxt = SimpleRay::IntersectionRes[0].tdist; 383 387 384 388 // signed distance should be already set in TestFullLeaf … … 592 596 tmax + Limits::Small; 593 597 if (TestFullLeaf(rays[indexR+offset], currNode, indexR)) { 598 // copy the result to tdist 599 SimpleRay::IntersectionRes[indexR + rayOffset].tdist = 600 SimpleRay::IntersectionRes[indexR + rayOffset].maxt; 594 601 595 602 // we remove the ray from the calculation … … 599 606 #ifdef _DEBUGKTB 600 607 cout << "Full leaf HIT " << endl; 601 #endif 608 #endif 602 609 603 610 #ifdef __TRAVERSAL_STATISTICS -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbtrav.h
r2602 r2629 150 150 // of a packet to individual rays and traced individually. 151 151 virtual void FindNearestI(RayPacket2x2 &raypack) { } 152 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax) { } 152 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, 153 const Vector3 &boxMax) { } 153 154 #endif 154 155 … … 328 329 // of a packet to individual rays and traced individually. 329 330 virtual void FindNearestI(RayPacket2x2 &raypack); 330 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax); 331 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, 332 const Vector3 &boxMax); 331 333 #endif // __SSE__ 332 334 #endif // _USE_HAVRAN_SSE … … 421 423 // of a packet to individual rays and traced individually. 422 424 virtual void FindNearestI(RayPacket2x2 &raypack); 423 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, const Vector3 &boxMax); 425 virtual void FindNearestI(RayPacket2x2 &raypack, const Vector3 &boxMin, 426 const Vector3 &boxMax); 424 427 #endif // __SSE__ 425 428 #endif // _USE_HAVRAN_SSE -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/raypack.h
r2592 r2629 10 10 // 11 11 // Initial coding by Vlastimil Havran, 2006. The data design is in fact 12 // Jakko Biker layout as propose in the article on Intel Web Site in year 200512 // Jakko Biker layout as proposed in the article on Intel Web Site in year 2005 13 13 // http://www.intel.com/cd/ids/developer/asmo-na/eng/245711.htm?page=1 14 14 … … 21 21 22 22 #include "Vector3.h" 23 #include "Matrix4x4.h" 23 24 #include "ktbconf.h" 24 25 … … 88 89 // and also for shadow rays finish at the same object 89 90 const Intersectable *_stopObject = NULL 90 ) 91 { 91 ) { 92 92 // location 93 93 ox[0] = orf[0].x; ox[1] = orf[1].x; ox[2] = orf[2].x; ox[3] = orf[3].x; … … 182 182 int GetType() const { return ttype; } 183 183 184 void ApplyTransform(const Matrix4x4 &tform) { 185 for (int i = 0; i < 4; i++) { 186 Vector3 o_orig(ox[i], oy[i], oz[i]); 187 Vector3 t_orig = tform * o_orig; 188 ox[i] = t_orig.x; oy[i] = t_orig.y; oz[i] = t_orig.z; 189 Vector3 o_dir(dx[i], dy[i], dz[i]); 190 Vector3 t_dir = RotateOnly(tform, o_dir); 191 dx[i] = t_dir.x; dy[i] = t_dir.y; dz[i] = t_dir.z; 192 193 // ?? note that normalization to the unit size of the direction 194 // ?? is NOT computed -- this is what we want. 195 } 196 Precompute(); 197 } 198 184 199 // Reading and Setting origin of the ray and direction 185 200 // Ray origin -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/sbbox.h
r2582 r2629 146 146 147 147 inline bool Equal(const SBBox &b, float eps = 0.f) const; 148 148 149 // Returns the intersection of two axis-aligned boxes. 150 friend inline SBBox Intersect(const SBBox &x, const SBBox &y); 151 149 152 // Test if the box is really sensefull 150 153 bool IsCorrect(); … … 278 281 DescribeXYZ(const SBBox &b, std::ostream &app, int indent); 279 282 283 inline SBBox 284 Intersect(const SBBox &x, const SBBox &y) 285 { 286 SBBox ret = x; 287 if (OverlapS(ret, y)) { 288 Maximize(ret.pp[0], y.pp[0]); 289 Minimize(ret.pp[1], y.pp[1]); 290 return ret; 291 } 292 293 // Null intersection. 294 return SBBox(Vector3(0), Vector3(0)); 295 } 296 297 280 298 #if 1 281 299 // The implementation I, the first version implemented by Vlastimil … … 425 443 #endif 426 444 445 427 446 } 428 447 -
GTP/trunk/Lib/Vis/Preprocessing/src/havran/testrt.cpp
r2602 r2629 26 26 #include "GlobalLinesRenderer.h" 27 27 #include "RayCaster.h" 28 #include "Triangle3.h" 29 #include "IntersectableWrapper.h" 28 30 #include "timer.h" 29 31 #include "raypack.h" … … 64 66 extern void Cleanup(); 65 67 66 static string ReplaceSuffix(const string &filename, const string &a, const string &b) 68 void 69 _SortRays2(SimpleRayContainer &rays, 70 const int l, 71 const int r, 72 const int depth, 73 float box[12]) 67 74 { 68 string result = filename; 69 70 int pos = (int)filename.rfind(a, (int)filename.size() - 1); 71 if (pos == filename.size() - a.size()) 72 { 73 result.replace(pos, a.size(), b); 75 // pick-up a pivot 76 int axis; 77 78 float maxDiff = -1.0f; 79 // get the largest axis 80 int offset = 0; 81 int i; 82 83 //const int batchsize = 16384; 84 //const int batchsize = 8192; 85 //const int batchsize = 128; 86 const int batchsize = 4; 87 88 //if (r - l < 16*batchsize) 89 // offset = 3; 90 91 // if (depth%2==0) 92 // offset = 3; 93 94 for (i=offset; i < offset + 6; i++) { 95 float diff = box[i + 6] - box[i]; 96 assert(diff >= 0.f); 97 if (diff > maxDiff) { 98 // Find the maximum 99 maxDiff = diff; 100 axis = i; 101 } 102 } 103 104 // cout<<depth<<" "<<axis<<" "<<l<<" "<<r<<endl; 105 106 i=l; 107 int j=r; 108 109 float x = (box[axis] + box[axis+6])*0.5f; 110 // float x = rays[(l+r)/2].GetParam(axis); 111 do { 112 while(i<j && rays[i].GetParam(axis) < x) 113 i++; 114 while(i<j && x < rays[j].GetParam(axis)) 115 j--; 116 117 if (i <= j) { 118 swap(rays[i], rays[j]); 119 i++; 120 j--; 74 121 } 75 76 return result; 122 } while (i<=j); 123 124 125 if (l + batchsize < j ) { 126 // set new max 127 float save = box[axis+6]; 128 box[axis+6] = x; 129 _SortRays2(rays, l, j, depth+1, box); 130 box[axis+6] = save; 131 } else { 132 // for (int k=0; k < 6; k++) 133 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 134 } 135 136 if (i + batchsize < r) { 137 // set new min 138 box[axis] = x; 139 _SortRays2(rays, i, r, depth+1, box); 140 } else { 141 // for (int k=0; k < 6; k++) 142 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 143 } 77 144 } 78 145 79 80 static int SplitFilenames(const string &str, vector<string> &filenames)146 void 147 SortRays2(SimpleRayContainer &rays, const AxisAlignedBox3 &box) 81 148 { 82 int pos = 0; 83 84 while(1) { 85 int npos = (int)str.find(';', pos); 86 87 if (npos < 0 || npos - pos < 1) 88 break; 89 filenames.push_back(string(str, pos, npos - pos)); 90 pos = npos + 1; 91 } 92 93 filenames.push_back(string(str, pos, str.size() - pos)); 94 return (int)filenames.size(); 95 } 149 const float sizeBox = Magnitude(box.Diagonal()); 150 // This is some size of the 151 const float sizeDir = 0.1f * sizeBox; 152 153 float b[12]={ 154 box.Min().x, 155 box.Min().y, 156 box.Min().z, 157 -sizeDir, 158 -sizeDir, 159 -sizeDir, 160 box.Max().x, 161 box.Max().y, 162 box.Max().z, 163 sizeDir, 164 sizeDir, 165 sizeDir 166 }; 167 168 169 _SortRays2(rays, 0, (int)rays.size()-1, 0, b); 170 171 return; 172 } 96 173 97 174 … … 254 331 AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 255 332 AxisAlignedBox3 bbox = bboxOrig; 256 int sizeDiag = Magnitude(bbox.Diagonal());333 float sizeDiag = Magnitude(bbox.Diagonal()); 257 334 bbox.Enlarge(sizeDiag * 1.5f); 258 335 259 336 Vector3 origin, dir; 260 337 261 //#define WIEN1262 #define WIEN2338 #define WIEN1 339 //#define WIEN2 263 340 //#define ARENA1 264 341 … … 267 344 origin = Vector3(1099.9f, 183.0f, -387.0f); 268 345 dir = Vector3(-0.6f, 0.0001f, -0.8f); 346 //dir = -dir; 269 347 #define DIREXISTS 270 348 #endif … … 292 370 cout << "Computing image\n" << endl; 293 371 372 int id = preprocessor->mObjects.size() + 1; 373 374 //We add here a few objects 375 ObjectContainer dynObjects; 376 Vector3 baseVec = origin + dir * 2.0f; 377 Triangle3 tr1(baseVec, baseVec + Vector3(1, 0, 0), 378 baseVec + Vector3(0, 1, 0)); 379 TriangleIntersectable ti1(tr1); 380 dynObjects.push_back(&ti1); 381 ti1.mId = id+1; 382 383 tr1.Init(baseVec, baseVec + Vector3(1, 0, 0), 384 baseVec + Vector3(0, 0, 1)); 385 TriangleIntersectable ti2(tr1); 386 dynObjects.push_back(&ti2); 387 ti2.mId = id+2; 388 389 tr1.Init(baseVec, baseVec + Vector3(0, 1, 0), 390 baseVec + Vector3(0, 0, 1)); 391 TriangleIntersectable ti3(tr1); 392 dynObjects.push_back(&ti3); 393 ti3.mId = id+3; 394 294 395 #if 1 295 // ray by ray 296 cam.SnapImage("test-rays.tga", 297 preprocessor->mRayCaster, 298 bboxOrig, 299 preprocessor->mSceneGraph); 300 #endif 396 // This is required for cam.SnapImagePacket2 397 // otherwise dynamic object cannot be identified! 398 preprocessor->mObjects.push_back(&ti1); 399 preprocessor->mObjects.push_back(&ti2); 400 preprocessor->mObjects.push_back(&ti3); 401 #endif 402 403 if (0) { 404 Matrix4x4 mat; 405 mat = IdentityMatrix(); 406 mat = mat * TranslationMatrix(Vector3(-1, 0, 0)); 407 preprocessor->mRayCaster->AddDynamicObjecs(dynObjects, mat); 408 301 409 #if 1 302 // using ray packets303 cam.SnapImagePacket("test-packet.tga",304 305 306 410 // ray by ray 411 cam.SnapImage("test-rays.tga", 412 preprocessor->mRayCaster, 413 bboxOrig, 414 preprocessor->mSceneGraph); 307 415 #endif 308 416 #if 1 309 // using ray packets 310 cam.SnapImage2("test-oneDir.tga", 311 preprocessor->mRayCaster, 312 bboxOrig, 313 preprocessor->mSceneGraph); 314 #endif 417 // using ray packets 418 cam.SnapImage2("test-oneDir.tga", 419 preprocessor->mRayCaster, 420 bboxOrig, 421 preprocessor->mSceneGraph); 422 #endif 423 424 #if 1 425 #ifdef _USE_HAVRAN_SSE 426 // using ray packets 427 cam.SnapImagePacket("test-packet.tga", 428 preprocessor->mRayCaster, 429 bboxOrig, 430 preprocessor->mSceneGraph); 431 #endif 432 #endif 433 #if 1 434 // using ray packets 435 cam.SnapImagePacket2("test-packet4.tga", 436 preprocessor->mRayCaster, 437 bboxOrig, 438 preprocessor->mSceneGraph); 439 #endif 440 } 441 else { 442 cout << "Computing animation" << endl; 443 for (int i = 0; i < 20; i++) { 444 preprocessor->mRayCaster->DeleteDynamicObjects(); 445 Matrix4x4 mat; 446 mat = IdentityMatrix(); 447 mat = mat * TranslationMatrix(Vector3(-0.1*(float)i, 0, 0)); 448 preprocessor->mRayCaster->AddDynamicObjecs(dynObjects, mat); 449 char name[200]; 450 #if 1 451 // ray by ray 452 sprintf(name, "test-rays-%03d.tga", i); 453 cam.SnapImage(name, 454 preprocessor->mRayCaster, 455 bboxOrig, 456 preprocessor->mSceneGraph); 457 #endif 458 #if 1 459 // using ray packets 460 sprintf(name, "test-oneDir-%03d.tga", i); 461 cam.SnapImage2(name, 462 preprocessor->mRayCaster, 463 bboxOrig, 464 preprocessor->mSceneGraph); 465 #endif 466 467 #if 1 468 #ifdef _USE_HAVRAN_SSE 469 // using ray packets 470 sprintf(name, "test-packet-%03d.tga", i); 471 cam.SnapImagePacket(name, 472 preprocessor->mRayCaster, 473 bboxOrig, 474 preprocessor->mSceneGraph); 475 #endif 476 #endif 477 #if 1 478 // using ray packets 479 sprintf(name, "test-packet4-%03d.tga", i); 480 cam.SnapImagePacket2(name, 481 preprocessor->mRayCaster, 482 bboxOrig, 483 preprocessor->mSceneGraph); 484 #endif 485 } // for 486 } // animation 487 315 488 316 489 cout << "Done\n" << endl; … … 327 500 }; 328 501 502 329 503 // This is for testing RT implementation 330 504 void … … 427 601 int cntMaxRays = 100000; 428 602 Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 429 vector<SimpleRay>rays;603 SimpleRayContainer rays; 430 604 SimpleRay rayTest; 431 605 vector<RESult> results; … … 475 649 if (castDoubleRays) 476 650 mult = 2.0; 477 651 652 cout << "Press a key to start ray shooting" << endl; 653 getchar(); 654 cout << "Ray shooting " << cntRays << " rays started - " 655 << (castDoubleRays ? " double " : " single ") 656 << " dir " << endl; 657 658 AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox(); 659 660 cout << "Sorting rays " << endl; 661 662 CTimer timer; 663 timer.Reset(); 664 timer.Start(); 665 long t1 = GetTime(); 666 667 //SortRays2(rays, bboxOrig); 668 669 timer.Stop(); 670 long t2 = GetTime(); 671 cout<<"\n#SORTING_TIME = "; 672 cout << TimeDiff(t1, t2)<<" [mikrosec]" 673 << " userTime = " << timer.UserTime() << " realTime = " 674 << timer.RealTime() << endl; 675 478 676 cout << "Starting to shoot " << cntRays * mult << " rays" << endl; 677 timer.Start(); 479 678 480 679 RayCaster *raycaster = preprocessor->mRayCaster; 481 680 VssRayContainer vssRays; 482 AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox();483 681 484 682 //#define DEBUGRESULTS … … 494 692 #endif 495 693 496 cout << "Press a key to start ray shooting" << endl;497 getchar();498 cout << "Ray shooting " << cntRays << " rays started - "499 << (castDoubleRays ? " double " : " single ")500 << " dir " << endl;501 502 long t1 = GetTime();503 CTimer timer;504 timer.Reset();505 timer.Start();506 507 694 SimpleRayContainer raysToTest; 508 695 for (int i = 0; i < cntRays - 16; i++) { 696 509 697 #if 0 510 698 int res = raycaster->CastRay(rays[i], … … 573 761 574 762 timer.Stop(); 575 longt2 = GetTime();576 cout<<"\n# RAY_CAST_TIME = ";763 t2 = GetTime(); 764 cout<<"\n#SORTING + RAY_CAST_TIME = "; 577 765 cout << TimeDiff(t1, t2)<<" [mikrosec]" 578 766 << " userTime = " << timer.UserTime() << " realTime = " … … 695 883 int cntMaxRays = 100000; 696 884 Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 697 vector<SimpleRay>rays;885 SimpleRayContainer rays; 698 886 SimpleRay rayTest; 699 887 vector<RESult> results; … … 957 1145 int cntMaxRays = 100000; 958 1146 Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays); 959 vector<SimpleRay>rays;1147 SimpleRayContainer rays; 960 1148 SimpleRay rayTest; 961 1149 vector<RESult> results; … … 1038 1226 timer.Start(); 1039 1227 Vector3 boxMin, boxMax; 1228 1229 bool printOut = false; 1040 1230 1041 1231 SimpleRayContainer raysToTest; … … 1056 1246 origin4, direction4, 1057 1247 result4, dist4); 1058 printf("I %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f\n", 1059 boxMin.x, boxMin.y, boxMin.z, boxMax.x, boxMax.y, boxMax.z); 1248 if (printOut) { 1249 printf("I %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f\n", 1250 boxMin.x, boxMin.y, boxMin.z, boxMax.x, boxMax.y, boxMax.z); 1251 } 1060 1252 1061 1253 for (int j = 0; j < 4; j++) { 1062 printf("%d %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f %d %4.7f\n", 1063 i+j, 1064 origin4[j].x, 1065 origin4[j].y, 1066 origin4[j].z, 1067 direction4[j].x, 1068 direction4[j].y, 1069 direction4[j].z, 1070 (result4[j] != -1) ? 1 : 0, 1071 (result4[j] != -1) ? dist4[j] : 0); 1254 #if 0 1255 if (result4[j] == 0) { 1256 int res = raycaster->CastRay(rays[i+j], 1257 vssRays, 1258 bboxOrig, 1259 false, 1260 true); 1261 if (res) { 1262 float tdist = SimpleRay::IntersectionRes[0].tdist; 1263 Vector3 point = rays[i+j].Extrap(tdist); 1264 AxisAlignedBox3 testbox(boxMin, boxMax); 1265 1266 if (testbox.IsInside(point)) { 1267 cout << "Error in the algorithm - computed not in the box, but" 1268 << " it is later found in the box" << endl; 1269 cout << " j = " << j << endl; 1270 cout << " box = " << testbox << endl; 1271 cout << " point = " << point << endl; 1272 raycaster->CastRaysPacket4(boxMin, boxMax, 1273 origin4, direction4, 1274 result4, dist4); 1275 } 1276 } 1277 } 1278 #endif 1279 1280 if (printOut) { 1281 printf("%d %4.7f %4.7f %4.7f %4.7f %4.7f %4.7f %d %4.7f\n", 1282 i+j, 1283 origin4[j].x, 1284 origin4[j].y, 1285 origin4[j].z, 1286 direction4[j].x, 1287 direction4[j].y, 1288 direction4[j].z, 1289 (result4[j] != -1) ? 1 : 0, 1290 (result4[j] != -1) ? dist4[j] : 0); 1291 } 1072 1292 } // for j 1073 1293 } // for i
Note: See TracChangeset
for help on using the changeset viewer.