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