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