[1272] | 1 | #ifdef GTP_INTERNAL
|
---|
| 2 | //#define USE_QT 0
|
---|
| 3 | #endif
|
---|
| 4 |
|
---|
[1387] | 5 | #define USE_THREADS 1
|
---|
[1272] | 6 |
|
---|
[1199] | 7 | #ifdef UNICODE
|
---|
| 8 | #undef UNICODE
|
---|
| 9 | #endif
|
---|
| 10 |
|
---|
[1151] | 11 | #include <windows.h>
|
---|
| 12 | #include <stdio.h>
|
---|
| 13 | #include <crtdbg.h>
|
---|
| 14 |
|
---|
[162] | 15 | #include "SamplingPreprocessor.h"
|
---|
[374] | 16 | #include "VssPreprocessor.h"
|
---|
[446] | 17 | #include "RssPreprocessor.h"
|
---|
[162] | 18 | #include "ExactPreprocessor.h"
|
---|
| 19 | #include "Parser.h"
|
---|
| 20 | #include "UnigraphicsParser.h"
|
---|
[170] | 21 | #include "X3dParser.h"
|
---|
[162] | 22 | #include "Environment.h"
|
---|
| 23 | #include "Camera.h"
|
---|
[170] | 24 | #include "MeshKdTree.h"
|
---|
[264] | 25 | #include "Exporter.h"
|
---|
[310] | 26 | #include "ViewCell.h"
|
---|
[321] | 27 | #include "SceneGraph.h"
|
---|
[1272] | 28 |
|
---|
[1387] | 29 | #if USE_THREADS && !USE_QT
|
---|
[1146] | 30 | #include "BoostPreprocessorThread.h"
|
---|
[1272] | 31 | #endif
|
---|
| 32 |
|
---|
[878] | 33 | #include "RenderSampler.h"
|
---|
[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 |
|
---|
[1241] | 55 |
|
---|
[1145] | 56 | void Cleanup()
|
---|
| 57 | {
|
---|
[1151] | 58 | DEL_PTR(rendererWidget);
|
---|
[1145] | 59 | DEL_PTR(preprocessor);
|
---|
| 60 |
|
---|
| 61 | Environment::DelSingleton();
|
---|
| 62 | MeshManager::DelSingleton();
|
---|
| 63 | MaterialManager::DelSingleton();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 |
|
---|
[1272] | 69 | string ReplaceSuffix(string filename,
|
---|
| 70 | string a,
|
---|
| 71 | string b)
|
---|
| 72 | {
|
---|
| 73 | string result = filename;
|
---|
| 74 |
|
---|
[1328] | 75 | int pos = (int)filename.rfind(a, (int)filename.size() - 1);
|
---|
[1272] | 76 | if (pos == filename.size() - a.size()) {
|
---|
| 77 | result.replace(pos, a.size(), b);
|
---|
| 78 | }
|
---|
| 79 | return result;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[162] | 82 | int
|
---|
[492] | 83 | main(int argc, char **argv)
|
---|
[997] | 84 | {
|
---|
[991] | 85 |
|
---|
[1145] | 86 | //Now just call this function at the start of your program and if you're
|
---|
| 87 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
| 88 | //window when the program shuts down. If you're not in debug mode this will
|
---|
| 89 | //be ignored. Use it as you will!
|
---|
| 90 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
[1272] | 91 | #if 0
|
---|
| 92 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
| 93 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
| 94 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
| 95 | #endif
|
---|
[997] | 96 |
|
---|
[1145] | 97 | int returnCode = 0;
|
---|
[1153] | 98 |
|
---|
[1145] | 99 | InitTiming();
|
---|
[997] | 100 |
|
---|
[1145] | 101 | Debug.open("debug.log");
|
---|
[1199] | 102 |
|
---|
[1145] | 103 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 104 | MeshKdTree::ParseEnvironment();
|
---|
[1002] | 105 |
|
---|
[1292] | 106 |
|
---|
[1145] | 107 | char buff[128];
|
---|
| 108 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 109 | string preprocessorType(buff);
|
---|
| 110 |
|
---|
| 111 | if (preprocessorType == "vss")
|
---|
[1328] | 112 | {
|
---|
[1145] | 113 | preprocessor = new VssPreprocessor();
|
---|
[1328] | 114 | }
|
---|
[374] | 115 | else
|
---|
[1002] | 116 | {
|
---|
[1145] | 117 | if (preprocessorType == "rss")
|
---|
[1002] | 118 | {
|
---|
[1145] | 119 | preprocessor = new RssPreprocessor();
|
---|
[1002] | 120 | }
|
---|
[811] | 121 | else
|
---|
[1145] | 122 | {
|
---|
| 123 | if (preprocessorType == "exact")
|
---|
| 124 | {
|
---|
| 125 | preprocessor = new ExactPreprocessor();
|
---|
| 126 | }
|
---|
| 127 | else
|
---|
| 128 | {
|
---|
| 129 | if (preprocessorType == "sampling")
|
---|
| 130 | {
|
---|
| 131 | preprocessor = new SamplingPreprocessor();
|
---|
| 132 | }
|
---|
| 133 | else
|
---|
| 134 | {
|
---|
| 135 | if (preprocessorType == "render")
|
---|
| 136 | {
|
---|
| 137 | preprocessor = new RenderSampler();
|
---|
| 138 | }
|
---|
[1328] | 139 | else
|
---|
| 140 | {
|
---|
[1145] | 141 | Environment::DelSingleton();
|
---|
| 142 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
| 143 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
| 144 | exit(1);
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
[1002] | 148 | }
|
---|
| 149 | }
|
---|
[997] | 150 |
|
---|
[1328] | 151 | ////////////////////////////////////////
|
---|
[1145] | 152 | //-- load scene
|
---|
[492] | 153 |
|
---|
[1145] | 154 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 155 | string filename(buff);
|
---|
[1328] | 156 |
|
---|
| 157 | if (!preprocessor->LoadScene(filename))
|
---|
| 158 | {
|
---|
| 159 | cout << "loading file " << filename << " failed" << endl;
|
---|
| 160 | Cleanup();
|
---|
| 161 | exit(1);
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[1272] | 164 | string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
[1328] | 165 |
|
---|
[1221] | 166 | //-- initialize external ray casters
|
---|
[1272] | 167 | if (preprocessor->InitRayCast(rayCastFile))
|
---|
[1328] | 168 | {
|
---|
[1221] | 169 | cout << "ray casting initialized!" << endl;
|
---|
[1328] | 170 | }
|
---|
[1221] | 171 | else
|
---|
| 172 | {
|
---|
| 173 | cout << "ray casting initialization failed" << endl;
|
---|
[1328] | 174 | Cleanup();
|
---|
[1221] | 175 | exit(1);
|
---|
| 176 | }
|
---|
[1344] | 177 |
|
---|
[1145] | 178 | //-- build kd tree from scene geometry
|
---|
| 179 | preprocessor->BuildKdTree();
|
---|
| 180 | preprocessor->KdTreeStatistics(cout);
|
---|
[1344] | 181 |
|
---|
[1221] | 182 | /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
|
---|
[1197] | 183 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
| 184 |
|
---|
[1196] | 185 | KdTree *kdTree2 = new KdTree;
|
---|
[1201] | 186 |
|
---|
| 187 | cout << "loading kd tree ... ";
|
---|
| 188 | long startTime = GetTime();
|
---|
| 189 | kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
|
---|
| 190 |
|
---|
| 191 | cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
| 192 |
|
---|
| 193 | Exporter *exporter = Exporter::GetExporter("testkd.x3d");
|
---|
[1197] | 194 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
| 195 |
|
---|
[1196] | 196 | if (exporter)
|
---|
| 197 | {
|
---|
| 198 | exporter->SetWireframe();
|
---|
[1197] | 199 | exporter->ExportKdTree(*kdTree2, true);
|
---|
[1196] | 200 |
|
---|
| 201 | delete exporter;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | DEL_PTR(kdTree2);
|
---|
[1344] | 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 | #if USE_THREADS
|
---|
| 218 | PreprocessorThread *pt;
|
---|
| 219 |
|
---|
| 220 | #if USE_QT
|
---|
| 221 | pt = new QtPreprocessorThread(preprocessor);
|
---|
| 222 | #else
|
---|
| 223 | pt = new BoostPreprocessorThread(preprocessor);
|
---|
[1272] | 224 | #endif
|
---|
[1387] | 225 | #endif
|
---|
| 226 |
|
---|
[1272] | 227 |
|
---|
[1248] | 228 | bool guiSupported = false;
|
---|
[1145] | 229 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
[1387] | 230 | {
|
---|
[1241] | 231 | cout << "using gl widget" << endl;
|
---|
[1153] | 232 | // create and run the preprocessor application in a parallel thread
|
---|
[1387] | 233 | #if USE_THREADS
|
---|
| 234 | pt->InitThread();
|
---|
| 235 | pt->RunThread();
|
---|
[1272] | 236 | #endif
|
---|
[1387] | 237 |
|
---|
| 238 | #if USE_QT
|
---|
[1248] | 239 | // display the render widget
|
---|
[1344] | 240 | if (!rendererWidget)
|
---|
| 241 | {
|
---|
[1387] | 242 | // create a qt application first (must be created before any opengl widget ...)
|
---|
| 243 | QApplication *app = new QApplication(argc, NULL);
|
---|
| 244 |
|
---|
| 245 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
| 246 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
| 247 | "This system does not support OpenGL/pbuffers.",
|
---|
| 248 | QMessageBox::Ok);
|
---|
| 249 | return NULL;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 |
|
---|
| 253 | rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
| 254 | preprocessor->mViewCellsManager,
|
---|
| 255 | preprocessor->mKdTree);
|
---|
| 256 |
|
---|
| 257 | rendererWidget->Show();
|
---|
| 258 | guiSupported = true;
|
---|
| 259 |
|
---|
| 260 |
|
---|
[1272] | 261 | }
|
---|
[1344] | 262 |
|
---|
[1387] | 263 | qApp->exec();
|
---|
| 264 |
|
---|
| 265 | #endif
|
---|
| 266 | }
|
---|
[1221] | 267 |
|
---|
[1248] | 268 | if (!guiSupported) {
|
---|
| 269 | preprocessor->mUseGlRenderer = false;
|
---|
| 270 | preprocessor->mUseGlDebugger = false;
|
---|
[1005] | 271 | }
|
---|
[1181] | 272 |
|
---|
[1248] | 273 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
|
---|
| 274 | // just call the mail method -> will be executed in the main thread
|
---|
[1387] | 275 | #if USE_THREADS
|
---|
| 276 | pt->RunThread();
|
---|
[1272] | 277 | #endif
|
---|
[1248] | 278 | }
|
---|
| 279 |
|
---|
[1145] | 280 | Cleanup();
|
---|
[1248] | 281 |
|
---|
[1145] | 282 | return returnCode;
|
---|
[162] | 283 | }
|
---|
| 284 |
|
---|