#ifndef __QTGLRENDERER_H #define __QTGLRENDERER_H #include #include #include #include "Vector3.h" #include "Containers.h" #include "Halton.h" #include "Renderer.h" #include "GlRenderer.h" #include "Beam.h" #include "QtPreprocessorThread.h" #include "LogReader.h" #include "Material.h" #include "common.h" class QWidget; #define REMOVE_TEMPORARY 1 namespace GtpVisibilityPreprocessor { class SceneGraph; class ViewCellsManager; class Mesh; class MeshInstance; class Intersectable; class Material; class Beam; class KdTree; class GlRendererBuffer; class BeamSampleStatistics; class OcclusionQuery; class TransformedMeshInstance; class ObjectPlacer; struct VssRayContainer; struct PvsRenderStatistics; struct RenderCostSample; //class LogWriter; class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer { Q_OBJECT public: QtGlRendererBuffer(int w, int h, SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree); ~QtGlRendererBuffer() {} virtual void MakeLive(); virtual void DoneLive(); virtual int GetWidth() const { return width(); } virtual int GetHeight() const { return height(); } int ComputePvs() const { return 0; } void RenderPvs(const ObjectPvs &pvs); float GetPixelError(int &pvsSize); int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const; /** quick hack in order to be able to render gvs pvs. */ void RenderTrianglePvs(); public: signals: void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); }; class QtRendererControlWidget : public QWidget { Q_OBJECT public: QListWidget *mPvsErrorWidget; QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0); QGroupBox *CreateVisualizationPanel(QWidget *parent); QGroupBox *CreateTrafoPanel(QWidget *parent); public slots: void FocusNextPvsErrorFrame(); void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); QGroupBox *CreateRenderCostPanel(QWidget *parent); QGroupBox *CreateRayVisualizationPanel(QWidget *parent); signals: void ReplayViewPoints(); void UpdateDynamicObjects(); void ComputeVisibility(); void StopComputation(); void SetRandomViewPoint(); void StoreStatistics(); void ComputeGVS(); void LoadObject(); void UpdateAllPvs(); void SetViewCellGranularity(int); void SetTransferFunction(int); void SetSceneCut(int); void SetTopDistance(int); void SetHidingCost(int); void SetVisibilityFilterSize(int); void SetSpatialFilterSize(int); void SetTransparency(int); void SetShowRays(bool); void SetRenderFilter(bool); void SetRenderVisibilityEstimates(bool); void SetUseFilter(bool); void SetUseSpatialFilter(bool); void SetRenderErrors(bool); void SetRenderBoxes(bool); void SetShowViewCells(bool); void SetShowRenderCost(bool); void SetShowPvsSizes(bool); void SetShowWireFrame(bool); void SetShowPiercingRays(bool); void SetShowWeightedRays(bool); void SetShowComparison(bool); void SetShowWeightedCost(bool); void SetTopView(bool); void SetCutViewCells(bool); void SetCutScene(bool); void SetHideByCost(bool); void SetUseTransparency(bool); void SetShowDistanceWeightedTriangles(bool); void SetShowWeightedTriangles(bool); void SetShowDistanceWeightedPvs(bool); void UseConstColorForRayViz(bool); void UseRayLengthForRayViz(bool); void SetShowContribution(bool); void SetShowDistribution(bool); void SetShowDistribution1(bool); void SetShowDistribution2(bool); void SetShowDistribution3(bool); void SetShowDistribution4(bool); void SetTranslation(bool); void SetRotation(bool); void SetScale(bool); }; class QtGlRendererWidget: public QGLWidget, public GlRendererWidget { Q_OBJECT public: // point of the last mouse click used for movement in the scene Vector3 mousePoint; bool mTopView; bool mRenderViewCells; bool mCutViewCells; bool mCutScene; bool mHideByCost; bool mRenderErrors; bool mRenderFilter; bool mRenderVisibilityEstimates; bool mUseFilter; bool mUseSpatialFilter; bool mShowRenderCost; bool mShowPiercingRays; bool mShowWeightedRays; bool mUseStandardColors; bool mShowRays; bool mShowPvsSizes; bool mShowComparison; float mSpatialFilterSize; Plane3 mSceneCutPlane; float mHidingCost; float mTopDistance; float mTransparency; bool mUseTransparency; bool mShowWeightedCost; bool mShowDistanceWeightedTriangles; bool mShowDistanceWeightedPvs; bool mShowWeightedTriangles; int mShowDistribution; int mCurrentDynamicObjectIdx; bool mReplayMode; // some statistics int mPvsSize; float mRenderError; float mTransferFunction; Vector3 mDummyViewPoint; int mRayVisualizationMethod; int mTrafoType; QtRendererControlWidget *mControlWidget; QtPreprocessorThread *mPreprocessorThread; ViewCellInfoContainer mCompareInfo; int mCurrentPvsCost; vector mColors; bool mUseRandomColorPerPvsObject; int mUpdateTimerId; int mReplayTimerId; ObjectPlacer *mPlacer; //DynamicObjectsContainer mPendingDynamicObjects; DynamicObjectsContainer mDynamicPvsObjects; QtGlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree, QWidget * parent = 0, const QGLWidget *shareWidget = 0, Qt::WFlags f = 0); QtGlRendererWidget() {}; ~QtGlRendererWidget(); void SetThread(QtPreprocessorThread *t) { mPreprocessorThread = t; } void RenderRenderCost(); virtual void SetupCamera(); void initializeGL() { InitGL(); } virtual void InitGL(); void resizeGL(int w, int h); void paintGL(); void timerEvent(QTimerEvent *event); void mousePressEvent(QMouseEvent *); void mouseReleaseEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *); void keyPressEvent(QKeyEvent * e); void VisualizePvs(); float RenderErrors(); void RenderInfo(); virtual int GetWidth() const { return width(); } virtual int GetHeight() const { return height(); } virtual void SetupCameraProjection(const int w, const int h, const float angle = 70.0f); void RenderViewCells(); virtual void Show() { show(); } bool PvsChanged(ViewCell *viewcell) const; void ComputeMaxValues(const ViewCellContainer &viewCells, int &maxPvs, int &maxPiercingRays, float &maxRelativeRays, float &maxRcCost); void AssignImportanceByRelativeValue(const ViewCellContainer &viewCells, int &maxPvs, int &maxPiercingRays, float &maxRelativeRays, float &maxRcCost); void AssignColorByComparison(const ViewCellContainer &viewcells, const ViewCellInfoContainer &compareInfo); void WriteViewCellInfos(); /** Unproject x/y screen coordinates. */ Vector3 Unproject(int x, int y); int FindDynamicObject(float x, float y); public slots: /** Replay the view points stored in the view points list. */ void ReplayViewPoints(); void UpdateDynamicObjects(); void UpdateAllPvs(); void ComputeVisibility(); void StopComputation(); void SetRandomViewPoint(); void StoreStatistics(); void LoadObject(); void SetRenderErrors(bool b) { mRenderErrors = b; updateGL(); } void ComputeGVS() { mComputeGVS = true; updateGL(); } void SetRenderBoxes(bool b) { mRenderBoxes = b; updateGL(); } void SetRenderFilter(bool b) { mRenderFilter = b; updateGL(); } void SetRenderVisibilityEstimates(bool b) { mRenderVisibilityEstimates = b; updateGL(); } void SetUseFilter(bool b) { mUseFilter = b; mPvsCache.Reset(); updateGL(); } void SetUseSpatialFilter(bool b) { mUseSpatialFilter = b; mPvsCache.Reset(); updateGL(); } void SetViewCellGranularity(int number); void SetTransferFunction(int number) { mTransferFunction = number/1000.0f; updateGL(); } void SetVisibilityFilterSize(int number); void SetSpatialFilterSize(int number); void SetSceneCut(int cut); void SetTopDistance(int dist); void SetTransparency(int dist); void SetHidingCost(int dist); void SetShowViewCells(bool b) { mRenderViewCells = b; updateGL(); } void SetShowRays(bool b) { mShowRays = b; updateGL(); } void SetShowRenderCost(bool b) { mShowRenderCost = b; updateGL(); } void SetShowPvsSizes(bool b) { mShowPvsSizes = b; updateGL(); } void SetShowComparison(bool b) { mShowComparison = b; updateGL(); } void SetShowPiercingRays(bool b) { mShowPiercingRays = b; updateGL(); } void SetShowWireFrame(bool b) { mUseStandardColors = b; updateGL(); } void SetShowWeightedRays(bool b) { mShowWeightedRays = b; updateGL(); } void SetTopView(bool b) { mTopView = b; updateGL(); } void SetCutViewCells(bool b) { mCutViewCells = b; updateGL(); } void SetCutScene(bool b) { mCutScene = b; updateGL(); } void SetHideByCost(bool b) { mHideByCost = b; updateGL(); } void SetUseTransparency(bool b) { mUseTransparency = b; updateGL(); } void SetShowWeightedCost(bool b) { mShowWeightedCost = b; updateGL(); } void SetShowDistanceWeightedPvs(bool b) { mShowDistanceWeightedPvs = b; updateGL(); } void SetShowDistanceWeightedTriangles(bool b) { mShowDistanceWeightedTriangles = b; updateGL(); } void SetShowWeightedTriangles(bool b) { mShowWeightedTriangles = b; updateGL(); } void UseConstColorForRayViz(bool b) { mRayVisualizationMethod = 0; } void UseRayLengthForRayViz(bool b) { mRayVisualizationMethod = 1; } void SetShowContribution(bool b) { mRayVisualizationMethod = 2; } void SetShowDistribution(bool b) { mRayVisualizationMethod = 3; } void SetTranslation(bool b) { mTrafoType = 0; } void SetScale(bool b) { mTrafoType = 1; } void SetRotation(bool b) { mTrafoType = 2; } void SetShowDistribution1(bool b) { if (b) mShowDistribution |= 1; else mShowDistribution ^= 1; std::cout << "b: " << (mShowDistribution & 1) << " " << (mShowDistribution & 2) << " " << (mShowDistribution & 4) << " " << (mShowDistribution & 8) << std::endl; } void SetShowDistribution2(bool b) { if (b) mShowDistribution |= 2; else mShowDistribution ^= 2; } void SetShowDistribution3(bool b) { if (b) mShowDistribution |= 4; else mShowDistribution ^= 4; } void SetShowDistribution4(bool b) { if (b) mShowDistribution |= 8; else mShowDistribution ^= 8; } /** Prepare pvs for rendering. */ virtual void PreparePvs(const ObjectPvs &pvs); /** Internal method rendering the pvs if it has been properly prepared. */ void _RenderPvs(); /** Render pvs using false colors. */ void _RenderColoredPvs(); float ComputeRenderCost(ViewCell *vc); ///////// signals: void PvsUpdated(); }; class QtGlDebuggerWidget: public QGLWidget { Q_OBJECT public: QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL); ~QtGlDebuggerWidget(); void initializeGL(); void resizeGL(int w, int h); void paintGL(); void timerEvent(QTimerEvent *) { update(); } void mousePressEvent(QMouseEvent *) { killTimer(timerId); } void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); } void initCommon(); void initPbuffer(); QtGlRendererBuffer *mRenderBuffer; Beam mBeam; int mSamples; Intersectable *mSourceObject; private: GLuint dynamicTexture; int timerId; }; extern QtGlDebuggerWidget *debuggerWidget; }; #endif