MeshLib Documentation
Loading...
Searching...
No Matches
MRMesh/MRAffineXf.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMacros.h"
4#include "MRMeshFwd.h"
5#include <type_traits>
6
7namespace MR
8{
9
12template <typename V>
14{
15 using T = typename V::ValueType;
16 using M = typename V::MatrixType;
17
19 V b;
20
21 constexpr AffineXf() noexcept = default;
22 constexpr AffineXf( const M & A, const V & b ) noexcept : A( A ), b( b ) { }
23 template <typename U>
24 constexpr explicit AffineXf( const AffineXf<U> & xf ) noexcept : A( xf.A ), b( xf.b ) { }
26 [[nodiscard]] static constexpr AffineXf translation( const V & b ) noexcept { return AffineXf{ M{}, b }; }
28 [[nodiscard]] static constexpr AffineXf linear( const M & A ) noexcept { return AffineXf{ A, V{} }; }
30 [[nodiscard]] static constexpr AffineXf xfAround( const M & A, const V & stable ) noexcept { return AffineXf{ A, stable - A * stable }; }
31
33 [[nodiscard]] constexpr V operator() ( const V & x ) const noexcept { return A * x + b; }
36 [[nodiscard]] constexpr V linearOnly( const V & x ) const noexcept { return A * x; }
38 [[nodiscard]] constexpr AffineXf inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> );
39
42 friend AffineXf<V> operator * ( const AffineXf<V> & u, const AffineXf<V> & v )
43 { return { u.A * v.A, u.A * v.b + u.b }; }
44
46 friend bool operator == ( const AffineXf<V> & a, const AffineXf<V> & b )
47 {
48 return a.A == b.A && a.b == b.b;
49 }
50
52 friend bool operator != ( const AffineXf<V> & a, const AffineXf<V> & b )
53 {
54 return !( a == b );
55 }
56};
57
60
61template <typename V>
62inline constexpr AffineXf<V> AffineXf<V>::inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> )
63{
64 AffineXf<V> res;
65 res.A = A.inverse();
66 res.b = -( res.A * b );
67 return res;
68}
69
71
72} // namespace MR
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:29
Definition MRCameraOrientationPlugin.h:8
MRMESH_CLASS Vector3< double > Matrix2< double > Matrix4< double > SymMatrix3< double > AffineXf
Definition MRMesh/MRMeshFwd.h:201
Definition MRMesh/MRAffineXf.h:14
typename V::ValueType T
Definition MRMesh/MRAffineXf.h:15
friend bool operator!=(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRMesh/MRAffineXf.h:52
static constexpr AffineXf linear(const M &A) noexcept
creates linear-only transformation (without translation)
Definition MRMesh/MRAffineXf.h:28
static constexpr AffineXf xfAround(const M &A, const V &stable) noexcept
creates transformation with given linear part with given stable point
Definition MRMesh/MRAffineXf.h:30
friend bool operator==(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRMesh/MRAffineXf.h:46
constexpr V operator()(const V &x) const noexcept
application of the transformation to a point
Definition MRMesh/MRAffineXf.h:33
typename V::MatrixType M
Definition MRMesh/MRAffineXf.h:16
constexpr AffineXf() noexcept=default
V b
Definition MRMesh/MRAffineXf.h:19
M A
Definition MRMesh/MRAffineXf.h:18
static constexpr AffineXf translation(const V &b) noexcept
creates translation-only transformation (with identity linear component)
Definition MRMesh/MRAffineXf.h:26
constexpr V linearOnly(const V &x) const noexcept
Definition MRMesh/MRAffineXf.h:36
constexpr AffineXf(const AffineXf< U > &xf) noexcept
Definition MRMesh/MRAffineXf.h:24