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

Revision 1221, 5.2 KB checked in by mattausch, 18 years ago (diff)

added intel ray tracing

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