1 | #ifdef GTP_INTERNAL
|
---|
2 | //#define USE_QT 0
|
---|
3 | #endif
|
---|
4 |
|
---|
5 | #define USE_QT 0
|
---|
6 | #if USE_QT
|
---|
7 | #define USE_BOOST 0
|
---|
8 | #else
|
---|
9 | #define USE_BOOST 0
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | #ifdef UNICODE
|
---|
13 | #undef UNICODE
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <windows.h>
|
---|
17 | #include <stdio.h>
|
---|
18 | #include <crtdbg.h>
|
---|
19 |
|
---|
20 | #include "SamplingPreprocessor.h"
|
---|
21 | #include "VssPreprocessor.h"
|
---|
22 | #include "RssPreprocessor.h"
|
---|
23 | #include "ExactPreprocessor.h"
|
---|
24 | #include "Parser.h"
|
---|
25 | #include "UnigraphicsParser.h"
|
---|
26 | #include "X3dParser.h"
|
---|
27 | #include "Environment.h"
|
---|
28 | #include "Camera.h"
|
---|
29 | #include "MeshKdTree.h"
|
---|
30 | #include "Exporter.h"
|
---|
31 | #include "ViewCell.h"
|
---|
32 | #include "SceneGraph.h"
|
---|
33 |
|
---|
34 | #include "PreprocessorThread.h"
|
---|
35 | #if USE_BOOST
|
---|
36 | #include "BoostPreprocessorThread.h"
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #include "RenderSampler.h"
|
---|
40 | #include "ResourceManager.h"
|
---|
41 | #include "GlRenderer.h"
|
---|
42 |
|
---|
43 | #if USE_QT
|
---|
44 | #include "QtPreprocessorThread.h"
|
---|
45 | #include "QtGlRenderer.h"
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #define USE_EXE_PATH false
|
---|
49 |
|
---|
50 |
|
---|
51 | using namespace GtpVisibilityPreprocessor;
|
---|
52 |
|
---|
53 | Preprocessor *preprocessor = NULL;
|
---|
54 | GlRendererWidget *rendererWidget = NULL;
|
---|
55 |
|
---|
56 | // DLL function signature
|
---|
57 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | void Cleanup()
|
---|
63 | {
|
---|
64 | DEL_PTR(rendererWidget);
|
---|
65 | DEL_PTR(preprocessor);
|
---|
66 |
|
---|
67 | Environment::DelSingleton();
|
---|
68 | MeshManager::DelSingleton();
|
---|
69 | MaterialManager::DelSingleton();
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | string ReplaceSuffix(string filename,
|
---|
76 | string a,
|
---|
77 | string b)
|
---|
78 | {
|
---|
79 | string result = filename;
|
---|
80 |
|
---|
81 | int pos = (int)filename.rfind(a, (int)filename.size() - 1);
|
---|
82 | if (pos == filename.size() - a.size()) {
|
---|
83 | result.replace(pos, a.size(), b);
|
---|
84 | }
|
---|
85 | return result;
|
---|
86 | }
|
---|
87 |
|
---|
88 | int
|
---|
89 | main(int argc, char **argv)
|
---|
90 | {
|
---|
91 |
|
---|
92 | //Now just call this function at the start of your program and if you're
|
---|
93 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
94 | //window when the program shuts down. If you're not in debug mode this will
|
---|
95 | //be ignored. Use it as you will!
|
---|
96 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
97 | #if 0
|
---|
98 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
99 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
100 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | int returnCode = 0;
|
---|
104 |
|
---|
105 | InitTiming();
|
---|
106 |
|
---|
107 | Debug.open("debug.log");
|
---|
108 |
|
---|
109 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
110 | MeshKdTree::ParseEnvironment();
|
---|
111 |
|
---|
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 | {
|
---|
147 | Environment::DelSingleton();
|
---|
148 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
149 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
150 | exit(1);
|
---|
151 | }
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | /////////////
|
---|
159 | //-- load scene
|
---|
160 |
|
---|
161 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
162 | string filename(buff);
|
---|
163 |
|
---|
164 | if (!preprocessor->LoadScene(filename))
|
---|
165 | {
|
---|
166 | cout << "loading file " << filename << " failed" << endl;
|
---|
167 | Cleanup();
|
---|
168 | exit(1);
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
|
---|
173 | char internKdTree[100];
|
---|
174 | Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree);
|
---|
175 |
|
---|
176 | //-- initialize external ray casters
|
---|
177 | if (preprocessor->InitRayCast(externKdTree, internKdTree))
|
---|
178 | {
|
---|
179 | cout << "ray casting initialized!" << endl;
|
---|
180 | }
|
---|
181 | else
|
---|
182 | {
|
---|
183 | cout << "ray casting initialization failed" << endl;
|
---|
184 | Cleanup();
|
---|
185 | exit(1);
|
---|
186 | }
|
---|
187 |
|
---|
188 | // export kd tree?
|
---|
189 | bool exportKdTree;
|
---|
190 | Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree);
|
---|
191 | if (exportKdTree)
|
---|
192 | {
|
---|
193 | const long startTime = GetTime();
|
---|
194 | cout << "exporting kd tree ... ";
|
---|
195 |
|
---|
196 | if (!preprocessor->ExportKdTree(internKdTree))
|
---|
197 | {
|
---|
198 | cout << " error exporting kd tree with filename " << internKdTree << endl;
|
---|
199 | }
|
---|
200 | else
|
---|
201 | {
|
---|
202 | cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | // parse view cells related options
|
---|
207 | preprocessor->PrepareViewCells();
|
---|
208 |
|
---|
209 | if (0)
|
---|
210 | {
|
---|
211 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
212 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
213 | }
|
---|
214 |
|
---|
215 | // create a preprocessor thread (note: capsulates calls to boost fuctions!)
|
---|
216 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
217 | PreprocessorThread *pt;
|
---|
218 |
|
---|
219 | #if USE_QT
|
---|
220 | pt = new QtPreprocessorThread(preprocessor);
|
---|
221 | #else
|
---|
222 | #if USE_BOOST
|
---|
223 | pt = new BoostPreprocessorThread(preprocessor);
|
---|
224 | #else
|
---|
225 | pt = new PreprocessorThread(preprocessor);
|
---|
226 | #endif
|
---|
227 | #endif
|
---|
228 |
|
---|
229 | bool guiSupported = false;
|
---|
230 |
|
---|
231 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
232 | {
|
---|
233 | cout << "using gl widget" << endl;
|
---|
234 | // create and run the preprocessor application in a parallel thread
|
---|
235 | #if USE_QT
|
---|
236 | #if USE_THREADS
|
---|
237 | pt->InitThread();
|
---|
238 | pt->RunThread();
|
---|
239 | #endif
|
---|
240 |
|
---|
241 | // display the render widget
|
---|
242 | if (!rendererWidget)
|
---|
243 | {
|
---|
244 | // create a qt application first (must be created before any opengl widget ...)
|
---|
245 | QApplication *app = new QApplication(argc, NULL);
|
---|
246 |
|
---|
247 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
248 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
249 | "This system does not support OpenGL/pbuffers.",
|
---|
250 | QMessageBox::Ok);
|
---|
251 | return NULL;
|
---|
252 | }
|
---|
253 |
|
---|
254 |
|
---|
255 | rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
|
---|
256 | preprocessor->mViewCellsManager,
|
---|
257 | preprocessor->mKdTree);
|
---|
258 |
|
---|
259 | rendererWidget->Show();
|
---|
260 | guiSupported = true;
|
---|
261 | }
|
---|
262 |
|
---|
263 | qApp->exec();
|
---|
264 | #endif
|
---|
265 | }
|
---|
266 |
|
---|
267 | if (!guiSupported) {
|
---|
268 | preprocessor->mUseGlRenderer = false;
|
---|
269 | preprocessor->mUseGlDebugger = false;
|
---|
270 | }
|
---|
271 |
|
---|
272 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
|
---|
273 | // just call the mail method -> will be executed in the main thread
|
---|
274 | pt->Main();
|
---|
275 | }
|
---|
276 |
|
---|
277 | // release memory
|
---|
278 | Cleanup();
|
---|
279 |
|
---|
280 | return returnCode;
|
---|
281 | }
|
---|
282 |
|
---|