Добавлеие позиционирования и аффинного преобразования для 2-мерного пространства, добавление функций для аффинных преобразований и позиционирования
This commit is contained in:
parent
3c2b89f369
commit
101df9f089
12 changed files with 734 additions and 322 deletions
|
|
@ -42,6 +42,10 @@
|
|||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="affine3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="affine3.h" />
|
||||
<Unit filename="main.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
|||
28
basic-geometry/affine2.c
Normal file
28
basic-geometry/affine2.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "affine2.h"
|
||||
|
||||
extern inline void bgc_affine2_reset_fp32(BgcAffine2FP32 * affine);
|
||||
extern inline void bgc_affine2_reset_fp64(BgcAffine2FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine2_make_fp32(const BgcMatrix2x2FP32 * distortion, const BgcVector2FP32 * shift, BgcAffine2FP32 * affine);
|
||||
extern inline void bgc_affine2_make_fp64(const BgcMatrix2x2FP64 * distortion, const BgcVector2FP64 * shift, BgcAffine2FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine2_copy_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination);
|
||||
extern inline void bgc_affine2_copy_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine2_convert_fp64_to_fp32(const BgcAffine2FP64 * source, BgcAffine2FP32 * destination);
|
||||
extern inline void bgc_affine2_convert_fp32_to_fp64(const BgcAffine2FP32 * source, BgcAffine2FP64 * destination);
|
||||
|
||||
extern inline int bgc_affine2_invert_fp32(BgcAffine2FP32 * affine);
|
||||
extern inline int bgc_affine2_invert_fp64(BgcAffine2FP64 * affine);
|
||||
|
||||
extern inline int bgc_affine2_get_inverse_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination);
|
||||
extern inline int bgc_affine2_get_inverse_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine2_combine_fp32(const BgcAffine2FP32 * parent, const BgcAffine2FP32 * child, BgcAffine2FP32 * combination);
|
||||
extern inline void bgc_affine2_combine_fp64(const BgcAffine2FP64 * parent, const BgcAffine2FP64 * child, BgcAffine2FP64 * combination);
|
||||
|
||||
extern inline void bgc_affine2_transform_point_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_point, BgcVector2FP32 * transformed_point);
|
||||
extern inline void bgc_affine2_transform_point_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_point, BgcVector2FP64 * transformed_point);
|
||||
|
||||
extern inline void bgc_affine2_transform_vector_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_vector, BgcVector2FP32 * transformed_vector);
|
||||
extern inline void bgc_affine2_transform_vector_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_vector, BgcVector2FP64 * transformed_vector);
|
||||
175
basic-geometry/affine2.h
Normal file
175
basic-geometry/affine2.h
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
#ifndef _BGC_AFFINE2_H_INCLUDED_
|
||||
#define _BGC_AFFINE2_H_INCLUDED_
|
||||
|
||||
#include "vector2.h"
|
||||
#include "matrixes.h"
|
||||
#include "matrix2x2.h"
|
||||
|
||||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BgcMatrix2x2FP32 distortion;
|
||||
BgcVector2FP32 shift;
|
||||
} BgcAffine2FP32;
|
||||
|
||||
typedef struct {
|
||||
BgcMatrix2x2FP64 distortion;
|
||||
BgcVector2FP64 shift;
|
||||
} BgcAffine2FP64;
|
||||
|
||||
// ==================== Reset ==================== //
|
||||
|
||||
inline void bgc_affine2_reset_fp32(BgcAffine2FP32 * affine)
|
||||
{
|
||||
bgc_matrix2x2_set_to_identity_fp32(&affine->distortion);
|
||||
bgc_vector2_reset_fp32(&affine->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_reset_fp64(BgcAffine2FP64 * affine)
|
||||
{
|
||||
bgc_matrix2x2_set_to_identity_fp64(&affine->distortion);
|
||||
bgc_vector2_reset_fp64(&affine->shift);
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_affine2_make_fp32(const BgcMatrix2x2FP32 * distortion, const BgcVector2FP32 * shift, BgcAffine2FP32 * affine)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp32(distortion, &affine->distortion);
|
||||
bgc_vector2_copy_fp32(shift, &affine->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_make_fp64(const BgcMatrix2x2FP64 * distortion, const BgcVector2FP64 * shift, BgcAffine2FP64 * affine)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp64(distortion, &affine->distortion);
|
||||
bgc_vector2_copy_fp64(shift, &affine->shift);
|
||||
}
|
||||
|
||||
|
||||
// ==================== Copy ===================== //
|
||||
|
||||
inline void bgc_affine2_copy_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_copy_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_copy_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_copy_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Convert =================== //
|
||||
|
||||
inline void bgc_affine2_convert_fp64_to_fp32(const BgcAffine2FP64 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
bgc_matrix2x2_convert_fp64_to_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_convert_fp64_to_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_convert_fp32_to_fp64(const BgcAffine2FP32 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
bgc_matrix2x2_convert_fp32_to_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_convert_fp32_to_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline int bgc_affine2_invert_fp32(BgcAffine2FP32 * affine)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp32(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector2_make_opposite_fp32(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine2_invert_fp64(BgcAffine2FP64 * affine)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp64(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector2_make_opposite_fp64(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline int bgc_affine2_get_inverse_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp32(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp32(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector2_make_opposite_fp32(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine2_get_inverse_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp64(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp64(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector2_make_opposite_fp64(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
||||
inline void bgc_affine2_combine_fp32(const BgcAffine2FP32 * parent, const BgcAffine2FP32 * child, BgcAffine2FP32 * combination)
|
||||
{
|
||||
BgcVector2FP32 child_shift;
|
||||
bgc_matrix2x2_get_right_product_fp32(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_2x2_at_2x2_fp32(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector2_add_fp32(&parent->shift, &child_shift, &combination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_combine_fp64(const BgcAffine2FP64 * parent, const BgcAffine2FP64 * child, BgcAffine2FP64 * combination)
|
||||
{
|
||||
BgcVector2FP64 child_shift;
|
||||
bgc_matrix2x2_get_right_product_fp64(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_2x2_at_2x2_fp64(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector2_add_fp64(&parent->shift, &child_shift, &combination->shift);
|
||||
}
|
||||
|
||||
// =============== Transform Point =============== //
|
||||
|
||||
inline void bgc_affine2_transform_point_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_point, BgcVector2FP32 * transformed_point)
|
||||
{
|
||||
BgcVector2FP32 distorted;
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector2_add_fp32(&affine->shift, &distorted, transformed_point);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_transform_point_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_point, BgcVector2FP64 * transformed_point)
|
||||
{
|
||||
BgcVector2FP64 distorted;
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector2_add_fp64(&affine->shift, &distorted, transformed_point);
|
||||
}
|
||||
|
||||
// ============== Transform Vector =============== //
|
||||
|
||||
inline void bgc_affine2_transform_vector_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_vector, BgcVector2FP32 * transformed_vector)
|
||||
{
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, initial_vector, transformed_vector);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_transform_vector_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_vector, BgcVector2FP64 * transformed_vector)
|
||||
{
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, initial_vector, transformed_vector);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -3,15 +3,21 @@
|
|||
extern inline void bgc_affine3_reset_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_reset_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_reset_distortion_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_reset_distortion_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_reset_shift_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_reset_shift_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_make_fp32(const BgcMatrix3x3FP32 * distortion, const BgcVector3FP32 * shift, BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_make_fp64(const BgcMatrix3x3FP64 * distortion, const BgcVector3FP64 * shift, BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_copy_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination);
|
||||
extern inline void bgc_affine3_copy_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine3_convert_fp64_to_fp32(const BgcAffine3FP64 * source, BgcAffine3FP32 * destination);
|
||||
extern inline void bgc_affine3_convert_fp32_to_fp64(const BgcAffine3FP32 * source, BgcAffine3FP64 * destination);
|
||||
|
||||
extern inline int bgc_affine3_invert_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline int bgc_affine3_invert_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline int bgc_affine3_get_inverse_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination);
|
||||
extern inline int bgc_affine3_get_inverse_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine3_combine_fp32(const BgcAffine3FP32 * parent, const BgcAffine3FP32 * child, BgcAffine3FP32 * combination);
|
||||
extern inline void bgc_affine3_combine_fp64(const BgcAffine3FP64 * parent, const BgcAffine3FP64 * child, BgcAffine3FP64 * combination);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef _BGC_AFFINE3_H_INCLUDED_
|
||||
#define _BGC_AFFINE3_H_INCLUDED_
|
||||
|
||||
#include "utilities.h"
|
||||
#include "vector3.h"
|
||||
#include "matrixes.h"
|
||||
#include "matrix3x3.h"
|
||||
|
|
@ -9,333 +8,167 @@
|
|||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcMatrix3x3FP32 distortion;
|
||||
BgcVector3FP32 shift;
|
||||
#else
|
||||
float r1c1, r1c2, r1c3, shift1;
|
||||
float r2c1, r2c2, r2c3, shift2;
|
||||
float r3c1, r3c2, r3c3, shift3;
|
||||
#endif
|
||||
} BgcAffine3FP32;
|
||||
|
||||
typedef struct {
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcMatrix3x3FP64 distortion;
|
||||
BgcVector3FP64 shift;
|
||||
#else
|
||||
double r1c1, r1c2, r1c3, shift1;
|
||||
double r2c1, r2c2, r2c3, shift2;
|
||||
double r3c1, r3c2, r3c3, shift3;
|
||||
#endif
|
||||
} BgcAffine3FP64;
|
||||
|
||||
// ==================== Reset ==================== //
|
||||
|
||||
inline void bgc_affine3_reset_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp32(&affine->distortion);
|
||||
bgc_vector3_reset_fp32(&affine->shift);
|
||||
#else
|
||||
affine->r1c1 = 1.0f;
|
||||
affine->r1c2 = 0.0f;
|
||||
affine->r1c3 = 0.0f;
|
||||
affine->shift1 = 0.0f;
|
||||
|
||||
affine->r2c1 = 0.0f;
|
||||
affine->r2c2 = 1.0f;
|
||||
affine->r2c3 = 0.0f;
|
||||
affine->shift2 = 0.0f;
|
||||
|
||||
affine->r3c1 = 0.0f;
|
||||
affine->r3c2 = 0.0f;
|
||||
affine->r3c3 = 1.0f;
|
||||
affine->shift3 = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp64(&affine->distortion);
|
||||
bgc_vector3_reset_fp64(&affine->shift);
|
||||
#else
|
||||
affine->r1c1 = 1.0;
|
||||
affine->r1c2 = 0.0;
|
||||
affine->r1c3 = 0.0;
|
||||
affine->shift1 = 0.0;
|
||||
|
||||
affine->r2c1 = 0.0;
|
||||
affine->r2c2 = 1.0;
|
||||
affine->r2c3 = 0.0;
|
||||
affine->shift2 = 0.0;
|
||||
|
||||
affine->r3c1 = 0.0;
|
||||
affine->r3c2 = 0.0;
|
||||
affine->r3c3 = 1.0;
|
||||
affine->shift3 = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_distortion_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp32(&affine->distortion);
|
||||
#else
|
||||
affine->r1c1 = 1.0f;
|
||||
affine->r1c2 = 0.0f;
|
||||
affine->r1c3 = 0.0f;
|
||||
|
||||
affine->r2c1 = 0.0f;
|
||||
affine->r2c2 = 1.0f;
|
||||
affine->r2c3 = 0.0f;
|
||||
|
||||
affine->r3c1 = 0.0f;
|
||||
affine->r3c2 = 0.0f;
|
||||
affine->r3c3 = 1.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_distortion_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp64(&affine->distortion);
|
||||
#else
|
||||
affine->r1c1 = 1.0;
|
||||
affine->r1c2 = 0.0;
|
||||
affine->r1c3 = 0.0;
|
||||
|
||||
affine->r2c1 = 0.0;
|
||||
affine->r2c2 = 1.0;
|
||||
affine->r2c3 = 0.0;
|
||||
|
||||
affine->r3c1 = 0.0;
|
||||
affine->r3c2 = 0.0;
|
||||
affine->r3c3 = 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_shift_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_vector3_reset_fp32(&affine->shift);
|
||||
#else
|
||||
affine->shift1 = 0.0f;
|
||||
affine->shift2 = 0.0f;
|
||||
affine->shift3 = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_shift_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_vector3_reset_fp64(&affine->shift);
|
||||
#else
|
||||
affine->shift1 = 0.0;
|
||||
affine->shift2 = 0.0;
|
||||
affine->shift3 = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_affine3_make_fp32(const BgcMatrix3x3FP32 * distortion, const BgcVector3FP32 * shift, BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_copy_fp32(distortion, &affine->distortion);
|
||||
bgc_vector3_copy_fp32(shift, &affine->shift);
|
||||
#else
|
||||
affine->r1c1 = distortion->r1c1;
|
||||
affine->r1c2 = distortion->r1c2;
|
||||
affine->r1c3 = distortion->r1c3;
|
||||
affine->shift1 = shift->x1;
|
||||
|
||||
affine->r2c1 = distortion->r2c1;
|
||||
affine->r2c2 = distortion->r2c2;
|
||||
affine->r2c3 = distortion->r2c3;
|
||||
affine->shift2 = shift->x2;
|
||||
|
||||
affine->r3c1 = distortion->r3c1;
|
||||
affine->r3c2 = distortion->r3c2;
|
||||
affine->r3c3 = distortion->r3c3;
|
||||
affine->shift3 = shift->x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_make_fp64(const BgcMatrix3x3FP64 * distortion, const BgcVector3FP64 * shift, BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_copy_fp64(distortion, &affine->distortion);
|
||||
bgc_vector3_copy_fp64(shift, &affine->shift);
|
||||
#else
|
||||
affine->r1c1 = distortion->r1c1;
|
||||
affine->r1c2 = distortion->r1c2;
|
||||
affine->r1c3 = distortion->r1c3;
|
||||
affine->shift1 = shift->x1;
|
||||
}
|
||||
|
||||
affine->r2c1 = distortion->r2c1;
|
||||
affine->r2c2 = distortion->r2c2;
|
||||
affine->r2c3 = distortion->r2c3;
|
||||
affine->shift2 = shift->x2;
|
||||
// ==================== Copy ===================== //
|
||||
|
||||
affine->r3c1 = distortion->r3c1;
|
||||
affine->r3c2 = distortion->r3c2;
|
||||
affine->r3c3 = distortion->r3c3;
|
||||
affine->shift3 = shift->x3;
|
||||
#endif
|
||||
inline void bgc_affine3_copy_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination)
|
||||
{
|
||||
bgc_matrix3x3_copy_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_copy_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine3_copy_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination)
|
||||
{
|
||||
bgc_matrix3x3_copy_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_copy_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Convert =================== //
|
||||
|
||||
inline void bgc_affine3_convert_fp64_to_fp32(const BgcAffine3FP64 * source, BgcAffine3FP32 * destination)
|
||||
{
|
||||
bgc_matrix3x3_convert_fp64_to_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_convert_fp64_to_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine3_convert_fp32_to_fp64(const BgcAffine3FP32 * source, BgcAffine3FP64 * destination)
|
||||
{
|
||||
bgc_matrix3x3_convert_fp32_to_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_convert_fp32_to_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline int bgc_affine3_invert_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp32(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp32(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector3_make_opposite_fp32(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine3_invert_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp64(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp64(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector3_make_opposite_fp64(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline int bgc_affine3_get_inverse_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp32(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp32(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector3_make_opposite_fp32(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine3_get_inverse_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp64(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp64(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector3_make_opposite_fp64(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
||||
inline void bgc_affine3_combine_fp32(const BgcAffine3FP32 * parent, const BgcAffine3FP32 * child, BgcAffine3FP32 * combination)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcVector3FP32 child_shift;
|
||||
bgc_matrix3x3_get_right_product_fp32(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_3x3_at_3x3_fp32(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector3_add_fp32(&parent->shift, &child_shift, &combination->shift);
|
||||
#else
|
||||
const float r1c1 = parent->r1c1 * child->r1c1 + parent->r1c2 * child->r2c1 + parent->r1c3 * child->r3c1;
|
||||
const float r1c2 = parent->r1c1 * child->r1c2 + parent->r1c2 * child->r2c2 + parent->r1c3 * child->r3c2;
|
||||
const float r1c3 = parent->r1c1 * child->r1c3 + parent->r1c2 * child->r2c3 + parent->r1c3 * child->r3c3;
|
||||
|
||||
const float r2c1 = parent->r2c1 * child->r1c1 + parent->r2c2 * child->r2c1 + parent->r2c3 * child->r3c1;
|
||||