last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2004 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 /** 00042 * \file cvrDistanceType.h 00043 * This file contains the class distanceType<T> which specifies three 00044 * types that are recommended for the result of a distance calculation 00045 * between two instances of T. The three types are: 00046 * - \c distance_type is used when a simple distance is calculated 00047 * between two instances of T which does not involve accumulation of 00048 * squares or typical floating point operations. 00049 * - \c square_distance_type is used for the result of distances 00050 * that involve the square of the type T. 00051 * - \c fp_distance_type is used for distances that involve floating 00052 * point operations such as the sqrt or log functions. 00053 * \author Peter Doerfler 00054 * \date 11.05.2003 00055 * $Id: cvrDistanceType.h,v 1.3 2007/04/18 21:13:40 alvarado Exp $ 00056 */ 00057 00058 #ifndef _CVR_DISTANCE_TYPE_H_ 00059 #define _CVR_DISTANCE_TYPE_H_ 00060 00061 #include "cvrObject.h" 00062 #include "cvrTypeInfo.h" 00063 00064 namespace cvr { 00065 00066 /** 00067 * This class defines the appropriate return types when calculating 00068 * the distance between two values of type T. These can be simple 00069 * types like \c int or \c double or \c lti types like \c vector<T>, 00070 * rgbaPixel, etc. There are three different distance types: 00071 * - \c distance_type is used when a simple distance is calculated 00072 * between two instances of T which does not involve accumulation of 00073 * squares or typical floating point operations. 00074 * - \c square_distance_type is used for the result of distances 00075 * that involve the square of the type T. 00076 * - \c fp_distance_type is used for distances that involve floating 00077 * point operations such as the sqrt or log functions. 00078 * 00079 * @ingroup gTypes 00080 */ 00081 template<class T> 00082 class distanceType { 00083 public: 00084 /** 00085 * Suggested distance type for distances that use simple 00086 * accumulation of type elements (for example l1Distantor). 00087 */ 00088 typedef typename distanceType<typename T::value_type>::distance_type 00089 distance_type; 00090 00091 /** 00092 * Suggested distance type for distances that use 00093 * accumulation of squares of type elements (for example l2SqrDistantor). 00094 */ 00095 typedef typename distanceType<typename T::value_type>::square_distance_type 00096 square_distance_type; 00097 00098 /** 00099 * Suggested distance type for distances that use accumulation of 00100 * type elements or their squares and use a typical floating point (fp) 00101 * operation like sqrt or log on that. (for example l2Distantor). 00102 */ 00103 typedef typename distanceType<typename T::value_type>::fp_distance_type 00104 fp_distance_type; 00105 00106 private: 00107 /** 00108 * Disable constructor of instances of this class 00109 */ 00110 distanceType() {}; 00111 }; 00112 00113 // ------------------------ 00114 // template specializations 00115 // ------------------------ 00116 00117 template<> 00118 class distanceType<ubyte> { 00119 public: 00120 typedef typeInfo<ubyte>::accumulation_type distance_type; 00121 typedef typeInfo<ubyte>::square_accumulation_type square_distance_type; 00122 typedef float fp_distance_type; 00123 private: 00124 distanceType() {}; 00125 }; 00126 00127 template<> 00128 class distanceType<byte> { 00129 public: 00130 typedef typeInfo<byte>::accumulation_type distance_type; 00131 typedef typeInfo<byte>::square_accumulation_type square_distance_type; 00132 typedef float fp_distance_type; 00133 private: 00134 distanceType() {}; 00135 }; 00136 00137 template<> 00138 class distanceType<short int> { 00139 public: 00140 typedef typeInfo<short int>::accumulation_type distance_type; 00141 typedef typeInfo<short int>::square_accumulation_type square_distance_type; 00142 typedef float fp_distance_type; 00143 private: 00144 distanceType() {}; 00145 }; 00146 00147 template<> 00148 class distanceType<unsigned short int> { 00149 public: 00150 typedef typeInfo<unsigned short int>::accumulation_type distance_type; 00151 typedef typeInfo<unsigned short int>::square_accumulation_type 00152 square_distance_type; 00153 typedef float fp_distance_type; 00154 private: 00155 distanceType() {}; 00156 }; 00157 00158 template<> 00159 class distanceType<int> { 00160 public: 00161 typedef typeInfo<int>::accumulation_type distance_type; 00162 typedef typeInfo<int>::square_accumulation_type square_distance_type; 00163 typedef double fp_distance_type; 00164 private: 00165 distanceType() {}; 00166 }; 00167 00168 template<> 00169 class distanceType<unsigned int> { 00170 public: 00171 typedef typeInfo<unsigned int>::accumulation_type distance_type; 00172 typedef typeInfo<unsigned int>::square_accumulation_type square_distance_type; 00173 typedef double fp_distance_type; 00174 private: 00175 distanceType() {}; 00176 }; 00177 00178 template<> 00179 class distanceType<float> { 00180 public: 00181 typedef typeInfo<float>::accumulation_type distance_type; 00182 typedef typeInfo<float>::square_accumulation_type square_distance_type; 00183 typedef double fp_distance_type; 00184 private: 00185 distanceType() {}; 00186 }; 00187 00188 template<> 00189 class distanceType<double> { 00190 public: 00191 typedef typeInfo<double>::accumulation_type distance_type; 00192 typedef typeInfo<double>::square_accumulation_type square_distance_type; 00193 typedef double fp_distance_type; 00194 private: 00195 distanceType() {}; 00196 }; 00197 00198 } 00199 00200 00201 #endif 00202