CycloPos Header version 1.0.0
ToolTech Software · C++ library reference
Loading...
Searching...
No Matches
cyMath.h
Go to the documentation of this file.
1//*****************************************************************************
2// File : cyMath.h
3// Module : CycloPos
4// Description : Math utilities for the CycloPos library
5// Author : Anders Modén
6// Product : CycloPos 1.0.0
7//
8// Copyright © 2011- ToolTech Software, Sweden
9//
10// NOTE: CycloPos is a generic VR and Tool positioning library for a mono camera
11//
12//
13// Revision History...
14//
15// Who Date Description
16//
17// AMO 110901 Created file
18//
19//******************************************************************************
20#ifndef __CY_MATH_H__
21#define __CY_MATH_H__
22
23#include "cyBase.h" // Base
24#include "gzMathMatrix.h"
25
26// ------------------- Some utils -------------------------------
27
28CY_EXPORT gzMatrixf getRobustProjectionMatrix(const gzMatrixf &F, const gzMatrixf &K0,const gzMatrixf &K1,const gzVectorf &matchPointA_1,const gzVectorf &matchPointB_1,const gzVectorf &matchPointA_2,const gzVectorf &matchPointB_2,const gzVectorf &matchPointA_3,const gzVectorf &matchPointB_3,gzVectorf *point_1=NULL,gzVectorf *point_2=NULL,gzVectorf *point_3=NULL);
29CY_EXPORT gzBool updateKanataniProjection(const gzMatrixf &F , gzVectorf &x , gzVectorf &xp);
30CY_EXPORT gzBool decomposeProjectionMatrix(const gzMatrixf &matrix, gzVectorf &translation,gzFloat &H,gzFloat &P,gzFloat &R);
31CY_EXPORT gzBool decomposeRotationMatrix(const gzMatrixf &matrix, gzFloat &H,gzFloat &P,gzFloat &R);
32CY_EXPORT gzMatrixf composeProjectionMatrix(const gzVectorf &translation,const gzFloat &H,const gzFloat &P,const gzFloat &R);
33CY_EXPORT gzMatrixf composeProjectionMatrix(const gzVectorf &target,const gzVectorf &pos,const gzFloat &R);
34CY_EXPORT gzMatrixf composeRotationMatrix(const gzFloat &H,const gzFloat &P,const gzFloat &R);
35CY_EXPORT gzMatrixf composeKMatrix(const gzFloat &fx,const gzFloat &fy,const gzFloat &x0=0.0f,const gzFloat &y0=0.0f,const gzFloat &s=0.0f);
36CY_EXPORT gzMatrixf composeFMatrix(const gzMatrixf &K0,const gzMatrixf &K1,const gzMatrixf &R,const gzVectorf &t);
37
38CY_EXPORT const gzMatrixf & getDeterminantFlip4();
39CY_EXPORT const gzMatrixf & getZFlip4();
40CY_EXPORT const gzMatrixf & getDeterminantFlip3();
41
42// ------------------- Some math macros -------------------------
43
44inline gzFloat angle(const gzFloat & X, const gzFloat & Y)
45{
46 if(X >= 0 && Y >= 0)
47 return atanf(Y/X);
48
49 if(X < 0 && Y >= 0)
50 return GZ_PI_F - atanf(-Y/X);
51
52 if(X < 0 && Y < 0)
53 return GZ_PI_F + atanf(Y/X);
54
55 if(X >= 0 && Y < 0)
56 return GZ_2PI_F - atanf(-Y/X);
57
58 return GZ_FLOAT_ZERO;
59}
60
61
62inline gzFloat samson_distance_mag(gzVectorf &x,gzVectorf &xp,gzMatrixf &F)
63{
64 gzVectorf Fx=(F*x);
65
66 //Fx.unify();
67
68 gzFloat A=gzSq2(Fx.dot(xp));
69
70 gzFloat B=(F*x).trunc(2).magnitude()+(F.transpose()*xp).trunc(2).magnitude();
71
72 if(B!=0)
73 return (A/B);
74 else
75 return FLT_MAX;
76}
77
78inline gzFloat projected_distance_mag(gzVectorf &x,gzVectorf &xp,gzMatrixf &F)
79{
80 gzMatrixf M,A;
81
82 F.decomposeSVD(&M);
83
84 // Create one valid Pp
85 gzVectorf ep=M.getCol(2);
86
87 // Canonical camera
88
89 gzMatrixf Pp=ep.scew()*F;
90 Pp.addCol(ep);
91
92 A.addRow(gzVectorf(-1,0,x[0],0));
93 A.addRow(gzVectorf(0,-1,x[1],0));
94 A.addRow(xp[0]*Pp.getRow(2)-Pp.getRow(0));
95 A.addRow(xp[1]*Pp.getRow(2)-Pp.getRow(1));
96
97 A.decomposeSVD(NULL,&M);
98
99 gzVectorf X=M.getRow(3); // Best initial guess for X
100
101 gzVectorf xc=X.unified().unified();
102 gzVectorf xpc=(Pp*X).unified();
103
104 // Error in projection
105 if(x.getSize()==3)
106 return (xc-x.unified()).magnitude()+(xpc-xp.unified()).magnitude();
107 else
108 return (xc-x).magnitude()+(xpc-xp).magnitude();
109}
110
111
112#endif // __CY_MATH_H__
Basic include for all CycloPos files. Defines export structures and basic flags and builtin compiled ...
#define CY_EXPORT
Export control of dll functions.
Definition cyBase.h:50
const gzMatrixf & getZFlip4()
gzFloat samson_distance_mag(gzVectorf &x, gzVectorf &xp, gzMatrixf &F)
Definition cyMath.h:62
const gzMatrixf & getDeterminantFlip4()
gzMatrixf composeFMatrix(const gzMatrixf &K0, const gzMatrixf &K1, const gzMatrixf &R, const gzVectorf &t)
gzFloat angle(const gzFloat &X, const gzFloat &Y)
Definition cyMath.h:44
gzBool decomposeProjectionMatrix(const gzMatrixf &matrix, gzVectorf &translation, gzFloat &H, gzFloat &P, gzFloat &R)
gzFloat projected_distance_mag(gzVectorf &x, gzVectorf &xp, gzMatrixf &F)
Definition cyMath.h:78
gzMatrixf getRobustProjectionMatrix(const gzMatrixf &F, const gzMatrixf &K0, const gzMatrixf &K1, const gzVectorf &matchPointA_1, const gzVectorf &matchPointB_1, const gzVectorf &matchPointA_2, const gzVectorf &matchPointB_2, const gzVectorf &matchPointA_3, const gzVectorf &matchPointB_3, gzVectorf *point_1=NULL, gzVectorf *point_2=NULL, gzVectorf *point_3=NULL)
const gzMatrixf & getDeterminantFlip3()
gzMatrixf composeProjectionMatrix(const gzVectorf &translation, const gzFloat &H, const gzFloat &P, const gzFloat &R)
gzBool updateKanataniProjection(const gzMatrixf &F, gzVectorf &x, gzVectorf &xp)
gzMatrixf composeRotationMatrix(const gzFloat &H, const gzFloat &P, const gzFloat &R)
gzMatrixf composeKMatrix(const gzFloat &fx, const gzFloat &fy, const gzFloat &x0=0.0f, const gzFloat &y0=0.0f, const gzFloat &s=0.0f)
gzBool decomposeRotationMatrix(const gzMatrixf &matrix, gzFloat &H, gzFloat &P, gzFloat &R)