CycloPos Header version 1.0.0
ToolTech Software · C++ library reference
Loading...
Searching...
No Matches
cyUtility.h
Go to the documentation of this file.
1//*****************************************************************************
2// File : cyUtility.h
3// Module : CycloPos
4// Description : Generic Utilities in 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_UTILITY_H__
21#define __CY_UTILITY_H__
22
27
28#include "cyBase.h"
29
31CY_EXPORT gzFloat getPixel(gzImage *image,const gzFloat &x,const gzFloat &y);
32
33inline gzVoid normalize(gzArray<gzFloat> &array)
34{
35 gzFloat mag(0);
36
37 gzFloat *p_data=array.getAddress();
38
39 gzInt32 i(array.getSize());
40
41 while(i)
42 {
43 mag+=gzSq2(*p_data);
44 ++p_data;
45 --i;
46 }
47
48 mag=1.0f/gzSqrt(mag);
49
50 p_data=array.getAddress();
51
52 i=array.getSize();
53
54 while(i)
55 {
56 *p_data*=mag;
57 ++p_data;
58 --i;
59 }
60}
61
62inline gzVoid bias(gzArray<gzFloat> &array,gzFloat bias)
63{
64 gzFloat *p_data=array.getAddress();
65
66 gzInt32 i(array.getSize());
67
68 while(i)
69 {
70 *p_data+=bias;
71 ++p_data;
72 --i;
73 }
74}
75
76inline gzFloatXY undistNormalized(gzFloatXY xdist,gzFloat xc,gzFloat yc,KVals k,gzBool taylor)
77{
78 // Distorted point with removed center BUT in normalized coordinates
79 // NORMALIZED !!!
80
81 gzFloat xd=xdist.x-xc;
82 gzFloat yd=xdist.y-yc;
83
84 gzFloat xu,yu;
85 gzFloat r=xd*xd+yd*yd;
86
87 if(taylor)
88 {
89 r=gzSqrt(r);
90
91 gzFloat dx=(1.0f + (k.k1 + (k.k2 + (k.k3 + (k.k4 + (k.k5 + k.k7 * r ) * r ) * r) * r) * r) * r);
92 gzFloat dy=(1.0f + k.k6*(k.k1 + (k.k2 + (k.k3 + (k.k4 + (k.k5 + k.k7 * r ) * r ) * r) * r) * r) * r);
93
94 xu=xd*dx;
95 yu=yd*dy;
96
97 }
98 else
99 {
100 gzFloat r2=r*r;
101 gzFloat r3=r*r2;
102 gzFloat r4=r2*r2;
103
104 xu=xd*(1+k.k1*r+k.k2*r2+k.k5*r3+k.k7*r4)+ 2*k.k3*xd*yd+k.k4*(r+2*xd*xd);
105 yu=yd*(1+k.k6*k.k1*r+k.k6*k.k2*r2+k.k6*k.k5*r3+k.k6*k.k7*r4)+ 2*k.k6*k.k4*xd*yd+k.k6*k.k3*(r+2*yd*yd);
106 }
107
108 // Add center
109 xu+=xc;
110 yu+=yc;
111
112 return gzFloatXY(xu,yu); // In normalised coordinates
113}
114
115
116#endif // __CY_UTILITY_H__
117
118
119
120
121
122
gzFloat k3
Definition cyBase.h:147
gzFloat k4
Definition cyBase.h:147
gzFloat k6
Definition cyBase.h:147
gzFloat k7
Definition cyBase.h:147
gzFloat k1
Definition cyBase.h:147
gzFloat k2
Definition cyBase.h:147
gzFloat k5
Definition cyBase.h:147
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
gzVoid bias(gzArray< gzFloat > &array, gzFloat bias)
Definition cyUtility.h:62
gzFloatXY undistNormalized(gzFloatXY xdist, gzFloat xc, gzFloat yc, KVals k, gzBool taylor)
Definition cyUtility.h:76
gzVoid normalize(gzArray< gzFloat > &array)
Definition cyUtility.h:33
gzFloat getPixel(gzImage *image, const gzFloat &x, const gzFloat &y)
Get gray scale intensity (0-1) at x,y from gzImage.