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

Revision 1486, 5.4 KB checked in by mattausch, 18 years ago (diff)

worked on guided visibility sampling

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