Field3D
|
00001 //----------------------------------------------------------------------------// 00002 00003 /* 00004 * Copyright (c) 2009 Sony Pictures Imageworks Inc 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the 00017 * distribution. Neither the name of Sony Pictures Imageworks nor the 00018 * names of its contributors may be used to endorse or promote 00019 * products derived from this software without specific prior written 00020 * permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00028 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00031 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00032 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00033 * OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 00036 //----------------------------------------------------------------------------// 00037 00043 //----------------------------------------------------------------------------// 00044 00045 #ifndef _INCLUDED_Field3D_Traits_H_ 00046 #define _INCLUDED_Field3D_Traits_H_ 00047 00048 #include <assert.h> 00049 #include <string> 00050 00051 #include <hdf5.h> 00052 00053 #include "Log.h" 00054 #include "Types.h" 00055 00056 //----------------------------------------------------------------------------// 00057 00058 #include "ns.h" 00059 00060 FIELD3D_NAMESPACE_OPEN 00061 00062 //----------------------------------------------------------------------------// 00063 // Enums 00064 //----------------------------------------------------------------------------// 00065 00066 enum DataTypeEnum { 00067 DataTypeHalf=0, 00068 DataTypeUnsignedChar, 00069 DataTypeInt, 00070 DataTypeFloat, 00071 DataTypeDouble, 00072 DataTypeVecHalf, 00073 DataTypeVecFloat, 00074 DataTypeVecDouble, 00075 DataTypeUnknown 00076 }; 00077 00078 //----------------------------------------------------------------------------// 00079 // FieldTraits 00080 //----------------------------------------------------------------------------// 00081 00087 template <class Data_T> 00088 class FieldTraits 00089 { 00090 public: 00092 static int dataDims(); 00093 }; 00094 00095 //----------------------------------------------------------------------------// 00096 // DataTypeTraits 00097 //----------------------------------------------------------------------------// 00098 00099 template <typename T> 00100 struct DataTypeTraits { 00101 static std::string name() 00102 { 00103 return typeid(T).name(); 00104 } 00105 static DataTypeEnum typeEnum(); 00106 static hid_t h5type(); 00107 static int h5bits(); 00108 }; 00109 00110 //----------------------------------------------------------------------------// 00111 // TemplatedFieldType 00112 //----------------------------------------------------------------------------// 00113 00115 template <class Field_T> 00116 struct TemplatedFieldType 00117 { 00118 const char *name() 00119 { 00120 return m_name.c_str(); 00121 } 00122 TemplatedFieldType() 00123 { 00124 m_name = Field_T::staticClassName(); 00125 m_name += 00126 "<" + 00127 DataTypeTraits<typename Field_T::value_type>::name() + 00128 ">"; 00129 } 00130 private: 00131 std::string m_name; 00132 }; 00133 00134 //----------------------------------------------------------------------------// 00135 // Template specializations 00136 //----------------------------------------------------------------------------// 00137 00138 #define FIELD3D_DECL_DATATYPENAME(typeName) \ 00139 template<> \ 00140 inline std::string DataTypeTraits<typeName>::name() \ 00141 { \ 00142 return std::string(#typeName); \ 00143 } \ 00144 00145 //----------------------------------------------------------------------------// 00146 00147 FIELD3D_DECL_DATATYPENAME(unsigned char) 00148 FIELD3D_DECL_DATATYPENAME(int) 00149 FIELD3D_DECL_DATATYPENAME(float) 00150 FIELD3D_DECL_DATATYPENAME(half) 00151 FIELD3D_DECL_DATATYPENAME(double) 00152 FIELD3D_DECL_DATATYPENAME(V3h) 00153 FIELD3D_DECL_DATATYPENAME(V3f) 00154 FIELD3D_DECL_DATATYPENAME(V3d) 00155 00156 //----------------------------------------------------------------------------// 00157 00158 template<> 00159 inline DataTypeEnum DataTypeTraits<half>::typeEnum() 00160 { 00161 return DataTypeHalf; 00162 } 00163 00164 //----------------------------------------------------------------------------// 00165 00166 template<> 00167 inline DataTypeEnum DataTypeTraits<unsigned char>::typeEnum() 00168 { 00169 return DataTypeUnsignedChar; 00170 } 00171 00172 //----------------------------------------------------------------------------// 00173 00174 template<> 00175 inline DataTypeEnum DataTypeTraits<int>::typeEnum() 00176 { 00177 return DataTypeInt; 00178 } 00179 00180 //----------------------------------------------------------------------------// 00181 00182 template<> 00183 inline DataTypeEnum DataTypeTraits<float>::typeEnum() 00184 { 00185 return DataTypeFloat; 00186 } 00187 00188 //----------------------------------------------------------------------------// 00189 00190 template<> 00191 inline DataTypeEnum DataTypeTraits<double>::typeEnum() 00192 { 00193 return DataTypeDouble; 00194 } 00195 00196 //----------------------------------------------------------------------------// 00197 00198 template<> 00199 inline DataTypeEnum DataTypeTraits<V3h>::typeEnum() 00200 { 00201 return DataTypeVecHalf; 00202 } 00203 00204 //----------------------------------------------------------------------------// 00205 00206 template<> 00207 inline DataTypeEnum DataTypeTraits<V3f>::typeEnum() 00208 { 00209 return DataTypeVecFloat; 00210 } 00211 00212 //----------------------------------------------------------------------------// 00213 00214 template<> 00215 inline DataTypeEnum DataTypeTraits<V3d>::typeEnum() 00216 { 00217 return DataTypeVecDouble; 00218 } 00219 00220 template <> 00221 inline hid_t DataTypeTraits<half>::h5type() 00222 { 00223 return H5T_NATIVE_SHORT; 00224 } 00225 00226 //----------------------------------------------------------------------------// 00227 00228 template <> 00229 inline hid_t DataTypeTraits<float>::h5type() 00230 { 00231 return H5T_NATIVE_FLOAT; 00232 } 00233 00234 //----------------------------------------------------------------------------// 00235 00236 template <> 00237 inline hid_t DataTypeTraits<double>::h5type() 00238 { 00239 return H5T_NATIVE_DOUBLE; 00240 } 00241 00242 //----------------------------------------------------------------------------// 00243 00244 template <> 00245 inline hid_t DataTypeTraits<char>::h5type() 00246 { 00247 return H5T_NATIVE_CHAR; 00248 } 00249 00250 //----------------------------------------------------------------------------// 00251 00252 template <> 00253 inline hid_t DataTypeTraits<unsigned char>::h5type() 00254 { 00255 return H5T_NATIVE_UCHAR; 00256 } 00257 00258 //----------------------------------------------------------------------------// 00259 00260 template <> 00261 inline hid_t DataTypeTraits<int>::h5type() 00262 { 00263 return H5T_NATIVE_INT; 00264 } 00265 00266 //----------------------------------------------------------------------------// 00267 00268 template <> 00269 inline hid_t DataTypeTraits<V3h>::h5type() 00270 { 00271 return H5T_NATIVE_SHORT; 00272 } 00273 00274 //----------------------------------------------------------------------------// 00275 00276 template <> 00277 inline hid_t DataTypeTraits<V3f>::h5type() 00278 { 00279 return H5T_NATIVE_FLOAT; 00280 } 00281 00282 //----------------------------------------------------------------------------// 00283 00284 template <> 00285 inline hid_t DataTypeTraits<V3d>::h5type() 00286 { 00287 return H5T_NATIVE_DOUBLE; 00288 } 00289 00290 //----------------------------------------------------------------------------// 00291 00292 template <> 00293 inline int DataTypeTraits<half>::h5bits() 00294 { 00295 return 16; 00296 } 00297 00298 //----------------------------------------------------------------------------// 00299 00300 template <> 00301 inline int DataTypeTraits<float>::h5bits() 00302 { 00303 return 32; 00304 } 00305 00306 //----------------------------------------------------------------------------// 00307 00308 template <> 00309 inline int DataTypeTraits<double>::h5bits() 00310 { 00311 return 64; 00312 } 00313 00314 //----------------------------------------------------------------------------// 00315 00316 template <> 00317 inline int DataTypeTraits<V3h>::h5bits() 00318 { 00319 return 16; 00320 } 00321 00322 //----------------------------------------------------------------------------// 00323 00324 template <> 00325 inline int DataTypeTraits<V3f>::h5bits() 00326 { 00327 return 32; 00328 } 00329 00330 //----------------------------------------------------------------------------// 00331 00332 template <> 00333 inline int DataTypeTraits<V3d>::h5bits() 00334 { 00335 return 64; 00336 } 00337 00338 //----------------------------------------------------------------------------// 00339 00340 FIELD3D_NAMESPACE_HEADER_CLOSE 00341 00342 //----------------------------------------------------------------------------// 00343 00344 #endif // Include guard