00001
00002 #include "segv_misc_manager.h"
00003
00004
00005
00006
00007 #if 1 //JLM
00008 #include <vpgl/file_formats/vpgl_nitf_rational_camera.h>
00009 #endif
00010
00011 #include <vpgl/vpgl_rational_camera.h>
00012 #include <vcl_iostream.h>
00013 #include <vcl_cmath.h>
00014 #include <vul/vul_file.h>
00015 #include <vnl/vnl_math.h>
00016 #include <vil/vil_image_view.h>
00017 #include <vil/vil_blocked_image_resource.h>
00018 #include <vil/vil_pyramid_image_resource.h>
00019 #include <vil/vil_load.h>
00020 #include <vil/vil_save.h>
00021 #include <vil/vil_new.h>
00022 #include <vil/vil_property.h>
00023 #include <sdet/sdet_detector_params.h>
00024 #include <sdet/sdet_detector.h>
00025 #include <sdet/sdet_harris_detector_params.h>
00026 #include <sdet/sdet_harris_detector.h>
00027 #include <sdet/sdet_nonmax_suppression_params.h>
00028 #include <sdet/sdet_nonmax_suppression.h>
00029 #include <sdet/sdet_fit_lines_params.h>
00030 #include <sdet/sdet_fit_lines.h>
00031 #include <sdet/sdet_fit_conics.h>
00032 #include <sdet/sdet_grid_finder_params.h>
00033 #include <sdet/sdet_grid_finder.h>
00034 #include <vgui/vgui.h>
00035 #include <vgui/vgui_find.h>
00036 #include <vgui/vgui_tableau.h>
00037 #include <vgui/vgui_dialog.h>
00038 #include <vgui/vgui_style_sptr.h>
00039 #include <vgui/vgui_style.h>
00040 #include <vgui/vgui_viewer2D_tableau.h>
00041 #include <vgui/vgui_shell_tableau.h>
00042 #include <vgui/vgui_grid_tableau.h>
00043 #include <vgui/vgui_range_map_params.h>
00044 #include <bgui/bgui_image_tableau.h>
00045 #include <bgui/bgui_vtol2D_tableau.h>
00046 #include <bgui/bgui_picker_tableau.h>
00047 #include <bgui/bgui_range_adjuster_tableau.h>
00048 #include <bgui/bgui_image_utils.h>
00049 #include <bvgl/bvgl_articulated_poly.h>
00050 #include <vsol/vsol_point_2d.h>
00051 #include <vsol/vsol_point_2d_sptr.h>
00052 #include <vsol/vsol_conic_2d.h>
00053 #include <vsol/vsol_polyline_2d.h>
00054 #include <vtol/vtol_vertex_2d.h>
00055 #include <vtol/vtol_vertex.h>
00056 #include <vtol/vtol_edge_2d.h>
00057 #include <vtol/vtol_intensity_face.h>
00058 #include <brip/brip_vil1_float_ops.h>
00059 #include <brip/brip_vil_float_ops.h>
00060 #include <brip/brip_para_cvrg_params.h>
00061 #include <brip/brip_para_cvrg.h>
00062 #include <brip/brip_watershed_params.h>
00063 #include <sdet/sdet_watershed_region_proc_params.h>
00064 #include <sdet/sdet_watershed_region_proc.h>
00065 #include <sdet/sdet_vehicle_finder_params.h>
00066 #include <sdet/sdet_vehicle_finder.h>
00067 #include <sdet/sdet_region_proc_params.h>
00068 #include <sdet/sdet_region_proc.h>
00069 #include <strk/strk_region_info_params.h>
00070 #include <strk/strk_region_info.h>
00071 #include <strk/strk_io.h>
00072
00073 ;
00074 segv_misc_manager *segv_misc_manager::instance_ = 0;
00075
00076 segv_misc_manager *segv_misc_manager::instance()
00077 {
00078 if (!instance_)
00079 {
00080 instance_ = new segv_misc_manager();
00081 instance_->init();
00082 }
00083 return segv_misc_manager::instance_;
00084 }
00085
00086
00087
00088
00089 segv_misc_manager::segv_misc_manager():vgui_wrapper_tableau()
00090 {
00091 first_ = true;
00092 }
00093
00094 segv_misc_manager::~segv_misc_manager()
00095 {
00096 }
00097
00098
00099 void segv_misc_manager::init()
00100 {
00101 bgui_image_tableau_sptr itab = bgui_image_tableau_new();
00102 bgui_vtol2D_tableau_sptr t2D = bgui_vtol2D_tableau_new(itab);
00103 bgui_picker_tableau_sptr picktab = bgui_picker_tableau_new(t2D);
00104 vgui_viewer2D_tableau_sptr v2D = vgui_viewer2D_tableau_new(picktab);
00105 grid_ = vgui_grid_tableau_new(1,1);
00106 grid_->set_grid_size_changeable(true);
00107 grid_->add_at(v2D, 0, 0);
00108 vgui_shell_tableau_sptr shell = vgui_shell_tableau_new(grid_);
00109 this->add_child(shell);
00110 first_ = true;
00111 }
00112
00113
00114 vgui_range_map_params_sptr segv_misc_manager::
00115 range_params(vil_image_resource_sptr const& image)
00116 {
00117 float gamma = 1.0;
00118 bool invert = false;
00119 bool gl_map = false;
00120 bool cache = true;
00121
00122
00123 vil_blocked_image_resource_sptr bir = blocked_image_resource(image);
00124 if (bir)
00125 { gl_map = true; cache = false; }
00126
00127
00128 bool pyr = image->get_property(vil_property_pyramid, 0);
00129 if (pyr)
00130 { gl_map = true; cache = false; }
00131
00132
00133 double min=0, max=0;
00134 unsigned n_components = image->nplanes();
00135 vgui_range_map_params_sptr rmps;
00136 if (n_components == 1)
00137 {
00138 bgui_image_utils iu(image);
00139 iu.range(min, max);
00140 rmps= new vgui_range_map_params(min, max, gamma, invert,
00141 gl_map, cache);
00142 }
00143 else if (n_components == 3)
00144 {
00145 min = 0; max = 255;
00146 rmps = new vgui_range_map_params(min, max, min, max, min, max,
00147 gamma, gamma, gamma, invert,
00148 gl_map, cache);
00149 }
00150 return rmps;
00151 }
00152
00153
00154 void segv_misc_manager::
00155 set_selected_grid_image(vil_image_resource_sptr const& image,
00156 vgui_range_map_params_sptr const& rmps)
00157 {
00158 bgui_image_tableau_sptr itab = this->selected_image_tab();
00159 if (!itab)
00160 this->add_image(image, rmps);
00161 else
00162 {
00163 itab->set_image_resource(image);
00164 itab->set_mapping(rmps);
00165 }
00166 itab->post_redraw();
00167 }
00168
00169
00170 void segv_misc_manager::
00171 add_image_at(vil_image_resource_sptr const& image,
00172 const unsigned col, const unsigned row,
00173 vgui_range_map_params_sptr const& rmps)
00174 {
00175 vgui_range_map_params_sptr rmap = rmps;
00176 if (!rmps)
00177 rmap = range_params(image);
00178 bgui_image_tableau_sptr itab = bgui_image_tableau_new(image);
00179 itab->set_mapping(rmap);
00180 bgui_vtol2D_tableau_sptr t2D = bgui_vtol2D_tableau_new(itab);
00181 bgui_picker_tableau_sptr picktab = bgui_picker_tableau_new(t2D);
00182 vgui_viewer2D_tableau_sptr v2D = vgui_viewer2D_tableau_new(picktab);
00183 grid_->add_at(v2D, col, row);
00184 itab->post_redraw();
00185 }
00186
00187
00188 void segv_misc_manager::
00189 add_image(vil_image_resource_sptr const& image,
00190 vgui_range_map_params_sptr const& rmps)
00191 {
00192 unsigned row=0, col=0;
00193 grid_->get_last_selected_position(&col, &row);
00194 this->add_image_at(image, col, row, rmps);
00195 }
00196
00197 #if 0
00198
00199
00200
00201 void segv_misc_manager::remove_image()
00202 {
00203 unsigned row=0, col=0;
00204 grid_->get_last_selected_position(&col, &row);
00205 grid_->remove_at(col, row);
00206 }
00207
00208 void segv_misc_manager::convert_to_grey()
00209 {
00210 vil_image_resource_sptr img = this->selected_image();
00211 if (!img)
00212 return;
00213 vil_image_view<unsigned char> grey =
00214 brip_vil_float_ops::convert_to_byte(img);
00215 vil_image_resource_sptr gimg = vil_new_image_resource_of_view(grey);
00216 this->add_image(gimg);
00217 }
00218 #endif
00219
00220
00221 bgui_image_tableau_sptr segv_misc_manager::selected_image_tab()
00222 {
00223 unsigned row=0, col=0;
00224 grid_->get_last_selected_position(&col, &row);
00225 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00226 if (top_tab)
00227 {
00228 bgui_image_tableau_sptr itab;
00229 itab.vertical_cast(vgui_find_below_by_type_name(top_tab,
00230 vcl_string("vgui_image_tableau")));
00231 if (itab)
00232 return itab;
00233 }
00234 vcl_cout << "Unable to get bgui_image_tableau at (" << col
00235 << ", " << row << ")\n";
00236 return bgui_image_tableau_sptr();
00237 }
00238
00239
00240 bgui_vtol2D_tableau_sptr
00241 segv_misc_manager::vtol2D_tab_at(const unsigned col,
00242 const unsigned row)
00243 {
00244 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00245 if (top_tab)
00246 {
00247 bgui_vtol2D_tableau_sptr v2D;
00248 v2D.vertical_cast(vgui_find_below_by_type_name(top_tab,
00249 vcl_string("bgui_vtol2D_tableau")));
00250 if (v2D)
00251 return v2D;
00252 }
00253 vcl_cout << "Unable to get bgui_vtol2D_tableau at (" << col
00254 << ", " << row << ")\n";
00255 return bgui_vtol2D_tableau_sptr();
00256 }
00257
00258
00259 bgui_vtol2D_tableau_sptr segv_misc_manager::selected_vtol2D_tab()
00260 {
00261 unsigned row=0, col=0;
00262 grid_->get_last_selected_position(&col, &row);
00263 return this->vtol2D_tab_at(col, row);
00264 }
00265
00266
00267 bgui_picker_tableau_sptr segv_misc_manager::selected_picker_tab()
00268 {
00269 unsigned row=0, col=0;
00270 grid_->get_last_selected_position(&col, &row);
00271 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00272 if (top_tab)
00273 {
00274 bgui_picker_tableau_sptr pick;
00275 pick.vertical_cast(vgui_find_below_by_type_name(top_tab,
00276 vcl_string("bgui_picker_tableau")));
00277 if (pick)
00278 return pick;
00279 }
00280 vcl_cout << "Unable to get bgui_picker_tableau at (" << col
00281 << ", " << row << ")\n";
00282 return bgui_picker_tableau_sptr();
00283 }
00284
00285
00286 vil_image_resource_sptr segv_misc_manager::selected_image()
00287 {
00288 bgui_image_tableau_sptr itab = this->selected_image_tab();
00289 if (!itab)
00290 return 0;
00291 return itab->get_image_resource();
00292 }
00293
00294 vil_image_resource_sptr segv_misc_manager::image_at(const unsigned col,
00295 const unsigned row)
00296 {
00297 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00298 if (!top_tab)
00299 return 0;
00300
00301 bgui_image_tableau_sptr itab;
00302 itab.vertical_cast(vgui_find_below_by_type_name(top_tab,
00303 vcl_string("vgui_image_tableau")));
00304 if (!itab)
00305 {
00306 vcl_cout << "Unable to get bgui_image_tableau at (" << col
00307 << ", " << row << ")\n";
00308 return 0;
00309 }
00310 return itab->get_image_resource();
00311 }
00312
00313
00314
00315
00316 void segv_misc_manager::clear_display()
00317 {
00318 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00319 if (!t2D)
00320 return;
00321 t2D->clear_all();
00322 }
00323
00324
00325
00326
00327 void segv_misc_manager::clear_all()
00328 {
00329 unsigned ncols = grid_->cols(), nrows = grid_->rows();
00330 for (unsigned r=0; r<nrows; ++r)
00331 for (unsigned c=0; c<ncols; ++c)
00332 {
00333 bgui_vtol2D_tableau_sptr t = this->vtol2D_tab_at(c, r);
00334 if (t)
00335 t->clear_all();
00336 }
00337 }
00338
00339
00340
00341
00342 void
00343 segv_misc_manager::draw_edges(vcl_vector<vtol_edge_2d_sptr>& edges,
00344 bool verts)
00345 {
00346 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00347 if (!t2D)
00348 return;
00349 this->clear_display();
00350 #if 0
00351 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00352 if (!itab)
00353 {
00354 vcl_cout << "In segv_misc_manager::draw_edges - null image tab\n";
00355 return;
00356 }
00357 #endif
00358 for (vcl_vector<vtol_edge_2d_sptr>::iterator eit = edges.begin();
00359 eit != edges.end(); eit++)
00360 {
00361 t2D->add_edge(*eit);
00362
00363 if (verts)
00364 {
00365 if ((*eit)->v1())
00366 {
00367 vtol_vertex_2d_sptr v1 = (*eit)->v1()->cast_to_vertex_2d();
00368 t2D->add_vertex(v1);
00369 }
00370 if ((*eit)->v2())
00371 {
00372 vtol_vertex_2d_sptr v2 = (*eit)->v2()->cast_to_vertex_2d();
00373 t2D->add_vertex(v2);
00374 }
00375 }
00376 }
00377 t2D->post_redraw();
00378 }
00379
00380
00381
00382
00383
00384 void segv_misc_manager::
00385 draw_polylines(vcl_vector<vsol_polyline_2d_sptr > const& polys,
00386 vgui_style_sptr style)
00387 {
00388 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00389 if (!t2D)
00390 return;
00391
00392 #if 0
00393 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00394 if (!itab)
00395 {
00396 vcl_cout << "In segv_misc_manager::draw_polylines - null image tab\n";
00397 return;
00398 }
00399 #endif
00400 for (vcl_vector<vsol_polyline_2d_sptr>::const_iterator pit = polys.begin();
00401 pit != polys.end(); pit++)
00402 {
00403 t2D->add_vsol_polyline_2d(*pit, style);
00404 }
00405
00406 t2D->post_redraw();
00407 }
00408
00409
00410
00411
00412 void segv_misc_manager::
00413 draw_lines(vcl_vector<vsol_line_2d_sptr > const& lines,
00414 const vgui_style_sptr& style)
00415 {
00416 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00417 if (!t2D)
00418 return;
00419
00420 #if 0
00421 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00422 if (!itab)
00423 {
00424 vcl_cout << "In segv_misc_manager::draw_edges - null image tab\n";
00425 return;
00426 }
00427 #endif
00428 for (vcl_vector<vsol_line_2d_sptr>::const_iterator lit = lines.begin();
00429 lit != lines.end(); lit++)
00430 {
00431 t2D->add_vsol_line_2d(*lit,style);
00432 }
00433
00434 t2D->post_redraw();
00435 }
00436
00437
00438
00439
00440 void segv_misc_manager::
00441 draw_conics(vcl_vector<vsol_conic_2d_sptr > const& conics,
00442 const vgui_style_sptr& style)
00443 {
00444 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00445 if (!t2D)
00446 return;
00447
00448 #if 0
00449 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00450 if (!itab)
00451 {
00452 vcl_cout << "In segv_misc_manager::draw_edges - null image tab\n";
00453 return;
00454 }
00455 #endif
00456 for (vcl_vector<vsol_conic_2d_sptr>::const_iterator lit = conics.begin();
00457 lit != conics.end(); lit++)
00458 {
00459 t2D->add_vsol_conic_2d(*lit,style);
00460 }
00461 t2D->post_redraw();
00462 }
00463
00464
00465
00466
00467 void segv_misc_manager::
00468 draw_points(vcl_vector<vsol_point_2d_sptr> const& points, const vgui_style_sptr& style)
00469 {
00470 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00471 if (!t2D)
00472 return;
00473
00474 #if 0
00475 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00476 if (!itab)
00477 {
00478 vcl_cout << "In segv_misc_manager::draw_edges - null image tab\n";
00479 return;
00480 }
00481 #endif
00482 for (vcl_vector<vsol_point_2d_sptr>::const_iterator pit = points.begin();
00483 pit != points.end(); pit++)
00484 {
00485 t2D->add_vsol_point_2d(*pit,style);
00486 }
00487
00488 t2D->post_redraw();
00489 }
00490
00491 void segv_misc_manager::draw_regions(vcl_vector<vtol_intensity_face_sptr>& regions,
00492 bool verts)
00493 {
00494 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00495 if (!t2D)
00496 return;
00497 for (vcl_vector<vtol_intensity_face_sptr>::iterator rit = regions.begin();
00498 rit != regions.end(); rit++)
00499 {
00500 vtol_face_2d_sptr f = (*rit)->cast_to_face_2d();
00501 t2D->add_face(f);
00502 if (verts)
00503 {
00504 vcl_vector<vtol_vertex_sptr> vts;
00505 f->vertices(vts);
00506 for (vcl_vector<vtol_vertex_sptr>::iterator vit = vts.begin();
00507 vit != vts.end(); vit++)
00508 {
00509 vtol_vertex_2d_sptr v = (*vit)->cast_to_vertex_2d();
00510 t2D->add_vertex(v);
00511 }
00512 }
00513 }
00514 t2D->post_redraw();
00515 }
00516
00517 void segv_misc_manager::quit()
00518 {
00519 this->clear_all();
00520 vgui::quit();
00521 }
00522
00523 void segv_misc_manager::load_image()
00524 {
00525 static bool greyscale = false;
00526 static bool sblock = false;
00527 vgui_dialog load_image_dlg("Load image file");
00528 static vcl_string image_filename = "/home/dec/images/cal_image1.tif";
00529 static vcl_string ext = "*.*";
00530 load_image_dlg.file("Image Filename:", ext, image_filename);
00531 load_image_dlg.checkbox("greyscale ", greyscale);
00532 load_image_dlg.checkbox("blocked?:", sblock);
00533 if (!load_image_dlg.ask())
00534 return;
00535
00536
00537 bool pyrm = false;
00538 vil_image_resource_sptr image;
00539 if (vul_file::is_directory(image_filename.c_str()))
00540 {
00541 vil_pyramid_image_resource_sptr pyr =
00542 vil_load_pyramid_resource(image_filename.c_str());
00543 if (pyr)
00544 {
00545 image = pyr.ptr();
00546 pyrm = true;
00547 }
00548 }
00549 if (!image)
00550 image = vil_load_image_resource(image_filename.c_str());
00551
00552 if (!image)
00553 return;
00554
00555 if (greyscale&&!pyrm)
00556 {
00557 vil_image_view<unsigned char> grey_view =
00558 brip_vil_float_ops::convert_to_grey(*image);
00559 image = vil_new_image_resource_of_view(grey_view);
00560 }
00561
00562 if (sblock&&!pyrm)
00563 {
00564 vil_blocked_image_resource_sptr bimage = vil_new_blocked_image_facade(image);
00565 image = (vil_image_resource*)(vil_new_cached_image_resource(bimage)).ptr();
00566 }
00567
00568 vgui_range_map_params_sptr rmps = range_params(image);
00569
00570 if (first_)
00571 {
00572 this->set_selected_grid_image(image, rmps);
00573 first_ = false;
00574 }
00575 else
00576 this->add_image(image, rmps);
00577 }
00578
00579 void segv_misc_manager::save_image()
00580 {
00581 vgui_dialog file_dialog("Save Image");
00582 static vcl_string image_file;
00583 static vcl_string ext = "tif";
00584 static vcl_string type = "tiff";
00585 static unsigned size_block = 0;
00586 static bool byte = false;
00587 file_dialog.file("Image Filename:", ext, image_file);
00588 file_dialog.field("Image Format: ", type);
00589 file_dialog.field("BlockSize", size_block);
00590 file_dialog.checkbox("Convert to byte image", byte);
00591 if (!file_dialog.ask())
00592 return;
00593 vil_image_resource_sptr img = this->selected_image();
00594 if (!img)
00595 {
00596 vcl_cerr << "Null image in segv_misc_manager::save_image\n";
00597 return;
00598 }
00599 vil_image_resource_sptr save_image = img;
00600 if (byte)
00601 {
00602 vil_image_view<unsigned char> byte_view = brip_vil_float_ops::convert_to_byte(img);
00603 save_image = vil_new_image_resource_of_view(byte_view);
00604 }
00605 if (size_block>0)
00606 {
00607 vil_blocked_image_resource_sptr bim =
00608 vil_new_blocked_image_resource(image_file.c_str(),
00609 save_image->ni(), save_image->nj(),
00610 save_image->nplanes(),
00611 save_image->pixel_format(),
00612 size_block, size_block,
00613 "tiff");
00614 vil_image_view_base_sptr view = save_image->get_view();
00615 if (view)
00616 bim->vil_image_resource::put_view(*view);
00617 return;
00618 }
00619
00620 if (!vil_save_image_resource(save_image, image_file.c_str(), type.c_str()))
00621 vcl_cerr << "segv_misc_manager::save_image operation failed\n";
00622 }
00623
00624 #if 0
00625 void segv_misc_manager::set_range_params()
00626 {
00627 bgui_image_tableau_sptr itab = this->selected_image_tab();
00628 if (!itab)
00629 return;
00630 vgui_range_map_params_sptr rmps = itab->map_params();
00631 if (!rmps)
00632 {
00633 vil_image_resource_sptr img = itab->get_image_resource();
00634 if (!img)
00635 return;
00636 rmps = range_params(img);
00637 if (!rmps)
00638 return;
00639 }
00640 unsigned nc = rmps->n_components_;
00641 static double min = static_cast<double>(rmps->min_L_),
00642 max = static_cast<double>(rmps->max_L_);
00643 static float gamma = rmps->gamma_L_;
00644 static bool invert = rmps->invert_;
00645 static bool gl_map = rmps->use_glPixelMap_;
00646 static bool cache = rmps->cache_mapped_pix_;
00647 if (nc==3)
00648 {
00649 min = static_cast<double>(rmps->min_R_);
00650 max = static_cast<double>(rmps->max_R_);
00651 gamma = rmps->gamma_R_;
00652 }
00653 vgui_dialog range_dlg("Set Range Map Params");
00654 range_dlg.field("Range min:", min);
00655 range_dlg.field("Range max:", max);
00656 range_dlg.field("Gamma:", gamma);
00657 range_dlg.checkbox("Invert:", invert);
00658 range_dlg.checkbox("Use GL Mapping", gl_map);
00659 range_dlg.checkbox("Cache Pixels", cache);
00660 if (!range_dlg.ask())
00661 return;
00662 if (nc==1)
00663 rmps= new vgui_range_map_params(min, max, gamma, invert,
00664 gl_map, cache);
00665 else if (nc == 3)
00666 rmps = new vgui_range_map_params(min, max, min, max, min, max,
00667 gamma, gamma, gamma, invert,
00668 gl_map, cache);
00669 else
00670 rmps = 0;
00671 itab->set_mapping(rmps);
00672 }
00673 #endif
00674
00675
00676 static vsol_polyline_2d_sptr
00677 trans_poly(const double alpha,
00678 const double theta,
00679 vsol_polyline_2d_sptr const & base_poly)
00680 {
00681 if (!base_poly)
00682 return 0;
00683 double e = vnl_math::e;
00684 double scale = vcl_pow(e, alpha);
00685 vcl_vector<vsol_point_2d_sptr> verts, trans_verts;
00686 for (unsigned i=0; i<base_poly->size(); ++i)
00687 {
00688 vsol_point_2d_sptr bv = base_poly->vertex(i);
00689 double x = bv->x(), y = bv->y();
00690 double sx = x*scale, sy = y*scale;
00691 double rsx = sx*vcl_cos(theta)-sy*vcl_sin(theta);
00692 double rsy = sx*vcl_sin(theta)+sy*vcl_cos(theta);
00693 vsol_point_2d_sptr tv = new vsol_point_2d(rsx, rsy);
00694 trans_verts.push_back(tv);
00695 }
00696 return new vsol_polyline_2d(trans_verts);
00697 }
00698
00699
00700 static vsol_polyline_2d_sptr base_poly()
00701 {
00702 vsol_point_2d_sptr p0 = new vsol_point_2d(-100,-100);
00703 vsol_point_2d_sptr p1 = new vsol_point_2d(-100,+100);
00704 vsol_point_2d_sptr p2 = new vsol_point_2d(+100,+100);
00705 vsol_point_2d_sptr p3 = new vsol_point_2d(+100,-100);
00706 vcl_vector<vsol_point_2d_sptr> verts;
00707 verts.push_back(p3); verts.push_back(p2);
00708 verts.push_back(p1); verts.push_back(p0);
00709 return new vsol_polyline_2d(verts);
00710 }
00711
00712
00713
00714
00715 static double topt(const double alpha_hat, const double theta_hat,
00716 const double alpha, const double theta)
00717 {
00718 double t = alpha_hat*alpha + theta_hat*theta;
00719 t /= (alpha_hat*alpha_hat + theta_hat*theta_hat);
00720 return t;
00721 }
00722
00723
00724 void segv_misc_manager::project_on_subm()
00725 {
00726 this->clear_display();
00727 vgui_style_sptr mstyle = vgui_style::new_style(0.5f, 1.0f, 0.25f,
00728 1.0f, 5.0f);
00729 vgui_style_sptr pstyle = vgui_style::new_style(1.0f, 0.5f, 0.1f,
00730 1.0f, 5.0f);
00731 static double theta_hat = 0.25*vnl_math::pi;
00732 static double alpha_hat = 1.0;
00733 static double theta = 0.3*vnl_math::pi;
00734 static double alpha = 1.5;
00735 static double tinc = 0.1;
00736 static double tmax = 3.0;
00737 vgui_dialog project_dlg("Projection Parameters");
00738 project_dlg.field("Theta hat:", theta_hat);
00739 project_dlg.field("Alpha hat:", alpha_hat);
00740 project_dlg.field("tinc:", tinc);
00741 project_dlg.field("tmax:", tmax);
00742 project_dlg.field("Theta:", theta );
00743 project_dlg.field("Alpha:", alpha);
00744 if (!project_dlg.ask())
00745 return;
00746 vcl_vector<vsol_polyline_2d_sptr> tpolys;
00747 vsol_polyline_2d_sptr base = base_poly();
00748 vsol_polyline_2d_sptr tbase = trans_poly(alpha,theta,base);
00749 tpolys.push_back(tbase);
00750 this->draw_polylines(tpolys,mstyle);
00751 tpolys.clear();
00752 double to = topt(alpha_hat, theta_hat, alpha, theta);
00753 double alp = to*alpha_hat;
00754 double thet = to*theta_hat;
00755 vsol_polyline_2d_sptr popt = trans_poly(alp, thet, base);
00756 tpolys.push_back(popt);
00757 this->draw_polylines(tpolys,pstyle);
00758 tpolys.clear();
00759 for (double t = 0; t<=tmax; t+=tinc)
00760 {
00761 alp = t*alpha_hat;
00762 thet = t*theta_hat;
00763 vsol_polyline_2d_sptr p = trans_poly(alp, thet, base);
00764 tpolys.push_back(p);
00765 }
00766 this->draw_polylines(tpolys);
00767 }
00768
00769 void segv_misc_manager::project_on_articulation()
00770 {
00771 this->clear_display();
00772 vgui_style_sptr mstyle = vgui_style::new_style(0.5f, 1.0f, 0.25f,
00773 1.0f, 5.0f);
00774 vgui_style_sptr pstyle = vgui_style::new_style(1.0f, 0.5f, 0.1f,
00775 1.0f, 5.0f);
00776 unsigned njoints = 4;
00777 static vcl_vector<double> joint_trans(njoints, 0);
00778 static double basis_angle = 0.25*vnl_math::pi;
00779 joint_trans[0] = 0.25*vnl_math::pi;
00780 joint_trans[1] = 0.25*vnl_math::pi;
00781 joint_trans[2] = -0.25*vnl_math::pi;
00782 vgui_dialog project_dlg("Articulation Projection Parameters");
00783 project_dlg.field("Ang 0:", joint_trans[0]);
00784 project_dlg.field("Ang 1:", joint_trans[1]);
00785 project_dlg.field("Ang 2:", joint_trans[2]);
00786 project_dlg.field("Basis Angle:", basis_angle);
00787 if (!project_dlg.ask())
00788 return;
00789 vcl_vector<double> links(njoints-1, 100.0);
00790 bvgl_articulated_poly_sptr ap = new bvgl_articulated_poly(njoints, links);
00791 ap->transform(joint_trans);
00792 ap->print();
00793
00794 vcl_vector<vsol_polyline_2d_sptr> tpolys;
00795
00796 vcl_vector<double> basis(njoints, basis_angle);
00797 for (double t = - 2.5; t<=2.5; t+=0.25)
00798 {
00799 bvgl_articulated_poly_sptr manifold =
00800 new bvgl_articulated_poly(njoints,links);
00801 manifold->sub_manifold_transform(t, basis);
00802 tpolys.push_back((vsol_polyline_2d*)(manifold.ptr()));
00803 }
00804 this->draw_polylines(tpolys);
00805 tpolys.clear();
00806 tpolys.push_back((vsol_polyline_2d*)(ap.ptr()));
00807 this->draw_polylines(tpolys, mstyle);
00808
00809 bvgl_articulated_poly_sptr proj =
00810 bvgl_articulated_poly::projection(ap, basis);
00811 tpolys.clear();
00812 tpolys.push_back((vsol_polyline_2d*)(proj.ptr()));
00813 this->draw_polylines(tpolys, pstyle);
00814 }