contrib/brl/bbas/bgui/bgui_vsol2D_tableau.cxx
Go to the documentation of this file.
00001 #include "bgui_vsol2D_tableau.h"
00002 //:
00003 // \file
00004 #include <bgui/bgui_vsol_soview2D.h>
00005 #include <vgui/vgui.h>
00006 #include <vgui/vgui_style.h>
00007 #include <vsol/vsol_spatial_object_2d.h>
00008 #include <vsol/vsol_point_2d.h>
00009 #include <vsol/vsol_line_2d.h>
00010 #include <vsol/vsol_polyline_2d.h>
00011 #include <vsol/vsol_conic_2d.h>
00012 #include <vsol/vsol_polygon_2d.h>
00013 #include <vdgl/vdgl_digital_curve.h>
00014 #include <vcl_cassert.h>
00015 
00016 bgui_vsol2D_tableau::bgui_vsol2D_tableau(const char* n) :
00017   vgui_easy2D_tableau(n) { this->init(); }
00018 
00019 bgui_vsol2D_tableau::bgui_vsol2D_tableau(vgui_image_tableau_sptr const& it,
00020                                          const char* n) :
00021   vgui_easy2D_tableau(it, n) { this->init(); }
00022 
00023 bgui_vsol2D_tableau::bgui_vsol2D_tableau(vgui_tableau_sptr const& t,
00024                                          const char* n) :
00025   vgui_easy2D_tableau(t, n) { this->init(); }
00026 
00027 bgui_vsol2D_tableau::~bgui_vsol2D_tableau()
00028 {
00029 }
00030 
00031 void bgui_vsol2D_tableau::init()
00032 {
00033   //define default soview styles
00034   //these can be overridden by later set_*_syle commands prior to drawing.
00035   //
00036   point_style_                = vgui_style::new_style(0.0f, 1.0f, 0.0f, 3.0f, 1.0f);
00037   line_style_                 = vgui_style::new_style(0.8f, 0.2f, 0.9f, 1.0f, 3.0f);
00038   conic_style_                 = vgui_style::new_style(0.2f, 0.8f, 0.1f, 1.0f, 3.0f);
00039   polyline_style_             = vgui_style::new_style(0.8f, 0.2f, 0.9f, 1.0f, 3.0f);
00040   digital_curve_style_        = vgui_style::new_style(0.8f, 0.0f, 0.8f, 1.0f, 3.0f);
00041   dotted_digital_curve_style_ = vgui_style::new_style(0.8f, 0.0f, 0.8f, 3.0f, 3.0f);
00042   edgel_curve_style_          = vgui_style::new_style(0.0f, 0.5f, 0.8f, 1.0f, 3.0f);
00043   dotted_edgel_curve_style_   = vgui_style::new_style(0.0f, 0.5f, 0.8f, 3.0f, 3.0f);
00044 }
00045 
00046 
00047 bgui_vsol_soview2D_point*
00048 bgui_vsol2D_tableau::add_vsol_point_2d(vsol_point_2d_sptr const& p,
00049                                               const vgui_style_sptr& style)
00050 {
00051   bgui_vsol_soview2D_point* obj =
00052       new bgui_vsol_soview2D_point(p);
00053   add(obj);
00054   if (style)
00055     obj->set_style( style );
00056   else
00057     obj->set_style( point_style_ );
00058   return obj;
00059 }
00060 
00061 
00062 bgui_vsol_soview2D_line_seg*
00063 bgui_vsol2D_tableau::add_vsol_line_2d(vsol_line_2d_sptr const& line,
00064                                              const vgui_style_sptr& style)
00065 {
00066   bgui_vsol_soview2D_line_seg* obj =
00067       new bgui_vsol_soview2D_line_seg(line);
00068   add(obj);
00069   if (style)
00070     obj->set_style( style );
00071   else
00072     obj->set_style( line_style_ );
00073   return obj;
00074 }
00075 
00076 
00077 bgui_vsol_soview2D_conic_seg*
00078 bgui_vsol2D_tableau::add_vsol_conic_2d(vsol_conic_2d_sptr const& conic,
00079                                       const vgui_style_sptr& style)
00080 {
00081   bgui_vsol_soview2D_conic_seg* obj =
00082       new bgui_vsol_soview2D_conic_seg(conic);
00083   add(obj);
00084   if (style)
00085     obj->set_style( style );
00086   else
00087     obj->set_style( conic_style_ );
00088   return obj;
00089 }
00090 
00091 
00092 bgui_vsol_soview2D_polyline*
00093 bgui_vsol2D_tableau::add_vsol_polyline_2d(vsol_polyline_2d_sptr const& pline,
00094                                                  const vgui_style_sptr& style)
00095 {
00096   bgui_vsol_soview2D_polyline* obj =
00097       new bgui_vsol_soview2D_polyline(pline);
00098   add(obj);
00099   if (style)
00100     obj->set_style( style );
00101   else
00102     obj->set_style( polyline_style_ );
00103   return obj;
00104 }
00105 
00106 
00107 bgui_vsol_soview2D_polygon*
00108 bgui_vsol2D_tableau::add_vsol_polygon_2d(vsol_polygon_2d_sptr const& pline,
00109                                                 const vgui_style_sptr& style)
00110 {
00111   bgui_vsol_soview2D_polygon* obj =
00112       new bgui_vsol_soview2D_polygon(pline);
00113   add(obj);
00114   if (style)
00115     obj->set_style( style );
00116   else
00117     obj->set_style( polyline_style_ );
00118   return obj;
00119 }
00120 
00121 bgui_vsol_soview2D_polygon_set*
00122 bgui_vsol2D_tableau::add_vsol_polygon_2d_set(vsol_poly_set_2d_sptr const& set,
00123                                              const vgui_style_sptr& style)
00124 {
00125   bgui_vsol_soview2D_polygon_set* obj =
00126       new bgui_vsol_soview2D_polygon_set(set);
00127   add(obj);
00128   if (style)
00129     obj->set_style( style );
00130   else
00131     obj->set_style( polyline_style_ );
00132   return obj;
00133 }
00134 
00135 bgui_vsol_soview2D_digital_curve*
00136 bgui_vsol2D_tableau::add_digital_curve(vsol_digital_curve_2d_sptr const& dc,
00137                                        const vgui_style_sptr& style)
00138 {
00139   bgui_vsol_soview2D_digital_curve* obj =
00140     new bgui_vsol_soview2D_digital_curve(dc);
00141   add(obj);
00142   if (style)
00143     obj->set_style( style );
00144   else
00145     obj->set_style( digital_curve_style_ );
00146   return obj;
00147 }
00148 
00149 
00150 bgui_vsol_soview2D_digital_curve*
00151 bgui_vsol2D_tableau::add_dotted_digital_curve(vsol_digital_curve_2d_sptr const& dc,
00152                                               const vgui_style_sptr& style)
00153 {
00154   bgui_vsol_soview2D_digital_curve* obj =
00155       new bgui_vsol_soview2D_digital_curve(dc, true);
00156   add(obj);
00157   if (style)
00158     obj->set_style( style );
00159   else
00160     obj->set_style( dotted_digital_curve_style_ );
00161   return obj;
00162 }
00163 
00164 
00165 bgui_vsol_soview2D_edgel_curve*
00166 bgui_vsol2D_tableau::add_edgel_curve(vdgl_digital_curve_sptr const& dc,
00167                                               const vgui_style_sptr& style)
00168 {
00169   bgui_vsol_soview2D_edgel_curve* obj =
00170     new bgui_vsol_soview2D_edgel_curve(dc);
00171   add(obj);
00172   if (style)
00173     obj->set_style( style );
00174   else
00175     obj->set_style( edgel_curve_style_ );
00176   return obj;
00177 }
00178 
00179 
00180 bgui_vsol_soview2D_edgel_curve*
00181 bgui_vsol2D_tableau::add_dotted_edgel_curve(vdgl_digital_curve_sptr const& dc,
00182                                             const vgui_style_sptr& style)
00183 {
00184   bgui_vsol_soview2D_edgel_curve* obj =
00185       new bgui_vsol_soview2D_edgel_curve(dc, true);
00186   add(obj);
00187   if (style)
00188     obj->set_style( style );
00189   else
00190     obj->set_style( dotted_edgel_curve_style_ );
00191   return obj;
00192 }
00193 
00194 
00195 void bgui_vsol2D_tableau::
00196 add_spatial_objects(vcl_vector<vsol_spatial_object_2d_sptr> const& sos,
00197                     const vgui_style_sptr& style)
00198 {
00199   for (vcl_vector<vsol_spatial_object_2d_sptr>::const_iterator sit = sos.begin();
00200        sit != sos.end(); sit++)
00201   {
00202     add_spatial_object( (*sit) , style );
00203   }
00204 }
00205 
00206 
00207 void bgui_vsol2D_tableau::
00208 add_spatial_object(vsol_spatial_object_2d_sptr const& sos,
00209                    const vgui_style_sptr& style)
00210 {
00211   if (sos->cast_to_point()) {
00212     vsol_point_2d_sptr p = sos->cast_to_point();
00213     this->add_vsol_point_2d(p , style );
00214   }
00215   else if (sos->cast_to_curve())
00216   {
00217     if (sos->cast_to_curve()->cast_to_digital_curve())
00218     {
00219       vsol_digital_curve_2d_sptr dc =
00220         sos->cast_to_curve()->cast_to_digital_curve();
00221       this->add_digital_curve(dc , style);
00222     }
00223     else if (sos->cast_to_curve()->cast_to_vdgl_digital_curve())
00224     {
00225       vdgl_digital_curve_sptr dc =
00226         sos->cast_to_curve()->cast_to_vdgl_digital_curve();
00227       this->add_edgel_curve(dc , style);
00228     }
00229     else if (sos->cast_to_curve()->cast_to_line())
00230     {
00231       vsol_line_2d_sptr line =
00232         sos->cast_to_curve()->cast_to_line();
00233       this->add_vsol_line_2d(line, style);
00234     }
00235     else if (sos->cast_to_curve()->cast_to_polyline())
00236     {
00237       vsol_polyline_2d_sptr pline =
00238         sos->cast_to_curve()->cast_to_polyline();
00239       this->add_vsol_polyline_2d(pline , style);
00240     }
00241     else if (sos->cast_to_curve()->cast_to_conic())
00242     {
00243       vsol_conic_2d_sptr conic = sos->cast_to_curve()->cast_to_conic();
00244 
00245       // make sure the endpoints are already defined
00246       assert(conic->p0() && conic->p1());
00247 
00248       this->add_vsol_conic_2d(conic, style);
00249     }
00250     else
00251       assert(!"unknown curve type in bgui_vsol2D_tableau::add_spatial_object()");
00252   }
00253   else if (sos->cast_to_region()) {
00254     if (sos->cast_to_region()->cast_to_polygon())
00255     {
00256       vsol_polygon_2d_sptr pline =
00257         sos->cast_to_region()->cast_to_polygon();
00258       this->add_vsol_polygon_2d(pline, style);
00259     }
00260     else
00261       assert(!"unknown region type in bgui_vsol2D_tableau::add_spatial_object()");
00262   }
00263   else
00264     assert(!"unknown spatial object type in bgui_vsol2D_tableau::add_spatial_object()");
00265   return;
00266 }
00267 
00268 
00269 void bgui_vsol2D_tableau::set_vsol_spatial_object_2d_style(vsol_spatial_object_2d_sptr sos,
00270                                                            const vgui_style_sptr& style)
00271 {
00272   if (sos->cast_to_point()) {
00273     set_vsol_point_2d_style(style);
00274   }
00275   else if (sos->cast_to_curve()) {
00276     set_digital_curve_style(style);
00277   }
00278 }
00279 
00280 
00281 void bgui_vsol2D_tableau::set_vsol_point_2d_style(const vgui_style_sptr& style)
00282 {
00283   point_style_->rgba[0] = style->rgba[0];
00284   point_style_->rgba[1] = style->rgba[1];
00285   point_style_->rgba[2] = style->rgba[2];
00286   point_style_->point_size = style->point_size;
00287   point_style_->line_width = style->line_width;
00288 }
00289 
00290 
00291 void bgui_vsol2D_tableau::set_vsol_line_2d_style(const vgui_style_sptr& style)
00292 {
00293   line_style_->rgba[0] = style->rgba[0];
00294   line_style_->rgba[1] = style->rgba[1];
00295   line_style_->rgba[2] = style->rgba[2];
00296   line_style_->point_size = style->point_size;
00297   line_style_->line_width = style->line_width;
00298 }
00299 
00300 
00301 void bgui_vsol2D_tableau::set_vsol_polyline_2d_style(const vgui_style_sptr& style)
00302 {
00303   polyline_style_->rgba[0] = style->rgba[0];
00304   polyline_style_->rgba[1] = style->rgba[1];
00305   polyline_style_->rgba[2] = style->rgba[2];
00306   polyline_style_->point_size = style->point_size;
00307   polyline_style_->line_width = style->line_width;
00308 }
00309 
00310 
00311 void bgui_vsol2D_tableau::set_digital_curve_style(const vgui_style_sptr& style)
00312 {
00313   digital_curve_style_->rgba[0] = style->rgba[0];
00314   digital_curve_style_->rgba[1] = style->rgba[1];
00315   digital_curve_style_->rgba[2] = style->rgba[2];
00316   digital_curve_style_->point_size = style->point_size;
00317   digital_curve_style_->line_width = style->line_width;
00318 }
00319 
00320 
00321 void bgui_vsol2D_tableau::set_dotted_digital_curve_style(const vgui_style_sptr& style)
00322 {
00323   dotted_digital_curve_style_->rgba[0] = style->rgba[0];
00324   dotted_digital_curve_style_->rgba[1] = style->rgba[1];
00325   dotted_digital_curve_style_->rgba[2] = style->rgba[2];
00326   dotted_digital_curve_style_->point_size = style->point_size;
00327   dotted_digital_curve_style_->line_width = style->line_width;
00328 }
00329 
00330 
00331 void bgui_vsol2D_tableau::set_edgel_curve_style(const vgui_style_sptr& style)
00332 {
00333   edgel_curve_style_->rgba[0] = style->rgba[0];
00334   edgel_curve_style_->rgba[1] = style->rgba[1];
00335   edgel_curve_style_->rgba[2] = style->rgba[2];
00336   edgel_curve_style_->point_size = style->point_size;
00337   edgel_curve_style_->line_width = style->line_width;
00338 }
00339 
00340 
00341 void bgui_vsol2D_tableau::set_dotted_edgel_curve_style(const vgui_style_sptr& style)
00342 {
00343   dotted_edgel_curve_style_->rgba[0] = style->rgba[0];
00344   dotted_edgel_curve_style_->rgba[1] = style->rgba[1];
00345   dotted_edgel_curve_style_->rgba[2] = style->rgba[2];
00346   dotted_edgel_curve_style_->point_size = style->point_size;
00347   dotted_edgel_curve_style_->line_width = style->line_width;
00348 }