MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAffineXf.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMacros.h"
4#include "MRMeshFwd.h"
5#include <iosfwd>
6#include <type_traits>
7
8#if MR_COMPILING_ANY_BINDINGS
12#include "MRMatrix2.h"
13#include "MRMatrix3.h"
14#endif
15
16namespace MR
17{
20
21
24template <typename V>
26{
27 using T = typename V::ValueType;
28 using M = typename V::MatrixType;
29
31 V b;
32
33 constexpr AffineXf() noexcept = default;
34 constexpr AffineXf( const M & A, const V & b ) noexcept : A( A ), b( b ) { }
35
38 template <typename U> MR_REQUIRES_IF_SUPPORTED( !std::is_same_v<U, V> )
39 constexpr explicit AffineXf( const AffineXf<U> & xf ) noexcept : A( xf.A ), b( xf.b ) { }
40
42 [[nodiscard]] static constexpr AffineXf translation( const V & b ) noexcept { return AffineXf{ M{}, b }; }
44 [[nodiscard]] static constexpr AffineXf linear( const M & A ) noexcept { return AffineXf{ A, V{} }; }
46 [[nodiscard]] static constexpr AffineXf xfAround( const M & A, const V & stable ) noexcept { return AffineXf{ A, stable - A * stable }; }
47
49 [[nodiscard]] constexpr V operator() ( const V & x ) const noexcept { return A * x + b; }
52 [[nodiscard]] constexpr V linearOnly( const V & x ) const noexcept { return A * x; }
54 [[nodiscard]] constexpr AffineXf inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> );
55
58 friend AffineXf<V> operator * ( const AffineXf<V> & u, const AffineXf<V> & v )
59 { return { u.A * v.A, u.A * v.b + u.b }; }
60
62 friend bool operator == ( const AffineXf<V> & a, const AffineXf<V> & b )
63 {
64 return a.A == b.A && a.b == b.b;
65 }
66
68 friend bool operator != ( const AffineXf<V> & a, const AffineXf<V> & b )
69 {
70 return !( a == b );
71 }
72
73 friend std::ostream& operator<<( std::ostream& s, const AffineXf& xf )
74 {
75 return s << xf.A << xf.b;
76 }
77
78 friend std::istream& operator>>( std::istream& s, AffineXf& xf )
79 {
80 return s >> xf.A >> xf.b;
81 }
82};
83
86
87template <typename V>
88inline constexpr AffineXf<V> AffineXf<V>::inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> )
89{
90 AffineXf<V> res;
91 res.A = A.inverse();
92 res.b = -( res.A * b );
93 return res;
94}
95
97
98}
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:34
typename V::ValueType T
Definition MRAffineXf.h:27
friend bool operator!=(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRAffineXf.h:68
static constexpr AffineXf linear(const M &A) noexcept
creates linear-only transformation (without translation)
Definition MRAffineXf.h:44
static constexpr AffineXf xfAround(const M &A, const V &stable) noexcept
creates transformation with given linear part with given stable point
Definition MRAffineXf.h:46
friend bool operator==(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRAffineXf.h:62
constexpr V operator()(const V &x) const noexcept
application of the transformation to a point
Definition MRAffineXf.h:49
typename V::MatrixType M
Definition MRAffineXf.h:28
friend std::istream & operator>>(std::istream &s, AffineXf &xf)
Definition MRAffineXf.h:78
constexpr AffineXf() noexcept=default
V b
Definition MRAffineXf.h:31
M A
Definition MRAffineXf.h:30
MR_REQUIRES_IF_SUPPORTED(!std::is_same_v< U, V >) const expr explicit AffineXf(const AffineXf< U > &xf) noexcept
Definition MRAffineXf.h:38
static constexpr AffineXf translation(const V &b) noexcept
creates translation-only transformation (with identity linear component)
Definition MRAffineXf.h:42
constexpr V linearOnly(const V &x) const noexcept
Definition MRAffineXf.h:52
friend std::ostream & operator<<(std::ostream &s, const AffineXf &xf)
Definition MRAffineXf.h:73
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRAffineXf.h:26