32 #ifndef HERMES_GEOMETRY_TRANSFORM_H
33 #define HERMES_GEOMETRY_TRANSFORM_H
35 #include <hermes/geometry/bbox.h>
84 Transform2 inverse(
const Transform2 &t);
135 r->
x = m[0][0] * x + m[0][1] * y + m[0][2];
136 r->
y = m[1][0] * x + m[1][1] * y + m[1][2];
137 real_t wp = m[2][0] * x + m[2][1] * y + m[2][2];
146 r->
x = m[0][0] * x + m[0][1] * y;
147 r->
y = m[1][0] * x + m[1][1] * y;
154 return vec2(m[0][0] * x + m[0][1] * y, m[1][0] * x + m[1][1] * y);
161 real_t xp = m[0][0] * x + m[0][1] * y + m[0][2];
162 real_t yp = m[1][0] * x + m[1][1] * y + m[1][2];
163 real_t wp = m[2][0] * x + m[2][1] * y + m[2][2];
166 return point2(xp / wp, yp / wp);
174 ret = make_union(ret, M(
point2(b.lower.x, b.lower.y)));
175 ret = make_union(ret, M(
point2(b.upper.x, b.lower.y)));
176 ret = make_union(ret, M(
point2(b.upper.x, b.upper.y)));
177 ret = make_union(ret, M(
point2(b.lower.x, b.upper.y)));
185 (*this)(ret.
o, &ret.
o);
186 (*this)(ret.
d, &ret.
d);
265 const vec3 &up = {0, 1, 0},
385 bbox3 ret(M(
point3(b.lower.x, b.lower.y, b.lower.z)));
386 ret = make_union(ret, M(
point3(b.upper.x, b.lower.y, b.lower.z)));
387 ret = make_union(ret, M(
point3(b.lower.x, b.upper.y, b.lower.z)));
388 ret = make_union(ret, M(
point3(b.lower.x, b.lower.y, b.upper.z)));
389 ret = make_union(ret, M(
point3(b.lower.x, b.upper.y, b.upper.z)));
390 ret = make_union(ret, M(
point3(b.upper.x, b.upper.y, b.lower.z)));
391 ret = make_union(ret, M(
point3(b.upper.x, b.lower.y, b.upper.z)));
392 ret = make_union(ret, M(
point3(b.lower.x, b.upper.y, b.upper.z)));
400 real_t xp =
m[0][0] * x +
m[0][1] * y +
m[0][2] * z +
m[0][3];
401 real_t yp =
m[1][0] * x +
m[1][1] * y +
m[1][2] * z +
m[1][3];
402 real_t zp =
m[2][0] * x +
m[2][1] * y +
m[2][2] * z +
m[2][3];
403 real_t wp =
m[3][0] * x +
m[3][1] * y +
m[3][2] * z +
m[3][3];
405 return point3(xp, yp, zp);
406 return point3(xp, yp, zp) / wp;
413 real_t xp =
m[0][0] * x +
m[0][1] * y +
m[0][2] * z +
m[0][3];
414 real_t yp =
m[1][0] * x +
m[1][1] * y +
m[1][2] * z +
m[1][3];
415 real_t zp =
m[2][0] * x +
m[2][1] * y +
m[2][2] * z +
m[2][3];
416 real_t wp =
m[3][0] * x +
m[3][1] * y +
m[3][2] * z +
m[3][3];
418 return point3(xp, yp, zp);
419 return point3(xp, yp, zp) / wp;
426 r->
x =
m[0][0] * x +
m[0][1] * y +
m[0][2] * z +
m[0][3];
427 r->
y =
m[1][0] * x +
m[1][1] * y +
m[1][2] * z +
m[1][3];
428 r->
z =
m[2][0] * x +
m[2][1] * y +
m[2][2] * z +
m[2][3];
429 real_t wp =
m[3][0] * x +
m[3][1] * y +
m[3][2] * z +
m[3][3];
438 return vec3(
m[0][0] * x +
m[0][1] * y +
m[0][2] * z,
439 m[1][0] * x +
m[1][1] * y +
m[1][2] * z,
440 m[2][0] * x +
m[2][1] * y +
m[2][2] * z);
448 return normal3(m_inv[0][0] * x + m_inv[1][0] * y + m_inv[2][0] * z,
449 m_inv[0][1] * x + m_inv[1][1] * y + m_inv[2][1] * z,
450 m_inv[0][2] * x + m_inv[1][2] * y + m_inv[2][2] * z);
457 (*this)(ret.
o, &ret.
o);
458 ret.
d = (*this)(ret.
d);
465 (*this)(r.
o, &ret->
o);
466 ret->
d = (*this)(ret->
d);
518 real_t x = p[0], y = p[1], z = 0.f;
521 r[0] =
m[0][0] * x +
m[0][1] * y +
m[0][2] * z +
m[0][3];
522 r[1] =
m[1][0] * x +
m[1][1] * y +
m[1][2] * z +
m[1][3];
524 r[2] =
m[2][0] * x +
m[2][1] * y +
m[2][2] * z +
m[2][3];
525 real_t wp =
m[3][0] * x +
m[3][1] * y +
m[3][2] * z +
m[3][3];
546 return mat3(
m[0][0],
m[0][1],
m[0][2],
m[1][0],
m[1][1],
547 m[1][2],
m[2][0],
m[2][1],
m[2][2]);
563 for (
int i = 0; i < 4; ++i)
564 for (
int j = 0; j < 4; ++j)
587 std::ostream &operator<<(std::ostream &os,
const Transform2 &m) {
588 for (
int i = 0; i < 3; i++) {
589 for (
int j = 0; j < 3; j++)
590 os << m[i][j] <<
" ";
601 std::ostream &operator<<(std::ostream &os,
const Transform &m) {
602 for (
int i = 0; i < 4; i++) {
603 for (
int j = 0; j < 4; j++)
604 os << m[i][j] <<
" ";
Support of bitwise operations for compatible enum classes.
#define HERMES_ENABLE_BITMASK_OPERATORS(x)
Adds bitwise operation support to a given enum class.
Definition: bitmask_operators.h:58
static MemoryDumper::RegionLayout memoryDumpLayout()
Gets memory layout.
Definition: math_element.h:56
HERMES_DEVICE_CALLABLE bool isIdentity() const
Definition: matrix.h:285
T x
0-th normal component
Definition: normal.h:172
T y
1-th normal component
Definition: normal.h:173
T z
2-th normal component
Definition: normal.h:174
T y
1-th component
Definition: point.h:140
T x
0-th component
Definition: point.h:139
T x
0-th component
Definition: point.h:270
T y
1-th component
Definition: point.h:271
T z
2-th component
Definition: point.h:272
vec2 d
ray's direction
Definition: ray.h:64
point2 o
ray's origin
Definition: ray.h:63
vec3 d
ray's direction
Definition: ray.h:95
point3 o
ray's origin
Definition: ray.h:94
T x
0-th component
Definition: vector.h:155
T y
1-th component
Definition: vector.h:156
T x
0-th component
Definition: vector.h:415
T z
2-th component
Definition: vector.h:417
T y
1-th component
Definition: vector.h:416
Debug, logging and assertion macros.
float real_t
default floating point type
Definition: defs.h:75
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45
uint32_t u32
32 bit size unsigned integer type
Definition: defs.h:88
Geometric normal classes.
static HERMES_DEVICE_CALLABLE std::enable_if_t< std::is_floating_point< T >::value, bool > is_nan(T v)
Checks if number representation is nan
Definition: numeric.h:884
Memory region description.
Definition: memory_dump.h:97