00001
00002 #include "gkll_multi_view_data.h"
00003
00004 #include <vtol/vtol_vertex_2d.h>
00005 #include <vtol/vtol_vertex_2d_sptr.h>
00006 #include <vtol/vtol_edge_2d.h>
00007 #include <vtol/vtol_edge_2d_sptr.h>
00008
00009 template <class T>
00010 gkll_multi_view_data<T>::gkll_multi_view_data():
00011 nbviews_(0)
00012 {
00013 }
00014
00015 template <class T>
00016 gkll_multi_view_data<T>::gkll_multi_view_data(int nbviews):
00017 nbviews_(nbviews),size_vect_ft_(0),matchnum_(-1),closed_track_(true),MVM(0)
00018 {
00019
00020 }
00021
00022 template <class T>
00023 gkll_multi_view_data<T>::~gkll_multi_view_data()
00024 {
00025 }
00026
00027 template <class T>
00028 void gkll_multi_view_data<T>::set_params(int nbviews)
00029 {
00030 nbviews_=nbviews;
00031 }
00032
00033 template <class T>
00034 void gkll_multi_view_data<T>::set(int view_num,int matchnum,T feature)
00035 {
00036 all_pts.push_back(feature);
00037
00038
00039 if (matchnum>matchnum_)
00040 {
00041 matchnum_=matchnum;
00042 NViewMatch temp_match(nbviews_);
00043 temp_match[view_num]=size_vect_ft_;
00044 MVM.push_back(temp_match);
00045 }
00046 else
00047 MVM[matchnum][view_num]=size_vect_ft_;
00048
00049 size_vect_ft_++;
00050 }
00051
00052 template <class T>
00053 void gkll_multi_view_data<T>::set(int view_num,T feature)
00054 {
00055 if ((matchnum_>=0)&& (view_num>=0) && (view_num<nbviews_))
00056 {
00057 all_pts.push_back(feature);
00058 MVM[matchnum_][view_num]=size_vect_ft_;
00059 size_vect_ft_++;
00060 }
00061 }
00062
00063 template <class T>
00064 void gkll_multi_view_data<T>::new_track()
00065 {
00066 if (closed_track_)
00067 {
00068 matchnum_++;
00069 NViewMatch temp_match(nbviews_);
00070 MVM.push_back(temp_match);
00071 closed_track_=false;
00072 }
00073 }
00074
00075 template <class T>
00076 void gkll_multi_view_data<T>::close_track()
00077 {
00078 closed_track_=true;
00079 }
00080
00081
00082
00083 template <class T>
00084 void gkll_multi_view_data<T>::get(int view_num,vcl_vector<T> &ft_vector)
00085 {
00086 if ((view_num>=0) && (view_num<nbviews_))
00087 {
00088 ft_vector.clear();
00089 NViewMatches::iterator iter;
00090 vcl_cerr << "MVM->size():"<<MVM.size()<<vcl_endl;
00091 for (iter=MVM.begin();iter!=MVM.end();iter++)
00092 {
00093 int ft_num=(*iter)[view_num];
00094 if (ft_num!=NViewMatch::nomatch)
00095 {
00096 T temp_ft=all_pts[ft_num];
00097 ft_vector.push_back(temp_ft);
00098 }
00099 }
00100 }
00101 }
00102
00103
00104
00105 template <class T>
00106 void gkll_multi_view_data<T>::get(int view_num1,int view_num2,
00107 vcl_vector<T> &ft_vector1,
00108 vcl_vector<T> &ft_vector2)
00109 {
00110 if ((view_num1>=0) && (view_num1<nbviews_) &&
00111 (view_num2>=0) && (view_num2<nbviews_) && (view_num2!=view_num1))
00112 {
00113 ft_vector1.clear();
00114 ft_vector2.clear();
00115 NViewMatches::iterator iter;
00116 for (iter=MVM.begin();iter!=MVM.end();iter++)
00117 {
00118 int ft_num1=(*iter)[view_num1];
00119 int ft_num2=(*iter)[view_num2];
00120 if ((ft_num1 != NViewMatch::nomatch) && (ft_num2!=NViewMatch::nomatch))
00121 {
00122 T temp_ft1=all_pts[ft_num1];
00123 T temp_ft2=all_pts[ft_num2];
00124 ft_vector1.push_back(temp_ft1);
00125 ft_vector2.push_back(temp_ft2);
00126 }
00127 }
00128 }
00129 }
00130
00131 template <class T>
00132 void gkll_multi_view_data<T>::get(int view_num1,int view_num2,int view_num3,
00133 vcl_vector<T> &ft_vector1,
00134 vcl_vector<T> &ft_vector2,
00135 vcl_vector<T> &ft_vector3)
00136 {
00137 if ((view_num1>=0) && (view_num1<nbviews_) &&
00138 (view_num2>=0) && (view_num2<nbviews_) &&
00139 (view_num3>=0) && (view_num3<nbviews_) &&
00140 (view_num2!=view_num1) && (view_num2!=view_num3) && (view_num3!=view_num1))
00141 {
00142 ft_vector1.clear();
00143 ft_vector2.clear();
00144 ft_vector3.clear();
00145
00146 NViewMatches::iterator iter;
00147 for (iter=MVM.begin();iter!=MVM.end();iter++)
00148 {
00149 int ft_num1=(*iter)[view_num1];
00150 int ft_num2=(*iter)[view_num2];
00151 int ft_num3=(*iter)[view_num3];
00152 if (ft_num1 != NViewMatch::nomatch &&
00153 ft_num2 != NViewMatch::nomatch &&
00154 ft_num3 != NViewMatch::nomatch)
00155 {
00156 T temp_ft1=all_pts[ft_num1];
00157 T temp_ft2=all_pts[ft_num2];
00158 T temp_ft3=all_pts[ft_num3];
00159 ft_vector1.push_back(temp_ft1);
00160 ft_vector2.push_back(temp_ft2);
00161 ft_vector3.push_back(temp_ft3);
00162 }
00163 }
00164 }
00165 }
00166
00167 template <class T>
00168 bool gkll_multi_view_data<T>::get_pred_match(int view_num,T obj,T & res)
00169 {
00170 if ((view_num>=0) && (view_num<nbviews_-1))
00171 {
00172 int i,j;
00173 NViewMatches::iterator iter;
00174 for (iter=MVM.begin();iter!=MVM.end();iter++)
00175 {
00176 i=(*iter)[view_num];
00177 j=(*iter)[view_num+1];
00178 if ((i!=NViewMatch::nomatch) && (j!=NViewMatch::nomatch))
00179 if (*all_pts[j]==*obj)
00180 {
00181 res=all_pts[i];
00182 return true;
00183 }
00184 }
00185 }
00186 return false;
00187 }
00188
00189 template <class T>
00190 void gkll_multi_view_data<T>::remove(int view_num, T match)
00191 {
00192 if ((view_num>=0) && (view_num<nbviews_-1))
00193 {
00194 int i;
00195 NViewMatches::iterator iter;
00196 for (iter=MVM.begin();iter!=MVM.end();iter++)
00197 {
00198 i=(*iter)[view_num];
00199 if (i!=NViewMatch::nomatch)
00200 if (all_pts[i]==match)
00201 {
00202 (*iter)[view_num]= NViewMatch::nomatch;
00203 if (view_num==1)
00204 {
00205 MVM.erase(iter);
00206 matchnum_--;
00207 }
00208 }
00209 }
00210 }
00211 }
00212
00213 template <class T>
00214 vcl_ostream& gkll_multi_view_data<T>::print(vcl_ostream& str)
00215 {
00216 for (unsigned int j=0;j<MVM.size();j++)
00217 {
00218 for (int i=0;i<nbviews_;i++)
00219 if (MVM[j][i]<0)
00220 str<<" "<<MVM[j][i];
00221 else if (MVM[j][i]<10)
00222 str<<" "<<MVM[j][i];
00223 else if (MVM[j][i]<100)
00224 str<<" "<<MVM[j][i];
00225 else
00226 str<<" "<<MVM[j][i];
00227 str<<vcl_endl;
00228 }
00229 return str;
00230 }
00231
00232 template class gkll_multi_view_data<vtol_vertex_2d_sptr>;
00233 template class gkll_multi_view_data<vtol_edge_2d_sptr>;