#include "glInterface.h" #include "QtGlRenderer.h" #include "Mesh.h" #include "OcclusionQuery.h" #include "ViewCellsManager.h" #include "SceneGraph.h" #include "Pvs.h" #include "Viewcell.h" #include "Beam.h" #include "KdTree.h" #include "Environment.h" #include "RssPreprocessor.h" #include "RssTree.h" #include "Trackball.h" #include "QtPreprocessorThread.h" #include "Material.h" #include "IntersectableWrapper.h" #include "LogWriter.h" #define USE_CG 1 #if USE_CG #include #include #endif #include namespace GtpVisibilityPreprocessor { class ViewCellsManager; static CGcontext sCgContext = NULL; static CGprogram sCgFragmentProgram = NULL; static CGprofile sCgFragmentProfile; //static vector sQueries; QtGlRendererWidget *rendererWidget = NULL; QtGlDebuggerWidget *debuggerWidget = NULL; const static int SAMPLES_INCR = 2000000; static inline bool ilt(Intersectable *obj1, Intersectable *obj2) { return obj1->mId < obj2->mId; } inline static bool nearerThan(ViewCell *vc1, ViewCell *vc2) { return vc1->GetDistance() > vc2->GetDistance(); } #if USE_CG static void handleCgError() { Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl; exit(1); } #endif void QtGlRendererBuffer::MakeCurrent() { makeCurrent(); } void QtGlRendererBuffer::DoneCurrent() { doneCurrent(); } QtGlRendererBuffer::QtGlRendererBuffer(const int w, const int h, SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree): QGLPixelBuffer(QSize(w, h)), //QGLWidget(NULL, w, h), GlRendererBuffer(sceneGraph, viewcells, tree) { MakeCurrent(); InitGL(); DoneCurrent(); } // reimplemented here so that we can snap the error windows float QtGlRendererBuffer::GetPixelError(int &pvsSize) { float pErrorPixels = -1.0f; mUseFalseColors = false; unsigned int pixelCount; ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint); // cout<<"View cell"<GetPvs(); else mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs); SetupCamera(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); glStencilFunc(GL_EQUAL, 0x0, 0x1); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); // Render PVS ObjectPvsIterator it = pvs.GetIterator(); pvsSize = pvs.GetSize(); Intersectable::NewMail(); while (it.HasMoreEntries()) { RenderIntersectable(it.Next()); } //glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glEnable(GL_STENCIL_TEST); mUseFalseColors = true; OcclusionQuery *query = mOcclusionQueries[0]; query->BeginQuery(); SetupCamera(); RenderScene(); query->EndQuery(); glDisable(GL_STENCIL_TEST); // reenable other state // int wait=0; // while (!query.ResultAvailable()) { // wait++; // } pixelCount = query->GetQueryResult(); pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); if (mSnapErrorFrames && pErrorPixels >= 0.01f) { glReadBuffer(GL_BACK); char filename[256]; sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels); QImage im = toImage(); string str = mSnapPrefix + filename; QString qstr(str.c_str()); im.save(qstr, "PNG"); if (1) { //0 && mFrame == 1543) { int x,y; int lastIndex = -1; for (y=0; y < im.height(); y++) for (x=0; x < im.width(); x++) { QRgb p = im.pixel(x,y); int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16); if (qGreen(p) != 255 && index!=0) { if (index != lastIndex) { // Debug<<"ei="<GetId() == id) && !obj->Mailed()) { obj = *oit; obj->Mail(); ++ pvsSize; pvs.push_back(obj); } } } return pvsSize; } void QtGlRendererWidget::InitGL() { GlRenderer::InitGL(); GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; /* mat_specular and mat_shininess are NOT default values */ GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 }; GLfloat mat_shininess[] = { 1.0 }; GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 }; GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 }; GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; // default Material glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); // a light glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); // set position of the light GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 }; glLightfv (GL_LIGHT0, GL_POSITION, infinite_light); // set position of the light2 GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 }; glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_FLAT); } void QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle) { if (!mTopView) { int ww = w; int hh = h; glViewport(0, 0, ww, hh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(angle, ww/(float)hh, 0.1, 2.0 * Magnitude(mSceneGraph->GetBox().Diagonal())); glMatrixMode(GL_MODELVIEW); } else { int ww = w; int hh = h; glViewport(0, 0, ww, hh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50.0, ww / (float)hh, 0.1, 20.0 * Magnitude(mSceneGraph->GetBox().Diagonal())); glMatrixMode(GL_MODELVIEW); } } bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const { if (viewCell != mPvsCache.mViewCell) return true; if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize) return true; return false; } void QtGlRendererWidget::_RenderPvs() { mUseFalseColors = false; int offset = (int)mObjects.size() * 3; char *arrayPtr = mUseVbos ? NULL : (char *)mData; glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr); glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); } void QtGlRendererWidget::_UpdatePvsIndices() { int indexBufferSize = 0; KdNode::NewMail(); //Intersectable::NewMail(); mPvsSize = mPvsCache.mPvs.GetSize(); ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); while (it.HasMoreEntries()) { Intersectable *obj = it.Next(); KdNode *node = static_cast(obj)->GetItem(); _UpdatePvsIndices(node, indexBufferSize); } mIndexBufferSize = indexBufferSize; } void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node, int &indexBufferSize) { if (node->Mailed()) return; node->Mail(); // if (mObjects.size() * 3 < indexBufferSize) cerr << "problem: " << mObjects.size() * 3 << " < " << indexBufferSize << endl; if (!node->IsLeaf()) { KdInterior *kdInterior = static_cast(node); _UpdatePvsIndices(kdInterior->mBack, indexBufferSize); _UpdatePvsIndices(kdInterior->mFront, indexBufferSize); } else { KdLeaf *leaf = static_cast(node); leaf->mIndexBufferStart = indexBufferSize; for (size_t i = 0; i < leaf->mObjects.size(); ++ i) { TriangleIntersectable *obj = static_cast(leaf->mObjects[i]); // check if already rendered /*if (!obj->Mailed()) { obj->Mail(); mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; indexBufferSize += 3; }*/ if (obj->mRenderedFrame != mCurrentFrame) { obj->mRenderedFrame = mCurrentFrame; mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; indexBufferSize += 3; } } leaf->mIndexBufferSize = indexBufferSize - leaf->mIndexBufferStart; } //cout << "id: " << indexBufferSize << endl; } void QtGlRendererWidget::RenderPvs() { if (mUseVbos) glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); ++ mCurrentFrame; EnableDrawArrays(); //Intersectable::NewMail(); if (mDetectEmptyViewSpace) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); ViewCell *viewcell = NULL; viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); if (viewcell) { // copy the pvs so that it can be filtered ... if (PvsChanged(viewcell)) { mPvsCache.Reset(); mPvsCache.mViewCell = viewcell; mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize(); if (mUseSpatialFilter) { //ObjectPvs pvs; //mMutex.lock(); // mSpatialFilter size is in range 0.001 - 0.1 mViewCellsManager->ApplyFilter2(viewcell, mUseFilter, 100.0f * mSpatialFilterSize, //pvs, mPvsCache.mPvs, &mPvsCache.filteredBoxes); //mPvsCache.mPvs = pvs; //mMutex.unlock(); } else { mPvsCache.mPvs = viewcell->GetPvs(); } /// update the indices for rendering _UpdatePvsIndices(); emit PvsUpdated(); } //Intersectable::NewMail(); PvsData pvsData; // Render PVS if (mUseSpatialFilter && mRenderBoxes) { for (int i=0; i < mPvsCache.filteredBoxes.size(); ++ i) { RenderBox(mPvsCache.filteredBoxes[i]); } } else { if (!mRenderVisibilityEstimates) { _RenderPvs(); } else { mPvsSize = mPvsCache.mPvs.GetSize(); ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); while (it.HasMoreEntries()) { Intersectable *object = it.Next(pvsData); //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f // glColor3f(visibility, 0.0f, 0.0f); //cerr << "sumpdf: " << pvsData.mSumPdf << endl; RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1)); glColor3f(color.r, color.g, color.b); mUseForcedColors = true; RenderIntersectable(object); mUseForcedColors = false; } } } if (mRenderFilter) { mWireFrame = true; RenderIntersectable(viewcell); /*glPushMatrix(); glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); glScalef(5.0f,5.0f,5.0f); glPushAttrib(GL_CURRENT_BIT); glColor3f(1.0f, 0.0f, 0.0f); // gluSphere((::GLUquadric *)mSphere, // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); glPopAttrib(); glPopMatrix(); */ mWireFrame = false; } } else { /*ObjectContainer::const_iterator oi = mObjects.begin(); for (; oi != mObjects.end(); oi++) RenderIntersectable(*oi);*/ RenderScene(); } //DisableDrawArrays(); //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); } float QtGlRendererWidget::RenderErrors() { float pErrorPixels = -1.0f; SetupCamera(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushAttrib(GL_ENABLE_BIT); glStencilFunc(GL_EQUAL, 0x0, 0x1); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); mUseForcedColors = true; glColor3f(0.0f, 0.8f, 0.2f); // Render PVS RenderPvs(); glEnable(GL_STENCIL_TEST); //mUseFalseColors = true; glDisable(GL_LIGHTING); OcclusionQuery *query = mOcclusionQueries[0]; query->BeginQuery(); SetupCamera(); glColor3f(1.0f, 0.0f, 0.0f); RenderScene(); mUseForcedColors = false; query->EndQuery(); glDisable(GL_STENCIL_TEST); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glPopAttrib(); // reenable other state // int wait=0; // while (!query.ResultAvailable()) { // wait++; // } int pixelCount = query->GetQueryResult(); pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); if (0) cout<<"error pixels="<timerId(); update(); } void QtGlRendererWidget::mousePressEvent(QMouseEvent *e) { int x = e->pos().x(); int y = e->pos().y(); mousePoint.x = x; mousePoint.y = y; } void QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e) { float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; float TURN_SENSITIVITY=0.1f; float TILT_SENSITIVITY=32.0 ; float TURN_ANGLE= M_PI/36.0 ; int x = e->pos().x(); int y = e->pos().y(); int diffx = -(mousePoint.x - x); int diffy = -(mousePoint.y - y); if (e->modifiers() & Qt::ControlModifier) { mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; } else { mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; float angle = atan2(mViewDirection.x, mViewDirection.z); mViewDirection.x = sin(angle + adiff); mViewDirection.z = cos(angle + adiff); } mousePoint.x = x; mousePoint.y = y; updateGL(); } void QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *) { } void QtGlRendererWidget::resizeGL(int w, int h) { SetupCameraProjection(w, h); updateGL(); } void QtGlRendererWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (1) { SetupCameraProjection(width(), height()); SetupCamera(); if (mRenderErrors) { RenderErrors(); } else { glColor3f(0.6f, 0.6f, 0.6f); RenderPvs(); } if (1 && mShowRays) { RenderRays(mViewCellsManager->mVizBuffer.GetRays()); } } RenderInfo(); mFrame ++; } void QtGlRendererWidget::SetupCamera() { if (!mTopView) GlRenderer::SetupCamera(); else { if (0) { float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, -1, mViewDirection.y); Vector3 target = mViewPoint + dist*mViewDirection; Vector3 up(0,1,0); glLoadIdentity(); gluLookAt(pos.x, pos.y, pos.z, target.x, target.y, target.z, up.x, up.y, up.z); } else { float dist = Magnitude(mSceneGraph->GetBox().Diagonal()) * mTopDistance; Vector3 pos = mViewPoint + dist*Vector3(0, 1, 0); Vector3 target = mViewPoint; Vector3 up(mViewDirection.x, 0, mViewDirection.z); glLoadIdentity(); gluLookAt(pos.x, pos.y, pos.z, target.x, target.y, target.z, up.x, up.y, up.z); } } } void QtGlRendererWidget::keyPressEvent ( QKeyEvent * e ) { switch (e->key()) { case Qt::Key_T: mTopView = !mTopView; SetupCameraProjection(width(), height()); updateGL(); break; case Qt::Key_V: mRenderViewCells = !mRenderViewCells; updateGL(); break; case Qt::Key_P: // set random viewpoint mViewCellsManager->GetViewPoint(mViewPoint); updateGL(); break; case Qt::Key_S: { // set view poitn and direction QString text; bool ok; text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z); text = QInputDialog::getText(this, "Enter a view point", "", QLineEdit::Normal, text, &ok); if (!ok) break; if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) { text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z); text = QInputDialog::getText(this, "Enter a direction", "", QLineEdit::Normal, text, &ok); if (!ok) break; if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x, &mViewDirection.y, &mViewDirection.z) == 3) { updateGL(); } break; } } default: e->ignore(); break; } } QtGlRendererWidget::QtGlRendererWidget( SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree, QWidget * parent, const QGLWidget * shareWidget, Qt::WFlags f ) : GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f) { mPreprocessorThread = NULL; mTopView = false; mRenderViewCells = false; mTopDistance = 1.0f; mCutViewCells = false; mCutScene = false; mRenderErrors = false; mRenderBoxes = false; mRenderFilter = true; mRenderVisibilityEstimates = false; mHideByCost = false; mUseTransparency = false; mTransferFunction = 1.0f; mIndexBufferSize = 0; //mCurrentFrame = 0; const int delay = 250; // in milliseconds timerId = startTimer(delay); bool tmp; Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); mUseFilter = tmp; Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", tmp ); mUseSpatialFilter = tmp; //mLogWriter = new LogWriter("myfile.out"); mShowRenderCost = false; mShowPvsSizes = false; mShowComparison = false; mShowPiercingRays = false; mShowWeightedRays = false; mShowWeightedCost = false; mShowDistanceWeightedPvs = true; mShowDistanceWeightedTriangles = false; mShowWeightedTriangles = false; mSpatialFilterSize = 0.01; mPvsSize = 0; mRenderError = 0.0f; mShowRays = false; mControlWidget = new QtRendererControlWidget(NULL); connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); connect(mControlWidget, SIGNAL(SetTransferFunction(int)), this, SLOT(SetTransferFunction(int))); connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs())); connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility())); connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation())); connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this, SLOT(SetRandomViewPoint())); connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void))); connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); connect(mControlWidget, SIGNAL(SetTransparency(int)), this, SLOT(SetTransparency(int))); connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int))); connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int))); connect(mControlWidget, SIGNAL(SetHidingCost(int)), this, SLOT(SetHidingCost(int))); connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool))); connect(mControlWidget, SIGNAL(SetUseTransparency(bool)), this, SLOT(SetUseTransparency(bool))); connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool))); connect(mControlWidget, SIGNAL(SetShowComparison(bool)), this, SLOT(SetShowComparison(bool))); connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); connect(mControlWidget, SIGNAL(SetHideByCost(bool)), this, SLOT(SetHideByCost(bool))); connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool))); connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool))); connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool))); connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), this, SLOT(SetRenderVisibilityEstimates(bool))); connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool))); connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), this, SLOT(SetUseSpatialFilter(bool))); connect(mControlWidget, SIGNAL(SetShowPiercingRays(bool)), this, SLOT(SetShowPiercingRays(bool))); connect(mControlWidget, SIGNAL(SetShowWeightedRays(bool)), this, SLOT(SetShowWeightedRays(bool))); connect(mControlWidget, SIGNAL(SetShowWeightedCost(bool)), this, SLOT(SetShowWeightedCost(bool))); connect(mControlWidget, SIGNAL(SetShowDistanceWeightedTriangles(bool)), this, SLOT(SetShowDistanceWeightedTriangles(bool))); connect(mControlWidget, SIGNAL(SetShowDistanceWeightedPvs(bool)), this, SLOT(SetShowDistanceWeightedPvs(bool))); connect(mControlWidget, SIGNAL(SetShowWeightedTriangles(bool)), this, SLOT(SetShowWeightedTriangles(bool))); connect(mControlWidget, SIGNAL(SetShowRays(bool)), this, SLOT(SetShowRays(bool))); resize(1000, 500); mControlWidget->show(); } void QtGlRendererWidget::UpdateAllPvs() { // $$ does not work so far:( mViewCellsManager->UpdatePvsForEvaluation(); // mViewCellsManager->FinalizeViewCells(false); } void QtGlRendererWidget::ComputeVisibility() { cerr<<"Compute Visibility called!\n"<isRunning()) mPreprocessorThread->RunThread(); } void QtGlRendererWidget::StopComputation() { cerr<<"stop computation called!\n"<GetPreprocessor()->mStopComputation = true; } void QtGlRendererWidget::SetRandomViewPoint() { cerr<<"setting random view point!\n"<GetViewPoint(mViewPoint); updateGL(); } void QtGlRendererWidget::StoreStatistics() { cerr<<"storing statistics!\n"<GetPreprocessor()->mCurrentSamples; cout<<"**********************************************" << endl; cout << "reached " << currentSamples << " samples " << " => writing file" << endl; LogWriter writer; writer.SetFilename("compare.log"); writer.Write(currentSamples, mViewCellsManager->GetViewCells()); cout << "finished writing file" << endl; mCompareInfo.clear(); updateGL(); } void QtGlRendererWidget::RenderRenderCost() { static vector costFunction; static float maxCost = -1; if (costFunction.size()==0) { ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree(); if (tree) { tree->GetCostFunction(costFunction); maxCost = -1; for (int i=0; i < costFunction.size(); i++) { // cout<GetRoot()->mGeometry.size(); if (costFunction[i] > maxCost) maxCost = costFunction[i]; } } } int currentPos = (int)mViewCellsManager->GetViewCells().size(); float currentCost= -1; if (currentPos < costFunction.size()) currentCost = costFunction[currentPos]; #if 1 cout<<"costFunction.size()="<<(int)costFunction.size()<GetViewCells().size(); int filter = 0; if (mViewCellsManager) filter = mViewCellsManager->GetMaxFilterSize(); glColor3f(1.0f,1.0f,1.0f); s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)", mFrame, mViewPoint.x, mViewPoint.y, mViewPoint.z, mViewDirection.x, mViewDirection.y, mViewDirection.z ); renderText(20,20,s); s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %", vc, filter, mPvsSize, mRenderError*100.0f); renderText(20,40,s); } void QtGlRendererWidget::SetViewCellGranularity(int number) { if (mViewCellsManager) { // mViewCellsManager->SetMaxFilterSize(number); // $$ tmp off mViewCellsManager->CollectViewCells(number); // $$ does not work so far:( // mViewCellsManager->UpdatePvsForEvaluation(); // mViewCellsManager->FinalizeViewCells(false); } updateGL(); } void QtGlRendererWidget::SetVisibilityFilterSize(int number) { if (mViewCellsManager) mViewCellsManager->SetMaxFilterSize(number); mPvsCache.Reset(); updateGL(); } void QtGlRendererWidget::SetSpatialFilterSize(int number) { mSpatialFilterSize = 1e-3*number; mPvsCache.Reset(); updateGL(); } void QtGlRendererWidget::SetSceneCut(int number) { // assume the cut plane can only be aligned with xz plane // shift it along y according to number, which is percentage of the bounding // box position if (mViewCellsManager) { const float f = number / 1000.0f; AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); Vector3 p = (1.0f - f) * box.Min() + f * box.Max(); mSceneCutPlane.mNormal = Vector3(0,-1,0); mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p); updateGL(); } } void QtGlRendererWidget::SetHidingCost(int number) { mHidingCost = (float)number / 1000.0f; } void QtGlRendererWidget::SetTopDistance(int number) { mTopDistance = number / 1000.0f; updateGL(); } void QtGlRendererWidget::SetTransparency(int number) { mTransparency = number / 1000.0f; updateGL(); } #if 0 float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc) { ObjectPvs basePvs; basePvs = vc->CopyPvs(); ObjectPvsIterator pit = basePvs.GetIterator(); float renderCost = 0; //cout << "cost vis: " << mShowDistanceWeightedPvs << " " << " " << mShowDistanceWeightedTriangles << " " << mShowWeightedTriangles << endl; // first mark all objects from this pvs while (pit.HasMoreEntries()) { if (mShowDistanceWeightedPvs) { KdIntersectable *kdObj = static_cast(pit.Next()); const AxisAlignedBox3 box = kdObj->GetBox(); const float dist = SqrDistance(vc->GetBox().Center(), box.Center()); renderCost += 1.0f / dist; } else if (mShowDistanceWeightedTriangles) { KdIntersectable *kdObj = static_cast(pit.Next()); const AxisAlignedBox3 box = kdObj->GetBox(); const float dist = SqrDistance(vc->GetBox().Center(), box.Center()); renderCost += kdObj->ComputeNumTriangles() / dist; } else //if (mShowWeightedTriangles) { KdIntersectable *kdObj = static_cast(pit.Next()); renderCost += kdObj->ComputeNumTriangles(); } //if (pit.Next()->Mail(); } return renderCost; } #else float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc) { float renderCost = 0; if (mShowDistanceWeightedPvs) { return vc->GetPvs().mStats.mDistanceWeightedPvs; } else if (mShowDistanceWeightedTriangles) { return vc->GetPvs().mStats.mDistanceWeightedTriangles; } else //if (mShowWeightedTriangles) { return vc->GetPvs().mStats.mWeightedTriangles; } } #endif void QtGlRendererWidget::ComputeMaxValues(const ViewCellContainer &viewCells, int &maxPvs, int &maxPiercingRays, float &maxRelativeRays, float &maxRcCost) { maxPvs = -1; maxPiercingRays = 1; // not zero for savety maxRelativeRays = Limits::Small; // not zero for savety maxRcCost = Limits::Small; for (size_t i = 0; i < viewCells.size(); ++ i) { ViewCell *vc = viewCells[i]; if (mShowPvsSizes) // pvs size { //const int p = vc->GetPvs().CountObjectsInPvs(); const int p = vc->GetPvs().GetSize(); if (p > maxPvs) maxPvs = p; } else if (mShowPiercingRays) // relative number of rays { const int piercingRays = vc->GetNumPiercingRays(); if (piercingRays > maxPiercingRays) maxPiercingRays = piercingRays; } else if (mShowWeightedRays) { const int piercingRays = vc->GetNumPiercingRays(); const float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); if ((float)piercingRays / relativeArea > maxRelativeRays) maxRelativeRays = (float)piercingRays / relativeArea; } else if (mShowWeightedCost) { const float rcCost = ComputeRenderCost(vc); mViewCellsManager->UpdateScalarPvsCost(vc, rcCost); if (rcCost > maxRcCost) maxRcCost = rcCost; } } } void QtGlRendererWidget::RenderViewCells() { mUseFalseColors = true; //glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); //glDisable(GL_CULL_FACE); double eq[4]; eq[0] = mSceneCutPlane.mNormal.x; eq[1] = mSceneCutPlane.mNormal.y; eq[2] = mSceneCutPlane.mNormal.z; eq[3] = mSceneCutPlane.mD; if (mCutViewCells) { glClipPlane(GL_CLIP_PLANE0, eq); glEnable(GL_CLIP_PLANE0); } ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); int maxPvs, maxPiercingRays; float maxRelativeRays, maxRcCost; ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost); int i; if (!mShowPvsSizes && !mShowPiercingRays && !mShowWeightedRays && !mShowWeightedCost) { for (i = 0; i < viewcells.size(); ++ i) { ViewCell *vc = viewcells[i]; RgbColor c; if (!mShowPvsSizes && !mShowPiercingRays) { mWireFrame = true; c = vc->GetColor(); } glColor3f(c.r, c.g, c.b); if (!mHideByCost || (mHidingCost < (vc->GetNumPiercingRays() / (float)maxPiercingRays))) { RenderViewCell(vc); } } } else { // transparency if (!mUseTransparency) { glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); } else { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc(GL_SRC_ALPHA, GL_ONE); for (i = 0; i < viewcells.size(); ++ i) { ViewCell *vc = viewcells[i]; const float dist = SqrDistance(mDummyViewPoint, vc->GetBox().Center()); vc->SetDistance(dist); } sort(viewcells.begin(), viewcells.end(), nearerThan); } if (!mShowComparison) AssignImportanceByRelativeValue(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost); else { if (mCompareInfo.empty()) { LogReader reader; reader.SetFilename("compare.log"); int samples; reader.Read(samples, mCompareInfo); } AssignColorByComparison(viewcells, mCompareInfo); } glEnable(GL_DEPTH_TEST); } glEnable(GL_CULL_FACE); glDisable(GL_CULL_FACE); glDisable(GL_CLIP_PLANE0); mUseFalseColors = false; mWireFrame = false; glPopAttrib(); } void QtGlRendererWidget::AssignImportanceByRelativeValue(const ViewCellContainer &viewCells, int &maxPvs, int &maxPiercingRays, float &maxRelativeRays, float &maxRcCost) { for (size_t i = 0; i < viewCells.size(); ++ i) { RgbColor c; ViewCell *vc = viewCells[i]; float importance; if (mShowPiercingRays) { importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays); } else if (mShowWeightedRays) // relative number of rays { float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); if (relativeArea < Limits::Small) relativeArea = Limits::Small; importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays; } else if (mShowPvsSizes) // pvs size { importance = mTransferFunction * ((float)vc->GetPvs().GetSize() / (float)maxPvs); } // weighted render cost else if (mShowWeightedCost) { const float rcCost = mTransferFunction * ComputeRenderCost(vc); importance = rcCost / maxRcCost; } // c = RgbColor(importance, 1.0f - importance, 0.0f); c = RainbowColorMapping(importance); glColor4f(c.r, c.g, c.b, 1.0f - mTransparency); if (!mHideByCost || (mHidingCost < importance)) { RenderViewCell(vc); } } } void QtGlRendererWidget::AssignColorByComparison(const ViewCellContainer &viewcells, //const ViewCellInfoContainer &infos1, const ViewCellInfoContainer &compareInfo) { //cout << "comparing " << viewcells.size() << " view cells to " << compareInfo.size() << " values" << endl; if (viewcells.size() > compareInfo.size()) { cerr << "loaded size (" << compareInfo.size() << ") does not fit to view cells size (" << viewcells.size() << ")" << endl; return; } //const float maxRatio = 1.0f; const float maxRatio = 2.0f; const float minRatio = 0.0f; const float scale = 1.0f / (maxRatio - minRatio); for (size_t i = 0; i < viewcells.size(); ++ i) { RgbColor c; ViewCell *vc = viewcells[i]; //ViewCellInfo vc1Info = infos1[i]; ViewCellInfo vc2Info = compareInfo[i]; //const float vcRatio = vc->GetNumPiercingRays() / vc2Info.mPiercingRays + Limits::Small; float vcRatio = 1.0f;//maxRatio; if (vc2Info.mPvsSize > Limits::Small) vcRatio = (float)vc->GetPvs().GetSize() / vc2Info.mPvsSize; // truncate here if (vcRatio > maxRatio) vcRatio = 1.0f; const float importance = (vcRatio - minRatio) * scale; if (i < 20) { cout << "pvs1: " << vc->GetPvs().GetSize() << " pvs2: " << compareInfo[i].mPvsSize << " importance: " << importance << endl; } // c = RgbColor(importance, 1.0f - importance, 0.0f); c = RainbowColorMapping(importance); glColor4f(c.r, c.g, c.b, 1.0f); if (1)//!mHideByCost || (mHidingCost < importance)) { RenderViewCell(vc); } } } /**********************************************************************/ /* QtRendererControlWidget implementation */ /**********************************************************************/ QGroupBox *QtRendererControlWidget::CreateVisualizationPanel(QWidget *parent) { QRadioButton *rb1, *rb2, *rb3, *rb4, *rb5; // Create a check box to be in the group box rb1 = new QRadioButton("piercing rays", parent); rb1->setText("piercing rays"); //vl->addWidget(rb1); connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowPiercingRays(bool))); rb2 = new QRadioButton("pvs size", parent); rb2->setText("pvs size"); connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); rb3 = new QRadioButton("wireframe", parent); rb3->setText("wireframe"); rb4 = new QRadioButton("weighted rays", parent); rb4->setText("weighted rays"); connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedRays(bool))); rb5 = new QRadioButton("pvs cost", parent); rb5->setText("pvs cost"); connect(rb5, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedCost(bool))); QGroupBox *groupBox = new QGroupBox("Visualization options"); QVBoxLayout *vbox2 = new QVBoxLayout; vbox2->addWidget(rb3); vbox2->addWidget(rb1); vbox2->addWidget(rb2); vbox2->addWidget(rb4); vbox2->addWidget(rb5); rb3->setChecked(true); vbox2->addStretch(1); groupBox->setLayout(vbox2); return groupBox; } QGroupBox *QtRendererControlWidget::CreateRenderCostPanel(QWidget *parent) { QRadioButton *rb1, *rb2, *rb3; // Create a check box to be in the group box rb1 = new QRadioButton("triangles", parent); rb1->setText("triangles"); //vl->addWidget(rb1); connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedTriangles(bool))); rb2 = new QRadioButton("distance weighted pvs", parent); rb2->setText("distance weighted"); connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedPvs(bool))); rb3 = new QRadioButton("distance weighted triangles", parent); rb3->setText("distance weighted triangles"); connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedTriangles(bool))); QGroupBox *groupBox = new QGroupBox("Render cost options"); QVBoxLayout *vbox2 = new QVBoxLayout; vbox2->addWidget(rb1); vbox2->addWidget(rb2); vbox2->addWidget(rb3); rb2->setChecked(true); vbox2->addStretch(1); groupBox->setLayout(vbox2); return groupBox; } QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f): QWidget(parent, f) { QVBoxLayout *vl = new QVBoxLayout; setLayout(vl); QWidget *vbox = new QGroupBox("ViewCells", this); layout()->addWidget(vbox); vl = new QVBoxLayout; vbox->setLayout(vl); QLabel *label = new QLabel("Granularity"); vbox->layout()->addWidget(label); QSlider *slider = new QSlider(Qt::Horizontal, vbox); vl->addWidget(slider); slider->show(); slider->setRange(1, 10000); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(200); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); /////////////////////////// label = new QLabel("Transfer function"); vbox->layout()->addWidget(label); slider = new QSlider(Qt::Horizontal, vbox); vl->addWidget(slider); slider->show(); slider->setRange(1, 10000); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(100); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int))); ////////////////////////////////////////7 QPushButton *button = new QPushButton("Update all PVSs", vbox); vbox->layout()->addWidget(button); connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs())); ////////////////////////////////////////77777 label = new QLabel("Filter size"); vbox->layout()->addWidget(label); slider = new QSlider(Qt::Horizontal, vbox); vbox->layout()->addWidget(slider); slider->show(); slider->setRange(1, 100); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(3); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int))); ////////////////////////////////////////// label = new QLabel("Spatial Filter size"); vbox->layout()->addWidget(label); slider = new QSlider(Qt::Horizontal, vbox); vbox->layout()->addWidget(slider); slider->show(); slider->setRange(1, 100); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(10); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int))); /////////////////////////////////// QWidget *hbox = new QWidget(vbox); vl->addWidget(hbox); QHBoxLayout *hlayout = new QHBoxLayout; hbox->setLayout(hlayout); QCheckBox *cb = new QCheckBox("Show viewcells", hbox); hlayout->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); cb = new QCheckBox("Render cost curve", hbox); hlayout->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool))); cb = new QCheckBox("Show rays", hbox); hlayout->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool))); cb = new QCheckBox("Show Comparison", hbox); hlayout->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowComparison(bool))); ////////////////// QHBoxLayout *vh = new QHBoxLayout; QGroupBox *myBox = new QGroupBox("Visualization"); myBox->setLayout(vh); vl->addWidget(myBox, 0, 0); QGroupBox *groupBox = CreateVisualizationPanel(hbox); vh->addWidget(groupBox, 0, 0); QGroupBox *groupBox2 = CreateRenderCostPanel(hbox); vh->addWidget(groupBox2, 0, 0); ////////////////////////////////// /*cb = new QRadiobox("Top View", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); */ vbox->resize(800,150); vbox = new QGroupBox("Rendering", this); layout()->addWidget(vbox); vl = new QVBoxLayout; vbox->setLayout(vl); cb = new QCheckBox("Cut view cells", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); slider = new QSlider(Qt::Horizontal, vbox); vbox->layout()->addWidget(slider); slider->show(); slider->setRange(0, 1000); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(1000); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); cb = new QCheckBox("Hide view cells by render cost ", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetHideByCost(bool))); //////////////////////////// const int range = 1000; label = new QLabel("Hide by cost"); vbox->layout()->addWidget(label); // the render cost visualization slider = new QSlider(Qt::Horizontal, vbox); vbox->layout()->addWidget(slider); slider->show(); slider->setRange(0, range); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(0); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetHidingCost(int))); /////////////////////////////////////////// cb = new QCheckBox("Top View", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); label = new QLabel("Top distance"); vbox->layout()->addWidget(label); slider = new QSlider(Qt::Horizontal, vbox); vbox->layout()->addWidget(slider); slider->show(); slider->setRange(1, 1000); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(500); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); /////////////////////////////////////////// cb = new QCheckBox("Transparency", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseTransparency(bool))); label = new QLabel("Use transparency"); vbox->layout()->addWidget(label); // the render cost visualization slider = new QSlider(Qt::Horizontal, vbox); vbox->layout()->addWidget(slider); slider->show(); slider->setRange(0, range); slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); slider->setValue(0); connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransparency(int))); ////////////////////////////// cb = new QCheckBox("Cut scene", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); cb = new QCheckBox("Render boxes", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool))); cb = new QCheckBox("Render visibility estimates", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool))); cb = new QCheckBox("Render errors", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); bool tmp; cb = new QCheckBox("Use filter", vbox); vbox->layout()->addWidget(cb); Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp ); cb->setChecked(tmp); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool))); cb = new QCheckBox("Use spatial filter", vbox); vbox->layout()->addWidget(cb); Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", tmp ); cb->setChecked(tmp); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool))); cb = new QCheckBox("Render filter", vbox); vbox->layout()->addWidget(cb); cb->setChecked(true); connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool))); /*vbox = new QGroupBox("PVS Errors", this); layout()->addWidget(vbox); vl = new QVBoxLayout; vbox->setLayout(vl); button = new QPushButton("Compute Visibility", vbox); vbox->layout()->addWidget(button); connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility())); button = new QPushButton("Stop Computation", vbox); vbox->layout()->addWidget(button); connect(button, SIGNAL(clicked()), SLOT(StopComputation())); button = new QPushButton("Set Random View Point", vbox); vbox->layout()->addWidget(button); connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));*/ button = new QPushButton("Store statistics", vbox); vbox->layout()->addWidget(button); connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics())); /*cb = new QCheckBox("Stats", vbox); vbox->layout()->addWidget(cb); cb->setChecked(false); connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics())); */ if (0) { vbox = new QGroupBox("PVS Errors", this); layout()->addWidget(vbox); vl = new QVBoxLayout; vbox->setLayout(vl); mPvsErrorWidget = new QListWidget(vbox); vbox->layout()->addWidget(mPvsErrorWidget); connect(mPvsErrorWidget, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(PvsErrorClicked(const QModelIndex &))); button = new QPushButton("Next Error Frame", vbox); vbox->layout()->addWidget(button); connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void))); } //connect(button, SIGNAL(clicked(void)), SLOT(StoreStatistics(void))); //mHidingCost = 0.1f; setWindowTitle("Preprocessor Control Widget"); adjustSize(); } void QtRendererControlWidget::FocusNextPvsErrorFrame(void) {} void QtRendererControlWidget::UpdatePvsErrorItem(int row, GlRendererBuffer::PvsErrorEntry &pvsErrorEntry) { QListWidgetItem *i = mPvsErrorWidget->item(row); QString s; s.sprintf("%5.5f", pvsErrorEntry.mError); if (i) { i->setText(s); } else { new QListWidgetItem(s, mPvsErrorWidget); } mPvsErrorWidget->update(); } /*********************************************************************/ /* QtGlDebuggerWidget implementation */ /*********************************************************************/ QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf) { // create the pbuffer //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this); timerId = startTimer(20); setWindowTitle(("OpenGL pbuffers")); } QtGlDebuggerWidget::~QtGlDebuggerWidget() { mRenderBuffer->releaseFromDynamicTexture(); glDeleteTextures(1, &dynamicTexture); DEL_PTR(mRenderBuffer); } void QtGlDebuggerWidget::initializeGL() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1, 1, -1, 1, 10, 100); glTranslatef(-0.5f, -0.5f, -0.5f); glTranslatef(0.0f, 0.0f, -15.0f); glMatrixMode(GL_MODELVIEW); glEnable(GL_CULL_FACE); initCommon(); initPbuffer(); } void QtGlDebuggerWidget::resizeGL(int w, int h) { glViewport(0, 0, w, h); } void QtGlDebuggerWidget::paintGL() { // draw a spinning cube into the pbuffer.. mRenderBuffer->makeCurrent(); BeamSampleStatistics stats; mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats); glFlush(); // rendering directly to a texture is not supported on X11, unfortunately mRenderBuffer->updateDynamicTexture(dynamicTexture); // and use the pbuffer contents as a texture when rendering the // background and the bouncing cubes makeCurrent(); glBindTexture(GL_TEXTURE_2D, dynamicTexture); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // draw the background glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void QtGlDebuggerWidget::initPbuffer() { // set up the pbuffer context mRenderBuffer->makeCurrent(); /*mRenderBuffer->InitGL(); glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -99, 99); glTranslatef(-0.5f, -0.5f, 0.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/ // generate a texture that has the same size/format as the pbuffer dynamicTexture = mRenderBuffer->generateDynamicTexture(); // bind the dynamic texture to the pbuffer - this is a no-op under X11 mRenderBuffer->bindToDynamicTexture(dynamicTexture); makeCurrent(); } void QtGlDebuggerWidget::initCommon() { glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); } }