Commit 2c86a948 authored by Jan Möbius's avatar Jan Möbius

Dennis:

Improved Stereo support
Options for stereo settings

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5572 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 01eecace
...@@ -168,6 +168,16 @@ void Core::readApplicationOptions(INIFile& _ini) { ...@@ -168,6 +168,16 @@ void Core::readApplicationOptions(INIFile& _ini) {
if ( _ini.get_entry( stereoMode, "Options" , "StereoMode") ) if ( _ini.get_entry( stereoMode, "Options" , "StereoMode") )
OpenFlipper::Options::stereoMode(static_cast<OpenFlipper::Options::StereoMode> (stereoMode)); OpenFlipper::Options::stereoMode(static_cast<OpenFlipper::Options::StereoMode> (stereoMode));
//============================================================================
// Load stereo view settings
//============================================================================
float val;
if ( _ini.get_entry( val, "Options" , "EyeDistance") )
OpenFlipper::Options::eyeDistance(val);
if ( _ini.get_entry( val, "Options" , "FocalDistance") )
OpenFlipper::Options::focalDistance(val);
//============================================================================ //============================================================================
// Load the custom anaglyph stereo mode color matrices // Load the custom anaglyph stereo mode color matrices
//============================================================================ //============================================================================
...@@ -517,6 +527,9 @@ void Core::writeApplicationOptions(INIFile& _ini) { ...@@ -517,6 +527,9 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options","StereoMode",OpenFlipper::Options::stereoMode() ); _ini.add_entry("Options","StereoMode",OpenFlipper::Options::stereoMode() );
_ini.add_entry("Options" , "EyeDistance", OpenFlipper::Options::eyeDistance());
_ini.add_entry("Options" , "FocalDistance", OpenFlipper::Options::focalDistance());
_ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() ); _ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
_ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() ); _ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() );
} }
......
...@@ -95,7 +95,13 @@ static bool stereo_ = true; ...@@ -95,7 +95,13 @@ static bool stereo_ = true;
static bool glStereo_ = true; static bool glStereo_ = true;
/// Stereo mode /// Stereo mode
StereoMode stereoMode_ = OpenGL; static StereoMode stereoMode_ = OpenGL;
/// get stereo eye distance (default = 7cm)
static float eyeDistance_ = 0.07;
/// stereo focal distance relative to scene near plane (default = to center of scene)
static float focalDistance_ = 0.5;
/// vectroy containing left/right color matrices for custom anaglyph mode /// vectroy containing left/right color matrices for custom anaglyph mode
std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0); std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0);
...@@ -440,6 +446,30 @@ StereoMode stereoMode( ) { ...@@ -440,6 +446,30 @@ StereoMode stereoMode( ) {
return stereoMode_; return stereoMode_;
} }
/// Store stereo eye distance
void eyeDistance( float _eye )
{
eyeDistance_ = _eye;
}
/// get stereo eye distance
float eyeDistance( )
{
return eyeDistance_;
}
/// Store stereo focal distance relative to scene near plane
void focalDistance( float _focal )
{
focalDistance_ = _focal;
}
/// get stereo focal distance relative to scene near plane
float focalDistance( )
{
return focalDistance_;
}
/// Store the 3x3 left eye color matrix values for custom anaglyph stereo mode /// Store the 3x3 left eye color matrix values for custom anaglyph stereo mode
void anaglyphLeftEyeColorMatrix( std::vector<float> _mat ) void anaglyphLeftEyeColorMatrix( std::vector<float> _mat )
{ {
......
...@@ -340,6 +340,22 @@ void fontsDir(QDir _dir); ...@@ -340,6 +340,22 @@ void fontsDir(QDir _dir);
DLLEXPORT DLLEXPORT
StereoMode stereoMode( ); StereoMode stereoMode( );
/// Store stereo eye distance
DLLEXPORT
void eyeDistance( float _eye );
/// get stereo eye distance
DLLEXPORT
float eyeDistance( );
/// Store stereo focal distance relative to scene near plane
DLLEXPORT
void focalDistance( float _focal );
/// get stereo focal distance relative to scene near plane
DLLEXPORT
float focalDistance( );
/// Store the 3x3 left eye color matrix values for custom anaglyph stereo mode /// Store the 3x3 left eye color matrix values for custom anaglyph stereo mode
DLLEXPORT DLLEXPORT
void anaglyphLeftEyeColorMatrix( std::vector<float> _mat ); void anaglyphLeftEyeColorMatrix( std::vector<float> _mat );
......
...@@ -458,8 +458,6 @@ void CoreWidget::registerCoreKeys() { ...@@ -458,8 +458,6 @@ void CoreWidget::registerCoreKeys() {
emit registerKey(Qt::Key_L , Qt::ControlModifier, "Show/Hide Logger"); emit registerKey(Qt::Key_L , Qt::ControlModifier, "Show/Hide Logger");
emit registerKey(Qt::Key_T , Qt::ControlModifier, "Show/Hide Toolbox"); emit registerKey(Qt::Key_T , Qt::ControlModifier, "Show/Hide Toolbox");
emit registerKey(Qt::Key_F , Qt::ControlModifier, "Toggle Fullscreen"); emit registerKey(Qt::Key_F , Qt::ControlModifier, "Toggle Fullscreen");
emit registerKey(Qt::Key_E , Qt::ControlModifier | Qt::AltModifier, "Adjust Eye distance for stereo mode");
emit registerKey(Qt::Key_F , Qt::ControlModifier | Qt::AltModifier, "Adjust Focal distance for stereo mode");
emit registerKey(Qt::Key_Escape , Qt::NoModifier, "Switch to last action mode ( Move,Picking,Light or Info Mode)"); emit registerKey(Qt::Key_Escape , Qt::NoModifier, "Switch to last action mode ( Move,Picking,Light or Info Mode)");
emit registerKey(Qt::Key_Space , Qt::NoModifier, "Toggle between multiview and single view"); emit registerKey(Qt::Key_Space , Qt::NoModifier, "Toggle between multiview and single view");
...@@ -471,75 +469,28 @@ void CoreWidget::registerCoreKeys() { ...@@ -471,75 +469,28 @@ void CoreWidget::registerCoreKeys() {
void CoreWidget::coreKeyPressEvent (QKeyEvent* _e){ void CoreWidget::coreKeyPressEvent (QKeyEvent* _e){
if (_e->modifiers() & Qt::ControlModifier ) { if (_e->modifiers() & Qt::ControlModifier ) {
if (_e->modifiers() & Qt::AltModifier ) switch (_e->key()) {
case Qt::Key_F :
if ( OpenFlipper::Options::stereo() ) { toggleFullscreen();
switch (_e->key()) { return;
// Stereo seeing: eye distance
case Qt::Key_E:
{
bool ok(false);
double val = QInputDialog::getDouble( this, "Eye Dist", "Eye Dist:",
examiner_widgets_[0]->eyeDistance(),
0.0, 100.0, 10,
&ok);
if (ok) {
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i)
examiner_widgets_[i]->setEyeDistance(val);
}
break;
}
// Stereo setting: focal length
case Qt::Key_F:
{
bool ok(false);
double val = QInputDialog::getDouble( this, "Focal Dist", "Focal Dist:",
examiner_widgets_[0]->focalDistance(),
0.0, 100.0, 10,
&ok);
if (ok) {
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i)
examiner_widgets_[i]->setFocalDistance(val);
}
break;
}
default:
break;
}
} else
emit log(LOGWARN,"Activate stereo mode to change stereo settings");
else
switch (_e->key()) {
case Qt::Key_F :
toggleFullscreen();
return;
case Qt::Key_L : case Qt::Key_L :
toggleLogger(); toggleLogger();
return; return;
case Qt::Key_T : case Qt::Key_T :
toggleToolbox(); toggleToolbox();
return; return;
case Qt::Key_O : case Qt::Key_O :
loadMenu(); loadMenu();
case Qt::Key_S : case Qt::Key_S :
saveMenu(); saveMenu();
default: default:
return; return;
} }
} }
......
...@@ -147,9 +147,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene, ...@@ -147,9 +147,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene,
far_ = 100.0; far_ = 100.0;
fovy_ = 45.0; fovy_ = 45.0;
focalDist_ = 3.0;
eyeDist_ = 0.01;
sceneGraphRoot_ = 0; sceneGraphRoot_ = 0;
normalsMode_ = DONT_TOUCH_NORMALS; normalsMode_ = DONT_TOUCH_NORMALS;
......
...@@ -554,29 +554,9 @@ private: ...@@ -554,29 +554,9 @@ private:
/// enable/disable stereo mode /// enable/disable stereo mode
virtual void setStereoMode(bool _b); virtual void setStereoMode(bool _b);
public:
/** \brief Set eye distance for stereo
*
* Set the eye distance used for stereo projection. The function will enforce a redraw.
*/
void setEyeDistance(double _distance);
/// Get the current eye Distance
double eyeDistance( );
/** \brief Set focal distance for stereo
*
* Set the focal distance used for stereo projection. The function will enforce a redraw.
*/
void setFocalDistance(double _distance);
/// Get the current focal Distance
double focalDistance( );
private: private:
// stereo stuff // stereo stuff
bool stereo_; bool stereo_;
double eyeDist_, focalDist_;
// custom anaglyph stuff // custom anaglyph stuff
int agTexWidth_; int agTexWidth_;
......
...@@ -71,27 +71,6 @@ static const char* customAnaglyphProg = { ...@@ -71,27 +71,6 @@ static const char* customAnaglyphProg = {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void glViewer::setEyeDistance(double _distance) {
eyeDist_ = _distance;
updateGL();
}
double glViewer::eyeDistance( ) {
return eyeDist_;
}
void glViewer::setFocalDistance(double _distance) {
focalDist_ = _distance;
updateGL();
}
double glViewer::focalDistance( ) {
return focalDist_;
}
//-----------------------------------------------------------------------------
void void
glViewer::setStereoMode(bool _b) glViewer::setStereoMode(bool _b)
{ {
...@@ -111,7 +90,7 @@ glViewer::setStereoMode(bool _b) ...@@ -111,7 +90,7 @@ glViewer::setStereoMode(bool _b)
void void
glViewer::drawScene_glStereo() glViewer::drawScene_glStereo()
{ {
double l, r, t, b, w, h, a, radians, wd2, ndfl; double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth(); w = glWidth();
h = glHeight(); h = glHeight();
...@@ -119,23 +98,23 @@ glViewer::drawScene_glStereo() ...@@ -119,23 +98,23 @@ glViewer::drawScene_glStereo()
radians = fovy_ * 0.5 / 180.0 * M_PI; radians = fovy_ * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians); wd2 = near_ * tan(radians);
ndfl = near_ / focalDist_ * scene_radius_; zerop = near_ + ((far_ - near_) * OpenFlipper::Options::focalDistance ());
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
l = -a*wd2; l = -a*wd2;
r = a*wd2; r = a*wd2;
t = wd2; t = wd2;
b = -wd2; b = -wd2;
double offset = 0.5 * eyeDist_; double offset = 0.5 * OpenFlipper::Options::eyeDistance () * xrange;
double offset2 = offset * ndfl; double offset2 = offset * ndfl;
// left eye // left eye
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, near_, far_); glFrustum(l+offset2, r+offset2, b, t, near_, far_);
glTranslatef(-offset, 0.0, 0.0); glTranslatef(+offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_LEFT); glDrawBuffer(GL_BACK_LEFT);
glstate_->clearBuffers (); glstate_->clearBuffers ();
...@@ -147,7 +126,7 @@ glViewer::drawScene_glStereo() ...@@ -147,7 +126,7 @@ glViewer::drawScene_glStereo()
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, near_, far_); glFrustum(l-offset2, r-offset2, b, t, near_, far_);
glTranslatef(offset, 0.0, 0.0); glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_RIGHT); glDrawBuffer(GL_BACK_RIGHT);
glstate_->clearBuffers (); glstate_->clearBuffers ();
...@@ -163,7 +142,7 @@ glViewer::drawScene_glStereo() ...@@ -163,7 +142,7 @@ glViewer::drawScene_glStereo()
void void
glViewer::drawScene_anaglyphStereo() glViewer::drawScene_anaglyphStereo()
{ {
double l, r, t, b, w, h, a, radians, wd2, ndfl; double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth(); w = glWidth();
h = glHeight(); h = glHeight();
...@@ -171,21 +150,23 @@ glViewer::drawScene_anaglyphStereo() ...@@ -171,21 +150,23 @@ glViewer::drawScene_anaglyphStereo()
radians = fovy_ * 0.5 / 180.0 * M_PI; radians = fovy_ * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians); wd2 = near_ * tan(radians);
ndfl = near_ / focalDist_ * scene_radius_; zerop = near_ + ((far_ - near_) * OpenFlipper::Options::focalDistance ());
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
l = -a*wd2; l = -a*wd2;
r = a*wd2; r = a*wd2;
t = wd2; t = wd2;
b = -wd2; b = -wd2;
double offset = 0.5 * eyeDist_; double offset = 0.5 * OpenFlipper::Options::eyeDistance () * xrange;
double offset2 = offset * ndfl; double offset2 = offset * ndfl;
// left eye // left eye
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, near_, far_); glFrustum(l+offset2, r+offset2, b, t, near_, far_);
glTranslatef(-offset, 0.0, 0.0); glTranslatef(offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers (); glstate_->clearBuffers ();
...@@ -201,7 +182,7 @@ glViewer::drawScene_anaglyphStereo() ...@@ -201,7 +182,7 @@ glViewer::drawScene_anaglyphStereo()
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, near_, far_); glFrustum(l-offset2, r-offset2, b, t, near_, far_);
glTranslatef(offset, 0.0, 0.0); glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
...@@ -292,7 +273,7 @@ glViewer::drawScene_customAnaglyphStereo() ...@@ -292,7 +273,7 @@ glViewer::drawScene_customAnaglyphStereo()
if (!customAnaglyphSupported_) if (!customAnaglyphSupported_)
return; return;
double l, r, t, b, w, h, a, radians, wd2, ndfl; double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth(); w = glWidth();
h = glHeight(); h = glHeight();
...@@ -300,14 +281,16 @@ glViewer::drawScene_customAnaglyphStereo() ...@@ -300,14 +281,16 @@ glViewer::drawScene_customAnaglyphStereo()
radians = fovy_ * 0.5 / 180.0 * M_PI; radians = fovy_ * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians); wd2 = near_ * tan(radians);
ndfl = near_ / focalDist_ * scene_radius_; zerop = near_ + ((far_ - near_) * OpenFlipper::Options::focalDistance ());
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
l = -a*wd2; l = -a*wd2;
r = a*wd2; r = a*wd2;
t = wd2; t = wd2;
b = -wd2; b = -wd2;
double offset = 0.5 * eyeDist_; double offset = 0.5 * OpenFlipper::Options::eyeDistance () * xrange;
double offset2 = offset * ndfl; double offset2 = offset * ndfl;
int vp_l, vp_b, vp_w, vp_h; int vp_l, vp_b, vp_w, vp_h;
...@@ -320,7 +303,7 @@ glViewer::drawScene_customAnaglyphStereo() ...@@ -320,7 +303,7 @@ glViewer::drawScene_customAnaglyphStereo()
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, near_, far_); glFrustum(l+offset2, r+offset2, b, t, near_, far_);
glTranslatef(-offset, 0.0, 0.0); glTranslatef(offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers (); glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
...@@ -334,7 +317,7 @@ glViewer::drawScene_customAnaglyphStereo() ...@@ -334,7 +317,7 @@ glViewer::drawScene_customAnaglyphStereo()
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, near_, far_); glFrustum(l-offset2, r-offset2, b, t, near_, far_);
glTranslatef(offset, 0.0, 0.0); glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers (); glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
......
...@@ -157,6 +157,9 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) { ...@@ -157,6 +157,9 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
stereoAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan); stereoAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan);
stereoCustomAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom); stereoCustomAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom);
eyeDistance->setValue (OpenFlipper::Options::eyeDistance());
focalDistance->setValue (OpenFlipper::Options::focalDistance() * 1000);
std::vector<float> mat = OpenFlipper::Options::anaglyphLeftEyeColorMatrix (); std::vector<float> mat = OpenFlipper::Options::anaglyphLeftEyeColorMatrix ();
lcm0->setValue (mat[0]); lcm0->setValue (mat[0]);
lcm1->setValue (mat[1]); lcm1->setValue (mat[1]);
...@@ -417,6 +420,9 @@ void OptionsWidget::slotApply() { ...@@ -417,6 +420,9 @@ void OptionsWidget::slotApply() {
else else
OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL); OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);
OpenFlipper::Options::eyeDistance(eyeDistance->value ());
OpenFlipper::Options::focalDistance((float)focalDistance->value () / 1000);
std::vector<float> mat (9, 0); std::vector<float> mat (9, 0);
mat[0] = lcm0->value (); mat[0] = lcm0->value ();
mat[1] = lcm1->value (); mat[1] = lcm1->value ();
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>541</width> <width>549</width>
<height>779</height> <height>819</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
...@@ -391,7 +391,7 @@ You can select multiple modes at the same time.</string> ...@@ -391,7 +391,7 @@ You can select multiple modes at the same time.</string>
<attribute name="title" > <attribute name="title" >
<string>Stereo</string> <string>Stereo</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_18" > <layout class="QVBoxLayout" name="verticalLayout_19" >
<item> <item>
<widget class="QGroupBox" name="groupBox_5" > <widget class="QGroupBox" name="groupBox_5" >
<property name="title" > <property name="title" >
...@@ -422,6 +422,116 @@ You can select multiple modes at the same time.</string> ...@@ -422,6 +422,116 @@ You can select multiple modes at the same time.</string>
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_7" >
<property name="title" >
<string>View properties</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_15" >
<item>
<layout class="QVBoxLayout" name="verticalLayout_18" >
<item>
<widget class="QLabel" name="label_11" >
<property name="text" >
<string>Eye distance:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12" >
<property name="text" >
<string>Focal distance:</string>
</property>
</widget>
</item>