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)(Preprocessor *);
|
---|
33 |
|
---|
34 | int LoadMyDll()
|
---|
35 | {
|
---|
36 | importFunction LoadRenderWidget;
|
---|
37 |
|
---|
38 | // Load DLL file
|
---|
39 | HINSTANCE hinstLib = LoadLibrary("QtGlRenderer.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(preprocessor);
|
---|
58 |
|
---|
59 | // Unload DLL file
|
---|
60 | //FreeLibrary(hinstLib);
|
---|
61 |
|
---|
62 | return 0;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 | void Cleanup()
|
---|
68 | {
|
---|
69 | DEL_PTR(rendererWidget);
|
---|
70 | DEL_PTR(preprocessor);
|
---|
71 |
|
---|
72 | Environment::DelSingleton();
|
---|
73 | MeshManager::DelSingleton();
|
---|
74 | MaterialManager::DelSingleton();
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | void DisplayWidget()
|
---|
79 | {
|
---|
80 | if (!rendererWidget)
|
---|
81 | LoadMyDll();
|
---|
82 |
|
---|
83 | //rendererWidget->Show();
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | int
|
---|
88 | main(int argc, char **argv)
|
---|
89 | {
|
---|
90 |
|
---|
91 | //Now just call this function at the start of your program and if you're
|
---|
92 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
93 | //window when the program shuts down. If you're not in debug mode this will
|
---|
94 | //be ignored. Use it as you will!
|
---|
95 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
96 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
97 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
98 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
99 |
|
---|
100 | int returnCode = 0;
|
---|
101 |
|
---|
102 | InitTiming();
|
---|
103 |
|
---|
104 | Debug.open("debug.log");
|
---|
105 |
|
---|
106 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
107 | MeshKdTree::ParseEnvironment();
|
---|
108 |
|
---|
109 | char buff[128];
|
---|
110 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
111 | string preprocessorType(buff);
|
---|
112 |
|
---|
113 | if (preprocessorType == "vss")
|
---|
114 | {
|
---|
115 | preprocessor = new VssPreprocessor();
|
---|
116 | }
|
---|
117 | else
|
---|
118 | {
|
---|
119 | if (preprocessorType == "rss")
|
---|
120 | {
|
---|
121 | preprocessor = new RssPreprocessor();
|
---|
122 | }
|
---|
123 | else
|
---|
124 | {
|
---|
125 | if (preprocessorType == "exact")
|
---|
126 | {
|
---|
127 | preprocessor = new ExactPreprocessor();
|
---|
128 | }
|
---|
129 | else
|
---|
130 | {
|
---|
131 | if (preprocessorType == "sampling")
|
---|
132 | {
|
---|
133 | preprocessor = new SamplingPreprocessor();
|
---|
134 | }
|
---|
135 | else
|
---|
136 | {
|
---|
137 | if (preprocessorType == "render")
|
---|
138 | {
|
---|
139 | preprocessor = new RenderSampler();
|
---|
140 | }
|
---|
141 | else {
|
---|
142 | Environment::DelSingleton();
|
---|
143 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
144 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
145 | exit(1);
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | //-- load scene
|
---|
154 |
|
---|
155 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
156 | string filename(buff);
|
---|
157 | preprocessor->LoadScene(filename);
|
---|
158 |
|
---|
159 | //-- build kd tree from scene geometry
|
---|
160 |
|
---|
161 | preprocessor->BuildKdTree();
|
---|
162 | preprocessor->KdTreeStatistics(cout);
|
---|
163 |
|
---|
164 | // parse view cells related options
|
---|
165 | preprocessor->PrepareViewCells();
|
---|
166 |
|
---|
167 | // p->mSceneGraph->Export("soda.x3d");
|
---|
168 | if (0) {
|
---|
169 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
170 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | // create a preprocessor thread (note: capsulte calls to boost fuctions!)
|
---|
175 |
|
---|
176 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
177 | BoostPreprocessorThread pt(preprocessor);
|
---|
178 |
|
---|
179 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
180 | {
|
---|
181 | cout << "here99" << endl;
|
---|
182 | // create and run the preprocessor application in a parallel thread
|
---|
183 | pt.InitThread(); cout << "here77" << endl;
|
---|
184 | //pt.RunThread();
|
---|
185 |
|
---|
186 | cout << "here51" << endl;
|
---|
187 | // display the render widget
|
---|
188 | DisplayWidget();
|
---|
189 | }
|
---|
190 | else
|
---|
191 | {
|
---|
192 | // just call the mail method -> will be executed in the main thread
|
---|
193 | pt.Main();
|
---|
194 | }
|
---|
195 | cout << "here39" << endl;
|
---|
196 | Cleanup();
|
---|
197 |
|
---|
198 | return returnCode;
|
---|
199 | }
|
---|
200 |
|
---|