[1272] | 1 | #ifdef GTP_INTERNAL
|
---|
| 2 | //#define USE_QT 0
|
---|
| 3 | #endif
|
---|
| 4 |
|
---|
[1457] | 5 | #define USE_QT 0
|
---|
| 6 | #if USE_QT
|
---|
| 7 | #define USE_BOOST 0
|
---|
| 8 | #else
|
---|
| 9 | #define USE_BOOST 0
|
---|
| 10 | #endif
|
---|
| 11 |
|
---|
[1199] | 12 | #ifdef UNICODE
|
---|
| 13 | #undef UNICODE
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
[1151] | 16 | #include <windows.h>
|
---|
| 17 | #include <stdio.h>
|
---|
| 18 | #include <crtdbg.h>
|
---|
| 19 |
|
---|
[1486] | 20 | #include "PreprocessorFactory.h"
|
---|
[162] | 21 | #include "Parser.h"
|
---|
| 22 | #include "Environment.h"
|
---|
[170] | 23 | #include "MeshKdTree.h"
|
---|
[1486] | 24 | #include "Preprocessor.h"
|
---|
[1272] | 25 |
|
---|
[1486] | 26 |
|
---|
[1457] | 27 | #include "PreprocessorThread.h"
|
---|
| 28 | #if USE_BOOST
|
---|
[1146] | 29 | #include "BoostPreprocessorThread.h"
|
---|
[1272] | 30 | #endif
|
---|
| 31 |
|
---|
[1001] | 32 | #include "ResourceManager.h"
|
---|
[492] | 33 | #include "GlRenderer.h"
|
---|
| 34 |
|
---|
[1272] | 35 | #if USE_QT
|
---|
[1387] | 36 | #include "QtPreprocessorThread.h"
|
---|
| 37 | #include "QtGlRenderer.h"
|
---|
[1272] | 38 | #endif
|
---|
| 39 |
|
---|
[162] | 40 | #define USE_EXE_PATH false
|
---|
| 41 |
|
---|
[372] | 42 |
|
---|
[863] | 43 | using namespace GtpVisibilityPreprocessor;
|
---|
[492] | 44 |
|
---|
[1145] | 45 | Preprocessor *preprocessor = NULL;
|
---|
[1151] | 46 | GlRendererWidget *rendererWidget = NULL;
|
---|
[1145] | 47 |
|
---|
[1151] | 48 | // DLL function signature
|
---|
[1153] | 49 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
[1145] | 50 |
|
---|
[1241] | 51 |
|
---|
[1199] | 52 |
|
---|
[1241] | 53 |
|
---|
[1145] | 54 | void Cleanup()
|
---|
| 55 | {
|
---|
[1151] | 56 | DEL_PTR(rendererWidget);
|
---|
[1145] | 57 | DEL_PTR(preprocessor);
|
---|
| 58 |
|
---|
| 59 | Environment::DelSingleton();
|
---|
| 60 | MeshManager::DelSingleton();
|
---|
| 61 | MaterialManager::DelSingleton();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
[1272] | 67 | string ReplaceSuffix(string filename,
|
---|
| 68 | string a,
|
---|
| 69 | string b)
|
---|
| 70 | {
|
---|
| 71 | string result = filename;
|
---|
| 72 |
|
---|
[1328] | 73 | int pos = (int)filename.rfind(a, (int)filename.size() - 1);
|
---|
[1272] | 74 | if (pos == filename.size() - a.size()) {
|
---|
| 75 | result.replace(pos, a.size(), b);
|
---|
| 76 | }
|
---|
| 77 | return result;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[162] | 80 | int
|
---|
[492] | 81 | main(int argc, char **argv)
|
---|
[997] | 82 | {
|
---|
[991] | 83 |
|
---|
[1145] | 84 | //Now just call this function at the start of your program and if you're
|
---|
| 85 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
| 86 | //window when the program shuts down. If you're not in debug mode this will
|
---|
| 87 | //be ignored. Use it as you will!
|
---|
| 88 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
[1272] | 89 | #if 0
|
---|
| 90 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
| 91 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
| 92 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
| 93 | #endif
|
---|
[997] | 94 |
|
---|
[1145] | 95 | int returnCode = 0;
|
---|
[1153] | 96 |
|
---|
[1145] | 97 | InitTiming();
|
---|
[997] | 98 |
|
---|
[1145] | 99 | Debug.open("debug.log");
|
---|
[1199] | 100 |
|
---|
[1145] | 101 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 102 | MeshKdTree::ParseEnvironment();
|
---|
[1002] | 103 |
|
---|
[1292] | 104 |
|
---|
[1145] | 105 | char buff[128];
|
---|
| 106 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 107 | string preprocessorType(buff);
|
---|
| 108 |
|
---|
[1486] | 109 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
[1328] | 110 | {
|
---|
[1486] | 111 | Environment::DelSingleton();
|
---|
| 112 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 113 | exit(1);
|
---|
[1328] | 114 | }
|
---|
[997] | 115 |
|
---|
[1415] | 116 |
|
---|
| 117 | /////////////
|
---|
[1145] | 118 | //-- load scene
|
---|
[492] | 119 |
|
---|
[1145] | 120 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 121 | string filename(buff);
|
---|
[1328] | 122 |
|
---|
| 123 | if (!preprocessor->LoadScene(filename))
|
---|
| 124 | {
|
---|
| 125 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 126 | Cleanup();
|
---|
| 127 | exit(1);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
[1418] | 131 | string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
| 132 | char internKdTree[100];
|
---|
| 133 | Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree);
|
---|
| 134 |
|
---|
[1221] | 135 | //-- initialize external ray casters
|
---|
[1418] | 136 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
[1328] | 137 | {
|
---|
[1221] | 138 | cout << "ray casting initialized!" << endl;
|
---|
[1328] | 139 | }
|
---|
[1221] | 140 | else
|
---|
| 141 | {
|
---|
| 142 | cout << "ray casting initialization failed" << endl;
|
---|
[1328] | 143 | Cleanup();
|
---|
[1221] | 144 | exit(1);
|
---|
| 145 | }
|
---|
[1344] | 146 |
|
---|
[1418] | 147 | // export kd tree?
|
---|
| 148 | bool exportKdTree;
|
---|
| 149 | Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree);
|
---|
| 150 | if (exportKdTree)
|
---|
| 151 | {
|
---|
| 152 | const long startTime = GetTime();
|
---|
| 153 | cout << "exporting kd tree ... ";
|
---|
| 154 |
|
---|
| 155 | if (!preprocessor->ExportKdTree(internKdTree))
|
---|
| 156 | {
|
---|
| 157 | cout << " error exporting kd tree with filename " << internKdTree << endl;
|
---|
| 158 | }
|
---|
| 159 | else
|
---|
| 160 | {
|
---|
| 161 | cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[1145] | 165 | // parse view cells related options
|
---|
| 166 | preprocessor->PrepareViewCells();
|
---|
| 167 |
|
---|
[1196] | 168 | if (0)
|
---|
| 169 | {
|
---|
[1145] | 170 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
| 171 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
[746] | 172 | }
|
---|
[1344] | 173 |
|
---|
[1239] | 174 | // create a preprocessor thread (note: capsulates calls to boost fuctions!)
|
---|
[1272] | 175 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
[1387] | 176 | PreprocessorThread *pt;
|
---|
| 177 |
|
---|
| 178 | #if USE_QT
|
---|
| 179 | pt = new QtPreprocessorThread(preprocessor);
|
---|
| 180 | #else
|
---|
[1457] | 181 | #if USE_BOOST
|
---|
[1387] | 182 | pt = new BoostPreprocessorThread(preprocessor);
|
---|
[1457] | 183 | #else
|
---|
| 184 | pt = new PreprocessorThread(preprocessor);
|
---|
| 185 | #endif
|
---|
[1272] | 186 | #endif
|
---|
[1387] | 187 |
|
---|
[1248] | 188 | bool guiSupported = false;
|
---|
[1454] | 189 |
|
---|
[1145] | 190 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
[1387] | 191 | {
|
---|
[1241] | 192 | cout << "using gl widget" << endl;
|
---|
[1153] | 193 | // create and run the preprocessor application in a parallel thread
|
---|
[1457] | 194 | #if USE_QT
|
---|
[1387] | 195 | #if USE_THREADS
|
---|
| 196 | pt->InitThread();
|
---|
| 197 | pt->RunThread();
|
---|
[1272] | 198 | #endif
|
---|
[1387] | 199 |
|
---|
[1248] | 200 | // display the render widget
|
---|
[1344] | 201 | if (!rendererWidget)
|
---|
| 202 | {
|
---|
[1387] | 203 | // create a qt application first (must be created before any opengl widget ...)
|
---|
| 204 | QApplication *app = new QApplication(argc, NULL);
|
---|
| 205 |
|
---|
| 206 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
| 207 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
| 208 | "This system does not support OpenGL/pbuffers.",
|
---|
| 209 | QMessageBox::Ok);
|
---|
| 210 | return NULL;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 | rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
| 215 | preprocessor->mViewCellsManager,
|
---|
| 216 | preprocessor->mKdTree);
|
---|
| 217 |
|
---|
| 218 | rendererWidget->Show();
|
---|
[1404] | 219 | guiSupported = true;
|
---|
[1272] | 220 | }
|
---|
[1344] | 221 |
|
---|
[1404] | 222 | qApp->exec();
|
---|
[1387] | 223 | #endif
|
---|
| 224 | }
|
---|
[1221] | 225 |
|
---|
[1248] | 226 | if (!guiSupported) {
|
---|
| 227 | preprocessor->mUseGlRenderer = false;
|
---|
| 228 | preprocessor->mUseGlDebugger = false;
|
---|
[1005] | 229 | }
|
---|
[1181] | 230 |
|
---|
[1248] | 231 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
|
---|
| 232 | // just call the mail method -> will be executed in the main thread
|
---|
[1454] | 233 | pt->Main();
|
---|
[1248] | 234 | }
|
---|
| 235 |
|
---|
[1415] | 236 | // release memory
|
---|
[1145] | 237 | Cleanup();
|
---|
[1248] | 238 |
|
---|
[1145] | 239 | return returnCode;
|
---|
[162] | 240 | }
|
---|
| 241 |
|
---|