cmtkTypes.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 2004-2010 SRI International
00004 //
00005 //  Copyright 1997-2009 Torsten Rohlfing
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkTypes_h_included_
00034 #define __cmtkTypes_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkMathUtil.h>
00039 
00040 #include <stdlib.h>
00041 #include <limits.h>
00042 #include <cfloat>
00043 #include <cstddef>
00044 
00045 #ifdef HAVE_VALUES_H
00046 #  include <values.h>
00047 #endif
00048 
00049 #ifdef _MSC_VER
00050 typedef unsigned short ushort;
00051 #endif
00052 
00053 #ifndef NULL
00054 #define NULL 0
00055 #endif
00056 
00057 #ifndef _HAVE_BYTE_
00058 typedef unsigned char byte;
00059 #define _HAVE_BYTE_
00060 #endif // #ifndef _HAVE_BYTE_
00061 
00062 namespace
00063 cmtk
00064 {
00065 
00068 
00074 enum 
00075 {
00077   AXIS_X = 0,
00079   AXIS_Y = 1,
00081   AXIS_Z = 2
00082 };
00083 
00085 typedef enum 
00086 {
00088   DATACLASS_GREY,
00090   DATACLASS_LABEL,
00092   DATACLASS_UNKNOWN
00093 } DataClass;
00094 
00096 DataClass StringToDataClass( const char *dataClassStr );
00097 
00099 const char* DataClassToString( const DataClass dataClass );
00100 
00102 typedef enum 
00103 {
00105   TYPE_BYTE = 0,
00107   TYPE_CHAR = 1,
00109   TYPE_SHORT = 2,
00111   TYPE_USHORT = 3,
00113   TYPE_INT = 4,
00115   TYPE_UINT = 5,
00117   TYPE_FLOAT = 6,
00119   TYPE_DOUBLE = 7,
00121   TYPE_NONE = -1
00122 } ScalarDataType;
00123 
00125 extern const char* DataTypeName[];
00126 
00127 #ifdef CMTK_DATA_FLOAT
00128 namespace Types
00129 { 
00133 typedef float DataItem; 
00134 }
00135 const ScalarDataType TYPE_ITEM = TYPE_FLOAT;
00136 #define CMTK_ITEM_MAX FLT_MAX
00137 #define CMTK_ITEM_MIN FLT_MIN
00138 #define CMTK_ITEM_NAN CMTK_FLOAT_NAN
00139 #else
00140 namespace Types 
00141 {
00142 typedef double DataItem; 
00143 }
00144 const ScalarDataType TYPE_ITEM = TYPE_DOUBLE;
00145 #define CMTK_ITEM_MAX DBL_MAX
00146 #define CMTK_ITEM_MIN DBL_MIN
00147 #define CMTK_ITEM_NAN CMTK_DOUBLE_NAN
00148 #endif // #ifdef CMTK_DATA_FLOAT
00149 
00150 namespace Types
00151 {
00152 
00154 template<class T>
00155 class Range
00156 {
00157 public:
00159   Range() {}
00160 
00162   Range( const T& lowerBound, const T& upperBound ) : m_LowerBound( lowerBound ), m_UpperBound( upperBound ) {}
00163 
00165   template<class T2>
00166   explicit Range( const Range<T2>& range ) : m_LowerBound( range.m_LowerBound ), m_UpperBound( range.m_UpperBound ) {}
00167 
00169   T Width() const
00170   {
00171     return this->m_UpperBound - this->m_LowerBound;
00172   }
00173 
00175   T m_LowerBound;
00176 
00178   T m_UpperBound;
00179 };
00180 
00182 typedef Range<DataItem> DataItemRange;
00183 
00184 }
00185 
00186 #ifdef CMTK_COORDINATES_FLOAT
00187 
00190 namespace Types 
00191 { 
00192 typedef float Coordinate; 
00193 }
00194 const ScalarDataType TYPE_COORDINATE = TYPE_FLOAT;
00195 #else
00196 
00197 namespace Types 
00198 { 
00199 typedef double Coordinate; 
00200 }
00201 const ScalarDataType TYPE_COORDINATE = TYPE_DOUBLE;
00202 #endif
00203 
00205 size_t TypeItemSize ( const ScalarDataType dtype );
00206 
00208 ScalarDataType SelectDataTypeInteger( const byte itemSize,const bool signBit );
00209 
00211 ScalarDataType GetSignedDataType( const ScalarDataType dtype );
00212 
00214 ScalarDataType GetDifferenceDataType( const ScalarDataType dtype1, const ScalarDataType dtype2 );
00215 
00217 ScalarDataType GetUnsignedDataType( const ScalarDataType dtype );
00218 
00219 namespace
00220 Types
00221 {
00222 
00224 template<class T1,class T2>
00225 class Combined
00226 {
00227 };
00228 
00230 template<>
00231 class Combined<float,float>
00232 {
00233 public:
00235   typedef float Type;
00236 };
00237 
00239 template<>
00240 class Combined<float,double>
00241 {
00242 public:
00244  typedef double Type;
00245 };
00246 
00248 template<>
00249 class Combined<double,float>
00250 {
00251 public:
00253   typedef double Type;
00254 };
00255 
00257 template<>
00258 class Combined<double,double>
00259 {
00260 public:
00262   typedef double Type;
00263 };
00264 
00265 } // namespace Types
00266 
00268 
00269 } // namespace cmtk
00270 
00271 #endif // #ifndef __cmtkTypes_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines