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

Revision 1146, 4.5 KB checked in by mattausch, 18 years ago (diff)

use qt renderer as dll
changed vsp render heuristics sweep
capsulated thread

RevLine 
[162]1#include "SamplingPreprocessor.h"
[374]2#include "VssPreprocessor.h"
[446]3#include "RssPreprocessor.h"
[162]4#include "ExactPreprocessor.h"
5#include "Parser.h"
6#include "UnigraphicsParser.h"
[170]7#include "X3dParser.h"
[162]8#include "Environment.h"
9#include "Camera.h"
[170]10#include "MeshKdTree.h"
[264]11#include "Exporter.h"
[310]12#include "ViewCell.h"
[321]13#include "SceneGraph.h"
[1146]14#include "BoostPreprocessorThread.h"
[878]15#include "RenderSampler.h"
[1001]16#include "ResourceManager.h"
[492]17#include "GlRenderer.h"
18
[162]19#define USE_EXE_PATH false
20
[570]21#include <crtdbg.h>
[372]22
[863]23using namespace GtpVisibilityPreprocessor;
[492]24
[1145]25Preprocessor *preprocessor = NULL;
[1146]26GlRenderWidget *renderWidget = NULL;
[1145]27
28
29void Cleanup()
30{
[1146]31        DEL_PTR(renderWidget);
[1145]32        DEL_PTR(preprocessor);
33
34        Environment::DelSingleton();
35        MeshManager::DelSingleton();
36        MaterialManager::DelSingleton();
37}
38
39
40void DisplayWidget()
41{
[1146]42        // note matt: capsulate qt dependent code as good as possible
43        renderWidget =
44                new GlRenderWidget(preprocessor->mSceneGraph,
45                                                   preprocessor->mViewCellsManager,
46                                                   preprocessor->mKdTree);
47
48        renderWidget->Show();
49
[1145]50#if QT_ENABLED
51
52        // create a qt application first (must be created before any opengl widget ...)
53        app = new QApplication(argc, argv);
54
55        if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
56                QMessageBox::information(0, "OpenGL pbuffers",
57                        "This system does not support OpenGL/pbuffers.",
58                        QMessageBox::Ok);
59                return -1;
60        }
61       
62        // note matt: capsulate qt dependent code as good as possible
63        rendererWidget =
64                new GlRendererWidget(p->mSceneGraph, p->mViewCellsManager, p->mKdTree);
65
66        rendererWidget->resize(640, 480);
67        rendererWidget->show();
68
69        if (0 && p->GetRenderer())
70        {
71                cout<<"CONNECTING"<<endl;
72                QObject::connect(p->GetRenderer(),
73                SIGNAL(UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &)),
74                                rendererWidget->mControlWidget,
75                                SLOT(UpdatePvsErrorItem(int i,
76                                GlRendererBuffer::PvsErrorEntry &)));
77
78                cout<<"CONNECTED"<<endl;
79        }
80#endif
81}
82
83
[162]84int
[492]85main(int argc, char **argv)
[997]86{
[991]87
[1145]88        //Now just call this function at the start of your program and if you're
89        //compiling in debug mode (F5), any leaks will be displayed in the Output
90        //window when the program shuts down. If you're not in debug mode this will
91        //be ignored. Use it as you will!
92        //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
93        _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
94        _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
95        _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
[997]96
[1145]97        int returnCode = 0;
[1112]98
[1145]99        InitTiming();
[997]100
[1145]101        Debug.open("debug.log");
[997]102
[1145]103        Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
104        MeshKdTree::ParseEnvironment();
[1002]105
[1145]106        char buff[128];
107        Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
108        string preprocessorType(buff);
109
110        if (preprocessorType == "vss")
[1002]111        {
[1145]112                preprocessor = new VssPreprocessor();
[1002]113        }
[374]114        else
[1002]115        {
[1145]116                if (preprocessorType == "rss")
[1002]117                {
[1145]118                        preprocessor = new RssPreprocessor();
[1002]119                }
[811]120                else
[1145]121                {
122                        if (preprocessorType == "exact")
123                        {
124                                preprocessor = new ExactPreprocessor();
125                        }
126                        else
127                        {
128                                if (preprocessorType == "sampling")
129                                {
130                                        preprocessor = new SamplingPreprocessor();
131                                }
132                                else
133                                {       
134                                        if (preprocessorType == "render")
135                                        {
136                                                preprocessor = new RenderSampler();
137                                        }
138                                        else {
139                                                Environment::DelSingleton();
140                                                cerr<<"Unknown preprocessor type"<<endl;
141                                                Debug<<"Unknown preprocessor type"<<endl;
142                                                exit(1);
143                                        }
144                                }
145                        }
[1002]146                }
147        }
[997]148       
149
[1145]150        //-- load scene
[492]151
[1145]152        Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
153        string filename(buff);
154        preprocessor->LoadScene(filename);
[997]155
[1145]156        //-- build kd tree from scene geometry
157
158        preprocessor->BuildKdTree();
159        preprocessor->KdTreeStatistics(cout);
160
161        // parse view cells related options
162        preprocessor->PrepareViewCells();
163
164        //  p->mSceneGraph->Export("soda.x3d");
165        if (0) {
166                preprocessor->Export(filename + "-out.x3d", true, false, false);
167                preprocessor->Export(filename + "-kdtree.x3d", false, true, false);     
[746]168        }
[878]169
[1001]170
[1145]171        // create a preprocessor thread
172        //PreprocessorThread *pt = new PreprocessorThread(p, app);
[1146]173        BoostPreprocessorThread pt(preprocessor);
[1145]174
175        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
176        {
177                // display the render widget
178                DisplayWidget();
179
[1146]180                // create and run the preprocessor application in a parallel thread
181                pt.InitThread();
182                pt.RunThread();
[1145]183        }
184        else
185        {
186                // just call the mail method -> will be executed in the main thread
187                pt.Main();
[1005]188        }
[878]189
[1002]190
[1145]191        Cleanup();
[840]192
[1145]193        return returnCode;
[162]194}
195
Note: See TracBrowser for help on using the repository browser.