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

Revision 1292, 6.3 KB checked in by bittner, 18 years ago (diff)

intel ray caster updates

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       
146        char buff[128];
147        Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
148        string preprocessorType(buff);
149
150        if (preprocessorType == "vss")
151          {
152                preprocessor = new VssPreprocessor();
153          }
154        else
155        {
156                if (preprocessorType == "rss")
157                {
158                        preprocessor = new RssPreprocessor();
159                }
160                else
161                {
162                        if (preprocessorType == "exact")
163                        {
164                                preprocessor = new ExactPreprocessor();
165                        }
166                        else
167                        {
168                                if (preprocessorType == "sampling")
169                                {
170                                        preprocessor = new SamplingPreprocessor();
171                                }
172                                else
173                                {       
174                                        if (preprocessorType == "render")
175                                        {
176                                                preprocessor = new RenderSampler();
177                                        }
178                                        else {
179                                                Environment::DelSingleton();
180                                                cerr<<"Unknown preprocessor type"<<endl;
181                                                Debug<<"Unknown preprocessor type"<<endl;
182                                                exit(1);
183                                        }
184                                }
185                        }
186                }
187        }
188       
189
190        //-- load scene
191
192        Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
193        string filename(buff);
194        preprocessor->LoadScene(filename);
195       
196        string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf");
197       
198        //-- initialize external ray casters
199        if (preprocessor->InitRayCast(rayCastFile))
200          {
201                cout << "ray casting initialized!" << endl;
202          }
203        else
204        {
205                cout << "ray casting initialization failed" << endl;
206                exit(1);
207        }
208
209        //-- build kd tree from scene geometry
210        preprocessor->BuildKdTree();
211        preprocessor->KdTreeStatistics(cout);
212       
213        /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
214        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
215
216        KdTree *kdTree2 = new KdTree;
217
218        cout << "loading kd tree ... ";
219        long startTime = GetTime();
220        kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
221               
222        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
223
224        Exporter *exporter = Exporter::GetExporter("testkd.x3d");
225        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
226
227        if (exporter)
228        {
229                exporter->SetWireframe();
230                exporter->ExportKdTree(*kdTree2, true);
231
232                delete exporter;
233        }
234
235        DEL_PTR(kdTree2);
236*/
237        // parse view cells related options
238        preprocessor->PrepareViewCells();
239
240        if (0)
241        {
242                preprocessor->Export(filename + "-out.x3d", true, false, false);
243                preprocessor->Export(filename + "-kdtree.x3d", false, true, false);     
244        }
245
246        // create a preprocessor thread (note: capsulates calls to boost fuctions!)
247        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
248#if USE_BOOST
249        BoostPreprocessorThread pt(preprocessor);
250#endif
251       
252        bool guiSupported = false;
253        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
254          {
255                cout << "using gl widget" << endl;
256                // create and run the preprocessor application in a parallel thread
257#if USE_BOOST
258                pt.InitThread();
259#endif
260                //pt.RunThread();
261               
262                // display the render widget
263                if (!rendererWidget) {
264
265#if !USE_QT
266                  guiSupported = LoadMyDll();
267#else
268                  rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
269                                                                                                  preprocessor->mViewCellsManager,
270                                                                                                  preprocessor->mKdTree);
271#endif
272                }
273               
274          }
275       
276        if (!guiSupported) {
277          preprocessor->mUseGlRenderer = false;
278          preprocessor->mUseGlDebugger = false;
279        }
280       
281        if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
282          // just call the mail method -> will be executed in the main thread
283#if USE_BOOST
284          pt.Main();
285#endif
286        }
287       
288        Cleanup();
289       
290        return returnCode;
291}
292
Note: See TracBrowser for help on using the repository browser.