Ignore:
Timestamp:
05/18/08 00:30:13 (16 years ago)
Author:
mattausch
Message:

fixed several problems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp

    r2685 r2686  
    3030 
    3131#include <QVBoxLayout> 
    32 static GLint cubeArray[][3] = { 
    33     {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, 
    34     {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}, 
    35     {0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}, 
    36     {0, 1, 0}, {0, 1, 1}, {1, 1, 1}, {1, 1, 0}, 
    37     {0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}, 
    38     {1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1} 
    39 }; 
    40  
    41 static GLint cubeTextureArray[][2] = { 
    42     {0, 0}, {1, 0}, {1, 1}, {0, 1}, 
    43     {0, 0}, {0, 1}, {1, 1}, {1, 0}, 
    44     {0, 0}, {1, 0}, {1, 1}, {0, 1}, 
    45     {1, 0}, {0, 0}, {0, 1}, {1, 1}, 
    46     {0, 0}, {1, 0}, {1, 1}, {0, 1}, 
    47     {1, 0}, {0, 0}, {0, 1}, {1, 1} 
    48 }; 
    49  
    50 static GLint faceArray[][2] = { 
    51     {1, -1}, {1, 1}, {-1, 1}, {-1, -1} 
    52 }; 
    53  
    54 static GLubyte colorArray[][4] = { 
    55     {170, 202, 0, 255}, 
    56     {120, 143, 0, 255}, 
    57     {83, 102, 0, 255}, 
    58     {120, 143, 0, 255} 
    59 }; 
    60  
    61  
     32 
     33 
     34using namespace std; 
    6235 
    6336 
     
    7952 
    8053 
     54static SimpleRayContainer sViewPointsList; 
     55static SimpleRayContainer::const_iterator sViewPointsListIt; 
     56 
     57 
    8158 
    8259static inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
     
    9976} 
    10077#endif 
    101  
    102  
    103 void QtGlRendererBuffer::dummyBuffer() 
    104 {  
    105         //QGLPixelBuffer *dummy = new QGLPixelBuffer(QSize(256, 256), format(), this); 
    106      
    107         // set up the pbuffer context 
    108     makeCurrent(); 
    109      
    110         glEnableClientState(GL_VERTEX_ARRAY); 
    111     glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
    112     glVertexPointer(3, GL_INT, 0, cubeArray); 
    113     glTexCoordPointer(2, GL_INT, 0, cubeTextureArray); 
    114     glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorArray); 
    115  
    116     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    117     glEnable(GL_BLEND); 
    118     glEnable(GL_TEXTURE_2D); 
    119     glEnable(GL_DEPTH_TEST); 
    120  
    121     glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
    122  
    123     glViewport(0, 0, size().width(), size().height()); 
    124     glMatrixMode(GL_PROJECTION); 
    125     glLoadIdentity(); 
    126     glOrtho(-1, 1, -1, 1, -99, 99); 
    127     glTranslatef(-0.5f, -0.5f, 0.0f); 
    128     glMatrixMode(GL_MODELVIEW); 
    129     glLoadIdentity(); 
    130  
    131     
    132         glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 
    133  
    134         // draw cube background 
    135         glPushMatrix(); 
    136         glLoadIdentity(); 
    137         glTranslatef(0.5f, 0.5f, -2.0f); 
    138         glDisable(GL_TEXTURE_2D); 
    139         glEnableClientState(GL_COLOR_ARRAY); 
    140         glVertexPointer(2, GL_INT, 0, faceArray); 
    141         glDrawArrays(GL_QUADS, 0, 4); 
    142         glVertexPointer(3, GL_INT, 0, cubeArray); 
    143         glDisableClientState(GL_COLOR_ARRAY); 
    144         glEnable(GL_TEXTURE_2D); 
    145         glPopMatrix(); 
    146  
    147         // draw cube 
    148         glTranslatef(0.5f, 0.5f, 0.5f); 
    149         glRotatef(3.0f, 1.0f, 1.0f, 1.0f); 
    150         glTranslatef(-0.5f, -0.5f, -0.5f); 
    151         glColor4f(0.9f, 0.9f, 0.9f, 1.0f); 
    152         glDrawArrays(GL_QUADS, 0, 24); 
    153  
    154         QImage im = toImage(); 
    155         QString qstr("test.png"); 
    156  
    157         im.save(qstr, "PNG"); 
    158  
    159         doneCurrent(); 
    160 } 
    16178 
    16279 
     
    210127{ 
    211128        EnableDrawArrays(); 
     129         
     130        // prepare pvs for rendering 
    212131        PreparePvs(pvs); 
    213132 
     
    348267        pErrorPixels = (float)pixelCount / (GetWidth() * GetHeight()); 
    349268 
     269        const int pixelThres = 100000; 
     270 
    350271        // some error happened 
    351         if (pixelCount > 0)  
    352         { 
    353                 cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << endl; 
     272        if (pixelCount > pixelThres)  
     273        { 
     274                cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << " vp: " << mViewPoint << endl; 
    354275         
    355276                if (mSnapErrorFrames)  
     
    611532        { 
    612533                Intersectable *obj = it.Next(); 
     534 
    613535                switch (obj->Type()) 
    614536                { 
     
    620542                        break; 
    621543#if DYNAMIC_OBJECTS_HACK 
    622 #if USE_TRANSFORMED_MESH_INSTANCE_HACK 
    623  
    624                 case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    625                         mDynamicObjects.push_back(static_cast<TransformedMeshInstance *>(obj)); 
    626                         break; 
    627  
    628 #else 
     544 
    629545                case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE: 
    630546                        mDynamicObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem()); 
    631547                        break; 
    632 #endif 
    633548#endif 
    634549                default: 
     
    660575        if (viewcell)  
    661576        { 
    662 #if 0 
     577#if 1 
    663578                // copy the pvs so that it can be filtered ... 
    664579                if (PvsChanged(viewcell))  
     
    689604                        PreparePvs(mPvsCache.mPvs); 
    690605                        emit PvsUpdated(); 
     606 
    691607                        mCurrentPvsCost = mPvsCache.mPvs.EvalPvsCost(); 
    692608                } 
    693609#else 
    694610         
     611                // update the indices for rendering 
    695612                PreparePvs(viewcell->GetPvs()); 
    696613                emit PvsUpdated(); 
     
    721638                        mWireFrame = false; 
    722639                } 
    723                 mCurrentPvsCost = viewcell->GetPvs().EvalPvsCost(); 
     640                 
     641                //mCurrentPvsCost = viewcell->GetPvs().EvalPvsCost(); 
    724642        }  
    725643        else  
     
    797715 
    798716 
    799 void QtGlRendererWidget::timerEvent(QTimerEvent *event)  
    800 { 
    801         //std::cout << "Timer ID:" << event->timerId(); 
    802         update(); 
     717void QtGlRendererWidget::timerEvent(QTimerEvent *timerEvent)  
     718{ 
     719        if (mReplayMode && (timerEvent->timerId() == mReplayTimerId)) 
     720        { 
     721                if (sViewPointsListIt == sViewPointsList.end()) 
     722                { 
     723                        cout << "stopping replay" << endl; 
     724                        mReplayMode = false; 
     725                } 
     726                else 
     727                { 
     728                        SimpleRay sray = *sViewPointsListIt; 
     729 
     730                        mViewPoint = sray.mOrigin; 
     731                        mViewDirection = sray.mDirection; 
     732 
     733                        ++ sViewPointsListIt; 
     734                } 
     735 
     736 
     737                updateGL(); 
     738        } 
     739 
     740        if (timerEvent->timerId() == mUpdateTimerId) 
     741                update(); 
    803742} 
    804743 
     
    826765QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e) 
    827766{ 
     767        if (mReplayMode) 
     768                return; 
     769 
    828770        float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 
    829771        float TURN_SENSITIVITY = 0.1f; 
     
    838780 
    839781        const float t = 1.0f; 
    840  
    841782        if (e->modifiers() & Qt::ControlModifier)  
    842783        { 
     
    10791020        mComputeGVS = false; 
    10801021        mUseRandomColorPerPvsObject = false; 
     1022        //mUseRandomColorPerPvsObject = true; 
    10811023 
    10821024        mHideByCost = false; 
     
    10871029 
    10881030        const int delay = 250; // in milliseconds 
    1089         timerId = startTimer(delay); 
     1031        mUpdateTimerId = startTimer(delay); 
     1032        mReplayTimerId = startTimer(1); // use fastest replay rate 
    10901033 
    10911034        bool tmp; 
     
    11211064        mShowRays = false; 
    11221065 
     1066        mReplayMode = false; 
     1067 
    11231068        SetSceneCut(1000); 
    11241069        mControlWidget = new QtRendererControlWidget(NULL); 
     
    11331078        connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void))); 
    11341079        connect(mControlWidget, SIGNAL(ComputeGVS(void)), this, SLOT(ComputeGVS(void))); 
     1080        connect(mControlWidget, SIGNAL(ReplayViewPoints(void)), this, SLOT(ReplayViewPoints(void))); 
    11351081        connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void))); 
    11361082 
     
    23032249        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool))); 
    23042250 
    2305  
    23062251        /*vbox = new QGroupBox("PVS Errors", this); 
    23072252        layout()->addWidget(vbox); 
     
    23282273#endif 
    23292274 
     2275#if 0 
     2276         
    23302277        button = new QPushButton("Compute GVS", vbox); 
    23312278        vbox->layout()->addWidget(button); 
    23322279        connect(button, SIGNAL(clicked()), SIGNAL(ComputeGVS())); 
     2280 
     2281#else 
     2282         
     2283        button = new QPushButton("Replay view points", vbox); 
     2284        vbox->layout()->addWidget(button); 
     2285        connect(button, SIGNAL(clicked()), SIGNAL(ReplayViewPoints())); 
     2286 
     2287#endif 
    23332288 
    23342289#if DYNAMIC_OBJECTS_HACK 
     
    24102365        // create the pbuffer 
    24112366        //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this); 
    2412         timerId = startTimer(20); 
     2367        //mUpdateTimerId = startTimer(20); 
    24132368        setWindowTitle(("OpenGL pbuffers")); 
    24142369} 
     
    25142469        while (it.HasMoreEntries()) 
    25152470        { 
    2516                 Intersectable *object = it.Next(pvsData); 
     2471                Intersectable *obj = it.Next(pvsData); 
    25172472 
    25182473                RgbColor color; 
    25192474 
    2520                 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 
    2521                 // glColor3f(visibility, 0.0f, 0.0f); 
    25222475                //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 
    25232476                if (mUseRandomColorPerPvsObject) 
    25242477                { 
    2525                         KdIntersectable *kdint = static_cast<KdIntersectable *>(object); 
     2478                        KdIntersectable *kdint = static_cast<KdIntersectable *>(obj); 
    25262479 
    25272480                        if (kdint->mGenericIdx == -1) 
    25282481                        { 
    25292482                                kdint->mGenericIdx = (int)mColors.size(); 
    2530                                 mColors.push_back(RandomColor()); 
     2483                                mColors.push_back(RandomColor(0, 1)); 
    25312484                        } 
    25322485                        color = mColors[kdint->mGenericIdx]; 
     
    25402493 
    25412494                mUseForcedColors = true; 
    2542                 RenderIntersectable(object); 
     2495                RenderIntersectable(obj); 
    25432496                mUseForcedColors = false; 
    25442497        } 
    25452498} 
    25462499 
    2547 void 
    2548 QtGlRendererWidget::UpdateDynamicObjects() 
    2549 { 
    2550   preprocessor->ScheduleUpdateDynamicObjects(); 
    2551    
    2552 } 
    2553  
    2554 } 
     2500 
     2501void QtGlRendererWidget::UpdateDynamicObjects() 
     2502{ 
     2503        preprocessor->ScheduleUpdateDynamicObjects();   
     2504} 
     2505 
     2506 
     2507void QtGlRendererWidget::ReplayViewPoints() 
     2508{ 
     2509        ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList(); 
     2510 
     2511        ViewCellPointsList::const_iterator vit, vit_end = vcPoints->end(); 
     2512 
     2513        sViewPointsList.clear(); 
     2514 
     2515        for (vit = vcPoints->begin(); vit != vit_end; ++ vit)  
     2516        { 
     2517                ViewCellPoints *vp = *vit; 
     2518 
     2519                SimpleRayContainer::const_iterator rit, rit_end = vp->second.end(); 
     2520         
     2521                for (rit = vp->second.begin(); rit != rit_end; ++ rit) 
     2522                { 
     2523                        sViewPointsList.push_back(*rit); 
     2524                } 
     2525        } 
     2526 
     2527        if (!sViewPointsList.empty()) 
     2528        { 
     2529                cout << "replaying " << (int)sViewPointsList.size() << " view points " << endl; 
     2530 
     2531                mReplayMode = true; 
     2532                sViewPointsListIt = sViewPointsList.begin(); 
     2533        } 
     2534} 
     2535 
     2536} 
Note: See TracChangeset for help on using the changeset viewer.