1 | #ifdef UNICODE
|
---|
2 | #undef UNICODE
|
---|
3 | #endif
|
---|
4 |
|
---|
5 | #include <windows.h>
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <crtdbg.h>
|
---|
8 |
|
---|
9 | #include "SamplingPreprocessor.h"
|
---|
10 | #include "VssPreprocessor.h"
|
---|
11 | #include "RssPreprocessor.h"
|
---|
12 | #include "ExactPreprocessor.h"
|
---|
13 | #include "Parser.h"
|
---|
14 | #include "UnigraphicsParser.h"
|
---|
15 | #include "X3dParser.h"
|
---|
16 | #include "Environment.h"
|
---|
17 | #include "Camera.h"
|
---|
18 | #include "MeshKdTree.h"
|
---|
19 | #include "Exporter.h"
|
---|
20 | #include "ViewCell.h"
|
---|
21 | #include "SceneGraph.h"
|
---|
22 | #include "BoostPreprocessorThread.h"
|
---|
23 | #include "RenderSampler.h"
|
---|
24 | #include "ResourceManager.h"
|
---|
25 | #include "GlRenderer.h"
|
---|
26 |
|
---|
27 | #define USE_EXE_PATH false
|
---|
28 |
|
---|
29 |
|
---|
30 | using namespace GtpVisibilityPreprocessor;
|
---|
31 |
|
---|
32 | Preprocessor *preprocessor = NULL;
|
---|
33 | GlRendererWidget *rendererWidget = NULL;
|
---|
34 |
|
---|
35 | // DLL function signature
|
---|
36 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
37 |
|
---|
38 | int LoadMyDll()
|
---|
39 | {
|
---|
40 | importFunction LoadRenderWidget;
|
---|
41 |
|
---|
42 | // Load DLL file
|
---|
43 | HINSTANCE hinstLib = LoadLibrary("QtGlRenderer.dll");
|
---|
44 |
|
---|
45 | if (hinstLib == NULL)
|
---|
46 | {
|
---|
47 | cout << "ERROR: unable to load DLL\n";
|
---|
48 | return 1;
|
---|
49 | }
|
---|
50 |
|
---|
51 | // Get function pointer
|
---|
52 | LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget");
|
---|
53 |
|
---|
54 | if (LoadRenderWidget == NULL)
|
---|
55 | {
|
---|
56 | cout << "ERROR: unable to find DLL function\n";
|
---|
57 | return 1;
|
---|
58 | }
|
---|
59 |
|
---|
60 | // load the render window
|
---|
61 | rendererWidget = LoadRenderWidget(preprocessor);
|
---|
62 |
|
---|
63 | // Unload DLL file
|
---|
64 | //FreeLibrary(hinstLib);
|
---|
65 |
|
---|
66 | return 0;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | void Cleanup()
|
---|
72 | {
|
---|
73 | DEL_PTR(rendererWidget);
|
---|
74 | DEL_PTR(preprocessor);
|
---|
75 |
|
---|
76 | Environment::DelSingleton();
|
---|
77 | MeshManager::DelSingleton();
|
---|
78 | MaterialManager::DelSingleton();
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | void DisplayWidget()
|
---|
83 | {
|
---|
84 | if (!rendererWidget)
|
---|
85 | LoadMyDll();
|
---|
86 |
|
---|
87 | //rendererWidget->Show();
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | int
|
---|
92 | main(int argc, char **argv)
|
---|
93 | {
|
---|
94 |
|
---|
95 | //Now just call this function at the start of your program and if you're
|
---|
96 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
97 | //window when the program shuts down. If you're not in debug mode this will
|
---|
98 | //be ignored. Use it as you will!
|
---|
99 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
100 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
101 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
102 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
103 |
|
---|
104 | int returnCode = 0;
|
---|
105 |
|
---|
106 | InitTiming();
|
---|
107 |
|
---|
108 | Debug.open("debug.log");
|
---|
109 |
|
---|
110 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
111 | MeshKdTree::ParseEnvironment();
|
---|
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 | Environment::DelSingleton();
|
---|
147 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
148 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
149 | exit(1);
|
---|
150 | }
|
---|
151 | }
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | //-- load scene
|
---|
158 |
|
---|
159 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
160 | string filename(buff);
|
---|
161 | preprocessor->LoadScene(filename);
|
---|
162 |
|
---|
163 | //-- build kd tree from scene geometry
|
---|
164 | preprocessor->BuildKdTree();
|
---|
165 | preprocessor->KdTreeStatistics(cout);
|
---|
166 | preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
|
---|
167 |
|
---|
168 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
169 |
|
---|
170 | KdTree *kdTree2 = new KdTree;
|
---|
171 |
|
---|
172 | cout << "loading kd tree ... ";
|
---|
173 | long startTime = GetTime();
|
---|
174 | kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
|
---|
175 |
|
---|
176 | cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
177 |
|
---|
178 | Exporter *exporter = Exporter::GetExporter("testkd.x3d");
|
---|
179 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
180 |
|
---|
181 | if (exporter)
|
---|
182 | {
|
---|
183 | exporter->SetWireframe();
|
---|
184 | exporter->ExportKdTree(*kdTree2, true);
|
---|
185 |
|
---|
186 | delete exporter;
|
---|
187 | }
|
---|
188 |
|
---|
189 | DEL_PTR(kdTree2);
|
---|
190 |
|
---|
191 | // parse view cells related options
|
---|
192 | preprocessor->PrepareViewCells();
|
---|
193 |
|
---|
194 | // p->mSceneGraph->Export("soda.x3d");
|
---|
195 | if (0)
|
---|
196 | {
|
---|
197 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
198 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | // create a preprocessor thread (note: capsulte calls to boost fuctions!)
|
---|
203 |
|
---|
204 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
205 | BoostPreprocessorThread pt(preprocessor);
|
---|
206 |
|
---|
207 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
208 | {
|
---|
209 | // create and run the preprocessor application in a parallel thread
|
---|
210 | pt.InitThread();
|
---|
211 | //pt.RunThread();
|
---|
212 |
|
---|
213 | // display the render widget
|
---|
214 | DisplayWidget();
|
---|
215 | }
|
---|
216 | else
|
---|
217 | {
|
---|
218 | // just call the mail method -> will be executed in the main thread
|
---|
219 | pt.Main();
|
---|
220 | }
|
---|
221 |
|
---|
222 | Cleanup();
|
---|
223 |
|
---|
224 | return returnCode;
|
---|
225 | }
|
---|
226 |
|
---|