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