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

Revision 1284, 6.3 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifdef GTP_INTERNAL
2//#define USE_QT 0
3#endif
4
5#define USE_BOOST 1
6
7#ifdef UNICODE
8#undef UNICODE
9#endif
10
11#include <windows.h>
12#include <stdio.h>
13#include <crtdbg.h>
14
15#include "SamplingPreprocessor.h"
16#include "VssPreprocessor.h"
17#include "RssPreprocessor.h"
18#include "ExactPreprocessor.h"
19#include "Parser.h"
20#include "UnigraphicsParser.h"
21#include "X3dParser.h"
22#include "Environment.h"
23#include "Camera.h"
24#include "MeshKdTree.h"
25#include "Exporter.h"
26#include "ViewCell.h"
27#include "SceneGraph.h"
28
29#if USE_BOOST
30#include "BoostPreprocessorThread.h"
31#endif
32
33#include "RenderSampler.h"
34#include "ResourceManager.h"
35#include "GlRenderer.h"
36
37#if USE_QT
38#include "QtRenderer/QtGlRenderer.h"
39#endif
40
41#define USE_EXE_PATH false
42
43
44using namespace GtpVisibilityPreprocessor;
45
46Preprocessor *preprocessor = NULL;
47GlRendererWidget *rendererWidget = NULL;
48
49// DLL function signature
50typedef GlRendererWidget *(*importFunction)(Preprocessor *);
51
52
53int LoadMyDll()
54{
55        importFunction LoadRenderWidget;
56
57        // Load DLL file
58        HINSTANCE hinstLib = LoadLibrary("../QtGlRenderer/Release/QtGlRenderer.dll");
59
60        if (hinstLib == NULL)
61        {
62                cout << "ERROR: unable to load DLL\n";
63                return 1;
64        }
65 
66        // Get function pointer
67        LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget");
68 
69        if (LoadRenderWidget == NULL)
70        {
71                cout << "ERROR: unable to find DLL function\n";
72                return 1;
73        }
74
75        cout << "loading widget ... ";
76        // load the render window
77        rendererWidget = LoadRenderWidget(preprocessor);
78        cout << "finished" << endl;
79        // Unload DLL file
80        //FreeLibrary(hinstLib);
81 
82        return 0;
83}
84
85
86void Cleanup()
87{
88        DEL_PTR(rendererWidget);
89        DEL_PTR(preprocessor);
90
91        Environment::DelSingleton();
92        MeshManager::DelSingleton();
93        MaterialManager::DelSingleton();
94}
95
96
97void DisplayWidget()
98{
99        if (!rendererWidget)
100        {
101                LoadMyDll();
102        }
103       
104  //rendererWidget->Show();
105}
106
107
108string ReplaceSuffix(string filename,
109                                         string a,
110                                         string b)
111{
112  string result = filename;
113
114  int pos = filename.rfind(a, filename.size()-1);
115  if (pos == filename.size() - a.size()) {
116        result.replace(pos, a.size(), b);
117  }
118  return result;
119}
120
121int
122main(int argc, char **argv)
123{
124
125        //Now just call this function at the start of your program and if you're
126        //compiling in debug mode (F5), any leaks will be displayed in the Output
127        //window when the program shuts down. If you're not in debug mode this will
128        //be ignored. Use it as you will!
129        //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
130#if 0
131  _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
132  _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
133  _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
134#endif
135
136        int returnCode = 0;
137       
138        InitTiming();
139
140        Debug.open("debug.log");
141 
142        Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
143        MeshKdTree::ParseEnvironment();
144
145        char buff[128];
146        Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
147        string preprocessorType(buff);
148
149        if (preprocessorType == "vss")
150          {
151                preprocessor = new VssPreprocessor();
152          }
153        else
154        {
155                if (preprocessorType == "rss")
156                {
157                        preprocessor = new RssPreprocessor();
158                }
159                else
160                {
161                        if (preprocessorType == "exact")
162                        {
163                                preprocessor = new ExactPreprocessor();
164                        }
165                        else
166                        {
167                                if (preprocessorType == "sampling")
168                                {
169                                        preprocessor = new SamplingPreprocessor();
170                                }
171                                else
172                                {       
173                                        if (preprocessorType == "render")
174                                        {
175                                                preprocessor = new RenderSampler();
176                                        }
177                                        else {
178                                                Environment::DelSingleton();
179                                                cerr<<"Unknown preprocessor type"<<endl;
180                                                Debug<<"Unknown preprocessor type"<<endl;
181                                                exit(1);
182                                        }
183                                }
184                        }
185                }
186        }
187       
188
189        //-- load scene
190
191        Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
192        string filename(buff);
193        preprocessor->LoadScene(filename);
194       
195        string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf");
196       
197        //-- initialize external ray casters
198        if (preprocessor->InitRayCast(rayCastFile))
199          {
200                cout << "ray casting initialized!" << endl;
201          }
202        else
203        {
204                cout << "ray casting initialization failed" << endl;
205                exit(1);
206        }
207
208        //-- build kd tree from scene geometry
209        preprocessor->BuildKdTree();
210        preprocessor->KdTreeStatistics(cout);
211       
212        /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
213        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
214
215        KdTree *kdTree2 = new KdTree;
216
217        cout << "loading kd tree ... ";
218        long startTime = GetTime();
219        kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
220               
221        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
222
223        Exporter *exporter = Exporter::GetExporter("testkd.x3d");
224        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
225
226        if (exporter)
227        {
228                exporter->SetWireframe();
229                exporter->ExportKdTree(*kdTree2, true);
230
231                delete exporter;
232        }
233
234        DEL_PTR(kdTree2);
235*/
236        // parse view cells related options
237        preprocessor->PrepareViewCells();
238
239        if (0)
240        {
241                preprocessor->Export(filename + "-out.x3d", true, false, false);
242                preprocessor->Export(filename + "-kdtree.x3d", false, true, false);     
243        }
244
245        // create a preprocessor thread (note: capsulates calls to boost fuctions!)
246        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
247#if USE_BOOST
248        BoostPreprocessorThread pt(preprocessor);
249#endif
250       
251        bool guiSupported = false;
252        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
253          {
254                cout << "using gl widget" << endl;
255                // create and run the preprocessor application in a parallel thread
256#if USE_BOOST
257                pt.InitThread();
258#endif
259                //pt.RunThread();
260               
261                // display the render widget
262                if (!rendererWidget) {
263
264#if !USE_QT
265                  guiSupported = LoadMyDll();
266#else
267                  rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
268                                                                                                  preprocessor->mViewCellsManager,
269                                                                                                  preprocessor->mKdTree);
270#endif
271                }
272               
273          }
274       
275        if (!guiSupported) {
276          preprocessor->mUseGlRenderer = false;
277          preprocessor->mUseGlDebugger = false;
278        }
279       
280        if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
281          // just call the mail method -> will be executed in the main thread
282#if USE_BOOST
283          pt.Main();
284#endif
285        }
286       
287        Cleanup();
288       
289        return returnCode;
290}
291
Note: See TracBrowser for help on using the repository browser.