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

Revision 1581, 5.5 KB checked in by bittner, 18 years ago (diff)

Qtglwidget changes - second view + trackball - ray casting seems not functional

RevLine 
[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]41using namespace GtpVisibilityPreprocessor;
[492]42
[1145]43Preprocessor *preprocessor = NULL;
[1151]44GlRendererWidget *rendererWidget = NULL;
[1145]45
[1151]46// DLL function signature
[1153]47typedef GlRendererWidget *(*importFunction)(Preprocessor *);
[1145]48
[1241]49
[1199]50
[1241]51
[1145]52void 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
63
64
[1272]65string ReplaceSuffix(string filename,
66                                         string a,
67                                         string b)
68{
69  string result = filename;
70
[1328]71  int pos = (int)filename.rfind(a, (int)filename.size() - 1);
[1272]72  if (pos == filename.size() - a.size()) {
73        result.replace(pos, a.size(), b);
74  }
75  return result;
76}
77
[162]78int
[492]79main(int argc, char **argv)
[997]80{
[991]81
[1145]82        //Now just call this function at the start of your program and if you're
83        //compiling in debug mode (F5), any leaks will be displayed in the Output
84        //window when the program shuts down. If you're not in debug mode this will
85        //be ignored. Use it as you will!
86        //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
[1272]87#if 0
88  _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
89  _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
90  _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
91#endif
[997]92
[1145]93        int returnCode = 0;
[1153]94       
[1145]95        InitTiming();
[997]96
[1145]97        Debug.open("debug.log");
[1199]98 
[1145]99        Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
100        MeshKdTree::ParseEnvironment();
[1002]101
[1292]102       
[1145]103        char buff[128];
104        Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
105        string preprocessorType(buff);
106
[1486]107        if (!(preprocessor = PreprocessorFactory::CreatePreprocessor(preprocessorType)))
[1328]108        {
[1486]109                Environment::DelSingleton();
110                cerr << "Unknown preprocessor type" << endl;
111                exit(1);
[1328]112        }
[997]113
[1415]114
115        /////////////
[1145]116        //-- load scene
[492]117
[1145]118        Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
119        string filename(buff);
[1328]120
121        if (!preprocessor->LoadScene(filename))
122        {
123                cout << "loading file " << filename << " failed" << endl;
124                Cleanup();
125                exit(1);
126        }
127
[1418]128        string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
129        char internKdTree[100];
130        Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree);
[1580]131        //string internKdTree = ReplaceSuffic(filename, ".x3d", ".kd");
[1418]132
[1221]133        //-- initialize external ray casters
[1418]134        if (preprocessor->InitRayCast(externKdTree, internKdTree))
[1328]135        {
[1221]136                cout << "ray casting initialized!" << endl;
[1328]137        }
[1221]138        else
139        {
140                cout << "ray casting initialization failed" << endl;
[1328]141                Cleanup();
[1221]142                exit(1);
143        }
[1344]144
[1418]145        // export kd tree?
146        bool exportKdTree;
147        Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree);
148        if (exportKdTree)
149        {
150                const long startTime = GetTime();
151                cout << "exporting kd tree ... ";
152
153                if (!preprocessor->ExportKdTree(internKdTree))
154                {
155                        cout << " error exporting kd tree with filename " << internKdTree << endl;
156                }
157                else
158                {
159                        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
160                }
161        }
162
[1145]163        // parse view cells related options
[1522]164        if (!preprocessor->PrepareViewCells())
165        {
166                Cleanup();
167                exit(1);
168        }
[1145]169
[1196]170        if (0)
171        {
[1545]172                preprocessor->Export(filename + "-out.x3d", true, false);
173                preprocessor->Export(filename + "-kdtree.x3d", false, true);   
[746]174        }
[1344]175
[1239]176        // create a preprocessor thread (note: capsulates calls to boost fuctions!)
[1272]177        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
[1387]178        PreprocessorThread *pt;
179
180#if USE_QT
181        pt = new QtPreprocessorThread(preprocessor);
182#else
[1579]183#if USE_THREADS
[1387]184        pt = new BoostPreprocessorThread(preprocessor);
[1457]185#else
186        pt = new PreprocessorThread(preprocessor);
[1272]187#endif
[1579]188#endif
[1387]189
[1248]190        bool guiSupported = false;
[1454]191
[1145]192        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
[1387]193          {
[1241]194                cout << "using gl widget" << endl;
[1153]195                // create and run the preprocessor application in a parallel thread
[1457]196#if USE_QT             
[1387]197#if USE_THREADS
198                pt->InitThread();
199                pt->RunThread();
[1272]200#endif
[1387]201               
[1248]202                // display the render widget
[1344]203                if (!rendererWidget)
204                {
[1387]205                  // create a qt application first (must be created before any opengl widget ...)
206                  QApplication *app = new QApplication(argc, NULL);
207                 
208                  if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
209                        QMessageBox::information(0, "OpenGL pbuffers",
210                                                                         "This system does not support OpenGL/pbuffers.",
211                                                                         QMessageBox::Ok);
212                        return NULL;
213                  }
214                 
215                 
216                  rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
217                                                                                                  preprocessor->mViewCellsManager,
218                                                                                                  preprocessor->mKdTree);
[1581]219                 
[1387]220                  rendererWidget->Show();
[1404]221                  guiSupported = true;
[1272]222                }
[1344]223
[1404]224                qApp->exec();   
[1387]225#endif
226          }
[1221]227       
[1248]228        if (!guiSupported) {
229          preprocessor->mUseGlRenderer = false;
230          preprocessor->mUseGlDebugger = false;
[1005]231        }
[1181]232       
[1248]233        if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
234          // just call the mail method -> will be executed in the main thread
[1454]235          pt->Main();
[1248]236        }
237       
[1415]238        // release memory
[1145]239        Cleanup();
[1248]240       
[1145]241        return returnCode;
[162]242}
243
Note: See TracBrowser for help on using the repository browser.