source: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp @ 1221

Revision 1221, 5.2 KB checked in by mattausch, 18 years ago (diff)

added intel ray tracing

RevLine 
[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]30using namespace GtpVisibilityPreprocessor;
[492]31
[1145]32Preprocessor *preprocessor = NULL;
[1151]33GlRendererWidget *rendererWidget = NULL;
[1145]34
[1151]35// DLL function signature
[1153]36typedef GlRendererWidget *(*importFunction)(Preprocessor *);
[1145]37
[1151]38int 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]71void 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
82void DisplayWidget()
83{
[1151]84        if (!rendererWidget)
85                LoadMyDll();
86
[1153]87        //rendererWidget->Show();
[1145]88}
89
90
[162]91int
[492]92main(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
[1221]163        //-- initialize external ray casters
164        if (preprocessor->InitRayCast("../data/grandcanyon1_RotXmin90.kdf"))
165        {
166                cout << "ray casting initialized!" << endl;
167        }
168        else
169        {
170                cout << "ray casting initialization failed" << endl;
171                exit(1);
172        }
173
[1145]174        //-- build kd tree from scene geometry
175        preprocessor->BuildKdTree();
176        preprocessor->KdTreeStatistics(cout);
[1196]177       
[1221]178        /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
[1197]179        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
180
[1196]181        KdTree *kdTree2 = new KdTree;
[1201]182
183        cout << "loading kd tree ... ";
184        long startTime = GetTime();
185        kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
186               
187        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
188
189        Exporter *exporter = Exporter::GetExporter("testkd.x3d");
[1197]190        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
191
[1196]192        if (exporter)
193        {
194                exporter->SetWireframe();
[1197]195                exporter->ExportKdTree(*kdTree2, true);
[1196]196
197                delete exporter;
198        }
199
200        DEL_PTR(kdTree2);
[1221]201*/
[1145]202        // parse view cells related options
203        preprocessor->PrepareViewCells();
204
205        //  p->mSceneGraph->Export("soda.x3d");
[1196]206        if (0)
207        {
[1145]208                preprocessor->Export(filename + "-out.x3d", true, false, false);
209                preprocessor->Export(filename + "-kdtree.x3d", false, true, false);     
[746]210        }
[878]211
[1001]212
[1154]213        // create a preprocessor thread (note: capsulte calls to boost fuctions!)
214
215        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
[1146]216        BoostPreprocessorThread pt(preprocessor);
[1145]217
218        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
219        {
[1153]220                // create and run the preprocessor application in a parallel thread
[1181]221                pt.InitThread();
[1221]222       
[1145]223                // display the render widget
224                DisplayWidget();
225        }
226        else
227        {
228                // just call the mail method -> will be executed in the main thread
229                pt.Main();
[1005]230        }
[1181]231       
[1145]232        Cleanup();
[840]233
[1145]234        return returnCode;
[162]235}
236
Note: See TracBrowser for help on using the repository browser.