diff --git a/Common/Context.h b/Common/Context.h index ee9feeefa5a5c6fdce4503fd702f33f9109f6146..40f90fe3a42be8c2146caac74c1c5b763696406e 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -135,6 +135,7 @@ class CTX { double lc; // double buffer/antialias/stereo graphics? int db, antialiasing, stereo, camera; + double eye_sep_ratio,focallength_ratio,camera_aperture; // orthogonal projection? int ortho; // draw the bounding boxes and the rot center? diff --git a/Common/Options.cpp b/Common/Options.cpp index 46ece0afb26db12f4daaccc94f80036391ba50a9..38adca50a09e2c163bde8c764c8c0b0b2390971c 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -3698,12 +3698,10 @@ double opt_general_stereo_mode(OPT_ARGS_NUM) if (CTX::instance()->stereo) CTX::instance()->camera = 1 ; #if defined(HAVE_FLTK) if(FlGui::available() && (action & GMSH_GUI)) { - FlGui::instance()->options->general.butt[17]->value - (CTX::instance()->stereo); - if (CTX::instance()->stereo) { - // when stereo mode is active camera mode is obligatory - FlGui::instance()->options->general.butt[18]->value - (CTX::instance()->camera); + FlGui::instance()->options->general.butt[17]->value (CTX::instance()->stereo); + if (CTX::instance()->stereo) { + // when stereo mode is active camera mode is obligatory + FlGui::instance()->options->general.butt[18]->value (CTX::instance()->camera); FlGui::instance()->options->general.butt[18]->deactivate(); } else{ @@ -3713,6 +3711,36 @@ double opt_general_stereo_mode(OPT_ARGS_NUM) #endif return CTX::instance()->stereo ; } +double opt_general_eye_sep_ratio(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX::instance()->eye_sep_ratio = (double)val; +#if defined(HAVE_FLTK) + if(FlGui::available() && (action & GMSH_GUI)) + FlGui::instance()->options->general.slider[0]->value (CTX::instance()->eye_sep_ratio ) ; +#endif + return CTX::instance()->eye_sep_ratio ; +} +double opt_general_focallength_ratio(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX::instance()->focallength_ratio = (double) val; +#if defined(HAVE_FLTK) + if(FlGui::available() && (action & GMSH_GUI)) + FlGui::instance()->options->general.slider[1]->value (CTX::instance()->focallength_ratio ) ; +#endif + return CTX::instance()->focallength_ratio ; +} +double opt_general_camera_aperture(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX::instance()->camera_aperture= (double)val; +#if defined(HAVE_FLTK) + if(FlGui::available() && (action & GMSH_GUI)) + FlGui::instance()->options->general.slider[2]->value (CTX::instance()->camera_aperture ) ; +#endif + return CTX::instance()->camera_aperture ; +} double opt_general_camera_mode(OPT_ARGS_NUM) { diff --git a/Common/Options.h b/Common/Options.h index bb487f59a6615ff6a389510c75f062fb4c42eec8..39f31fe7a43f3acb37799f08c4ba561c813e2d8b 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -22,7 +22,7 @@ #define OPT_ARGS_STR int num, int action, std::string val #define OPT_ARGS_NUM int num, int action, double val #define OPT_ARGS_COL int num, int action, unsigned int val - + // STRINGS std::string opt_general_axes_label0(OPT_ARGS_STR); @@ -352,6 +352,9 @@ double opt_general_zoom_factor(OPT_ARGS_NUM); double opt_general_expert_mode(OPT_ARGS_NUM); double opt_general_stereo_mode(OPT_ARGS_NUM); double opt_general_camera_mode(OPT_ARGS_NUM); +double opt_general_eye_sep_ratio(OPT_ARGS_NUM); +double opt_general_focallength_ratio(OPT_ARGS_NUM); +double opt_general_camera_aperture(OPT_ARGS_NUM); double opt_general_clip0a(OPT_ARGS_NUM); double opt_general_clip0b(OPT_ARGS_NUM); double opt_general_clip0c(OPT_ARGS_NUM); diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index ae562182d6349d21ee743e0690237b0d9d0cdb1f..ed5650319f05d519b71044aa880c36e4c1925690 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -53,6 +53,10 @@ class drawContextFltk : public drawContextGlobal{ for(unsigned int j = 0; j < FlGui::instance()->graph[i]->gl.size(); j++){ FlGui::instance()->graph[i]->gl[j]->make_current(); FlGui::instance()->graph[i]->gl[j]->redraw(); + // to initialize the camera distance from model + drawContext * ctx = FlGui::instance()->graph[i]->gl[j]->getDrawContext(); + //ctx->camera.init(); + ctx->camera.update(); } } FlGui::instance()->check(); @@ -803,6 +807,7 @@ void FlGui::callForSolverPlugin(int dim) void redraw_cb(Fl_Widget *w, void *data) { drawContext::global()->draw(); + } void window_cb(Fl_Widget *w, void *data) diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h index 9547b4a3179ceeaf05b6b5a0ab55403dd5bc3a41..d33865caa0f044eb8a02b2ac064304210e9287e9 100644 --- a/Fltk/graphicWindow.h +++ b/Fltk/graphicWindow.h @@ -1,3 +1,4 @@ + // Gmsh - Copyright (C) 1997-2010 C. Geuzaine, J.-F. Remacle // // See the LICENSE.txt file for license information. Please report all diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp index be56fc25c4efd0f6c6f99fa2cbeb14ddbe9a0887..89530c462880e34a3c0e84be33e2cd22920aba6b 100644 --- a/Fltk/optionWindow.cpp +++ b/Fltk/optionWindow.cpp @@ -25,6 +25,9 @@ #include "PViewOptions.h" #include "OS.h" #include "Context.h" +// +#include "graphicWindow.h" +#include "openglWindow.h" extern StringXColor GeneralOptions_Color[] ; extern StringXColor GeometryOptions_Color[] ; @@ -159,6 +162,18 @@ void general_options_cb(Fl_Widget *w, void *data) FlGui::instance()->options->showGroup(1); } +static void general_camera_cb(Fl_Widget *w, void *data) +{ + optionWindow *o = FlGui::instance()->options; + o->activate((const char*)data); + opt_general_eye_sep_ratio(0, GMSH_SET, o->general.slider[0]->value()); + opt_general_focallength_ratio(0, GMSH_SET, o->general.slider[1]->value()); + opt_general_camera_aperture(0, GMSH_SET, o->general.slider[2]->value()); + drawContext::global()->draw(); + +} + + static void general_options_color_scheme_cb(Fl_Widget *w, void *data) { opt_general_color_scheme @@ -237,7 +252,7 @@ static void general_options_ok_cb(Fl_Widget *w, void *data) o->general.value[4]->value(z); } } - + // opt_general_axes_auto_position(0, GMSH_SET, o->general.butt[0]->value()); opt_general_small_axes(0, GMSH_SET, o->general.butt[1]->value()); opt_general_fast_redraw(0, GMSH_SET, o->general.butt[2]->value()); @@ -246,17 +261,54 @@ static void general_options_ok_cb(Fl_Widget *w, void *data) opt_general_double_buffer(0, GMSH_SET, o->general.butt[3]->value()); if(opt_general_antialiasing(0, GMSH_GET, 0) != o->general.butt[12]->value()) opt_general_antialiasing(0, GMSH_SET, o->general.butt[12]->value()); + + + + if (!CTX::instance()->stereo){ + o->general.slider[0]->deactivate(); + o->general.slider[1]->deactivate(); + } + if (!CTX::instance()->camera){ o->general.slider[2]->deactivate(); } + else{ o->general.slider[2]->activate(); } + if(opt_general_stereo_mode(0, GMSH_GET, 0) != o->general.butt[17]->value()) { opt_general_stereo_mode(0, GMSH_SET, o->general.butt[17]->value()); // when stereo mode is active camera mode is obligatory so camera button is desactivated if (CTX::instance()->stereo){ o->general.butt[18]->value(1); o->general.butt[18]->deactivate(); + o->general.slider[0]->activate(); + o->general.slider[1]->activate(); + o->general.slider[2]->activate(); + + //beginning of test to re-allocate gl for stereo : inspired from "split" method + openglWindow::setLastHandled(0); + for(unsigned int i = 0; i < FlGui::instance()->graph.size(); i++){ + graphicWindow * graph = FlGui::instance()->graph[i]; + graph->tile->clear(); + graph->gl.clear(); + openglWindow* stereo_gl=new openglWindow(0, 0, graph->tile->w() , graph->tile->h() ); + stereo_gl->mode( FL_RGB | FL_DEPTH | FL_DOUBLE | FL_STEREO) ; + stereo_gl->end(); + graph->gl.push_back(stereo_gl ); + graph->tile->add(stereo_gl); + stereo_gl->show(); + cout<<" new gl windows for stereovision"<<stereo_gl<<endl; + } + //end of test to re-allocate gl for stereo : inspired from "split" method + + + } + else { + o->general.butt[18]->activate(); + o->general.slider[0]->deactivate(); + o->general.slider[1]->deactivate(); } - else o->general.butt[18]->activate(); } if(opt_general_camera_mode(0, GMSH_GET, 0) != o->general.butt[18]->value()) { opt_general_camera_mode(0, GMSH_SET, o->general.butt[18]->value()); + if (!CTX::instance()->camera){ o->general.slider[2]->deactivate(); } + else{ o->general.slider[2]->activate(); } } opt_general_trackball(0, GMSH_SET, o->general.butt[5]->value()); @@ -342,6 +394,8 @@ static void general_arrow_param_cb(Fl_Widget *w, void *data) } } + + void geometry_options_cb(Fl_Widget *w, void *data) { FlGui::instance()->options->showGroup(2); @@ -1329,7 +1383,6 @@ optionWindow::optionWindow(int deltaFontSize) general.butt[18]->type(FL_TOGGLE_BUTTON); general.butt[18]->callback(general_options_ok_cb); - general.butt[17] = new Fl_Check_Button (L + width / 2, 2 * WB + 11 * BH, width/2-WB, BH, "Enable stereo"); general.butt[17]->type(FL_TOGGLE_BUTTON); @@ -1708,8 +1761,54 @@ optionWindow::optionWindow(int deltaFontSize) o->end(); } + + // new menu for stereo + { + Fl_Group *o = new Fl_Group + (L + WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Camera"); + o->hide(); + + general.slider[0] = new Fl_Value_Slider(L + WB+ 2.*IW /10,2* WB + BH,2* BB, BH, "Eye sep ratio (%) [default 1.5]"); + general.slider[0]->type(FL_HOR_NICE_SLIDER); + general.slider[0]->minimum(0.1); + if ( CTX::instance()->eye_sep_ratio==0.) opt_general_eye_sep_ratio(0, GMSH_SET, 1.5); + general.slider[0]->value( CTX::instance()->eye_sep_ratio); + general.slider[0]->step(.1); + general.slider[0]->callback(general_camera_cb); + general.slider[0]->maximum(10.); + + general.slider[1] = new Fl_Value_Slider(L + WB+ 2.*IW /10,4* WB +2.5* BH,2* BB, BH, "Focallength ratio [default 1.]"); + general.slider[1]->type(FL_HOR_NICE_SLIDER); + general.slider[1]->minimum(0.1); + if ( CTX::instance()->focallength_ratio==0) opt_general_focallength_ratio(0, GMSH_SET, 1.); + general.slider[1]->value( CTX::instance()->focallength_ratio); + general.slider[1]->step(.1); + general.slider[1]->callback(general_camera_cb); + general.slider[1]->maximum(10.); + + general.slider[2] = new Fl_Value_Slider(L + WB+ 2.*IW /10,4* WB +6* BH,2* BB, BH, "Camera Aperture (°) [default 40.]"); + general.slider[2]->type(FL_HOR_NICE_SLIDER); + general.slider[2]->minimum(10.); + if ( CTX::instance()->camera_aperture==0) opt_general_camera_aperture(0, GMSH_SET, 40.); + general.slider[2]->value( CTX::instance()->camera_aperture); + general.slider[2]->step(1); + general.slider[2]->callback(general_camera_cb); + general.slider[2]->maximum(120.); + + if (!CTX::instance()->stereo){ + general.slider[0]->deactivate(); + general.slider[1]->deactivate(); + } + if (!CTX::instance()->camera){ general.slider[2]->deactivate(); } + else{general.slider[2]->activate(); } + + o->end(); + + } + //end of new menu for stereo o->end(); } + general.group->end(); // Geometry options diff --git a/Fltk/optionWindow.h b/Fltk/optionWindow.h index 4c279a1ce791c56bb7ea02625512ed9b403c59c5..34b9db54780d9fb2d13be8193bff78db39d12b60 100644 --- a/Fltk/optionWindow.h +++ b/Fltk/optionWindow.h @@ -7,6 +7,7 @@ #define _OPTION_WINDOW_H_ #include <FL/Fl_Window.H> +#include <FL/Fl_Value_Slider.H> #include <FL/Fl_Hold_Browser.H> #include <FL/Fl_Button.H> #include <FL/Fl_Return_Button.H> @@ -20,6 +21,8 @@ #include "spherePositionWidget.h" #include "colorbarWindow.h" + + #define NUM_FONTS 14 extern Fl_Menu_Item menu_font_names[]; @@ -28,6 +31,7 @@ class optionWindow{ Fl_Window *win; Fl_Hold_Browser *browser; Fl_Return_Button *redraw; + struct{ Fl_Group *group; Fl_Check_Button *butt[21]; @@ -36,6 +40,7 @@ class optionWindow{ Fl_Button *color[50]; Fl_Input *input[20]; Fl_Choice *choice[20]; + Fl_Value_Slider *slider[20]; spherePositionWidget *sphere; } general; struct{ @@ -98,5 +103,5 @@ void mesh_options_cb(Fl_Widget *w, void *data); void solver_options_cb(Fl_Widget *w, void *data); void post_options_cb(Fl_Widget *w, void *data); void view_options_cb(Fl_Widget *w, void *data); - #endif + diff --git a/Graphics/Camera.cpp b/Graphics/Camera.cpp index 8458d915e13b7c0f2304508a9c6ed944d0bfe6ba..31e178551ed9c83bbbf650b335651d1e5c13fae0 100644 --- a/Graphics/Camera.cpp +++ b/Graphics/Camera.cpp @@ -3,6 +3,7 @@ #include <stdio.h> #include <math.h> #include "Camera.h" +#include "Options.h" #include "Gmsh.h" #include "GmshConfig.h" #include "GmshMessage.h" @@ -10,23 +11,30 @@ #include "Context.h" #include "drawContext.h" -Camera::~Camera(){}; + +#if defined(HAVE_FLTK) +#include <FL/Fl_JPEG_Image.H> +#include <FL/Fl_PNG_Image.H> +#endif + +using namespace std; + void Camera::init(){ on=true; glFnear=0.1 ; glFfar=10000; - // eye_sep_ratio=.015; - eye_sep_ratio=.05; - // apparent angle of the screen height - aperture = 25; - focallength = 100.; + if ( CTX::instance()->eye_sep_ratio==0 ) opt_general_eye_sep_ratio(0, GMSH_SET, 1.5); + if ( CTX::instance()->camera_aperture==0) opt_general_camera_aperture(0, GMSH_SET, 40.); + if ( CTX::instance()->focallength_ratio==0) opt_general_focallength_ratio(0, GMSH_SET, 1.); + eye_sep_ratio=CTX::instance()->eye_sep_ratio; + aperture = CTX::instance()->camera_aperture; + focallength =CTX::instance()->focallength_ratio* 100.; alongZ(); this->lookAtCg(); - eyesep=distance*eye_sep_ratio; + eyesep=distance*eye_sep_ratio/100.; ref_distance=distance; this->update(); - } void Camera::alongX(){ @@ -70,9 +78,9 @@ void Camera::lookAtCg(){ //distance=Lc*1.45; position=target-distance*view; this->update(); - focallength=distance; + focallength=focallength_ratio*distance; ref_distance=distance; - eyesep=focallength*eye_sep_ratio; + eyesep=focallength*eye_sep_ratio/100.; } void Camera::giveViewportDimension(const int& W,const int& H){ @@ -93,6 +101,11 @@ void Camera::update() { normalize(up); normalize(right); normalize(view); + aperture = CTX::instance()->camera_aperture; + focallength_ratio=CTX::instance()->focallength_ratio; + focallength=focallength_ratio*distance; + eye_sep_ratio=CTX::instance()->eye_sep_ratio; + eyesep=focallength*eye_sep_ratio/100.; radians = 0.0174532925 * aperture / 2.; wd2 = glFnear * tan(radians); ndfl = glFnear / focallength; @@ -100,14 +113,20 @@ void Camera::update() { void Camera::affiche() { + cout<<" ------------ GENERAL PARAMETERS ------------" <<endl ; + cout<<" CTX aperture "<< CTX::instance()->camera_aperture <<endl ; + cout<<" CTX eyesep ratio "<< CTX::instance()->eye_sep_ratio <<endl ; + cout<<" CTX focallength ratio "<< CTX::instance()->focallength_ratio <<endl ; cout<<" ------------ CAMERA PARAMETERS ------------" <<endl ; cout<<" position "<< position.x<<","<<position.y<<","<<position.z <<endl ; cout<<" view "<< view.x<<","<<view.y<<","<<view.z <<endl; cout<<" up "<< up.x<<","<<up.y<<","<<up.z <<endl; cout<<" right "<< right.x<<","<<right.y<<","<<right.z <<endl; cout<<" target "<< target.x<<","<<target.y<<","<<target.z <<endl; + cout<<" focallength_ratio "<<focallength_ratio <<endl; cout<<" focallength "<<focallength <<endl; cout<<" aperture "<<aperture <<endl; + cout<<" eyesep_ratio "<<eye_sep_ratio <<endl; cout<<" eyesep "<<eyesep <<endl; cout<<" screenwidth "<<screenwidth <<endl; cout<<" screenheight "<<screenheight <<endl; diff --git a/Graphics/Camera.h b/Graphics/Camera.h index adf77eec90d546db23838c088df83f87e2e0e2db..84e6b29bdd711b32eed1ffa6d50ab20378415709 100644 --- a/Graphics/Camera.h +++ b/Graphics/Camera.h @@ -56,6 +56,7 @@ public: XYZ right; /* View right direction */ XYZ target; /* center of rotation and screen */ double focallength; /* Focal Length along vd */ + double focallength_ratio; double aperture; /* Camera aperture */ double eyesep; /* Eye separation */ int screenwidth,screenheight; @@ -65,7 +66,7 @@ public: double Lc, eye_sep_ratio, closeness, ndfl, glFnear, glFfar, radians, wd2; double glFleft,glFright,glFtop,glFbottom; Camera():stereoEnable(false),on(false){}; - ~Camera(); + ~Camera(){}; void giveViewportDimension(const int& W,const int& H); void lookAtCg(); void init(); diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp index 19e5902ba028438e6a9a6a7ebbc4314900d43715..2844242eab481b3ac1d4885ba853bc5996ee4bab 100644 --- a/Graphics/drawContext.cpp +++ b/Graphics/drawContext.cpp @@ -454,9 +454,8 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick) double zmax = std::max(fabs(CTX::instance()->min[2]), fabs(CTX::instance()->max[2])); if(zmax < CTX::instance()->lc) zmax = CTX::instance()->lc; - - if ( (CTX::instance()->camera) && (!CTX::instance()->stereo) ) { // if we use the new camera mode - + + if ( CTX::instance()->camera ) { // if we use the camera mode double clip_near, clip_far; clip_near = 0.75 * CTX::instance()->clipFactor * zmax; clip_far = 75. * CTX::instance()->clipFactor * zmax; @@ -466,8 +465,11 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick) double w=(double)viewport[2]; double h=(double)viewport[3]; double ratio=w/h; - double dx=.5*w*ratio; - double dy=.5*w; + // double dx=.5*w*ratio; + // double dy=.5*w; + + double dx=1.5*tan(camera.radians)*w*ratio; + double dy=1.5*tan(camera.radians)*w; double dz=-w*1.25; glBegin(GL_QUADS); //glColor4ubv((GLubyte *) & CTX::instance()->color.bg);