20 #if !defined(__MITSUBA_CORE_VECTOR_H_)
21 #define __MITSUBA_CORE_VECTOR_H_
38 const static int dim = 1;
49 #if !defined(MTS_DEBUG_UNINITIALIZED)
52 TVector1() { x = std::numeric_limits<T>::quiet_NaN(); }
113 SLog(
EWarn,
"Vector1: Division by zero!");
122 SLog(
EWarn,
"Vector1: Division by zero!");
173 std::ostringstream oss;
174 oss <<
"[" << x <<
"]";
188 return std::abs(
dot(v1, v2));
198 SLog(
EError,
"normalizeStrict(): %s", errMsg);
205 SLog(
EWarn,
"Vector1i: Division by zero!");
213 SLog(
EWarn,
"Vector1i: Division by zero!");
254 const static int dim = 2;
265 #if !defined(MTS_DEBUG_UNINITIALIZED)
268 TVector2() { x = y = std::numeric_limits<T>::quiet_NaN(); }
279 : x((T) v.x), y((T) v.y) { }
283 : x((T) p.x), y((T) p.y) { }
333 SLog(
EWarn,
"Vector2: Division by zero!");
336 return TVector2(x * recip, y * recip);
343 SLog(
EWarn,
"Vector2: Division by zero!");
346 x *= recip; y *= recip;
372 return x == 0 && y == 0;
377 return (v.
x == x && v.
y == y);
382 return v.
x != x || v.
y != y;
393 std::ostringstream oss;
394 oss <<
"[" << x <<
", " << y <<
"]";
404 return v1.
x * v2.
x + v1.
y * v2.
y;
408 return std::abs(
dot(v1, v2));
412 return v1.
x * v2.
y - v1.
y * v2.
x;
422 SLog(
EError,
"normalizeStrict(): %s", errMsg);
429 SLog(
EWarn,
"Vector2i: Division by zero!");
437 SLog(
EWarn,
"Vector2i: Division by zero!");
458 const static int dim = 3;
469 #if !defined(MTS_DEBUG_UNINITIALIZED)
472 TVector3() { x = y = z = std::numeric_limits<T>::quiet_NaN(); }
479 explicit TVector3(T val) : x(val), y(val), z(val) { }
483 : x((T) v.x), y((T) v.y), z((T) v.z) { }
487 : x((T) p.x), y((T) p.y), z((T) p.z) { }
508 x += v.
x; y += v.
y; z += v.
z;
514 x -= v.
x; y -= v.
y; z -= v.
z;
525 x *= f; y *= f; z *= f;
538 SLog(
EWarn,
"Vector3: Division by zero!");
541 return TVector3(x * recip, y * recip, z * recip);
548 SLog(
EWarn,
"Vector3: Division by zero!");
551 x *= recip; y *= recip; z *= recip;
567 return x*x + y*y + z*z;
577 return x == 0 && y == 0 && z == 0;
582 return (v.
x == x && v.
y == y && v.
z == z);
587 return v.
x != x || v.
y != y || v.
z != z;
599 std::ostringstream oss;
600 oss <<
"[" << x <<
", " << y <<
", " << z <<
"]";
610 return v1.
x * v2.
x + v1.
y * v2.
y + v1.
z * v2.
z;
614 return std::abs(
dot(v1, v2));
619 (v1.
y * v2.
z) - (v1.
z * v2.
y),
620 (v1.
z * v2.
x) - (v1.
x * v2.
z),
621 (v1.
x * v2.
y) - (v1.
y * v2.
x)
632 SLog(
EError,
"normalizeStrict(): %s", errMsg);
639 SLog(
EWarn,
"Vector3i: Division by zero!");
647 SLog(
EWarn,
"Vector3i: Division by zero!");
670 const static int dim = 4;
681 #if !defined(MTS_DEBUG_UNINITIALIZED)
684 TVector4() { x = y = z = w = std::numeric_limits<T>::quiet_NaN(); }
688 TVector4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) { }
691 explicit TVector4(T val) : x(val), y(val), z(val), w(val) { }
695 : x((T) v.x), y((T) v.y), z((T) v.z), w((T) v.w) { }
699 : x((T) p.x), y((T) p.y), z((T) p.z), w((T) p.w) { }
721 x += v.
x; y += v.
y; z += v.
z; w += v.
w;
727 x -= v.
x; y -= v.
y; z -= v.
z; w -= v.
w;
733 return TVector4(x * f, y * f, z * f, w * f);
738 x *= f; y *= f; z *= f; w *= f;
751 SLog(
EWarn,
"Vector4: Division by zero!");
754 return TVector4(x * recip, y * recip, z * recip, w * recip);
761 SLog(
EWarn,
"Vector4: Division by zero!");
764 x *= recip; y *= recip; z *= recip; w *= recip;
780 return x*x + y*y + z*z + w*w;
790 return x == 0 && y == 0 && z == 0 && w == 0;
795 return (v.
x == x && v.
y == y && v.
z == z && v.
w == w);
800 return v.
x != x || v.
y != y || v.
z != z || v.
w != w;
813 std::ostringstream oss;
814 oss <<
"[" << x <<
", " << y <<
", " << z <<
", " << w <<
"]";
824 return v1.
x * v2.
x + v1.
y * v2.
y + v1.
z * v2.
z + v1.
w * v2.
w;
828 return std::abs(
dot(v1, v2));
838 SLog(
EError,
"normalizeStrict(): %s", errMsg);
845 SLog(
EWarn,
"Vector4i: Division by zero!");
847 return TVector4(x/s, y/s, z/s, w/s);
853 SLog(
EWarn,
"Vector4i: Division by zero!");
TVector4(const TPoint4< T2 > &p)
Initialize the vector with the components of a point data structure.
Definition: vector.h:698
T length() const
Return the 1-norm of this vector.
Definition: vector.h:144
TVector1 & operator-=(const TVector1 &v)
Subtract another vector from the current one.
Definition: vector.h:88
T operator[](int i) const
Index into the vector's components (const version)
Definition: vector.h:561
LengthType length() const
Return the 2-norm of this vector.
Definition: vector.h:366
TVector2< int > & operator/=(int s)
Definition: vector.h:434
TVector2 operator+(const TVector2 &v) const
Add two vectors and return the result.
Definition: vector.h:292
TVector2 & operator/=(T f)
Divide the vector by the given scalar.
Definition: vector.h:340
TVector4< T > operator*(T f, const TVector4< T > &v)
Definition: vector.h:819
TVector3()
Construct a new vector without initializing it.
Definition: vector.h:470
TVector1(Stream *stream)
Unserialize a vector from a binary data stream.
Definition: vector.h:67
T readElement()
Read an element from the stream (uses partial template specialization to select a method appropriate ...
Definition: stream.h:508
std::string toString() const
Return a readable string representation of this vector.
Definition: vector.h:172
T & operator[](int i)
Index into the vector's components.
Definition: vector.h:769
T lengthSquared() const
Return the squared 2-norm of this vector.
Definition: vector.h:779
TVector2(const TVector2< T2 > &v)
Initialize the vector with the components of another vector data structure.
Definition: vector.h:278
T type
Definition: vector.h:224
TVector3 operator-() const
Return a negated version of the vector.
Definition: vector.h:530
TVector3 & operator+=(const TVector3 &v)
Add another vector to the current one.
Definition: vector.h:507
TVector1 & operator/=(T f)
Divide the vector by the given scalar.
Definition: vector.h:119
TVector4(Stream *stream)
Unserialize a vector from a binary data stream.
Definition: vector.h:702
void serialize(Stream *stream) const
Serialize this vector to a binary data stream.
Definition: vector.h:164
T dot(const TVector4< T > &v1, const TVector4< T > &v2)
Definition: vector.h:823
TVector2 operator/(T f) const
Divide the vector by the given scalar and return the result.
Definition: vector.h:330
T absDot(const TVector4< T > &v1, const TVector4< T > &v2)
Definition: vector.h:827
T y
Definition: vector.h:455
T x
Definition: vector.h:667
TPoint4< T > PointType
Definition: vector.h:664
detail::VectorLength< T, std::numeric_limits< T >::is_integer >::type LengthType
Definition: vector.h:453
TVector1< int > operator/(int s) const
Definition: vector.h:202
Parameterizable one-dimensional point data structure.
Definition: point.h:33
detail::VectorLength< T, std::numeric_limits< T >::is_integer >::type LengthType
Definition: vector.h:249
TVector3 operator-(const TVector3 &v) const
Subtract two vectors and return the result.
Definition: vector.h:502
void serialize(Stream *stream) const
Serialize this vector to a binary data stream.
Definition: vector.h:591
T Scalar
Definition: vector.h:247
TVector4< T > normalizeStrict(const TVector4< T > &v, const char *errMsg)
Definition: vector.h:835
TVector4 operator-(const TVector4 &v) const
Subtract two vectors and return the result.
Definition: vector.h:715
TVector4 operator/(T f) const
Divide the vector by the given scalar and return the result.
Definition: vector.h:748
TVector2 operator*(T f) const
Multiply the vector by the given scalar and return the result.
Definition: vector.h:314
#define SLog(level, fmt,...)
Write a Log message to the console (static version - to be used outside of classes that derive from O...
Definition: logger.h:49
TVector1()
Construct a new vector without initializing it.
Definition: vector.h:50
T z
Definition: vector.h:667
TVector3 operator/(T f) const
Divide the vector by the given scalar and return the result.
Definition: vector.h:535
TPoint1< T > PointType
Definition: vector.h:33
TVector4 & operator/=(T f)
Divide the vector by the given scalar.
Definition: vector.h:758
TVector1 operator-() const
Return a negated version of the vector.
Definition: vector.h:105
TVector3(T val)
Initialize all components of the the vector with the specified value.
Definition: vector.h:479
TVector1(const TVector1< T1 > &v)
Initialize the vector with the components of another vector data structure.
Definition: vector.h:59
T det(const TVector2< T > &v1, const TVector2< T > &v2)
Definition: vector.h:411
double type
Definition: vector.h:232
TVector1 operator-(const TVector1 &v) const
Subtract two vectors and return the result.
Definition: vector.h:77
TVector2 operator-(const TVector2 &v) const
Subtract two vectors and return the result.
Definition: vector.h:297
TVector3(T x, T y, T z)
Initialize the vector with the specified X, Y and Z components.
Definition: vector.h:476
TPoint2< T > PointType
Definition: vector.h:248
T Scalar
Definition: vector.h:663
TVector4< int > & operator/=(int s)
Definition: vector.h:850
TVector4()
Construct a new vector without initializing it.
Definition: vector.h:682
TVector3(const TPoint3< T2 > &p)
Initialize the vector with the components of a point data structure.
Definition: vector.h:486
T Scalar
Definition: vector.h:451
Float type
Definition: vector.h:228
TVector3 & operator/=(T f)
Divide the vector by the given scalar.
Definition: vector.h:545
TVector1 & operator*=(T f)
Multiply the vector by the given scalar.
Definition: vector.h:99
T x
Definition: vector.h:251
T Scalar
Definition: vector.h:32
TVector2 & operator-=(const TVector2 &v)
Subtract another vector from the current one.
Definition: vector.h:308
TVector2 operator-() const
Return a negated version of the vector.
Definition: vector.h:325
T x
Definition: vector.h:35
bool operator==(const TVector2 &v) const
Equality test.
Definition: vector.h:376
bool isZero() const
Return whether or not this vector is identically zero.
Definition: vector.h:149
void serialize(Stream *stream) const
Serialize this vector to a binary data stream.
Definition: vector.h:386
T & operator[](int i)
Index into the vector's components.
Definition: vector.h:351
Parameterizable two-dimensional point data structure.
Definition: point.h:222
TVector3 & operator*=(T f)
Multiply the vector by the given scalar.
Definition: vector.h:524
TVector1 operator/(T f) const
Divide the vector by the given scalar and return the result.
Definition: vector.h:110
T lengthSquared() const
Return the squared 1-norm of this vector.
Definition: vector.h:139
TVector3 & operator-=(const TVector3 &v)
Subtract another vector from the current one.
Definition: vector.h:513
LengthType length() const
Return the 2-norm of this vector.
Definition: vector.h:784
void serialize(Stream *stream) const
Serialize this vector to a binary data stream.
Definition: vector.h:804
bool operator==(const TVector4 &v) const
Equality test.
Definition: vector.h:794
TVector3(Stream *stream)
Unserialize a vector from a binary data stream.
Definition: vector.h:490
std::string toString() const
Return a readable string representation of this vector.
Definition: vector.h:392
T z
Definition: vector.h:455
Parameterizable one-dimensional vector data structure.
Definition: vector.h:31
TVector2()
Construct a new vector without initializing it.
Definition: vector.h:266
TVector2(T val)
Initialize all components of the the vector with the specified value.
Definition: vector.h:275
T operator[](int i) const
Index into the vector's components (const version)
Definition: vector.h:134
Parameterizable three-dimensional vector data structure.
Definition: vector.h:450
TVector1< int > & operator/=(int s)
Definition: vector.h:210
void writeElement(T value)
Write an element to the stream (uses partial template specialization to select a method appropriate t...
Definition: stream.h:512
T operator[](int i) const
Index into the vector's components (const version)
Definition: vector.h:774
TVector4 operator*(T f) const
Multiply the vector by the given scalar and return the result.
Definition: vector.h:732
LengthType length() const
Return the 2-norm of this vector.
Definition: vector.h:571
bool operator!=(const TVector3 &v) const
Inequality test.
Definition: vector.h:586
TVector1 operator+(const TVector1 &v) const
Add two vectors and return the result.
Definition: vector.h:72
Abstract seekable stream class.
Definition: stream.h:58
TVector4(T val)
Initialize all components of the the vector with the specified value.
Definition: vector.h:691
Warning message.
Definition: formatter.h:32
TVector2< int > operator/(int s) const
Definition: vector.h:426
T x
Definition: vector.h:455
std::string toString() const
Return a readable string representation of this vector.
Definition: vector.h:812
bool isZero() const
Return whether or not this vector is identically zero.
Definition: vector.h:371
bool operator!=(const TVector4 &v) const
Inequality test.
Definition: vector.h:799
TVector4(const TVector4< T2 > &v)
Initialize the vector with the components of another vector data structure.
Definition: vector.h:694
T & operator[](int i)
Index into the vector's components.
Definition: vector.h:129
detail::VectorLength< T, std::numeric_limits< T >::is_integer >::type LengthType
Definition: vector.h:665
TVector2 & operator+=(const TVector2 &v)
Add another vector to the current one.
Definition: vector.h:302
TVector3 operator+(const TVector3 &v) const
Add two vectors and return the result.
Definition: vector.h:497
Error message, causes an exception to be thrown.
Definition: formatter.h:33
Parameterizable three-dimensional point data structure.
Definition: point.h:415
T y
Definition: vector.h:251
TVector4 & operator*=(T f)
Multiply the vector by the given scalar.
Definition: vector.h:737
TVector4< int > operator/(int s) const
Definition: vector.h:842
T operator[](int i) const
Index into the vector's components (const version)
Definition: vector.h:356
bool operator==(const TVector1 &v) const
Equality test.
Definition: vector.h:154
bool operator==(const TVector3 &v) const
Equality test.
Definition: vector.h:581
TVector2(Stream *stream)
Unserialize a vector from a binary data stream.
Definition: vector.h:286
Parameterizable two-dimensional vector data structure.
Definition: vector.h:246
TVector3(const TVector3< T2 > &v)
Initialize the vector with the components of another vector data structure.
Definition: vector.h:482
TVector1(const TPoint1< T1 > &p)
Initialize the vector with the components of a point data structure.
Definition: vector.h:63
TVector3 operator*(T f) const
Multiply the vector by the given scalar and return the result.
Definition: vector.h:519
Parameterizable four-dimensional vector data structure.
Definition: vector.h:662
TVector4 & operator+=(const TVector4 &v)
Add another vector to the current one.
Definition: vector.h:720
T lengthSquared() const
Return the squared 2-norm of this vector.
Definition: vector.h:566
TVector3< int > & operator/=(int s)
Definition: vector.h:644
T y
Definition: vector.h:667
TVector3< int > operator/(int s) const
Definition: vector.h:636
bool operator!=(const TVector1 &v) const
Inequality test.
Definition: vector.h:159
TVector4< T > normalize(const TVector4< T > &v)
Definition: vector.h:831
double type
Definition: vector.h:236
TVector1(T x)
Initialize the vector with the specified value.
Definition: vector.h:56
TVector1 operator*(T f) const
Multiply the vector by the given scalar and return the result.
Definition: vector.h:94
bool operator!=(const TVector2 &v) const
Inequality test.
Definition: vector.h:381
TVector3< T > cross(const TVector3< T > &v1, const TVector3< T > &v2)
Definition: vector.h:617
TVector4 operator+(const TVector4 &v) const
Add two vectors and return the result.
Definition: vector.h:710
TVector4 & operator-=(const TVector4 &v)
Subtract another vector from the current one.
Definition: vector.h:726
bool isZero() const
Return whether or not this vector is identically zero.
Definition: vector.h:789
Parameterizable four-dimensional point data structure.
Definition: point.h:612
TVector2(T x, T y)
Initialize the vector with the specified X and Z components.
Definition: vector.h:272
TVector4(T x, T y, T z, T w)
Initialize the vector with the specified X, Y and Z components.
Definition: vector.h:688
TPoint3< T > PointType
Definition: vector.h:452
TVector1 & operator+=(const TVector1 &v)
Add another vector to the current one.
Definition: vector.h:82
T w
Definition: vector.h:667
T & operator[](int i)
Index into the vector's components.
Definition: vector.h:556
std::string toString() const
Return a readable string representation of this vector.
Definition: vector.h:598
bool isZero() const
Return whether or not this vector is identically zero.
Definition: vector.h:576
TVector2 & operator*=(T f)
Multiply the vector by the given scalar.
Definition: vector.h:319
TVector4 operator-() const
Return a negated version of the vector.
Definition: vector.h:743
TVector2(const TPoint2< T2 > &p)
Initialize the vector with the components of a point data structure.
Definition: vector.h:282
T lengthSquared() const
Return the squared 2-norm of this vector.
Definition: vector.h:361