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