contrib/gel/gevd/gevd_clean_edgels.h
Go to the documentation of this file.
00001 #ifndef gevd_clean_edgels_h_
00002 #define gevd_clean_edgels_h_
00003 //:
00004 // \file
00005 // \brief Remove edgel chains with (1) end vertices closer than 3 pixels, (2) bridges, (3) self-intersection
00006 //
00007 //  In using an edge segmentation for region analysis it is necessary to
00008 //  eliminate edges that do not permit the extraction of valid region
00009 //  topology. There are a number of conditions that would defeat a region
00010 //  analysis algorithm:
00011 //
00012 //   1: Too short edges.  If the vertices of an edge closer than 3 pixels,
00013 //   (where distance is measured by the minimum image distance along the
00014 //    image axis) and the edgels are all within a pixel of a straight line
00015 //   joining the vertices then the edge should be eliminated and replaced
00016 //   by a single vertex at the midpoint of the original vertices.
00017 //
00018 //   2: Insufficient edgels.  In some cases the VDEdgeDetector does not
00019 //     supply enough edgels to form a continuous chain between vertices.
00020 //     This problem appears to happen for n_edgels<=2.
00021 //
00022 //   3: Bridges.  There is no point in passing edges which have a vertex
00023 //   of order 1. That is, there is only one edge incident on the vertex.
00024 //   Such edges will never lead to a correct region topology.
00025 //
00026 //   4: Self intersection. An edge should never intersect itself in any case,
00027 //   but it might be possible that an edge-detection algorithm could produce
00028 //   such edges. For example, the VanDuc edge-detector does currently
00029 //   form self-intersecting edges.(not yet implemented)
00030 //
00031 // \author
00032 //  J.L. Mundy - Feb 20, 1999
00033 //
00034 // \verbatim
00035 //  Modifications
00036 //   Feb 2001
00037 //         Effectively the same as Detection/Clean.h but duplicated here
00038 //         to allow for CAD required changes
00039 // \endverbatim
00040 //-------------------------------------------------------------------------
00041 #include <vcl_vector.h>
00042 #include <vtol/vtol_vertex_2d.h>
00043 #include <vtol/vtol_vertex_2d_sptr.h>
00044 #include <vtol/vtol_edge_2d_sptr.h>
00045 #include <vsol/vsol_point_2d_sptr.h>
00046 
00047 class gevd_clean_edgels
00048 {
00049  public:
00050   gevd_clean_edgels();
00051   ~gevd_clean_edgels();
00052   void DoCleanEdgelChains(vcl_vector<vtol_edge_2d_sptr>& in_edgels, vcl_vector<vtol_edge_2d_sptr>& out_edgels, int steps = 10);
00053   void JumpGaps();
00054   void RemoveBridges();
00055   void DeleteShortEdges();
00056   void FixDefficientEdgels();
00057   void RemoveJaggies();
00058   void RemoveLoops();
00059  protected:
00060   void print_protection();
00061   void detect_similar_edges(vcl_vector<vtol_edge_2d_sptr>& common_edges, float tolerance,
00062                             vcl_vector<vtol_edge_2d_sptr>& deleted_edges);
00063   void remove_similar_edges(vtol_vertex_2d*& v1, vcl_vector<vtol_edge_2d_sptr>& deleted_edges);
00064   bool edge_exists(vtol_vertex_2d_sptr v1, vtol_vertex_2d_sptr v2, vcl_vector<vtol_edge_2d_sptr>& intersection);
00065   void remove_connected_edges(vtol_vertex_2d* v, vcl_vector<vtol_edge_2d_sptr>& edges);
00066   bool closest_vertex(vtol_edge_2d_sptr e, vsol_point_2d_sptr p, float radius, vtol_vertex_2d_sptr& v);
00067   bool split_edge(vtol_edge_2d_sptr e, vtol_vertex_2d_sptr v, vtol_edge_2d_sptr& e1, vtol_edge_2d_sptr& e2);
00068   vcl_vector<vtol_edge_2d_sptr>* out_edgels_;
00069 };
00070 
00071 #endif // gevd_clean_edgels_h_