From a1a0ee07e8d579e753eee567dd1ccc8500a711e4 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 5 Jan 2011 10:00:01 +0000 Subject: [PATCH] polish camera/stero modes --- Common/DefaultOptions.h | 6 + Common/Options.cpp | 38 ++--- Fltk/openglWindow.cpp | 70 ++++---- Fltk/optionWindow.cpp | 182 +++++++++------------ Fltk/optionWindow.h | 1 - Geo/GModel.cpp | 13 +- Graphics/Camera.cpp | 351 +++++++++++++++++++++------------------- Graphics/Camera.h | 38 ++--- doc/CREDITS.txt | 6 +- 9 files changed, 335 insertions(+), 370 deletions(-) diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index c5f643ff47..fe27cbf48f 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -508,6 +508,12 @@ StringXNumber GeneralOptions_Number[] = { { F|O, "Camera" , opt_general_camera_mode, 0. , "Enable camera view mode" }, + { F|O, "CameraAperture" , opt_general_camera_aperture, 40. , + "Camera aperture in degrees" }, + { F|O, "CameraEyeSeparationRatio" , opt_general_eye_sep_ratio, 1.5 , + "Eye separation ratio in % for stereo rendering" }, + { F|O, "CameraFocalLengthRatio" , opt_general_focallength_ratio, 1.0 , + "Camera Focal length ratio" }, { F, "Clip0A" , opt_general_clip0a , 1.0 , "First coefficient in equation for clipping plane 0 (`A' in `AX+BY+CZ+D=0')" }, { F, "Clip0B" , opt_general_clip0b , 0.0 , diff --git a/Common/Options.cpp b/Common/Options.cpp index 2a117c9b24..30510cd0ae 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -3695,51 +3695,49 @@ double opt_general_stereo_mode(OPT_ARGS_NUM) { if(action & GMSH_SET) CTX::instance()->stereo = (int)val; - 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[18]->deactivate(); - } - else{ - FlGui::instance()->options->general.butt[18]->activate(); - } - } + if (CTX::instance()->stereo) // when stereo mode is active camera mode is obligatory + opt_general_camera_mode(num, action, 1.); +#if defined(HAVE_FLTK) + if(FlGui::available() && (action & GMSH_GUI)) + FlGui::instance()->options->general.butt[17]->value(CTX::instance()->stereo); #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 ) ; + FlGui::instance()->options->general.value[29]->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 ) ; + FlGui::instance()->options->general.value[30]->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; + 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 ) ; + FlGui::instance()->options->general.value[31]->value + (CTX::instance()->camera_aperture); #endif - return CTX::instance()->camera_aperture ; + return CTX::instance()->camera_aperture; } double opt_general_camera_mode(OPT_ARGS_NUM) @@ -3747,9 +3745,11 @@ double opt_general_camera_mode(OPT_ARGS_NUM) if(action & GMSH_SET) CTX::instance()->camera = (int)val; #if defined(HAVE_FLTK) - if(FlGui::available() && (action & GMSH_GUI)) + if(FlGui::available() && (action & GMSH_GUI)){ FlGui::instance()->options->general.butt[18]->value (CTX::instance()->camera); + FlGui::instance()->options->activate("general_camera"); + } #endif return CTX::instance()->camera ; } diff --git a/Fltk/openglWindow.cpp b/Fltk/openglWindow.cpp index 683b0ed9d3..a2140903ef 100644 --- a/Fltk/openglWindow.cpp +++ b/Fltk/openglWindow.cpp @@ -20,7 +20,7 @@ static void lassoZoom(drawContext *ctx, mousePosition &click1, mousePosition &click2) { - if(click1.win[0] == click2.win[0] || click1.win[1] == click2.win[1]) return; + if(click1.win[0] == click2.win[0] || click1.win[1] == click2.win[1]) return; ctx->s[0] *= (double)ctx->viewport[2] / (click2.win[0] - click1.win[0]); ctx->s[1] *= (double)ctx->viewport[3] / (click2.win[1] - click1.win[1]); @@ -219,8 +219,8 @@ void openglWindow::draw() } else if(CTX::instance()->stereo){ Camera *cam = &(_ctx->camera); - if (!cam->on) cam->init(); - cam->giveViewportDimension(_ctx->viewport[2],_ctx->viewport[3]); + if(!cam->on) cam->init(); + cam->giveViewportDimension(_ctx->viewport[2], _ctx->viewport[3]); // for RED/CYAN stereo pairs but not convincing /* @@ -265,35 +265,35 @@ void openglWindow::draw() glAccum(GL_RETURN,1.0); */ - //right eye - XYZ eye = cam->eyesep / 2.0* cam->right; + // right eye + XYZ eye = cam->eyesep / 2.0 * cam->right; glMatrixMode(GL_PROJECTION); glLoadIdentity(); double left = - cam->screenratio * cam->wd2 - 0.5 * cam->eyesep * cam->ndfl; double right = cam->screenratio * cam->wd2 - 0.5 * cam->eyesep * cam->ndfl; double top = cam->wd2; double bottom = - cam->wd2; - glFrustum(left,right,bottom,top,cam->glFnear,cam->glFfar); + glFrustum(left, right, bottom, top, cam->glFnear, cam->glFfar); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_RIGHT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - gluLookAt(cam->position.x+eye.x, cam->position.y+eye.y, cam->position.z+eye.z, - cam->target.x+eye.x, cam->target.y+eye.y, cam->target.z+eye.z, - cam->up.x, cam->up.y, cam->up.z); + gluLookAt(cam->position.x+eye.x, cam->position.y+eye.y, cam->position.z+eye.z, + cam->target.x+eye.x, cam->target.y+eye.y, cam->target.z+eye.z, + cam->up.x, cam->up.y, cam->up.z); _ctx->draw3d(); _ctx->draw2d(); _drawScreenMessage(); _drawBorder(); - //left eye + // left eye glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - cam->screenratio * cam->wd2 + 0.5 * cam->eyesep * cam->ndfl; right = cam->screenratio * cam->wd2 + 0.5 * cam->eyesep * cam->ndfl; top = cam->wd2; bottom = - cam->wd2; - glFrustum(left,right,bottom,top,cam->glFnear,cam->glFfar); + glFrustum(left, right, bottom, top, cam->glFnear, cam->glFfar); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_LEFT); @@ -362,25 +362,22 @@ int openglWindow::handle(int event) _trySelectionXYWH[3] = (int)fabs(_click.win[1] - _curr.win[1]); } else{ - if (CTX::instance()->camera){ Camera * cam = &(_ctx->camera); - double dy=fabs( -_click.win[1] + _curr.win[1] ); - double dx=fabs( -_click.win[0] + _curr.win[0] ) ; - double factx = w()/ fabs(dx); - double facty = h()/ fabs(dy); - double fact = .8* std::min(factx, facty); - double x_med=( _click.win[0] + _curr.win[0])/2.; - double y_med=( _click.win[1] + _curr.win[1])/2.; - double theta_x =.96* cam->radians*( w()/2 - x_med )*2. /h() ; - double theta_y =.96* cam->radians*( h()/2 - y_med )*2. /h() ; - + double dy = fabs(-_click.win[1] + _curr.win[1]); + double dx = fabs(-_click.win[0] + _curr.win[0]); + double factx = w() / fabs(dx); + double facty = h() / fabs(dy); + double fact = .8 * std::min(factx, facty); + double x_med = (_click.win[0] + _curr.win[0]) / 2.; + double y_med = (_click.win[1] + _curr.win[1]) / 2.; + double theta_x = .96 * cam->radians * (w() / 2 - x_med) * 2. / h(); + double theta_y = .96 * cam->radians * (h() / 2 - y_med) * 2. / h(); cam->moveRight(theta_x); cam->moveUp(theta_y); _ctx->camera.zoom(fact); _ctx->camera.update(); redraw(); - } else{ lassoZoom(_ctx, _click, _curr); @@ -403,7 +400,6 @@ int openglWindow::handle(int event) _ctx->s[1] = _ctx->s[0]; _ctx->s[2] = _ctx->s[0]; redraw(); - } else if(lassoMode) { lassoMode = false; @@ -426,7 +422,6 @@ int openglWindow::handle(int event) _trySelectionXYWH[1] = (int)_curr.win[1]; _trySelectionXYWH[2] = 5; _trySelectionXYWH[3] = 5; - } } else { @@ -464,18 +459,19 @@ int openglWindow::handle(int event) double dy = Fl::event_dy(); double fact = (5. * CTX::instance()->zoomFactor * fabs(dy) + h()) / (double)h(); if (CTX::instance()->camera){ - fact= ((dy > 0) ? fact : 1./fact); + fact = ((dy > 0) ? fact : 1. / fact); _ctx->camera.zoom(fact); _ctx->camera.update(); redraw(); - }else{ + } + else{ _ctx->s[0] *= ((dy > 0) ? fact : 1./fact); _ctx->s[1] = _ctx->s[0]; _ctx->s[2] = _ctx->s[0]; _prev.recenter(_ctx); redraw(); } - } + } FlGui::instance()->manip->update(); return 1; @@ -499,33 +495,31 @@ int openglWindow::handle(int event) // (m1) and (!shift) and (!alt) => rotation else if(Fl::event_button() == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)) { - // trackball if(CTX::instance()->useTrackball) _ctx->addQuaternion((2. * _prev.win[0] - w()) / w(), (h() - 2. * _prev.win[1]) / h(), (2. * _curr.win[0] - w()) / w(), (h() - 2. * _curr.win[1]) / h()); - // !trackball else { _ctx->r[1] += ((fabs(dx) > fabs(dy)) ? 180. * dx / (double)w() : 0.); _ctx->r[0] += ((fabs(dx) > fabs(dy)) ? 0. : 180. * dy / (double)h()); } } - // m2 or (m1 and shift) => zoom (only move in y is used) + // m2 or (m1 and shift) => zoom (only move in y is used) // but start point is the center of the homothety else if(Fl::event_button() == 2 || (Fl::event_button() == 1 && Fl::event_state(FL_SHIFT))) { - // zoom isotrop in camera mode + // isotrop zoom in camera mode if (CTX::instance()->camera){ - double dy= (int)_curr.win[1] - (int)_prev.win[1] ; - double fact =( CTX::instance()->zoomFactor * fabs(dy) +(double) h()) / (double)h(); + double dy= (int)_curr.win[1] - (int)_prev.win[1]; + double fact = (CTX::instance()->zoomFactor * fabs(dy) + (double)h()) / (double)h(); fact= ((dy > 0) ? fact : 1./fact); _ctx->camera.zoom(fact); _ctx->camera.update(); redraw(); } else{ - // move in y greater than move in x + // move in y greater than move in x if(fabs(dy) > fabs(dx)) { double fact = (CTX::instance()->zoomFactor * fabs(dy) + h()) / (double)h(); _ctx->s[0] *= ((dy > 0) ? fact : 1./fact); @@ -533,18 +527,16 @@ int openglWindow::handle(int event) _ctx->s[2] = _ctx->s[0]; _click.recenter(_ctx); } - // trackball else if(!CTX::instance()->useTrackball) _ctx->r[2] += -180. * dx / (double)w(); } - } // other case => translation else { if (CTX::instance()->camera){ Camera * cam= &(_ctx->camera); - double theta_x=cam->radians*( -(double)_prev.win[0]+ (double)_curr.win[0] )*2. /h() ; - double theta_y=cam->radians*( -(double)_prev.win[1]+ (double)_curr.win[1] )*2. /h() ; + double theta_x = cam->radians * (-(double)_prev.win[0] + (double)_curr.win[0]) * 2. / h(); + double theta_y = cam->radians * (-(double)_prev.win[1] + (double)_curr.win[1]) * 2. / h(); cam->moveRight(theta_x); cam->moveUp(theta_y); } diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp index 89530c4628..59ef8b1152 100644 --- a/Fltk/optionWindow.cpp +++ b/Fltk/optionWindow.cpp @@ -25,7 +25,6 @@ #include "PViewOptions.h" #include "OS.h" #include "Context.h" -// #include "graphicWindow.h" #include "openglWindow.h" @@ -162,18 +161,6 @@ 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 @@ -252,7 +239,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()); @@ -261,56 +248,6 @@ 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(); - } - } - 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()); opt_general_terminal(0, GMSH_SET, o->general.butt[7]->value()); double sessionrc = opt_general_session_save(0, GMSH_GET, 0); @@ -374,6 +311,31 @@ static void general_options_ok_cb(Fl_Widget *w, void *data) opt_general_axes(0, GMSH_SET, o->general.choice[4]->value()); opt_general_background_gradient(0, GMSH_SET, o->general.choice[5]->value()); + opt_general_eye_sep_ratio(0, GMSH_SET, o->general.value[29]->value()); + opt_general_focallength_ratio(0, GMSH_SET, o->general.value[30]->value()); + opt_general_camera_aperture(0, GMSH_SET, o->general.value[31]->value()); + opt_general_camera_mode(0, GMSH_SET, o->general.butt[18]->value()); + 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()); + // beginning of test to re-allocate gl for stereo: inspired from + // "split" method + if (CTX::instance()->stereo){ + 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(); + Msg::Info("new gl windows for stereo vision!"); + } + } + } + if(CTX::instance()->fastRedraw) CTX::instance()->post.draw = CTX::instance()->mesh.draw = 0; drawContext::global()->draw(); @@ -394,8 +356,6 @@ 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); @@ -1378,16 +1338,6 @@ optionWindow::optionWindow(int deltaFontSize) general.value[10]->align(FL_ALIGN_RIGHT); general.value[10]->callback(general_options_ok_cb, (void*)"rotation_center_coord"); - general.butt[18] = new Fl_Check_Button - (L + 2 * WB, 2 * WB + 11 * BH, width/2-WB, BH, "Enable camera"); - 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); - general.butt[17]->callback(general_options_ok_cb); - o->end(); } { @@ -1761,47 +1711,45 @@ 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.butt[18] = new Fl_Check_Button + (L + 2 * WB, 2 * WB + 1 * BH, BW, BH, "Enable camera (experimental)"); + general.butt[18]->type(FL_TOGGLE_BUTTON); + general.butt[18]->callback(general_options_ok_cb, (void*)"general_camera"); + + general.butt[17] = new Fl_Check_Button + (L + 2 * WB, 2 * WB + 2 * BH, BW, BH, "Enable stereo rendering (experimental)"); + general.butt[17]->type(FL_TOGGLE_BUTTON); + general.butt[17]->callback(general_options_ok_cb); + + general.value[29] = new Fl_Value_Input + (L + 2 * WB, 2 * WB + 3 * BH, IW, BH, "Eye separation ratio (%)"); + general.value[29]->minimum(0.1); + general.value[29]->maximum(10.); + general.value[29]->step(.1); + general.value[29]->align(FL_ALIGN_RIGHT); + general.value[29]->callback(general_options_ok_cb); + + general.value[30] = new Fl_Value_Input + (L + 2 * WB, 2 * WB + 4 * BH, IW, BH, "Focal length ratio (%)"); + general.value[30]->minimum(0.1); + general.value[30]->maximum(10.); + general.value[30]->step(.1); + general.value[30]->align(FL_ALIGN_RIGHT); + general.value[30]->callback(general_options_ok_cb); - 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.); + general.value[31] = new Fl_Value_Input + (L + 2 * WB, 2 * WB + 5 * BH, IW, BH, "Camera Aperture (degrees)"); + general.value[31]->minimum(10.); + general.value[31]->maximum(120.); + general.value[31]->step(1); + general.value[31]->align(FL_ALIGN_RIGHT); + general.value[31]->callback(general_options_ok_cb); - 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(); } @@ -3704,6 +3652,20 @@ void optionWindow::activate(const char *what) general.value[27]->deactivate(); } } + else if(!strcmp(what, "general_camera")){ + if(general.butt[18]->value()){ + general.butt[17]->activate(); + general.value[29]->activate(); + general.value[30]->activate(); + general.value[31]->activate(); + } + else{ + general.butt[17]->deactivate(); + general.value[29]->deactivate(); + general.value[30]->deactivate(); + general.value[31]->deactivate(); + } + } else if(!strcmp(what, "geo_transform")){ if(geo.choice[3]->value() == 1){ for(int i = 7; i <= 18; i++) diff --git a/Fltk/optionWindow.h b/Fltk/optionWindow.h index 34b9db5478..a321aab0de 100644 --- a/Fltk/optionWindow.h +++ b/Fltk/optionWindow.h @@ -40,7 +40,6 @@ class optionWindow{ Fl_Button *color[50]; Fl_Input *input[20]; Fl_Choice *choice[20]; - Fl_Value_Slider *slider[20]; spherePositionWidget *sphere; } general; struct{ diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 2e0a1c3a5e..945e5bb82f 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1833,18 +1833,22 @@ GEdge *GModel::addNURBS(GVertex *start, GVertex *end, std::vector<std::vector<double> > points, std::vector<double> knots, std::vector<double> weights, - std::vector<int> mult){ + std::vector<int> mult) +{ if(_factory) return _factory->addNURBS(this, start,end,points,knots,weights, mult); return 0; } -void GModel::addRuledFaces (std::vector<std::vector<GEdge *> > edges){ +void GModel::addRuledFaces (std::vector<std::vector<GEdge *> > edges) +{ if(_factory) _factory->addRuledFaces(this, edges); } -GFace* GModel::addFace (std::vector<GEdge *> edges, std::vector< std::vector<double > > points){ +GFace* GModel::addFace (std::vector<GEdge *> edges, + std::vector< std::vector<double > > points) +{ if(_factory) return _factory->addFace(this, edges, points); return 0; @@ -1921,7 +1925,8 @@ void GModel::createBoundaryLayer(std::vector<GEntity *> e, double h) #endif } -GEntity *GModel::addPipe(GEntity *e, std::vector<GEdge *> edges){ +GEntity *GModel::addPipe(GEntity *e, std::vector<GEdge *> edges) +{ if(_factory) return _factory->addPipe(this,e,edges); return 0; diff --git a/Graphics/Camera.cpp b/Graphics/Camera.cpp index 31e178551e..fdd2cb0b2c 100644 --- a/Graphics/Camera.cpp +++ b/Graphics/Camera.cpp @@ -1,9 +1,15 @@ +// Gmsh - Copyright (C) 1997-2010 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to <gmsh@geuz.org>. +// +// Contributed by Gilles Marckmann <gilles.marckmann@ec-nantes.fr> + #include <string> #include <iostream> #include <stdio.h> #include <math.h> #include "Camera.h" -#include "Options.h" #include "Gmsh.h" #include "GmshConfig.h" #include "GmshMessage.h" @@ -11,272 +17,279 @@ #include "Context.h" #include "drawContext.h" - -#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; - 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; +void Camera::init() +{ + on = true; + glFnear = 0.1 ; + glFfar = 10000; + eye_sep_ratio = CTX::instance()->eye_sep_ratio; aperture = CTX::instance()->camera_aperture; - focallength =CTX::instance()->focallength_ratio* 100.; + focallength = CTX::instance()->focallength_ratio * 100.; alongZ(); this->lookAtCg(); - eyesep=distance*eye_sep_ratio/100.; + eyesep = distance * eye_sep_ratio / 100.; ref_distance=distance; this->update(); } -void Camera::alongX(){ - view.set(-1.,0.,0.); +void Camera::alongX() +{ + view.set(-1., 0., 0.); up.set(0., 0., 1); - position=target-distance*view; + position = target-distance * view; this->update(); } -void Camera::alongY(){ - view.set(0.,-1.,0.); + +void Camera::alongY() +{ + view.set(0., -1., 0.); up.set(1., 0., 0); - position=target-distance*view; + position = target-distance * view; this->update(); } -void Camera::alongZ(){ - view.set(0.,0.,-1.); + +void Camera::alongZ() +{ + view.set(0., 0., -1.); up.set(0., 1., 0); - position=target-distance*view; + position = target-distance * view; this->update(); } -void Camera::tiltHeadLeft(){ - up=-1.*right; + +void Camera::tiltHeadLeft() +{ + up = -1. * right; update(); } -void Camera::tiltHeadRight(){ - up=right; + +void Camera::tiltHeadRight() +{ + up = right; update(); } - - -void Camera::lookAtCg(){ - target.x=CTX::instance()->cg[0]; - target.y=CTX::instance()->cg[1]; - target.z=CTX::instance()->cg[2]; - double W=CTX::instance()->max[0]-CTX::instance()->min[0]; - double H=CTX::instance()->max[1]-CTX::instance()->min[1]; - double P=CTX::instance()->max[2]-CTX::instance()->min[2]; - Lc=sqrt(1.*W*W+1.*H*H+1.*P*P); - distance=.8*fabs(.5*Lc*4./3./tan(aperture*.01745329/2.)); - //distance=Lc*1.45; - position=target-distance*view; +void Camera::lookAtCg() +{ + target.x = CTX::instance()->cg[0]; + target.y = CTX::instance()->cg[1]; + target.z = CTX::instance()->cg[2]; + double W = CTX::instance()->max[0] - CTX::instance()->min[0]; + double H = CTX::instance()->max[1] - CTX::instance()->min[1]; + double P = CTX::instance()->max[2] - CTX::instance()->min[2]; + Lc = sqrt(1. * W * W + 1. * H * H + 1. * P * P); + distance = .8 * fabs(.5 * Lc * 4. / 3. / tan(aperture * .01745329 / 2.)); + position = target - distance * view; this->update(); - focallength=focallength_ratio*distance; - ref_distance=distance; - eyesep=focallength*eye_sep_ratio/100.; + focallength = focallength_ratio * distance; + ref_distance = distance; + eyesep = focallength * eye_sep_ratio / 100.; } -void Camera::giveViewportDimension(const int& W,const int& H){ - screenwidth=W; - screenheight=H; - screenratio=(double)W/(double)H; - glFleft =-screenratio*wd2; - glFright = screenratio*wd2; - glFtop = wd2; - glFbottom =-wd2; +void Camera::giveViewportDimension(const int& W,const int& H) +{ + screenwidth = W; + screenheight = H; + screenratio = (double)W / (double)H; + glFleft = -screenratio * wd2; + glFright = screenratio * wd2; + glFtop = wd2; + glFbottom = -wd2; } -void Camera::update() { - right.x=view.y*up.z-view.z*up.y; - right.y=view.z*up.x-view.x*up.z; - right.z=view.x*up.y-view.y*up.x; - ref_distance=distance; +void Camera::update() +{ + right.x = view.y * up.z - view.z * up.y; + right.y = view.z * up.x - view.x * up.z; + right.z = view.x * up.y - view.y * up.x; + ref_distance = distance; 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.; + 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; + ndfl = glFnear / focallength; } - -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; - cout<<" distance "<<distance <<endl; - cout<<" ref_distance "<<ref_distance <<endl; - cout<<" button_left_down "<<button_left_down <<endl; - cout<<" button_middle_down "<< button_middle_down <<endl; - cout<<" button_right_down "<< button_right_down <<endl; - cout<<" stereoEnable "<< stereoEnable <<endl; - cout<<" Lc "<< Lc<<endl; - cout<<" eye_sep_ratio "<<eye_sep_ratio <<endl; - cout<<" closeness "<< closeness<<endl; - cout<<" glFnear "<< glFnear <<endl; - cout<<" glFfar "<< glFfar <<endl; - cout<<" radians "<<radians <<endl; - cout<<" wd2 "<<wd2 <<endl; +void Camera::affiche() +{ + std::cout<<" ------------ GENERAL PARAMETERS ------------" <<std::endl ; + std::cout<<" CTX aperture "<< CTX::instance()->camera_aperture <<std::endl ; + std::cout<<" CTX eyesep ratio "<< CTX::instance()->eye_sep_ratio <<std::endl ; + std::cout<<" CTX focallength ratio "<< CTX::instance()->focallength_ratio <<std::endl ; + std::cout<<" ------------ CAMERA PARAMETERS ------------" <<std::endl ; + std::cout<<" position "<< position.x<<","<<position.y<<","<<position.z <<std::endl ; + std::cout<<" view "<< view.x<<","<<view.y<<","<<view.z <<std::endl; + std::cout<<" up "<< up.x<<","<<up.y<<","<<up.z <<std::endl; + std::cout<<" right "<< right.x<<","<<right.y<<","<<right.z <<std::endl; + std::cout<<" target "<< target.x<<","<<target.y<<","<<target.z <<std::endl; + std::cout<<" focallength_ratio "<<focallength_ratio <<std::endl; + std::cout<<" focallength "<<focallength <<std::endl; + std::cout<<" aperture "<<aperture <<std::endl; + std::cout<<" eyesep_ratio "<<eye_sep_ratio <<std::endl; + std::cout<<" eyesep "<<eyesep <<std::endl; + std::cout<<" screenwidth "<<screenwidth <<std::endl; + std::cout<<" screenheight "<<screenheight <<std::endl; + std::cout<<" distance "<<distance <<std::endl; + std::cout<<" ref_distance "<<ref_distance <<std::endl; + std::cout<<" button_left_down "<<button_left_down <<std::endl; + std::cout<<" button_middle_down "<< button_middle_down <<std::endl; + std::cout<<" button_right_down "<< button_right_down <<std::endl; + std::cout<<" stereoEnable "<< stereoEnable <<std::endl; + std::cout<<" Lc "<< Lc<<std::endl; + std::cout<<" eye_sep_ratio "<<eye_sep_ratio <<std::endl; + std::cout<<" closeness "<< closeness<<std::endl; + std::cout<<" glFnear "<< glFnear <<std::endl; + std::cout<<" glFfar "<< glFfar <<std::endl; + std::cout<<" radians "<<radians <<std::endl; + std::cout<<" wd2 "<<wd2 <<std::endl; } - - -void Camera::moveRight(double& theta) { +void Camera::moveRight(double& theta) +{ this->update(); - position=position-distance*tan(theta)*right; - target=position+distance*view; + position = position-distance * tan(theta) * right; + target = position + distance * view; this->update(); } - -void Camera::moveUp(double& theta) { +void Camera::moveUp(double& theta) +{ this->update(); - position=position+distance*tan(theta)*up; - target=position+distance*view; + position = position+distance * tan(theta) * up; + target = position+distance * view; this->update(); } - -void Camera::zoom(double& factor) { - distance=fabs(1./factor*ref_distance); - position=target-distance*view; +void Camera::zoom(double& factor) +{ + distance = fabs(1. / factor * ref_distance); + position = target - distance * view; } - -void Camera::rotate(double* q) { +void Camera::rotate(double* q) +{ this->update(); // rotation projection in global coordinates Quaternion omega; - omega.x=q[0]*right.x+q[1]*up.x-q[2]*view.x ; - omega.y=q[0]*right.y+q[1]*up.y-q[2]*view.y ; - omega.z=q[0]*right.z+q[1]*up.z-q[2]*view.z ; - omega.w=q[3]; + omega.x = q[0] * right.x + q[1] * up.x - q[2] * view.x; + omega.y = q[0] * right.y + q[1] * up.y - q[2] * view.y; + omega.z = q[0] * right.z + q[1] * up.z - q[2] * view.z; + omega.w = q[3]; // normalize the axe of rotation in the Quaternion omega if not null - double sina=sin(acos(omega.w)); + double sina = sin(acos(omega.w)); double length; if (sina != 0.){ - length=(omega.x*omega.x+omega.y*+omega.y+omega.z*omega.z)/(sina*sina); + length = (omega.x * omega.x + omega.y * omega.y + omega.z * omega.z) / (sina * sina); } else{ - length=0.; + length = 0.; } - length=sqrt(length); + length = sqrt(length); if (length!=0.){ - omega.x/=length; - omega.y/=length; - omega.z/=length; - Quaternion conj=conjugate(omega); - view=omega*view*conj; - up=omega*up*conj; - right=omega*right*conj; + omega.x /= length; + omega.y /= length; + omega.z /= length; + Quaternion conj = conjugate(omega); + view = omega * view * conj; + up = omega * up * conj; + right = omega * right * conj; normalize(view); normalize(up); normalize(right); //actualize camera position - position=target-distance*view; + position = target - distance * view; } this->update(); } - - - - // Quaternion and XYZ functions -double length(Quaternion &q) { return sqrt(q.x*q.x+q.y*q.y+q.z*q.z+q.w*q.w); } +double length(Quaternion &q) +{ + return sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); +} -double length(XYZ &p) { return sqrt(p.x*p.x+p.y*p.y+p.z*p.z);} +double length(XYZ &p) +{ + return sqrt(p.x * p.x + p.y * p.y + p.z * p.z); +} void normalize(Quaternion &quat) { double L = length(quat); - quat.x /= L; quat.y /= L; quat.z /= L; quat.w /= L; + quat.x /= L; quat.y /= L; quat.z /= L; quat.w /= L; } -void normalize(XYZ &p){ +void normalize(XYZ &p) +{ double L = length(p); - p.x /= L; p.y /= L; p.z /= L; + p.x /= L; p.y /= L; p.z /= L; } -XYZ::XYZ (const Quaternion &R):x(R.x), y(R.y), z(R.z){} +XYZ::XYZ (const Quaternion &R) : x(R.x), y(R.y), z(R.z){} -XYZ::XYZ(double _x,double _y,double _z):x(_x),y(_y),z(_z){} +XYZ::XYZ(double _x,double _y,double _z) : x(_x),y(_y),z(_z){} -void XYZ::set(const double& _x,const double& _y,const double& _z){x=_x;y=_y;z=_z;} +void XYZ::set(const double& _x, const double& _y, const double& _z){ x = _x; y =_y; z = _z; } -void rotate(Quaternion omega,XYZ axe) { +void rotate(Quaternion omega,XYZ axe) +{ XYZ new_axe; Quaternion qaxe,new_qaxe; - qaxe.x=axe.x; qaxe.y=axe.y; qaxe.z=axe.z; qaxe.w=0.; - new_qaxe=mult(mult(omega,qaxe),conjugate(omega)); - axe.x=new_qaxe.x ; axe.y=new_qaxe.y; axe.z=new_qaxe.z; + qaxe.x = axe.x; qaxe.y = axe.y; qaxe.z = axe.z; qaxe.w = 0.; + new_qaxe = mult(mult(omega, qaxe), conjugate(omega)); + axe.x = new_qaxe.x; axe.y = new_qaxe.y; axe.z = new_qaxe.z; } -XYZ operator* (const double &a,const XYZ &T){ +XYZ operator* (const double &a, const XYZ &T) +{ XYZ res(T); - res.x*=a; - res.y*=a; - res.z*=a; + res.x *= a; + res.y *= a; + res.z *= a; return res; } -XYZ operator+ (const XYZ &L,const XYZ &R){ + +XYZ operator+ (const XYZ &L, const XYZ &R) +{ XYZ res(L); - res.x+=R.x; - res.y+=R.y; - res.z+=R.z; + res.x += R.x; + res.y += R.y; + res.z += R.z; return res; } -XYZ operator- (const XYZ &L,const XYZ &R){ +XYZ operator- (const XYZ &L, const XYZ &R) +{ XYZ res(L); - res.x-=R.x; - res.y-=R.y; - res.z-=R.z; + res.x -= R.x; + res.y -= R.y; + res.z -= R.z; return res; } -Quaternion::Quaternion(const XYZ &R):x(R.x), y(R.y), z(R.z),w(0.){} +Quaternion::Quaternion(const XYZ &R) : x(R.x), y(R.y), z(R.z), w(0.) {} -Quaternion mult(const Quaternion& A,const Quaternion& B) +Quaternion mult(const Quaternion& A, const Quaternion& B) { Quaternion C; - C.x = A.w*B.x + A.x*B.w + A.y*B.z - A.z*B.y; - C.y = A.w*B.y - A.x*B.z + A.y*B.w + A.z*B.x; - C.z = A.w*B.z + A.x*B.y - A.y*B.x + A.z*B.w; - C.w = A.w*B.w - A.x*B.x - A.y*B.y - A.z*B.z; + C.x = A.w * B.x + A.x * B.w + A.y * B.z - A.z * B.y; + C.y = A.w * B.y - A.x * B.z + A.y * B.w + A.z * B.x; + C.z = A.w * B.z + A.x * B.y - A.y * B.x + A.z * B.w; + C.w = A.w * B.w - A.x * B.x - A.y * B.y - A.z * B.z; return C; } -Quaternion operator *(const Quaternion& A,const Quaternion& B){ - return mult(A,B); +Quaternion operator *(const Quaternion& A, const Quaternion& B) +{ + return mult(A, B); } -Quaternion conjugate(Quaternion quat) { - quat.x = -quat.x; quat.y = -quat.y; quat.z = -quat.z; +Quaternion conjugate(Quaternion quat) +{ + quat.x = -quat.x; quat.y = -quat.y; quat.z = -quat.z; return quat; } diff --git a/Graphics/Camera.h b/Graphics/Camera.h index 84e6b29bdd..019c9a82cb 100644 --- a/Graphics/Camera.h +++ b/Graphics/Camera.h @@ -1,13 +1,13 @@ +// Gmsh - Copyright (C) 1997-2010 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to <gmsh@geuz.org>. +// +// Contributed by Gilles Marckmann <gilles.marckmann@ec-nantes.fr> #ifndef _CAMERA_H_ #define _CAMERA_H_ - -/* -typedef struct { - double x,y,z,w; -} Quaternion; -*/ class Quaternion; class XYZ { @@ -15,13 +15,11 @@ public: XYZ(){}; ~XYZ(){}; XYZ(double _x,double _y,double _z); - double x,y,z; - // double length(XYZ &p); - // void normalize(XYZ &p); - // void rotate(Quaternion omega,XYZ axe) ; + double x, y, z; void set(const double & _x, const double & _y ,const double & _z); XYZ (const Quaternion &R); }; + double length(XYZ &p); void normalize(XYZ &p); void rotate(Quaternion omega,XYZ axe) ; @@ -29,13 +27,12 @@ XYZ operator* (const double &a,const XYZ &T); XYZ operator+ (const XYZ &L,const XYZ &R); XYZ operator- (const XYZ &L,const XYZ &R); - class Quaternion{ public: double x,y,z,w; Quaternion(){}; ~Quaternion(){}; - Quaternion (const XYZ &R); + Quaternion(const XYZ &R); }; double length(Quaternion &quat); @@ -44,11 +41,8 @@ Quaternion conjugate(Quaternion quat); Quaternion mult(const Quaternion& A,const Quaternion& B); Quaternion operator *(const Quaternion &A, const Quaternion &B); - -using namespace std; - class Camera { -public: + public: bool on; XYZ position; /* camera position */ XYZ view; /* View direction vector */ @@ -65,8 +59,8 @@ public: bool stereoEnable; double Lc, eye_sep_ratio, closeness, ndfl, glFnear, glFfar, radians, wd2; double glFleft,glFright,glFtop,glFbottom; - Camera():stereoEnable(false),on(false){}; - ~Camera(){}; + Camera() : stereoEnable(false), on(false) {} + ~Camera(){} void giveViewportDimension(const int& W,const int& H); void lookAtCg(); void init(); @@ -83,9 +77,8 @@ public: void tiltHeadRight(); }; - class mouseAndKeyboard { -public: + public: bool button_left_down; bool button_middle_down; bool button_right_down; @@ -95,9 +88,4 @@ public: ~mouseAndKeyboard() {}; }; - - - - - #endif diff --git a/doc/CREDITS.txt b/doc/CREDITS.txt index 41e60ebb27..6fcf6e5175 100644 --- a/doc/CREDITS.txt +++ b/doc/CREDITS.txt @@ -19,9 +19,9 @@ connection), Matt Gundry (Plot3d mesh format), Matti Pellikka (Homology), Nicolas Tardieu (Netgen), Pascale Noyret (MED mesh format), Pierre Badel (root finding and minimization), Ruth Sabariego (pyramids), Stephen Guzik (CGNS and partitioners), Bastien Gorissen -(parallel remote), Eric Bechet (solver). See comments in the sources -for more information. If we forgot to list your contributions please -send us an email! +(parallel remote), Eric Bechet (solver), Gilles Marckmann (camera and +stero mode). See comments in the sources for more information. If we +forgot to list your contributions please send us an email! The AVL tree code (Common/avl.*) and the YUV image code (Graphics/gl2yuv.*) are copyright (C) 1988-1993, 1995 The Regents of -- GitLab