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