Go to the documentation of this file.00001 #include "bgui_vtol2D_tableau.h"
00002
00003
00004 #include <bgui/bgui_vtol_soview2D.h>
00005 #include <vgui/vgui.h>
00006 #include <vgui/vgui_style.h>
00007 #include <vtol/vtol_face_2d.h>
00008 #include <vdgl/vdgl_edgel_chain.h>
00009 #include <vdgl/vdgl_interpolator.h>
00010
00011
00012 bgui_vtol2D_tableau::bgui_vtol2D_tableau(const char* n) :
00013 bgui_vsol2D_tableau(n) { this->init(); }
00014
00015 bgui_vtol2D_tableau::bgui_vtol2D_tableau(vgui_image_tableau_sptr const& it,
00016 const char* n) :
00017 bgui_vsol2D_tableau(it, n) { this->init(); }
00018
00019 bgui_vtol2D_tableau::bgui_vtol2D_tableau(vgui_tableau_sptr const& t,
00020 const char* n) :
00021 bgui_vsol2D_tableau(t, n) { this->init(); }
00022
00023 bgui_vtol2D_tableau::~bgui_vtol2D_tableau()
00024 {
00025 #if 0 //not needed if vgui::quit() is used
00026 this->clear_all();
00027 #endif
00028 }
00029
00030 #ifdef DEBUG
00031 static void print_edgels(vtol_edge_2d_sptr const & e)
00032 {
00033 vsol_curve_2d_sptr c = e->curve();
00034 if (!c) return;
00035 vdgl_digital_curve_sptr dc = c->cast_to_vdgl_digital_curve();
00036 if (!dc) return;
00037 vdgl_interpolator_sptr trp = dc->get_interpolator();
00038 if (!trp) return;
00039 vdgl_edgel_chain_sptr ec = trp->get_edgel_chain();
00040 if (!ec)
00041 return;
00042 int N = ec->size();
00043 for (int i = 0; i<N; i++)
00044 vcl_cout << "egl(" << i << ")=" << (*ec)[i] << '\n';
00045 }
00046 #endif
00047
00048 void bgui_vtol2D_tableau::init()
00049 {
00050
00051
00052
00053 vertex_style_ = vgui_style::new_style(1.0f, 0.0f, 0.0f, 3.0f, 0.0f);
00054 edge_style_ = vgui_style::new_style(0.0f, 1.0f, 0.0f, 1.0f, 3.0f);
00055 edge_group_style_ = vgui_style::new_style(0.0f, 1.0f, 0.0f, 1.0f, 3.0f);
00056 face_style_ = vgui_style::new_style(0.0f, 1.0f, 0.0f, 1.0f, 3.0f);
00057
00058
00059 bgui_vsol2D_tableau::init();
00060 }
00061
00062 bool bgui_vtol2D_tableau::handle(vgui_event const &e)
00063 {
00064
00065 return bgui_vsol2D_tableau::handle(e);
00066 }
00067
00068
00069 bgui_vtol_soview2D_vertex*
00070 bgui_vtol2D_tableau::add_vertex(vtol_vertex_2d_sptr const& v,
00071 const vgui_style_sptr& style)
00072 {
00073 bgui_vtol_soview2D_vertex* obj = new bgui_vtol_soview2D_vertex();
00074 obj->x = (float)v->x();
00075 obj->y = (float)v->y();
00076 add(obj);
00077 if (style)
00078 obj->set_style( style );
00079 else
00080 obj->set_style( vertex_style_ );
00081
00082 if (obj) {
00083 int id = obj->get_id();
00084 obj_map_[id]=v->cast_to_topology_object();
00085 }
00086 return obj;
00087 }
00088
00089
00090 bgui_vtol_soview2D_edge*
00091 bgui_vtol2D_tableau::add_edge(vtol_edge_2d_sptr const& e,
00092 const vgui_style_sptr& style)
00093 {
00094 #ifdef DEBUG
00095 print_edgels(e);
00096 #endif
00097 bgui_vtol_soview2D_edge* obj = new bgui_vtol_soview2D_edge(e);
00098
00099 add(obj);
00100 if (style)
00101 obj->set_style( style );
00102 else
00103 obj->set_style( edge_style_ );
00104
00105 if (obj) {
00106 int id = obj->get_id();
00107 obj_map_[id]=e->cast_to_topology_object();
00108 }
00109 return obj;
00110 }
00111
00112
00113 bgui_vtol_soview2D_edge_group*
00114 bgui_vtol2D_tableau::add_edge_group(vcl_vector<vtol_edge_2d_sptr>& edges,
00115 const vgui_style_sptr& style )
00116 {
00117 bgui_vtol_soview2D_edge_group* obj =
00118 new bgui_vtol_soview2D_edge_group(edges);
00119 add(obj);
00120 if (style)
00121 obj->set_style( style );
00122 else
00123 obj->set_style( edge_group_style_ );
00124
00125 return obj;
00126 }
00127
00128
00129 bgui_vtol_soview2D_face*
00130 bgui_vtol2D_tableau::add_face(vtol_face_2d_sptr const& f,
00131 const vgui_style_sptr& style)
00132 {
00133 bgui_vtol_soview2D_face* obj = new bgui_vtol_soview2D_face(f);
00134
00135 add(obj);
00136 if (style)
00137 obj->set_style( style );
00138 else
00139 obj->set_style( face_style_ );
00140
00141 if (obj) {
00142 int id = obj->get_id();
00143 obj_map_[id]=f->cast_to_topology_object();
00144 }
00145 return obj;
00146 }
00147
00148
00149
00150
00151 void bgui_vtol2D_tableau::
00152 add_topology_objects(vcl_vector<vtol_topology_object_sptr> const& tos,
00153 const vgui_style_sptr& style)
00154 {
00155 for (vcl_vector<vtol_topology_object_sptr>::const_iterator tot = tos.begin();
00156 tot != tos.end(); tot++)
00157 {
00158 add_topology_object((*tot) , style );
00159 }
00160 }
00161
00162
00163 void bgui_vtol2D_tableau::
00164 add_topology_object(vtol_topology_object_sptr const& tos,
00165 const vgui_style_sptr& style)
00166 {
00167 if (tos->cast_to_vertex()) {
00168 if (tos->cast_to_vertex()->cast_to_vertex_2d())
00169 {
00170 vtol_vertex_2d_sptr v = tos->cast_to_vertex()->cast_to_vertex_2d();
00171 this->add_vertex(v , style );
00172 }
00173 }
00174 else if (tos->cast_to_edge()) {
00175 if (tos->cast_to_edge()->cast_to_edge_2d())
00176 {
00177 vtol_edge_2d_sptr e = tos->cast_to_edge()->cast_to_edge_2d();
00178 this->add_edge(e , style );
00179 }
00180 }
00181 else if (tos->cast_to_face()) {
00182 if (tos->cast_to_face()->cast_to_face_2d())
00183 {
00184 vtol_face_2d_sptr f = tos->cast_to_face()->cast_to_face_2d();
00185 this->add_face(f , style );
00186 }
00187 }
00188 }
00189
00190
00191 void bgui_vtol2D_tableau::add_edges(vcl_vector<vtol_edge_2d_sptr> const& edges,
00192 bool verts ,
00193 const vgui_style_sptr& style )
00194 {
00195 for (vcl_vector<vtol_edge_2d_sptr>::const_iterator eit = edges.begin();
00196 eit != edges.end(); eit++)
00197 {
00198 this->add_edge(*eit , style );
00199
00200 if (verts)
00201 {
00202 vcl_vector<vtol_vertex_sptr> vts; (*eit)->vertices(vts);
00203 for (vcl_vector<vtol_vertex_sptr>::iterator vit = vts.begin();
00204 vit != vts.end(); vit++)
00205 this->add_vertex((*vit)->cast_to_vertex_2d(), style);
00206 }
00207 }
00208 }
00209
00210
00211 void
00212 bgui_vtol2D_tableau::add_faces(vcl_vector<vtol_face_2d_sptr> const& faces,
00213 bool verts,
00214 const vgui_style_sptr& style )
00215 {
00216 for (vcl_vector<vtol_face_2d_sptr>::const_iterator fit = faces.begin();
00217 fit != faces.end(); fit++)
00218 {
00219 vtol_face_2d_sptr f = (*fit);
00220 this->add_face(f , style );
00221 if (verts)
00222 {
00223 vcl_vector<vtol_vertex_sptr> vts; f->vertices(vts);
00224 for (vcl_vector<vtol_vertex_sptr>::iterator vit = vts.begin();
00225 vit != vts.end(); vit++)
00226 this->add_vertex((*vit)->cast_to_vertex_2d(), style);
00227 }
00228 }
00229 }
00230
00231
00232 vtol_edge_2d_sptr bgui_vtol2D_tableau::get_mapped_edge(const int id)
00233 {
00234 vtol_topology_object_sptr to = obj_map_[id];
00235 if (!to)
00236 {
00237 vcl_cout << "In bgui_vtol2D_tableau::get_mapped_edge(..) - null map entry\n";
00238 return 0;
00239 }
00240 return to->cast_to_edge()->cast_to_edge_2d();
00241 }
00242
00243 vtol_face_2d_sptr bgui_vtol2D_tableau::get_mapped_face(const int id)
00244 {
00245 vtol_topology_object_sptr to = obj_map_[id];
00246 if (!to)
00247 {
00248 vcl_cout << "In bgui_vtol2D_tableau::get_mapped_face(..) - null map entry\n";
00249 return 0;
00250 }
00251 return to->cast_to_face()->cast_to_face_2d();
00252 }
00253
00254
00255 void bgui_vtol2D_tableau::clear_all()
00256 {
00257 obj_map_.clear();
00258
00259
00260 vgui_easy2D_tableau::clear();
00261 }
00262
00263 void bgui_vtol2D_tableau::set_vtol_topology_object_style(vtol_topology_object_sptr tos,
00264 const vgui_style_sptr& style)
00265 {
00266 if (tos->cast_to_vertex())
00267 set_vertex_style(style);
00268 else if (tos->cast_to_edge()) {
00269 set_edge_style(style);
00270 set_edge_group_style(style);
00271 }
00272 else if (tos->cast_to_face())
00273 set_face_style(style);
00274 }
00275
00276 void bgui_vtol2D_tableau::set_vertex_style(const vgui_style_sptr& style)
00277 {
00278 vertex_style_ = style;
00279 }
00280
00281 void bgui_vtol2D_tableau::set_edge_style(const vgui_style_sptr& style)
00282 {
00283 edge_style_ = style;
00284 }
00285
00286 void bgui_vtol2D_tableau::set_edge_group_style(const vgui_style_sptr& style)
00287 {
00288 edge_group_style_ = style;
00289 }
00290
00291 void bgui_vtol2D_tableau::set_face_style(const vgui_style_sptr& style)
00292 {
00293 face_style_ = style;
00294 }