7#ifndef OPENVDB_MATH_TUPLE_HAS_BEEN_INCLUDED
8#define OPENVDB_MATH_TUPLE_HAS_BEEN_INCLUDED
28template<
int SIZE,
typename T>
35 static const int size = SIZE;
48 template <
int src_size,
typename src_valtype>
50 enum { COPY_END = (SIZE < src_size ? SIZE : src_size) };
52 for (
int i = 0; i < COPY_END; ++i) {
55 for (
int i = COPY_END; i < SIZE; ++i) {
62 template <
typename IdxT,
63 typename std::enable_if<std::is_integral<IdxT>::value,
bool>::type =
true>
65 assert(i >= IdxT(0) && i < IdxT(SIZE));
71 template <
typename IdxT,
72 typename std::enable_if<std::is_integral<IdxT>::value,
bool>::type =
true>
74 assert(i >= IdxT(0) && i < IdxT(SIZE));
82 T
operator[](
int i)
const {
return this->
template operator[]<
int>(i); }
83 T&
operator[](
int i) {
return this->
template operator[]<
int>(i); }
91 void toV(S *v)
const {
92 for (
int i = 0; i < SIZE; ++i) {
109 std::ostringstream buffer;
114 for (
unsigned j(0); j < SIZE; j++) {
115 if (j) buffer <<
", ";
124 void write(std::ostream& os)
const {
125 os.write(
reinterpret_cast<const char*
>(&mm),
sizeof(T)*SIZE);
128 is.read(
reinterpret_cast<char*
>(&mm),
sizeof(T)*SIZE);
133 for (
int i = 0; i < SIZE; ++i) {
134 if (math::isNan(mm[i]))
return true;
141 for (
int i = 0; i < SIZE; ++i) {
142 if (math::isInfinite(mm[i]))
return true;
149 for (
int i = 0; i < SIZE; ++i) {
150 if (!math::isFinite(mm[i]))
return false;
157 for (
int i = 0; i < SIZE; ++i) {
158 if (!math::isZero(mm[i]))
return false;
172template<
int SIZE,
typename T0,
typename T1>
176 for (
int i = 0; i < SIZE-1; ++i) {
179 return t0[SIZE-1] < t1[SIZE-1];
184template<
int SIZE,
typename T0,
typename T1>
188 for (
int i = 0; i < SIZE-1; ++i) {
191 return t0[SIZE-1] > t1[SIZE-1];
199template<
int SIZE,
typename T>
204 for (
int i = 0; i < SIZE; ++i) result[i] = math::Abs(t[i]);
209template<
int SIZE,
typename T>
213template<
int SIZE,
typename T>
217template<
int SIZE,
typename T>
221template<
int SIZE,
typename T>
228template <
int SIZE,
typename T>
231 ostr << classname.
str();
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
T operator[](IdxT i) const
Definition Tuple.h:64
bool isZero() const
True if all elements are exactly zero.
Definition Tuple.h:156
void write(std::ostream &os) const
Copies this tuple into an array of a compatible type.
Definition Tuple.h:124
bool isInfinite() const
True if an Inf is present in this tuple.
Definition Tuple.h:140
T & operator[](IdxT i)
Definition Tuple.h:73
value_type const * asV() const
Exposes the internal array. Be careful when using this function.
Definition Tuple.h:102
value_type * asV()
Exposes the internal array. Be careful when using this function.
Definition Tuple.h:98
T operator[](int i) const
Definition Tuple.h:82
Tuple(Tuple< src_size, src_valtype > const &src)
Conversion constructor.
Definition Tuple.h:49
void toV(S *v) const
Copies this tuple into an array of a compatible type.
Definition Tuple.h:91
T & operator[](int i)
Definition Tuple.h:83
std::string str() const
Definition Tuple.h:108
T ValueType
Definition Tuple.h:33
bool isNan() const
True if a Nan is present in this tuple.
Definition Tuple.h:132
T value_type
Definition Tuple.h:32
void read(std::istream &is)
Copies this tuple into an array of a compatible type.
Definition Tuple.h:127
bool isFinite() const
True if no Nan or Inf values are present.
Definition Tuple.h:148
bool isInfinite(const float x)
Return true if x is an infinity value (either positive infinity or negative infinity).
Definition Math.h:385
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition Tuple.h:174
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition Tuple.h:186
bool isFinite(const float x)
Return true if x is finite.
Definition Math.h:375
auto PrintCast(const T &val) -> typename std::enable_if<!std::is_same< T, int8_t >::value &&!std::is_same< T, uint8_t >::value, const T & >::type
8-bit integer values print to std::ostreams as characters. Cast them so that they print as integers i...
Definition Math.h:882
bool isNan(const float x)
Return true if x is a NaN (Not-A-Number) value.
Definition Math.h:395
Coord Abs(const Coord &xyz)
Definition Coord.h:515
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition Math.h:337
std::ostream & operator<<(std::ostream &ostr, const Metadata &metadata)
Write a Metadata to an output stream.
Definition Metadata.h:351
Definition Exceptions.h:13
Dummy class for tag dispatch of conversion constructors.
Definition Tuple.h:23
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212