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

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