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

Revision 1181, 4.3 KB checked in by mattausch, 18 years ago (diff)
RevLine 
[1151]1#include <windows.h>
2#include <stdio.h>
3#include <crtdbg.h>
4
[162]5#include "SamplingPreprocessor.h"
[374]6#include "VssPreprocessor.h"
[446]7#include "RssPreprocessor.h"
[162]8#include "ExactPreprocessor.h"
9#include "Parser.h"
10#include "UnigraphicsParser.h"
[170]11#include "X3dParser.h"
[162]12#include "Environment.h"
13#include "Camera.h"
[170]14#include "MeshKdTree.h"
[264]15#include "Exporter.h"
[310]16#include "ViewCell.h"
[321]17#include "SceneGraph.h"
[1146]18#include "BoostPreprocessorThread.h"
[878]19#include "RenderSampler.h"
[1001]20#include "ResourceManager.h"
[492]21#include "GlRenderer.h"
22
[162]23#define USE_EXE_PATH false
24
[372]25
[863]26using namespace GtpVisibilityPreprocessor;
[492]27
[1145]28Preprocessor *preprocessor = NULL;
[1151]29GlRendererWidget *rendererWidget = NULL;
[1145]30
[1151]31// DLL function signature
[1153]32typedef GlRendererWidget *(*importFunction)(Preprocessor *);
[1145]33
[1151]34int LoadMyDll()
35{
36        importFunction LoadRenderWidget;
37       
38    // Load DLL file
[1153]39        HINSTANCE hinstLib = LoadLibrary("QtGlRenderer.dll");
[1151]40       
41        if (hinstLib == NULL)
42        {
43                cout << "ERROR: unable to load DLL\n";
44                return 1;
45        }
46
47        // Get function pointer
[1153]48        LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget");
[1151]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
[1153]57    rendererWidget = LoadRenderWidget(preprocessor);
[1151]58
[1152]59        // Unload DLL file
60    //FreeLibrary(hinstLib);
61
[1151]62        return 0;
63}
64
65
66
[1145]67void Cleanup()
68{
[1151]69        DEL_PTR(rendererWidget);
[1145]70        DEL_PTR(preprocessor);
71
72        Environment::DelSingleton();
73        MeshManager::DelSingleton();
74        MaterialManager::DelSingleton();
75}
76
77
78void DisplayWidget()
79{
[1151]80        if (!rendererWidget)
81                LoadMyDll();
82
[1153]83        //rendererWidget->Show();
[1145]84}
85
86
[162]87int
[492]88main(int argc, char **argv)
[997]89{
[991]90
[1145]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);
[997]99
[1145]100        int returnCode = 0;
[1153]101       
[1145]102        InitTiming();
[997]103
[1145]104        Debug.open("debug.log");
[997]105
[1145]106        Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
107        MeshKdTree::ParseEnvironment();
[1002]108
[1145]109        char buff[128];
110        Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
111        string preprocessorType(buff);
112
113        if (preprocessorType == "vss")
[1002]114        {
[1145]115                preprocessor = new VssPreprocessor();
[1002]116        }
[374]117        else
[1002]118        {
[1145]119                if (preprocessorType == "rss")
[1002]120                {
[1145]121                        preprocessor = new RssPreprocessor();
[1002]122                }
[811]123                else
[1145]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                        }
[1002]149                }
150        }
[997]151       
152
[1145]153        //-- load scene
[492]154
[1145]155        Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
156        string filename(buff);
157        preprocessor->LoadScene(filename);
[997]158
[1145]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);     
[746]171        }
[878]172
[1001]173
[1154]174        // create a preprocessor thread (note: capsulte calls to boost fuctions!)
175
176        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
[1146]177        BoostPreprocessorThread pt(preprocessor);
[1145]178
179        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
180        {
[1153]181                // create and run the preprocessor application in a parallel thread
[1181]182                pt.InitThread();
[1153]183                //pt.RunThread();
184
[1145]185                // display the render widget
186                DisplayWidget();
187        }
188        else
189        {
190                // just call the mail method -> will be executed in the main thread
191                pt.Main();
[1005]192        }
[1181]193       
[1145]194        Cleanup();
[840]195
[1145]196        return returnCode;
[162]197}
198
Note: See TracBrowser for help on using the repository browser.