cvrEuclideanDistance.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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #ifndef _CVR_EUCLIDEAN_DISTANCE_H_
00056 #define _CVR_EUCLIDEAN_DISTANCE_H_
00057
00058 #include <vector>
00059 #include "cvrPoint.h"
00060 #include "cvrPoint3D.h"
00061 #include "cvrRGBPixel.h"
00062 #include "cvrRGBAPixel.h"
00063 #include "cvrVector.h"
00064 #include "cvrMatrix.h"
00065 #include "cvrDistanceType.h"
00066
00067 namespace cvr {
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 template<class T>
00088 typename distanceType<T>::square_distance_type
00089 euclideanDistance(const T& a, const T& b) {
00090 return abs(static_cast<typename distanceType<T>::square_distance_type>(a)
00091 -static_cast<typename distanceType<T>::square_distance_type>(b));
00092 }
00093
00094
00095
00096
00097
00098 template<class T>
00099 typename distanceType<T>::square_distance_type
00100 euclideanDistance(const vector<T>& a,const vector<T>& b) {
00101 typename vector<T>::const_iterator ita,itb,ite;
00102 assert(a.size()==b.size());
00103 typename distanceType<T>::square_distance_type sum(0);
00104 for (ita=a.begin(),itb=b.begin(),ite=a.end();
00105 ita!=ite;
00106 ++ita,++itb) {
00107 const typename distanceType<T>::square_distance_type diff
00108 = static_cast<typename distanceType<T>::square_distance_type>(*ita)
00109 -static_cast<typename distanceType<T>::square_distance_type>(*itb);
00110 sum+=diff*diff;
00111 }
00112 return sqrt(sum);
00113 }
00114
00115
00116
00117
00118
00119 template<class T>
00120 typename distanceType<T>::square_distance_type
00121 euclideanDistance(const matrix<T>& a,const matrix<T>& b) {
00122 assert(a.size() == b.size());
00123
00124 typename matrix<T>::const_iterator ait,bit,eit;
00125 typename distanceType<T>::square_distance_type dist(0);
00126 ait = a.begin();
00127 bit = b.begin();
00128 eit = a.end();
00129
00130 while (ait != eit) {
00131 const typename distanceType<T>::square_distance_type diff
00132 = static_cast<typename distanceType<T>::square_distance_type>(*ait)
00133 -static_cast<typename distanceType<T>::square_distance_type>(*bit);
00134 dist+=diff*diff;
00135 ++ait;
00136 ++bit;
00137 }
00138 return sqrt(dist);
00139 }
00140
00141
00142
00143
00144
00145
00146 template<class T>
00147 typename distanceType<T>::square_distance_type
00148 euclideanDistance(const std::vector<T>& a,const std::vector<T>& b) {
00149 typename std::vector<T>::const_iterator ita,itb,ite;
00150 assert(a.size()==b.size());
00151 typename distanceType<T>::square_distance_type sum(0);
00152 for (ita=a.begin(),itb=b.begin(),ite=a.end();
00153 ita!=ite;
00154 ++ita,++itb) {
00155 const typename distanceType<T>::square_distance_type diff
00156 = static_cast<typename distanceType<T>::square_distance_type>(*ita)
00157 -static_cast<typename distanceType<T>::square_distance_type>(*itb);
00158 sum+=diff*diff;
00159 }
00160 return sqrt(sum);
00161 }
00162
00163
00164
00165
00166
00167 template<class T >
00168 typename distanceType<T>::square_distance_type
00169 euclideanDistance(const point<T>& a,const point<T>& b) {
00170 return sqrt(static_cast<typename distanceType<T>::square_distance_type>
00171 (a.distanceSqr(b)));
00172 }
00173
00174
00175
00176
00177
00178 template<class T>
00179 typename distanceType<T>::square_distance_type
00180 euclideanDistance(const point3D<T>& a, const point3D<T>& b) {
00181 return sqrt(static_cast<typename distanceType<T>::square_distance_type>
00182 (a.distanceSqr(b)));
00183 }
00184
00185
00186
00187
00188
00189 template<class T>
00190 inline typename distanceType<T>::square_distance_type
00191 euclideanDistance(const rgbPixel<T>& a, const rgbPixel<T>& b) {
00192 return sqrt(static_cast<typename distanceType<T>::square_distance_type>
00193 (a.distanceSqr(b)));
00194 }
00195
00196
00197
00198
00199
00200 inline distanceType<rgbaPixel>::square_distance_type
00201 euclideanDistance(const rgbaPixel& a, const rgbaPixel& b) {
00202 return cvr::sqrt(static_cast<distanceType<rgbaPixel>::square_distance_type>
00203 (a.distanceSqr(b)));
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 template<class T>
00228 typename distanceType<T>::square_distance_type
00229 euclideanDistanceSqr(const T& a, const T& b) {
00230 const typename distanceType<T>::square_distance_type diff
00231 = static_cast<typename distanceType<T>::square_distance_type>(a)
00232 -static_cast<typename distanceType<T>::square_distance_type>(b);
00233 return diff*diff;
00234 }
00235
00236
00237
00238
00239
00240 template<class T>
00241 typename distanceType<T>::square_distance_type
00242 euclideanDistanceSqr(const vector<T>& a,const vector<T>& b) {
00243 typename vector<T>::const_iterator ita,itb,ite;
00244 assert(a.size()==b.size());
00245 typename distanceType<T>::square_distance_type sum(0);
00246 for (ita=a.begin(),itb=b.begin(),ite=a.end();
00247 ita!=ite;
00248 ++ita,++itb) {
00249 const typename distanceType<T>::square_distance_type diff
00250 = static_cast<typename distanceType<T>::square_distance_type>(*ita)
00251 -static_cast<typename distanceType<T>::square_distance_type>(*itb);
00252 sum+=diff*diff;
00253 }
00254 return sum;
00255 }
00256
00257
00258
00259
00260
00261 template<class T>
00262 typename distanceType<T>::square_distance_type
00263 euclideanDistanceSqr(const matrix<T>& a,const matrix<T>& b) {
00264 assert(a.size() == b.size());
00265
00266 typename matrix<T>::const_iterator ait,bit,eit;
00267 typename distanceType<T>::square_distance_type dist(0);
00268 ait = a.begin();
00269 bit = b.begin();
00270 eit = a.end();
00271
00272 while (ait != eit) {
00273 const typename distanceType<T>::square_distance_type diff
00274 = static_cast<typename distanceType<T>::square_distance_type>(*ait)
00275 -static_cast<typename distanceType<T>::square_distance_type>(*bit);
00276 dist+=diff*diff;
00277 ++ait;
00278 ++bit;
00279 }
00280 return dist;
00281 }
00282
00283
00284
00285
00286
00287
00288 template<class T>
00289 typename distanceType<T>::square_distance_type
00290 euclideanDistanceSqr(const std::vector<T>& a,const std::vector<T>& b) {
00291 typename std::vector<T>::const_iterator ita,itb,ite;
00292 assert(a.size()==b.size());
00293 typename distanceType<T>::square_distance_type sum(0);
00294 for (ita=a.begin(),itb=b.begin(),ite=a.end();
00295 ita!=ite;
00296 ++ita,++itb) {
00297 const typename distanceType<T>::square_distance_type diff
00298 = static_cast<typename distanceType<T>::square_distance_type>(*ita)
00299 -static_cast<typename distanceType<T>::square_distance_type>(*itb);
00300 sum+=diff*diff;
00301 }
00302 return sum;
00303 }
00304
00305
00306
00307
00308
00309 template<class T >
00310 typename distanceType<T>::square_distance_type
00311 euclideanDistanceSqr(const point<T>& a,const point<T>& b) {
00312 return static_cast<typename distanceType<T>::square_distance_type>
00313 (a.distanceSqr(b));
00314 }
00315
00316
00317
00318
00319
00320 template<class T>
00321 typename distanceType<T>::square_distance_type
00322 euclideanDistanceSqr(const point3D<T>& a, const point3D<T>& b) {
00323 return static_cast<typename distanceType<T>::square_distance_type>
00324 (a.distanceSqr(b));
00325 }
00326
00327
00328
00329
00330
00331 template<class T>
00332 inline typename distanceType<T>::square_distance_type
00333 euclideanDistanceSqr(const rgbPixel<T>& a, const rgbPixel<T>& b) {
00334 return static_cast<typename distanceType<T>::square_distance_type>
00335 (a.distanceSqr(b));
00336 }
00337
00338
00339
00340
00341
00342 inline distanceType<rgbaPixel>::square_distance_type
00343 euclideanDistanceSqr(const rgbaPixel& a, const rgbaPixel& b) {
00344 return static_cast<distanceType<rgbaPixel>::square_distance_type>
00345 (a.distanceSqr(b));
00346 }
00347
00348
00349
00350
00351 }
00352
00353 #endif
00354