[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"
|
---|
[1634] | 22 | #include "common.h"
|
---|
[1272] | 23 |
|
---|
[1457] | 24 | #include "PreprocessorThread.h"
|
---|
[1694] | 25 | #include "ObjExporter.h"
|
---|
| 26 | #include "SceneGraph.h"
|
---|
[1579] | 27 |
|
---|
[1694] | 28 |
|
---|
| 29 |
|
---|
[1579] | 30 | #if !USE_QT && USE_THREADS
|
---|
[1146] | 31 | #include "BoostPreprocessorThread.h"
|
---|
[1272] | 32 | #endif
|
---|
| 33 |
|
---|
[1001] | 34 | #include "ResourceManager.h"
|
---|
[492] | 35 | #include "GlRenderer.h"
|
---|
| 36 |
|
---|
[1272] | 37 | #if USE_QT
|
---|
[1387] | 38 | #include "QtPreprocessorThread.h"
|
---|
| 39 | #include "QtGlRenderer.h"
|
---|
[1272] | 40 | #endif
|
---|
| 41 |
|
---|
[162] | 42 | #define USE_EXE_PATH false
|
---|
| 43 |
|
---|
[372] | 44 |
|
---|
[863] | 45 | using namespace GtpVisibilityPreprocessor;
|
---|
[492] | 46 |
|
---|
[1145] | 47 | Preprocessor *preprocessor = NULL;
|
---|
[1151] | 48 | GlRendererWidget *rendererWidget = NULL;
|
---|
[1145] | 49 |
|
---|
[1151] | 50 | // DLL function signature
|
---|
[1153] | 51 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
[1145] | 52 |
|
---|
[1241] | 53 |
|
---|
[1199] | 54 |
|
---|
[1145] | 55 | void Cleanup()
|
---|
| 56 | {
|
---|
[1151] | 57 | DEL_PTR(rendererWidget);
|
---|
[1145] | 58 | DEL_PTR(preprocessor);
|
---|
| 59 |
|
---|
| 60 | Environment::DelSingleton();
|
---|
| 61 | MeshManager::DelSingleton();
|
---|
| 62 | MaterialManager::DelSingleton();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
[1626] | 66 | static string ReplaceSuffix(string filename, string a, string b)
|
---|
| 67 | {
|
---|
| 68 | string result = filename;
|
---|
[1145] | 69 |
|
---|
[1626] | 70 | int pos = (int)filename.rfind(a, (int)filename.size() - 1);
|
---|
| 71 | if (pos == filename.size() - a.size()) {
|
---|
| 72 | result.replace(pos, a.size(), b);
|
---|
| 73 | }
|
---|
| 74 | return result;
|
---|
| 75 | }
|
---|
[1145] | 76 |
|
---|
[1626] | 77 |
|
---|
[1634] | 78 | static int SplitFilenames(const string str, vector<string> &filenames)
|
---|
[1272] | 79 | {
|
---|
[1634] | 80 | int pos = 0;
|
---|
[1633] | 81 |
|
---|
[1634] | 82 | while(1) {
|
---|
| 83 | int npos = (int)str.find(';', pos);
|
---|
| 84 |
|
---|
| 85 | if (npos < 0 || npos - pos < 1)
|
---|
| 86 | break;
|
---|
| 87 | filenames.push_back(string(str, pos, npos - pos));
|
---|
| 88 | pos = npos + 1;
|
---|
[1633] | 89 | }
|
---|
[1634] | 90 |
|
---|
| 91 | filenames.push_back(string(str, pos, str.size() - pos));
|
---|
| 92 | return (int)filenames.size();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
[1695] | 96 | static string GetInternFilename(const string &filename, const string newSuffix)
|
---|
[1634] | 97 | {
|
---|
| 98 | vector<string> filenames;
|
---|
| 99 | const int files = SplitFilenames(filename, filenames);
|
---|
| 100 |
|
---|
| 101 | vector<string>::const_iterator sit, sit_end = filenames.end();
|
---|
| 102 | string kdFilename;
|
---|
| 103 |
|
---|
| 104 | int i = 0;
|
---|
| 105 | for (sit = filenames.begin(); sit != sit_end; ++ sit, ++ i)
|
---|
[1633] | 106 | {
|
---|
[1634] | 107 | string currentFile = *sit;
|
---|
| 108 | string strippedFilename;
|
---|
[1633] | 109 |
|
---|
[1634] | 110 | if (i == 0)
|
---|
| 111 | {
|
---|
| 112 | strippedFilename = currentFile;
|
---|
| 113 | }
|
---|
| 114 | else
|
---|
| 115 | {
|
---|
[1640] | 116 | char *str = StripPath(currentFile.c_str());
|
---|
| 117 | strippedFilename = string(str);
|
---|
| 118 |
|
---|
[1695] | 119 | delete [] str;
|
---|
[1634] | 120 | }
|
---|
| 121 |
|
---|
| 122 | string suffix("_");
|
---|
| 123 |
|
---|
| 124 | if (i == (int)filenames.size() - 1)
|
---|
| 125 | {
|
---|
[1695] | 126 | suffix = newSuffix;
|
---|
[1634] | 127 | }
|
---|
| 128 |
|
---|
| 129 | if (strstr(strippedFilename.c_str(), ".x3d"))
|
---|
| 130 | {
|
---|
| 131 | kdFilename += ReplaceSuffix(strippedFilename, ".x3d", suffix);
|
---|
| 132 | }
|
---|
| 133 | else if (strstr(strippedFilename.c_str(), ".dat"))
|
---|
| 134 | {
|
---|
| 135 | kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix);
|
---|
| 136 | }
|
---|
| 137 | else if (strstr(strippedFilename.c_str(), ".obj"))
|
---|
| 138 | {
|
---|
[1658] | 139 | kdFilename += ReplaceSuffix(strippedFilename, ".obj", suffix);
|
---|
[1634] | 140 | }
|
---|
| 141 | else
|
---|
| 142 | {
|
---|
| 143 | cerr << "Error: Currently unsupported format for kd, filename " << currentFile << endl;
|
---|
| 144 | }
|
---|
[1626] | 145 | }
|
---|
[1272] | 146 |
|
---|
[1634] | 147 | //cout << "kdfilename: " << kdFilename << endl;
|
---|
| 148 | return kdFilename;
|
---|
[1272] | 149 | }
|
---|
| 150 |
|
---|
[1626] | 151 |
|
---|
[162] | 152 | int
|
---|
[492] | 153 | main(int argc, char **argv)
|
---|
[997] | 154 | {
|
---|
[991] | 155 |
|
---|
[1145] | 156 | //Now just call this function at the start of your program and if you're
|
---|
| 157 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
| 158 | //window when the program shuts down. If you're not in debug mode this will
|
---|
| 159 | //be ignored. Use it as you will!
|
---|
| 160 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
[1696] | 161 | #if 1
|
---|
[1272] | 162 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
| 163 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
| 164 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
| 165 | #endif
|
---|
[997] | 166 |
|
---|
[1145] | 167 | int returnCode = 0;
|
---|
[1153] | 168 |
|
---|
[1145] | 169 | InitTiming();
|
---|
[997] | 170 |
|
---|
[1145] | 171 | Debug.open("debug.log");
|
---|
[1199] | 172 |
|
---|
[1145] | 173 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 174 | MeshKdTree::ParseEnvironment();
|
---|
[1002] | 175 |
|
---|
[1292] | 176 |
|
---|
[1145] | 177 | char buff[128];
|
---|
| 178 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 179 | string preprocessorType(buff);
|
---|
| 180 |
|
---|
[1486] | 181 | if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
|
---|
[1328] | 182 | {
|
---|
[1486] | 183 | Environment::DelSingleton();
|
---|
| 184 | cerr << "Unknown preprocessor type" << endl;
|
---|
| 185 | exit(1);
|
---|
[1328] | 186 | }
|
---|
[997] | 187 |
|
---|
[1415] | 188 |
|
---|
| 189 | /////////////
|
---|
[1145] | 190 | //-- load scene
|
---|
[492] | 191 |
|
---|
[1145] | 192 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 193 | string filename(buff);
|
---|
[1695] | 194 |
|
---|
[1328] | 195 |
|
---|
| 196 | if (!preprocessor->LoadScene(filename))
|
---|
| 197 | {
|
---|
| 198 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 199 | Cleanup();
|
---|
| 200 | exit(1);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[1626] | 203 | const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
[1695] | 204 | const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ? ".kdm" : ".kdt");
|
---|
[1418] | 205 |
|
---|
[1697] | 206 | ////////////
|
---|
| 207 | //-- initialize external ray caster
|
---|
[1695] | 208 |
|
---|
[1418] | 209 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
[1328] | 210 | {
|
---|
[1221] | 211 | cout << "ray casting initialized!" << endl;
|
---|
[1328] | 212 | }
|
---|
[1221] | 213 | else
|
---|
| 214 | {
|
---|
| 215 | cout << "ray casting initialization failed" << endl;
|
---|
[1328] | 216 | Cleanup();
|
---|
[1221] | 217 | exit(1);
|
---|
| 218 | }
|
---|
[1344] | 219 |
|
---|
[1695] | 220 |
|
---|
| 221 | // export objects as obj
|
---|
| 222 | if (preprocessor->mExportObj)
|
---|
| 223 | {
|
---|
| 224 | if (strstr(filename.c_str(), ".obj"))
|
---|
| 225 | {
|
---|
| 226 | cerr << "already in obj format" << endl;
|
---|
[1701] | 227 | if (0) preprocessor->ExportObj("test.obj", preprocessor->mObjects);
|
---|
[1695] | 228 | }
|
---|
| 229 | else
|
---|
| 230 | {
|
---|
| 231 | const string objname = GetInternFilename(filename, ".obj");
|
---|
| 232 |
|
---|
[1701] | 233 | cout << "exporting scene to " << objname << endl;
|
---|
[1695] | 234 | bool success = preprocessor->ExportObj(objname, preprocessor->mObjects);
|
---|
| 235 |
|
---|
| 236 | if (success)
|
---|
| 237 | {
|
---|
| 238 | cout << "finished exporting obj" << endl;
|
---|
| 239 | }
|
---|
| 240 | else
|
---|
| 241 | {
|
---|
| 242 | cerr << "error exporting " << objname << endl;
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
[1713] | 246 | if (0){
|
---|
| 247 | Exporter *exporter= Exporter::GetExporter("test1.wrl");
|
---|
| 248 | AxisAlignedBox3 bbox = preprocessor->mKdTree->GetBox();
|
---|
| 249 | bbox.Scale(Vector3(0.5, 1, 0.5));
|
---|
| 250 | exporter->SetWireframe();
|
---|
| 251 | exporter->ExportBox(preprocessor->mKdTree->GetBox());
|
---|
| 252 | exporter->ExportBox(bbox);
|
---|
| 253 | exporter->SetFilled();
|
---|
| 254 | exporter->ExportGeometry(preprocessor->mObjects, true, &bbox);
|
---|
| 255 | delete exporter;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 |
|
---|
[1145] | 259 | // parse view cells related options
|
---|
[1522] | 260 | if (!preprocessor->PrepareViewCells())
|
---|
| 261 | {
|
---|
| 262 | Cleanup();
|
---|
| 263 | exit(1);
|
---|
| 264 | }
|
---|
[1145] | 265 |
|
---|
[1196] | 266 | if (0)
|
---|
| 267 | {
|
---|
[1545] | 268 | preprocessor->Export(filename + "-out.x3d", true, false);
|
---|
| 269 | preprocessor->Export(filename + "-kdtree.x3d", false, true);
|
---|
[746] | 270 | }
|
---|
[1344] | 271 |
|
---|
[1239] | 272 | // create a preprocessor thread (note: capsulates calls to boost fuctions!)
|
---|
[1272] | 273 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
[1387] | 274 | PreprocessorThread *pt;
|
---|
| 275 |
|
---|
[1715] | 276 |
|
---|
[1387] | 277 | #if USE_QT
|
---|
[1715] | 278 | // create a qt application first (must be created before any opengl widget ...)
|
---|
| 279 | QApplication *app = new QApplication(argc, NULL);
|
---|
| 280 |
|
---|
[1387] | 281 | pt = new QtPreprocessorThread(preprocessor);
|
---|
| 282 | #else
|
---|
[1579] | 283 | #if USE_THREADS
|
---|
[1387] | 284 | pt = new BoostPreprocessorThread(preprocessor);
|
---|
[1457] | 285 | #else
|
---|
| 286 | pt = new PreprocessorThread(preprocessor);
|
---|
[1272] | 287 | #endif
|
---|
[1579] | 288 | #endif
|
---|
[1387] | 289 |
|
---|
[1248] | 290 | bool guiSupported = false;
|
---|
[1454] | 291 |
|
---|
[1145] | 292 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
[1387] | 293 | {
|
---|
[1241] | 294 | cout << "using gl widget" << endl;
|
---|
[1153] | 295 | // create and run the preprocessor application in a parallel thread
|
---|
[1457] | 296 | #if USE_QT
|
---|
[1387] | 297 | #if USE_THREADS
|
---|
| 298 | pt->InitThread();
|
---|
[1613] | 299 | if (!preprocessor->mDelayVisibilityComputation)
|
---|
| 300 | pt->RunThread();
|
---|
[1272] | 301 | #endif
|
---|
[1387] | 302 |
|
---|
[1248] | 303 | // display the render widget
|
---|
[1344] | 304 | if (!rendererWidget)
|
---|
| 305 | {
|
---|
[1387] | 306 |
|
---|
| 307 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
| 308 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
| 309 | "This system does not support OpenGL/pbuffers.",
|
---|
| 310 | QMessageBox::Ok);
|
---|
| 311 | return NULL;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 |
|
---|
| 315 | rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
| 316 | preprocessor->mViewCellsManager,
|
---|
| 317 | preprocessor->mKdTree);
|
---|
[1613] | 318 |
|
---|
| 319 | ((QtGlRendererWidget *)rendererWidget)->SetThread((QtPreprocessorThread *)pt);
|
---|
[1387] | 320 | rendererWidget->Show();
|
---|
[1404] | 321 | guiSupported = true;
|
---|
[1272] | 322 | }
|
---|
[1344] | 323 |
|
---|
[1404] | 324 | qApp->exec();
|
---|
[1387] | 325 | #endif
|
---|
| 326 | }
|
---|
[1221] | 327 |
|
---|
[1248] | 328 | if (!guiSupported) {
|
---|
| 329 | preprocessor->mUseGlRenderer = false;
|
---|
| 330 | preprocessor->mUseGlDebugger = false;
|
---|
[1005] | 331 | }
|
---|
[1696] | 332 |
|
---|
[1248] | 333 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
|
---|
[1696] | 334 | // just call the mail method -> will be executed in the main thread
|
---|
| 335 | pt->Main();
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[1415] | 338 | // release memory
|
---|
[1145] | 339 | Cleanup();
|
---|
[1248] | 340 |
|
---|
[1145] | 341 | return returnCode;
|
---|
[162] | 342 | }
|
---|
| 343 |
|
---|