source: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp @ 1545

Revision 1545, 5.5 KB checked in by mattausch, 18 years ago (diff)
RevLine 
[1272]1#ifdef GTP_INTERNAL
[1501]2        #define USE_QT 1
3#else
4        #define USE_QT 0
[1272]5#endif
6
[1457]7#if USE_QT
8#define USE_BOOST 0
9#else
[1501]10#define USE_BOOST 1
[1457]11#endif
12
[1199]13#ifdef UNICODE
14#undef UNICODE
15#endif
16
[1151]17#include <windows.h>
18#include <stdio.h>
19#include <crtdbg.h>
20
[1486]21#include "PreprocessorFactory.h"
[162]22#include "Parser.h"
23#include "Environment.h"
[170]24#include "MeshKdTree.h"
[1486]25#include "Preprocessor.h"
[1272]26
[1486]27
[1457]28#include "PreprocessorThread.h"
29#if USE_BOOST
[1146]30#include "BoostPreprocessorThread.h"
[1272]31#endif
32
[1001]33#include "ResourceManager.h"
[492]34#include "GlRenderer.h"
35
[1272]36#if USE_QT
[1387]37#include "QtPreprocessorThread.h"
38#include "QtGlRenderer.h"
[1272]39#endif
40
[162]41#define USE_EXE_PATH false
42
[372]43
[863]44using namespace GtpVisibilityPreprocessor;
[492]45
[1145]46Preprocessor *preprocessor = NULL;
[1151]47GlRendererWidget *rendererWidget = NULL;
[1145]48
[1151]49// DLL function signature
[1153]50typedef GlRendererWidget *(*importFunction)(Preprocessor *);
[1145]51
[1241]52
[1199]53
[1241]54
[1145]55void 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
66
67
[1272]68string ReplaceSuffix(string filename,
69                                         string a,
70                                         string b)
71{
72  string result = filename;
73
[1328]74  int pos = (int)filename.rfind(a, (int)filename.size() - 1);
[1272]75  if (pos == filename.size() - a.size()) {
76        result.replace(pos, a.size(), b);
77  }
78  return result;
79}
80
[162]81int
[492]82main(int argc, char **argv)
[997]83{
[991]84
[1145]85        //Now just call this function at the start of your program and if you're
86        //compiling in debug mode (F5), any leaks will be displayed in the Output
87        //window when the program shuts down. If you're not in debug mode this will
88        //be ignored. Use it as you will!
89        //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
[1272]90#if 0
91  _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
92  _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
93  _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
94#endif
[997]95
[1145]96        int returnCode = 0;
[1153]97       
[1145]98        InitTiming();
[997]99
[1145]100        Debug.open("debug.log");
[1199]101 
[1145]102        Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
103        MeshKdTree::ParseEnvironment();
[1002]104
[1292]105       
[1145]106        char buff[128];
107        Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
108        string preprocessorType(buff);
109
[1486]110        if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
[1328]111        {
[1486]112                Environment::DelSingleton();
113                cerr << "Unknown preprocessor type" << endl;
114                exit(1);
[1328]115        }
[997]116
[1415]117
118        /////////////
[1145]119        //-- load scene
[492]120
[1145]121        Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
122        string filename(buff);
[1328]123
124        if (!preprocessor->LoadScene(filename))
125        {
126                cout << "loading file " << filename << " failed" << endl;
127                Cleanup();
128                exit(1);
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
[1522]166        if (!preprocessor->PrepareViewCells())
167        {
168                Cleanup();
169                exit(1);
170        }
[1145]171
[1196]172        if (0)
173        {
[1545]174                preprocessor->Export(filename + "-out.x3d", true, false);
175                preprocessor->Export(filename + "-kdtree.x3d", false, true);   
[746]176        }
[1344]177
[1239]178        // create a preprocessor thread (note: capsulates calls to boost fuctions!)
[1272]179        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
[1387]180        PreprocessorThread *pt;
181
182#if USE_QT
183        pt = new QtPreprocessorThread(preprocessor);
184#else
[1457]185#if USE_BOOST
[1387]186        pt = new BoostPreprocessorThread(preprocessor);
[1457]187#else
188        pt = new PreprocessorThread(preprocessor);
189#endif 
[1272]190#endif
[1387]191
[1248]192        bool guiSupported = false;
[1454]193
[1145]194        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
[1387]195          {
[1241]196                cout << "using gl widget" << endl;
[1153]197                // create and run the preprocessor application in a parallel thread
[1457]198#if USE_QT             
[1387]199#if USE_THREADS
200                pt->InitThread();
201                pt->RunThread();
[1272]202#endif
[1387]203               
[1248]204                // display the render widget
[1344]205                if (!rendererWidget)
206                {
[1387]207                  // create a qt application first (must be created before any opengl widget ...)
208                  QApplication *app = new QApplication(argc, NULL);
209                 
210                  if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
211                        QMessageBox::information(0, "OpenGL pbuffers",
212                                                                         "This system does not support OpenGL/pbuffers.",
213                                                                         QMessageBox::Ok);
214                        return NULL;
215                  }
216                 
217                 
218                  rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
219                                                                                                  preprocessor->mViewCellsManager,
220                                                                                                  preprocessor->mKdTree);
221
222                  rendererWidget->Show();
[1404]223                  guiSupported = true;
[1272]224                }
[1344]225
[1404]226                qApp->exec();   
[1387]227#endif
228          }
[1221]229       
[1248]230        if (!guiSupported) {
231          preprocessor->mUseGlRenderer = false;
232          preprocessor->mUseGlDebugger = false;
[1005]233        }
[1181]234       
[1248]235        if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
236          // just call the mail method -> will be executed in the main thread
[1454]237          pt->Main();
[1248]238        }
239       
[1415]240        // release memory
[1145]241        Cleanup();
[1248]242       
[1145]243        return returnCode;
[162]244}
245
Note: See TracBrowser for help on using the repository browser.