MeshLib C++ Docs
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 <iosfwd>
6#include <type_traits>
7
8#if MR_COMPILING_ANY_BINDINGS
9// In C: Include the headers for the matrices that are otherwise missing in the C bindings.
10// I'm not sure how the binding generator could possibly guess that it needs to include those.
11// In Python: Need those headers to generate the implementation for `operator<<` and `operator>>`, which call into the same operators of matrices.
12#include "MRMatrix2.h"
13#include "MRMatrix3.h"
14#endif
15
16namespace MR
17{
18
21template <typename V>
23{
24 using T = typename V::ValueType;
25 using M = typename V::MatrixType;
26
28 V b;
29
30 constexpr AffineXf() noexcept = default;
31 constexpr AffineXf( const M & A, const V & b ) noexcept : A( A ), b( b ) { }
32
33 // Here `U == V` doesn't seem to cause any issues in the C++ code, but we're still disabling it because it somehow gets emitted
34 // when generating the bindings, and results in duplicate functions in C#.
35 template <typename U> MR_REQUIRES_IF_SUPPORTED( !std::is_same_v<U, V> )
36 constexpr explicit AffineXf( const AffineXf<U> & xf ) noexcept : A( xf.A ), b( xf.b ) { }
37
39 [[nodiscard]] static constexpr AffineXf translation( const V & b ) noexcept { return AffineXf{ M{}, b }; }
41 [[nodiscard]] static constexpr AffineXf linear( const M & A ) noexcept { return AffineXf{ A, V{} }; }
43 [[nodiscard]] static constexpr AffineXf xfAround( const M & A, const V & stable ) noexcept { return AffineXf{ A, stable - A * stable }; }
44
46 [[nodiscard]] constexpr V operator() ( const V & x ) const noexcept { return A * x + b; }
49 [[nodiscard]] constexpr V linearOnly( const V & x ) const noexcept { return A * x; }
51 [[nodiscard]] constexpr AffineXf inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> );
52
55 friend AffineXf<V> operator * ( const AffineXf<V> & u, const AffineXf<V> & v )
56 { return { u.A * v.A, u.A * v.b + u.b }; }
57
59 friend bool operator == ( const AffineXf<V> & a, const AffineXf<V> & b )
60 {
61 return a.A == b.A && a.b == b.b;
62 }
63
65 friend bool operator != ( const AffineXf<V> & a, const AffineXf<V> & b )
66 {
67 return !( a == b );
68 }
69
70 friend std::ostream& operator<<( std::ostream& s, const AffineXf& xf )
71 {
72 return s << xf.A << xf.b;
73 }
74
75 friend std::istream& operator>>( std::istream& s, AffineXf& xf )
76 {
77 return s >> xf.A >> xf.b;
78 }
79};
80
83
84template <typename V>
85inline constexpr AffineXf<V> AffineXf<V>::inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> )
86{
87 AffineXf<V> res;
88 res.A = A.inverse();
89 res.b = -( res.A * b );
90 return res;
91}
92
94
95} // namespace MR
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:34
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRAffineXf.h:23
typename V::ValueType T
Definition MRMesh/MRAffineXf.h:24
friend bool operator!=(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRMesh/MRAffineXf.h:65
static constexpr AffineXf linear(const M &A) noexcept
creates linear-only transformation (without translation)
Definition MRMesh/MRAffineXf.h:41
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:43
friend bool operator==(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRMesh/MRAffineXf.h:59
constexpr V operator()(const V &x) const noexcept
application of the transformation to a point
Definition MRMesh/MRAffineXf.h:46
typename V::MatrixType M
Definition MRMesh/MRAffineXf.h:25
friend std::istream & operator>>(std::istream &s, AffineXf &xf)
Definition MRMesh/MRAffineXf.h:75
constexpr AffineXf() noexcept=default
V b
Definition MRMesh/MRAffineXf.h:28
M A
Definition MRMesh/MRAffineXf.h:27
MR_REQUIRES_IF_SUPPORTED(!std::is_same_v< U, V >) const expr explicit AffineXf(const AffineXf< U > &xf) noexcept
Definition MRMesh/MRAffineXf.h:35
static constexpr AffineXf translation(const V &b) noexcept
creates translation-only transformation (with identity linear component)
Definition MRMesh/MRAffineXf.h:39
constexpr V linearOnly(const V &x) const noexcept
Definition MRMesh/MRAffineXf.h:49
friend std::ostream & operator<<(std::ostream &s, const AffineXf &xf)
Definition MRMesh/MRAffineXf.h:70