Field3D
Traits.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
43 //----------------------------------------------------------------------------//
44 
45 #ifndef _INCLUDED_Field3D_Traits_H_
46 #define _INCLUDED_Field3D_Traits_H_
47 
48 #include <assert.h>
49 #include <string>
50 
51 #include <hdf5.h>
52 
53 #include "Log.h"
54 #include "Types.h"
55 
56 //----------------------------------------------------------------------------//
57 
58 #include "ns.h"
59 
61 
62 //----------------------------------------------------------------------------//
63 // Types
64 //----------------------------------------------------------------------------//
65 
66 #if !defined(_MSC_VER)
67 using ::uint8_t;
68 using ::int8_t;
69 using ::uint16_t;
70 using ::int16_t;
71 using ::uint32_t;
72 using ::int32_t;
73 using ::uint64_t;
74 using ::int64_t;
75 #else
76 typedef unsigned char uint8_t;
77 typedef signed char int8_t;
78 typedef unsigned short uint16_t;
79 typedef signed short int16_t;
80 typedef unsigned int uint32_t;
81 typedef int int32_t;
82 typedef unsigned long long uint64_t;
83 typedef long long int64_t;
84 #endif
85 
86 typedef half float16_t;
87 typedef float float32_t;
88 typedef double float64_t;
89 
90 #ifdef FIELD3D_VERSION_NS
96 #else
97 typedef Imath::Vec3<float16_t> vec16_t;
98 typedef Imath::Vec3<float32_t> vec32_t;
99 typedef Imath::Vec3<float64_t> vec64_t;
100 typedef Imath::Vec3<int32_t> veci32_t;
101 typedef Imath::M44d mtx64_t;
102 #endif
103 
104 //----------------------------------------------------------------------------//
105 // Enums
106 //----------------------------------------------------------------------------//
107 
118 };
119 
120 //----------------------------------------------------------------------------//
121 
126 
127  // Signed and unsigned integers from char to long
128  F3DInt8 = 0,
130 
133 
136 
139 
140  // Floats
144 
145  // Vec3
150 
151  // Matrix
153 
154  // String
156 
158 
159  // Invalid type enum
160  F3DInvalidDataType = 127
161 };
162 
163 //----------------------------------------------------------------------------//
164 // FieldTraits
165 //----------------------------------------------------------------------------//
166 
172 template <class Data_T>
174 {
175 public:
177  static const int k_dataDims = 3;
178  static int dataDims() { return k_dataDims; }
179 };
180 
181 template <>
183 {
184 public:
185  static const int k_dataDims = 1;
186  static int dataDims() { return k_dataDims; }
187 };
188 
189 template <>
190 struct FieldTraits<float>
191 {
192 public:
193  static const int k_dataDims = 1;
194  static int dataDims() { return k_dataDims; }
195 };
196 
197 template <>
198 struct FieldTraits<double>
199 {
200 public:
201  static const int k_dataDims = 1;
202  static int dataDims() { return k_dataDims; }
203 };
204 
205 template <>
206 struct FieldTraits<int>
207 {
208 public:
209  static const int k_dataDims = 1;
210  static int dataDims() { return k_dataDims; }
211 };
212 
213 template <>
214 struct FieldTraits<char>
215 {
216 public:
217  static const int k_dataDims = 1;
218  static int dataDims() { return k_dataDims; }
219 };
220 
221 template <>
222 struct FieldTraits<unsigned char>
223 {
224 public:
225  static const int k_dataDims = 1;
226  static int dataDims() { return k_dataDims; }
227 };
228 
229 template <>
231 {
232 public:
233  static const int k_dataDims = 3;
234  static int dataDims() { return k_dataDims; }
235 };
236 
237 template <>
239 {
240 public:
241  static const int k_dataDims = 3;
242  static int dataDims() { return k_dataDims; }
243 };
244 
245 template <>
247 {
248 public:
249  static const int k_dataDims = 3;
250  static int dataDims() { return k_dataDims; }
251 };
252 
253 template <>
255 {
256 public:
257  static const int k_dataDims = 3;
258  static int dataDims() { return k_dataDims; }
259 };
260 
261 //----------------------------------------------------------------------------//
262 // DataTypeTraits
263 //----------------------------------------------------------------------------//
264 
265 template <typename T>
267  static std::string name()
268  {
269  return typeid(T).name();
270  }
272  static hid_t h5type();
273  static int h5bits();
274 };
275 
276 //----------------------------------------------------------------------------//
277 // TemplatedFieldType
278 //----------------------------------------------------------------------------//
279 
281 template <class Field_T>
283 {
284  const char *name()
285  {
286  return m_name.c_str();
287  }
289  {
290  m_name = Field_T::staticClassName();
291  m_name +=
292  "<" +
294  ">";
295  }
296 private:
297  std::string m_name;
298 };
299 
300 //----------------------------------------------------------------------------//
301 // NestedFieldType
302 //----------------------------------------------------------------------------//
303 
305 template <typename Field_T>
307 {
308  const char *name()
309  {
310  return m_name.c_str();
311  }
313  {
314  typedef typename Field_T::NestedType NestedType;
315  typedef typename NestedType::value_type value_type;
316 
317  m_name = Field_T::staticClassName();
318  m_name +=
319  std::string("<") + NestedType::staticClassName() + "<" +
321  }
322 private:
323  std::string m_name;
324 };
325 
326 //----------------------------------------------------------------------------//
327 // Template specializations
328 //----------------------------------------------------------------------------//
329 
330 #define FIELD3D_DECL_DATATYPENAME(typeName) \
331  template<> \
332  inline std::string DataTypeTraits<typeName>::name() \
333  { \
334  return std::string(#typeName); \
335  } \
336 
337 //----------------------------------------------------------------------------//
338 
339 FIELD3D_DECL_DATATYPENAME(unsigned char)
347 
348 //----------------------------------------------------------------------------//
349 
350 template<>
352 {
353  return DataTypeHalf;
354 }
355 
356 //----------------------------------------------------------------------------//
357 
358 template<>
360 {
361  return DataTypeUnsignedChar;
362 }
363 
364 //----------------------------------------------------------------------------//
365 
366 template<>
368 {
369  return DataTypeInt;
370 }
371 
372 //----------------------------------------------------------------------------//
373 
374 template<>
376 {
377  return DataTypeFloat;
378 }
379 
380 //----------------------------------------------------------------------------//
381 
382 template<>
384 {
385  return DataTypeDouble;
386 }
387 
388 //----------------------------------------------------------------------------//
389 
390 template<>
392 {
393  return DataTypeVecHalf;
394 }
395 
396 //----------------------------------------------------------------------------//
397 
398 template<>
400 {
401  return DataTypeVecFloat;
402 }
403 
404 //----------------------------------------------------------------------------//
405 
406 template<>
408 {
409  return DataTypeVecDouble;
410 }
411 
412 template <>
414 {
415  return H5T_NATIVE_SHORT;
416 }
417 
418 //----------------------------------------------------------------------------//
419 
420 template <>
422 {
423  return H5T_NATIVE_FLOAT;
424 }
425 
426 //----------------------------------------------------------------------------//
427 
428 template <>
430 {
431  return H5T_NATIVE_DOUBLE;
432 }
433 
434 //----------------------------------------------------------------------------//
435 
436 template <>
438 {
439  return H5T_NATIVE_CHAR;
440 }
441 
442 //----------------------------------------------------------------------------//
443 
444 template <>
446 {
447  return H5T_NATIVE_UCHAR;
448 }
449 
450 //----------------------------------------------------------------------------//
451 
452 template <>
454 {
455  return H5T_NATIVE_INT;
456 }
457 
458 //----------------------------------------------------------------------------//
459 
460 template <>
462 {
463  return H5T_NATIVE_SHORT;
464 }
465 
466 //----------------------------------------------------------------------------//
467 
468 template <>
470 {
471  return H5T_NATIVE_FLOAT;
472 }
473 
474 //----------------------------------------------------------------------------//
475 
476 template <>
478 {
479  return H5T_NATIVE_DOUBLE;
480 }
481 
482 //----------------------------------------------------------------------------//
483 
484 template <>
486 {
487  return 16;
488 }
489 
490 //----------------------------------------------------------------------------//
491 
492 template <>
494 {
495  return 32;
496 }
497 
498 //----------------------------------------------------------------------------//
499 
500 template <>
502 {
503  return 64;
504 }
505 
506 //----------------------------------------------------------------------------//
507 
508 template <>
510 {
511  return 16;
512 }
513 
514 //----------------------------------------------------------------------------//
515 
516 template <>
518 {
519  return 32;
520 }
521 
522 //----------------------------------------------------------------------------//
523 
524 template <>
526 {
527  return 64;
528 }
529 
530 //----------------------------------------------------------------------------//
531 
533 
534 //----------------------------------------------------------------------------//
535 
536 #endif // Include guard
F3DVec64
@ F3DVec64
Definition: Traits.h:148
F3DFloat64
@ F3DFloat64
Definition: Traits.h:143
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
F3DFloat32
@ F3DFloat32
Definition: Traits.h:142
FieldTraits< V3h >::dataDims
static int dataDims()
Definition: Traits.h:234
V3i
Imath::V3i V3i
Definition: SpiMathLib.h:71
F3DFloat16
@ F3DFloat16
Definition: Traits.h:141
FIELD3D_DECL_DATATYPENAME
#define FIELD3D_DECL_DATATYPENAME(typeName)
Definition: Traits.h:330
FieldTraits< V3d >::dataDims
static int dataDims()
Definition: Traits.h:250
F3DVec32
@ F3DVec32
Definition: Traits.h:147
V3d
Imath::V3d V3d
Definition: SpiMathLib.h:74
DataTypeTraits::h5type
static hid_t h5type()
F3DNumDataTypes
@ F3DNumDataTypes
Definition: Traits.h:157
Types.h
Contains typedefs for the commonly used types in Field3D.
TemplatedFieldType::TemplatedFieldType
TemplatedFieldType()
Definition: Traits.h:288
FieldTraits< double >::dataDims
static int dataDims()
Definition: Traits.h:202
DataTypeFloat
@ DataTypeFloat
Definition: Traits.h:112
float64_t
double float64_t
Definition: Traits.h:88
DataTypeEnum
DataTypeEnum
Definition: Traits.h:108
DataTypeUnknown
@ DataTypeUnknown
Definition: Traits.h:117
V3f
Imath::V3f V3f
Definition: SpiMathLib.h:73
F3DVec16
@ F3DVec16
Definition: Traits.h:146
DataTypeVecHalf
@ DataTypeVecHalf
Definition: Traits.h:114
NestedFieldType::NestedFieldType
NestedFieldType()
Definition: Traits.h:312
FieldTraits< char >::dataDims
static int dataDims()
Definition: Traits.h:218
FieldTraits
Definition: Traits.h:174
Log.h
Contains the Log class which can be used to redirect output to an arbitrary destination.
FieldTraits< V3f >::dataDims
static int dataDims()
Definition: Traits.h:242
DataTypeHalf
@ DataTypeHalf
Definition: Traits.h:109
half
FIELD3D_NAMESPACE_OPEN typedef ::half half
Definition: SpiMathLib.h:64
ns.h
NestedFieldType::m_name
std::string m_name
Definition: Traits.h:323
F3DUint16
@ F3DUint16
Definition: Traits.h:132
F3DUint64
@ F3DUint64
Definition: Traits.h:138
DataTypeTraits::h5bits
static int h5bits()
vec32_t
Field3D::V3f vec32_t
Definition: Traits.h:92
F3DInt16
@ F3DInt16
Definition: Traits.h:131
mtx64_t
Field3D::M44d mtx64_t
Definition: Traits.h:95
FieldTraits< half >::dataDims
static int dataDims()
Definition: Traits.h:186
F3DInt64
@ F3DInt64
Definition: Traits.h:137
TemplatedFieldType::name
const char * name()
Definition: Traits.h:284
DataTypeTraits::typeEnum
static DataTypeEnum typeEnum()
vec64_t
Field3D::V3d vec64_t
Definition: Traits.h:93
NestedFieldType::name
const char * name()
Definition: Traits.h:308
DataTypeVecDouble
@ DataTypeVecDouble
Definition: Traits.h:116
FieldTraits::k_dataDims
static const int k_dataDims
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Definition: Traits.h:177
float32_t
float float32_t
Definition: Traits.h:87
FieldTraits< C3f >::dataDims
static int dataDims()
Definition: Traits.h:258
F3DUint8
@ F3DUint8
Definition: Traits.h:129
DataTypeVecFloat
@ DataTypeVecFloat
Definition: Traits.h:115
F3DInt32
@ F3DInt32
Definition: Traits.h:134
F3DMtx64
@ F3DMtx64
Definition: Traits.h:152
F3DUint32
@ F3DUint32
Definition: Traits.h:135
DataTypeUnsignedChar
@ DataTypeUnsignedChar
Definition: Traits.h:110
DataTypeDouble
@ DataTypeDouble
Definition: Traits.h:113
V3h
Imath::Vec3< half > V3h
Definition: SpiMathLib.h:72
M44d
Imath::M44d M44d
Definition: SpiMathLib.h:82
TemplatedFieldType::m_name
std::string m_name
Definition: Traits.h:297
F3DString
@ F3DString
Definition: Traits.h:155
F3DInvalidDataType
@ F3DInvalidDataType
Definition: Traits.h:160
F3DInt8
@ F3DInt8
Definition: Traits.h:128
DataTypeInt
@ DataTypeInt
Definition: Traits.h:111
F3DVecI32
@ F3DVecI32
Definition: Traits.h:149
NestedFieldType
Used to return a string for the name of a nested templated field.
Definition: Traits.h:307
DataTypeTraits
Definition: Traits.h:266
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
FieldTraits< float >::dataDims
static int dataDims()
Definition: Traits.h:194
C3f
Imath::C3f C3f
Definition: SpiMathLib.h:68
TemplatedFieldType
Used to return a string for the name of a templated field.
Definition: Traits.h:283
DataTypeTraits::name
static std::string name()
Definition: Traits.h:267
veci32_t
Field3D::V3i veci32_t
Definition: Traits.h:94
OgDataType
OgDataType
Enumerates the various uses for Ogawa-level groups.
Definition: Traits.h:125
FieldTraits< int >::dataDims
static int dataDims()
Definition: Traits.h:210
FieldTraits::dataDims
static int dataDims()
Definition: Traits.h:178
vec16_t
Field3D::V3h vec16_t
Definition: Traits.h:91
FieldTraits< unsigned char >::dataDims
static int dataDims()
Definition: Traits.h:226
float16_t
half float16_t
Definition: Traits.h:86