00001 #ifndef sdet_contour_h_
00002 #define sdet_contour_h_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #include <vcl_vector.h>
00075 #include <vbl/vbl_array_2d.h>
00076 #include <vdgl/vdgl_digital_curve_sptr.h>
00077 #include <vtol/vtol_vertex_2d_sptr.h>
00078 #include <vtol/vtol_edge_2d.h>
00079 #include <vtol/vtol_edge_2d_sptr.h>
00080 #include <gevd/gevd_bufferxy.h>
00081
00082 class sdet_contour
00083 {
00084 public:
00085 sdet_contour(float min_strength, int min_length,
00086 float min_jump,
00087 float max_gap=2.236068f);
00088 ~sdet_contour();
00089
00090
00091 bool FindNetwork(gevd_bufferxy& edgels, bool junctionp,
00092 const int njunction,
00093 const int* junctionx, const int* junctiony,
00094 vcl_vector<vtol_edge_2d_sptr>*& edges,
00095 vcl_vector<vtol_vertex_2d_sptr >*& vertices);
00096
00097
00098 void SubPixelAccuracy(vcl_vector<vtol_edge_2d_sptr>& edges,
00099 vcl_vector<vtol_vertex_2d_sptr >& vertices,
00100 const gevd_bufferxy& locationx,
00101 const gevd_bufferxy& locationy);
00102
00103
00104 void InsertBorder(vcl_vector<vtol_edge_2d_sptr>& edges,
00105 vcl_vector<vtol_vertex_2d_sptr >& vertices);
00106
00107
00108 static void EqualizeSpacing(vcl_vector<vtol_edge_2d_sptr>& chains);
00109
00110
00111
00112 static void Translate(vcl_vector<vtol_edge_2d_sptr>& edges,
00113 vcl_vector<vtol_vertex_2d_sptr >& vertices,
00114 float tx=0.5, float ty = 0.5);
00115
00116
00117 static void ClearNetwork(vcl_vector<vtol_edge_2d_sptr>*& edges,
00118 vcl_vector<vtol_vertex_2d_sptr >*& vertices);
00119
00120
00121 static void SetEdgelData(gevd_bufferxy& grad_mag, gevd_bufferxy& angle,
00122 vcl_vector<vtol_edge_2d_sptr>& edges);
00123
00124
00125 void BeSilent() {talkative_ = false;}
00126 void BeTalkative() {talkative_ = true;}
00127 void SetDebug() {debug_ = true;}
00128 void ClearDebug() {debug_ = false;}
00129
00130 static bool talkative_;
00131 static bool debug_;
00132
00133
00134 protected:
00135
00136 int FindChains(gevd_bufferxy& edgels,
00137 const int njunction,
00138 const int* junctionx, const int* junctiony,
00139 vcl_vector<vtol_edge_2d_sptr>& edges);
00140
00141
00142 int FindJunctions(gevd_bufferxy& edgels,
00143 vcl_vector<vtol_edge_2d_sptr>& edges,
00144 vcl_vector<vtol_vertex_2d_sptr >& vertices);
00145
00146 bool move_junction(vtol_vertex_2d_sptr const& junction,
00147 int& index, vdgl_digital_curve_sptr const & dc);
00148
00149 void update_edgel_chain(vtol_edge_2d_sptr const& edge,
00150 const int old_x, const int old_y,
00151 vtol_vertex_2d_sptr& v);
00152
00153 bool near_border(vtol_vertex_2d_sptr const& v);
00154
00155
00156 bool DetectJunction(vtol_vertex_2d_sptr const& end, int& index,
00157 vtol_edge_2d_sptr& weaker,
00158 vtol_edge_2d_sptr& stronger,
00159 const int maxSpiral,
00160 const gevd_bufferxy& edgels);
00161
00162
00163 void BreakChain(vtol_vertex_2d_sptr const& junction,
00164 int& index,
00165 vtol_edge_2d_sptr const& stronger,
00166 vtol_edge_2d_sptr& longer,
00167 vtol_edge_2d_sptr& shorter);
00168
00169
00170 void LoopChain(vtol_vertex_2d_sptr const& junction, int& index,
00171 vtol_edge_2d_sptr const& chain,
00172 vtol_edge_2d_sptr& straight,
00173 vtol_edge_2d_sptr& curled);
00174
00175
00176 void BreakCycle(vtol_vertex_2d_sptr const& junction,
00177 int& index, vtol_edge_2d_sptr const& stronger,
00178 vtol_edge_2d_sptr & split);
00179
00180
00181 vtol_vertex_2d_sptr
00182 DetectTouch(vtol_vertex_2d_sptr const& end, const int maxSpiral);
00183
00184
00185 void MergeEndPtTouchingEndPt(vtol_vertex_2d_sptr const& end1,
00186 vtol_vertex_2d_sptr const& end2,
00187 vtol_edge_2d_sptr& merge,
00188 vtol_edge_2d_sptr& longer,
00189 vtol_edge_2d_sptr& shorter);
00190
00191
00192 bool MergeEndPtTouchingJunction(vtol_vertex_2d_sptr const& endpt,
00193 vtol_vertex_2d_sptr const& junction,
00194 vtol_edge_2d_sptr& old_edge,
00195 vtol_edge_2d_sptr& new_edge);
00196
00197
00198 bool MergeEndPtsOfChain(vtol_vertex_2d_sptr const& endpt,
00199 vtol_vertex_2d_sptr const& other,
00200 vtol_vertex_2d_sptr& removed_vert);
00201
00202
00203
00204
00205
00206 static void LookupTableInsert(vcl_vector<vtol_edge_2d_sptr>& set,
00207 vtol_edge_2d_sptr elmt);
00208
00209
00210 static void LookupTableReplace(vcl_vector<vtol_edge_2d_sptr>& set,
00211 vtol_edge_2d_sptr deleted,
00212 vtol_edge_2d_sptr inserted);
00213
00214
00215 static void LookupTableRemove(vcl_vector<vtol_edge_2d_sptr>& set,
00216 vtol_edge_2d_sptr elmt);
00217
00218
00219 static void LookupTableCompress(vcl_vector<vtol_edge_2d_sptr>& set);
00220
00221
00222
00223 static void LookupTableInsert(vcl_vector<vtol_vertex_2d_sptr >& set,
00224 vtol_vertex_2d_sptr elmt);
00225
00226
00227 static void LookupTableReplace(vcl_vector<vtol_vertex_2d_sptr >& set,
00228 vtol_vertex_2d_sptr deleted,
00229 vtol_vertex_2d_sptr inserted);
00230
00231
00232 static void LookupTableRemove(vcl_vector<vtol_vertex_2d_sptr >& set,
00233 vtol_vertex_2d_sptr elmt);
00234
00235
00236 static void LookupTableCompress(vcl_vector<vtol_vertex_2d_sptr >& set);
00237
00238
00239 float minStrength;
00240 int minLength;
00241 float minJump;
00242 float max_gap;
00243 int maxSpiral;
00244 vbl_array_2d<vtol_edge_2d_sptr> *edgeMap;
00245 vbl_array_2d<vtol_vertex_2d_sptr> *vertexMap;
00246 vcl_vector<vtol_vertex_2d_sptr> test_verts_;
00247 };
00248
00249 #endif // sdet_contour_h_