[2595] | 1 | #define USE_THREADS 0
|
---|
| 2 |
|
---|
| 3 | #ifdef UNICODE
|
---|
| 4 | #undef UNICODE
|
---|
| 5 | #endif
|
---|
| 6 |
|
---|
| 7 | #define NOMINMAX
|
---|
| 8 | #ifdef __WINDOWS__
|
---|
| 9 | #include <windows.h>
|
---|
| 10 | #ifdef _CRT_SET
|
---|
| 11 | #include <crtdbg.h>
|
---|
| 12 | #endif // _CRT_SET
|
---|
| 13 | #endif
|
---|
| 14 | #include <cstdio>
|
---|
| 15 |
|
---|
| 16 | #include "Camera.h"
|
---|
| 17 | #include "PreprocessorFactory.h"
|
---|
| 18 | #include "Parser.h"
|
---|
| 19 | #include "Environment.h"
|
---|
| 20 | #include "MeshKdTree.h"
|
---|
| 21 | #include "Preprocessor.h"
|
---|
| 22 | #include "common.h"
|
---|
| 23 | #include "PreprocessorThread.h"
|
---|
| 24 | #include "ObjExporter.h"
|
---|
| 25 | #include "SceneGraph.h"
|
---|
| 26 | #include "GlobalLinesRenderer.h"
|
---|
| 27 | #include "RayCaster.h"
|
---|
| 28 | #include "timer.h"
|
---|
| 29 | #include "raypack.h"
|
---|
| 30 |
|
---|
| 31 | #include "ViewCellsManager.h"
|
---|
| 32 |
|
---|
| 33 | #ifdef USE_QT
|
---|
| 34 | #include "QtPreprocessorThread.h"
|
---|
| 35 | #include "QtGlViewer.h"
|
---|
| 36 | #include "QtGlRenderer.h"
|
---|
| 37 | #else
|
---|
| 38 | #if USE_THREADS
|
---|
[2602] | 39 | #include "BoostPreprocessorThread.h"
|
---|
[2595] | 40 | #endif
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
| 43 | #include "ResourceManager.h"
|
---|
| 44 | #include "GlRenderer.h"
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | #define USE_EXE_PATH false
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | using namespace GtpVisibilityPreprocessor;
|
---|
| 51 |
|
---|
| 52 | //Preprocessor *preprocessor = NULL;
|
---|
| 53 | extern GlRendererWidget *rendererWidget;
|
---|
| 54 | //GlobalLinesRenderer *globalLinesRenderer = NULL;
|
---|
| 55 |
|
---|
| 56 | // DLL function signature
|
---|
| 57 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | // Flag if the ray should be single sided (one direction)
|
---|
| 61 | // or double sided (shooting ray in both directions)
|
---|
| 62 | static bool castDoubleRays;
|
---|
| 63 |
|
---|
| 64 | extern void Cleanup();
|
---|
| 65 |
|
---|
| 66 | static string ReplaceSuffix(const string &filename, const string &a, const string &b)
|
---|
| 67 | {
|
---|
| 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);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | return result;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | static int SplitFilenames(const string &str, vector<string> &filenames)
|
---|
| 81 | {
|
---|
| 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 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | static string GetInternFilename(const string &filename, const string newSuffix)
|
---|
| 99 | {
|
---|
| 100 | vector<string> filenames;
|
---|
| 101 | const int files = SplitFilenames(filename, filenames);
|
---|
| 102 |
|
---|
| 103 | vector<string>::const_iterator sit, sit_end = filenames.end();
|
---|
| 104 | string kdFilename;
|
---|
| 105 |
|
---|
| 106 | int i = 0;
|
---|
| 107 | for (sit = filenames.begin(); sit != sit_end; ++ sit, ++ i)
|
---|
| 108 | {
|
---|
| 109 | string currentFile = *sit;
|
---|
| 110 | string strippedFilename;
|
---|
| 111 |
|
---|
| 112 | if (i == 0)
|
---|
| 113 | {
|
---|
| 114 | strippedFilename = currentFile;
|
---|
| 115 | }
|
---|
| 116 | else
|
---|
| 117 | {
|
---|
| 118 | char *str = StripPath(currentFile.c_str());
|
---|
| 119 | strippedFilename = string(str);
|
---|
| 120 |
|
---|
| 121 | delete [] str;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | string suffix("_");
|
---|
| 125 |
|
---|
| 126 | if (i == (int)filenames.size() - 1)
|
---|
| 127 | {
|
---|
| 128 | suffix = newSuffix;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | if (strstr(strippedFilename.c_str(), ".x3d"))
|
---|
| 132 | {
|
---|
| 133 | kdFilename += ReplaceSuffix(strippedFilename, ".x3d", suffix);
|
---|
| 134 | }
|
---|
| 135 | else if (strstr(strippedFilename.c_str(), ".dat"))
|
---|
| 136 | {
|
---|
| 137 | kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix);
|
---|
| 138 | }
|
---|
| 139 | else if (strstr(strippedFilename.c_str(), ".obj"))
|
---|
| 140 | {
|
---|
| 141 | kdFilename += ReplaceSuffix(strippedFilename, ".obj", suffix);
|
---|
| 142 | }
|
---|
| 143 | else
|
---|
| 144 | {
|
---|
| 145 | cerr << "Error: Currently unsupported format for kd, filename " << currentFile << endl;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | //cout << "kdfilename: " << kdFilename << endl;
|
---|
| 150 | return kdFilename;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | // -------------------------------------------------------
|
---|
| 155 | // Written by Vlastimil Havran
|
---|
| 156 |
|
---|
| 157 | // This is for testing RT implementation
|
---|
| 158 | void
|
---|
| 159 | TestRTcamera(int argc, char **argv)
|
---|
| 160 | {
|
---|
| 161 | int returnCode = 0;
|
---|
| 162 |
|
---|
| 163 | InitTiming();
|
---|
| 164 | Debug.open("debug.log");
|
---|
| 165 |
|
---|
| 166 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 167 | MeshKdTree::ParseEnvironment();
|
---|
| 168 |
|
---|
| 169 | char buff[128];
|
---|
| 170 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 171 | string preprocessorType(buff);
|
---|
| 172 |
|
---|
| 173 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
| 174 | {
|
---|
| 175 | Environment::DelSingleton();
|
---|
| 176 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 177 | exit(1);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 182 | string filename(buff);
|
---|
| 183 |
|
---|
| 184 | const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
| 185 | const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ?
|
---|
| 186 | ".kdm" : ".kdt");
|
---|
| 187 |
|
---|
| 188 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
| 189 | {
|
---|
| 190 | cout << "ray casting initialized!" << endl;
|
---|
| 191 | }
|
---|
| 192 | else
|
---|
| 193 | {
|
---|
| 194 | cout << "ray casting initialization failed!" << endl;
|
---|
| 195 | Cleanup();
|
---|
| 196 | exit(1);
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | //Debug << "using pvs type " << PVS_TYPE << endl;
|
---|
| 200 |
|
---|
| 201 | /////////////
|
---|
| 202 | //-- load scene
|
---|
| 203 |
|
---|
| 204 | if (!preprocessor->LoadScene(filename))
|
---|
| 205 | {
|
---|
| 206 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 207 | Cleanup();
|
---|
| 208 | exit(1);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | ////////////
|
---|
| 212 | //-- initialize external ray caster
|
---|
| 213 |
|
---|
| 214 | if (preprocessor->LoadInternKdTree(internKdTree))
|
---|
| 215 | {
|
---|
| 216 | cout << "intern kd tree loaded!" << endl;
|
---|
| 217 | }
|
---|
| 218 | else
|
---|
| 219 | {
|
---|
| 220 | cout << "loading intern kd tree failed!" << endl;
|
---|
| 221 | Cleanup();
|
---|
| 222 | exit(1);
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | // export objects as obj
|
---|
| 226 | if (preprocessor->mExportObj)
|
---|
| 227 | {
|
---|
| 228 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 229 | {
|
---|
| 230 | cerr << "already in obj format" << endl;
|
---|
| 231 | if (0) preprocessor->ExportObj("test.obj", preprocessor->mObjects);
|
---|
| 232 | }
|
---|
| 233 | else
|
---|
| 234 | {
|
---|
| 235 |
|
---|
| 236 | const string objname = GetInternFilename(filename, ".obj");
|
---|
| 237 |
|
---|
| 238 | cout << "exporting scene to " << objname << endl;
|
---|
| 239 | bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | if (success)
|
---|
| 243 | cout << "finished exporting obj" << endl;
|
---|
| 244 | else
|
---|
| 245 | cerr << "error exporting " << objname << endl;
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | int width = 1000;
|
---|
| 250 | int height = 500;
|
---|
| 251 | float fieldOfView = 115.f;
|
---|
| 252 | Camera cam(width, height, fieldOfView);
|
---|
| 253 |
|
---|
| 254 | AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox();
|
---|
| 255 | AxisAlignedBox3 bbox = bboxOrig;
|
---|
| 256 | int sizeDiag = Magnitude(bbox.Diagonal());
|
---|
| 257 | bbox.Enlarge(sizeDiag * 1.5f);
|
---|
| 258 |
|
---|
| 259 | Vector3 origin, dir;
|
---|
| 260 |
|
---|
| 261 | //#define WIEN1
|
---|
| 262 | #define WIEN2
|
---|
| 263 | //#define ARENA1
|
---|
| 264 |
|
---|
| 265 | #ifdef WIEN1
|
---|
| 266 | // 1099.9 183.0 -387
|
---|
| 267 | origin = Vector3(1099.9f, 183.0f, -387.0f);
|
---|
| 268 | dir = Vector3(-0.6f, 0.0001f, -0.8f);
|
---|
| 269 | #define DIREXISTS
|
---|
| 270 | #endif
|
---|
| 271 | #ifdef WIEN2
|
---|
| 272 | // 935.6 215.8 -1012.3
|
---|
| 273 | origin = Vector3(935.6, 215.8, -1012.4);
|
---|
| 274 | dir = Vector3(0.01f, 0.01f, 1.0f);
|
---|
| 275 | #define DIREXISTS
|
---|
| 276 | #endif
|
---|
| 277 | #ifdef ARENA1
|
---|
| 278 | origin = Vector3(22.16, 19.63, -950.44);
|
---|
| 279 | dir = Vector3(0.9, 0.001f, -0.5f);
|
---|
| 280 | #define DIREXISTS
|
---|
| 281 | #endif
|
---|
| 282 |
|
---|
| 283 | cam.SetPosition(origin);
|
---|
| 284 |
|
---|
| 285 | #ifndef DIREXISTS
|
---|
| 286 | Vector3 center = bbox.Center();
|
---|
| 287 | dir = center - origin;
|
---|
| 288 | #endif
|
---|
| 289 |
|
---|
| 290 | dir.Normalize();
|
---|
| 291 | cam.SetDirection(dir);
|
---|
| 292 | cout << "Computing image\n" << endl;
|
---|
| 293 |
|
---|
| 294 | #if 1
|
---|
| 295 | // ray by ray
|
---|
| 296 | cam.SnapImage("test-rays.tga",
|
---|
| 297 | preprocessor->mRayCaster,
|
---|
| 298 | bboxOrig,
|
---|
| 299 | preprocessor->mSceneGraph);
|
---|
| 300 | #endif
|
---|
| 301 | #if 1
|
---|
| 302 | // using ray packets
|
---|
| 303 | cam.SnapImagePacket("test-packet.tga",
|
---|
| 304 | preprocessor->mRayCaster,
|
---|
| 305 | bboxOrig,
|
---|
| 306 | preprocessor->mSceneGraph);
|
---|
| 307 | #endif
|
---|
| 308 | #if 1
|
---|
| 309 | // using ray packets
|
---|
| 310 | cam.SnapImage2("test-oneDir.tga",
|
---|
| 311 | preprocessor->mRayCaster,
|
---|
| 312 | bboxOrig,
|
---|
| 313 | preprocessor->mSceneGraph);
|
---|
| 314 | #endif
|
---|
| 315 |
|
---|
| 316 | cout << "Done\n" << endl;
|
---|
| 317 | return;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | struct RESult {
|
---|
| 321 | int hitA;
|
---|
| 322 | float hitAT;
|
---|
| 323 | int hitB;
|
---|
| 324 | float hitBT;
|
---|
| 325 | RESult(int hA, float tA, int hB, float tB):
|
---|
| 326 | hitA(hA), hitAT(tA), hitB(hB), hitBT(tB) { }
|
---|
| 327 | };
|
---|
| 328 |
|
---|
| 329 | // This is for testing RT implementation
|
---|
| 330 | void
|
---|
| 331 | TestRTfromFile(int argc, char **argv)
|
---|
| 332 | {
|
---|
| 333 | int returnCode = 0;
|
---|
| 334 |
|
---|
| 335 | InitTiming();
|
---|
| 336 | Debug.open("debug.log");
|
---|
| 337 |
|
---|
| 338 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 339 | MeshKdTree::ParseEnvironment();
|
---|
| 340 |
|
---|
| 341 | char buff[128];
|
---|
| 342 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 343 | string preprocessorType(buff);
|
---|
| 344 |
|
---|
| 345 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
| 346 | {
|
---|
| 347 | Environment::DelSingleton();
|
---|
| 348 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 349 | exit(1);
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 |
|
---|
| 353 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 354 | string filename(buff);
|
---|
| 355 |
|
---|
| 356 | const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
| 357 | const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ?
|
---|
| 358 | ".kdm" : ".kdt");
|
---|
| 359 |
|
---|
| 360 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
| 361 | {
|
---|
| 362 | cout << "ray casting initialized!" << endl;
|
---|
| 363 | }
|
---|
| 364 | else
|
---|
| 365 | {
|
---|
| 366 | cout << "ray casting initialization failed!" << endl;
|
---|
| 367 | Cleanup();
|
---|
| 368 | exit(1);
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | //Debug << "using pvs type " << PVS_TYPE << endl;
|
---|
| 372 |
|
---|
| 373 | /////////////
|
---|
| 374 | //-- load scene
|
---|
| 375 |
|
---|
| 376 | if (!preprocessor->LoadScene(filename))
|
---|
| 377 | {
|
---|
| 378 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 379 | Cleanup();
|
---|
| 380 | exit(1);
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | ////////////
|
---|
| 384 | //-- initialize external ray caster
|
---|
| 385 |
|
---|
| 386 | if (preprocessor->LoadInternKdTree(internKdTree))
|
---|
| 387 | {
|
---|
| 388 | cout << "intern kd tree loaded!" << endl;
|
---|
| 389 | }
|
---|
| 390 | else
|
---|
| 391 | {
|
---|
| 392 | cout << "loading intern kd tree failed!" << endl;
|
---|
| 393 | Cleanup();
|
---|
| 394 | exit(1);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | // export objects as obj
|
---|
| 398 | if (preprocessor->mExportObj)
|
---|
| 399 | {
|
---|
| 400 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 401 | {
|
---|
| 402 | cerr << "already in obj format" << endl;
|
---|
| 403 | if (0) preprocessor->ExportObj("test.obj", preprocessor->mObjects);
|
---|
| 404 | }
|
---|
| 405 | else
|
---|
| 406 | {
|
---|
| 407 | const string objname = GetInternFilename(filename, ".obj");
|
---|
| 408 |
|
---|
| 409 | cout << "exporting scene to " << objname << endl;
|
---|
| 410 | bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);
|
---|
| 411 |
|
---|
| 412 | if (success)
|
---|
| 413 | cout << "finished exporting obj" << endl;
|
---|
| 414 | else
|
---|
| 415 | cerr << "error exporting " << objname << endl;
|
---|
| 416 | }
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | Environment::GetSingleton()->GetStringValue("Rays.file", buff);
|
---|
| 420 | FILE *fp = fopen(buff, "rb");
|
---|
| 421 | if (!fp) {
|
---|
| 422 | cerr << "ERROR: file " << buff << " cannot be opened for reading" << endl;
|
---|
| 423 | cerr << "EXITING" << endl;
|
---|
| 424 | exit(3);
|
---|
| 425 | }
|
---|
| 426 | cout << "File " << buff << " was opened successfully" << endl;
|
---|
| 427 | int cntMaxRays = 100000;
|
---|
| 428 | Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays);
|
---|
| 429 | vector<SimpleRay> rays;
|
---|
| 430 | SimpleRay rayTest;
|
---|
| 431 | vector<RESult> results;
|
---|
| 432 |
|
---|
| 433 | int cntRays = 0;
|
---|
| 434 | for (int i = 0; cntRays < cntMaxRays; i++) {
|
---|
| 435 | int ch = fgetc(fp);
|
---|
| 436 | switch (ch) {
|
---|
| 437 | case 'G': { // two-sided rays of 16
|
---|
| 438 | for (int j = 0; j < 16; j++) {
|
---|
| 439 | int order;
|
---|
| 440 | float ox, oy, oz, dx, dy, dz;
|
---|
| 441 | int hitA; float hitAT;
|
---|
| 442 | int hitB; float hitBT;
|
---|
| 443 | if (fscanf(fp, "%d %f %f %f %f %f %f %d %f %d %f\n",
|
---|
| 444 | &order, &ox, &oy, &oz, &dx, &dy, &dz, &hitA, &hitAT, &hitB, &hitBT) != 11) {
|
---|
| 445 | cerr << "Problem parsing the ray file" << endl;
|
---|
| 446 | cerr << "EXITING for ray order" << order << endl;
|
---|
| 447 | goto FINISH;
|
---|
| 448 | }
|
---|
| 449 | Vector3 mPosition(ox, oy, oz);
|
---|
| 450 | Vector3 mDirection(dx, dy, dz);
|
---|
| 451 | rayTest.Set(mPosition, mDirection, 0, 1.0, true);
|
---|
| 452 | rays.push_back(rayTest);
|
---|
| 453 | results.push_back(RESult(hitA, hitAT, hitB, hitBT));
|
---|
| 454 | cntRays++;
|
---|
| 455 | }
|
---|
| 456 | break;
|
---|
| 457 | }
|
---|
| 458 | case 'H': // one-sided rays of 16
|
---|
| 459 | cerr << "Not yet implemented " << endl; abort();
|
---|
| 460 |
|
---|
| 461 | case 'D': // two-sided ray
|
---|
| 462 | cerr << "Not yet implemented " << endl; abort();
|
---|
| 463 |
|
---|
| 464 | case 'S': // one-sided ray
|
---|
| 465 | cerr << "Not yet implemented " << endl; abort();
|
---|
| 466 | } // switch
|
---|
| 467 | } // for i
|
---|
| 468 |
|
---|
| 469 | FINISH:
|
---|
| 470 | fclose(fp);
|
---|
| 471 |
|
---|
| 472 | Environment::GetSingleton()->GetBoolValue("TestDoubleRays", castDoubleRays);
|
---|
| 473 |
|
---|
| 474 | double mult = 1.0;
|
---|
| 475 | if (castDoubleRays)
|
---|
| 476 | mult = 2.0;
|
---|
| 477 |
|
---|
| 478 | cout << "Starting to shoot " << cntRays * mult << " rays" << endl;
|
---|
| 479 |
|
---|
| 480 | RayCaster *raycaster = preprocessor->mRayCaster;
|
---|
| 481 | VssRayContainer vssRays;
|
---|
| 482 | AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox();
|
---|
| 483 |
|
---|
| 484 | //#define DEBUGRESULTS
|
---|
| 485 |
|
---|
| 486 | #ifdef DEBUGRESULTS
|
---|
| 487 | int cntIntelYesWeNo = 0;
|
---|
| 488 | int cntIntelNoWeYes = 0;
|
---|
| 489 | int cntIntelOurDistMismatch = 0;
|
---|
| 490 | bool printOut = false;
|
---|
[2602] | 491 | double sumDistIntel = 0.f;
|
---|
| 492 | double sumDistOurAlg = 0.f;
|
---|
[2595] | 493 | double sumDistAbsDiff = 0.f;
|
---|
| 494 | #endif
|
---|
| 495 |
|
---|
| 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 | SimpleRayContainer raysToTest;
|
---|
| 508 | for (int i = 0; i < cntRays - 16; i++) {
|
---|
| 509 | #if 0
|
---|
| 510 | int res = raycaster->CastRay(rays[i],
|
---|
| 511 | vssRays,
|
---|
| 512 | bboxOrig,
|
---|
| 513 | castDoubleRays, // castDoubleRay,
|
---|
| 514 | false); // pruneInvalidRays
|
---|
| 515 | #else
|
---|
| 516 | raysToTest.erase(raysToTest.begin(), raysToTest.end());
|
---|
| 517 | for (int j = 0; j < 16; j++, i++) {
|
---|
| 518 | raysToTest.push_back(rays[i]);
|
---|
| 519 | }
|
---|
| 520 | #if 0
|
---|
| 521 | for (int j = 0; j < 16; j++) {
|
---|
| 522 | cout << "orig = " << raysToTest[j].mOrigin << " dir = "
|
---|
| 523 | << raysToTest[j].mDirection << endl;
|
---|
| 524 | }
|
---|
| 525 | #endif
|
---|
| 526 |
|
---|
| 527 | raycaster->CastRays16(raysToTest,
|
---|
| 528 | vssRays,
|
---|
| 529 | bboxOrig,
|
---|
| 530 | castDoubleRays,
|
---|
| 531 | false);
|
---|
| 532 | #endif
|
---|
| 533 |
|
---|
| 534 | #ifdef DEBUGRESULTS
|
---|
| 535 | if (!castDoubleRays) {
|
---|
| 536 | float T = rays[i].IntersectionRes[0].tdist;
|
---|
| 537 | if ( (res != results[i].hitA) ||
|
---|
[2602] | 538 | ((res)&&(results[i].hitA)&& (fabs(T - results[i].hitAT)) > 0.1f)
|
---|
[2595] | 539 | )
|
---|
| 540 | {
|
---|
| 541 | if (printOut)
|
---|
| 542 | cout << " i = " << i << " ";
|
---|
| 543 | if ((res != 0) && (results[i].hitA == 0)) {
|
---|
| 544 | cntIntelNoWeYes++;
|
---|
| 545 | if (printOut)
|
---|
| 546 | cout << "Intel no intersection, our alg intersection at t = " << T << endl;
|
---|
| 547 | }
|
---|
| 548 | else {
|
---|
[2602] | 549 | if ((res == 0) && (results[i].hitA)) {
|
---|
[2595] | 550 | cntIntelYesWeNo++;
|
---|
| 551 | if (printOut)
|
---|
| 552 | cout << "Intel intersection at = " << results[i].hitAT
|
---|
| 553 | << " , our alg no intersection = " << endl;
|
---|
| 554 |
|
---|
| 555 | }
|
---|
| 556 | else {
|
---|
| 557 | cntIntelOurDistMismatch++;
|
---|
| 558 | sumDistOurAlg += T;
|
---|
| 559 | sumDistIntel += results[i].hitAT;
|
---|
| 560 | sumDistAbsDiff += fabs(T - results[i].hitAT);
|
---|
| 561 | if (printOut)
|
---|
| 562 | cout << "Intel intersection at = " << results[i].hitAT
|
---|
| 563 | << " , our alg intersection at = " << T << endl;
|
---|
| 564 | }
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 | } // double rays
|
---|
| 568 | else {
|
---|
| 569 | // checking for results of double rays - not yet implemented
|
---|
| 570 | }
|
---|
| 571 | #endif
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | timer.Stop();
|
---|
| 575 | long t2 = GetTime();
|
---|
| 576 | cout<<"\n#RAY_CAST_TIME = ";
|
---|
| 577 | cout << TimeDiff(t1, t2)<<" [mikrosec]"
|
---|
| 578 | << " userTime = " << timer.UserTime() << " realTime = "
|
---|
| 579 | << timer.RealTime() << endl;
|
---|
| 580 | cout << "Rays shot per milisecond [userTimer] = "
|
---|
| 581 | << ((double)cntRays * mult/(double)timer.UserTime()) / 1000.f << endl;
|
---|
| 582 |
|
---|
| 583 | #ifdef DEBUGRESULTS
|
---|
| 584 | cout << "cntIntelYesWeNo = " << cntIntelYesWeNo << endl;
|
---|
| 585 | cout << "cntIntelNoWeYes = " << cntIntelNoWeYes << endl;
|
---|
| 586 | cout << "cntIntelOurDistMismatch = " << cntIntelOurDistMismatch++ << endl;
|
---|
| 587 | cout << " sumDistIntel = " << sumDistIntel/(double)cntIntelOurDistMismatch << endl;
|
---|
| 588 | cout << " sumDistOur = " << sumDistOurAlg/(double)cntIntelOurDistMismatch << endl;
|
---|
| 589 | cout << " sumAbsDiffDist = " << sumDistAbsDiff/(double)cntIntelOurDistMismatch
|
---|
| 590 | << endl;
|
---|
| 591 | #endif
|
---|
| 592 | cout << "Done\n" << endl;
|
---|
| 593 | return;
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | //-------------------------------------------------------------------------
|
---|
| 597 | // This is for testing RT implementation using ray packets
|
---|
| 598 | void
|
---|
| 599 | TestRTfromFilePackets(int argc, char **argv)
|
---|
| 600 | {
|
---|
| 601 | int returnCode = 0;
|
---|
| 602 |
|
---|
| 603 | InitTiming();
|
---|
| 604 | Debug.open("debug.log");
|
---|
| 605 |
|
---|
| 606 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 607 | MeshKdTree::ParseEnvironment();
|
---|
| 608 |
|
---|
| 609 | char buff[128];
|
---|
| 610 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 611 | string preprocessorType(buff);
|
---|
| 612 |
|
---|
| 613 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
| 614 | {
|
---|
| 615 | Environment::DelSingleton();
|
---|
| 616 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 617 | exit(1);
|
---|
| 618 | }
|
---|
| 619 |
|
---|
| 620 |
|
---|
| 621 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 622 | string filename(buff);
|
---|
| 623 |
|
---|
| 624 | const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
| 625 | const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ?
|
---|
| 626 | ".kdm" : ".kdt");
|
---|
| 627 |
|
---|
| 628 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
| 629 | {
|
---|
| 630 | cout << "ray casting initialized!" << endl;
|
---|
| 631 | }
|
---|
| 632 | else
|
---|
| 633 | {
|
---|
| 634 | cout << "ray casting initialization failed!" << endl;
|
---|
| 635 | Cleanup();
|
---|
| 636 | exit(1);
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 | //Debug << "using pvs type " << PVS_TYPE << endl;
|
---|
| 640 |
|
---|
| 641 | /////////////
|
---|
| 642 | //-- load scene
|
---|
| 643 |
|
---|
| 644 | if (!preprocessor->LoadScene(filename))
|
---|
| 645 | {
|
---|
| 646 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 647 | Cleanup();
|
---|
| 648 | exit(1);
|
---|
| 649 | }
|
---|
| 650 |
|
---|
| 651 | ////////////
|
---|
| 652 | //-- initialize external ray caster
|
---|
| 653 |
|
---|
| 654 | if (preprocessor->LoadInternKdTree(internKdTree))
|
---|
| 655 | {
|
---|
| 656 | cout << "intern kd tree loaded!" << endl;
|
---|
| 657 | }
|
---|
| 658 | else
|
---|
| 659 | {
|
---|
| 660 | cout << "loading intern kd tree failed!" << endl;
|
---|
| 661 | Cleanup();
|
---|
| 662 | exit(1);
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | // export objects as obj
|
---|
| 666 | if (preprocessor->mExportObj)
|
---|
| 667 | {
|
---|
| 668 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 669 | {
|
---|
| 670 | cerr << "already in obj format" << endl;
|
---|
| 671 | if (0) preprocessor->ExportObj("test.obj", preprocessor->mObjects);
|
---|
| 672 | }
|
---|
| 673 | else
|
---|
| 674 | {
|
---|
| 675 | const string objname = GetInternFilename(filename, ".obj");
|
---|
| 676 |
|
---|
| 677 | cout << "exporting scene to " << objname << endl;
|
---|
| 678 | bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);
|
---|
| 679 |
|
---|
| 680 | if (success)
|
---|
| 681 | cout << "finished exporting obj" << endl;
|
---|
| 682 | else
|
---|
| 683 | cerr << "error exporting " << objname << endl;
|
---|
| 684 | }
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | Environment::GetSingleton()->GetStringValue("Rays.file", buff);
|
---|
| 688 | FILE *fp = fopen(buff, "rb");
|
---|
| 689 | if (!fp) {
|
---|
| 690 | cerr << "ERROR: file " << buff << " cannot be opened for reading" << endl;
|
---|
| 691 | cerr << "EXITING" << endl;
|
---|
| 692 | exit(3);
|
---|
| 693 | }
|
---|
| 694 | cout << "File " << buff << " was opened successfully" << endl;
|
---|
| 695 | int cntMaxRays = 100000;
|
---|
| 696 | Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays);
|
---|
| 697 | vector<SimpleRay> rays;
|
---|
| 698 | SimpleRay rayTest;
|
---|
| 699 | vector<RESult> results;
|
---|
| 700 |
|
---|
| 701 | int cntRays = 0;
|
---|
| 702 | for (int i = 0; cntRays < cntMaxRays; i++) {
|
---|
| 703 | int ch = fgetc(fp);
|
---|
| 704 | switch (ch) {
|
---|
| 705 | case 'G': { // two-sided rays of 16
|
---|
| 706 | for (int j = 0; j < 16; j++) {
|
---|
| 707 | int order;
|
---|
| 708 | float ox, oy, oz, dx, dy, dz;
|
---|
| 709 | int hitA; float hitAT;
|
---|
| 710 | int hitB; float hitBT;
|
---|
| 711 | if (fscanf(fp, "%d %f %f %f %f %f %f %d %f %d %f\n",
|
---|
| 712 | &order, &ox, &oy, &oz, &dx, &dy, &dz, &hitA, &hitAT, &hitB, &hitBT) != 11) {
|
---|
| 713 | cerr << "Problem parsing the ray file" << endl;
|
---|
| 714 | cerr << "EXITING for ray order" << order << endl;
|
---|
| 715 | goto FINISH;
|
---|
| 716 | }
|
---|
| 717 | Vector3 mPosition(ox, oy, oz);
|
---|
| 718 | Vector3 mDirection(dx, dy, dz);
|
---|
| 719 | rayTest.Set(mPosition, mDirection, 0, 1.0, true);
|
---|
| 720 | rays.push_back(rayTest);
|
---|
| 721 | results.push_back(RESult(hitA, hitAT, hitB, hitBT));
|
---|
| 722 | cntRays++;
|
---|
| 723 | }
|
---|
| 724 | break;
|
---|
| 725 | }
|
---|
| 726 | case 'H': // one-sided rays of 16
|
---|
| 727 | cerr << "Not yet implemented " << endl; abort();
|
---|
| 728 |
|
---|
| 729 | case 'D': // two-sided ray
|
---|
| 730 | cerr << "Not yet implemented " << endl; abort();
|
---|
| 731 |
|
---|
| 732 | case 'S': // one-sided ray
|
---|
| 733 | cerr << "Not yet implemented " << endl; abort();
|
---|
| 734 | } // switch
|
---|
| 735 | } // for i
|
---|
| 736 | FINISH:
|
---|
| 737 | fclose(fp);
|
---|
| 738 |
|
---|
| 739 | Environment::GetSingleton()->GetBoolValue("TestDoubleRays", castDoubleRays);
|
---|
| 740 |
|
---|
| 741 | double mult = 1.0;
|
---|
| 742 | if (castDoubleRays)
|
---|
| 743 | mult = 2.0;
|
---|
| 744 |
|
---|
| 745 | cout << "Starting to shoot " << cntRays * mult << " rays" << endl;
|
---|
| 746 |
|
---|
| 747 | RayCaster *raycaster = preprocessor->mRayCaster;
|
---|
| 748 | VssRayContainer vssRays;
|
---|
| 749 | AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox();
|
---|
| 750 |
|
---|
[2602] | 751 | #undef DEBUGRESULTS
|
---|
[2595] | 752 | //#define DEBUGRESULTS
|
---|
| 753 |
|
---|
| 754 | #ifdef DEBUGRESULTS
|
---|
| 755 | int cntIntelYesWeNo = 0;
|
---|
| 756 | int cntIntelNoWeYes = 0;
|
---|
| 757 | int cntIntelOurDistMismatch = 0;
|
---|
| 758 | bool printOut = false;
|
---|
| 759 | double sumDistIntel = 0.;
|
---|
[2602] | 760 | double sumDistOurAlg = 0.;
|
---|
[2595] | 761 | double sumDistAbsDiff = 0.f;
|
---|
| 762 | #endif
|
---|
| 763 |
|
---|
| 764 | cout << "Press a key to start ray shooting" << endl;
|
---|
| 765 | getchar();
|
---|
| 766 | cout << "Ray packs shooting " << cntRays << " rays started - "
|
---|
| 767 | << (castDoubleRays ? " double " : " single ")
|
---|
| 768 | << " dir " << endl;
|
---|
| 769 |
|
---|
| 770 | long t1 = GetTime();
|
---|
| 771 | CTimer timer;
|
---|
| 772 | timer.Reset();
|
---|
| 773 | timer.Start();
|
---|
| 774 |
|
---|
| 775 | #ifdef _USE_HAVRAN_SSE
|
---|
| 776 | #ifdef __SSE__
|
---|
| 777 | RayPacket2x2 raysPack;
|
---|
| 778 |
|
---|
| 779 | for (int i = 0; i < cntRays - 16; i++) {
|
---|
| 780 | for (int j = 0; j < 4; j++, i++) {
|
---|
| 781 | raysPack.SetLoc(j, rays[i].mOrigin);
|
---|
| 782 | raysPack.SetDir(j, rays[i].mDirection);
|
---|
| 783 | } // for
|
---|
| 784 | #if 0
|
---|
| 785 | for (int j = 0; j < 16; j++) {
|
---|
| 786 | cout << "orig = " << raysToTest[j].mOrigin << " dir = "
|
---|
| 787 | << raysToTest[j].mDirection << endl;
|
---|
| 788 | }
|
---|
| 789 | #endif
|
---|
| 790 | raysPack.ComputeDirSign();
|
---|
| 791 | raycaster->CastRaysPacket2x2(raysPack, castDoubleRays);
|
---|
| 792 |
|
---|
| 793 | #ifdef DEBUGRESULTS
|
---|
| 794 | if (!castDoubleRays) {
|
---|
| 795 | float T = rays[i].IntersectionRes[0].tdist;
|
---|
| 796 | if ( (res != results[i].hitA) ||
|
---|
| 797 | ((res)&&(results[i].hitA)&& (fabs(T - results[i].hitAT)) > 2.0f)
|
---|
| 798 | )
|
---|
| 799 | {
|
---|
| 800 | if (printOut)
|
---|
| 801 | cout << " i = " << i << " ";
|
---|
| 802 | if ((res != 0) && (results[i].hitA == 0)) {
|
---|
| 803 | cntIntelNoWeYes++;
|
---|
| 804 | if (printOut)
|
---|
| 805 | cout << "Intel no intersection, our alg intersection at t = " << T << endl;
|
---|
| 806 | }
|
---|
| 807 | else {
|
---|
| 808 | if ((res = 0) && (results[i].hitA)) {
|
---|
| 809 | cntIntelYesWeNo++;
|
---|
| 810 | if (printOut)
|
---|
| 811 | cout << "Intel intersection at = " << results[i].hitAT
|
---|
| 812 | << " , our alg no intersection = " << endl;
|
---|
| 813 |
|
---|
| 814 | }
|
---|
| 815 | else {
|
---|
| 816 | cntIntelOurDistMismatch++;
|
---|
| 817 | sumDistOurAlg += T;
|
---|
| 818 | sumDistIntel += results[i].hitAT;
|
---|
| 819 | sumDistAbsDiff += fabs(T - results[i].hitAT);
|
---|
| 820 | if (printOut)
|
---|
| 821 | cout << "Intel intersection at = " << results[i].hitAT
|
---|
| 822 | << " , our alg intersection at = " << T << endl;
|
---|
| 823 | }
|
---|
| 824 | }
|
---|
| 825 | }
|
---|
| 826 | } // double rays
|
---|
| 827 | else {
|
---|
| 828 | // checking for results of double rays - not yet implemented
|
---|
| 829 | }
|
---|
| 830 | #endif
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 | #endif // __SSE__
|
---|
| 834 | #endif // _USE_HAVRAN_SSE
|
---|
| 835 |
|
---|
| 836 | timer.Stop();
|
---|
| 837 | long t2 = GetTime();
|
---|
| 838 | cout<<"\n#RAY_CAST_TIME = ";
|
---|
| 839 | cout << TimeDiff(t1, t2)<<" [mikrosec]"
|
---|
| 840 | << " userTime = " << timer.UserTime() << " realTime = "
|
---|
| 841 | << timer.RealTime() << endl;
|
---|
| 842 | ;
|
---|
| 843 | cout << "Rays shot per milisecond [userTimer] = "
|
---|
| 844 | << ((double)cntRays * mult/(double)timer.UserTime()) / 1000.f << endl;
|
---|
| 845 |
|
---|
| 846 | #ifdef DEBUGRESULTS
|
---|
| 847 | cout << "cntIntelYesWeNo = " << cntIntelYesWeNo << endl;
|
---|
| 848 | cout << "cntIntelNoWeYes = " << cntIntelNoWeYes << endl;
|
---|
| 849 | cout << "cntIntelOurDistMismatch = " << cntIntelOurDistMismatch++ << endl;
|
---|
| 850 | cout << " sumDistIntel = " << sumDistIntel/(double)cntIntelOurDistMismatch << endl;
|
---|
| 851 | cout << " sumDistOur = " << sumDistOurAlg/(double)cntIntelOurDistMismatch << endl;
|
---|
| 852 | cout << " sumAbsDiffDist = " << sumDistAbsDiff/(double)cntIntelOurDistMismatch
|
---|
| 853 | << endl;
|
---|
| 854 | #endif
|
---|
| 855 | cout << "Done\n" << endl;
|
---|
| 856 | return;
|
---|
| 857 | }
|
---|
[2602] | 858 |
|
---|
| 859 | // This is for testing RT implementation
|
---|
| 860 | void
|
---|
| 861 | TestRT_4_fromFile(int argc, char **argv)
|
---|
| 862 | {
|
---|
| 863 | int returnCode = 0;
|
---|
| 864 |
|
---|
| 865 | InitTiming();
|
---|
| 866 | Debug.open("debug.log");
|
---|
| 867 |
|
---|
| 868 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 869 | MeshKdTree::ParseEnvironment();
|
---|
| 870 |
|
---|
| 871 | char buff[128];
|
---|
| 872 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 873 | string preprocessorType(buff);
|
---|
| 874 |
|
---|
| 875 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
| 876 | {
|
---|
| 877 | Environment::DelSingleton();
|
---|
| 878 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 879 | exit(1);
|
---|
| 880 | }
|
---|
| 881 |
|
---|
| 882 |
|
---|
| 883 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 884 | string filename(buff);
|
---|
| 885 |
|
---|
| 886 | const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
| 887 | const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ?
|
---|
| 888 | ".kdm" : ".kdt");
|
---|
| 889 |
|
---|
| 890 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
| 891 | {
|
---|
| 892 | cout << "ray casting initialized!" << endl;
|
---|
| 893 | }
|
---|
| 894 | else
|
---|
| 895 | {
|
---|
| 896 | cout << "ray casting initialization failed!" << endl;
|
---|
| 897 | Cleanup();
|
---|
| 898 | exit(1);
|
---|
| 899 | }
|
---|
| 900 |
|
---|
| 901 | //Debug << "using pvs type " << PVS_TYPE << endl;
|
---|
| 902 |
|
---|
| 903 | /////////////
|
---|
| 904 | //-- load scene
|
---|
| 905 |
|
---|
| 906 | if (!preprocessor->LoadScene(filename))
|
---|
| 907 | {
|
---|
| 908 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 909 | Cleanup();
|
---|
| 910 | exit(1);
|
---|
| 911 | }
|
---|
| 912 |
|
---|
| 913 | ////////////
|
---|
| 914 | //-- initialize external ray caster
|
---|
| 915 |
|
---|
| 916 | if (preprocessor->LoadInternKdTree(internKdTree))
|
---|
| 917 | {
|
---|
| 918 | cout << "intern kd tree loaded!" << endl;
|
---|
| 919 | }
|
---|
| 920 | else
|
---|
| 921 | {
|
---|
| 922 | cout << "loading intern kd tree failed!" << endl;
|
---|
| 923 | Cleanup();
|
---|
| 924 | exit(1);
|
---|
| 925 | }
|
---|
| 926 |
|
---|
| 927 | // export objects as obj
|
---|
| 928 | if (preprocessor->mExportObj)
|
---|
| 929 | {
|
---|
| 930 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 931 | {
|
---|
| 932 | cerr << "already in obj format" << endl;
|
---|
| 933 | if (0) preprocessor->ExportObj("test.obj", preprocessor->mObjects);
|
---|
| 934 | }
|
---|
| 935 | else
|
---|
| 936 | {
|
---|
| 937 | const string objname = GetInternFilename(filename, ".obj");
|
---|
| 938 |
|
---|
| 939 | cout << "exporting scene to " << objname << endl;
|
---|
| 940 | bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);
|
---|
| 941 |
|
---|
| 942 | if (success)
|
---|
| 943 | cout << "finished exporting obj" << endl;
|
---|
| 944 | else
|
---|
| 945 | cerr << "error exporting " << objname << endl;
|
---|
| 946 | }
|
---|
| 947 | }
|
---|
| 948 |
|
---|
| 949 | Environment::GetSingleton()->GetStringValue("Rays.file", buff);
|
---|
| 950 | FILE *fp = fopen(buff, "rb");
|
---|
| 951 | if (!fp) {
|
---|
| 952 | cerr << "ERROR: file " << buff << " cannot be opened for reading" << endl;
|
---|
| 953 | cerr << "EXITING" << endl;
|
---|
| 954 | exit(3);
|
---|
| 955 | }
|
---|
| 956 | cout << "File " << buff << " was opened successfully" << endl;
|
---|
| 957 | int cntMaxRays = 100000;
|
---|
| 958 | Environment::GetSingleton()->GetIntValue("Rays.cnt", cntMaxRays);
|
---|
| 959 | vector<SimpleRay> rays;
|
---|
| 960 | SimpleRay rayTest;
|
---|
| 961 | vector<RESult> results;
|
---|
| 962 | vector<AxisAlignedBox3> boxes;
|
---|
| 963 |
|
---|
| 964 | int cntRays = 0;
|
---|
| 965 | for (int i = 0; cntRays < cntMaxRays;) {
|
---|
| 966 | int ch = fgetc(fp);
|
---|
| 967 | switch (ch) {
|
---|
| 968 | case 'I': { // two-sided rays of 16
|
---|
| 969 | Vector3 minv, maxv;
|
---|
| 970 | if (fscanf(fp, "%f %f %f %f %f %f\n",
|
---|
| 971 | &minv.x, &minv.y, &minv.z,
|
---|
| 972 | &maxv.x, &maxv.y, &maxv.z) != 6) {
|
---|
| 973 | cerr << "Problem parsing the ray file" << endl;
|
---|
| 974 | cerr << "EXITING for ray order" << i << endl;
|
---|
| 975 | goto FINISH;
|
---|
| 976 | }
|
---|
| 977 | boxes.push_back(AxisAlignedBox3(minv, maxv));
|
---|
| 978 |
|
---|
| 979 | for (int j = 0; j < 4; j++) {
|
---|
| 980 | int order;
|
---|
| 981 | float ox, oy, oz, dx, dy, dz;
|
---|
| 982 | int hitA; float hitAT;
|
---|
| 983 | int hitB; float hitBT;
|
---|
| 984 | if (fscanf(fp, "%d %f %f %f %f %f %f %d %f\n",
|
---|
| 985 | &order, &ox, &oy, &oz, &dx, &dy, &dz,
|
---|
| 986 | &hitA, &hitAT) != 9) {
|
---|
| 987 | cerr << "Problem parsing the ray file" << endl;
|
---|
| 988 | cerr << "EXITING for ray order" << order << endl;
|
---|
| 989 | goto FINISH;
|
---|
| 990 | }
|
---|
| 991 | Vector3 mPosition(ox, oy, oz);
|
---|
| 992 | Vector3 mDirection(dx, dy, dz);
|
---|
| 993 | rayTest.Set(mPosition, mDirection, 0, 1.0, true);
|
---|
| 994 | rays.push_back(rayTest);
|
---|
| 995 | results.push_back(RESult(hitA, hitAT, 0, -1.f));
|
---|
| 996 | cntRays++;
|
---|
| 997 | i++;
|
---|
| 998 | }
|
---|
| 999 | break;
|
---|
| 1000 | }
|
---|
| 1001 | default: {
|
---|
| 1002 | cerr << "Not yet implemented or end of file" << endl;
|
---|
| 1003 | goto FINISH;
|
---|
| 1004 | }
|
---|
| 1005 | } // switch
|
---|
| 1006 | } // for i
|
---|
| 1007 |
|
---|
| 1008 | FINISH:
|
---|
| 1009 |
|
---|
| 1010 | fclose(fp);
|
---|
| 1011 | cout << "Starting to shoot " << cntRays << " rays" << endl;
|
---|
| 1012 |
|
---|
| 1013 | RayCaster *raycaster = preprocessor->mRayCaster;
|
---|
| 1014 | VssRayContainer vssRays;
|
---|
| 1015 | AxisAlignedBox3 bboxOrig = preprocessor->mSceneGraph->GetBox();
|
---|
| 1016 |
|
---|
| 1017 | //#define DEBUGRESULTS
|
---|
| 1018 |
|
---|
| 1019 | #ifdef DEBUGRESULTS
|
---|
| 1020 | int cntIntelYesWeNo = 0;
|
---|
| 1021 | int cntIntelNoWeYes = 0;
|
---|
| 1022 | int cntIntelOurDistMismatch = 0;
|
---|
| 1023 | bool printOut = false;
|
---|
| 1024 | double sumDistIntel = 0.f;
|
---|
| 1025 | double sumDistOurAlg = 0.f;
|
---|
| 1026 | double sumDistAbsDiff = 0.f;
|
---|
| 1027 | #endif
|
---|
| 1028 |
|
---|
| 1029 | //cout << "Press a key to start ray shooting" << endl;
|
---|
| 1030 | //getchar();
|
---|
| 1031 | cout << "Ray shooting " << cntRays << " rays started - "
|
---|
| 1032 | << (castDoubleRays ? " double " : " single ")
|
---|
| 1033 | << " dir " << endl;
|
---|
| 1034 |
|
---|
| 1035 | long t1 = GetTime();
|
---|
| 1036 | CTimer timer;
|
---|
| 1037 | timer.Reset();
|
---|
| 1038 | timer.Start();
|
---|
| 1039 | Vector3 boxMin, boxMax;
|
---|
| 1040 |
|
---|
| 1041 | SimpleRayContainer raysToTest;
|
---|
| 1042 | int boxI = 0;
|
---|
| 1043 | for (int i = 0; i < cntRays - 4; i+= 4, boxI++) {
|
---|
| 1044 | Vector3 origin4[4];
|
---|
| 1045 | Vector3 direction4[4];
|
---|
| 1046 | int result4[4];
|
---|
| 1047 | float dist4[4];
|
---|
| 1048 | boxMin = boxes[boxI].Min();
|
---|
| 1049 | boxMax = boxes[boxI].Max();
|
---|
| 1050 | for (int j = 0; j < 4; j++) {
|
---|
| 1051 | int o = i+j;
|
---|
| 1052 | origin4[j] = rays[o].mOrigin;
|
---|
| 1053 | direction4[j] = rays[o].mDirection;
|
---|
| 1054 | }
|
---|
| 1055 | raycaster->CastRaysPacket4(boxMin, boxMax,
|
---|
| 1056 | origin4, direction4,
|
---|
| 1057 | 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);
|
---|
| 1060 |
|
---|
| 1061 | 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);
|
---|
| 1072 | } // for j
|
---|
| 1073 | } // for i
|
---|
| 1074 |
|
---|
| 1075 | timer.Stop();
|
---|
| 1076 | long t2 = GetTime();
|
---|
| 1077 | cout<<"\n#RAY_CAST_TIME = ";
|
---|
| 1078 | cout << TimeDiff(t1, t2)<<" [mikrosec]"
|
---|
| 1079 | << " userTime = " << timer.UserTime() << " realTime = "
|
---|
| 1080 | << timer.RealTime() << endl;
|
---|
| 1081 | cout << "Rays shot per milisecond [userTimer] = "
|
---|
| 1082 | << ((double)cntRays/(double)timer.UserTime()) / 1000.f << endl;
|
---|
| 1083 |
|
---|
| 1084 | #ifdef DEBUGRESULTS
|
---|
| 1085 | cout << "cntIntelYesWeNo = " << cntIntelYesWeNo << endl;
|
---|
| 1086 | cout << "cntIntelNoWeYes = " << cntIntelNoWeYes << endl;
|
---|
| 1087 | cout << "cntIntelOurDistMismatch = " << cntIntelOurDistMismatch++ << endl;
|
---|
| 1088 | cout << " sumDistIntel = " << sumDistIntel/(double)cntIntelOurDistMismatch << endl;
|
---|
| 1089 | cout << " sumDistOur = " << sumDistOurAlg/(double)cntIntelOurDistMismatch << endl;
|
---|
| 1090 | cout << " sumAbsDiffDist = " << sumDistAbsDiff/(double)cntIntelOurDistMismatch
|
---|
| 1091 | << endl;
|
---|
| 1092 | #endif
|
---|
| 1093 | cout << "Done\n" << endl;
|
---|
| 1094 | return;
|
---|
| 1095 | }
|
---|