00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <map>
00012
00013 using namespace std;
00014
00015 #include "std/support.H"
00016 #include "glew/glew.H"
00017
00018 #include "geom/winsys.H"
00019 #include "glui/glui.h"
00020
00021 #include "gtex/line_drawing.H"
00022 #include "gtex/curvature_texture.H"
00023
00024 #include "curvature_ui.H"
00025
00026
00027
00028
00029
00030 class CurvatureUI {
00031
00032 public:
00033
00034 CurvatureUI(VIEWptr v);
00035
00036 ~CurvatureUI();
00037
00038 bool is_vis();
00039
00040 bool show();
00041 bool hide();
00042
00043 bool update();
00044
00045 static void checkbox_cb(int id);
00046 static void slider_cb(int id);
00047 static void radiogroup_cb(int id);
00048
00049 private:
00050
00051 void build();
00052 void destroy();
00053
00054 VIEWptr view;
00055
00056 GLUI *glui;
00057
00058 enum rollout_ids_t {
00059 ROLLOUT_LINE_DRAWING,
00060 ROLLOUT_CURVATURE_VIS,
00061 ROLLOUT_CURVATURE_GAUSSIAN_FILTER,
00062 ROLLOUT_CURVATURE_MEAN_FILTER,
00063 ROLLOUT_CURVATURE_RADIAL_FILTER
00064 };
00065
00066 typedef map<rollout_ids_t, GLUI_Rollout*> rollout_map_t;
00067 rollout_map_t rollouts;
00068
00069 enum checkbox_ids_t {
00070 CHECKBOX_DRAW_CONTOURS,
00071 CHECKBOX_DRAW_SUGCONTOURS,
00072 CHECKBOX_DRAW_COLOR,
00073 CHECKBOX_DRAW_GAUSSIAN_CURVATURE,
00074 CHECKBOX_DRAW_MEAN_CURVATURE,
00075 CHECKBOX_DRAW_RADIAL_CURVATURE
00076 };
00077
00078 typedef map<checkbox_ids_t, GLUI_Checkbox*> checkbox_map_t;
00079 checkbox_map_t checkboxes;
00080
00081 enum slider_ids_t {
00082 SLIDER_SC_THRESH
00083 };
00084
00085 typedef map<slider_ids_t, GLUI_Slider*> slider_map_t;
00086 slider_map_t sliders;
00087
00088 enum radiogroup_ids_t {
00089 RADIOGROUP_GAUSSIAN_FILTER,
00090 RADIOGROUP_MEAN_FILTER,
00091 RADIOGROUP_RADIAL_FILTER
00092 };
00093
00094 typedef map<radiogroup_ids_t, GLUI_RadioGroup*> radiogroup_map_t;
00095 radiogroup_map_t radiogroups;
00096
00097 enum radiobutton_ids_t {
00098 RADIOBUTTON_GAUSSIAN_FILTER_NONE,
00099 RADIOBUTTON_GAUSSIAN_FILTER_GAUSSIAN,
00100 RADIOBUTTON_GAUSSIAN_FILTER_MEAN,
00101 RADIOBUTTON_GAUSSIAN_FILTER_RADIAL,
00102 RADIOBUTTON_MEAN_FILTER_NONE,
00103 RADIOBUTTON_MEAN_FILTER_GAUSSIAN,
00104 RADIOBUTTON_MEAN_FILTER_MEAN,
00105 RADIOBUTTON_MEAN_FILTER_RADIAL,
00106 RADIOBUTTON_RADIAL_FILTER_NONE,
00107 RADIOBUTTON_RADIAL_FILTER_GAUSSIAN,
00108 RADIOBUTTON_RADIAL_FILTER_MEAN,
00109 RADIOBUTTON_RADIAL_FILTER_RADIAL
00110 };
00111
00112 typedef map<radiobutton_ids_t, GLUI_RadioButton*> radiobutton_map_t;
00113 radiobutton_map_t radiobuttons;
00114
00115 CurvatureUI(const CurvatureUI &);
00116 CurvatureUI &operator=(const CurvatureUI &);
00117
00118 };
00119
00120
00121
00122 CurvatureUISingleton::CurvatureUISingleton()
00123 : _sc_thresh(0.05),
00124 _line_drawing_draw_contours(true),
00125 _line_drawing_draw_sugcontours(true),
00126 _line_drawing_draw_color(false),
00127 _curvature_draw_gaussian_curv(true),
00128 _curvature_draw_mean_curv(true),
00129 _curvature_draw_radial_curv(true),
00130 _curvature_gaussian_filter(CurvatureTexture::FILTER_NONE),
00131 _curvature_mean_filter(CurvatureTexture::FILTER_NONE),
00132 _curvature_radial_filter(CurvatureTexture::FILTER_NONE)
00133 {
00134
00135 }
00136
00137 CurvatureUISingleton::~CurvatureUISingleton()
00138 {
00139
00140 view2ui_map_t::iterator itor = view2ui_map.begin();
00141
00142 for(;itor != view2ui_map.end(); ++itor){
00143
00144 delete itor->second;
00145
00146 }
00147
00148 }
00149
00150 bool
00151 CurvatureUISingleton::is_vis(CVIEWptr& v)
00152 {
00153
00154 CurvatureUI *cui = fetch(v);
00155
00156 if (!cui){
00157
00158 err_msg("CurvatureUISingleton::is_vis() - Error! Failed to fetch CurvatureUI!");
00159 return false;
00160
00161 }
00162
00163 return cui->is_vis();
00164
00165 }
00166
00167 bool
00168 CurvatureUISingleton::show(CVIEWptr& v)
00169 {
00170
00171 CurvatureUI *cui = fetch(v);
00172
00173 if(!cui){
00174
00175 err_msg("CurvatureUISingleton::show() - Error! Failed to fetch CurvatureUI!");
00176 return false;
00177
00178 }
00179
00180 if(!cui->show()){
00181
00182 err_msg("CurvatureUISingleton::show() - Error! Failed to show CurvatureUI!");
00183 return false;
00184
00185 } else {
00186
00187 err_msg("CurvatureUISingleton::show() - Sucessfully showed CurvatureUI.");
00188 return true;
00189
00190 }
00191
00192 }
00193
00194 bool
00195 CurvatureUISingleton::hide(CVIEWptr& v)
00196 {
00197
00198 CurvatureUI *cui = fetch(v);
00199
00200 if(!cui){
00201
00202 err_msg("CurvatureUISingleton::hide() - Error! Failed to fetch CurvatureUI!");
00203 return false;
00204
00205 }
00206
00207 if(!cui->hide()){
00208
00209 err_msg("CurvatureUISingleton::hide() - Error! Failed to hide CurvatureUI!");
00210 return false;
00211
00212 } else {
00213
00214 err_msg("CurvatureUISingleton::hide() - Sucessfully hid CurvatureUI.");
00215 return true;
00216
00217 }
00218
00219 }
00220
00221 bool
00222 CurvatureUISingleton::update(CVIEWptr& v)
00223 {
00224
00225 CurvatureUI *cui = fetch(v);
00226
00227 if (!cui){
00228
00229 err_msg("CurvatureUISingleton::update() - Error! Failed to fetch CurvatureUI!");
00230 return false;
00231
00232 }
00233
00234 if (!cui->update()){
00235
00236 err_msg("CurvatureUISingleton::update() - Error! Failed to update CurvatureUI!");
00237 return false;
00238
00239 } else {
00240
00241 err_msg("CurvatureUISingleton::update() - Sucessfully updated CurvatureUI.");
00242 return true;
00243
00244 }
00245
00246 }
00247
00248 CurvatureUI*
00249 CurvatureUISingleton::fetch(CVIEWptr& v)
00250 {
00251
00252 if (!v) {
00253 err_msg("CurvatureUISingleton::fetch() - Error! view is nil");
00254 return 0;
00255 }
00256 if (!v->impl()) {
00257 err_msg("CurvatureUISingleton::fetch() - Error! view->impl() is nil");
00258 return 0;
00259 }
00260
00261 view2ui_map_t::iterator v2ui_itor = view2ui_map.find(v->impl());
00262
00263 if(v2ui_itor != view2ui_map.end()){
00264
00265 return v2ui_itor->second;
00266
00267 } else {
00268
00269 CurvatureUI *cui = new CurvatureUI(v);
00270
00271 view2ui_map.insert(make_pair(v->impl(), cui));
00272
00273 return cui;
00274
00275 }
00276
00277 }
00278
00279
00280
00281 CurvatureUI::CurvatureUI(VIEWptr v)
00282 : view(v), glui(0)
00283 {
00284
00285 }
00286
00287 CurvatureUI::~CurvatureUI()
00288 {
00289
00290 if(glui) destroy();
00291
00292 }
00293
00294 bool
00295 CurvatureUI::is_vis()
00296 {
00297
00298 return glui != 0;
00299
00300 }
00301
00302 bool
00303 CurvatureUI::show()
00304 {
00305
00306 if(glui){
00307
00308 cerr << "CurvatureUI::show() - Error! CurvatureUI is already shown!" << endl;
00309 return false;
00310
00311 } else {
00312
00313 build();
00314
00315 if(!glui){
00316
00317 cerr << "CurvatureUI::show() - Error! CurvatureUI failed to build GLUI object!"
00318 << endl;
00319 return false;
00320
00321 } else {
00322
00323 glui->show();
00324
00325
00326
00327
00328
00329 glui->sync_live();
00330
00331 return true;
00332
00333 }
00334
00335 }
00336
00337 }
00338
00339 bool
00340 CurvatureUI::hide()
00341 {
00342
00343 if(!glui){
00344
00345 cerr << "CurvatureUI::hide() - Error! CurvatureUI is already hidden!" << endl;
00346 return false;
00347
00348 } else {
00349
00350 glui->hide();
00351
00352 destroy();
00353
00354 assert(!glui);
00355
00356 return true;
00357
00358 }
00359
00360 }
00361
00362 bool
00363 CurvatureUI::update()
00364 {
00365
00366 if(!glui){
00367
00368 cerr << "CurvatureUI::update() - Error! No GLUI object to update (not showing)!"
00369 << endl;
00370 return false;
00371
00372 } else {
00373
00374
00375
00376
00377
00378 glui->sync_live();
00379
00380 return true;
00381
00382 }
00383
00384 }
00385
00386 void CurvatureUI::checkbox_cb(int id)
00387 {
00388
00389 checkbox_ids_t enum_id = static_cast<checkbox_ids_t>(id);
00390
00391 CurvatureUI *cui = CurvatureUISingleton::Instance().fetch(VIEW::peek());
00392
00393
00394 assert(cui->checkboxes.count(enum_id) != 0);
00395
00396 bool checkbox_val = (cui->checkboxes[enum_id]->get_int_val() != 0);
00397
00398 switch(enum_id){
00399
00400 case CHECKBOX_DRAW_CONTOURS:
00401
00402 LineDrawingTexture::set_draw_contours(checkbox_val);
00403
00404 break;
00405
00406 case CHECKBOX_DRAW_SUGCONTOURS:
00407
00408 LineDrawingTexture::set_draw_sugcontours(checkbox_val);
00409
00410 break;
00411
00412 case CHECKBOX_DRAW_COLOR:
00413
00414 LineDrawingTexture::set_draw_in_color(checkbox_val);
00415
00416 break;
00417
00418 case CHECKBOX_DRAW_GAUSSIAN_CURVATURE:
00419
00420 CurvatureTexture::set_draw_gaussian_curv(checkbox_val);
00421
00422 break;
00423
00424 case CHECKBOX_DRAW_MEAN_CURVATURE:
00425
00426 CurvatureTexture::set_draw_mean_curv(checkbox_val);
00427
00428 break;
00429
00430 case CHECKBOX_DRAW_RADIAL_CURVATURE:
00431
00432 CurvatureTexture::set_draw_radial_curv(checkbox_val);
00433
00434 break;
00435
00436 default:
00437
00438 cerr << "CurvatureUI::checkbox_cb() - Error: Invalid checkbox ID!"
00439 << endl;
00440
00441 break;
00442
00443 }
00444
00445 }
00446
00447 void CurvatureUI::slider_cb(int id)
00448 {
00449
00450 slider_ids_t enum_id = static_cast<slider_ids_t>(id);
00451
00452 CurvatureUI *cui = CurvatureUISingleton::Instance().fetch(VIEW::peek());
00453
00454
00455 assert(cui->sliders.count(enum_id) != 0);
00456
00457 float slider_val = cui->sliders[enum_id]->get_float_val();
00458
00459 switch(enum_id){
00460
00461 case SLIDER_SC_THRESH:
00462
00463 LineDrawingTexture::set_sugcontour_thresh(slider_val);
00464 CurvatureTexture::set_sugcontour_thresh(slider_val);
00465
00466 break;
00467
00468 default:
00469
00470 cerr << "CurvatureUI::slider_cb() - Error: Invalid slider ID!"
00471 << endl;
00472
00473 break;
00474
00475 }
00476
00477 }
00478
00479 void CurvatureUI::radiogroup_cb(int id)
00480 {
00481
00482 radiogroup_ids_t enum_id = static_cast<radiogroup_ids_t>(id);
00483
00484 CurvatureUI *cui = CurvatureUISingleton::Instance().fetch(VIEW::peek());
00485
00486
00487 assert(cui->radiogroups.count(enum_id) != 0);
00488
00489 int radiogroup_val = cui->radiogroups[enum_id]->get_int_val();
00490
00491 CurvatureTexture::curvature_filter_t filter_val;
00492
00493 switch(radiogroup_val){
00494
00495 case 0:
00496
00497 filter_val = CurvatureTexture::FILTER_NONE;
00498
00499 break;
00500
00501 case 1:
00502
00503 filter_val = CurvatureTexture::FILTER_GAUSSIAN;
00504
00505 break;
00506
00507 case 2:
00508
00509 filter_val = CurvatureTexture::FILTER_MEAN;
00510
00511 break;
00512
00513 case 3:
00514
00515 filter_val = CurvatureTexture::FILTER_RADIAL;
00516
00517 break;
00518
00519 default:
00520
00521 cerr << "CurvatureUI::radiogroup_cb() - Error: Invalid curvature filter type!"
00522 << endl;
00523
00524 filter_val = CurvatureTexture::FILTER_NONE;
00525
00526 break;
00527
00528 }
00529
00530 switch(enum_id){
00531
00532 case RADIOGROUP_GAUSSIAN_FILTER:
00533
00534 CurvatureTexture::set_gaussian_filter(filter_val);
00535
00536 break;
00537
00538 case RADIOGROUP_MEAN_FILTER:
00539
00540 CurvatureTexture::set_mean_filter(filter_val);
00541
00542 break;
00543
00544 case RADIOGROUP_RADIAL_FILTER:
00545
00546 CurvatureTexture::set_radial_filter(filter_val);
00547
00548 break;
00549
00550 default:
00551
00552 cerr << "CurvatureUI::radiogroup_cb() - Error: Invalid radiogroup ID!"
00553 << endl;
00554
00555 break;
00556
00557 }
00558
00559 }
00560
00561 void
00562 CurvatureUI::build()
00563 {
00564
00565 assert(!glui);
00566
00567 int root_x, root_y, root_w, root_h;
00568 view->win()->size(root_w,root_h);
00569 view->win()->position(root_x,root_y);
00570
00571 glui = GLUI_Master.create_glui("Curvature gTexture Controls", 0,
00572 root_x + root_w + 10, root_y);
00573 glui->set_main_gfx_window(view->win()->id());
00574
00575
00576
00577 sliders[SLIDER_SC_THRESH]
00578 = glui->add_slider("Suggestive Contour Threshold",
00579 GLUI_SLIDER_FLOAT, 0.0f, 0.1f,
00580 &(CurvatureUISingleton::Instance()._sc_thresh),
00581 SLIDER_SC_THRESH, &CurvatureUI::slider_cb);
00582
00583
00584
00585 rollouts[ROLLOUT_LINE_DRAWING]
00586 = glui->add_rollout("Line Drawing Controls", true);
00587
00588 checkboxes[CHECKBOX_DRAW_CONTOURS]
00589 = glui->add_checkbox_to_panel(rollouts[ROLLOUT_LINE_DRAWING],
00590 "Draw Contours",
00591 &(CurvatureUISingleton::Instance()._line_drawing_draw_contours),
00592 CHECKBOX_DRAW_CONTOURS, &CurvatureUI::checkbox_cb);
00593 checkboxes[CHECKBOX_DRAW_SUGCONTOURS]
00594 = glui->add_checkbox_to_panel(rollouts[ROLLOUT_LINE_DRAWING],
00595 "Draw Suggestive Contours",
00596 &(CurvatureUISingleton::Instance()._line_drawing_draw_sugcontours),
00597 CHECKBOX_DRAW_SUGCONTOURS, &CurvatureUI::checkbox_cb);
00598 checkboxes[CHECKBOX_DRAW_COLOR]
00599 = glui->add_checkbox_to_panel(rollouts[ROLLOUT_LINE_DRAWING],
00600 "Draw in Color",
00601 &(CurvatureUISingleton::Instance()._line_drawing_draw_color),
00602 CHECKBOX_DRAW_COLOR, &CurvatureUI::checkbox_cb);
00603
00604
00605
00606 rollouts[ROLLOUT_CURVATURE_VIS]
00607 = glui->add_rollout("Curvature Controls", true);
00608
00609 checkboxes[CHECKBOX_DRAW_GAUSSIAN_CURVATURE]
00610 = glui->add_checkbox_to_panel(rollouts[ROLLOUT_CURVATURE_VIS],
00611 "Draw Gaussian Curvature",
00612 &(CurvatureUISingleton::Instance()._curvature_draw_gaussian_curv),
00613 CHECKBOX_DRAW_GAUSSIAN_CURVATURE, &CurvatureUI::checkbox_cb);
00614 rollouts[ROLLOUT_CURVATURE_GAUSSIAN_FILTER]
00615 = glui->add_rollout_to_panel(rollouts[ROLLOUT_CURVATURE_VIS],
00616 "Gaussian Curvature Filter", true);
00617 radiogroups[RADIOGROUP_GAUSSIAN_FILTER]
00618 = glui->add_radiogroup_to_panel(rollouts[ROLLOUT_CURVATURE_GAUSSIAN_FILTER],
00619 &(CurvatureUISingleton::Instance()._curvature_gaussian_filter),
00620 RADIOGROUP_GAUSSIAN_FILTER, &CurvatureUI::radiogroup_cb);
00621 radiobuttons[RADIOBUTTON_GAUSSIAN_FILTER_NONE]
00622 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_GAUSSIAN_FILTER],
00623 "None");
00624 radiobuttons[RADIOBUTTON_GAUSSIAN_FILTER_GAUSSIAN]
00625 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_GAUSSIAN_FILTER],
00626 "By Derivative of Gaussian Curvature");
00627 radiobuttons[RADIOBUTTON_GAUSSIAN_FILTER_MEAN]
00628 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_GAUSSIAN_FILTER],
00629 "By Derivative of Mean Curvature");
00630 radiobuttons[RADIOBUTTON_GAUSSIAN_FILTER_RADIAL]
00631 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_GAUSSIAN_FILTER],
00632 "By Derivative of Radial Curvature");
00633
00634 checkboxes[CHECKBOX_DRAW_MEAN_CURVATURE]
00635 = glui->add_checkbox_to_panel(rollouts[ROLLOUT_CURVATURE_VIS],
00636 "Draw Mean Curvature",
00637 &(CurvatureUISingleton::Instance()._curvature_draw_mean_curv),
00638 CHECKBOX_DRAW_MEAN_CURVATURE, &CurvatureUI::checkbox_cb);
00639 rollouts[ROLLOUT_CURVATURE_MEAN_FILTER]
00640 = glui->add_rollout_to_panel(rollouts[ROLLOUT_CURVATURE_VIS],
00641 "Mean Curvature Filter", true);
00642 radiogroups[RADIOGROUP_MEAN_FILTER]
00643 = glui->add_radiogroup_to_panel(rollouts[ROLLOUT_CURVATURE_MEAN_FILTER],
00644 &(CurvatureUISingleton::Instance()._curvature_mean_filter),
00645 RADIOGROUP_MEAN_FILTER, &CurvatureUI::radiogroup_cb);
00646 radiobuttons[RADIOBUTTON_MEAN_FILTER_NONE]
00647 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_MEAN_FILTER],
00648 "None");
00649 radiobuttons[RADIOBUTTON_MEAN_FILTER_GAUSSIAN]
00650 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_MEAN_FILTER],
00651 "By Derivative of Gaussian Curvature");
00652 radiobuttons[RADIOBUTTON_MEAN_FILTER_MEAN]
00653 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_MEAN_FILTER],
00654 "By Derivative of Mean Curvature");
00655 radiobuttons[RADIOBUTTON_MEAN_FILTER_RADIAL]
00656 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_MEAN_FILTER],
00657 "By Derivative of Radial Curvature");
00658
00659 checkboxes[CHECKBOX_DRAW_RADIAL_CURVATURE]
00660 = glui->add_checkbox_to_panel(rollouts[ROLLOUT_CURVATURE_VIS],
00661 "Draw Radial Curvature",
00662 &(CurvatureUISingleton::Instance()._curvature_draw_radial_curv),
00663 CHECKBOX_DRAW_RADIAL_CURVATURE, &CurvatureUI::checkbox_cb);
00664 rollouts[ROLLOUT_CURVATURE_RADIAL_FILTER]
00665 = glui->add_rollout_to_panel(rollouts[ROLLOUT_CURVATURE_VIS],
00666 "Radial Curvature Filter", true);
00667 radiogroups[RADIOGROUP_RADIAL_FILTER]
00668 = glui->add_radiogroup_to_panel(rollouts[ROLLOUT_CURVATURE_RADIAL_FILTER],
00669 &(CurvatureUISingleton::Instance()._curvature_radial_filter),
00670 RADIOGROUP_RADIAL_FILTER, &CurvatureUI::radiogroup_cb);
00671 radiobuttons[RADIOBUTTON_RADIAL_FILTER_NONE]
00672 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_RADIAL_FILTER],
00673 "None");
00674 radiobuttons[RADIOBUTTON_RADIAL_FILTER_GAUSSIAN]
00675 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_RADIAL_FILTER],
00676 "By Derivative of Gaussian Curvature");
00677 radiobuttons[RADIOBUTTON_RADIAL_FILTER_MEAN]
00678 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_RADIAL_FILTER],
00679 "By Derivative of Mean Curvature");
00680 radiobuttons[RADIOBUTTON_RADIAL_FILTER_RADIAL]
00681 = glui->add_radiobutton_to_group(radiogroups[RADIOGROUP_RADIAL_FILTER],
00682 "By Derivative of Radial Curvature");
00683
00684 }
00685
00686 void
00687 CurvatureUI::destroy()
00688 {
00689
00690 assert(glui);
00691
00692 rollouts.clear();
00693 checkboxes.clear();
00694 sliders.clear();
00695
00696
00697 glui->close();
00698
00699 glui = 0;
00700
00701 }