[1199] | 1 | #ifdef UNICODE
|
---|
| 2 | #undef UNICODE
|
---|
| 3 | #endif
|
---|
| 4 |
|
---|
[1151] | 5 | #include <windows.h>
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include <crtdbg.h>
|
---|
| 8 |
|
---|
[162] | 9 | #include "SamplingPreprocessor.h"
|
---|
[374] | 10 | #include "VssPreprocessor.h"
|
---|
[446] | 11 | #include "RssPreprocessor.h"
|
---|
[162] | 12 | #include "ExactPreprocessor.h"
|
---|
| 13 | #include "Parser.h"
|
---|
| 14 | #include "UnigraphicsParser.h"
|
---|
[170] | 15 | #include "X3dParser.h"
|
---|
[162] | 16 | #include "Environment.h"
|
---|
| 17 | #include "Camera.h"
|
---|
[170] | 18 | #include "MeshKdTree.h"
|
---|
[264] | 19 | #include "Exporter.h"
|
---|
[310] | 20 | #include "ViewCell.h"
|
---|
[321] | 21 | #include "SceneGraph.h"
|
---|
[1146] | 22 | #include "BoostPreprocessorThread.h"
|
---|
[878] | 23 | #include "RenderSampler.h"
|
---|
[1001] | 24 | #include "ResourceManager.h"
|
---|
[492] | 25 | #include "GlRenderer.h"
|
---|
| 26 |
|
---|
[162] | 27 | #define USE_EXE_PATH false
|
---|
| 28 |
|
---|
[372] | 29 |
|
---|
[863] | 30 | using namespace GtpVisibilityPreprocessor;
|
---|
[492] | 31 |
|
---|
[1145] | 32 | Preprocessor *preprocessor = NULL;
|
---|
[1151] | 33 | GlRendererWidget *rendererWidget = NULL;
|
---|
[1145] | 34 |
|
---|
[1151] | 35 | // DLL function signature
|
---|
[1153] | 36 | typedef GlRendererWidget *(*importFunction)(Preprocessor *);
|
---|
[1145] | 37 |
|
---|
[1241] | 38 |
|
---|
[1151] | 39 | int LoadMyDll()
|
---|
| 40 | {
|
---|
[1241] | 41 | importFunction LoadRenderWidget;
|
---|
[1199] | 42 |
|
---|
[1241] | 43 | // Load DLL file
|
---|
| 44 | HINSTANCE hinstLib = LoadLibrary("../QtGlRenderer/Release/QtGlRenderer.dll");
|
---|
| 45 |
|
---|
| 46 | if (hinstLib == NULL)
|
---|
[1151] | 47 | {
|
---|
[1241] | 48 | cout << "ERROR: unable to load DLL\n";
|
---|
| 49 | return 1;
|
---|
[1151] | 50 | }
|
---|
[1199] | 51 |
|
---|
[1241] | 52 | // Get function pointer
|
---|
| 53 | LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget");
|
---|
[1199] | 54 |
|
---|
[1241] | 55 | if (LoadRenderWidget == NULL)
|
---|
[1151] | 56 | {
|
---|
[1241] | 57 | cout << "ERROR: unable to find DLL function\n";
|
---|
| 58 | return 1;
|
---|
[1151] | 59 | }
|
---|
[1241] | 60 |
|
---|
| 61 | cout << "loading widget ... ";
|
---|
| 62 | // load the render window
|
---|
| 63 | rendererWidget = LoadRenderWidget(preprocessor);
|
---|
| 64 | cout << "finished" << endl;
|
---|
| 65 | // Unload DLL file
|
---|
| 66 | //FreeLibrary(hinstLib);
|
---|
[1199] | 67 |
|
---|
[1241] | 68 | return 0;
|
---|
[1151] | 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
[1145] | 72 | void Cleanup()
|
---|
| 73 | {
|
---|
[1151] | 74 | DEL_PTR(rendererWidget);
|
---|
[1145] | 75 | DEL_PTR(preprocessor);
|
---|
| 76 |
|
---|
| 77 | Environment::DelSingleton();
|
---|
| 78 | MeshManager::DelSingleton();
|
---|
| 79 | MaterialManager::DelSingleton();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | void DisplayWidget()
|
---|
| 84 | {
|
---|
[1151] | 85 | if (!rendererWidget)
|
---|
[1241] | 86 | {
|
---|
[1151] | 87 | LoadMyDll();
|
---|
[1241] | 88 | }
|
---|
| 89 |
|
---|
[1248] | 90 | //rendererWidget->Show();
|
---|
[1145] | 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
[162] | 94 | int
|
---|
[492] | 95 | main(int argc, char **argv)
|
---|
[997] | 96 | {
|
---|
[991] | 97 |
|
---|
[1145] | 98 | //Now just call this function at the start of your program and if you're
|
---|
| 99 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
| 100 | //window when the program shuts down. If you're not in debug mode this will
|
---|
| 101 | //be ignored. Use it as you will!
|
---|
| 102 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
| 103 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
| 104 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
| 105 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
[997] | 106 |
|
---|
[1145] | 107 | int returnCode = 0;
|
---|
[1153] | 108 |
|
---|
[1145] | 109 | InitTiming();
|
---|
[997] | 110 |
|
---|
[1145] | 111 | Debug.open("debug.log");
|
---|
[1199] | 112 |
|
---|
[1145] | 113 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 114 | MeshKdTree::ParseEnvironment();
|
---|
[1002] | 115 |
|
---|
[1145] | 116 | char buff[128];
|
---|
| 117 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 118 | string preprocessorType(buff);
|
---|
| 119 |
|
---|
| 120 | if (preprocessorType == "vss")
|
---|
[1199] | 121 | {
|
---|
[1145] | 122 | preprocessor = new VssPreprocessor();
|
---|
[1199] | 123 | }
|
---|
[374] | 124 | else
|
---|
[1002] | 125 | {
|
---|
[1145] | 126 | if (preprocessorType == "rss")
|
---|
[1002] | 127 | {
|
---|
[1145] | 128 | preprocessor = new RssPreprocessor();
|
---|
[1002] | 129 | }
|
---|
[811] | 130 | else
|
---|
[1145] | 131 | {
|
---|
| 132 | if (preprocessorType == "exact")
|
---|
| 133 | {
|
---|
| 134 | preprocessor = new ExactPreprocessor();
|
---|
| 135 | }
|
---|
| 136 | else
|
---|
| 137 | {
|
---|
| 138 | if (preprocessorType == "sampling")
|
---|
| 139 | {
|
---|
| 140 | preprocessor = new SamplingPreprocessor();
|
---|
| 141 | }
|
---|
| 142 | else
|
---|
| 143 | {
|
---|
| 144 | if (preprocessorType == "render")
|
---|
| 145 | {
|
---|
| 146 | preprocessor = new RenderSampler();
|
---|
| 147 | }
|
---|
| 148 | else {
|
---|
| 149 | Environment::DelSingleton();
|
---|
| 150 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
| 151 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
| 152 | exit(1);
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
[1002] | 156 | }
|
---|
| 157 | }
|
---|
[997] | 158 |
|
---|
| 159 |
|
---|
[1145] | 160 | //-- load scene
|
---|
[492] | 161 |
|
---|
[1145] | 162 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 163 | string filename(buff);
|
---|
| 164 | preprocessor->LoadScene(filename);
|
---|
[997] | 165 |
|
---|
[1221] | 166 | //-- initialize external ray casters
|
---|
| 167 | if (preprocessor->InitRayCast("../data/grandcanyon1_RotXmin90.kdf"))
|
---|
| 168 | {
|
---|
| 169 | cout << "ray casting initialized!" << endl;
|
---|
| 170 | }
|
---|
| 171 | else
|
---|
| 172 | {
|
---|
| 173 | cout << "ray casting initialization failed" << endl;
|
---|
| 174 | exit(1);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[1145] | 177 | //-- build kd tree from scene geometry
|
---|
| 178 | preprocessor->BuildKdTree();
|
---|
| 179 | preprocessor->KdTreeStatistics(cout);
|
---|
[1196] | 180 |
|
---|
[1221] | 181 | /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
|
---|
[1197] | 182 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
| 183 |
|
---|
[1196] | 184 | KdTree *kdTree2 = new KdTree;
|
---|
[1201] | 185 |
|
---|
| 186 | cout << "loading kd tree ... ";
|
---|
| 187 | long startTime = GetTime();
|
---|
| 188 | kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
|
---|
| 189 |
|
---|
| 190 | cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
| 191 |
|
---|
| 192 | Exporter *exporter = Exporter::GetExporter("testkd.x3d");
|
---|
[1197] | 193 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
| 194 |
|
---|
[1196] | 195 | if (exporter)
|
---|
| 196 | {
|
---|
| 197 | exporter->SetWireframe();
|
---|
[1197] | 198 | exporter->ExportKdTree(*kdTree2, true);
|
---|
[1196] | 199 |
|
---|
| 200 | delete exporter;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | DEL_PTR(kdTree2);
|
---|
[1221] | 204 | */
|
---|
[1145] | 205 | // parse view cells related options
|
---|
| 206 | preprocessor->PrepareViewCells();
|
---|
| 207 |
|
---|
[1196] | 208 | if (0)
|
---|
| 209 | {
|
---|
[1145] | 210 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
| 211 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
[746] | 212 | }
|
---|
[878] | 213 |
|
---|
[1001] | 214 |
|
---|
[1239] | 215 | // create a preprocessor thread (note: capsulates calls to boost fuctions!)
|
---|
[1154] | 216 |
|
---|
| 217 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
[1146] | 218 | BoostPreprocessorThread pt(preprocessor);
|
---|
[1145] | 219 |
|
---|
[1248] | 220 | bool guiSupported = false;
|
---|
[1145] | 221 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
[1248] | 222 | {
|
---|
[1241] | 223 | cout << "using gl widget" << endl;
|
---|
[1153] | 224 | // create and run the preprocessor application in a parallel thread
|
---|
[1181] | 225 | pt.InitThread();
|
---|
[1248] | 226 | //pt.RunThread();
|
---|
| 227 |
|
---|
| 228 | // display the render widget
|
---|
| 229 | if (!rendererWidget)
|
---|
| 230 | guiSupported = LoadMyDll();
|
---|
| 231 | }
|
---|
[1221] | 232 |
|
---|
[1248] | 233 | if (!guiSupported) {
|
---|
| 234 | preprocessor->mUseGlRenderer = false;
|
---|
| 235 | preprocessor->mUseGlDebugger = false;
|
---|
[1005] | 236 | }
|
---|
[1181] | 237 |
|
---|
[1248] | 238 | if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
|
---|
| 239 | // just call the mail method -> will be executed in the main thread
|
---|
| 240 | pt.Main();
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[1145] | 243 | Cleanup();
|
---|
[1248] | 244 |
|
---|
[1145] | 245 | return returnCode;
|
---|
[162] | 246 | }
|
---|
| 247 |
|
---|