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