Commit edb867ba authored by Frédéric Larue's avatar Frédéric Larue

Render option setting moved to GLViewer, now defined as a shared library.

parent 7b472b02
......@@ -9,7 +9,28 @@ set( CMAKE_AUTOMOC ON )
file( GLOB LIB_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h )
file( GLOB LIB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp )
add_library( ${PROJECT_NAME} ${LIB_HEADERS} ${LIB_SOURCES} )
add_library( ${PROJECT_NAME} SHARED ${LIB_HEADERS} ${LIB_SOURCES} )
if( WIN32 )
target_link_libraries( ${CURRENT_TARGET}
${Qt5Widgets_LIBRARIES}
GPU
Interfaces
UIData
UIParam
glew32 opengl32
)
else()
target_link_libraries( ${CURRENT_TARGET}
${Qt5Widgets_LIBRARIES}
GPU
Interfaces
UIData
UIParam
${GLEW_LIBRARIES}
GL
)
endif()
if( ENABLE_SOLUTION_FOLDERS )
......
......@@ -12,11 +12,12 @@
#include "GLViewerDefs.h"
#include <QtGui>
#include "Box.h"
class Frustum
class GLVIEWER_API Frustum
{
enum PlaneId
{
......
......@@ -7,6 +7,7 @@
#include "GLViewer.h"
#include "UIMainWindow.h"
#include <fstream>
#include <iostream>
......@@ -21,6 +22,23 @@
QVector3D GLViewer::BgTopColor;
QVector3D GLViewer::BgBottomColor;
QVector3D GLViewer::CoolColor( 0.5f, 0.0f, 1.0f );
QVector3D GLViewer::WarmColor( 1.0f, 0.8f, 0.0f );
QVector3D GLViewer::LightColor( 1.0f, 1.0f, 1.0f );
QVector3D GLViewer::AmbientColor;
QVector3D GLViewer::SpecularColor;
float GLViewer::Ambient = 0.1f;
float GLViewer::Specular = 0.5f;
float GLViewer::Shininess = 80.0f;
void GLViewer::DisplayableInfo::Initialize( DisplayableInterface *displayable,
DisplayableList::iterator priorityPos,
UIParamSet &params )
......@@ -838,19 +856,11 @@ void GLViewer::paintGL()
glDisable( GL_DEPTH_TEST );
glDepthMask( GL_FALSE );
QColor dark = palette().color( QPalette::Dark );
QColor light = palette().color( QPalette::Light );
glBegin( GL_QUADS );
//glColor3ub( 132, 132, 132 );
//glColor3ub( 58, 58, 58 );
//glColor3ub( 42, 42, 42 );
glColor3ub( dark.red(), dark.green(), dark.blue() );
glColor3fv( &GLViewer::BgBottomColor[0] );
glVertex2i( -1, -1 );
glVertex2i( 1, -1 );
//glColor3ub( 208, 208, 208 );
//glColor3ub( 134, 134, 134 );
//glColor3ub( 118, 118, 118 );
glColor3ub( light.red(), light.green(), light.blue() );
glColor3fv( &GLViewer::BgTopColor[0] );
glVertex2i( 1, 1 );
glVertex2i( -1, 1 );
glEnd();
......
......@@ -10,6 +10,7 @@
#define GLVIEWER_H
#include "GLViewerDefs.h"
#include "../GPU/GPU.h"
#include "DisplayableInterface.h"
#include <set>
......@@ -24,7 +25,7 @@ class Panel;
class GLViewer : public QOpenGLWidget
class GLVIEWER_API GLViewer : public QOpenGLWidget
{
Q_OBJECT
......@@ -57,7 +58,7 @@ public:
unsigned int pointSize;
};
class NavigationControl
class GLVIEWER_API NavigationControl
{
GLViewer *m_Viewer;
......@@ -126,6 +127,22 @@ protected:
static const char* s_ZBufferVPG;
static const char* s_ZBufferFPG;
public:
static QVector3D BgTopColor;
static QVector3D BgBottomColor;
static QVector3D CoolColor;
static QVector3D WarmColor;
static QVector3D LightColor;
static QVector3D AmbientColor;
static QVector3D SpecularColor;
static float Ambient;
static float Specular;
static float Shininess;
/********************\
| Member variable(s) |
\********************/
......
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#ifdef _WIN32
#ifdef GLViewer_EXPORTS
#define GLVIEWER_API __declspec(dllexport)
#else
#define GLVIEWER_API __declspec(dllimport)
#endif
#else
#define GLVIEWER_API
#endif
......@@ -4,10 +4,11 @@
#include "GLViewerDefs.h"
#include "SelectionTool.h"
class SelectionManager
class GLVIEWER_API SelectionManager
{
SelectableEntity m_SelectableEntity;
RealTimeSelectionListener* m_RealTimeSelectionListeners;
......
......@@ -7,7 +7,7 @@
#include "SelectionManager.h"
class SelectionManagerImageTexels : public TexelSelectionManager
class GLVIEWER_API SelectionManagerImageTexels : public TexelSelectionManager
{
struct Tile
{
......
......@@ -7,7 +7,7 @@
#include "SelectionManager.h"
class SelectionManagerMeshFaces : public FaceSelectionManager
class GLVIEWER_API SelectionManagerMeshFaces : public FaceSelectionManager
{
static const char* s_DisplayShaderVSH;
static const char* s_DisplayShaderGSH;
......
......@@ -7,7 +7,7 @@
#include "SelectionManager.h"
class SelectionManagerMeshTexels : public TexelSelectionManager
class GLVIEWER_API SelectionManagerMeshTexels : public TexelSelectionManager
{
static const char* s_DisplayShaderVSH;
static const char* s_DisplayShaderFSH;
......
......@@ -7,7 +7,7 @@
#include "SelectionManager.h"
class SelectionManagerMeshVertices : public VertexSelectionManager
class GLVIEWER_API SelectionManagerMeshVertices : public VertexSelectionManager
{
static const char* s_DisplayShaderVSH;
static const char* s_DisplayShaderGSH;
......
......@@ -23,7 +23,6 @@ include_directories( ${CMAKE_BINARY_DIR}/GUI_main )
if( WIN32 )
target_link_libraries( ${CURRENT_TARGET}
${Qt5Widgets_LIBRARIES}
${ITK_LIBRARIES}
GLViewer
GPU
Interfaces
......@@ -35,7 +34,6 @@ target_link_libraries( ${CURRENT_TARGET}
else()
target_link_libraries( ${CURRENT_TARGET}
${Qt5Widgets_LIBRARIES}
${ITK_LIBRARIES}
GLViewer
GPU
Interfaces
......
......@@ -223,6 +223,7 @@ void UIMainWindow::init()
connect( ui->tableCurrentProjContent, SIGNAL(askForReframing()), this, SLOT(reframeScene()) );
connect( ui->tableCurrentProjContent, SIGNAL(exportLaunched(ExportInterface*,int,QString)), this, SLOT(launchExport(ExportInterface*,int,QString)) );
initRenderOptions();
initializeCentralWidgetStack();
setViewerMode( DISPLAY_DOF_3D );
......@@ -235,6 +236,7 @@ void UIMainWindow::init()
connect( ui->projectViewButtonRemove, SIGNAL(clicked(bool)), this, SLOT(removeFromCurrentProject()) );
connect( ui->projectViewButtonRename, SIGNAL(clicked(bool)), ui->tableCurrentProjContent, SLOT(editSelectedDataName()) );
connect( ui->actionRenderOptions, SIGNAL(triggered()), this, SLOT(showRenderingOptionDialog()) );
connect( ui->actionLoadImage, SIGNAL(triggered()), this, SLOT(addToCurrentProject()) );
connect( ui->actionNewProject, SIGNAL(triggered()), this, SLOT(newProject()) );
connect( ui->actionSaveProject, SIGNAL(triggered()), this, SLOT(saveCurrentProject()) );
......@@ -2006,3 +2008,154 @@ void UIMainWindow::showThemeSettingsDialog()
ThemeSettingsDialog dlg;
dlg.exec();
}
bool UIMainWindow::initRenderOptions()
{
std::function<QVector3D(const QString&)> colorFromHexa = []( const QString& hexa )
{
bool ok;
uint32_t colorVal = hexa.toLong( &ok, 16 );
return QVector3D( (colorVal >> 16)&0xFF, (colorVal >>8)&0xFF, colorVal&0xFF ) / 255.0f;
};
std::function<QVector3D(const QColor&)> ColorToVector = []( const QColor &col ) { return QVector3D( col.red(), col.green(), col.blue() ) / 255.0f; };
QSettings *settings = UIMainWindow::getUserSettings();
if( settings->contains( "RenderOptions/bgTopColor") )
GLViewer::BgTopColor = colorFromHexa( settings->value( "RenderOptions/bgTopColor" ).toString() );
else
GLViewer::BgTopColor = ColorToVector( palette().color( QPalette::Light ) );
if( settings->contains( "RenderOptions/bgBottomColor") )
GLViewer::BgBottomColor = colorFromHexa( settings->value( "RenderOptions/bgBottomColor" ).toString() );
else
GLViewer::BgBottomColor = ColorToVector( palette().color( QPalette::Dark ) );
if( settings->contains( "RenderOptions/coolColor") )
GLViewer::CoolColor = colorFromHexa( settings->value( "RenderOptions/coolColor" ).toString() );
if( settings->contains( "RenderOptions/warmColor") )
GLViewer::WarmColor = colorFromHexa( settings->value( "RenderOptions/warmColor" ).toString() );
if( settings->contains( "RenderOptions/lightColor") )
GLViewer::LightColor = colorFromHexa( settings->value( "RenderOptions/lightColor" ).toString() );
if( settings->contains( "RenderOptions/ambient") )
GLViewer::Ambient = settings->value( "RenderOptions/ambient" ).toFloat();
if( settings->contains( "RenderOptions/specular") )
GLViewer::Specular = settings->value( "RenderOptions/specular" ).toFloat();
if( settings->contains( "RenderOptions/shininess") )
GLViewer::Shininess = settings->value( "RenderOptions/shininess" ).toFloat();
GLViewer::AmbientColor = GLViewer::LightColor * GLViewer::Ambient;
GLViewer::SpecularColor = GLViewer::LightColor * GLViewer::Specular;
return true;
}
bool UIMainWindow::updateRenderOptions()
{
std::function<QString(const QVector3D&)> hexaFromColor = []( const QVector3D& color )
{
QColor c( int(255.0f*color.x()), int(255.0f*color.y()), int(255.0f*color.z()) );
int colorVal = (c.red() << 16) + (c.green() << 8) + c.blue();
return QString::number(colorVal,16).toUpper().rightJustified(6,'0');
};
QSettings *settings = UIMainWindow::getUserSettings();
settings->beginGroup( "RenderOptions" );
settings->setValue( "bgTopColor" , QVariant( hexaFromColor(GLViewer::BgTopColor) ) );
settings->setValue( "bgBottomColor", QVariant( hexaFromColor(GLViewer::BgBottomColor) ) );
settings->setValue( "coolColor" , QVariant( hexaFromColor(GLViewer::CoolColor) ) );
settings->setValue( "warmColor" , QVariant( hexaFromColor(GLViewer::WarmColor) ) );
settings->setValue( "lightColor" , QVariant( hexaFromColor(GLViewer::LightColor) ) );
settings->setValue( "ambient" , QVariant( GLViewer::Ambient ) );
settings->setValue( "specular" , QVariant( GLViewer::Specular ) );
settings->setValue( "shininess" , QVariant( GLViewer::Shininess ) );
settings->endGroup();
GLViewer::AmbientColor = GLViewer::LightColor * GLViewer::Ambient;
GLViewer::SpecularColor = GLViewer::LightColor * GLViewer::Specular;
return true;
}
void UIMainWindow::showRenderingOptionDialog()
{
std::function<QColor(const QVector3D&)> VectorToColor = []( const QVector3D &vec ) { return QColor( int(255.0f*vec.x()), int(255.0f*vec.y()), int(255.0f*vec.z()) ); };
QVector3D bgTopColorBackup = GLViewer::BgTopColor;
QVector3D bgBottomColorBackup = GLViewer::BgBottomColor;
QVector3D coolColorBackup = GLViewer::CoolColor;
QVector3D warmColorBackup = GLViewer::WarmColor;
QVector3D lightColorBackup = GLViewer::LightColor;
QVector3D ambientColorBackup = GLViewer::AmbientColor;
QVector3D specularColorBackup = GLViewer::SpecularColor;
float ambientBackup = GLViewer::Ambient;
float specularBackup = GLViewer::Specular;
float shininessBackup = GLViewer::Shininess;;
UIParamDialog dlg( "Render options", this );
int thisScreenId = QApplication::desktop()->screenNumber( this );
QWidget *thisScreen = QApplication::desktop()->screen( thisScreenId );
dlg.Add( new UIParamColorRGB("bgTop", "Bg. top color", "Background top color.", VectorToColor(GLViewer::BgTopColor)) );
dlg.Add( new UIParamColorRGB("bgBottom", "Bg. bottop color", "Backgroud bottom color.", VectorToColor(GLViewer::BgBottomColor)) );
dlg.AddSeparator();
dlg.Add( new UIParamColorRGB("cool", "Cool color", "Color corresponding to shaded regions for the default shading mode.", VectorToColor(GLViewer::CoolColor)) );
dlg.Add( new UIParamColorRGB("warm", "Warm color", "Color corresponding to lighted regions for the default shading mode.", VectorToColor(GLViewer::WarmColor)) );
dlg.AddSeparator();
dlg.Add( new UIParamColorRGB("diff", "Light color", "Light color.", VectorToColor(GLViewer::LightColor)) );
dlg.Add( new UIParamSlider("amb", "Ambient", "Strength of the light ambient component (as a factor of the light color).", 1000*GLViewer::Ambient, 0, 1000, 50) );
dlg.Add( new UIParamSlider("spec", "Specular", "Strength of the light specular component (as a factor of the light color).", 1000*GLViewer::Specular, 0, 1000, 50) );
dlg.Add( new UIParamSlider("shin", "Shininess", "Thickness of the specular lobe.", GLViewer::Shininess, 0, 200, 10) );
connect( &dlg.GetParameters(), SIGNAL(parameterUpdated(UIParam*)), this, SLOT(renderOptionParameterModified(UIParam*)) );
if( dlg.exec() != QDialog::Accepted )
{
GLViewer::BgTopColor = bgTopColorBackup;
GLViewer::BgBottomColor = bgBottomColorBackup;
GLViewer::CoolColor = coolColorBackup;
GLViewer::WarmColor = warmColorBackup;
GLViewer::LightColor = lightColorBackup;
GLViewer::AmbientColor = ambientColorBackup;
GLViewer::SpecularColor = specularColorBackup;
GLViewer::Ambient = ambientBackup;
GLViewer::Specular = specularBackup;
GLViewer::Shininess = shininessBackup;
updateRenderOptions();
}
}
void UIMainWindow::renderOptionParameterModified( UIParam *p )
{
std::function<QVector3D(const QColor&)> ColorToVector = []( const QColor &col ) { return QVector3D( col.red(), col.green(), col.blue() ) / 255.0f; };
if( p->Id() == "bgTop" )
GLViewer::BgTopColor = ColorToVector( ((UIParamColorRGB*) p)->Value() );
else if( p->Id() == "bgBottom" )
GLViewer::BgBottomColor = ColorToVector( ((UIParamColorRGB*) p)->Value() );
else if( p->Id() == "cool" )
GLViewer::CoolColor = ColorToVector( ((UIParamColorRGB*) p)->Value() );
else if( p->Id() == "warm" )
GLViewer::WarmColor = ColorToVector( ((UIParamColorRGB*) p)->Value() );
else if( p->Id() == "diff" )
GLViewer::LightColor = ColorToVector( ((UIParamColorRGB*) p)->Value() );
else if( p->Id() == "amb" )
GLViewer::Ambient = ((UIParamSlider*) p)->Value() * 0.001f;
else if( p->Id() == "spec" )
GLViewer::Specular = ((UIParamSlider*) p)->Value() * 0.001f;
else if( p->Id() == "shin" )
GLViewer::Shininess = ((UIParamSlider*) p)->Value();
updateRenderOptions();
getCurrentViewer()->update();
}
......@@ -128,7 +128,10 @@ public:
virtual void onDataParentChanged( GenericUIData *data, GenericUIData *prevParent, GenericUIData *newParent ) {}
private:
void closeEvent( QCloseEvent* evt );
bool initRenderOptions();
bool updateRenderOptions();
void closeEvent( QCloseEvent* evt );
void setMainWindowTitleInfos( const QString& str );
......@@ -202,6 +205,9 @@ public slots:
void popCentralWidget();
inline void dataParentChanged( GenericUIData *data, GenericUIData *prevParent, GenericUIData *newParent ) { onDataParentChanged(data,prevParent,newParent); }
void showRenderingOptionDialog();
void renderOptionParameterModified( UIParam *p );
};
......
......@@ -76,6 +76,7 @@
<property name="title">
<string>Settings</string>
</property>
<addaction name="actionRenderOptions"/>
<addaction name="actionCustomizeTheme"/>
</widget>
<addaction name="menuFile"/>
......@@ -818,6 +819,11 @@
<string>Customize theme</string>
</property>
</action>
<action name="actionRenderOptions">
<property name="text">
<string>Render options</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment