[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 |
|
---|
[1151] | 38 | int LoadMyDll()
|
---|
| 39 | {
|
---|
[1199] | 40 | importFunction LoadRenderWidget;
|
---|
| 41 |
|
---|
| 42 | // Load DLL file
|
---|
| 43 | HINSTANCE hinstLib = LoadLibrary("QtGlRenderer.dll");
|
---|
| 44 |
|
---|
| 45 | if (hinstLib == NULL)
|
---|
[1151] | 46 | {
|
---|
[1199] | 47 | cout << "ERROR: unable to load DLL\n";
|
---|
| 48 | return 1;
|
---|
[1151] | 49 | }
|
---|
[1199] | 50 |
|
---|
| 51 | // Get function pointer
|
---|
| 52 | LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget");
|
---|
| 53 |
|
---|
| 54 | if (LoadRenderWidget == NULL)
|
---|
[1151] | 55 | {
|
---|
[1199] | 56 | cout << "ERROR: unable to find DLL function\n";
|
---|
| 57 | return 1;
|
---|
[1151] | 58 | }
|
---|
[1199] | 59 |
|
---|
| 60 | // load the render window
|
---|
| 61 | rendererWidget = LoadRenderWidget(preprocessor);
|
---|
| 62 |
|
---|
| 63 | // Unload DLL file
|
---|
| 64 | //FreeLibrary(hinstLib);
|
---|
| 65 |
|
---|
| 66 | return 0;
|
---|
[1151] | 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
[1145] | 71 | void Cleanup()
|
---|
| 72 | {
|
---|
[1151] | 73 | DEL_PTR(rendererWidget);
|
---|
[1145] | 74 | DEL_PTR(preprocessor);
|
---|
| 75 |
|
---|
| 76 | Environment::DelSingleton();
|
---|
| 77 | MeshManager::DelSingleton();
|
---|
| 78 | MaterialManager::DelSingleton();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | void DisplayWidget()
|
---|
| 83 | {
|
---|
[1151] | 84 | if (!rendererWidget)
|
---|
| 85 | LoadMyDll();
|
---|
| 86 |
|
---|
[1153] | 87 | //rendererWidget->Show();
|
---|
[1145] | 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
[162] | 91 | int
|
---|
[492] | 92 | main(int argc, char **argv)
|
---|
[997] | 93 | {
|
---|
[991] | 94 |
|
---|
[1145] | 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);
|
---|
[997] | 103 |
|
---|
[1145] | 104 | int returnCode = 0;
|
---|
[1153] | 105 |
|
---|
[1145] | 106 | InitTiming();
|
---|
[997] | 107 |
|
---|
[1145] | 108 | Debug.open("debug.log");
|
---|
[1199] | 109 |
|
---|
[1145] | 110 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
| 111 | MeshKdTree::ParseEnvironment();
|
---|
[1002] | 112 |
|
---|
[1145] | 113 | char buff[128];
|
---|
| 114 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
| 115 | string preprocessorType(buff);
|
---|
| 116 |
|
---|
| 117 | if (preprocessorType == "vss")
|
---|
[1199] | 118 | {
|
---|
[1145] | 119 | preprocessor = new VssPreprocessor();
|
---|
[1199] | 120 | }
|
---|
[374] | 121 | else
|
---|
[1002] | 122 | {
|
---|
[1145] | 123 | if (preprocessorType == "rss")
|
---|
[1002] | 124 | {
|
---|
[1145] | 125 | preprocessor = new RssPreprocessor();
|
---|
[1002] | 126 | }
|
---|
[811] | 127 | else
|
---|
[1145] | 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 | }
|
---|
[1002] | 153 | }
|
---|
| 154 | }
|
---|
[997] | 155 |
|
---|
| 156 |
|
---|
[1145] | 157 | //-- load scene
|
---|
[492] | 158 |
|
---|
[1145] | 159 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 160 | string filename(buff);
|
---|
| 161 | preprocessor->LoadScene(filename);
|
---|
[997] | 162 |
|
---|
[1145] | 163 | //-- build kd tree from scene geometry
|
---|
| 164 | preprocessor->BuildKdTree();
|
---|
| 165 | preprocessor->KdTreeStatistics(cout);
|
---|
[1201] | 166 | preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
|
---|
[1196] | 167 |
|
---|
[1197] | 168 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
| 169 |
|
---|
[1196] | 170 | KdTree *kdTree2 = new KdTree;
|
---|
[1201] | 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");
|
---|
[1197] | 179 | MeshManager::GetSingleton()->ExportEntries("meshes.bin");
|
---|
| 180 |
|
---|
[1196] | 181 | if (exporter)
|
---|
| 182 | {
|
---|
| 183 | exporter->SetWireframe();
|
---|
[1197] | 184 | exporter->ExportKdTree(*kdTree2, true);
|
---|
[1196] | 185 |
|
---|
| 186 | delete exporter;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | DEL_PTR(kdTree2);
|
---|
| 190 |
|
---|
[1145] | 191 | // parse view cells related options
|
---|
| 192 | preprocessor->PrepareViewCells();
|
---|
| 193 |
|
---|
| 194 | // p->mSceneGraph->Export("soda.x3d");
|
---|
[1196] | 195 | if (0)
|
---|
| 196 | {
|
---|
[1145] | 197 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
| 198 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
[746] | 199 | }
|
---|
[878] | 200 |
|
---|
[1001] | 201 |
|
---|
[1154] | 202 | // create a preprocessor thread (note: capsulte calls to boost fuctions!)
|
---|
| 203 |
|
---|
| 204 | //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
|
---|
[1146] | 205 | BoostPreprocessorThread pt(preprocessor);
|
---|
[1145] | 206 |
|
---|
| 207 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
| 208 | {
|
---|
[1153] | 209 | // create and run the preprocessor application in a parallel thread
|
---|
[1181] | 210 | pt.InitThread();
|
---|
[1153] | 211 | //pt.RunThread();
|
---|
| 212 |
|
---|
[1145] | 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();
|
---|
[1005] | 220 | }
|
---|
[1181] | 221 |
|
---|
[1145] | 222 | Cleanup();
|
---|
[840] | 223 |
|
---|
[1145] | 224 | return returnCode;
|
---|
[162] | 225 | }
|
---|
| 226 |
|
---|