Banuba SDK
Loading...
Searching...
No Matches
bnb::transformation Class Reference

This class implements affine or perspective 2d transformations Standard usage implies transformation from common basis into other(common, image or standard) basis (e.g. More...

#include <transformation.hpp>

Inheritance diagram for bnb::transformation:
bnb::interfaces::transformation

Classes

struct  affine_coeffs_t
 

Public Types

enum class  rotate_t : uint32_t { deg_0 = 0 , deg_90 = 90 , deg_180 = 180 , deg_270 = 270 }
 Rotation is counter clockwise(only in standart basis): More...
 
using mat_t = std::array<float, mat_s * mat_s>
 3x3 row-maj transform matrix
 

Public Member Functions

 transformation ()
 Constructs identity transform.
 
 transformation (const mat_t &mat)
 Constructs from mat_t.
 
 transformation (mat_t::const_pointer mat)
 
 transformation (rotate_t rotate)
 Constructs rotate transformation.
 
 transformation (float scale_x, float scale_y=1.f, float t_x=0, float t_y=0, rotate_t rotate=rotate_t::deg_0, bool flip_x=false, bool flip_y=false)
 Constructs affine transformation.
 
 transformation (affine_coeffs_t coeffs)
 Constructs affine transformation.
 
 transformation (pixel_rect source_rect, pixel_rect target_rect, rotate_t rotate=rotate_t::deg_0, bool flip_x=false, bool flip_y=false)
 Constructs transformation from source to target rectangle Rotation and flips are around rectangles' center.
 
 transformation (transformation &&t) noexcept
 
transformationoperator= (transformation &&t) noexcept
 
 transformation (const transformation &t)
 
transformationoperator= (const transformation &t)
 
transformation operator>> (const transformation &t) const noexcept
 Applies transform t after this e.g.
 
point2d operator* (const point2d &point) const noexcept
 Apply transform to point.
 
bool operator== (const transformation &t) const noexcept
 
transformation inverse () const
 Get the inverse of the transformation.
 
transformation clone () const noexcept
 Clone the transformation.
 
mat_t::const_pointer data () const noexcept
 Pointer to matrix data in memory (row major)
 
mat_t get_mat () const noexcept
 Returns 3x3 row-maj transform matrix.
 
mat_t transposed_data () const noexcept
 Returns transposed matrix data (column major, opengl)
 
std::string to_string () const noexcept
 Cast to string for debug purposes.
 
bool is_affine () const noexcept
 Checks if last row is [0, 0, 1] up to float precision.
 
void normalize_affine () noexcept
 Normalizes transform to be exactly affine.
 
std::optional< transformation::affine_coeffs_textract_affine_coeffs () const
 Tries to extract affine coefficients from transformation.
 
std::shared_ptr< interfaces::transformationchain_right (const std::shared_ptr< interfaces::transformation > &t) const override
 
interfaces::point2d transform_point (const interfaces::point2d &p) const override
 Apply transform to point.
 
interfaces::pixel_rect transform_rect (const interfaces::pixel_rect &rect) const override
 
bool equals (const std::shared_ptr< interfaces::transformation > &t) const override
 
std::shared_ptr< interfaces::transformationinverse_j () const override
 Get the inverse of the transformation.
 
std::shared_ptr< interfaces::transformationclone_j () const override
 Clone the transformation.
 
std::vector< float > get_mat_j () const override
 Returns 3x3 row-maj transform matrix.
 
- Public Member Functions inherited from bnb::interfaces::transformation
virtual std::shared_ptr< transformationchain_right (const std::shared_ptr< transformation > &t) const =0
 Applies transform t after this e.g.
 
virtual bool equals (const std::shared_ptr< transformation > &t) const =0
 

Static Public Member Functions

static const transformationget_flip_instance (bool flip_x, bool flip_y)
 Get reference to static flip-only transform.
 
- Static Public Member Functions inherited from bnb::interfaces::transformation
static std::shared_ptr< transformationmake_identity ()
 Constructs identity transform.
 
static std::shared_ptr< transformationmake_data (const std::vector< float > &mat)
 Constructs from mat_t.
 
static std::shared_ptr< transformationmake_rot (rotation rot)
 Constructs rotate transformation.
 
static std::shared_ptr< transformationmake_affine (float scale_x, float scale_y, float t_x, float t_y, rotation rot, bool flip_x, bool flip_y)
 Constructs affine transformation.
 
static std::shared_ptr< transformationmake_rects (const pixel_rect &source_rect, const pixel_rect &target_rect, rotation rot, bool flip_x, bool flip_y)
 Constructs transformation from source to target rectangle Rotation and flips are around rectangles' center.
 

Static Public Attributes

static const int mat_s = 3
 

Detailed Description

This class implements affine or perspective 2d transformations Standard usage implies transformation from common basis into other(common, image or standard) basis (e.g.

written as (common -> image) in documentation)

Frequently used basises are: <f ^f >f vf: direction of face-up vector left, up, right, down

standard basis: ^ y | ^f .--> x

common basis = image(buffer) basis: .--> x | ^f v y

Definition at line 58 of file transformation.hpp.

Member Typedef Documentation

◆ mat_t

using bnb::transformation::mat_t = std::array<float, mat_s * mat_s>

3x3 row-maj transform matrix

Definition at line 64 of file transformation.hpp.

Member Enumeration Documentation

◆ rotate_t

enum class bnb::transformation::rotate_t : uint32_t
strong

Rotation is counter clockwise(only in standart basis):

  • Rotating vector(1,0) (= x basis vector) by 90deg results in vector(0,1) (= y basis vector)
  • In image buffer basis(y points down) the rotation would go clockwise

Definition at line 70 of file transformation.hpp.

71 {
72 deg_0 = 0,
73 deg_90 = 90,
74 deg_180 = 180,
75 deg_270 = 270
76 };

Constructor & Destructor Documentation

◆ ~transformation()

bnb::transformation::~transformation ( )
virtual

Reimplemented from bnb::interfaces::transformation.

Member Function Documentation

◆ chain_right()

std::shared_ptr< interfaces::transformation > bnb::transformation::chain_right ( const std::shared_ptr< interfaces::transformation > & t) const
inlineoverride

Definition at line 161 of file transformation.hpp.

162 {
163 return std::make_shared<transformation>(*this >> static_cast<transformation&>(*t));
164 }
transformation()
Constructs identity transform.

◆ clone_j()

std::shared_ptr< interfaces::transformation > bnb::transformation::clone_j ( ) const
inlineoverridevirtual

Clone the transformation.

Implements bnb::interfaces::transformation.

Definition at line 175 of file transformation.hpp.

176 {
177 return std::make_shared<transformation>(clone());
178 }
transformation clone() const noexcept
Clone the transformation.

◆ equals()

bool bnb::transformation::equals ( const std::shared_ptr< interfaces::transformation > & t) const
inlineoverride

Definition at line 167 of file transformation.hpp.

168 {
169 return *this == static_cast<transformation&>(*t);
170 }

◆ get_mat_j()

std::vector< float > bnb::transformation::get_mat_j ( ) const
inlineoverridevirtual

Returns 3x3 row-maj transform matrix.

Implements bnb::interfaces::transformation.

Definition at line 179 of file transformation.hpp.

180 {
181 auto m = get_mat();
182 return {m.begin(), m.end()};
183 }
mat_t get_mat() const noexcept
Returns 3x3 row-maj transform matrix.

◆ inverse()

transformation bnb::transformation::inverse ( ) const

Get the inverse of the transformation.

Exceptions
std::logic_errorwhen matrix is singular

◆ inverse_j()

std::shared_ptr< interfaces::transformation > bnb::transformation::inverse_j ( ) const
inlineoverridevirtual

Get the inverse of the transformation.

Exceptions
std::logic_errorwhen matrix is singular

Implements bnb::interfaces::transformation.

Definition at line 171 of file transformation.hpp.

172 {
173 return std::make_shared<transformation>(inverse());
174 }
transformation inverse() const
Get the inverse of the transformation.

◆ normalize_affine()

void bnb::transformation::normalize_affine ( )
noexcept

Normalizes transform to be exactly affine.

Results are invalid in case last row is not [~0, ~0, C]

◆ operator>>()

transformation bnb::transformation::operator>> ( const transformation & t) const
noexcept

Applies transform t after this e.g.

{rotate >> translate;} rotates first: (initial -> rotated) >> (rotated -> translated) = (initial -> translated)

Member Data Documentation

◆ mat_s

const int bnb::transformation::mat_s = 3
static

Definition at line 61 of file transformation.hpp.


The documentation for this class was generated from the following file: