PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
Transform.h
Go to the documentation of this file.
1
11#ifndef PBAT_GEOMETRY_SDF_TRANSFORM_H
12#define PBAT_GEOMETRY_SDF_TRANSFORM_H
13
14#include "TypeDefs.h"
15#include "pbat/HostDevice.h"
17#include "pbat/math/linalg/mini/BinaryOperations.h"
18#include "pbat/math/linalg/mini/Eigen.h"
19#include "pbat/math/linalg/mini/Product.h"
20
21#include <Eigen/SVD>
22
23namespace pbat::geometry::sdf {
24
29template <common::CArithmetic TScalar>
31{
32 using ScalarType = TScalar;
38 Transform() = default;
44 Transform(Mat3<ScalarType> const& _R, Vec3<ScalarType> const& _t) : R(_R), t(_t) {}
55
60 PBAT_HOST_DEVICE Vec3<ScalarType> operator()(Vec3<ScalarType> const& p) const
61 {
62 return R * p + t;
63 }
64
69 PBAT_HOST_DEVICE Vec3<ScalarType> operator/(Vec3<ScalarType> const& p) const
70 {
71 return R.Transpose() * (p - t);
72 }
73
78 {
79 Eigen::Matrix<ScalarType, 3, 3> Reig = math::linalg::mini::ToEigen(R);
80 Eigen::JacobiSVD<decltype(Reig)> svd{Reig, Eigen::ComputeFullU | Eigen::ComputeFullV};
81 Reig = svd.matrixU() * svd.matrixV().transpose();
82 R = math::linalg::mini::FromEigen(Reig);
83 }
84};
85
86} // namespace pbat::geometry::sdf
87
88#endif // PBAT_GEOMETRY_SDF_TRANSFORM_H
This file defines common type definitions used in the SDF module.
Concepts for common types.
Namespace for signed distance functions (SDFs) and related operations.
Definition BinaryNode.cpp:3
math::linalg::mini::SVector< TScalar, 3 > Vec3
3D vector type
Definition TypeDefs.h:23
math::linalg::mini::SMatrix< TScalar, 3, 3 > Mat3
3x3 matrix type
Definition TypeDefs.h:32
math::linalg::mini::Zeros< TScalar, 3, 1 > Zero3
3D zero vector type
Definition TypeDefs.h:38
static Transform Identity()
Create an identity transform.
Definition Transform.h:49
void CleanRotation()
Clean the rotation matrix to ensure it is a valid rotation (orthogonal with determinant 1)
Definition Transform.h:77
PBAT_HOST_DEVICE Vec3< ScalarType > operator/(Vec3< ScalarType > const &p) const
Apply the inverse transform to a point (technically, a vector)
Definition Transform.h:69
Transform()=default
Default constructor.
Mat3< ScalarType > R
Rotation matrix.
Definition Transform.h:33
PBAT_HOST_DEVICE Vec3< ScalarType > operator()(Vec3< ScalarType > const &p) const
Apply the transform to a point (technically, a vector)
Definition Transform.h:60
Transform(Mat3< ScalarType > const &_R, Vec3< ScalarType > const &_t)
Constructor with rotation matrix and translation vector.
Definition Transform.h:44
TScalar ScalarType
Scalar type.
Definition Transform.h:32
Vec3< ScalarType > t
Translation vector.
Definition Transform.h:34