contrib/gel/vmal/vmal_convert_osl.cxx
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // .DESCRIPTION:
00003 //   See vmal_convert_osl.h
00004 //-----------------------------------------------------------------------------
00005 
00006 #include "vmal_convert_osl.h"
00007 #include <vtol/vtol_vertex_sptr.h>
00008 #include <vtol/vtol_vertex_2d.h>
00009 #include <vtol/vtol_zero_chain.h>
00010 #include <vtol/vtol_edge_2d.h>
00011 
00012 vtol_vertex_2d_sptr convert_vertex_2d(osl_vertex & in)
00013 {
00014   return new vtol_vertex_2d(in.GetX(),in.GetY());
00015 }
00016 
00017 vtol_edge_2d_sptr convert_edge_2d(osl_edge & in,vcl_string type)
00018 {
00019   vtol_edge_2d_sptr out;
00020 
00021   if (type=="CURVE_NO_TYPE")
00022   {
00023     float *x=in.GetX();
00024     float *y=in.GetY();
00025     vcl_vector<vtol_vertex_sptr> new_vertices;
00026 
00027     for (unsigned int i=0; i<in.size(); ++i)
00028       new_vertices.push_back(new vtol_vertex_2d(x[i],y[i]));
00029     out=new vtol_edge_2d(new vtol_zero_chain(new_vertices));
00030   }
00031   else if (type=="LINE")
00032   {
00033     osl_vertex* v1=in.GetV1();
00034     osl_vertex* v2=in.GetV2();
00035     vtol_vertex_2d_sptr new_v1=convert_vertex_2d(*v1);
00036     vtol_vertex_2d_sptr new_v2=convert_vertex_2d(*v2);
00037     out=new vtol_edge_2d(new_v1,new_v2,0);
00038   }
00039 
00040   return out;
00041 }
00042 
00043 vcl_vector<vtol_edge_2d_sptr>* convert_vector_edge_2d(vcl_list<osl_edge*> & in,vcl_string type)
00044 {
00045   vcl_list<osl_edge*>::iterator iter;
00046   vcl_vector<vtol_edge_2d_sptr>* out=new vcl_vector<vtol_edge_2d_sptr>();
00047   for (iter=in.begin();iter!=in.end();iter++)
00048   {
00049     vtol_edge_2d_sptr temp_edge_2d=convert_edge_2d(*(*iter),type);
00050     out->push_back(temp_edge_2d);
00051   }
00052   return out;
00053 }
00054 
00055 vcl_vector<vcl_vector<vtol_edge_2d_sptr>*>* convert_array_edge_2d(vcl_list<vcl_list<osl_edge *>*> & in,
00056                                                                   vcl_string type)
00057 {
00058   vcl_list<vcl_list<osl_edge *>*>::iterator iter;
00059   vcl_vector<vcl_vector<vtol_edge_2d_sptr>*>* out=new vcl_vector<vcl_vector<vtol_edge_2d_sptr>*>;
00060   for (iter = in.begin();iter!=in.end();iter++)
00061   {
00062     vcl_vector<vtol_edge_2d_sptr>* vtol_lines=convert_vector_edge_2d(*(*iter),type);
00063     out->push_back(vtol_lines);
00064   }
00065   return out;
00066 }
00067 
00068 void convert_pointarray(vcl_vector<vtol_vertex_2d_sptr>& in,
00069                         vcl_vector<HomgPoint2D> & out)
00070 {
00071   vcl_vector<vtol_vertex_2d_sptr>::iterator iter;
00072   for (iter=in.begin();iter!=in.end();iter++)
00073   {
00074     HomgPoint2D temp((*iter)->x(),(*iter)->y(),1);
00075     out.push_back(temp);
00076   }
00077 }