1 | #include <windows.h>
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <crtdbg.h>
|
---|
4 |
|
---|
5 | #include "SamplingPreprocessor.h"
|
---|
6 | #include "VssPreprocessor.h"
|
---|
7 | #include "RssPreprocessor.h"
|
---|
8 | #include "ExactPreprocessor.h"
|
---|
9 | #include "Parser.h"
|
---|
10 | #include "UnigraphicsParser.h"
|
---|
11 | #include "X3dParser.h"
|
---|
12 | #include "Environment.h"
|
---|
13 | #include "Camera.h"
|
---|
14 | #include "MeshKdTree.h"
|
---|
15 | #include "Exporter.h"
|
---|
16 | #include "ViewCell.h"
|
---|
17 | #include "SceneGraph.h"
|
---|
18 | #include "BoostPreprocessorThread.h"
|
---|
19 | #include "RenderSampler.h"
|
---|
20 | #include "ResourceManager.h"
|
---|
21 | #include "GlRenderer.h"
|
---|
22 |
|
---|
23 | #define USE_EXE_PATH false
|
---|
24 |
|
---|
25 |
|
---|
26 | using namespace GtpVisibilityPreprocessor;
|
---|
27 |
|
---|
28 | Preprocessor *preprocessor = NULL;
|
---|
29 | GlRendererWidget *rendererWidget = NULL;
|
---|
30 |
|
---|
31 | // DLL function signature
|
---|
32 | typedef GlRendererWidget *(*importFunction)();
|
---|
33 |
|
---|
34 | int LoadMyDll()
|
---|
35 | {
|
---|
36 | importFunction LoadRenderWidget;
|
---|
37 |
|
---|
38 | // Load DLL file
|
---|
39 | HINSTANCE hinstLib = LoadLibrary("QtRenderer.dll");
|
---|
40 |
|
---|
41 | if (hinstLib == NULL)
|
---|
42 | {
|
---|
43 | cout << "ERROR: unable to load DLL\n";
|
---|
44 | return 1;
|
---|
45 | }
|
---|
46 |
|
---|
47 | // Get function pointer
|
---|
48 | LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget");
|
---|
49 |
|
---|
50 | if (LoadRenderWidget == NULL)
|
---|
51 | {
|
---|
52 | cout << "ERROR: unable to find DLL function\n";
|
---|
53 | return 1;
|
---|
54 | }
|
---|
55 |
|
---|
56 | // load the render window
|
---|
57 | rendererWidget = LoadRenderWidget();
|
---|
58 |
|
---|
59 | return 0;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 | void Cleanup()
|
---|
65 | {
|
---|
66 | DEL_PTR(rendererWidget);
|
---|
67 | DEL_PTR(preprocessor);
|
---|
68 |
|
---|
69 | Environment::DelSingleton();
|
---|
70 | MeshManager::DelSingleton();
|
---|
71 | MaterialManager::DelSingleton();
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | void DisplayWidget()
|
---|
76 | {
|
---|
77 | if (!rendererWidget)
|
---|
78 | LoadMyDll();
|
---|
79 |
|
---|
80 | // note matt: capsulate qt dependent code as good as possible
|
---|
81 | /*new GlRendererWidget(preprocessor->mSceneGraph,
|
---|
82 | preprocessor->mViewCellsManager,
|
---|
83 | preprocessor->mKdTree);
|
---|
84 | */
|
---|
85 | rendererWidget->Show();
|
---|
86 |
|
---|
87 | #if QT_ENABLED
|
---|
88 |
|
---|
89 | // create a qt application first (must be created before any opengl widget ...)
|
---|
90 | app = new QApplication(argc, argv);
|
---|
91 |
|
---|
92 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
93 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
94 | "This system does not support OpenGL/pbuffers.",
|
---|
95 | QMessageBox::Ok);
|
---|
96 | return -1;
|
---|
97 | }
|
---|
98 |
|
---|
99 | // note matt: capsulate qt dependent code as good as possible
|
---|
100 | rendererWidget =
|
---|
101 | new GlRendererWidget(p->mSceneGraph, p->mViewCellsManager, p->mKdTree);
|
---|
102 |
|
---|
103 | rendererWidget->resize(640, 480);
|
---|
104 | rendererWidget->show();
|
---|
105 |
|
---|
106 | if (0 && p->GetRenderer())
|
---|
107 | {
|
---|
108 | cout<<"CONNECTING"<<endl;
|
---|
109 | QObject::connect(p->GetRenderer(),
|
---|
110 | SIGNAL(UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &)),
|
---|
111 | rendererWidget->mControlWidget,
|
---|
112 | SLOT(UpdatePvsErrorItem(int i,
|
---|
113 | GlRendererBuffer::PvsErrorEntry &)));
|
---|
114 |
|
---|
115 | cout<<"CONNECTED"<<endl;
|
---|
116 | }
|
---|
117 | #endif
|
---|
118 | }
|
---|
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 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
131 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
132 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
133 |
|
---|
134 | int returnCode = 0;
|
---|
135 |
|
---|
136 | InitTiming();
|
---|
137 |
|
---|
138 | Debug.open("debug.log");
|
---|
139 |
|
---|
140 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
141 | MeshKdTree::ParseEnvironment();
|
---|
142 |
|
---|
143 | char buff[128];
|
---|
144 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
145 | string preprocessorType(buff);
|
---|
146 |
|
---|
147 | if (preprocessorType == "vss")
|
---|
148 | {
|
---|
149 | preprocessor = new VssPreprocessor();
|
---|
150 | }
|
---|
151 | else
|
---|
152 | {
|
---|
153 | if (preprocessorType == "rss")
|
---|
154 | {
|
---|
155 | preprocessor = new RssPreprocessor();
|
---|
156 | }
|
---|
157 | else
|
---|
158 | {
|
---|
159 | if (preprocessorType == "exact")
|
---|
160 | {
|
---|
161 | preprocessor = new ExactPreprocessor();
|
---|
162 | }
|
---|
163 | else
|
---|
164 | {
|
---|
165 | if (preprocessorType == "sampling")
|
---|
166 | {
|
---|
167 | preprocessor = new SamplingPreprocessor();
|
---|
168 | }
|
---|
169 | else
|
---|
170 | {
|
---|
171 | if (preprocessorType == "render")
|
---|
172 | {
|
---|
173 | preprocessor = new RenderSampler();
|
---|
174 | }
|
---|
175 | else {
|
---|
176 | Environment::DelSingleton();
|
---|
177 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
178 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
179 | exit(1);
|
---|
180 | }
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 |
|
---|
187 | //-- load scene
|
---|
188 |
|
---|
189 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
190 | string filename(buff);
|
---|
191 | preprocessor->LoadScene(filename);
|
---|
192 |
|
---|
193 | //-- build kd tree from scene geometry
|
---|
194 |
|
---|
195 | preprocessor->BuildKdTree();
|
---|
196 | preprocessor->KdTreeStatistics(cout);
|
---|
197 |
|
---|
198 | // parse view cells related options
|
---|
199 | preprocessor->PrepareViewCells();
|
---|
200 |
|
---|
201 | // p->mSceneGraph->Export("soda.x3d");
|
---|
202 | if (0) {
|
---|
203 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
204 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | // create a preprocessor thread
|
---|
209 | //PreprocessorThread *pt = new PreprocessorThread(p, app);
|
---|
210 | BoostPreprocessorThread pt(preprocessor);
|
---|
211 |
|
---|
212 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
213 | {
|
---|
214 | // display the render widget
|
---|
215 | DisplayWidget();
|
---|
216 |
|
---|
217 | // create and run the preprocessor application in a parallel thread
|
---|
218 | pt.InitThread();
|
---|
219 | pt.RunThread();
|
---|
220 | }
|
---|
221 | else
|
---|
222 | {
|
---|
223 | // just call the mail method -> will be executed in the main thread
|
---|
224 | pt.Main();
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 | Cleanup();
|
---|
229 |
|
---|
230 | return returnCode;
|
---|
231 | }
|
---|
232 |
|
---|