[1926] | 1 | #define USE_THREADS 0
|
---|
[1457] | 2 |
|
---|
[1199] | 3 | #ifdef UNICODE
|
---|
| 4 | #undef UNICODE
|
---|
| 5 | #endif
|
---|
| 6 |
|
---|
[2176] | 7 | #define NOMINMAX
|
---|
[2575] | 8 | #ifdef __WINDOWS__
|
---|
[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"
|
---|
[2582] | 28 | //#include "vlastimil/testrt.h"
|
---|
[1579] | 29 |
|
---|
[1926] | 30 | #include "ViewCellsManager.h"
|
---|
[1694] | 31 |
|
---|
[2568] | 32 | #ifdef USE_QT
|
---|
[1926] | 33 | #include "QtPreprocessorThread.h"
|
---|
| 34 | #include "QtGlViewer.h"
|
---|
| 35 | #include "QtGlRenderer.h"
|
---|
[2560] | 36 | #include <QGLWidget>
|
---|
| 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 | {
|
---|
[2575] | 134 | #if 0
|
---|
| 135 | // Test code by VH
|
---|
| 136 | //TestRTcamera(argc, argv);
|
---|
| 137 | //TestRTfromFile(argc, argv);
|
---|
| 138 | TestRTfromFilePackets(argc, argv);
|
---|
| 139 | return 0;
|
---|
| 140 | #endif
|
---|
[2560] | 141 |
|
---|
[2575] | 142 | int returnCode = 0;
|
---|
| 143 |
|
---|
| 144 | //Now just call this function at the start of your program and if you're
|
---|
| 145 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
| 146 | //window when the program shuts down. If you're not in debug mode this will
|
---|
| 147 | //be ignored. Use it as you will!
|
---|
| 148 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
[2582] | 149 |
|
---|
| 150 | //#define _CRT_SET
|
---|
| 151 |
|
---|
[2575] | 152 | #ifdef _CRT_SET
|
---|
| 153 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
| 154 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
| 155 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
| 156 | #endif
|
---|
| 157 |
|
---|
[1145] | 158 | InitTiming();
|
---|
[2020] | 159 | Debug.open("debug.log");
|
---|
[997] | 160 |
|
---|
[1145] | 161 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 162 | MeshKdTree::ParseEnvironment();
|
---|
[1002] | 163 |
|
---|
[1145] | 164 | char buff[128];
|
---|
| 165 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 166 | string preprocessorType(buff);
|
---|
| 167 |
|
---|
[1486] | 168 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
[1328] | 169 | {
|
---|
[1486] | 170 | Environment::DelSingleton();
|
---|
| 171 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 172 | exit(1);
|
---|
[1328] | 173 | }
|
---|
[997] | 174 |
|
---|
[2608] | 175 |
|
---|
[1145] | 176 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 177 | string filename(buff);
|
---|
[1695] | 178 |
|
---|
[2003] | 179 | const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
[2049] | 180 | const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ?
|
---|
| 181 | ".kdm" : ".kdt");
|
---|
[1328] | 182 |
|
---|
[2003] | 183 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
| 184 | {
|
---|
| 185 | cout << "ray casting initialized!" << endl;
|
---|
| 186 | }
|
---|
| 187 | else
|
---|
| 188 | {
|
---|
| 189 | cout << "ray casting initialization failed!" << endl;
|
---|
| 190 | Cleanup();
|
---|
| 191 | exit(1);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[2582] | 194 |
|
---|
[2176] | 195 | //Debug << "using pvs type " << PVS_TYPE << endl;
|
---|
[2003] | 196 |
|
---|
| 197 | /////////////
|
---|
| 198 | //-- load scene
|
---|
| 199 |
|
---|
[1328] | 200 | if (!preprocessor->LoadScene(filename))
|
---|
| 201 | {
|
---|
| 202 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 203 | Cleanup();
|
---|
| 204 | exit(1);
|
---|
| 205 | }
|
---|
[1926] | 206 |
|
---|
[2560] | 207 |
|
---|
[1697] | 208 | ////////////
|
---|
| 209 | //-- initialize external ray caster
|
---|
[1999] | 210 |
|
---|
[2003] | 211 | if (preprocessor->LoadInternKdTree(internKdTree))
|
---|
[1328] | 212 | {
|
---|
[2003] | 213 | cout << "intern kd tree loaded!" << endl;
|
---|
[1328] | 214 | }
|
---|
[1221] | 215 | else
|
---|
| 216 | {
|
---|
[2003] | 217 | cout << "loading intern kd tree failed!" << endl;
|
---|
[1328] | 218 | Cleanup();
|
---|
[1221] | 219 | exit(1);
|
---|
| 220 | }
|
---|
[1344] | 221 |
|
---|
[1695] | 222 | // export objects as obj
|
---|
| 223 | if (preprocessor->mExportObj)
|
---|
| 224 | {
|
---|
| 225 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 226 | {
|
---|
| 227 | cerr << "already in obj format" << endl;
|
---|
[1701] | 228 | if (0) preprocessor->ExportObj("test.obj", preprocessor->mObjects);
|
---|
[1695] | 229 | }
|
---|
| 230 | else
|
---|
| 231 | {
|
---|
[2049] | 232 |
|
---|
[1695] | 233 | const string objname = GetInternFilename(filename, ".obj");
|
---|
| 234 |
|
---|
[1701] | 235 | cout << "exporting scene to " << objname << endl;
|
---|
[1695] | 236 | bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);
|
---|
| 237 |
|
---|
[2049] | 238 |
|
---|
[1695] | 239 | if (success)
|
---|
| 240 | cout << "finished exporting obj" << endl;
|
---|
| 241 | else
|
---|
| 242 | cerr << "error exporting " << objname << endl;
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
[1713] | 245 |
|
---|
[1145] | 246 | // parse view cells related options
|
---|
[1522] | 247 | if (!preprocessor->PrepareViewCells())
|
---|
| 248 | {
|
---|
[1926] | 249 | cerr << "error: view cells could not be loaded" << endl;
|
---|
| 250 |
|
---|
[1522] | 251 | Cleanup();
|
---|
| 252 | exit(1);
|
---|
| 253 | }
|
---|
[1999] | 254 |
|
---|
[2048] | 255 | string viewCellPointsFile;
|
---|
[2017] | 256 |
|
---|
[2048] | 257 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 258 | viewCellPointsFile = ReplaceSuffix(filename, ".obj", ".vc");
|
---|
| 259 | else if (strstr(filename.c_str(), ".dat"))
|
---|
| 260 | viewCellPointsFile = ReplaceSuffix(filename, ".dat", ".vc");
|
---|
| 261 | else if (strstr(filename.c_str(), ".x3d"))
|
---|
| 262 | viewCellPointsFile = ReplaceSuffix(filename, ".x3d", ".vc");
|
---|
[2023] | 263 |
|
---|
[2048] | 264 | bool importRandomViewCells;
|
---|
| 265 | Environment::GetSingleton()->GetBoolValue("ViewCells.importRandomViewCells",
|
---|
| 266 | importRandomViewCells);
|
---|
| 267 |
|
---|
| 268 | if (importRandomViewCells)
|
---|
| 269 | {
|
---|
| 270 | cout << "importing random view cells" << endl;
|
---|
[2598] | 271 | preprocessor->mViewCellsManager->ImportViewCellsList(viewCellPointsFile);
|
---|
[2048] | 272 | cout << "finished" << endl;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[1968] | 275 | bool useHwGlobalLines;
|
---|
| 276 | Environment::GetSingleton()->GetBoolValue("Preprocessor.useHwGlobalLines",
|
---|
| 277 | useHwGlobalLines);
|
---|
| 278 |
|
---|
| 279 | if (useHwGlobalLines)
|
---|
| 280 | preprocessor->PrepareHwGlobalLines();
|
---|
| 281 |
|
---|
[1239] | 282 | // create a preprocessor thread (note: capsulates calls to boost fuctions!)
|
---|
[1926] | 283 | PreprocessorThread *pt = NULL;
|
---|
[1968] | 284 |
|
---|
[2560] | 285 | //preprocessor->PrepareHwGlobalLines();
|
---|
| 286 | //globalLinesRenderer->Run();
|
---|
[1940] | 287 |
|
---|
| 288 |
|
---|
[1248] | 289 | bool guiSupported = false;
|
---|
[2560] | 290 | const bool useRendererBuffer = true;
|
---|
[2049] | 291 |
|
---|
| 292 | int frames;
|
---|
| 293 | Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", frames);
|
---|
[2560] | 294 |
|
---|
[2611] | 295 | bool evalPixelError;
|
---|
| 296 | Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", evalPixelError);
|
---|
| 297 |
|
---|
[2049] | 298 | #ifdef USE_QT
|
---|
| 299 |
|
---|
[2560] | 300 | // create a qt application first (must be created before any opengl widget ...)
|
---|
| 301 | QApplication *app = new QApplication(argc, NULL);
|
---|
| 302 | pt = new QtPreprocessorThread(preprocessor);
|
---|
| 303 |
|
---|
[2611] | 304 | // if (preprocessor->mUseGlRenderer && (importRandomViewCells || frames))
|
---|
[2610] | 305 |
|
---|
[2611] | 306 | if (evalPixelError && (importRandomViewCells || frames))
|
---|
[2610] | 307 | {
|
---|
[2049] | 308 | QGLFormat f;
|
---|
| 309 | f.setStencil(true);
|
---|
| 310 | QGLFormat::setDefaultFormat(f);
|
---|
| 311 | // NOTE: render texture should be power of 2 and square
|
---|
| 312 | // renderer must be initialised
|
---|
| 313 | // $$matt
|
---|
| 314 | preprocessor->renderer =
|
---|
[2610] | 315 | new QtGlRendererBuffer(512, 512,
|
---|
| 316 | preprocessor->mSceneGraph,
|
---|
| 317 | preprocessor->mViewCellsManager,
|
---|
| 318 | preprocessor->mKdTree);
|
---|
| 319 |
|
---|
| 320 | }
|
---|
| 321 |
|
---|
[2560] | 322 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
| 323 | {
|
---|
| 324 | ////////
|
---|
| 325 | //-- create and run the preprocessor application in a parallel thread
|
---|
[1926] | 326 |
|
---|
[2560] | 327 | cout << "using gl widget" << endl;
|
---|
[2049] | 328 |
|
---|
[2560] | 329 | pt->InitThread();
|
---|
| 330 | pt->RunThread();
|
---|
[1613] | 331 |
|
---|
[2560] | 332 | // display the render widget
|
---|
| 333 | if (!rendererWidget)
|
---|
| 334 | {
|
---|
| 335 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
| 336 | cout << "damn" << endl;
|
---|
| 337 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
| 338 | "This system does not support OpenGL/pbuffers.",
|
---|
| 339 | QMessageBox::Ok);
|
---|
| 340 | return NULL;
|
---|
| 341 | }
|
---|
[2017] | 342 |
|
---|
[2560] | 343 | rendererWidget =
|
---|
| 344 | new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
| 345 | preprocessor->mViewCellsManager,
|
---|
| 346 | preprocessor->mKdTree);
|
---|
[2017] | 347 |
|
---|
[2560] | 348 | rendererWidget->Show();
|
---|
[2023] | 349 |
|
---|
[2615] | 350 | //rendererWidget->SetWindowTitle("Global Visualization");
|
---|
| 351 |
|
---|
[2560] | 352 | if (1) // not working with vbo
|
---|
| 353 | {
|
---|
[2569] | 354 | cout << "starting the qt viewer" << endl;
|
---|
[2560] | 355 | QtGlViewer *viewer =
|
---|
| 356 | new QtGlViewer(NULL, (QtGlRendererWidget *)rendererWidget);
|
---|
| 357 | viewer->show();
|
---|
| 358 | }
|
---|
[2538] | 359 |
|
---|
[2560] | 360 | guiSupported = true;
|
---|
| 361 | }
|
---|
[2538] | 362 |
|
---|
[2560] | 363 | bool exportRandomViewCells;
|
---|
| 364 | Environment::GetSingleton()->GetBoolValue("ViewCells.exportRandomViewCells",
|
---|
| 365 | exportRandomViewCells);
|
---|
[2538] | 366 |
|
---|
[2560] | 367 | if (exportRandomViewCells)
|
---|
| 368 | {
|
---|
| 369 | cout << "exporting random view cells" << endl;
|
---|
| 370 | preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile);
|
---|
| 371 | cout << "finished" << endl;
|
---|
| 372 | }
|
---|
[2538] | 373 |
|
---|
[2560] | 374 | /*bool evaluatePixelError;
|
---|
| 375 | Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", evaluatePixelError);
|
---|
[2538] | 376 |
|
---|
[2560] | 377 | if (evaluatePixelError)
|
---|
| 378 | {
|
---|
| 379 | cout << "evaluating pixel error" << endl;
|
---|
| 380 | preprocessor->ComputeRenderError();
|
---|
| 381 | }*/
|
---|
[2538] | 382 |
|
---|
[2560] | 383 | qApp->exec();
|
---|
| 384 | }
|
---|
| 385 | #else // USE_QUT
|
---|
[2538] | 386 |
|
---|
[2560] | 387 | //#if USE_THREADS
|
---|
| 388 | // pt = new BoostPreprocessorThread(preprocessor);
|
---|
| 389 | //#else
|
---|
| 390 | // use a dummy thread
|
---|
| 391 | pt = new DummyPreprocessorThread(preprocessor);
|
---|
| 392 | //#endif
|
---|
[1387] | 393 | #endif
|
---|
[1785] | 394 |
|
---|
[2560] | 395 | preprocessor->SetThread(pt);
|
---|
[1696] | 396 |
|
---|
[2560] | 397 | // no gui available
|
---|
| 398 | if (!guiSupported)
|
---|
| 399 | {
|
---|
| 400 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
| 401 | cout << "warning: gui not supported!" << endl;
|
---|
[2538] | 402 |
|
---|
[2560] | 403 | preprocessor->mUseGlRenderer = false;
|
---|
| 404 | preprocessor->mUseGlDebugger = false;
|
---|
| 405 | }
|
---|
[1999] | 406 |
|
---|
[2560] | 407 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger))
|
---|
| 408 | {
|
---|
| 409 | cout << "executing main thread" << endl;
|
---|
| 410 | // just call the mail method -> will be executed in the main thread
|
---|
| 411 | pt->Main();
|
---|
| 412 | }
|
---|
[2538] | 413 |
|
---|
[2560] | 414 | // release memory
|
---|
| 415 | Cleanup();
|
---|
| 416 | delete pt;
|
---|
| 417 |
|
---|
| 418 | return returnCode;
|
---|
[162] | 419 | }
|
---|
| 420 |
|
---|