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

Revision 1344, 6.4 KB checked in by mattausch, 18 years ago (diff)

worked on triangle processing. logical units will be created by grouping objects
using their visibility definitions.

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
[1328]114  int pos = (int)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")
[1328]151        {
[1145]152                preprocessor = new VssPreprocessor();
[1328]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                                        }
[1328]178                                        else
179                                        {
[1145]180                                                Environment::DelSingleton();
181                                                cerr<<"Unknown preprocessor type"<<endl;
182                                                Debug<<"Unknown preprocessor type"<<endl;
183                                                exit(1);
184                                        }
185                                }
186                        }
[1002]187                }
188        }
[997]189
[1328]190        ////////////////////////////////////////
[1145]191        //-- load scene
[492]192
[1145]193        Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
194        string filename(buff);
[1328]195
196        if (!preprocessor->LoadScene(filename))
197        {
198                cout << "loading file " << filename << " failed" << endl;
199                Cleanup();
200                exit(1);
201        }
202
[1272]203        string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf");
[1328]204
[1221]205        //-- initialize external ray casters
[1272]206        if (preprocessor->InitRayCast(rayCastFile))
[1328]207        {
[1221]208                cout << "ray casting initialized!" << endl;
[1328]209        }
[1221]210        else
211        {
212                cout << "ray casting initialization failed" << endl;
[1328]213                Cleanup();
[1221]214                exit(1);
215        }
[1344]216
[1145]217        //-- build kd tree from scene geometry
218        preprocessor->BuildKdTree();
219        preprocessor->KdTreeStatistics(cout);
[1344]220
[1221]221        /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
[1197]222        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
223
[1196]224        KdTree *kdTree2 = new KdTree;
[1201]225
226        cout << "loading kd tree ... ";
227        long startTime = GetTime();
228        kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
229               
230        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
231
232        Exporter *exporter = Exporter::GetExporter("testkd.x3d");
[1197]233        MeshManager::GetSingleton()->ExportEntries("meshes.bin");
234
[1196]235        if (exporter)
236        {
237                exporter->SetWireframe();
[1197]238                exporter->ExportKdTree(*kdTree2, true);
[1196]239
240                delete exporter;
241        }
242
243        DEL_PTR(kdTree2);
[1344]244*/
[1145]245        // parse view cells related options
246        preprocessor->PrepareViewCells();
247
[1196]248        if (0)
249        {
[1145]250                preprocessor->Export(filename + "-out.x3d", true, false, false);
251                preprocessor->Export(filename + "-kdtree.x3d", false, true, false);     
[746]252        }
[1344]253
[1239]254        // create a preprocessor thread (note: capsulates calls to boost fuctions!)
[1272]255        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
256#if USE_BOOST
[1264]257        BoostPreprocessorThread pt(preprocessor);
[1272]258#endif
259       
[1248]260        bool guiSupported = false;
[1145]261        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
[1344]262        {
[1241]263                cout << "using gl widget" << endl;
[1153]264                // create and run the preprocessor application in a parallel thread
[1272]265#if USE_BOOST
[1181]266                pt.InitThread();
[1272]267#endif
[1248]268                //pt.RunThread();
[1344]269
[1248]270                // display the render widget
[1344]271                if (!rendererWidget)
272                {
[1272]273#if !USE_QT
[1344]274                        guiSupported = LoadMyDll();
[1272]275#else
[1344]276                        rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph,
277                                preprocessor->mViewCellsManager,
278                                preprocessor->mKdTree);
[1272]279#endif
280                }
[1344]281
282        }
[1221]283       
[1248]284        if (!guiSupported) {
285          preprocessor->mUseGlRenderer = false;
286          preprocessor->mUseGlDebugger = false;
[1005]287        }
[1181]288       
[1248]289        if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) {
290          // just call the mail method -> will be executed in the main thread
[1272]291#if USE_BOOST
[1248]292          pt.Main();
[1272]293#endif
[1248]294        }
295       
[1145]296        Cleanup();
[1248]297       
[1145]298        return returnCode;
[162]299}
300
Note: See TracBrowser for help on using the repository browser.