174 lines
6.1 KiB
C
174 lines
6.1 KiB
C
#ifndef _BGC_AFFINE3_H_INCLUDED_
|
|
#define _BGC_AFFINE3_H_INCLUDED_
|
|
|
|
#include "vector3.h"
|
|
#include "matrixes.h"
|
|
#include "matrix3x3.h"
|
|
|
|
// ==================== Types ==================== //
|
|
|
|
typedef struct {
|
|
BgcMatrix3x3FP32 distortion;
|
|
BgcVector3FP32 shift;
|
|
} BgcAffine3FP32;
|
|
|
|
typedef struct {
|
|
BgcMatrix3x3FP64 distortion;
|
|
BgcVector3FP64 shift;
|
|
} BgcAffine3FP64;
|
|
|
|
// ==================== Reset ==================== //
|
|
|
|
inline void bgc_affine3_reset_fp32(BgcAffine3FP32 * affine)
|
|
{
|
|
bgc_matrix3x3_set_to_identity_fp32(&affine->distortion);
|
|
bgc_vector3_reset_fp32(&affine->shift);
|
|
}
|
|
|
|
inline void bgc_affine3_reset_fp64(BgcAffine3FP64 * affine)
|
|
{
|
|
bgc_matrix3x3_set_to_identity_fp64(&affine->distortion);
|
|
bgc_vector3_reset_fp64(&affine->shift);
|
|
}
|
|
|
|
// ==================== Make ===================== //
|
|
|
|
inline void bgc_affine3_make_fp32(const BgcMatrix3x3FP32 * distortion, const BgcVector3FP32 * shift, BgcAffine3FP32 * affine)
|
|
{
|
|
bgc_matrix3x3_copy_fp32(distortion, &affine->distortion);
|
|
bgc_vector3_copy_fp32(shift, &affine->shift);
|
|
}
|
|
|
|
inline void bgc_affine3_make_fp64(const BgcMatrix3x3FP64 * distortion, const BgcVector3FP64 * shift, BgcAffine3FP64 * affine)
|
|
{
|
|
bgc_matrix3x3_copy_fp64(distortion, &affine->distortion);
|
|
bgc_vector3_copy_fp64(shift, &affine->shift);
|
|
}
|
|
|
|
// ==================== Copy ===================== //
|
|
|
|
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)
|
|
{
|
|
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);
|
|
}
|
|
|
|
inline void bgc_affine3_combine_fp64(const BgcAffine3FP64 * parent, const BgcAffine3FP64 * child, BgcAffine3FP64 * combination)
|
|
{
|
|
BgcVector3FP64 child_shift;
|
|
bgc_matrix3x3_get_right_product_fp64(&parent->distortion, &child->shift, &child_shift);
|
|
bgc_matrix_product_3x3_at_3x3_fp64(&parent->distortion, &child->distortion, &combination->distortion);
|
|
bgc_vector3_add_fp64(&parent->shift, &child_shift, &combination->shift);
|
|
}
|
|
|
|
// =============== Transform Point =============== //
|
|
|
|
inline void bgc_affine3_transform_point_fp32(const BgcAffine3FP32 * affine, const BgcVector3FP32 * initial_point, BgcVector3FP32 * transformed_point)
|
|
{
|
|
BgcVector3FP32 distorted;
|
|
bgc_matrix3x3_get_right_product_fp32(&affine->distortion, initial_point, &distorted);
|
|
bgc_vector3_add_fp32(&affine->shift, &distorted, transformed_point);
|
|
}
|
|
|
|
inline void bgc_affine3_transform_point_fp64(const BgcAffine3FP64 * affine, const BgcVector3FP64 * initial_point, BgcVector3FP64 * transformed_point)
|
|
{
|
|
BgcVector3FP64 distorted;
|
|
bgc_matrix3x3_get_right_product_fp64(&affine->distortion, initial_point, &distorted);
|
|
bgc_vector3_add_fp64(&affine->shift, &distorted, transformed_point);
|
|
}
|
|
|
|
// ============== Transform Vector =============== //
|
|
|
|
inline void bgc_affine3_transform_vector_fp32(const BgcAffine3FP32 * affine, const BgcVector3FP32 * initial_vector, BgcVector3FP32 * transformed_vector)
|
|
{
|
|
bgc_matrix3x3_get_right_product_fp32(&affine->distortion, initial_vector, transformed_vector);
|
|
}
|
|
|
|
inline void bgc_affine3_transform_vector_fp64(const BgcAffine3FP64 * affine, const BgcVector3FP64 * initial_vector, BgcVector3FP64 * transformed_vector)
|
|
{
|
|
bgc_matrix3x3_get_right_product_fp64(&affine->distortion, initial_vector, transformed_vector);
|
|
}
|
|
|
|
#endif
|