[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 | {
|
---|
[2575] | 133 | #if 0
|
---|
| 134 | // Test code by VH
|
---|
[2629] | 135 | TestRTcamera(argc, argv);
|
---|
[2575] | 136 | //TestRTfromFile(argc, argv);
|
---|
[2629] | 137 | //TestRTfromFilePackets(argc, argv);
|
---|
| 138 | //TestRT_4_fromFile(argc, argv);
|
---|
[2575] | 139 | return 0;
|
---|
| 140 | #endif
|
---|
[2657] | 141 | cout<<"hello world"<<endl;
|
---|
[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))
|
---|
[2625] | 307 | {
|
---|
[2049] | 308 | QGLFormat f;
|
---|
| 309 | f.setStencil(true);
|
---|
| 310 | QGLFormat::setDefaultFormat(f);
|
---|
[2625] | 311 |
|
---|
[2049] | 312 | // NOTE: render texture should be power of 2 and square
|
---|
| 313 | // renderer must be initialised
|
---|
| 314 | // $$matt
|
---|
| 315 | preprocessor->renderer =
|
---|
[2634] | 316 | new QtGlRendererBuffer(1024, 1024,
|
---|
| 317 | preprocessor->mSceneGraph,
|
---|
| 318 | preprocessor->mViewCellsManager,
|
---|
| 319 | preprocessor->mKdTree);
|
---|
| 320 |
|
---|
[2647] | 321 | }
|
---|
| 322 |
|
---|
| 323 | bool exportRandomViewCells;
|
---|
| 324 | Environment::GetSingleton()->GetBoolValue("ViewCells.exportRandomViewCells",
|
---|
| 325 | exportRandomViewCells);
|
---|
| 326 |
|
---|
| 327 | if (exportRandomViewCells)
|
---|
| 328 | {
|
---|
| 329 | cout << "exporting random view cells" << endl;
|
---|
| 330 | preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile);
|
---|
| 331 | cout << "finished" << endl;
|
---|
[2634] | 332 | }
|
---|
[2647] | 333 |
|
---|
[2560] | 334 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
| 335 | {
|
---|
| 336 | ////////
|
---|
| 337 | //-- create and run the preprocessor application in a parallel thread
|
---|
[1926] | 338 |
|
---|
[2560] | 339 | cout << "using gl widget" << endl;
|
---|
[2049] | 340 |
|
---|
[2560] | 341 | pt->InitThread();
|
---|
| 342 | pt->RunThread();
|
---|
[1613] | 343 |
|
---|
[2560] | 344 | // display the render widget
|
---|
| 345 | if (!rendererWidget)
|
---|
| 346 | {
|
---|
| 347 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
| 348 | cout << "damn" << endl;
|
---|
| 349 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
| 350 | "This system does not support OpenGL/pbuffers.",
|
---|
| 351 | QMessageBox::Ok);
|
---|
| 352 | return NULL;
|
---|
| 353 | }
|
---|
[2017] | 354 |
|
---|
[2560] | 355 | rendererWidget =
|
---|
| 356 | new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
[2625] | 357 | preprocessor->mViewCellsManager,
|
---|
| 358 | preprocessor->mKdTree);
|
---|
[2017] | 359 |
|
---|
[2560] | 360 | rendererWidget->Show();
|
---|
[2023] | 361 |
|
---|
[2625] | 362 | // hack matt
|
---|
| 363 | preprocessor->mRendererWidget = rendererWidget;
|
---|
[2615] | 364 | //rendererWidget->SetWindowTitle("Global Visualization");
|
---|
| 365 |
|
---|
[2560] | 366 | if (1) // not working with vbo
|
---|
| 367 | {
|
---|
[2569] | 368 | cout << "starting the qt viewer" << endl;
|
---|
[2560] | 369 | QtGlViewer *viewer =
|
---|
| 370 | new QtGlViewer(NULL, (QtGlRendererWidget *)rendererWidget);
|
---|
| 371 | viewer->show();
|
---|
| 372 | }
|
---|
[2538] | 373 |
|
---|
[2560] | 374 | guiSupported = true;
|
---|
| 375 | }
|
---|
[2538] | 376 |
|
---|
| 377 |
|
---|
[2560] | 378 | /*bool evaluatePixelError;
|
---|
| 379 | Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", evaluatePixelError);
|
---|
[2538] | 380 |
|
---|
[2560] | 381 | if (evaluatePixelError)
|
---|
| 382 | {
|
---|
| 383 | cout << "evaluating pixel error" << endl;
|
---|
| 384 | preprocessor->ComputeRenderError();
|
---|
| 385 | }*/
|
---|
[2538] | 386 |
|
---|
[2560] | 387 | qApp->exec();
|
---|
| 388 | }
|
---|
| 389 | #else // USE_QUT
|
---|
[2538] | 390 |
|
---|
[2560] | 391 | //#if USE_THREADS
|
---|
| 392 | // pt = new BoostPreprocessorThread(preprocessor);
|
---|
| 393 | //#else
|
---|
| 394 | // use a dummy thread
|
---|
| 395 | pt = new DummyPreprocessorThread(preprocessor);
|
---|
| 396 | //#endif
|
---|
[1387] | 397 | #endif
|
---|
[1785] | 398 |
|
---|
[2560] | 399 | preprocessor->SetThread(pt);
|
---|
[1696] | 400 |
|
---|
[2560] | 401 | // no gui available
|
---|
| 402 | if (!guiSupported)
|
---|
| 403 | {
|
---|
| 404 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
| 405 | cout << "warning: gui not supported!" << endl;
|
---|
[2538] | 406 |
|
---|
[2560] | 407 | preprocessor->mUseGlRenderer = false;
|
---|
| 408 | preprocessor->mUseGlDebugger = false;
|
---|
| 409 | }
|
---|
[1999] | 410 |
|
---|
[2560] | 411 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger))
|
---|
| 412 | {
|
---|
| 413 | cout << "executing main thread" << endl;
|
---|
| 414 | // just call the mail method -> will be executed in the main thread
|
---|
| 415 | pt->Main();
|
---|
| 416 | }
|
---|
[2538] | 417 |
|
---|
[2560] | 418 | // release memory
|
---|
| 419 | Cleanup();
|
---|
| 420 | delete pt;
|
---|
| 421 |
|
---|
| 422 | return returnCode;
|
---|
[162] | 423 | }
|
---|
| 424 |
|
---|