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