1 #include <iostream>
2 #include <algorithm>
3 #include <sstream>
4 #include "bwm_tableau_cam.h"
5 #include "bwm_site_mgr.h"
6 //:
7 // \file
8 #include <bwm/bwm_tableau_mgr.h>
9 #include <bwm/bwm_observer_mgr.h>
10 #include <bwm/bwm_observable_mesh.h>
11 #include <bwm/bwm_observable_mesh_circular.h>
12 #include <bwm/bwm_tableau_text.h>
13 #include <bwm/bwm_popup_menu.h>
14 #include <bwm/bwm_world.h>
15 #include <bwm/algo/bwm_utils.h>
16 #include <bwm/algo/bwm_algo.h>
17 
18 #include "vgl/vgl_homg_plane_3d.h"
19 #include <vsol/vsol_point_2d.h>
20 #include <vsol/vsol_box_3d.h>
21 #include <vsol/vsol_polygon_2d_sptr.h>
22 #include <vsol/vsol_polygon_3d_sptr.h>
23 
24 #include "vgui/vgui_dialog.h"
25 #include "vgui/vgui_dialog_extensions.h"
26 #include "vgui/vgui_viewer2D_tableau.h"
27 #include "vgui/vgui_shell_tableau.h"
28 
29 
30 #include <volm/volm_category_io.h>
31 #ifdef _MSC_VER
32 #  include "vcl_msvc_warnings.h"
33 #endif
34 #include "vul/vul_file.h"
35 
36 #define NUM_CIRCL_SEC 12
37 
get_popup(vgui_popup_params const & params,vgui_menu & menu)38 void bwm_tableau_cam::get_popup(vgui_popup_params const &params, vgui_menu &menu)
39 {
40   menu.clear();
41 
42   bwm_popup_menu pop(this);
43   vgui_menu submenu;
44   pop.get_menu(menu);
45 }
46 
create_polygon_mesh()47 void bwm_tableau_cam::create_polygon_mesh()
48 {
49   // first lock the bgui_image _tableau
50   this->lock();
51   bwm_observer_mgr::instance()->stop_corr();
52   vsol_polygon_2d_sptr poly2d;
53   set_color(1, 0, 0);
54   pick_polygon(poly2d);
55   if (! poly2d) {
56     std::cerr << "In bwm_tableau_cam::create_polygon_mesh - pick_polygon failed\n";
57     return ;
58   }
59   vsol_polygon_3d_sptr poly3d;
60 
61   //vgl_homg_plane_3d<double> plane(0,0,1,-740);
62   //my_observer_->set_proj_plane(plane);
63   //std::cout << "setting proj plane: " << plane << std::endl;
64 
65   my_observer_->backproj_poly(poly2d, poly3d);
66   if (!poly3d) {
67     std::cout << "in bwm_tableau_cam::create_polygon_mesh - backprojection failed\n";
68     return;
69   }
70   bwm_observable_mesh_sptr my_polygon = new bwm_observable_mesh(bwm_observable_mesh::BWM_MESH_FEATURE);
71   bwm_world::instance()->add(my_polygon);
72   bwm_observer_mgr::instance()->attach(my_polygon);
73   my_polygon->set_object(poly3d);
74   my_polygon->set_site(bwm_site_mgr::instance()->site_name());
75   this->unlock();
76 }
77 
triangulate_mesh()78 void bwm_tableau_cam::triangulate_mesh()
79 {
80   my_observer_->triangulate_meshes();
81 }
82 
create_circular_polygon()83 void bwm_tableau_cam::create_circular_polygon()
84 {
85   this->lock();
86   bwm_observer_mgr::instance()->stop_corr();
87   vsol_polygon_2d_sptr poly2d;
88   set_color(1, 0, 0);
89 
90   std::vector< vsol_point_2d_sptr > ps_list;
91   unsigned max = 10;
92   pick_point_set(ps_list, max);
93   if (ps_list.size() == 0) {
94     std::cerr << "In bwm_tableau_cam::create_circle - pick_points failed\n";
95     return ;
96   }
97   vsol_polygon_3d_sptr poly3d;
98   double r;
99   vgl_point_2d<double> center;
100   my_observer_->create_circular_polygon(ps_list, poly3d, NUM_CIRCL_SEC, r, center);
101   bwm_observable_mesh_sptr my_polygon = new bwm_observable_mesh_circular(r, center);
102   bwm_world::instance()->add(my_polygon);
103   bwm_observer_mgr::instance()->attach(my_polygon);
104   my_polygon->set_object(poly3d);
105   this->unlock();
106 }
107 
set_master()108 void bwm_tableau_cam::set_master()
109 {
110   bwm_observer_mgr::BWM_MASTER_OBSERVER = this->my_observer_;
111 }
112 
113 //: set the observer as per the image type
set_eo()114 void bwm_tableau_cam::set_eo()
115 {
116   bwm_observer_mgr::BWM_EO_OBSERVER = this->my_observer_;
117 }
118 
set_other_mode()119 void bwm_tableau_cam::set_other_mode()
120 {
121   bwm_observer_mgr::BWM_OTHER_MODE_OBSERVER = this->my_observer_;
122 }
123 
move_obj_by_vertex()124 void bwm_tableau_cam::move_obj_by_vertex()
125 {
126   // first check if master tableau is set
127   bwm_observer_cam* mt = bwm_observer_mgr::BWM_MASTER_OBSERVER;
128   if (mt == nullptr) {
129     std::cerr << "Master Tableau is not selected, please select one different than the current one!\n";
130     return;
131   }
132   else if (mt == this->my_observer_) {
133     std::cerr << "Please select a tableau different than the current one!\n";
134     return;
135   }
136 
137   my_observer_->set_selection(false);
138   float x,y;
139   set_color(1, 0, 0);
140   pick_point(&x, &y);
141   vsol_point_2d_sptr pt = new vsol_point_2d((double)x,(double)y);
142   my_observer_->set_selection(true);
143   my_observer_->move_ground_plane(mt->get_proj_plane(), pt);
144 }
145 
extrude_face()146 void bwm_tableau_cam::extrude_face()
147 {
148   my_observer_->extrude_face();
149 }
150 
divide_face()151 void bwm_tableau_cam::divide_face()
152 {
153   float x1, y1, x2, y2;
154   unsigned face_id;
155 
156   bwm_observer_mgr::instance()->stop_corr();
157   bwm_observable_sptr obj = my_observer_->selected_face(face_id);
158   if (obj) {
159     pick_line(&x1, &y1, &x2, &y2);
160     my_observer_->divide_face(obj, face_id, x1, y1, x2, y2);
161   }
162   else
163     std::cerr << "Please first select the face to be divided\n";
164 }
165 
create_inner_face()166 void bwm_tableau_cam::create_inner_face()
167 {
168   bwm_observer_mgr::instance()->stop_corr();
169   vsol_polygon_2d_sptr poly2d;
170   set_color(1, 0, 0);
171   pick_polygon(poly2d);
172   my_observer_->connect_inner_face(poly2d);
173 }
174 
move_corr()175 void bwm_tableau_cam::move_corr()
176 {
177   float x,y;
178   set_color(1, 0, 0);
179   pick_point(&x, &y);
180   vsol_point_2d_sptr pt = new vsol_point_2d((double)x,(double)y);
181   my_observer_->move_corr_point(pt);
182 }
183 
set_corr_to_vertex()184 void bwm_tableau_cam::set_corr_to_vertex()
185 {
186   my_observer_->set_corr_to_vertex();
187 }
188 
world_pt_corr()189 void bwm_tableau_cam::world_pt_corr()
190 {
191   my_observer_->world_pt_corr();
192 }
193 
194 
select_proj_plane()195 void bwm_tableau_cam::select_proj_plane()
196 {
197   my_observer_->select_proj_plane();
198 }
199 
define_proj_plane()200 void bwm_tableau_cam::define_proj_plane()
201 {
202   bwm_observer_mgr::instance()->stop_corr();
203   // pick the ground truth line
204   float x1, y1, x2, y2;
205   pick_line(&x1, &y1, &x2, &y2);
206   std::cout << '(' << x1 << ',' << y1 << ')' << '(' << x2 << ',' << y2 << ')' << std::endl;
207   my_observer_->set_ground_plane(x1, y1, x2, y2);
208 }
209 
define_xy_proj_plane()210 void bwm_tableau_cam::define_xy_proj_plane()
211 {
212   static double z = 0;
213   vgui_dialog zval("Define XY plane");
214   zval.field("Elevation (meters)", z);
215   if (!zval.ask())
216     return;
217   vgl_homg_plane_3d<double> plane(0,0,1,-z);
218   my_observer_->set_proj_plane(plane);
219 }
220 
define_yz_proj_plane()221 void bwm_tableau_cam::define_yz_proj_plane()
222 {
223   static double x = 0;
224   vgui_dialog xval("Define YZ plane");
225   xval.field("X (meters)", x);
226   if (!xval.ask())
227     return;
228   vgl_homg_plane_3d<double> plane(1,0,0,-x);
229   my_observer_->set_proj_plane(plane);
230 }
231 
define_xz_proj_plane()232 void bwm_tableau_cam::define_xz_proj_plane()
233 {
234   static double y= 0;
235   vgui_dialog yval("Define XZ plane");
236   yval.field("Y (meters)", y);
237   if (!yval.ask())
238     return;
239   vgl_homg_plane_3d<double> plane(0,1,0,-y);
240   my_observer_->set_proj_plane(plane);
241 }
242 
label_roof()243 void bwm_tableau_cam::label_roof()
244 {
245   my_observer_->label_roof();
246 }
247 
label_wall()248 void bwm_tableau_cam::label_wall()
249 {
250   my_observer_->label_wall();
251 }
252 
load_mesh()253 void bwm_tableau_cam::load_mesh()
254 {
255   // get the file name for the mesh
256   std::string file = bwm_utils::select_file();
257 
258   // load the mesh from the given file
259   bwm_observable_mesh_sptr obj = new bwm_observable_mesh();
260   bwm_observer_mgr::instance()->attach(obj);
261   bool success = obj->load_from(file.data());
262   if (success) {
263     bwm_world::instance()->add(obj);
264     obj->set_path(file.data());
265     my_observer_->set_face_mode();
266   }
267   else
268     bwm_observer_mgr::instance()->detach(obj);
269 }
270 
load_mesh_multiple()271 void bwm_tableau_cam::load_mesh_multiple()
272 {
273   // read txt file
274   std::string master_filename = bwm_utils::select_file();
275   std::ifstream file_inp(master_filename.data());
276   if (!file_inp.good()) {
277     std::cerr << "error opening file "<< master_filename << '\n';
278     return;
279   }
280 
281   while (!file_inp.eof()) {
282     std::ostringstream fullpath;
283     std::string mesh_fname;
284     file_inp >> mesh_fname;
285     if (!mesh_fname.empty() && (mesh_fname[0] != '#')) {
286       fullpath << master_filename << '.' << mesh_fname;
287       // load the mesh from the given file
288       bwm_observable_mesh_sptr obj = new bwm_observable_mesh();
289       bwm_observer_mgr::instance()->attach(obj);
290       obj->load_from(fullpath.str());
291     }
292   }
293   file_inp.close();
294 
295   return;
296 }
297 
delete_object()298 void bwm_tableau_cam::delete_object()
299 {
300   my_observer_->delete_object();
301 }
302 
delete_all()303 void bwm_tableau_cam::delete_all()
304 {
305   my_observer_->delete_all();
306 }
307 
save()308 void bwm_tableau_cam::save()
309 {
310   my_observer_->save();
311 }
312 
save(std::string path)313 void bwm_tableau_cam::save(std::string path)
314 {
315   my_observer_->save(path);
316 }
317 
save_all()318 void bwm_tableau_cam::save_all()
319 {
320   my_observer_->save();
321 }
322 
save_all(std::string path)323 void bwm_tableau_cam::save_all(std::string path)
324 {
325   my_observer_->save();
326 }
327 
scan_regions()328 void bwm_tableau_cam::scan_regions()
329 {
330   my_observer_->scan_regions();
331 }
332 
project_shadow()333 void bwm_tableau_cam::project_shadow()
334 {
335   my_observer_->project_shadow();
336 }
337 
show_geo_position()338 void bwm_tableau_cam::show_geo_position()
339 {
340   my_observer_->show_geo_position();
341 }
342 
geo_position_vertex()343 void bwm_tableau_cam::geo_position_vertex()
344 {
345   my_observer_->position_vertex(true);
346 }
347 
local_position_vertex()348 void bwm_tableau_cam::local_position_vertex()
349 {
350   my_observer_->position_vertex(false);
351 }
352 
scroll_to_point(double lx,double ly,double lz)353 void bwm_tableau_cam::scroll_to_point(double lx, double ly, double lz)
354 {
355   my_observer_->scroll_to_point(lx,ly,lz);
356 }
357 
create_terrain()358 void bwm_tableau_cam::create_terrain()
359 {
360 #if 0 // commented out
361   this->lock();
362   //1. pick a boundary for the terrain as a polygon
363   bwm_observer_mgr::instance()->stop_corr();
364   vsol_polygon_2d_sptr poly2d;
365   set_color(1, 0, 0);
366   pick_polygon(poly2d);
367 #endif // 0
368   my_observer_->create_terrain();
369 #if 0 // commented out
370   this->unlock();
371 #endif // 0
372 }
373 
help_pop()374 void bwm_tableau_cam::help_pop()
375 {
376   bwm_tableau_text* text_tab = new bwm_tableau_text(500, 500);
377 #if 0
378   text->set_text("C:/lems/lemsvxlsrc/lemsvxlsrc/contrib/bwm/doc/doc/HELP_cam.txt");
379 #endif
380   std::string h("SHIFT p = create 3-d polygon\nSHIFT t = triangulate_mesh\nSHIFT m = move object by vertex\nSHIFT e = extrude face\nSHIFT s = save a selected 3-d polygon\nSHIFT h = key help documentation\n");
381   text_tab->set_string(h);
382   vgui_tableau_sptr v = vgui_viewer2D_tableau_new(text_tab);
383   vgui_tableau_sptr s = vgui_shell_tableau_new(v);
384   vgui_dialog popup("CAMERA TABLEAU HELP");
385   popup.inline_tableau(s, 550, 550);
386   if (!popup.ask())
387     return;
388 }
389 
handle(const vgui_event & e)390 bool bwm_tableau_cam::handle(const vgui_event& e)
391 {
392   //std::cout << "Key:" << e.key << " modif: " << e.modifier << std::endl;
393   if (e.key == 'p' && e.modifier == vgui_SHIFT && e.type == vgui_KEY_PRESS) {
394     create_polygon_mesh();
395     return true;
396   }
397   else if (e.key == 't' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
398     this->triangulate_mesh();
399     return true;
400   }
401   else if ( e.key == 'm' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
402     this->move_obj_by_vertex();
403     return true;
404   }
405   else if ( e.key == 'e' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
406     this->extrude_face();
407     return true;
408   }
409   else if ( e.key == 's' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
410     this->save();
411     return true;
412   }
413   else if ( e.key == '1' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
414     this->project_shadow();
415     return true;
416   }
417 #if 0 //flakey behavior --needs work
418   else if ( e.key == 'z' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
419     this->deselect_all();
420     return true;
421   }
422   else if ( e.key == 'a' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
423     this->clear_all();
424     return true;
425   }
426 #endif
427   else if ( e.key == 'h' && e.modifier==vgui_SHIFT && e.type==vgui_KEY_PRESS) {
428     this->help_pop();
429     return true;
430   }
431  return bwm_tableau_img::handle(e);
432 }
433 
434 // ======================   camera calibration methods =============
set_focal_length()435 void bwm_tableau_cam::set_focal_length()
436 {
437   static double focal_length = 3000.0;
438   vgui_dialog fval("Set Focal Length");
439   fval.field("Focal Length (pixel units)", focal_length);
440   if (!fval.ask())
441     return;
442   my_observer_->set_focal_length(focal_length);
443 }
444 
set_cam_height()445 void bwm_tableau_cam::set_cam_height()
446 {
447   static double cam_height = 1.6;
448   vgui_dialog hval("Set Camera Center Height");
449   hval.field("Height (m)", cam_height);
450   if (!hval.ask())
451     return;
452   my_observer_->set_cam_height(cam_height);
453 }
454 
add_ground_plane()455 void bwm_tableau_cam::add_ground_plane()
456 {
457   // allowed land class
458   std::vector<std::string> land_types = this->set_land_types();
459 
460   static std::string name = "ground_plane";
461   static unsigned order = 0;
462   static unsigned land_vec_id = 0;
463   vgui_dialog vdval("Ground Plane Region");
464   vdval.field("Name ", name);
465   vdval.choice("Land Class ", land_types, land_vec_id);
466   // obtain actual land id
467   std::string land_name = land_types[land_vec_id];
468   unsigned char land_id = volm_osm_category_io::volm_land_table_name[land_name].id_;
469   if (!vdval.ask())
470     return;
471   my_observer_->add_ground_plane(order, (unsigned)land_id, name);
472 }
473 
add_sky()474 void bwm_tableau_cam::add_sky()
475 {
476   static std::string name = "sky";
477   static unsigned  order = 255;
478   vgui_dialog vdval("Sky Region");
479   vdval.field("Name ", name);
480   if (!vdval.ask())
481     return;
482   my_observer_->add_sky(order, name);
483 }
484 
485 #if 0
486 void bwm_tableau_cam::add_vertical_depth_region()
487 {
488   static double min_depth = 0.0;
489   static double max_depth = 100.0;
490   static std::string name = "";
491   vgui_dialog vdval("Vertical Region");
492   vdval.field("Min Depth (m)", min_depth);
493   vdval.field("Max Depth (m)", max_depth);
494   vdval.field("Name ", name);
495   if (!vdval.ask())
496     return;
497   my_observer_->add_vertical_depth_region(min_depth, max_depth, name);
498 }
499 #endif
500 
add_region()501 void bwm_tableau_cam::add_region()
502 {
503   // allowed orientation
504   std::vector<std::string> orient_types;
505   orient_types = this->set_orient_types();
506   // allowed land class
507   std::vector<std::string> land_types;
508   land_types = this->set_land_types();
509 
510   static std::string name = "";
511   static double     min_depth = 0.0;
512   static double     max_depth = 100.0;
513   static unsigned   order = 0;
514   static unsigned   orientation = 0;
515   static unsigned   land_vec_id = 0;
516   static double     height = -1.0;
517   // create menu
518   vgui_dialog vdval("Add Region");
519   vdval.field("Name ", name);
520   vdval.field("Min Depth (m)", min_depth);
521   vdval.field("Max Depth (m)", max_depth);
522   vdval.field("Height (m)", height);
523   vdval.field("Order ", order);
524   vdval.choice("Orientation ", orient_types, orientation);
525   vdval.choice("Land Class ", land_types, land_vec_id);
526   if (!vdval.ask())
527     return;
528   // obtain the actual land id
529   std::string land_name = land_types[land_vec_id];
530   unsigned char land_id = volm_osm_category_io::volm_land_table_name[land_name].id_;
531   // create associated depth_map_region
532   my_observer_->add_region(name, min_depth, max_depth, order, orientation, (unsigned)land_id, height);
533 }
534 
edit_region_props()535 void bwm_tableau_cam::edit_region_props()
536 {
537   // allowed orientation
538   std::vector<std::string> orient_types;
539   orient_types = this->set_orient_types();
540   // allowed land class
541   std::vector<std::string> land_types;
542   land_types = this->set_land_types();
543   // fetch all regions in depth_map_scene, including all sky regions, ground regions and objects
544   std::vector<depth_map_region_sptr> regions = my_observer_->scene_regions();
545   // initialize region properties
546   static std::map<std::string, unsigned> depth_order;
547   static std::map<std::string, double> min_depth;
548   static std::map<std::string, double> max_depth;
549   static std::map<std::string, double> height;
550   static std::map<std::string, unsigned> orient;
551   static std::map<std::string, unsigned> land_id;
552   static std::map<std::string, bool> active;
553   static std::map<std::string, bool> is_reference;
554   // for padding to align fields
555   unsigned max_string_size = 0;
556   for (std::vector<depth_map_region_sptr>::iterator rit = regions.begin();
557        rit != regions.end(); ++rit) {
558     std::string name  = (*rit)->name();
559     if (name.size()>max_string_size)
560       max_string_size  = name.size();
561     depth_order[name]  = (*rit)->order();
562     min_depth[name]    = (*rit)->min_depth();
563     max_depth[name]    = (*rit)->max_depth();
564     height[name]       = (*rit)->height();
565     //depth_inc[name]   = (*rit)->depth_inc();
566     active[name]       = (*rit)->active();
567     orient[name]       = (*rit)->orient_type();
568     land_id[name]      = (*rit)->land_id();
569     is_reference[name] = (*rit)->is_ref();
570   }
571   vgui_dialog_extensions reg_dialog("Scene Region Editor");
572   std::vector<depth_map_region_sptr>::iterator gpit;
573   for (std::vector<depth_map_region_sptr>::iterator rit = regions.begin(); rit != regions.end(); ++rit) {
574     std::string temp = (*rit)->name();
575     // compute padding
576     int pad_cnt = max_string_size-temp.size();
577     for (int k = 0; k<pad_cnt; ++k)
578       temp += ' ';
579     reg_dialog.message(temp.c_str()) ;
580     if ( ((*rit)->name()).find("sky") != std::string::npos ) {
581       reg_dialog.line_break();
582       continue;
583     }
584     //if ( ((*rit)->name()).find("ground_plane") != std::string::npos ) {
585     //  reg_dialog.choice("Land Class", land_types, land_id[(*rit)->name()]);
586     //  reg_dialog.line_break();
587     //  continue;
588     //}
589     reg_dialog.field("Order", depth_order[(*rit)->name()]);
590     reg_dialog.field("MinDepth", min_depth[(*rit)->name()]);
591     reg_dialog.field("MaxDepth", max_depth[(*rit)->name()]);
592     reg_dialog.field("Height",   height[(*rit)->name()]);
593     reg_dialog.choice("Orientation", orient_types, orient[(*rit)->name()]);
594     reg_dialog.choice("Land Class", land_types, land_id[(*rit)->name()]);
595     reg_dialog.checkbox("Active", active[(*rit)->name()]);
596     reg_dialog.checkbox("Reference", is_reference[(*rit)->name()]);
597     reg_dialog.line_break();
598   }
599 
600   if (!reg_dialog.ask())
601     return;
602   // update region properties
603   for (std::vector<depth_map_region_sptr>::iterator rit = regions.begin(); rit != regions.end(); ++rit) {
604     std::string name = (*rit)->name();
605     (*rit)->set_order(depth_order[name]);
606     (*rit)->set_min_depth(min_depth[name]);
607     (*rit)->set_max_depth(max_depth[name]);
608     (*rit)->set_height(height[name]);
609     (*rit)->set_land_type(volm_osm_category_io::volm_land_table_name[land_types[land_id[name]]].id_);
610     (*rit)->set_active(active[name]);
611     (*rit)->set_ref(is_reference[name]);
612     (*rit)->set_orient_type(orient[name]);
613   }
614   //my_observer_->set_ground_plane_max_depth();
615 }
616 
edit_region_weights()617 void bwm_tableau_cam::edit_region_weights()
618 {
619   std::vector<volm_weight> weights;
620   // get the depth_map_scene
621   depth_map_scene dms = my_observer_->scene();
622 
623   // weight vector follows the order defined in depth_map_scene
624   std::vector<depth_map_region_sptr> objs = dms.scene_regions();
625   unsigned n_obj = (unsigned)objs.size();
626   std::sort(objs.begin(), objs.end(), compare_order());
627 
628   if (my_observer_->weights().empty()) {
629     // calculate average weight as default
630     float w_avg, w_obj;
631     if (!dms.sky().empty() && !dms.ground_plane().empty()) {
632       w_avg = 1.0f / (2.0f + dms.scene_regions().size());
633       float w_sky = w_avg * 1.5f;
634       float w_grd = w_avg * 1.0f;
635       w_obj = (1.0f - w_sky - w_grd) / dms.scene_regions().size();
636       weights.push_back(volm_weight("sky", "sky", 0.0f, 0.0f, 0.0f, 1.0f, w_sky));
637       weights.push_back(volm_weight("ground_plane", "ground_plane", 0.3f, 0.4f, 0.0f, 0.3f, w_grd));
638     }
639     else if (!dms.sky().empty()) {
640       w_avg = 1.0f / (1 + dms.scene_regions().size());
641       float w_sky = w_avg * 1.5f;
642       w_obj = (1.0f - w_sky) / dms.scene_regions().size();
643       weights.push_back(volm_weight("sky", "sky", 0.0f, 0.0f, 0.0f, 1.0f, w_sky));
644     }
645     else if (!dms.ground_plane().empty()) {
646       w_avg = 1.0f / (1 + dms.scene_regions().size());
647       float w_grd = w_avg * 1.0f;
648       w_obj = (1.0f - w_grd) / dms.scene_regions().size();
649       weights.push_back(volm_weight("ground_plane", "ground_plane", 0.3f, 0.4f, 0.0f, 0.3f, w_grd));
650     }
651     else {
652       w_avg = 1.0f / dms.scene_regions().size();
653       w_obj = w_avg;
654     }
655     for (unsigned i = 0; i < objs.size(); i++)
656       weights.push_back(volm_weight(objs[i]->name(), objs[i]->name(), 0.25f, 0.25f, 0.25f, 0.25f, w_obj));
657   }
658   else {
659     weights = my_observer_->weights();
660   }
661   // arrange the menu by order
662   std::vector<depth_map_region_sptr> regions;
663   if (!dms.sky().empty())
664     regions.push_back(dms.sky()[0]);
665   if (!dms.ground_plane().empty())
666     regions.push_back(dms.ground_plane()[0]);
667   for (unsigned i = 0; i < objs.size(); i++)
668     regions.push_back(objs[i]);
669 
670   // for padding to align fields
671   unsigned max_string_size = 0;
672   for (std::vector<depth_map_region_sptr>::iterator rit = regions.begin(); rit != regions.end(); ++rit) {
673     std::string tmp;
674     if ( ((*rit)->name()).find("sky") != std::string::npos)
675       tmp = "sky";
676     else if ( ((*rit)->name()).find("ground_plane") != std::string::npos)
677       tmp = "ground_plane";
678     else
679       tmp = (*rit)->name();
680     if (tmp.size()> max_string_size)
681       max_string_size = tmp.size();
682   }
683 
684   vgui_dialog_extensions reg_dialog("Scene Region Weight Editor");
685   for (unsigned i = 0; i < regions.size(); i++) {
686     std::string tmp;
687     if (regions[i]->name().find("sky") != std::string::npos)
688       tmp = "sky";
689     else if (regions[i]->name().find("ground_plane") != std::string::npos)
690       tmp = "ground_plane";
691     else
692       tmp = regions[i]->name();
693     // compute padding
694     int pad_cnt = max_string_size - tmp.size();
695     for (int k = 0; k < pad_cnt; k++)  tmp += ' ';
696     reg_dialog.message(tmp.c_str());
697 
698     reg_dialog.field("Orientation", weights[i].w_ori_);
699     reg_dialog.field("Land_Class",  weights[i].w_lnd_);
700     reg_dialog.field("MinDepth",    weights[i].w_dst_);
701     reg_dialog.field("Order",       weights[i].w_ord_);
702     reg_dialog.field("Object",      weights[i].w_obj_);
703     reg_dialog.line_break();
704   }
705 
706   if (!reg_dialog.ask())
707     return;
708 
709   // update weight
710   my_observer_->set_weights(weights);
711 }
712 
save_depth_map_scene()713 void bwm_tableau_cam::save_depth_map_scene()
714 {
715   // before save, put the image path into depth_map_scene
716   my_observer_->set_image_path(this->img_path());
717   // save depth_map_scene
718   std::string path = bwm_utils::select_file();
719   my_observer_->save_depth_map_scene(path);
720 
721   // save associated weight parameters
722   std::string dir = vul_file::dirname(path);
723   std::string weight_file = dir + "/weight_param.txt";
724   my_observer_->save_weight_params(weight_file);
725 }
726 
set_land_types()727 std::vector<std::string> bwm_tableau_cam::set_land_types()
728 {
729 #if 1
730   return volm_osm_category_io::volm_category_name_table;
731 #endif
732 }
733 
set_orient_types()734 std::vector<std::string> bwm_tableau_cam::set_orient_types()
735 {
736   std::vector<std::string> orient_types;
737   std::map<depth_map_region::orientation, std::string> orient_string;
738   std::map<std::string, depth_map_region::orientation>::iterator mit = volm_orient_table::ori_id.begin();
739   for (; mit != volm_orient_table::ori_id.end(); ++mit)
740     orient_string[mit->second] = mit->first;
741   std::map<depth_map_region::orientation, std::string>::iterator it = orient_string.begin();
742   for (; it != orient_string.end(); ++it)
743     orient_types.push_back(it->second);
744   return orient_types;
745 }
746