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