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