Changeset 2629 for GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
- Timestamp:
- 01/23/08 00:21:50 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r2592 r2629 5 5 #include "ViewCellsManager.h" 6 6 7 #include <cassert> 7 8 8 9 namespace GtpVisibilityPreprocessor { … … 178 179 //const int batchsize = 16384; 179 180 const int batchsize = 8192; 180 // const int batchsize = 1024;181 181 //const int batchsize = 128; 182 182 … … 238 238 } 239 239 240 241 void 242 RayCaster::SortRays2(SimpleRayContainer &rays) 243 { 244 AxisAlignedBox3 box = 245 mPreprocessor.mViewCellsManager->GetViewSpaceBox(); 246 247 const float sizeBox = Magnitude(box.Diagonal()); 248 // This is some size of the 249 const float sizeDir = 0.2f * sizeBox; 250 251 float b[12]={ 252 box.Min().x, 253 box.Min().y, 254 box.Min().z, 255 -sizeDir, 256 -sizeDir, 257 -sizeDir, 258 box.Max().x, 259 box.Max().y, 260 box.Max().z, 261 sizeDir, 262 sizeDir, 263 sizeDir 264 }; 265 266 #if 0 267 static vector<SimpleRay *> pointerArray; 268 269 if (pointerArray.size()!=rays.size()) { 270 // realloc the pointerarray 271 pointerArray.resize(rays.size()); 272 } 273 274 // init pointer array 275 SimpleRay *p = &pointerArray[0]; 276 for (i=0; i < rays.size(); i++, p++) 277 pointerArray[i] = p; 278 #endif 279 280 _SortRays2(rays, 0, (int)rays.size()-1, 0, b); 281 282 return; 283 } 240 284 285 void 286 RayCaster::_SortRays2(SimpleRayContainer &rays, 287 const int l, 288 const int r, 289 const int depth, 290 float box[12]) 291 { 292 // pick-up a pivot 293 int axis; 294 295 float maxDiff = -1.0f; 296 // get the largest axis 297 int offset = 0; 298 int i; 299 300 //const int batchsize = 16384; 301 //const int batchsize = 8192; 302 const int batchsize = 128; 303 304 //if (r - l < 16*batchsize) 305 // offset = 3; 306 307 // if (depth%2==0) 308 // offset = 3; 309 310 for (i=offset; i < offset + 6; i++) { 311 float diff = box[i + 6] - box[i]; 312 assert(diff >= 0.f); 313 if (diff > maxDiff) { 314 // Find the maximum 315 maxDiff = diff; 316 axis = i; 317 } 318 } 319 320 // cout<<depth<<" "<<axis<<" "<<l<<" "<<r<<endl; 321 322 i=l; 323 int j=r; 324 325 float x = (box[axis] + box[axis+6])*0.5f; 326 // float x = rays[(l+r)/2].GetParam(axis); 327 do { 328 while(i<j && rays[i].GetParam(axis) < x) 329 i++; 330 while(i<j && x < rays[j].GetParam(axis)) 331 j--; 332 333 if (i <= j) { 334 swap(rays[i], rays[j]); 335 i++; 336 j--; 337 } 338 } while (i<=j); 339 340 341 if (l + batchsize < j ) { 342 // set new max 343 float save = box[axis+6]; 344 box[axis+6] = x; 345 _SortRays2(rays, l, j, depth+1, box); 346 box[axis+6] = save; 347 } else { 348 // for (int k=0; k < 6; k++) 349 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 350 } 351 352 if (i + batchsize < r) { 353 // set new min 354 box[axis] = x; 355 _SortRays2(rays, i, r, depth+1, box); 356 } else { 357 // for (int k=0; k < 6; k++) 358 // cout<<k<<" "<<box[k]<<" - "<<box[k+6]<<endl; 359 } 360 361 } 362 363 241 364 VssRay *RayCaster::RequestRay(const Vector3 &origin, 242 365 const Vector3 &termination,
Note: See TracChangeset
for help on using the changeset viewer.