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 |
|
---|
44 | using namespace GtpVisibilityPreprocessor;
|
---|
45 |
|
---|
46 | Preprocessor *preprocessor = NULL;
|
---|
47 | GlRendererWidget *rendererWidget = NULL;
|
---|
48 |
|
---|
49 | // DLL function signature
|
---|
50 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
51 |
|
---|
52 |
|
---|
53 | int 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 |
|
---|
86 | void Cleanup()
|
---|
87 | {
|
---|
88 | DEL_PTR(rendererWidget);
|
---|
89 | DEL_PTR(preprocessor);
|
---|
90 |
|
---|
91 | Environment::DelSingleton();
|
---|
92 | MeshManager::DelSingleton();
|
---|
93 | MaterialManager::DelSingleton();
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | void DisplayWidget()
|
---|
98 | {
|
---|
99 | if (!rendererWidget)
|
---|
100 | {
|
---|
101 | LoadMyDll();
|
---|
102 | }
|
---|
103 |
|
---|
104 | //rendererWidget->Show();
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | string ReplaceSuffix(string filename,
|
---|
109 | string a,
|
---|
110 | string b)
|
---|
111 | {
|
---|
112 | string result = filename;
|
---|
113 |
|
---|
114 | int pos = (int)filename.rfind(a, (int)filename.size() - 1);
|
---|
115 | if (pos == filename.size() - a.size()) {
|
---|
116 | result.replace(pos, a.size(), b);
|
---|
117 | }
|
---|
118 | return result;
|
---|
119 | }
|
---|
120 |
|
---|
121 | int
|
---|
122 | main(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 | {
|
---|
180 | Environment::DelSingleton();
|
---|
181 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
182 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
183 | exit(1);
|
---|
184 | }
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | ////////////////////////////////////////
|
---|
191 | //-- load scene
|
---|
192 |
|
---|
193 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
194 | string filename(buff);
|
---|
195 |
|
---|
196 | if (!preprocessor->LoadScene(filename))
|
---|
197 | {
|
---|
198 | cout << "loading file " << filename << " failed" << endl;
|
---|
199 | Cleanup();
|
---|
200 | exit(1);
|
---|
201 | }
|
---|
202 |
|
---|
203 | string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
204 |
|
---|
205 | //-- initialize external ray casters
|
---|
206 | if (preprocessor->InitRayCast(rayCastFile))
|
---|
207 | {
|
---|
208 | cout << "ray casting initialized!" << endl;
|
---|
209 | }
|
---|
210 | else
|
---|
211 | {
|
---|
212 | cout << "ray casting initialization failed" << endl;
|
---|
213 | Cleanup();
|
---|
214 | exit(1);
|
---|
215 | }
|
---|
216 | cout << "here3.9" << endl;
|
---|
217 | //-- build kd tree from scene geometry
|
---|
218 | preprocessor->BuildKdTree();
|
---|
219 | preprocessor->KdTreeStatistics(cout);
|
---|
220 | cout << "here3" << endl;
|
---|
221 | /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
|
---|
222 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
223 |
|
---|
224 | KdTree *kdTree2 = new KdTree;
|
---|
225 |
|
---|
226 | cout << "loading kd tree ... ";
|
---|
227 | long startTime = GetTime();
|
---|
228 | kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
|
---|
229 |
|
---|
230 | cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
231 |
|
---|
232 | Exporter *exporter = Exporter::GetExporter("testkd.x3d");
|
---|
233 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
234 |
|
---|
235 | if (exporter)
|
---|
236 | {
|
---|
237 | exporter->SetWireframe();
|
---|
238 | exporter->ExportKdTree(*kdTree2, true);
|
---|
239 |
|
---|
240 | delete exporter;
|
---|
241 | }
|
---|
242 |
|
---|
243 | DEL_PTR(kdTree2);
|
---|
244 | */cout << "here4" << endl;
|
---|
245 | // parse view cells related options
|
---|
246 | preprocessor->PrepareViewCells();
|
---|
247 |
|
---|
248 | if (0)
|
---|
249 | {
|
---|
250 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
251 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
252 | }
|
---|
253 | cout << "here5" << endl;
|
---|
254 | // create a preprocessor thread (note: capsulates calls to boost fuctions!)
|
---|
255 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
256 | #if USE_BOOST
|
---|
257 | BoostPreprocessorThread pt(preprocessor);
|
---|
258 | #endif
|
---|
259 |
|
---|
260 | bool guiSupported = false;
|
---|
261 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
262 | {
|
---|
263 | cout << "using gl widget" << endl;
|
---|
264 | // create and run the preprocessor application in a parallel thread
|
---|
265 | #if USE_BOOST
|
---|
266 | pt.InitThread();
|
---|
267 | #endif
|
---|
268 | //pt.RunThread();
|
---|
269 |
|
---|
270 | // display the render widget
|
---|
271 | if (!rendererWidget) {
|
---|
272 |
|
---|
273 | #if !USE_QT
|
---|
274 | guiSupported = LoadMyDll();
|
---|
275 | #else
|
---|
276 | rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
277 | preprocessor->mViewCellsManager,
|
---|
278 | preprocessor->mKdTree);
|
---|
279 | #endif
|
---|
280 | }
|
---|
281 |
|
---|
282 | }
|
---|
283 |
|
---|
284 | if (!guiSupported) {
|
---|
285 | preprocessor->mUseGlRenderer = false;
|
---|
286 | preprocessor->mUseGlDebugger = false;
|
---|
287 | }
|
---|
288 |
|
---|
289 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
|
---|
290 | // just call the mail method -> will be executed in the main thread
|
---|
291 | #if USE_BOOST
|
---|
292 | pt.Main();
|
---|
293 | #endif
|
---|
294 | }
|
---|
295 |
|
---|
296 | Cleanup();
|
---|
297 |
|
---|
298 | return returnCode;
|
---|
299 | }
|
---|
300 |
|
---|