00001 #include "bgui_vtol_soview2D.h" 00002 //: 00003 // \file 00004 #include <vcl_iostream.h> 00005 #include <vgui/vgui_gl.h> 00006 #include <vdgl/vdgl_digital_curve.h> 00007 #include <vdgl/vdgl_interpolator.h> 00008 #include <vdgl/vdgl_edgel_chain.h> 00009 #include <vsol/vsol_point_2d.h> 00010 #include <vsol/vsol_point_2d_sptr.h> 00011 #include <vsol/vsol_line_2d.h> 00012 #include <vtol/vtol_face_2d.h> 00013 00014 //-------------------------------------------------------------------------- 00015 //: vsol_point_2d view 00016 //-------------------------------------------------------------------------- 00017 vcl_ostream& bgui_vtol_soview2D_point::print(vcl_ostream& s) const 00018 { 00019 s << "[bgui_vtol_soview2D_point " << x << ',' << y << ' '; 00020 return vgui_soview2D::print(s) << ']'; 00021 } 00022 00023 00024 //-------------------------------------------------------------------------- 00025 //: vdgl_digital_curve view 00026 //-------------------------------------------------------------------------- 00027 vcl_ostream& bgui_vtol_soview2D_dotted_digital_curve::print(vcl_ostream& s) const 00028 { 00029 return s; 00030 } 00031 00032 bgui_vtol_soview2D_dotted_digital_curve:: 00033 bgui_vtol_soview2D_dotted_digital_curve(vdgl_digital_curve_sptr const& dc) 00034 { 00035 if (!dc) 00036 { 00037 vcl_cout << "In bgui_vtol_soview2D_dotted_digital_curve(..) - null input dc\n"; 00038 return; 00039 } 00040 00041 //get the edgel chain 00042 vdgl_interpolator_sptr itrp = dc->get_interpolator(); 00043 vdgl_edgel_chain_sptr ech = itrp->get_edgel_chain(); 00044 00045 //n, x, and y are in the parent class vgui_soview2D_linestrip 00046 unsigned int n = ech->size(); 00047 00048 float x, y; 00049 for (unsigned int i=0; i<n;i++) 00050 { 00051 vdgl_edgel ed = (*ech)[i]; 00052 x = (float)ed.get_x(); 00053 y = (float)ed.get_y(); 00054 vgui_soview2D* p = new vgui_soview2D_point(x, y); 00055 ls.push_back(p); 00056 } 00057 return; 00058 } 00059 00060 //: vdgl_digital_curve view 00061 //-------------------------------------------------------------------------- 00062 vcl_ostream& bgui_vtol_soview2D_digital_curve::print(vcl_ostream& s) const 00063 { 00064 return s; 00065 } 00066 00067 bgui_vtol_soview2D_digital_curve:: 00068 bgui_vtol_soview2D_digital_curve(vdgl_digital_curve_sptr const& dc) 00069 { 00070 if (!dc) 00071 { 00072 vcl_cout << "In bgui_vtol_soview2D_digital_curve(..) - null input dc\n"; 00073 return; 00074 } 00075 00076 //get the edgel chain 00077 vdgl_interpolator_sptr itrp = dc->get_interpolator(); 00078 vdgl_edgel_chain_sptr ech = itrp->get_edgel_chain(); 00079 00080 //n, x, and y are in the parent class vgui_soview2D_linestrip 00081 n = ech->size(); 00082 00083 x = new float[n], y = new float[n]; 00084 for (unsigned int i=0; i<n;i++) 00085 { 00086 vdgl_edgel ed = (*ech)[i]; 00087 x[i] = (float)ed.get_x(); 00088 y[i] = (float)ed.get_y(); 00089 } 00090 00091 return; 00092 } 00093 00094 00095 bgui_vtol_soview2D_line_seg:: 00096 bgui_vtol_soview2D_line_seg(vsol_line_2d_sptr const& seg) 00097 { 00098 vsol_point_2d_sptr p0 = seg->p0(); 00099 vsol_point_2d_sptr p1 = seg->p1(); 00100 x0 = (float)p0->x(); y0 = (float)p0->y(); 00101 x1 = (float)p1->x(); y1 = (float)p1->y(); 00102 } 00103 00104 //-------------------------------------------------------------------------- 00105 //: vtol_vertex_2d view 00106 //-------------------------------------------------------------------------- 00107 vcl_ostream& bgui_vtol_soview2D_vertex::print(vcl_ostream& s) const 00108 { 00109 s << "[bgui_vtol_soview2D_vertex " << x << ',' << y << ' '; 00110 return vgui_soview2D::print(s) << ']'; 00111 } 00112 00113 00114 //-------------------------------------------------------------------------- 00115 //: vtol_edge_2d view 00116 //-------------------------------------------------------------------------- 00117 vcl_ostream& bgui_vtol_soview2D_edge::print(vcl_ostream& s) const 00118 { 00119 return vgui_soview2D_linestrip::print(s); 00120 } 00121 00122 bgui_vtol_soview2D_edge::bgui_vtol_soview2D_edge(vtol_edge_2d_sptr const& e) 00123 { 00124 if (!e) 00125 { 00126 vcl_cout << "In bgui_vtol_soview2D_edge(..) - null input edge\n"; 00127 return; 00128 } 00129 00130 //find out what kind of curve the edge has 00131 vsol_curve_2d_sptr c = e->curve(); 00132 if (!c) 00133 { 00134 vcl_cout << "In bgui_vtol_soview2D_edge(..) - null curve\n"; 00135 return; 00136 } 00137 if (c->cast_to_vdgl_digital_curve()) 00138 { 00139 vdgl_digital_curve_sptr dc = c->cast_to_vdgl_digital_curve(); 00140 //get the edgel chain 00141 vdgl_interpolator_sptr itrp = dc->get_interpolator(); 00142 vdgl_edgel_chain_sptr ech = itrp->get_edgel_chain(); 00143 00144 //n, x, and y are in the parent class vgui_soview2D_linestrip 00145 n = ech->size(); 00146 //offset the coordinates for display (may not be needed) 00147 x = new float[n], y = new float[n]; 00148 for (unsigned int i=0; i<n;i++) 00149 { 00150 vdgl_edgel ed = (*ech)[i]; 00151 x[i] = (float)ed.get_x(); 00152 y[i] = (float)ed.get_y(); 00153 } 00154 return; 00155 } 00156 if (c->cast_to_line()) 00157 { 00158 n = 2; 00159 x = new float[n], y = new float[n]; 00160 vsol_line_2d_sptr l = c->cast_to_line(); 00161 vsol_point_2d_sptr p0 = l->p0(); 00162 x[0] = (float)p0->x(); y[0] = (float)p0->y(); 00163 vsol_point_2d_sptr p1 = l->p1(); 00164 x[1] = (float)p1->x(); y[1] = (float)p1->y(); 00165 return; 00166 } 00167 vcl_cout << "In bgui_vtol_soview2D_edge(vtol_edge_2d_sptr& e) -" 00168 << " attempt to draw an edge with unknown curve geometry\n"; 00169 } 00170 00171 //-------------------------------------------------------------------------- 00172 //: vtol_edge_2d group view 00173 //-------------------------------------------------------------------------- 00174 00175 vcl_ostream& bgui_vtol_soview2D_edge_group::print(vcl_ostream& s) const 00176 { 00177 return vgui_soview2D_group::print(s); 00178 } 00179 00180 bgui_vtol_soview2D_edge_group:: 00181 bgui_vtol_soview2D_edge_group(vcl_vector<vtol_edge_2d_sptr>& edges) 00182 { 00183 for (vcl_vector<vtol_edge_2d_sptr>::iterator eit = edges.begin(); 00184 eit != edges.end(); eit++) 00185 ls.push_back(new bgui_vtol_soview2D_edge(*eit)); 00186 } 00187 00188 //-------------------------------------------------------------------------- 00189 //: vtol_face_2d view 00190 //-------------------------------------------------------------------------- 00191 00192 vcl_ostream& bgui_vtol_soview2D_face::print(vcl_ostream& s) const 00193 { 00194 return vgui_soview2D_group::print(s); 00195 } 00196 00197 00198 bgui_vtol_soview2D_face::bgui_vtol_soview2D_face(vtol_face_2d_sptr const& f) 00199 { 00200 if (!f) 00201 { 00202 vcl_cout << "In bgui_vtol_soview2D_face(..) - null input face\n"; 00203 return; 00204 } 00205 00206 edge_list edges; f->edges(edges); 00207 for (edge_list::iterator eit = edges.begin(); eit != edges.end(); ++eit) 00208 ls.push_back(new bgui_vtol_soview2D_edge((*eit)->cast_to_edge_2d())); 00209 }