[1926] | 1 | #define USE_THREADS 0
|
---|
[1457] | 2 |
|
---|
[1199] | 3 | #ifdef UNICODE
|
---|
| 4 | #undef UNICODE
|
---|
| 5 | #endif
|
---|
| 6 |
|
---|
[2176] | 7 | #define NOMINMAX
|
---|
[2634] | 8 | #ifdef _WIN32
|
---|
[1151] | 9 | #include <windows.h>
|
---|
[2575] | 10 | #ifdef _CRT_SET
|
---|
[1151] | 11 | #include <crtdbg.h>
|
---|
[2575] | 12 | #endif // _CRT_SET
|
---|
| 13 | #endif
|
---|
| 14 | #include <cstdio>
|
---|
[1151] | 15 |
|
---|
[2575] | 16 | #include "Camera.h"
|
---|
[1486] | 17 | #include "PreprocessorFactory.h"
|
---|
[162] | 18 | #include "Parser.h"
|
---|
| 19 | #include "Environment.h"
|
---|
[170] | 20 | #include "MeshKdTree.h"
|
---|
[1486] | 21 | #include "Preprocessor.h"
|
---|
[1634] | 22 | #include "common.h"
|
---|
[1457] | 23 | #include "PreprocessorThread.h"
|
---|
[1694] | 24 | #include "ObjExporter.h"
|
---|
| 25 | #include "SceneGraph.h"
|
---|
[1949] | 26 | #include "GlobalLinesRenderer.h"
|
---|
[2575] | 27 | #include "RayCaster.h"
|
---|
[1926] | 28 | #include "ViewCellsManager.h"
|
---|
[1694] | 29 |
|
---|
[2629] | 30 |
|
---|
[2568] | 31 | #ifdef USE_QT
|
---|
[1926] | 32 | #include "QtPreprocessorThread.h"
|
---|
| 33 | #include "QtGlViewer.h"
|
---|
| 34 | #include "QtGlRenderer.h"
|
---|
[2560] | 35 | #include <QGLWidget>
|
---|
| 36 |
|
---|
[2568] | 37 | #else
|
---|
[1926] | 38 | #if USE_THREADS
|
---|
| 39 | #include "BoostPreprocessorThread.h"
|
---|
| 40 | #endif
|
---|
[2568] | 41 | #endif
|
---|
[1272] | 42 |
|
---|
[1001] | 43 | #include "ResourceManager.h"
|
---|
[492] | 44 | #include "GlRenderer.h"
|
---|
| 45 |
|
---|
[1272] | 46 |
|
---|
[162] | 47 | #define USE_EXE_PATH false
|
---|
| 48 |
|
---|
[372] | 49 |
|
---|
[863] | 50 | using namespace GtpVisibilityPreprocessor;
|
---|
[492] | 51 |
|
---|
[1888] | 52 | //Preprocessor *preprocessor = NULL;
|
---|
[1151] | 53 | GlRendererWidget *rendererWidget = NULL;
|
---|
[1940] | 54 | //GlobalLinesRenderer *globalLinesRenderer = NULL;
|
---|
[1145] | 55 |
|
---|
[1940] | 56 |
|
---|
[1151] | 57 | // DLL function signature
|
---|
[1153] | 58 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
[1145] | 59 |
|
---|
[1241] | 60 |
|
---|
[2686] | 61 | static string GetViewPointsListName(const string &filename)
|
---|
| 62 | {
|
---|
| 63 | string viewCellPointsFile;
|
---|
[1199] | 64 |
|
---|
[2686] | 65 | char buff[200];
|
---|
| 66 | Environment::GetSingleton()->GetStringValue("ViewCells.randomViewPointsList", buff);
|
---|
| 67 |
|
---|
| 68 | string vpList(buff);
|
---|
| 69 |
|
---|
| 70 | if (vpList == "")
|
---|
| 71 | {
|
---|
| 72 | // if not specified, take file that has same prefix as scene file
|
---|
| 73 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 74 | viewCellPointsFile = ReplaceSuffix(filename, ".obj", ".vc");
|
---|
| 75 | else if (strstr(filename.c_str(), ".dat"))
|
---|
| 76 | viewCellPointsFile = ReplaceSuffix(filename, ".dat", ".vc");
|
---|
| 77 | else if (strstr(filename.c_str(), ".x3d"))
|
---|
| 78 | viewCellPointsFile = ReplaceSuffix(filename, ".x3d", ".vc");
|
---|
| 79 | }
|
---|
| 80 | else
|
---|
| 81 | {
|
---|
| 82 | viewCellPointsFile = vpList;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | return viewCellPointsFile;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
[1145] | 89 | void Cleanup()
|
---|
| 90 | {
|
---|
[1151] | 91 | DEL_PTR(rendererWidget);
|
---|
[1145] | 92 | DEL_PTR(preprocessor);
|
---|
| 93 |
|
---|
| 94 | Environment::DelSingleton();
|
---|
| 95 | MeshManager::DelSingleton();
|
---|
| 96 | MaterialManager::DelSingleton();
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 |
|
---|
[2452] | 101 |
|
---|
[1695] | 102 | static string GetInternFilename(const string &filename, const string newSuffix)
|
---|
[1634] | 103 | {
|
---|
| 104 | vector<string> filenames;
|
---|
| 105 | const int files = SplitFilenames(filename, filenames);
|
---|
| 106 |
|
---|
| 107 | vector<string>::const_iterator sit, sit_end = filenames.end();
|
---|
| 108 | string kdFilename;
|
---|
| 109 |
|
---|
| 110 | int i = 0;
|
---|
| 111 | for (sit = filenames.begin(); sit != sit_end; ++ sit, ++ i)
|
---|
[1633] | 112 | {
|
---|
[1634] | 113 | string currentFile = *sit;
|
---|
| 114 | string strippedFilename;
|
---|
[1633] | 115 |
|
---|
[1634] | 116 | if (i == 0)
|
---|
| 117 | {
|
---|
| 118 | strippedFilename = currentFile;
|
---|
| 119 | }
|
---|
| 120 | else
|
---|
| 121 | {
|
---|
[1640] | 122 | char *str = StripPath(currentFile.c_str());
|
---|
| 123 | strippedFilename = string(str);
|
---|
| 124 |
|
---|
[1695] | 125 | delete [] str;
|
---|
[1634] | 126 | }
|
---|
| 127 |
|
---|
| 128 | string suffix("_");
|
---|
| 129 |
|
---|
| 130 | if (i == (int)filenames.size() - 1)
|
---|
| 131 | {
|
---|
[1695] | 132 | suffix = newSuffix;
|
---|
[1634] | 133 | }
|
---|
| 134 |
|
---|
| 135 | if (strstr(strippedFilename.c_str(), ".x3d"))
|
---|
| 136 | {
|
---|
| 137 | kdFilename += ReplaceSuffix(strippedFilename, ".x3d", suffix);
|
---|
| 138 | }
|
---|
| 139 | else if (strstr(strippedFilename.c_str(), ".dat"))
|
---|
| 140 | {
|
---|
| 141 | kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix);
|
---|
| 142 | }
|
---|
| 143 | else if (strstr(strippedFilename.c_str(), ".obj"))
|
---|
| 144 | {
|
---|
[1658] | 145 | kdFilename += ReplaceSuffix(strippedFilename, ".obj", suffix);
|
---|
[1634] | 146 | }
|
---|
| 147 | else
|
---|
| 148 | {
|
---|
| 149 | cerr << "Error: Currently unsupported format for kd, filename " << currentFile << endl;
|
---|
| 150 | }
|
---|
[1626] | 151 | }
|
---|
[1272] | 152 |
|
---|
[1634] | 153 | //cout << "kdfilename: " << kdFilename << endl;
|
---|
| 154 | return kdFilename;
|
---|
[1272] | 155 | }
|
---|
| 156 |
|
---|
[162] | 157 | int
|
---|
[492] | 158 | main(int argc, char **argv)
|
---|
[997] | 159 | {
|
---|
[2676] | 160 | int returnCode = 0;
|
---|
[2659] | 161 |
|
---|
[2676] | 162 | #ifdef _CRT_SET
|
---|
[2575] | 163 |
|
---|
[2676] | 164 | //Now just call this function at the start of your program and if you're
|
---|
| 165 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
| 166 | //window when the program shuts down. If you're not in debug mode this will
|
---|
| 167 | //be ignored. Use it as you will!
|
---|
| 168 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
[2582] | 169 |
|
---|
[2676] | 170 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
| 171 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
| 172 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
[2575] | 173 | #endif
|
---|
| 174 |
|
---|
[2676] | 175 | InitTiming();
|
---|
| 176 | Debug.open("debug.log");
|
---|
[997] | 177 |
|
---|
[2676] | 178 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 179 | MeshKdTree::ParseEnvironment();
|
---|
| 180 |
|
---|
| 181 | char buff[128];
|
---|
| 182 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 183 | string preprocessorType(buff);
|
---|
| 184 |
|
---|
| 185 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
[1328] | 186 | {
|
---|
[1486] | 187 | Environment::DelSingleton();
|
---|
| 188 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 189 | exit(1);
|
---|
[1328] | 190 | }
|
---|
[997] | 191 |
|
---|
[2676] | 192 |
|
---|
[1145] | 193 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 194 | string filename(buff);
|
---|
[2676] | 195 |
|
---|
[2003] | 196 | const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
[2049] | 197 | const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ?
|
---|
[2676] | 198 | ".kdm" : ".kdt");
|
---|
[1328] | 199 |
|
---|
[2003] | 200 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
| 201 | {
|
---|
| 202 | cout << "ray casting initialized!" << endl;
|
---|
| 203 | }
|
---|
| 204 | else
|
---|
| 205 | {
|
---|
| 206 | cout << "ray casting initialization failed!" << endl;
|
---|
| 207 | Cleanup();
|
---|
| 208 | exit(1);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | /////////////
|
---|
| 212 | //-- load scene
|
---|
| 213 |
|
---|
[1328] | 214 | if (!preprocessor->LoadScene(filename))
|
---|
| 215 | {
|
---|
| 216 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 217 | Cleanup();
|
---|
| 218 | exit(1);
|
---|
| 219 | }
|
---|
[2560] | 220 |
|
---|
[2676] | 221 |
|
---|
[1697] | 222 | ////////////
|
---|
| 223 | //-- initialize external ray caster
|
---|
[1999] | 224 |
|
---|
[2003] | 225 | if (preprocessor->LoadInternKdTree(internKdTree))
|
---|
[1328] | 226 | {
|
---|
[2003] | 227 | cout << "intern kd tree loaded!" << endl;
|
---|
[1328] | 228 | }
|
---|
[1221] | 229 | else
|
---|
| 230 | {
|
---|
[2003] | 231 | cout << "loading intern kd tree failed!" << endl;
|
---|
[1328] | 232 | Cleanup();
|
---|
[1221] | 233 | exit(1);
|
---|
| 234 | }
|
---|
[2676] | 235 |
|
---|
[1695] | 236 | // export objects as obj
|
---|
| 237 | if (preprocessor->mExportObj)
|
---|
| 238 | {
|
---|
| 239 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 240 | {
|
---|
| 241 | cerr << "already in obj format" << endl;
|
---|
[1701] | 242 | if (0) preprocessor->ExportObj("test.obj", preprocessor->mObjects);
|
---|
[1695] | 243 | }
|
---|
| 244 | else
|
---|
| 245 | {
|
---|
[2676] | 246 |
|
---|
[1695] | 247 | const string objname = GetInternFilename(filename, ".obj");
|
---|
| 248 |
|
---|
[1701] | 249 | cout << "exporting scene to " << objname << endl;
|
---|
[1695] | 250 | bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);
|
---|
| 251 |
|
---|
| 252 | if (success)
|
---|
| 253 | cout << "finished exporting obj" << endl;
|
---|
| 254 | else
|
---|
| 255 | cerr << "error exporting " << objname << endl;
|
---|
| 256 | }
|
---|
| 257 | }
|
---|
[2660] | 258 |
|
---|
[1145] | 259 | // parse view cells related options
|
---|
[1522] | 260 | if (!preprocessor->PrepareViewCells())
|
---|
| 261 | {
|
---|
[1926] | 262 | cerr << "error: view cells could not be loaded" << endl;
|
---|
[1522] | 263 | Cleanup();
|
---|
| 264 | exit(1);
|
---|
| 265 | }
|
---|
[2659] | 266 | else
|
---|
| 267 | cout << "view cells successfully loaded" << endl;
|
---|
[1999] | 268 |
|
---|
[2017] | 269 |
|
---|
[2686] | 270 | const string viewCellPointsFile = GetViewPointsListName(filename);
|
---|
[2023] | 271 |
|
---|
[2048] | 272 | bool importRandomViewCells;
|
---|
[2686] | 273 | Environment::GetSingleton()->GetBoolValue("ViewCells.importRandomViewCells", importRandomViewCells);
|
---|
[2048] | 274 |
|
---|
| 275 | if (importRandomViewCells)
|
---|
| 276 | {
|
---|
[2686] | 277 | cout << "importing random view points" << endl;
|
---|
| 278 |
|
---|
[2677] | 279 | if (preprocessor->mViewCellsManager->ImportViewCellsList(viewCellPointsFile))
|
---|
| 280 | cout << "successfully loaded " << viewCellPointsFile << endl;
|
---|
| 281 | else
|
---|
[2686] | 282 | cerr << "error: file << " << viewCellPointsFile << " not found" << endl;
|
---|
[2048] | 283 | }
|
---|
| 284 |
|
---|
[2660] | 285 |
|
---|
[1968] | 286 | bool useHwGlobalLines;
|
---|
| 287 | Environment::GetSingleton()->GetBoolValue("Preprocessor.useHwGlobalLines",
|
---|
[2676] | 288 | useHwGlobalLines);
|
---|
[1968] | 289 |
|
---|
| 290 | if (useHwGlobalLines)
|
---|
| 291 | preprocessor->PrepareHwGlobalLines();
|
---|
| 292 |
|
---|
[1239] | 293 | // create a preprocessor thread (note: capsulates calls to boost fuctions!)
|
---|
[1926] | 294 | PreprocessorThread *pt = NULL;
|
---|
[2676] | 295 |
|
---|
[2560] | 296 | //preprocessor->PrepareHwGlobalLines();
|
---|
| 297 | //globalLinesRenderer->Run();
|
---|
[1940] | 298 |
|
---|
| 299 |
|
---|
[1248] | 300 | bool guiSupported = false;
|
---|
[2560] | 301 | const bool useRendererBuffer = true;
|
---|
[2049] | 302 |
|
---|
| 303 | int frames;
|
---|
| 304 | Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", frames);
|
---|
[2560] | 305 |
|
---|
[2611] | 306 | bool evalPixelError;
|
---|
| 307 | Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", evalPixelError);
|
---|
[2660] | 308 |
|
---|
| 309 |
|
---|
[2049] | 310 | #ifdef USE_QT
|
---|
| 311 |
|
---|
[2560] | 312 | // create a qt application first (must be created before any opengl widget ...)
|
---|
| 313 | QApplication *app = new QApplication(argc, NULL);
|
---|
[2679] | 314 |
|
---|
[2560] | 315 | pt = new QtPreprocessorThread(preprocessor);
|
---|
[2676] | 316 |
|
---|
[2611] | 317 | if (evalPixelError && (importRandomViewCells || frames))
|
---|
[2625] | 318 | {
|
---|
[2664] | 319 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers())
|
---|
| 320 | {
|
---|
| 321 | cerr << "this system does not support OpenGL/pbuffers" << endl;
|
---|
| 322 |
|
---|
| 323 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
| 324 | "This system does not support OpenGL/pbuffers.",
|
---|
| 325 | QMessageBox::Ok);
|
---|
| 326 |
|
---|
| 327 | return NULL;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[2049] | 330 | QGLFormat f;
|
---|
| 331 | f.setStencil(true);
|
---|
| 332 | QGLFormat::setDefaultFormat(f);
|
---|
[2625] | 333 |
|
---|
[2049] | 334 | // NOTE: render texture should be power of 2 and square
|
---|
| 335 | // renderer must be initialised
|
---|
| 336 | // $$matt
|
---|
[2679] | 337 | QtGlRendererBuffer *glbuf =
|
---|
[2676] | 338 | new QtGlRendererBuffer(1024, 1024,
|
---|
[2679] | 339 | preprocessor->mSceneGraph,
|
---|
| 340 | preprocessor->mViewCellsManager,
|
---|
| 341 | preprocessor->mKdTree);
|
---|
[2676] | 342 |
|
---|
[2679] | 343 | preprocessor->renderer = glbuf;
|
---|
[2647] | 344 | }
|
---|
| 345 |
|
---|
| 346 | bool exportRandomViewCells;
|
---|
| 347 | Environment::GetSingleton()->GetBoolValue("ViewCells.exportRandomViewCells",
|
---|
[2676] | 348 | exportRandomViewCells);
|
---|
| 349 |
|
---|
[2647] | 350 | if (exportRandomViewCells)
|
---|
[2664] | 351 | {
|
---|
[2647] | 352 | cout << "exporting random view cells" << endl;
|
---|
| 353 | preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile);
|
---|
| 354 | cout << "finished" << endl;
|
---|
[2664] | 355 | }
|
---|
[2647] | 356 |
|
---|
[2560] | 357 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
| 358 | {
|
---|
| 359 | ////////
|
---|
| 360 | //-- create and run the preprocessor application in a parallel thread
|
---|
[1926] | 361 |
|
---|
[2560] | 362 | cout << "using gl widget" << endl;
|
---|
[2049] | 363 |
|
---|
[2560] | 364 | pt->InitThread();
|
---|
| 365 | pt->RunThread();
|
---|
[1613] | 366 |
|
---|
[2560] | 367 | // display the render widget
|
---|
| 368 | if (!rendererWidget)
|
---|
| 369 | {
|
---|
[2664] | 370 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers())
|
---|
| 371 | {
|
---|
| 372 | cerr << "this system does not support OpenGL/pbuffers" << endl;
|
---|
| 373 |
|
---|
[2560] | 374 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
| 375 | "This system does not support OpenGL/pbuffers.",
|
---|
| 376 | QMessageBox::Ok);
|
---|
[2664] | 377 |
|
---|
[2560] | 378 | return NULL;
|
---|
| 379 | }
|
---|
[2017] | 380 |
|
---|
[2560] | 381 | rendererWidget =
|
---|
| 382 | new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
[2676] | 383 | preprocessor->mViewCellsManager,
|
---|
| 384 | preprocessor->mKdTree);
|
---|
[2017] | 385 |
|
---|
[2560] | 386 | rendererWidget->Show();
|
---|
[2023] | 387 |
|
---|
[2625] | 388 | // hack matt
|
---|
| 389 | preprocessor->mRendererWidget = rendererWidget;
|
---|
[2615] | 390 | //rendererWidget->SetWindowTitle("Global Visualization");
|
---|
| 391 |
|
---|
[2689] | 392 | if (1 && !rendererWidget->GetUseVbos()) // viewer not working with vbo
|
---|
[2560] | 393 | {
|
---|
[2569] | 394 | cout << "starting the qt viewer" << endl;
|
---|
[2560] | 395 | QtGlViewer *viewer =
|
---|
| 396 | new QtGlViewer(NULL, (QtGlRendererWidget *)rendererWidget);
|
---|
| 397 | viewer->show();
|
---|
| 398 | }
|
---|
[2538] | 399 |
|
---|
[2560] | 400 | guiSupported = true;
|
---|
| 401 | }
|
---|
[2538] | 402 |
|
---|
[2560] | 403 | qApp->exec();
|
---|
| 404 | }
|
---|
[2664] | 405 | #else // USE_QT
|
---|
[2538] | 406 |
|
---|
[2664] | 407 | /*#if USE_THREADS
|
---|
[2676] | 408 | pt = new BoostPreprocessorThread(preprocessor);
|
---|
[2664] | 409 | #else
|
---|
[2676] | 410 | // use a dummy thread
|
---|
| 411 | pt = new DummyPreprocessorThread(preprocessor);
|
---|
[2664] | 412 | #endif
|
---|
| 413 | */
|
---|
[1387] | 414 | #endif
|
---|
[1785] | 415 |
|
---|
[2560] | 416 | preprocessor->SetThread(pt);
|
---|
[1696] | 417 |
|
---|
[2560] | 418 | // no gui available
|
---|
| 419 | if (!guiSupported)
|
---|
| 420 | {
|
---|
| 421 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
| 422 | cout << "warning: gui not supported!" << endl;
|
---|
[2538] | 423 |
|
---|
[2560] | 424 | preprocessor->mUseGlRenderer = false;
|
---|
| 425 | preprocessor->mUseGlDebugger = false;
|
---|
| 426 | }
|
---|
[1999] | 427 |
|
---|
[2560] | 428 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger))
|
---|
| 429 | {
|
---|
| 430 | cout << "executing main thread" << endl;
|
---|
| 431 | // just call the mail method -> will be executed in the main thread
|
---|
| 432 | pt->Main();
|
---|
| 433 | }
|
---|
[2538] | 434 |
|
---|
[2560] | 435 | // release memory
|
---|
| 436 | Cleanup();
|
---|
| 437 | delete pt;
|
---|
| 438 |
|
---|
| 439 | return returnCode;
|
---|
[162] | 440 | }
|
---|
| 441 |
|
---|