Conversions.H
Go to the documentation of this file.00001
00002
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 #ifndef IMAGE_CONVERSIONS_H_DEFINED
00040 #define IMAGE_CONVERSIONS_H_DEFINED
00041
00042 #include "Util/Assert.H"
00043 #include "Image/Image.H"
00044
00045 #include <vector>
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 template <class T>
00057 inline Image<T> vectorToImage(const std::vector<std::vector<T> >& A);
00058
00059 template <class T>
00060 inline Image<T> vectorToImage(const std::vector<std::vector<T>* >& A);
00061
00062 template <class T>
00063 inline Image<T> vectorToImage(const std::vector<std::vector<T*> >& A);
00064
00065
00066 template <class T>
00067 inline void getVector(const Image<T>& src,
00068 std::vector<std::vector<T> > *V);
00069
00070
00071 template <class T>
00072 inline void getVector(const Image<T>& src,
00073 std::vector<std::vector<T*> > *V);
00074
00075
00076 template <class T>
00077 inline void getVectorRow(const Image<T>& src,
00078 std::vector<T> *V, int row);
00079
00080
00081 template <class T>
00082 inline void getVectorRow(const Image<T>& src,
00083 std::vector<T*> *V, int row);
00084
00085
00086 template <class T>
00087 inline void getVectorColumn(const Image<T>& src,
00088 std::vector<T> *V, int column);
00089
00090
00091 template <class T>
00092 inline void getVectorColumn(const Image<T>& src,
00093 std::vector<T*> *V, int column);
00094
00095
00096
00097
00098
00099
00100 template <class T> inline
00101 Image<T> vectorToImage(const std::vector<std::vector<T> >& src)
00102 {
00103 Image<T> dst((signed)src[0].size(),(signed)src.size(), NO_INIT);
00104
00105 typename Image<T>::iterator aptr = dst.beginw();
00106 typename std::vector<std::vector<T> >::const_iterator vptr = src.begin();
00107 typename std::vector<std::vector<T> >::const_iterator vstp = src.end();
00108 while(vptr != vstp)
00109 {
00110 typename std::vector<T>::const_iterator vvptr = vptr->begin();
00111 typename std::vector<T>::const_iterator vvstp = vptr->end();
00112 while(vvptr != vvstp)
00113 *aptr++ = *vvptr++;
00114 ++vptr;
00115 }
00116
00117 return dst;
00118 }
00119
00120
00121 template <class T> inline
00122 Image<T> vectorToImage(const std::vector<std::vector<T>* >& src)
00123 {
00124 Image<T> dst((signed)src[0]->size(),(signed)src.size(), NO_INIT);
00125
00126 typename Image<T>::iterator aptr = dst.beginw();
00127 for(int ii = 0; ii < (signed)src.size(); ii++)
00128 {
00129
00130 typename std::vector<T>::iterator vvptr = src[ii]->begin();
00131 typename std::vector<T>::iterator vvstp = src[ii]->end();
00132 while(vvptr != vvstp)
00133 *aptr++ = *vvptr++;
00134 }
00135
00136 return dst;
00137 }
00138
00139
00140 template <class T> inline
00141 Image<T> vectorToImage(const std::vector<std::vector<T*> >& src)
00142 {
00143 Image<T> dst((signed)src[0].size(),(signed)src.size(), NO_INIT);
00144
00145 typename Image<T>::iterator aptr = dst.beginw();
00146 typename std::vector<std::vector<T*> >::const_iterator vptr = src.begin();
00147 typename std::vector<std::vector<T*> >::const_iterator vstp = src.end();
00148 while(vptr != vstp)
00149 {
00150 typename std::vector<T*>::iterator vvptr = vptr->begin();
00151 typename std::vector<T*>::iterator vvstp = vptr->end();
00152 while(vvptr != vvstp)
00153 *aptr++ = **vvptr++;
00154 ++vptr;
00155 }
00156
00157 return dst;
00158 }
00159
00160
00161 template <class T> inline
00162 void getVector(const Image<T>& src, std::vector<std::vector<T> > *V)
00163 {
00164 ASSERT(V->size() >= (unsigned int)src.getHeight());
00165 ASSERT(V->at(0).size() >= (unsigned int)src.getWidth());
00166 typename Image<T>::const_iterator aptr = src.begin();
00167 typename std::vector<std::vector<T> >::iterator vptr = V->begin();
00168 typename std::vector<std::vector<T> >::iterator vstp = V->end();
00169 while(vptr != vstp)
00170 {
00171 typename std::vector<T>::iterator vvptr = vptr->begin();
00172 typename std::vector<T>::iterator vvstp = vptr->end();
00173 while(vvptr != vvstp)
00174 *vvptr++ = *aptr++;
00175 }
00176 }
00177
00178
00179 template <class T> inline
00180 void getVector(const Image<T>& src, std::vector<std::vector<T*> > *V)
00181 {
00182 ASSERT(V->size() >= (unsigned int)src.getHeight());
00183 ASSERT(V->at(0).size() >= (unsigned int)src.getWidth());
00184 typename Image<T>::const_iterator aptr = src.begin();
00185 typename std::vector<std::vector<T*> >::iterator vptr = V->begin();
00186 typename std::vector<std::vector<T*> >::iterator vstp = V->end();
00187 while(vptr != vstp)
00188 {
00189 typename std::vector<T*>::iterator vvptr = vptr->begin();
00190 typename std::vector<T*>::iterator vvstp = vptr->end();
00191 while(vvptr != vvstp)
00192 **vvptr++ = *aptr++;
00193 }
00194 }
00195
00196
00197 template <class T> inline
00198 void getVectorRow(const Image<T>& src, std::vector<T> *V, int row)
00199 {
00200 ASSERT(V->size() >= (unsigned int)src.getWidth());
00201 typename Image<T>::const_iterator aptr =
00202 src.begin() + (row * src.getWidth());
00203 typename std::vector<T>::iterator vptr = V->begin();
00204 typename std::vector<T>::iterator vstp = V->end();
00205 while(vptr != vstp)
00206 {
00207 *vptr++ = *aptr++;
00208 }
00209 }
00210
00211
00212 template <class T> inline
00213 void getVectorRow(const Image<T>& src, std::vector<T*> *V, int row)
00214 {
00215 ASSERT(V->size() >= (unsigned int)src.getWidth());
00216 typename Image<T>::const_iterator aptr =
00217 src.begin() + (row * src.getWidth());
00218
00219 typename std::vector<T*>::iterator vptr = V->begin();
00220 typename std::vector<T*>::iterator vstp = V->end();
00221 while(vptr != vstp)
00222 {
00223 **vptr++ = *aptr++;
00224 }
00225 }
00226
00227
00228 template <class T> inline
00229 void getVectorColumn(const Image<T>& src, std::vector<T> *V, int column)
00230 {
00231 ASSERT(V->size() >= (unsigned int)src.getHeight());
00232 typename std::vector<T>::iterator vptr = V->begin();
00233 typename std::vector<T>::iterator vstp = V->end();
00234 int current = 0;
00235 while(vptr != vstp)
00236 {
00237 *vptr++ = src.begin()[column + current*src.getWidth()];
00238 current++;
00239 }
00240 }
00241
00242
00243 template <class T> inline
00244 void getVectorColumn(const Image<T>& src, std::vector<T*> *V, int column)
00245 {
00246 ASSERT(V->size() >= (unsigned int)src.getHeight());
00247 typename std::vector<T*>::iterator vptr = V->begin();
00248 typename std::vector<T*>::iterator vstp = V->end();
00249 int current = 0;
00250 while(vptr != vstp)
00251 {
00252 **vptr++ = src.begin()[column + current*src.getWidth()];
00253 current++;
00254 }
00255 }
00256
00257
00258 #endif // !IMAGE_CONVERSIONS_H_DEFINED