Field3D
Types.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_Types_H_
46 #define _INCLUDED_Field3D_Types_H_
47 
48 //----------------------------------------------------------------------------//
49 
50 #include <vector>
51 #include <limits>
52 
53 #ifdef FIELD3D_CUSTOM_MATH_LIB
54 # include FIELD3D_MATH_LIB_INCLUDE
55 #else
56 # include "StdMathLib.h"
57 #endif
58 
59 //----------------------------------------------------------------------------//
60 // Interval
61 //----------------------------------------------------------------------------//
62 
65 struct Interval
66 {
67  // Constructor ---------------------------------------------------------------
68 
70  Interval(double start, double end, double step)
71  : t0(start), t1(end), stepLength(step)
72  { }
73 
74  // Public data members -------------------------------------------------------
75 
77  double t0;
79  double t1;
82  double stepLength;
83 };
84 
85 //----------------------------------------------------------------------------//
86 
87 typedef std::vector<Interval> IntervalVec;
88 
89 //----------------------------------------------------------------------------//
90 // Utilities
91 //----------------------------------------------------------------------------//
92 
93 template <typename From_T, typename To_T>
94 To_T clampForType(const From_T v)
95 {
96  // Different behavior for integer vs fp types
97  To_T lowestTo;
98  From_T lowest;
99  if (std::numeric_limits<To_T>::is_integer) {
100  lowestTo = std::numeric_limits<To_T>::min();
101  lowest = static_cast<From_T>(lowestTo);
102  } else {
103  lowestTo = -std::numeric_limits<To_T>::max();
104  lowest = static_cast<From_T>(lowestTo);
105  }
106  const To_T highestTo = std::numeric_limits<To_T>::max();
107  const From_T highest = static_cast<From_T>(highestTo);
108  // Perform check
109  if (v < lowest) {
110  return lowest;
111  } else if (v > highest) {
112  return highest;
113  }
114  return v;
115 }
116 
117 //----------------------------------------------------------------------------//
118 
119 #endif // Include guard
120 
Interval::Interval
Interval(double start, double end, double step)
Default constructor.
Definition: Types.h:70
Interval::t1
double t1
The end of the interval (inclusive)
Definition: Types.h:79
detail::max
T max(const T a, const T2 b)
Max operation on mixed types.
Definition: FieldSampler.h:32
Interval::t0
double t0
The start of the interval (inclusive)
Definition: Types.h:77
Interval
Represents a single integration interval. The interval is assumed to be inclusive,...
Definition: Types.h:66
Interval::stepLength
double stepLength
The world space step length that is reasonable to use for the given interval.
Definition: Types.h:82
clampForType
To_T clampForType(const From_T v)
Definition: Types.h:94
IntervalVec
std::vector< Interval > IntervalVec
Definition: Types.h:87
detail::min
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
StdMathLib.h