contrib/brl/bbas/btol/btol_vertex_algs.cxx
Go to the documentation of this file.
00001 #include "btol_vertex_algs.h"
00002 //:
00003 // \file
00004 #include <vcl_cmath.h> // for fabs()
00005 #include <vcl_algorithm.h>
00006 #include "btol_edge_algs.h"
00007 #include <vtol/vtol_vertex.h>
00008 #include <vtol/vtol_vertex_2d.h>
00009 #include <vtol/vtol_edge_sptr.h>
00010 
00011 //: Destructor
00012 btol_vertex_algs::~btol_vertex_algs()
00013 {
00014 }
00015 
00016 //:
00017 //-----------------------------------------------------------------------------
00018 // Replaces va by vb on all the edges connected to va.
00019 // The result is that vb has the union of the sets of
00020 // edges incident on va and vb as superiors.
00021 //-----------------------------------------------------------------------------
00022 bool btol_vertex_algs::merge_superiors(vtol_vertex_sptr& va,
00023                                        vtol_vertex_sptr& vb)
00024 {
00025   if (!va||!vb)
00026     return false;
00027   vcl_vector<vtol_edge_sptr> edges; va->edges(edges);
00028   for (vcl_vector<vtol_edge_sptr>::iterator eit = edges.begin();
00029        eit != edges.end(); eit++)
00030     btol_edge_algs::subst_vertex_on_edge(va, vb, *eit);
00031   return true;
00032 }
00033 
00034 #if 0 // unused static function
00035 static void vertex_erase(vcl_vector<vtol_vertex_sptr>& verts,
00036                          vtol_vertex_sptr& v)
00037 {
00038   vcl_vector<vtol_vertex_sptr>::iterator vit =
00039     vcl_find(verts.begin(), verts.end(), v);
00040   if (vit == verts.end())
00041     return;
00042   verts.erase(vit);
00043   return;
00044 }
00045 #endif // 0
00046 
00047 vtol_vertex_2d_sptr btol_vertex_algs::
00048 transform(vtol_vertex_2d_sptr const& v,
00049           vnl_matrix_fixed<double,3,3> const& T)
00050 {
00051   vnl_vector_fixed<double,3> P(v->x(), v->y(), 1.0);
00052   vnl_vector_fixed<double,3> p = T*P;
00053   if (vcl_fabs(p[2])<1e-06)
00054     return 0;
00055   else
00056     return new vtol_vertex_2d(p[0]/p[2], p[1]/p[2]);
00057 }
00058