LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiDistanceType.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiDistanceType.h
00027  * authors ....: Peter Doerfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 11.05.2003
00030  * revisions ..: $Id: ltiDistanceType.h,v 1.2 2006/02/07 18:08:00 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_DISTANCE_TYPE_H_
00034 #define _LTI_DISTANCE_TYPE_H_
00035 
00036 #include "ltiObject.h"
00037 #include "ltiTypeInfo.h"
00038 
00039 /**
00040  * \file ltiDistanceType.h This file contains the class distanceType<T>
00041  * which specifies three types that are recommended for the result of
00042  * a distance calculation between two instances of T. The three types are:
00043  * - \a distance_type is used when a simple distance is calculated
00044  *   between two instances of T which does not involve accumulation of
00045  *   squares or typical floating point operations.
00046  * - \a square_distance_type is used for the result of distances
00047  *   that involve the square of the type T.
00048  * - \a fp_distance_type is used for distances that involve floating
00049  *   point operations such as the sqrt or log functions.
00050  */
00051 
00052 /**
00053  * namespace lti
00054  */
00055 namespace lti {
00056 
00057   /**
00058    * This class defines the appropriate return types when calculating
00059    * the distance between to values of type T. These can be simple
00060    * types like int or double or lti types like vector<T>, rgbPixel
00061    * etc. There are three different distance types:
00062    * - \a distance_type is used when a simple distance is calculated
00063    *   between two instances of T which does not involve accumulation of
00064    *   squares or typical floating point operations.
00065    * - \a square_distance_type is used for the result of distances
00066    *   that involve the square of the type T.
00067    * - \a fp_distance_type is used for distances that involve floating
00068    *   point operations such as the sqrt or log functions.
00069    */
00070   template<class T>
00071   class distanceType : public object {
00072   public:
00073     /**
00074      * Suggested distance type for distances that use simple
00075      * accumulation of type elements (for example l1Distantor).
00076      */
00077     typedef typename distanceType<typename T::value_type>::distance_type
00078     distance_type;
00079 
00080     /**
00081      * Suggested distance type for distances that use
00082      * accumulation of squares of type elements (for example l2SqrDistantor).
00083      */
00084     typedef typename distanceType<typename T::value_type>::square_distance_type
00085     square_distance_type;
00086 
00087     /**
00088      * Suggested distance type for distances that use accumulation of
00089      * type elements or their squares and use a typical floating point (fp)
00090      * operation like sqrt or log on that. (for example l2Distantor).
00091      */
00092     typedef typename distanceType<typename T::value_type>::fp_distance_type
00093     fp_distance_type;
00094   };
00095 
00096   // ------------------------
00097   // template specializations
00098   // ------------------------
00099 
00100 #ifndef _LTI_MSC_6
00101 
00102   // This is the way is should be
00103 
00104   template<class T>
00105   class distanceType< tpoint<T> > : public object {
00106   public:
00107     typedef T distance_type;
00108     typedef T square_distance_type;
00109     typedef double fp_distance_type;
00110   };
00111 
00112   template<class T>
00113   class distanceType< tpoint3D<T> > : public object {
00114   public:
00115     typedef T distance_type;
00116     typedef T square_distance_type;
00117     typedef double fp_distance_type;
00118   };
00119 
00120   template<class T>
00121   class distanceType< trgbPixel<T> > : public object {
00122   public:
00123     typedef typename distanceType<T>::distance_type distance_type;
00124     typedef typename distanceType<T>::distance_type square_distance_type;
00125     typedef double fp_distance_type;
00126   };
00127 
00128 #else
00129 
00130   // Endless code duplication for MSC 6
00131   // keeping it to the most typical instantiations
00132 
00133   template<>
00134   class distanceType<point> : public object {
00135   public:
00136     typedef int distance_type;
00137     typedef int square_distance_type;
00138     typedef double fp_distance_type;
00139   };
00140 
00141   template<>
00142   class distanceType< tpoint<float> > : public object {
00143   public:
00144     typedef float distance_type;
00145     typedef float square_distance_type;
00146     typedef double fp_distance_type;
00147   };
00148 
00149   template<>
00150   class distanceType<dpoint> : public object {
00151   public:
00152     typedef double distance_type;
00153     typedef double square_distance_type;
00154     typedef double fp_distance_type;
00155   };
00156 
00157   template<>
00158   class distanceType<point3D> : public object {
00159   public:
00160     typedef int distance_type;
00161     typedef int square_distance_type;
00162     typedef double fp_distance_type;
00163   };
00164 
00165   template<>
00166   class distanceType< tpoint3D<float> > : public object {
00167   public:
00168     typedef float distance_type;
00169     typedef float square_distance_type;
00170     typedef double fp_distance_type;
00171   };
00172 
00173   template<>
00174   class distanceType<dpoint3D> : public object {
00175   public:
00176     typedef double distance_type;
00177     typedef double square_distance_type;
00178     typedef double fp_distance_type;
00179   };
00180   
00181   template<>
00182   class distanceType< trgbPixel<int> > : public object {
00183   public:
00184     typedef int distance_type;
00185     typedef int square_distance_type;
00186     typedef double fp_distance_type;
00187   };
00188 
00189   template<>
00190   class distanceType< trgbPixel<float> > : public object {
00191   public:
00192     typedef float distance_type;
00193     typedef float square_distance_type;
00194     typedef double fp_distance_type;
00195   };
00196 
00197   template<>
00198   class distanceType< trgbPixel<double> > : public object {
00199   public:
00200     typedef double distance_type;
00201     typedef double square_distance_type;
00202     typedef double fp_distance_type;
00203   };
00204 
00205 
00206 #endif
00207 
00208   template<>
00209   class distanceType<ubyte> : public object {
00210   public:
00211     typedef typeInfo<ubyte>::accumulation_type distance_type;
00212     typedef typeInfo<ubyte>::square_accumulation_type square_distance_type;
00213     typedef double fp_distance_type;
00214   };
00215 
00216   template<>
00217   class distanceType<byte> : public object {
00218   public:
00219     typedef typeInfo<byte>::accumulation_type distance_type;
00220     typedef typeInfo<byte>::square_accumulation_type square_distance_type;
00221     typedef double fp_distance_type;
00222   };
00223 
00224   template<>
00225   class distanceType<short int> : public object {
00226   public:
00227     typedef typeInfo<short int>::accumulation_type distance_type;
00228     typedef typeInfo<short int>::square_accumulation_type square_distance_type;
00229     typedef double fp_distance_type;
00230   };
00231 
00232   template<>
00233   class distanceType<unsigned short int> : public object {
00234   public:
00235     typedef typeInfo<unsigned short int>::accumulation_type distance_type;
00236     typedef typeInfo<unsigned short int>::square_accumulation_type 
00237     square_distance_type;
00238     typedef double fp_distance_type;
00239   };
00240 
00241   template<>
00242   class distanceType<int> : public object {
00243   public:
00244     typedef typeInfo<int>::accumulation_type distance_type;
00245     typedef typeInfo<int>::square_accumulation_type square_distance_type;
00246     typedef double fp_distance_type;
00247   };
00248 
00249   template<>
00250   class distanceType<unsigned int> : public object {
00251   public:
00252     typedef typeInfo<unsigned int>::accumulation_type distance_type;
00253     typedef typeInfo<unsigned int>::square_accumulation_type square_distance_type;
00254     typedef double fp_distance_type;
00255   };
00256 
00257   template<>
00258   class distanceType<float> : public object {
00259   public:
00260     typedef typeInfo<float>::accumulation_type distance_type;
00261     typedef typeInfo<float>::square_accumulation_type square_distance_type;
00262     typedef double fp_distance_type;
00263   };
00264 
00265   template<>
00266   class distanceType<double> : public object {
00267   public:
00268     typedef typeInfo<double>::accumulation_type distance_type;
00269     typedef typeInfo<double>::square_accumulation_type square_distance_type;
00270     typedef double fp_distance_type;
00271   };
00272 
00273 
00274 }
00275 
00276 
00277 #endif

Generated on Sat Apr 10 15:25:22 2010 for LTI-Lib by Doxygen 1.6.1