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

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