19 #if !defined(__NORI_VECTOR_H)
20 #define __NORI_VECTOR_H
22 #include <nori/common.h>
37 template <
typename _Scalar,
int _Dimension>
struct TVector :
public Eigen::Matrix<_Scalar, _Dimension, 1> {
40 Dimension = _Dimension
43 typedef _Scalar Scalar;
44 typedef Eigen::Matrix<Scalar, Dimension, 1> Base;
49 TVector(Scalar value = (Scalar) 0) { Base::setConstant(value); }
52 TVector(Scalar x, Scalar y) : Base(x, y) { }
55 TVector(Scalar x, Scalar y, Scalar z) : Base(x, y, z) { }
58 TVector(Scalar x, Scalar y, Scalar z, Scalar w) : Base(x, y, z, w) { }
61 template <
typename Derived>
TVector(
const Eigen::MatrixBase<Derived>& p)
66 this->Base::operator=(p);
73 for (
size_t i=0; i<Dimension; ++i) {
74 result += std::to_string(this->coeff(i));
78 return "[" + result +
"]";
85 template <
typename _Scalar,
int _Dimension>
struct TPoint :
public Eigen::Matrix<_Scalar, _Dimension, 1> {
88 Dimension = _Dimension
91 typedef _Scalar Scalar;
92 typedef Eigen::Matrix<Scalar, Dimension, 1> Base;
97 TPoint(Scalar value = (Scalar) 0) { Base::setConstant(value); }
100 TPoint(Scalar x, Scalar y) : Base(x, y) { }
103 TPoint(Scalar x, Scalar y, Scalar z) : Base(x, y, z) { }
106 TPoint(Scalar x, Scalar y, Scalar z, Scalar w) : Base(x, y, z, w) { }
109 template <
typename Derived>
TPoint(
const Eigen::MatrixBase<Derived>& p)
114 this->Base::operator=(p);
121 for (
size_t i=0; i<Dimension; ++i) {
122 result += std::to_string(this->coeff(i));
126 return "[" + result +
"]";
133 struct Normal3f :
public Eigen::Matrix<float, 3, 1> {
139 typedef float Scalar;
140 typedef Eigen::Matrix<Scalar, Dimension, 1> Base;
146 Normal3f(Scalar value = 0.0f) { Base::setConstant(value); }
149 Normal3f(Scalar x, Scalar y, Scalar z) : Base(x, y, z) { }
152 template <
typename Derived>
Normal3f(
const Eigen::MatrixBase<Derived>& p)
157 this->Base::operator=(p);
163 return tfm::format(
"[%f, %f, %f]", coeff(0), coeff(1), coeff(2));
3-dimensional surface normal representation
Normal3f & operator=(const Eigen::MatrixBase< Derived > &p)
Assign a normal from MatrixBase (needed to play nice with Eigen)
std::string toString() const
Return a human-readable string summary.
Normal3f(Scalar value=0.0f)
Create a new normal with constant component vlaues.
Normal3f(Scalar x, Scalar y, Scalar z)
Create a new 3D normal.
Normal3f(const Eigen::MatrixBase< Derived > &p)
Construct a normal from MatrixBase (needed to play nice with Eigen)
Generic N-dimensional point data structure based on Eigen::Matrix.
TPoint & operator=(const Eigen::MatrixBase< Derived > &p)
Assign a point from MatrixBase (needed to play nice with Eigen)
std::string toString() const
Return a human-readable string summary.
TPoint(Scalar value=(Scalar) 0)
Create a new point with constant component vlaues.
TPoint(Scalar x, Scalar y, Scalar z)
Create a new 3D point (type error if Dimension != 3)
TPoint(Scalar x, Scalar y)
Create a new 2D point (type error if Dimension != 2)
TPoint(Scalar x, Scalar y, Scalar z, Scalar w)
Create a new 4D point (type error if Dimension != 4)
TPoint(const Eigen::MatrixBase< Derived > &p)
Construct a point from MatrixBase (needed to play nice with Eigen)
Generic N-dimensional vector data structure based on Eigen::Matrix.
TVector(Scalar x, Scalar y, Scalar z)
Create a new 3D vector (type error if Dimension != 3)
std::string toString() const
Return a human-readable string summary.
TVector(Scalar x, Scalar y, Scalar z, Scalar w)
Create a new 4D vector (type error if Dimension != 4)
TVector & operator=(const Eigen::MatrixBase< Derived > &p)
Assign a vector from MatrixBase (needed to play nice with Eigen)
TVector(Scalar x, Scalar y)
Create a new 2D vector (type error if Dimension != 2)
TVector(const Eigen::MatrixBase< Derived > &p)
Construct a vector from MatrixBase (needed to play nice with Eigen)
TVector(Scalar value=(Scalar) 0)
Create a new vector with constant component vlaues.