source: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp @ 2689

Revision 2689, 63.0 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[2576]1#include "glInterface.h"
2#include "QtGlRenderer.h"
[1252]3#include "Mesh.h"
4#include "OcclusionQuery.h"
5#include "ViewCellsManager.h"
6#include "SceneGraph.h"
7#include "Pvs.h"
8#include "Viewcell.h"
9#include "Beam.h"
10#include "KdTree.h"
11#include "Environment.h"
[1942]12#include "RssPreprocessor.h"
13#include "RssTree.h"
14#include "Trackball.h"
15#include "QtPreprocessorThread.h"
[2148]16#include "Material.h"
[2538]17#include "IntersectableWrapper.h"
[2580]18#include "LogWriter.h"
[2636]19#include "RayCaster.h"
[1942]20
[2538]21
[1942]22#define USE_CG 1
23
[2620]24#define TEST_PVS_RENDERING 0
[1942]25
26#if USE_CG
[1252]27#include <Cg/cg.h>
28#include <Cg/cgGL.h>
[1942]29#endif
[1252]30
31#include <QVBoxLayout>
32
[2679]33
[2686]34using namespace std;
[2679]35
36
[2669]37namespace GtpVisibilityPreprocessor
38{
[1252]39
[1942]40 
[1252]41class ViewCellsManager;
42
43static CGcontext sCgContext = NULL;
44static CGprogram sCgFragmentProgram = NULL;
45static CGprofile sCgFragmentProfile;
46
47
48QtGlRendererWidget *rendererWidget = NULL;
49QtGlDebuggerWidget *debuggerWidget = NULL;
50
[2580]51const static int SAMPLES_INCR = 2000000;
[1252]52
[2604]53
[2686]54static SimpleRayContainer sViewPointsList;
55static SimpleRayContainer::const_iterator sViewPointsListIt;
[2604]56
[2686]57
58
[1252]59static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
60{
61        return obj1->mId < obj2->mId;
62}
63
[2562]64
65inline static bool nearerThan(ViewCell *vc1, ViewCell *vc2)
66{
67        return vc1->GetDistance() > vc2->GetDistance();
68}
69
70
[1942]71#if USE_CG
[1252]72static void handleCgError()
73{
74    Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
75    exit(1);
76}
[1942]77#endif
[1252]78
[2676]79
[2677]80void QtGlRendererBuffer::MakeLive()
[1252]81{
[2676]82        QGLPixelBuffer::makeCurrent();
83        //makeCurrent();
[1252]84}
85
[2676]86
[2677]87void QtGlRendererBuffer::DoneLive()
[1252]88{
[2676]89        QGLPixelBuffer::doneCurrent();
90        //doneCurrent();
[1252]91}
92 
93
[2664]94QtGlRendererBuffer::QtGlRendererBuffer(int w, int h,
[1252]95                                                                           SceneGraph *sceneGraph,
96                                                                           ViewCellsManager *viewcells,
97                                                                           KdTree *tree):
[2669]98QGLPixelBuffer(QSize(w, h),
99                           QGLFormat(QGL::StencilBuffer |
100                                                 QGL::DepthBuffer |
101                                                 QGL::DoubleBuffer |
[2677]102                                                 QGL::Rgba)
103                                                 ),
[2664]104GlRendererBuffer(sceneGraph, viewcells, tree)
[1942]105{
[2679]106        //makeCurrent();
[2677]107        MakeLive();
[2664]108        glViewport(0, 0, w, h);
109    glMatrixMode(GL_PROJECTION);
110    glLoadIdentity();
111    glOrtho(-1, 1, -1, 1, -99, 99);
112    //glTranslatef(-0.5f, -0.5f, 0.0f);
113    glMatrixMode(GL_MODELVIEW);
114    glLoadIdentity();
115
116        InitGL();
[2677]117
[2679]118        //doneCurrent();
119        //DoneLive();
[1252]120}
121
[2664]122
123void QtGlRendererBuffer::RenderPvs(const ObjectPvs &pvs)
[2620]124{
[2671]125        EnableDrawArrays();
[2686]126       
127        // prepare pvs for rendering
[2663]128        PreparePvs(pvs);
[1942]129
[2671]130        if (mUseVbos)
131                glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
132
[2663]133        int offset = (int)mObjects.size() * 3;
134        char *arrayPtr = mUseVbos ? NULL : (char *)mData;
[2620]135
[2663]136        glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
137        glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
138        glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
[2620]139}
140
[2670]141
[2002]142// reimplemented here so that we can snap the error windows
[2664]143float QtGlRendererBuffer::GetPixelError(int &pvsSize)
[1252]144{
[2677]145        MakeLive();
[2671]146
[2670]147        if (0)
148        {
149                cout << "stencil: " << format().stencil() << endl;
150                cout << "depth: " << format().depth() << endl;
151                cout << "rgba: " << format().rgba() << endl;
152                cout << "double: " << format().doubleBuffer() << endl;
[2677]153                cout << "depth: " << format().depth() << endl;
154                cout << "gl:" << format().hasOpenGL() << endl;
155                cout << "dir:" << format().directRendering() << endl;
[2670]156        }
[2669]157
[2670]158        ++ mCurrentFrame;
159
[2662]160        float pErrorPixels = -1.0f;
[2008]161
[2543]162        mUseFalseColors = false;
[2663]163        unsigned int pixelCount = 0;
[2008]164
[2669]165       
[2543]166        ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
[2648]167
[2543]168        if (viewcell == NULL)
[2664]169                return -1.0f;
[2050]170
[2627]171        bool evaluateFilter;
172        Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluateFilter", evaluateFilter);
173
[2670]174        ObjectPvs pvs;
175
[2627]176        if (!evaluateFilter)
[2662]177                pvs = viewcell->GetPvs();
[2663]178        else
179                mViewCellsManager->ApplyFilter2(viewcell, false, mViewCellsManager->GetFilterWidth(), pvs);
[2635]180
[2669]181        pvsSize = pvs.GetSize();
182       
183        if (pvsSize == 0)
184                return 0.0f;
[2002]185
[2613]186        mUseForcedColors = true;
187
[2543]188        SetupCamera();
[2664]189
[2669]190        // use shading
191        if (mSnapErrorFrames)
192        {
193                GLfloat light_ambient[] = {0.3, 0.3, 0.3, 1.0};
194                GLfloat light_diffuse[] = {0.6, 0.6, 0.6, 1.0};
195                GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
196
[2670]197                //GLfloat light_position[] =  {278.0f, 548.8f,279.0f, 1.0f};
198                GLfloat light_position[] =  {0.f,0.f,0.f, 1.0f};
[2669]199
200                glEnable(GL_LIGHT0);
201
202                // a light
203                glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
204                glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
205                glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
206
207                glEnable(GL_LIGHTING);
208                glLightfv (GL_LIGHT0, GL_POSITION, light_position);
209
210                glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
211                glEnable(GL_COLOR_MATERIAL);
212
213                glShadeModel(GL_SMOOTH);
214        }
215
216        glDisable(GL_ALPHA_TEST);
217               
218        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
[2543]219        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
[2669]220
221        //glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE);
222        glColor3f(0, 1, 0);
223
224        glDepthFunc(GL_LESS);
225        glDepthMask(GL_TRUE);
[2663]226        glEnable(GL_DEPTH_TEST);
[2050]227
[2669]228        glStencilFunc(GL_EQUAL, 0x0, 0x1);
229        glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
[2543]230
[2670]231        KdNode::NewMail2();
232        Intersectable::NewMail();
233
[2669]234        // render pvs once
[2620]235        RenderPvs(pvs);
[2662]236
[2671]237        //cout << "rendered nodes: " << mRenderedNodes << endl;
238
[2564]239        //glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
[2669]240        //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
[1942]241        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
[2667]242
[2543]243        glEnable(GL_STENCIL_TEST);
[2671]244        glColor3f(1, 0, 0);
[2543]245
[2662]246
[2669]247        // render scene, record differences
248        OcclusionQuery *query = mOcclusionQueries[0];
[2543]249
[2669]250        KdNode::NewMail2();
[2613]251        Intersectable::NewMail();
252
[2543]253        query->BeginQuery();
254
[2670]255        ++ mCurrentFrame;
256
[2543]257        RenderScene();
[2662]258
[2689]259        glFlush();
260
[2543]261        query->EndQuery();
262        glDisable(GL_STENCIL_TEST);
[2664]263       
[2543]264        pixelCount = query->GetQueryResult();
265
[2677]266        pErrorPixels = (float)pixelCount / (GetWidth() * GetHeight());
[2670]267
[2687]268        const int pixelThres = 0;
[2686]269
[2677]270        // some error happened
[2686]271        if (pixelCount > pixelThres)
[2662]272        {
[2686]273                cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << " vp: " << mViewPoint << endl;
[2670]274       
275                if (mSnapErrorFrames)
276                {
277                        glReadBuffer(GL_BACK);
278                        //glReadBuffer(GL_FRONT);
[2543]279
[2671]280
[2670]281                        //////////////
282                        //-- output error visualization
[2613]283
[2670]284                        char filename[256];
[2677]285                        //sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels);
[2687]286                        sprintf(filename, "error-frame-%04d-%04d-%08d.png", mFrame, viewcell->GetId(), pixelCount);
[2670]287                        QImage im = toImage();
288                        string str = mSnapPrefix + filename;
289                        QString qstr(str.c_str());
[2662]290
[2670]291                        im.save(qstr, "PNG");
[2662]292
[2687]293#if 0
[2670]294                        ///////////
295                        //-- output computed pvs
[2662]296
[2687]297                        //mUseFalseColors = true;
[2670]298                        glPushAttrib(GL_CURRENT_BIT);
299                        glColor3f(0, 1, 0);
[2662]300
[2670]301                        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
302                        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
[2669]303
[2670]304                        KdNode::NewMail2();
305                        Intersectable::NewMail();
[2662]306
[2670]307                        ++ mCurrentFrame;
[2671]308
[2670]309                        // render pvs once
310                        RenderPvs(pvs);
[2669]311
[2689]312                        glFlush();
313
[2687]314                        //mUseForcedColors = false;
[2670]315                        im = toImage();
[2679]316                        sprintf(filename, "error-frame-%04d-%04d-%08d-pvs.png", mFrame, viewcell->GetId(), pixelCount);
[2670]317                        str = mSnapPrefix + filename;
318                        qstr = str.c_str();
319                        im.save(qstr, "PNG");
320
321                        glPopAttrib();
[2687]322#endif
[2670]323                }
[1252]324        }
[2662]325
[2543]326        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
[2613]327
[2679]328        //DoneLive();
[2613]329
[2543]330        return pErrorPixels;
[1252]331}
332
[1942]333int
334QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,
335                                                           ObjectContainer &pvs) const
[1252]336{
337        int pvsSize = 0;
338        QImage image = toImage();
339        Intersectable::NewMail();
340
341        std::stable_sort(objects.begin(), objects.end(), ilt);
342
343        MeshInstance dummy(NULL);
344
345        Intersectable *obj = NULL;
[2543]346
[1252]347        for (int x = 0; x < image.width(); ++ x)
348        {
349                for (int y = 0; y < image.height(); ++ y)
350                {
351                        QRgb pix = image.pixel(x, y);
352                        const int id = GetId(qRed(pix), qGreen(pix), qBlue(pix));
353
354                        dummy.SetId(id);
355
356                        ObjectContainer::iterator oit =
357                                lower_bound(objects.begin(), objects.end(), &dummy, ilt);
[2543]358
[1252]359                        if (//(oit != oit.end()) &&
360                                ((*oit)->GetId() == id) &&
361                                !obj->Mailed())
362                        {
363                                obj = *oit;
364                                obj->Mail();
365                                ++ pvsSize;
366                                pvs.push_back(obj);
367                        }
368                }
369        }
370
371        return pvsSize;
372}
373
374
[2543]375void QtGlRendererWidget::InitGL()
[1997]376{
[2543]377        GlRenderer::InitGL();
[1942]378
[2643]379        //glEnable(GL_FOG);
380        //glFogi(GL_FOG_MODE, GL_EXP);
381        glFogi(GL_FOG_MODE, GL_LINEAR);
382
383//      glFogf(GL_FOG_DENSITY, .2f);
384        glFogf(GL_FOG_START, 50.f);
385        glFogf(GL_FOG_END, 500.f);
386
[2633]387        GLfloat light_ambient[] = {0.3, 0.3, 0.3, 1.0};
388    GLfloat light_diffuse[] = {0.6, 0.6, 0.6, 1.0};
389    GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
390    GLfloat light_position[] =  //{278.0f, 548.8f,279.0f, 1.0f };
391    { 0.f,0.f,0.f,1.0f };
392
393    /*glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
394    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
395    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
396    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
397*/
398    glEnable(GL_LIGHT0);
399
[2604]400        GLfloat mat_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
401       
402        // mat_specular and mat_shininess are NOT default values
403        GLfloat mat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
404        GLfloat mat_specular[] = {0.3f, 0.3f, 0.3f, 1.0f};
405        GLfloat mat_shininess[] = {1.0f};
[1942]406
[2633]407/*      GLfloat light_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
[2604]408        GLfloat light_diffuse[] = {0.4f, 0.4f, 0.4f, 1.0f};
409        GLfloat light_specular[] = {0.3f, 0.3f, 0.3f, 1.0f};
[2543]410
[2604]411        GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
[2633]412*/
[2543]413
414        // default Material
415        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
416        glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
417        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
418        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
419
420        // a light
421        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
422        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
423        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
424
[2633]425        /*glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
[2543]426        glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
427        glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
[2633]428*/
429        //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
[2543]430
431        glEnable(GL_LIGHTING);
432        glEnable(GL_LIGHT0);
[2633]433//      glEnable(GL_LIGHT1);
[2543]434
435        // set position of the light
[2633]436        /*GLfloat infinite_light[] = {  1.0, 0.8, 1.0, 0.0  };
[2543]437        glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
438
439        // set position of the light2
440        GLfloat infinite_light2[] = {  -0.3, 1.5, 1.0, 0.0  };
441        glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
[2633]442*/
443        glLightfv (GL_LIGHT0, GL_POSITION, light_position);
[2543]444
445        glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
[2571]446        // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
[2543]447        glEnable(GL_COLOR_MATERIAL);
448
[2633]449        glShadeModel(GL_SMOOTH);
[1997]450}
[1942]451
[1997]452
[1252]453void
[1942]454QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
[1252]455{
[2543]456        if (!mTopView) {
457                int ww = w;
458                int hh = h;
459                glViewport(0, 0, ww, hh);
460                glMatrixMode(GL_PROJECTION);
461                glLoadIdentity();
[2562]462                gluPerspective(angle, ww/(float)hh, 0.1, 2.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
[2543]463                glMatrixMode(GL_MODELVIEW);
464        } else {
465                int ww = w;
466                int hh = h;
467                glViewport(0, 0, ww, hh);
468                glMatrixMode(GL_PROJECTION);
469                glLoadIdentity();
[2562]470                gluPerspective(50.0, ww / (float)hh, 0.1, 20.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
[2543]471                glMatrixMode(GL_MODELVIEW);
472        }
[1252]473}
474
[1942]475
[2538]476bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const
477{
478        if (viewCell != mPvsCache.mViewCell)
479                return true;
[1942]480
[2538]481        if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize)
482                return true;
483
484        return false;
485}
486
487
488void QtGlRendererWidget::_RenderPvs()
[1252]489{
[2671]490        EnableDrawArrays();
[2682]491
[2683]492        if (mUseVbos)
[2671]493                glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
494
[2633]495        mUseFalseColors = false;
[2538]496
[2543]497        int offset = (int)mObjects.size() * 3;
[2538]498        char *arrayPtr = mUseVbos ? NULL : (char *)mData;
[2543]499
[2538]500        glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
501        glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
502        glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
[2664]503
[2685]504#if DYNAMIC_OBJECTS_HACK
[2609]505        // handle dynamic objects
506        DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicObjects.end();
507
508        for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit)
509        {
[2621]510                _RenderDynamicObject(*dit);
[2609]511        }
[2615]512#endif
[2538]513}
[1942]514
[1252]515
[2670]516void QtGlRendererWidget::PreparePvs(const ObjectPvs &pvs)
[2538]517{
[2543]518        int indexBufferSize = 0;
519       
[2670]520        // hack: mail not working with multiple threads
[2643]521        KdNode::NewMail2();
[2538]522
[2633]523        mPvsSize = pvs.GetSize();
524
[2615]525#if DYNAMIC_OBJECTS_HACK
[2609]526        mDynamicObjects.clear();
[2615]527#endif
[2538]528
[2633]529        ObjectPvsIterator it = pvs.GetIterator();
530
[2543]531        while (it.HasMoreEntries())
[2538]532        {
533                Intersectable *obj = it.Next();
[2686]534
[2609]535                switch (obj->Type())
536                {
537                case Intersectable::KD_INTERSECTABLE:
538                        {
539                                KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
540                                _UpdatePvsIndices(node, indexBufferSize);
541                        }
542                        break;
[2615]543#if DYNAMIC_OBJECTS_HACK
544
545                case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE:
546                        mDynamicObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem());
547                        break;
548#endif
[2609]549                default:
550                        cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl;
551                }
[2538]552        }
[2543]553
554        mIndexBufferSize = indexBufferSize;
[2538]555}
556
557
[2670]558void QtGlRendererWidget::VisualizePvs()
[2538]559{
560        if (mUseVbos)
561                glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
562
[2543]563        ++ mCurrentFrame;
564
[2538]565        EnableDrawArrays();
[2669]566               
[2538]567        if (mDetectEmptyViewSpace)
568                glEnable(GL_CULL_FACE);
569        else
570                glDisable(GL_CULL_FACE);
571
[2543]572        ViewCell *viewcell = NULL;
[2538]573        viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
574
575        if (viewcell)
576        {
[2543]577                // copy the pvs so that it can be filtered ...
[2538]578                if (PvsChanged(viewcell))
579                {
580                        mPvsCache.Reset();
581                        mPvsCache.mViewCell = viewcell;
582                        mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize();
583
584                        if (mUseSpatialFilter)
585                        {
[2543]586                                //mMutex.lock();
[2538]587                                // mSpatialFilter size is in range 0.001 - 0.1
[2643]588                                mViewCellsManager->ApplyFilter2(viewcell,
589                                        mUseFilter,
590                                        100.0f * mSpatialFilterSize,
591                                        mPvsCache.mPvs,         
592                                        &mPvsCache.filteredBoxes);
[2543]593                                //mPvsCache.mPvs = pvs;
594                                //mMutex.unlock();
[2633]595                                //cout << "pvs size: " << mPvsCache.mPvs.GetSize() << endl;
[2542]596                        }
[2538]597                        else
598                        {
599                                mPvsCache.mPvs = viewcell->GetPvs();
600                        }
[2633]601                       
602                        // update the indices for rendering
[2671]603                        PreparePvs(mPvsCache.mPvs);
[2538]604                        emit PvsUpdated();
[2686]605
[2643]606                        mCurrentPvsCost = mPvsCache.mPvs.EvalPvsCost();
[2538]607                }
[2643]608
[2538]609                // Render PVS
610                if (mUseSpatialFilter && mRenderBoxes)
611                {
[2664]612                        for (size_t i=0; i < mPvsCache.filteredBoxes.size(); ++ i)
[2542]613                        {
[2538]614                                RenderBox(mPvsCache.filteredBoxes[i]);
[2542]615                        }
[2538]616                }
617                else
618                {
[2604]619                        if (!mRenderVisibilityEstimates && !mUseRandomColorPerPvsObject)
[2538]620                                _RenderPvs();
621                        else
[2609]622                                _RenderColoredPvs();
[1942]623                }
[2538]624
625                if (mRenderFilter)
626                {
627                        mWireFrame = true;
628                        RenderIntersectable(viewcell);
[2564]629                       
[2538]630                        mWireFrame = false;
631                }
[2686]632               
633                //mCurrentPvsCost = viewcell->GetPvs().EvalPvsCost();
[2538]634        }
635        else
636        {
637                RenderScene();
[1942]638        }
[2643]639
640        //cout << "vp: " << mViewPoint << " vd: " << mViewDirection << endl;
[1252]641}
642
643float
644QtGlRendererWidget::RenderErrors()
645{
[2543]646        float pErrorPixels = -1.0f;
[1252]647
[2543]648        SetupCamera();
649        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
[2049]650
[2543]651        glPushAttrib(GL_ENABLE_BIT);
[2049]652
[2543]653        glStencilFunc(GL_EQUAL, 0x0, 0x1);
654        glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
[2049]655
[2638]656        glColor3f(0.6f, 0.6f, 0.6f);
657
[2543]658        // Render PVS
[2670]659        VisualizePvs();
[1252]660
[2543]661        glEnable(GL_STENCIL_TEST);
[1252]662
[2543]663        glDisable(GL_LIGHTING);
[1252]664
[2543]665        SetupCamera();
[1252]666
[2638]667        mUseForcedColors = true;
668
[2543]669        glColor3f(1.0f, 0.0f, 0.0f);
[2049]670
[2662]671        OcclusionQuery *query = mOcclusionQueries[0];
672        query->BeginQuery();
673
[2543]674        RenderScene();
675
676        mUseForcedColors = false;
677
678        query->EndQuery();
679
680        glDisable(GL_STENCIL_TEST);
681        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
682
683        glPopAttrib();
684
685        // reenable other state
686        //  int wait=0;
687        //  while (!query.ResultAvailable()) {
688        //      wait++;
689        //  }
690
691        int pixelCount = query->GetQueryResult();
[2664]692        pErrorPixels = ((float)pixelCount) / (GetWidth() * GetHeight());
[2670]693       
[2664]694        if (0) cout << "error pixels=" << pixelCount << endl;
[2543]695
696        mRenderError = pErrorPixels;
697
698        return pErrorPixels;
[1252]699}
700
701
[2686]702void QtGlRendererWidget::timerEvent(QTimerEvent *timerEvent)
[1252]703{
[2686]704        if (mReplayMode && (timerEvent->timerId() == mReplayTimerId))
705        {
706                if (sViewPointsListIt == sViewPointsList.end())
707                {
708                        cout << "stopping replay" << endl;
709                        mReplayMode = false;
710                }
711                else
712                {
713                        SimpleRay sray = *sViewPointsListIt;
714
715                        mViewPoint = sray.mOrigin;
716                        mViewDirection = sray.mDirection;
717
718                        ++ sViewPointsListIt;
719                }
720
721
722                updateGL();
723        }
724
725        if (timerEvent->timerId() == mUpdateTimerId)
726                update();
[2538]727}
728
729
730void QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
731{
[2543]732        int x = e->pos().x();
733        int y = e->pos().y();
[1252]734
[2543]735        mousePoint.x = x;
736        mousePoint.y = y;
737
[1252]738}
739
[2636]740void QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *e)
741{
742
743  if (e->modifiers() & Qt::AltModifier)
744        if (mCurrentDynamicObjectIdx >= 0) {
[2685]745          // preprocessor->ScheduleUpdateDynamicObjects();
[2636]746        }
747}
748
[1252]749void
750QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
751{
[2686]752        if (mReplayMode)
753                return;
754
[2538]755        float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
[2609]756        float TURN_SENSITIVITY = 0.1f;
757        float TILT_SENSITIVITY = 32.0 ;
[2685]758        float TURN_ANGLE= M_PI / 36.0 ;
[1252]759
[2538]760        int x = e->pos().x();
761        int y = e->pos().y();
[1942]762
[2538]763        int diffx = -(mousePoint.x - x);
764        int diffy = -(mousePoint.y - y);
765
[2614]766        const float t = 1.0f;
[2538]767        if (e->modifiers() & Qt::ControlModifier)
768        {
[2609]769                mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY / 2.0;
770                mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY / 2.0;
[2685]771        }
[2615]772#if DYNAMIC_OBJECTS_HACK
[2614]773        else if (e->modifiers() & Qt::AltModifier)
[2538]774        {
[2614]775                if (mCurrentDynamicObjectIdx >= 0)
776                {
777                        Matrix4x4 tm;
778
779                        switch (mTrafoType)
780                        {
781                        case 0:
782                                {
[2638]783                                  if (e->modifiers() & Qt::ShiftModifier) {
784                                        const Vector3 transl(0, diffy, 0);
785                                        tm = TranslationMatrix(transl);
786                                 
787                                  } else {
[2614]788                                        const Vector3 transl(diffx, 0, diffy);
789                                        tm = TranslationMatrix(transl);
[2638]790                                  }
[2614]791                                }
792                                break;
793                        case 1:
794                                {
795                                        float scalef = 1.0f + 0.01f * (diffx + diffy);
796                                        if (scalef < 0.9) scalef = 0.9f;
797                                        else if (scalef > 1.1f) scalef = 1.1f;
798                                        tm = ScaleMatrix(scalef, scalef, scalef);
799                                }
800                                break;
801                        case 2:
802                                {
[2638]803                                  //                                    tm = RotationXMatrix(diffx) * RotationYMatrix(diffy);
804                                  tm = RotationYMatrix(diffx);
[2614]805                                }
806                                break;
807                        default:
808                                cerr << "not implemented" << endl;
809                        }
810
[2636]811                        SceneGraphLeaf *l =
812                          mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
[2621]813                        l->ApplyTransform(tm);
[2636]814                       
[2614]815                        updateGL();
816                }
817        }
[2615]818#endif
[2614]819        else
820        {
[2538]821                mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
822                float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
823                float angle = atan2(mViewDirection.x, mViewDirection.z);
824                mViewDirection.x = sin(angle + adiff);
825                mViewDirection.z = cos(angle + adiff);
826        }
827
828        mousePoint.x = x;
829        mousePoint.y = y;
830
831        updateGL();
[1252]832}
833
834
835void
836QtGlRendererWidget::resizeGL(int w, int h)
837{
[2543]838        SetupCameraProjection(w, h);
839        updateGL();
[1252]840}
841
[2670]842
843void QtGlRendererWidget::paintGL()
[1252]844{
[2543]845        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[1252]846
[2560]847        if (1)
848        {
[2543]849                SetupCameraProjection(width(), height());
850                SetupCamera();
851
[2560]852                if (mRenderErrors)
853                {
[2543]854                        RenderErrors();
[2560]855                }
856                else
857                {
[2543]858                        glColor3f(0.6f, 0.6f, 0.6f);
[2670]859                        VisualizePvs();
[2543]860                }
[2571]861
[2643]862                if (mShowRays)
[2571]863                {
[2593]864                        RenderRays(mViewCellsManager->mVizBuffer.GetRays(), mRayVisualizationMethod, mShowDistribution, 1);
[2571]865                }
[1942]866        }
[1252]867
[2543]868        RenderInfo();
869        mFrame ++;
[2638]870        //      cout<<"vp="<<mViewPoint<<" vd="<<mViewDirection<<endl;
[1252]871}
872
873
874void
875QtGlRendererWidget::SetupCamera()
876{
[2543]877        if (!mTopView)
878                GlRenderer::SetupCamera();
[2593]879        else
880        {
881                if (0)
882                {
[2543]883                        float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
884                        Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
885                                -1,
886                                mViewDirection.y);
887
888                        Vector3 target = mViewPoint + dist*mViewDirection;
889                        Vector3 up(0,1,0);
890
891                        glLoadIdentity();
892                        gluLookAt(pos.x, pos.y, pos.z,
[1252]893                                target.x, target.y, target.z,
894                                up.x, up.y, up.z);
[2563]895                }
896                else
897                {
898                        float dist = Magnitude(mSceneGraph->GetBox().Diagonal()) * mTopDistance;
[2625]899                        Vector3 pos = mViewPoint  + dist * Vector3(0,   1, 0);
[2543]900
901                        Vector3 target = mViewPoint;
902                        Vector3 up(mViewDirection.x, 0, mViewDirection.z);
903
904                        glLoadIdentity();
905                        gluLookAt(pos.x, pos.y, pos.z,
[1252]906                                target.x, target.y, target.z,
907                                up.x, up.y, up.z);
[2543]908
909                }
[1252]910        }
911
912}
913
[1942]914
[1252]915void
916QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
917{
[2604]918        switch (e->key())
919        {
920case Qt::Key_E:
921        mRenderErrors = !mRenderErrors;
922        updateGL();
923        break;
924case Qt::Key_R:
925        mUseRandomColorPerPvsObject = !mUseRandomColorPerPvsObject;;
926        updateGL();
927        break;
[2543]928case Qt::Key_T:
[1252]929        mTopView = !mTopView;
[1942]930        SetupCameraProjection(width(), height());
[1252]931        updateGL();
932        break;
[2543]933case Qt::Key_V:
[1252]934        mRenderViewCells = !mRenderViewCells;
935        updateGL();
936        break;
[2543]937case Qt::Key_P:
[1252]938        // set random viewpoint
939        mViewCellsManager->GetViewPoint(mViewPoint);
940        updateGL();
941        break;
[2543]942case Qt::Key_S: {
[1966]943        // set view poitn and direction
944        QString text;
945        bool ok;
946        text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
947        text = QInputDialog::getText(this,
[2543]948                "Enter a view point",
949                "",
950                QLineEdit::Normal,
951                text,
952                &ok);
[1966]953        if (!ok)
[2543]954                break;
955
[1967]956        if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
[2543]957                text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
958                text = QInputDialog::getText(this,
959                        "Enter a direction",
960                        "",
961                        QLineEdit::Normal,
962                        text,
963                        &ok);
964                if (!ok)
965                        break;
966                if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
967                        &mViewDirection.y, &mViewDirection.z) == 3) {
968                                updateGL();
969                        }
970                        break;
[1967]971        }
[2543]972                                }
973default:
[2604]974        cerr << "unknown key" << endl;
[1252]975        e->ignore();
976        break;
[2543]977        }
[1252]978}
979
980
[2543]981
[1942]982QtGlRendererWidget::QtGlRendererWidget(
983                                                                           SceneGraph *sceneGraph,
984                                                                           ViewCellsManager *viewcells,
985                                                                           KdTree *tree,
986                                                                           QWidget * parent,
987                                                                           const QGLWidget * shareWidget,
988                                                                           Qt::WFlags f
989                                                                           )
[2543]990                                                                           :
[2633]991GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(QGLFormat(QGL::SampleBuffers), parent, shareWidget, f)
[1252]992{
[2543]993        mPreprocessorThread = NULL;
994        mTopView = false;
995        mRenderViewCells = false;
996        mTopDistance = 1.0f;
997        mCutViewCells = false;
998        mCutScene = false;
999        mRenderErrors = false;
1000        mRenderBoxes = false;
1001        mRenderFilter = true;
1002        mRenderVisibilityEstimates = false;
[2633]1003        //mRenderVisibilityEstimates = true;
[2562]1004
[2643]1005        mComputeGVS = false;
[2604]1006        mUseRandomColorPerPvsObject = false;
[2686]1007        //mUseRandomColorPerPvsObject = true;
[2604]1008
[2562]1009        mHideByCost = false;
[2564]1010        mUseTransparency = false;
[2562]1011
[2569]1012        mTransferFunction = 1.0f;
[2543]1013        mIndexBufferSize = 0;
[1252]1014
[2562]1015        const int delay = 250; // in milliseconds
[2686]1016        mUpdateTimerId = startTimer(delay);
1017        mReplayTimerId = startTimer(1); // use fastest replay rate
[1252]1018
[2543]1019        bool tmp;
[1942]1020
[2543]1021        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
1022        mUseFilter = tmp;
[1252]1023
[2580]1024        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", tmp );
[2543]1025        mUseSpatialFilter = tmp;
[1252]1026
[2580]1027        //mLogWriter = new LogWriter("myfile.out");
1028
[2543]1029        mShowRenderCost = false;
1030        mShowPvsSizes = false;
[2580]1031        mShowComparison = false;
[2560]1032        mShowPiercingRays = false;
[2566]1033        mShowWeightedRays = false;
[2604]1034        mUseStandardColors = false;
1035        mShowWeightedCost = true;
[2566]1036
[2569]1037        mShowDistanceWeightedPvs = true;
1038        mShowDistanceWeightedTriangles = false;
1039        mShowWeightedTriangles = false;
[2591]1040        mShowDistribution = 15;
[2614]1041        mCurrentDynamicObjectIdx = -1;
[2569]1042
[2543]1043        mSpatialFilterSize = 0.01;
1044        mPvsSize = 0;
[2587]1045        mRayVisualizationMethod = 0;
[2614]1046        mTrafoType = 0;
1047
[2543]1048        mRenderError = 0.0f;
1049        mShowRays = false;
[1252]1050
[2686]1051        mReplayMode = false;
1052
[2643]1053        SetSceneCut(1000);
[2543]1054        mControlWidget = new QtRendererControlWidget(NULL);
[1942]1055
[2543]1056        connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
[2584]1057        connect(mControlWidget, SIGNAL(SetTransferFunction(int)), this, SLOT(SetTransferFunction(int)));
1058
[2543]1059        connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
1060        connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
1061        connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
[2584]1062        connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,     SLOT(SetRandomViewPoint()));
1063        connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void)));
[2643]1064        connect(mControlWidget, SIGNAL(ComputeGVS(void)), this, SLOT(ComputeGVS(void)));
[2686]1065        connect(mControlWidget, SIGNAL(ReplayViewPoints(void)), this, SLOT(ReplayViewPoints(void)));
[2609]1066        connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void)));
[2543]1067
1068        connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
1069        connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
[2563]1070        connect(mControlWidget, SIGNAL(SetTransparency(int)), this, SLOT(SetTransparency(int)));
[2543]1071
1072        connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
1073        connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
[2562]1074        connect(mControlWidget, SIGNAL(SetHidingCost(int)), this, SLOT(SetHidingCost(int)));
[2543]1075
1076        connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
1077        connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
[2564]1078        connect(mControlWidget, SIGNAL(SetUseTransparency(bool)), this, SLOT(SetUseTransparency(bool)));
[2543]1079        connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
[2580]1080        connect(mControlWidget, SIGNAL(SetShowComparison(bool)), this, SLOT(SetShowComparison(bool)));
[2543]1081        connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
1082        connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
[2562]1083        connect(mControlWidget, SIGNAL(SetHideByCost(bool)), this, SLOT(SetHideByCost(bool)));
[2543]1084        connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
1085        connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
1086        connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
1087        connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
[2566]1088        connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), this, SLOT(SetRenderVisibilityEstimates(bool)));
[2543]1089        connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
[2566]1090        connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), this, SLOT(SetUseSpatialFilter(bool)));
[2560]1091        connect(mControlWidget, SIGNAL(SetShowPiercingRays(bool)), this, SLOT(SetShowPiercingRays(bool)));
[2604]1092        connect(mControlWidget, SIGNAL(SetShowWireFrame(bool)), this, SLOT(SetShowWireFrame(bool)));
[2566]1093        connect(mControlWidget, SIGNAL(SetShowWeightedRays(bool)), this, SLOT(SetShowWeightedRays(bool)));
[2569]1094        connect(mControlWidget, SIGNAL(SetShowWeightedCost(bool)), this, SLOT(SetShowWeightedCost(bool)));
[2543]1095
[2569]1096        connect(mControlWidget, SIGNAL(SetShowDistanceWeightedTriangles(bool)), this, SLOT(SetShowDistanceWeightedTriangles(bool)));
1097        connect(mControlWidget, SIGNAL(SetShowDistanceWeightedPvs(bool)), this, SLOT(SetShowDistanceWeightedPvs(bool)));
1098        connect(mControlWidget, SIGNAL(SetShowWeightedTriangles(bool)), this, SLOT(SetShowWeightedTriangles(bool)));
1099
[2587]1100        connect(mControlWidget, SIGNAL(UseConstColorForRayViz(bool)), this, SLOT(UseConstColorForRayViz(bool)));
1101        connect(mControlWidget, SIGNAL(UseRayLengthForRayViz(bool)), this, SLOT(UseRayLengthForRayViz(bool)));
1102        connect(mControlWidget, SIGNAL(SetShowContribution(bool)), this, SLOT(SetShowContribution(bool)));
1103        connect(mControlWidget, SIGNAL(SetShowDistribution(bool)), this, SLOT(SetShowDistribution(bool)));
1104
[2591]1105        connect(mControlWidget, SIGNAL(SetShowDistribution1(bool)), this, SLOT(SetShowDistribution1(bool)));
1106        connect(mControlWidget, SIGNAL(SetShowDistribution2(bool)), this, SLOT(SetShowDistribution2(bool)));
1107        connect(mControlWidget, SIGNAL(SetShowDistribution3(bool)), this, SLOT(SetShowDistribution3(bool)));
1108        connect(mControlWidget, SIGNAL(SetShowDistribution4(bool)), this, SLOT(SetShowDistribution4(bool)));
[2587]1109
[2591]1110        connect(mControlWidget, SIGNAL(SetShowRays(bool)), this, SLOT(SetShowRays(bool)));
1111
[2614]1112        connect(mControlWidget, SIGNAL(SetTranslation(bool)), this, SLOT(SetTranslation(bool)));
1113        connect(mControlWidget, SIGNAL(SetRotation(bool)), this, SLOT(SetRotation(bool)));
1114        connect(mControlWidget, SIGNAL(SetScale(bool)), this, SLOT(SetScale(bool)));
[2636]1115
1116        connect(mControlWidget, SIGNAL(UpdateDynamicObjects()), this, SLOT(UpdateDynamicObjects()));
1117
[2615]1118        setWindowTitle("PVS Visualization");
1119
1120        // setting the main window size here
[2645]1121        resize(800, 600);
1122        //resize(640, 400);
[2615]1123       
[2543]1124        mControlWidget->show();
[1252]1125}
1126
[1942]1127void
1128QtGlRendererWidget::UpdateAllPvs()
1129{
[2543]1130        // $$ does not work so far:(
1131        mViewCellsManager->UpdatePvsForEvaluation();
1132        //      mViewCellsManager->FinalizeViewCells(false);
[1942]1133}
[1252]1134
1135void
[1942]1136QtGlRendererWidget::ComputeVisibility()
[1252]1137{
[2543]1138        cerr<<"Compute Visibility called!\n"<<endl;
1139        if (!mPreprocessorThread->isRunning())
1140                mPreprocessorThread->RunThread();
[1942]1141}
[1925]1142
[1942]1143void
1144QtGlRendererWidget::StopComputation()
1145{
[2543]1146        cerr<<"stop computation called!\n"<<endl;
1147        mViewCellsManager->GetPreprocessor()->mStopComputation = true;
[1942]1148}
[1252]1149
[1942]1150void
1151QtGlRendererWidget::SetRandomViewPoint()
1152{
[2584]1153        cerr<<"setting random view point!\n"<<endl;
[2543]1154        mViewCellsManager->GetViewPoint(mViewPoint);
1155        updateGL();
[1942]1156}
[1252]1157
[2584]1158
1159void QtGlRendererWidget::StoreStatistics()
1160{
1161        cerr<<"storing statistics!\n"<<endl;
1162        const int currentSamples = mViewCellsManager->GetPreprocessor()->mCurrentSamples;
1163
1164        cout<<"**********************************************" << endl;
1165        cout << "reached " << currentSamples << " samples " << " => writing file" << endl;
1166               
1167        LogWriter writer;
1168        writer.SetFilename("compare.log");
1169        writer.Write(currentSamples, mViewCellsManager->GetViewCells());
1170        cout << "finished writing file" << endl;
1171        mCompareInfo.clear();
1172        updateGL();
1173}
1174
[2609]1175
1176void QtGlRendererWidget::LoadObject()
1177{
[2645]1178        string filename("../data/teapot.bn");
1179        //string filename("../data/cube.obj");
[2609]1180       
1181        cout << "Loading model << " << filename << endl;
1182
[2614]1183        ++ mCurrentDynamicObjectIdx;
1184
[2636]1185        if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename)) {
1186         
1187          cout << "Loading finished" << endl;
1188        } else
1189          cerr << "Loading failed" << endl;
1190       
[2609]1191    updateGL();
1192}
1193
[1942]1194void
1195QtGlRendererWidget::RenderRenderCost()
1196{
[1252]1197        static vector<float> costFunction;
1198        static float maxCost = -1;
1199        if (costFunction.size()==0) {
[2543]1200                ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
1201                if (tree) {
1202                        tree->GetCostFunction(costFunction);
1203                        maxCost = -1;
1204                        for (int i=0;  i < costFunction.size(); i++) {
1205                                //                cout<<i<<":"<<costFunction[i]<<" ";
1206                                // update cost function to an absolute value based on the total geometry count
[2601]1207                                costFunction[i] *= mSceneGraph->GetSize();
[2543]1208                                if (costFunction[i] > maxCost)
1209                                        maxCost = costFunction[i];
1210                        }
[1252]1211                }
1212        }
1213
[2543]1214
[1252]1215        int currentPos = (int)mViewCellsManager->GetViewCells().size();
1216        float currentCost= -1;
1217
1218        if (currentPos < costFunction.size())
[2543]1219                currentCost = costFunction[currentPos];
[1942]1220#if 1   
[2538]1221        cout<<"costFunction.size()="<<(int)costFunction.size()<<endl;
[1252]1222        cout<<"CP="<<currentPos<<endl;
1223        cout<<"MC="<<maxCost<<endl;
1224        cout<<"CC="<<currentCost<<endl;
1225#endif
1226        if (costFunction.size()) {
[2543]1227                float scaley = 1.0f/log10(maxCost);
1228                float scalex = 1.0f/(float)costFunction.size();
[1942]1229
[2543]1230                glDisable(GL_DEPTH_TEST);
1231                // init ortographic projection
1232                glMatrixMode(GL_PROJECTION);
[1252]1233
[2543]1234                glPushMatrix();
1235
1236                glLoadIdentity();
1237                gluOrtho2D(0, 1.0f, 0, 1.0f);
1238
1239                glTranslatef(0.1f, 0.1f, 0.0f);
1240                glScalef(0.8f, 0.8f, 1.0f);
1241                glMatrixMode(GL_MODELVIEW);
1242                glLoadIdentity();
1243
1244                glColor3f(1.0f,0,0);
1245                glBegin(GL_LINE_STRIP);
1246                //        glVertex3f(0,0,0);
1247
1248                for (int i=0;  i < costFunction.size(); i++) {
1249                        float x =  i*scalex;
1250                        float y = log10(costFunction[i])*scaley;
1251                        glVertex3f(x,y,0.0f);
1252                }
1253                glEnd();
1254
1255                glColor3f(1.0f,0,0);
1256                glBegin(GL_LINES);
1257                float x =  currentPos*scalex;
[1252]1258                glVertex3f(x,0.0,0.0f);
1259                glVertex3f(x,1.0f,0.0f);
[2543]1260                glEnd();
[1252]1261
[2543]1262                glColor3f(0.0f,0,0);
1263                // show a grid
1264                glBegin(GL_LINE_LOOP);
1265                glVertex3f(0,0,0.0f);
1266                glVertex3f(1,0,0.0f);
1267                glVertex3f(1,1,0.0f);
1268                glVertex3f(0,1,0.0f);
1269                glEnd();
[1252]1270
[2543]1271                glBegin(GL_LINES);
1272                for (int i=0;  i < costFunction.size(); i += 1000) {
1273                        float x =  i*scalex;
1274                        glVertex3f(x,0.0,0.0f);
1275                        glVertex3f(x,1.0f,0.0f);
1276                }
[1252]1277
[2543]1278                for (int i=0;  pow(10.0f, i) < maxCost; i+=1) {
1279                        float y = i*scaley;
1280                        //              QString s;
1281                        //              s.sprintf("%d", (int)pow(10,i));
1282                        //              renderText(width()/2+5, y*height(), s);
1283                        glVertex3f(0.0f, y, 0.0f);
1284                        glVertex3f(1.0f, y, 0.0f);
1285                }
[1252]1286
[2543]1287                glEnd();
1288
1289
1290                // restore the projection matrix
1291                glMatrixMode(GL_PROJECTION);
1292                glPopMatrix();
1293                glMatrixMode(GL_MODELVIEW);
1294                glEnable(GL_DEPTH_TEST);
1295
[1252]1296        }
[1942]1297
1298
[2543]1299
[1252]1300}
1301
[1942]1302void
1303QtGlRendererWidget::RenderInfo()
1304{
[1983]1305
[2543]1306        QString s;
[2604]1307
[2543]1308        int vc = 0;
1309        if (mViewCellsManager)
1310                vc = (int)mViewCellsManager->GetViewCells().size();
[1252]1311
[2543]1312        int filter = 0;
1313        if (mViewCellsManager)
1314                filter = mViewCellsManager->GetMaxFilterSize();
[1942]1315
[2604]1316        glColor3f(0.0f, 0.0f, 1.0f);
[1942]1317
[2604]1318#if REMOVE_TEMPORARY
[2543]1319        s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
1320                mFrame,
1321                mViewPoint.x,
1322                mViewPoint.y,
1323                mViewPoint.z,
1324                mViewDirection.x,
1325                mViewDirection.y,
1326                mViewDirection.z
1327                );
[1942]1328
[2604]1329        renderText(20, 20, s);
[1942]1330
[2543]1331        s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %",
1332                vc,
1333                filter,
1334                mPvsSize,
1335                mRenderError*100.0f);
[1942]1336
[2604]1337        renderText(20, 40, s);
1338#endif
[2644]1339
[2604]1340        QFont font40; font40.setPointSize(30);
[2643]1341        //s.sprintf("PVS: %04d", mPvsSize);
1342        //renderText(20, 40, s, font40);
[2638]1343       
[2643]1344        //s.sprintf("RAW TRI: %07d", mViewCellsManager->GetPreprocessor()->mGenericStats);
1345        //renderText(290, 40, s, font40);
1346        //s.sprintf("PVS TRI: %07d", mViewCellsManager->GetPreprocessor()->mGenericStats2);
1347        //renderText(290, 70, s, font40);
1348
1349        s.sprintf("PVS TRI: %07d", (int)mCurrentPvsCost);
1350        renderText(290, 70, s, font40);
1351        //renderText(290, 70, s, font40);
1352
[1942]1353}
1354
1355
[1252]1356void
1357QtGlRendererWidget::SetViewCellGranularity(int number)
1358{
[2643]1359        if (mViewCellsManager)
1360        {
1361                //      mViewCellsManager->SetMaxFilterSize(number);
[1252]1362
[2543]1363                // $$ tmp off
1364                mViewCellsManager->CollectViewCells(number);
[1983]1365
[2543]1366                // $$ does not work so far:(
1367                //      mViewCellsManager->UpdatePvsForEvaluation();
1368                //      mViewCellsManager->FinalizeViewCells(false);
1369        }
1370        updateGL();
[1252]1371}
1372
1373void
1374QtGlRendererWidget::SetVisibilityFilterSize(int number)
1375{
[2543]1376        if (mViewCellsManager)
1377                mViewCellsManager->SetMaxFilterSize(number);
[2643]1378
[2543]1379        mPvsCache.Reset();
1380        updateGL();
[1252]1381}
1382
1383void
1384QtGlRendererWidget::SetSpatialFilterSize(int number)
1385{
[2543]1386        mSpatialFilterSize = 1e-3*number;
1387        mPvsCache.Reset();
1388        updateGL();
[1252]1389}
1390
1391void
1392QtGlRendererWidget::SetSceneCut(int number)
1393{
[2543]1394        // assume the cut plane can only be aligned with xz plane
1395        // shift it along y according to number, which is percentage of the bounding
1396        // box position
[2562]1397        if (mViewCellsManager)
1398        {
[2571]1399                const float f = number / 1000.0f;
[2543]1400                AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
[2571]1401                Vector3 p = (1.0f - f) * box.Min() + f * box.Max();
[2643]1402                mSceneCutPlane.mNormal = Vector3(0, -1, 0);
[2543]1403                mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
[2562]1404
[2543]1405                updateGL();
1406        }
[1252]1407}
1408
1409void
[2562]1410QtGlRendererWidget::SetHidingCost(int number)
1411{
1412        mHidingCost = (float)number / 1000.0f;
1413}
1414
1415
1416void
[1252]1417QtGlRendererWidget::SetTopDistance(int number)
1418{
[2569]1419        mTopDistance = number / 1000.0f;
[2543]1420        updateGL();
[1252]1421}
1422
[2569]1423void QtGlRendererWidget::SetTransparency(int number)
[2563]1424{
[2569]1425        mTransparency = number / 1000.0f;
[2563]1426        updateGL();
1427}
1428
[2570]1429#if 0
[2569]1430float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
1431{
1432        ObjectPvs basePvs;
1433       
1434        basePvs = vc->CopyPvs();
1435        ObjectPvsIterator pit = basePvs.GetIterator();
1436
1437        float renderCost = 0;
1438
1439        //cout << "cost vis: " << mShowDistanceWeightedPvs << " " << " " << mShowDistanceWeightedTriangles << " " << mShowWeightedTriangles << endl;
1440       
1441        // first mark all objects from this pvs
1442        while (pit.HasMoreEntries())   
1443        {
[2615]1444                KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
1445
[2569]1446                if (mShowDistanceWeightedPvs)
1447                {
1448                        const AxisAlignedBox3 box = kdObj->GetBox();
1449
1450                        const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
1451                        renderCost += 1.0f / dist;
1452                }
1453                else if (mShowDistanceWeightedTriangles)
1454                {
1455                        const AxisAlignedBox3 box = kdObj->GetBox();
1456
1457                        const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
1458                        renderCost += kdObj->ComputeNumTriangles() / dist;
1459                }
1460                else //if (mShowWeightedTriangles)
1461                {
1462                        renderCost += kdObj->ComputeNumTriangles();
1463                }
1464                //if (pit.Next()->Mail();
1465        }
1466
1467        return renderCost;
1468}
[2570]1469#else
[2569]1470
[2570]1471float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
1472{
1473        float renderCost = 0;
[2569]1474
[2633]1475#ifdef USE_VERBOSE_PVS
[2570]1476        if (mShowDistanceWeightedPvs)
1477        {
1478                return vc->GetPvs().mStats.mDistanceWeightedPvs;
1479        }
1480        else if (mShowDistanceWeightedTriangles)
1481        {
1482                return vc->GetPvs().mStats.mDistanceWeightedTriangles;
1483        }
1484        else //if (mShowWeightedTriangles)
1485        {
1486                return vc->GetPvs().mStats.mWeightedTriangles;
1487        }
[2617]1488#else
1489        return 0.0f;
1490#endif
[2570]1491}
1492#endif
1493
[1252]1494
[2049]1495
[2576]1496void QtGlRendererWidget::ComputeMaxValues(const ViewCellContainer &viewCells,
1497                                                                                  int &maxPvs,
1498                                                                                  int &maxPiercingRays,
1499                                                                                  float &maxRelativeRays,
1500                                                                                  float &maxRcCost)
1501{
1502        maxPvs = -1;
1503        maxPiercingRays = 1; // not zero for savety
1504        maxRelativeRays = Limits::Small; // not zero for savety
1505        maxRcCost = Limits::Small;
[1252]1506
[2576]1507        for (size_t i = 0; i < viewCells.size(); ++ i)
[2560]1508        {
[2576]1509                ViewCell *vc = viewCells[i];
[1252]1510
[2571]1511                if (mShowPvsSizes) // pvs size
[2569]1512                {
1513                        //const int p = vc->GetPvs().CountObjectsInPvs();
1514                        const int p = vc->GetPvs().GetSize();
1515                        if (p > maxPvs)
1516                                maxPvs = p;
1517                }
1518                else if (mShowPiercingRays) // relative number of rays
1519                {
1520                        const int piercingRays = vc->GetNumPiercingRays();
[2562]1521
[2569]1522                        if (piercingRays > maxPiercingRays)
1523                                maxPiercingRays = piercingRays;
1524                }
1525                else if (mShowWeightedRays)
1526                {
1527                        const int piercingRays = vc->GetNumPiercingRays();
[2566]1528
[2569]1529                        const float relativeArea =
1530                                vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
[2566]1531
[2569]1532                        if ((float)piercingRays / relativeArea > maxRelativeRays)
1533                                maxRelativeRays = (float)piercingRays / relativeArea;
1534                }
1535                else if (mShowWeightedCost)
1536                {
1537                        const float rcCost = ComputeRenderCost(vc);
1538                        mViewCellsManager->UpdateScalarPvsCost(vc, rcCost);
1539
1540                        if (rcCost > maxRcCost)
1541                                maxRcCost = rcCost;
1542                }
[2543]1543        }
[2576]1544}
[1252]1545
[2576]1546
1547void QtGlRendererWidget::RenderViewCells()
1548{
1549        mUseFalseColors = true;
1550        //glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
1551
1552        glEnable(GL_CULL_FACE);
1553        glCullFace(GL_FRONT);
1554        //glDisable(GL_CULL_FACE);
1555
1556        if (mCutViewCells)
1557        {
[2601]1558                double eq[4];
1559                eq[0] = mSceneCutPlane.mNormal.x;
1560                eq[1] = mSceneCutPlane.mNormal.y;
1561                eq[2] = mSceneCutPlane.mNormal.z;
1562                eq[3] = mSceneCutPlane.mD;
1563
[2576]1564                glClipPlane(GL_CLIP_PLANE0, eq);
1565                glEnable(GL_CLIP_PLANE0);
1566        }
1567
1568        ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
[2584]1569       
[2576]1570        int maxPvs, maxPiercingRays;
1571        float maxRelativeRays, maxRcCost;
1572
1573        ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
[2633]1574       
[2615]1575        // matt: temp hack
[2633]1576        //maxRcCost = 5000.0f;
[2615]1577        //cout << "maxRcCost: " << maxRcCost << endl;
[2633]1578
[2581]1579        int i;
[2576]1580
[2604]1581        // transparency
1582        if (!mUseTransparency)
1583        {
1584                glEnable(GL_DEPTH_TEST);
1585                glDisable(GL_BLEND);
1586        }
1587        else
1588        {
1589                glDisable(GL_DEPTH_TEST);
1590                glEnable(GL_BLEND);
1591
1592                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1593                //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1594
1595                for (i = 0; i < viewcells.size(); ++ i)
1596                {
1597                        ViewCell *vc = viewcells[i];
1598
1599                        const float dist = SqrDistance(mDummyViewPoint, vc->GetBox().Center());
1600                        vc->SetDistance(dist);
1601                }
1602
1603                sort(viewcells.begin(), viewcells.end(), nearerThan);
1604        }
1605
1606        //mWireFrame = true;
1607               
[2601]1608        // normal rendering
[2604]1609        //if (!mShowPvsSizes && !mShowPiercingRays && !mShowWeightedRays && !mShowWeightedCost && !mShowComparison)
1610        if (mUseStandardColors)
[2560]1611        {
[2562]1612                for (i = 0; i < viewcells.size(); ++ i)
1613                {
1614                        ViewCell *vc = viewcells[i];
1615                        RgbColor c;
[2543]1616
[2604]1617                        //if (!mShowPvsSizes && !mShowPiercingRays)
1618                        c = vc->GetColor();
1619                       
[2562]1620                        glColor3f(c.r, c.g, c.b);
1621
[2569]1622                        if (!mHideByCost || (mHidingCost < (vc->GetNumPiercingRays() / (float)maxPiercingRays)))
[2562]1623                        {
1624                RenderViewCell(vc);
1625                        }
1626                }
1627        }
[2601]1628        else // using specialised colors
[2562]1629        {
[2584]1630                if (!mShowComparison)
[2576]1631                        AssignImportanceByRelativeValue(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
1632                else
[2577]1633                {
[2584]1634                        if (mCompareInfo.empty())
1635                        {
1636                                LogReader reader;
1637                                reader.SetFilename("compare.log");
1638                                int samples;
1639                                reader.Read(samples, mCompareInfo);
1640                        }
[2580]1641
[2584]1642                        AssignColorByComparison(viewcells, mCompareInfo);
[2577]1643                }
[2566]1644
[2562]1645                glEnable(GL_DEPTH_TEST);       
[1252]1646        }
[2571]1647       
1648        glEnable(GL_CULL_FACE);
1649        glDisable(GL_CULL_FACE);
[1252]1650
[2571]1651        glDisable(GL_CLIP_PLANE0);
1652
[2543]1653        mUseFalseColors = false;
1654        mWireFrame = false;
[1942]1655
[2543]1656        glPopAttrib();
[1252]1657}
1658
1659
[2576]1660void QtGlRendererWidget::AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
1661                                                                                                                 int &maxPvs,
1662                                                                                                                 int &maxPiercingRays,
1663                                                                                                                 float &maxRelativeRays,
1664                                                                                                                 float &maxRcCost)
1665{
1666        for (size_t i = 0; i < viewCells.size(); ++ i)
1667        {
1668                RgbColor c;
1669                ViewCell *vc = viewCells[i];
[1252]1670
[2576]1671                float importance;
[1252]1672
[2576]1673                if (mShowPiercingRays)
1674                {
1675                        importance = mTransferFunction *
1676                                ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
1677                }
1678                else if (mShowWeightedRays) // relative number of rays
1679                {
1680                        float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
[1252]1681
[2576]1682                        if (relativeArea < Limits::Small)
1683                                relativeArea = Limits::Small;
1684
1685                        importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays;
1686                }
1687                else if (mShowPvsSizes) // pvs size
1688                {
1689                        importance = mTransferFunction *
1690                                ((float)vc->GetPvs().GetSize() / (float)maxPvs);
1691                } // weighted render cost
1692                else if (mShowWeightedCost)
1693                {
1694                        const float rcCost = mTransferFunction * ComputeRenderCost(vc);
1695                        importance = rcCost / maxRcCost;
1696                }
[2615]1697if (importance > 1.0f) importance = 1.0f;
[2576]1698                // c = RgbColor(importance, 1.0f - importance, 0.0f);
1699                c = RainbowColorMapping(importance);
1700
1701                glColor4f(c.r, c.g, c.b, 1.0f - mTransparency);
1702
1703                if (!mHideByCost || (mHidingCost < importance))
1704                {
1705                        RenderViewCell(vc);
1706                }
1707        }
[1252]1708}
1709
1710
[2576]1711void QtGlRendererWidget::AssignColorByComparison(const ViewCellContainer &viewcells,
[2580]1712                                                                                                 //const ViewCellInfoContainer &infos1,
1713                                                                                                 const ViewCellInfoContainer &compareInfo)
[1252]1714{
[2584]1715        if (viewcells.size() > compareInfo.size())
1716        {
[2663]1717                cerr << "loaded size (" << (int)compareInfo.size()
1718                         << ") does not fit to view cells size (" << (int)viewcells.size() << ")" << endl;
[2584]1719                return;
1720        }
[2576]1721
[2584]1722        //const float maxRatio = 1.0f;
1723        const float maxRatio = 2.0f;
1724        const float minRatio = 0.0f;
1725
[2576]1726        const float scale = 1.0f / (maxRatio - minRatio);
1727
1728        for (size_t i = 0; i < viewcells.size(); ++ i)
1729        {
1730                RgbColor c;
1731                ViewCell *vc = viewcells[i];
1732
[2580]1733                //ViewCellInfo vc1Info = infos1[i];
1734                ViewCellInfo vc2Info = compareInfo[i];
[2576]1735
[2584]1736                //const float vcRatio = vc->GetNumPiercingRays() / vc2Info.mPiercingRays + Limits::Small;
1737                float vcRatio = 1.0f;//maxRatio;
1738               
1739                if (vc2Info.mPvsSize > Limits::Small)
1740                        vcRatio = (float)vc->GetPvs().GetSize() / vc2Info.mPvsSize;
[2576]1741
[2584]1742                // truncate here
1743                if (vcRatio > maxRatio) vcRatio = 1.0f;
1744
[2576]1745                const float importance = (vcRatio - minRatio) * scale;
[2584]1746       
[2593]1747                if (0 && (i < 20))
[2584]1748                {
1749                        cout << "pvs1: " << vc->GetPvs().GetSize() << " pvs2: " << compareInfo[i].mPvsSize << " importance: " << importance << endl;
1750                }
[2576]1751
1752                // c = RgbColor(importance, 1.0f - importance, 0.0f);
1753                c = RainbowColorMapping(importance);
1754
1755                glColor4f(c.r, c.g, c.b, 1.0f);
1756
1757                if (1)//!mHideByCost || (mHidingCost < importance))
1758                {
1759                        RenderViewCell(vc);
1760                }
1761        }
[1252]1762}
1763
1764
[2576]1765
1766/**********************************************************************/
1767/*              QtRendererControlWidget implementation                */
1768/**********************************************************************/
1769
[2580]1770
[2569]1771QGroupBox *QtRendererControlWidget::CreateVisualizationPanel(QWidget *parent)
1772{
1773        QRadioButton *rb1, *rb2, *rb3, *rb4, *rb5;
1774       
[2604]1775        rb1 = new QRadioButton("random colors", parent);
[2614]1776        rb1->setText("random");
[2587]1777        connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWireFrame(bool)));
1778
[2569]1779        // Create a check box to be in the group box
[2587]1780        rb2 = new QRadioButton("piercing rays", parent);
1781        rb2->setText("piercing rays");
[2569]1782        //vl->addWidget(rb1);
[2587]1783        connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowPiercingRays(bool)));
[2569]1784
[2587]1785        rb3 = new QRadioButton("pvs size", parent);
1786        rb3->setText("pvs size");
1787        connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
[2569]1788       
1789        rb4 = new QRadioButton("weighted rays", parent);
1790        rb4->setText("weighted rays");
1791        connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedRays(bool)));
1792       
1793        rb5 = new QRadioButton("pvs cost", parent);
1794        rb5->setText("pvs cost");
1795        connect(rb5, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedCost(bool)));
1796
[2615]1797        QGroupBox *groupBox = new QGroupBox("PVS Visualization");
[2569]1798
1799        QVBoxLayout *vbox2 = new QVBoxLayout;
1800   
1801        vbox2->addWidget(rb1);
1802        vbox2->addWidget(rb2);
[2587]1803        vbox2->addWidget(rb3);
[2569]1804        vbox2->addWidget(rb4);
1805        vbox2->addWidget(rb5);
1806       
[2604]1807        rb5->setChecked(true);
[2569]1808
1809        vbox2->addStretch(1);
1810        groupBox->setLayout(vbox2);
1811
1812        return groupBox;
1813}
1814
1815
[2614]1816QGroupBox *QtRendererControlWidget::CreateTrafoPanel(QWidget *parent)
1817{
1818        QRadioButton *rb1, *rb2, *rb3;
1819       
1820        rb1 = new QRadioButton("translation", parent);
1821        rb1->setText("translation");
1822        connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetTranslation(bool)));
[2569]1823
[2614]1824        // Create a check box to be in the group box
1825        rb2 = new QRadioButton("scale", parent);
1826        rb2->setText("scale");
1827        //vl->addWidget(rb1);
1828        connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetScale(bool)));
1829
1830        rb3 = new QRadioButton("rotation", parent);
1831        rb3->setText("rotation");
1832        connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetRotation(bool)));
1833   
1834        QVBoxLayout *vbox2 = new QVBoxLayout;
1835        QGroupBox *groupBox = new QGroupBox("Trafo types");
1836
1837        vbox2->addWidget(rb1);
1838        vbox2->addWidget(rb2);
1839        vbox2->addWidget(rb3);
1840       
1841        rb1->setChecked(true);
1842
1843        vbox2->addStretch(1);
[2636]1844
1845
1846        QPushButton *button = new QPushButton("Update", groupBox);
1847        vbox2->addWidget(button);
1848        connect(button, SIGNAL(clicked()), SIGNAL(UpdateDynamicObjects()));
1849       
1850       
[2614]1851        groupBox->setLayout(vbox2);
[2636]1852       
[2614]1853        return groupBox;
1854}
1855
1856
[2569]1857QGroupBox *QtRendererControlWidget::CreateRenderCostPanel(QWidget *parent)
1858{
1859        QRadioButton *rb1, *rb2, *rb3;
1860       
1861        // Create a check box to be in the group box
1862        rb1 = new QRadioButton("triangles", parent);
1863        rb1->setText("triangles");
1864        connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedTriangles(bool)));
1865
1866        rb2 = new QRadioButton("distance weighted pvs", parent);
1867        rb2->setText("distance weighted");
1868        connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedPvs(bool)));
1869
1870        rb3 = new QRadioButton("distance weighted triangles", parent);
1871        rb3->setText("distance weighted triangles");
1872        connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedTriangles(bool)));
1873
1874        QGroupBox *groupBox = new QGroupBox("Render cost options");
1875        QVBoxLayout *vbox2 = new QVBoxLayout;
1876   
1877        vbox2->addWidget(rb1);
1878        vbox2->addWidget(rb2);
1879        vbox2->addWidget(rb3);
1880       
[2587]1881        rb1->setChecked(true);
[2569]1882
1883        vbox2->addStretch(1);
1884        groupBox->setLayout(vbox2);
1885
1886        return groupBox;
1887}
1888
[2576]1889
[2587]1890QGroupBox *QtRendererControlWidget::CreateRayVisualizationPanel(QWidget *parent)
1891{
1892        QRadioButton *rb1, *rb2, *rb3, *rb4;
1893       
1894        // Create a check box to be in the group box
1895        rb1 = new QRadioButton("const color", parent);
1896        rb1->setText("const color");
1897        //vl->addWidget(rb1);
1898        connect(rb1, SIGNAL(toggled(bool)), SIGNAL(UseConstColorForRayViz(bool)));
1899
1900        rb2 = new QRadioButton("ray length", parent);
1901        rb2->setText("ray length");
1902        connect(rb2, SIGNAL(toggled(bool)), SIGNAL(UseRayLengthForRayViz(bool)));
1903       
1904        rb3 = new QRadioButton("contribution", parent);
1905        rb3->setText("contribution");
1906        connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowContribution(bool)));
1907       
1908        rb4 = new QRadioButton("distribution", parent);
1909        rb4->setText("distribution");
1910        connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution(bool)));
1911
[2591]1912
1913        ///////////////////////////
1914
1915       
[2615]1916        QGroupBox *groupBox = new QGroupBox("Ray visualization");
[2587]1917        QVBoxLayout *vbox2 = new QVBoxLayout;
1918   
1919        vbox2->addWidget(rb1);
1920        vbox2->addWidget(rb2);
1921        vbox2->addWidget(rb3);
1922        vbox2->addWidget(rb4);
1923       
1924        rb1->setChecked(true);
1925
[2591]1926
1927        QCheckBox *cb = new QCheckBox("Distribution 1", parent);
1928        vbox2->addWidget(cb);
1929        cb->setChecked(true);
1930        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution1(bool)));
1931
1932        cb = new QCheckBox("Distribution 2", parent);
1933        vbox2->addWidget(cb);
1934        cb->setChecked(true);
1935        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution2(bool)));
1936
1937        cb = new QCheckBox("Distribution 3", parent);
1938        vbox2->addWidget(cb);
1939        cb->setChecked(true);
1940        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution3(bool)));
1941       
1942        cb = new QCheckBox("Distribution 4", parent);
1943        vbox2->addWidget(cb);
1944        cb->setChecked(true);
1945        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution4(bool)));
1946
1947
[2587]1948        vbox2->addStretch(1);
1949        groupBox->setLayout(vbox2);
1950
1951        return groupBox;
1952}
1953
1954
[1252]1955QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
[2543]1956QWidget(parent, f)
[1252]1957{
1958
[2543]1959        QVBoxLayout *vl = new QVBoxLayout;
1960        setLayout(vl);
[2615]1961       
1962        //QWidget *vbox;
[1252]1963
[2615]1964        //vbox = new QGroupBox("Render Controls", this);
1965        //layout()->addWidget(vbox);
1966        //vl = new QVBoxLayout;
1967        //vbox->setLayout(vl);
[1252]1968
[2604]1969        QLabel *label;
1970        QSlider *slider;
1971        QPushButton *button;
1972
[2645]1973#if 0//REMOVE_TEMPORARY
[2604]1974
1975        label = new QLabel("Granularity");
[2615]1976        //vbox->layout()->addWidget(label);
1977        vl->addWidget(label);
[1942]1978
[2644]1979        slider = new QSlider(Qt::Horizontal);
[2543]1980        vl->addWidget(slider);
1981        slider->show();
1982        slider->setRange(1, 10000);
1983        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1984        slider->setValue(200);
[1942]1985
[2543]1986        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
[1252]1987
[2563]1988        ///////////////////////////
1989
[2543]1990        label = new QLabel("Transfer function");
[2615]1991        vl->addWidget(label);
[1252]1992
[2644]1993        slider = new QSlider(Qt::Horizontal);
[2543]1994        vl->addWidget(slider);
1995        slider->show();
1996        slider->setRange(1, 10000);
1997        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1998        slider->setValue(100);
[1252]1999
2000
[2543]2001        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
[1252]2002
[2563]2003        ////////////////////////////////////////7
[1252]2004
[2644]2005        button = new QPushButton("Update all PVSs");
[2615]2006        vl->addWidget(button);
[2563]2007        connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
2008
2009        ////////////////////////////////////////77777
2010
[2543]2011        label = new QLabel("Filter size");
[2615]2012        vl->addWidget(label);
[1942]2013
[2644]2014        slider = new QSlider(Qt::Horizontal);
[2615]2015        vl->addWidget(slider);
[2543]2016        slider->show();
2017        slider->setRange(1, 100);
2018        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
2019        slider->setValue(3);
[1252]2020
[2543]2021        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
[1252]2022
[2604]2023#endif
[1252]2024
[2604]2025
[2615]2026       
[2563]2027        ///////////////////////////////////
[1252]2028
[2563]2029
[2644]2030        QWidget *hbox = new QWidget();
[2543]2031        vl->addWidget(hbox);
2032        QHBoxLayout *hlayout = new QHBoxLayout;
2033        hbox->setLayout(hlayout);
[1942]2034
[2543]2035        QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
2036        hlayout->addWidget(cb);
2037        cb->setChecked(false);
2038        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
[2615]2039       
2040        cb = new QCheckBox("Render errors", hbox);
2041        hlayout->layout()->addWidget(cb);
2042        cb->setChecked(false);
2043        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
[1942]2044
[2615]2045#if REMOVE_TEMPORARY
[2543]2046        cb = new QCheckBox("Render cost curve", hbox);
2047        hlayout->addWidget(cb);
2048        cb->setChecked(false);
2049        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
[2615]2050#endif
[2543]2051        cb = new QCheckBox("Show rays", hbox);
2052        hlayout->addWidget(cb);
2053        cb->setChecked(false);
2054        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
[2615]2055#if REMOVE_TEMPORARY   
[2580]2056        cb = new QCheckBox("Show Comparison", hbox);
2057        hlayout->addWidget(cb);
2058        cb->setChecked(false);
2059        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowComparison(bool)));
[2615]2060#endif
[1252]2061
[2569]2062        //////////////////
[2563]2063
[2569]2064        QHBoxLayout *vh = new QHBoxLayout;
[2564]2065
[2569]2066        QGroupBox *myBox = new QGroupBox("Visualization");
[2563]2067
[2569]2068        myBox->setLayout(vh);
2069        vl->addWidget(myBox, 0, 0);
[2566]2070
[2569]2071        QGroupBox *groupBox = CreateVisualizationPanel(hbox);
2072        vh->addWidget(groupBox, 0, 0);
[2643]2073
[2615]2074#if REMOVE_TEMPORARY
[2569]2075        QGroupBox *groupBox2 = CreateRenderCostPanel(hbox);
2076        vh->addWidget(groupBox2, 0, 0);
[2643]2077       
[2587]2078        QGroupBox *groupBox3 = CreateRayVisualizationPanel(hbox);
2079        vh->addWidget(groupBox3, 0, 0);
2080
[2614]2081        QGroupBox *groupBox4 = CreateTrafoPanel(hbox);
2082        vh->addWidget(groupBox4, 0, 0);
[2643]2083#endif
[2614]2084
[2563]2085        //////////////////////////////////
2086
[2644]2087        bool tmp = false;
2088        const int range = 1000;
[2563]2089
[2615]2090        //vbox->resize(800,150);
2091        QWidget *vbox;
[1252]2092
[2543]2093        vbox = new QGroupBox("Rendering", this);
2094        layout()->addWidget(vbox);
[1252]2095
[2543]2096        vl = new QVBoxLayout;
2097        vbox->setLayout(vl);
[1252]2098
2099
[2543]2100        cb = new QCheckBox("Cut view cells", vbox);
2101        vbox->layout()->addWidget(cb);
2102        cb->setChecked(false);
2103        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
[1252]2104
[1942]2105
[2543]2106        slider = new QSlider(Qt::Horizontal, vbox);
2107        vbox->layout()->addWidget(slider);
2108        slider->show();
2109        slider->setRange(0, 1000);
2110        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
2111        slider->setValue(1000);
[1942]2112
[2543]2113        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
[1252]2114
[2644]2115
2116        cb = new QCheckBox("Use spatial filter", vbox);
2117        vbox->layout()->addWidget(cb);
2118        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", tmp);
2119        cb->setChecked(tmp);
2120        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
2121
2122
2123        label = new QLabel("Spatial Filter size");
2124        vbox->layout()->addWidget(label);
[2563]2125       
[2644]2126        slider = new QSlider(Qt::Horizontal, vbox);
2127        vbox->layout()->addWidget(slider);
2128        slider->show();
2129        slider->setRange(1, 100);
2130        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
2131        slider->setValue(10);
2132
2133        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
2134
2135        ////////////////////////////
2136
2137       
[2563]2138        cb = new QCheckBox("Hide view cells by render cost ", vbox);
2139        vbox->layout()->addWidget(cb);
2140        cb->setChecked(false);
2141        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetHideByCost(bool)));
[1252]2142
[2563]2143        label = new QLabel("Hide by cost");
2144        vbox->layout()->addWidget(label);
2145
2146        // the render cost visualization
2147        slider = new QSlider(Qt::Horizontal, vbox);
2148        vbox->layout()->addWidget(slider);
2149        slider->show();
2150        slider->setRange(0, range);
2151        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
2152        slider->setValue(0);
2153        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetHidingCost(int)));
2154
2155        ///////////////////////////////////////////
2156
2157        cb = new QCheckBox("Top View", vbox);
2158        vbox->layout()->addWidget(cb);
2159        cb->setChecked(false);
2160        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
2161
2162
2163        label = new QLabel("Top distance");
2164        vbox->layout()->addWidget(label);
2165       
2166        slider = new QSlider(Qt::Horizontal, vbox);
2167        vbox->layout()->addWidget(slider);
2168        slider->show();
2169        slider->setRange(1, 1000);
2170        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
2171        slider->setValue(500);
2172
2173        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
2174       
2175
2176        ///////////////////////////////////////////
[2615]2177#if REMOVE_TEMPORARY
[2563]2178        cb = new QCheckBox("Transparency", vbox);
2179        vbox->layout()->addWidget(cb);
2180        cb->setChecked(false);
[2564]2181        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseTransparency(bool)));
[2563]2182
2183        label = new QLabel("Use transparency");
2184        vbox->layout()->addWidget(label);
2185
2186        // the render cost visualization
2187        slider = new QSlider(Qt::Horizontal, vbox);
2188        vbox->layout()->addWidget(slider);
2189        slider->show();
2190        slider->setRange(0, range);
2191        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
2192        slider->setValue(0);
[2644]2193        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransparency(int)));
[2615]2194#endif
[2644]2195       
[2563]2196
2197        //////////////////////////////
2198
[2604]2199#if REMOVE_TEMPORARY
[2644]2200
[2543]2201        cb = new QCheckBox("Cut scene", vbox);
2202        vbox->layout()->addWidget(cb);
2203        cb->setChecked(false);
2204        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
[2615]2205
[2543]2206        cb = new QCheckBox("Render boxes", vbox);
2207        vbox->layout()->addWidget(cb);
2208        cb->setChecked(false);
2209        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
[1942]2210
[2543]2211        cb = new QCheckBox("Render visibility estimates", vbox);
2212        vbox->layout()->addWidget(cb);
2213        cb->setChecked(false);
2214        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
[2615]2215#endif
[1942]2216
[2604]2217#if REMOVE_TEMPORARY
[2543]2218
2219        cb = new QCheckBox("Use filter", vbox);
2220        vbox->layout()->addWidget(cb);
[2644]2221        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp);
[2543]2222        cb->setChecked(tmp);
2223        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
[2604]2224#endif
[2543]2225
[2644]2226
2227       
2228
[2615]2229#if REMOVE_TEMPORARY
[2644]2230       
[2543]2231        cb = new QCheckBox("Render filter", vbox);
2232        vbox->layout()->addWidget(cb);
2233        cb->setChecked(true);
2234        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
2235
[2584]2236        /*vbox = new QGroupBox("PVS Errors", this);
[1942]2237        layout()->addWidget(vbox);
[2543]2238
[1942]2239        vl = new QVBoxLayout;
2240        vbox->setLayout(vl);
[2543]2241
[2563]2242        button = new QPushButton("Compute Visibility", vbox);
[2543]2243        vbox->layout()->addWidget(button);
2244        connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
2245
2246        button = new QPushButton("Stop Computation", vbox);
2247        vbox->layout()->addWidget(button);
2248        connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
2249
2250        button = new QPushButton("Set Random View Point", vbox);
2251        vbox->layout()->addWidget(button);
[2584]2252        connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));*/
[2543]2253
[2584]2254        button = new QPushButton("Store statistics", vbox);
2255        vbox->layout()->addWidget(button);
2256        connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics()));
[2644]2257
[2621]2258#endif
[2543]2259
[2686]2260#if 0
2261       
[2643]2262        button = new QPushButton("Compute GVS", vbox);
2263        vbox->layout()->addWidget(button);
2264        connect(button, SIGNAL(clicked()), SIGNAL(ComputeGVS()));
2265
[2686]2266#else
2267       
2268        button = new QPushButton("Replay view points", vbox);
2269        vbox->layout()->addWidget(button);
2270        connect(button, SIGNAL(clicked()), SIGNAL(ReplayViewPoints()));
2271
2272#endif
2273
[2621]2274#if DYNAMIC_OBJECTS_HACK
2275
[2609]2276        button = new QPushButton("Load object", vbox);
2277        vbox->layout()->addWidget(button);
2278        connect(button, SIGNAL(clicked()), SIGNAL(LoadObject()));
[2615]2279#endif
[2621]2280
[2584]2281        /*cb = new QCheckBox("Stats", vbox);
2282        vbox->layout()->addWidget(cb);
2283        cb->setChecked(false);
[2609]2284        connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));*/
[2614]2285
[2569]2286        if (0)
2287        {
[2543]2288                vbox = new QGroupBox("PVS Errors", this);
2289                layout()->addWidget(vbox);
2290
2291                vl = new QVBoxLayout;
2292                vbox->setLayout(vl);
2293
2294                mPvsErrorWidget = new QListWidget(vbox);
2295                vbox->layout()->addWidget(mPvsErrorWidget);
2296
2297                connect(mPvsErrorWidget,
[1942]2298                        SIGNAL(doubleClicked(const QModelIndex &)),
2299                        this,
2300                        SLOT(PvsErrorClicked(const QModelIndex &)));
[2543]2301
[2563]2302                button = new QPushButton("Next Error Frame", vbox);
[2543]2303                vbox->layout()->addWidget(button);
2304                connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
2305        }
[2562]2306       
[2584]2307        //connect(button, SIGNAL(clicked(void)), SLOT(StoreStatistics(void)));
[2643]2308       
2309        //////////////////////////////////////////
[2562]2310
[2615]2311
[2543]2312        setWindowTitle("Preprocessor Control Widget");
2313        adjustSize();
[1252]2314}
2315
2316
[1942]2317
2318
[1252]2319void
2320QtRendererControlWidget::FocusNextPvsErrorFrame(void)
[2576]2321{}
[2543]2322
[1252]2323void
2324QtRendererControlWidget::UpdatePvsErrorItem(int row,
[2543]2325                                                                                        GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
[1252]2326{
2327
[2543]2328        QListWidgetItem *i = mPvsErrorWidget->item(row);
2329        QString s;
2330        s.sprintf("%5.5f", pvsErrorEntry.mError);
2331        if (i) {
2332                i->setText(s);
2333        } else {
2334                new QListWidgetItem(s, mPvsErrorWidget);
2335        }
2336        mPvsErrorWidget->update();
[1252]2337}
2338
2339
[2576]2340
2341
2342/*********************************************************************/
2343/*                   QtGlDebuggerWidget implementation               */
2344/*********************************************************************/
2345
2346
2347QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
2348: QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
2349{
2350        // create the pbuffer
2351        //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
[2686]2352        //mUpdateTimerId = startTimer(20);
[2576]2353        setWindowTitle(("OpenGL pbuffers"));
2354}
2355
2356
2357QtGlDebuggerWidget::~QtGlDebuggerWidget()
2358{
2359        mRenderBuffer->releaseFromDynamicTexture();
2360        glDeleteTextures(1, &dynamicTexture);
2361
2362        DEL_PTR(mRenderBuffer);
2363}
2364
2365
[1252]2366void QtGlDebuggerWidget::initializeGL()
2367{
2368        glMatrixMode(GL_PROJECTION);
2369        glLoadIdentity();
2370
2371        glFrustum(-1, 1, -1, 1, 10, 100);
2372        glTranslatef(-0.5f, -0.5f, -0.5f);
2373        glTranslatef(0.0f, 0.0f, -15.0f);
2374        glMatrixMode(GL_MODELVIEW);
2375
2376        glEnable(GL_CULL_FACE);
2377        initCommon();
2378        initPbuffer();
2379
2380}
2381
2382
2383void QtGlDebuggerWidget::resizeGL(int w, int h)
2384{
2385        glViewport(0, 0, w, h);
2386}
2387
2388
2389void QtGlDebuggerWidget::paintGL()
2390{
2391        // draw a spinning cube into the pbuffer..
2392        mRenderBuffer->makeCurrent();
[2543]2393
[1252]2394        BeamSampleStatistics stats;
2395        mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
2396
2397        glFlush();
2398
2399        // rendering directly to a texture is not supported on X11, unfortunately
[2543]2400        mRenderBuffer->updateDynamicTexture(dynamicTexture);
[1252]2401
[2543]2402        // and use the pbuffer contents as a texture when rendering the
2403        // background and the bouncing cubes
2404        makeCurrent();
2405        glBindTexture(GL_TEXTURE_2D, dynamicTexture);
2406        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[1252]2407
[2543]2408        // draw the background
[1252]2409        glMatrixMode(GL_MODELVIEW);
[2543]2410        glPushMatrix();
2411        glLoadIdentity();
2412        glMatrixMode(GL_PROJECTION);
2413        glPushMatrix();
2414        glLoadIdentity();
2415
[1252]2416        glPopMatrix();
[2543]2417        glMatrixMode(GL_MODELVIEW);
2418        glPopMatrix();
[1252]2419}
2420
2421
2422void QtGlDebuggerWidget::initPbuffer()
2423{
2424        // set up the pbuffer context
[2543]2425        mRenderBuffer->makeCurrent();
[2664]2426       
[1252]2427        // generate a texture that has the same size/format as the pbuffer
[2543]2428        dynamicTexture = mRenderBuffer->generateDynamicTexture();
[1252]2429
2430        // bind the dynamic texture to the pbuffer - this is a no-op under X11
2431        mRenderBuffer->bindToDynamicTexture(dynamicTexture);
[2677]2432        //makeCurrent();
[1252]2433}
2434
[2576]2435
[1252]2436void QtGlDebuggerWidget::initCommon()
2437{
2438        glEnable(GL_TEXTURE_2D);
2439        glEnable(GL_DEPTH_TEST);
2440
2441        glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
2442}
2443
2444
[2609]2445void QtGlRendererWidget::_RenderColoredPvs()
2446{
2447        // note: could be done more efficiently using color buffers
2448        mPvsSize = mPvsCache.mPvs.GetSize();
2449
2450        ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
2451
2452        PvsData pvsData;
2453
2454        while (it.HasMoreEntries())
2455        {
[2686]2456                Intersectable *obj = it.Next(pvsData);
[2609]2457
2458                RgbColor color;
2459
2460                //cerr << "sumpdf: " << pvsData.mSumPdf << endl;
2461                if (mUseRandomColorPerPvsObject)
2462                {
[2686]2463                        KdIntersectable *kdint = static_cast<KdIntersectable *>(obj);
[2609]2464
2465                        if (kdint->mGenericIdx == -1)
2466                        {
2467                                kdint->mGenericIdx = (int)mColors.size();
[2686]2468                                mColors.push_back(RandomColor(0, 1));
[2609]2469                        }
2470                        color = mColors[kdint->mGenericIdx];
2471                }
2472                else
2473                {
2474                        color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1));
2475                }
2476
2477                glColor3f(color.r, color.g, color.b);
2478
2479                mUseForcedColors = true;
[2686]2480                RenderIntersectable(obj);
[2609]2481                mUseForcedColors = false;
2482        }
2483}
2484
[2686]2485
2486void QtGlRendererWidget::UpdateDynamicObjects()
[2636]2487{
[2686]2488        preprocessor->ScheduleUpdateDynamicObjects(); 
[2611]2489}
[2636]2490
[2686]2491
2492void QtGlRendererWidget::ReplayViewPoints()
2493{
2494        ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList();
2495
2496        ViewCellPointsList::const_iterator vit, vit_end = vcPoints->end();
2497
2498        sViewPointsList.clear();
2499
2500        for (vit = vcPoints->begin(); vit != vit_end; ++ vit)
2501        {
2502                ViewCellPoints *vp = *vit;
2503
2504                SimpleRayContainer::const_iterator rit, rit_end = vp->second.end();
2505       
2506                for (rit = vp->second.begin(); rit != rit_end; ++ rit)
2507                {
2508                        sViewPointsList.push_back(*rit);
2509                }
2510        }
2511
2512        if (!sViewPointsList.empty())
2513        {
2514                cout << "replaying " << (int)sViewPointsList.size() << " view points " << endl;
2515
2516                mReplayMode = true;
2517                sViewPointsListIt = sViewPointsList.begin();
2518        }
[2636]2519}
[2686]2520
2521}
Note: See TracBrowser for help on using the repository browser.