Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
ITABase
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Institute of Technical Acoustics (ITA)
ITABase
Commits
01a43cb1
Commit
01a43cb1
authored
Dec 06, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing some warnings and preventing division by integer
parent
3bfe86ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
87 deletions
+77
-87
include/ITANumericUtils.h
include/ITANumericUtils.h
+28
-37
src/ITANumericUtils.cpp
src/ITANumericUtils.cpp
+49
-50
No files found.
include/ITANumericUtils.h
View file @
01a43cb1
...
...
@@ -324,27 +324,21 @@ ITA_BASE_API float anglef_mindiff_0_360_DEG( const float alpha, const float beta
ITA_BASE_API
float
anglef_mindiff_abs_0_360_DEG
(
const
float
alpha
,
const
float
beta
);
// Orientierung in Yaw-Pitch-Roll Winkeln in View-Up-Vektor umrechnen (Alle Winkel in Bogenmaß)
ITA_BASE_API
void
convertYPR2VU
(
const
double
yaw
,
const
double
pitch
,
const
double
roll
,
double
&
vx
,
double
&
vy
,
double
&
vz
,
double
&
ux
,
double
&
uy
,
double
&
uz
);
//! Orientierung in Yaw-Pitch-Roll Winkeln in View-Up-Vektor umrechnen (Alle Winkel in Bogenmaß)
ITA_BASE_API
void
convertYPR2VU
(
const
double
yaw
,
const
double
pitch
,
const
double
roll
,
double
&
vx
,
double
&
vy
,
double
&
vz
,
double
&
ux
,
double
&
uy
,
double
&
uz
);
// Orientierung in Yaw-Pitch-Roll Winkeln in View-Up-Vektor umrechnen (Alle Winkel in Bogenmaß)
ITA_BASE_API
void
convertYPR2VU
(
const
float
yaw
,
const
float
pitch
,
const
float
roll
,
float
&
vx
,
float
&
vy
,
float
&
vz
,
float
&
ux
,
float
&
uy
,
float
&
uz
);
//! Orientierung in Yaw-Pitch-Roll Winkeln in View-Up-Vektor umrechnen (Alle Winkel in Bogenmaß)
ITA_BASE_API
void
convertYPR2VU
(
const
float
yaw
,
const
float
pitch
,
const
float
roll
,
float
&
vx
,
float
&
vy
,
float
&
vz
,
float
&
ux
,
float
&
uy
,
float
&
uz
);
// Orientierung in View-Up-Vektor in Yaw-Pitch-Roll Winkeln umrechnen (Alle Winkel in Bogenmaß)
ITA_BASE_API
void
convertVU2YPR
(
const
double
vx
,
const
double
vy
,
const
double
vz
,
const
double
ux
,
const
double
uy
,
const
double
uz
,
double
&
yaw
,
double
&
pitch
,
double
&
roll
);
// Orientierung in View-Up-Vektor in Yaw-Pitch-Roll Winkeln umrechnen (Alle Winkel in Bogenmaß)
ITA_BASE_API
void
convertVU2YPR
(
const
float
vx
,
const
float
vy
,
const
float
vz
,
const
float
ux
,
const
float
uy
,
const
float
uz
,
float
&
yaw
,
float
&
pitch
,
float
&
roll
);
//! Orientierung in View-Up-Vektor in Yaw-Pitch-Roll Winkeln umrechnen (Alle Winkel in Bogenmaß)
ITA_BASE_API
void
convertVU2YPR
(
const
float
vx
,
const
float
vy
,
const
float
vz
,
const
float
ux
,
const
float
uy
,
const
float
uz
,
float
&
yaw
,
float
&
pitch
,
float
&
roll
);
// Datenklasse für Fehlerwerte
//
!
Datenklasse für Fehlerwerte
template
<
typename
T
>
class
ITA_BASE_API
ErrorValues
{
...
...
@@ -363,7 +357,7 @@ public:
{};
};
// Fehler zwischen zwei Vektoren berechnen
//
!
Fehler zwischen zwei Vektoren berechnen
template
<
typename
Tc
,
typename
Ta
,
typename
Tb
>
inline
ErrorValues
<
Tc
>
computeErrorValues
(
const
Ta
*
A
,
const
Tb
*
B
,
const
int
size
)
{
...
...
@@ -391,13 +385,8 @@ inline ErrorValues<Tc> computeErrorValues( const Ta* A, const Tb* B, const int s
return
v
;
};
/* +-----------------------+
| |
| Listen und Folgen |
| |
+-----------------------+ */
// Fills a vector with numbers dest = { a+n*s < b | n in N }
//
!
Fills a vector with numbers dest = { a+n*s < b | n in N }
template
<
typename
T
>
inline
void
linspace
(
std
::
vector
<
T
>&
dest
,
T
a
,
T
b
,
T
s
=
1
)
{
dest
.
clear
();
...
...
@@ -425,38 +414,40 @@ template< typename T > inline void linspace( std::vector< T >& dest, T a, T b, T
}
};
// Fills a vector with powers of two in the range a=2^i <= 2^j <= 2^k=b
// (Note a and b must be powers of two, otherwise an exception is thrown)
//! Fills a vector with powers of two in the range a=2^i <= 2^j <= 2^k=b
/**
* @note a and b must be powers of two, otherwise an exception is thrown)
*/
ITA_BASE_API
void
pow2space
(
std
::
vector
<
int
>&
dest
,
const
int
a
,
const
int
b
);
//
r
eturns the elevation angle (0 = frontal direction) in radians from a polar angle theta (0 = above)
ITA_BASE_API
double
theta2elevation
(
const
double
dThetaRAD
);
//
! R
eturns the elevation angle (0 = frontal direction) in radians from a polar angle theta (0 = above)
ITA_BASE_API
double
theta2elevation
(
const
double
dThetaRAD
);
// returns the polar angle theta (0 = above) in radians from a given elevation angle (0 = frontal direction)
ITA_BASE_API
double
elevation2theta
(
const
double
dElevationRAD
);
//
!
returns the polar angle theta (0 = above) in radians from a given elevation angle (0 = frontal direction)
ITA_BASE_API
double
elevation2theta
(
const
double
dElevationRAD
);
// Calculates the factorial of an positive integer m
ITA_BASE_API
int
factorial
(
const
int
m
);
//Calculates the normalizing constant for SHRealvaluedBasefunctions
//
!
Calculates the normalizing constant for SHRealvaluedBasefunctions
ITA_BASE_API
double
SHNormalizeConst
(
const
int
m
,
const
int
n
);
//Calculates the Kronecker delta
//
!
Calculates the Kronecker delta
ITA_BASE_API
int
SHKronecker
(
const
int
m
);
// Returns the linear index of a basefunction with degree m and order n, linear indexing starts with 0
//
!
Returns the linear index of a basefunction with degree m and order n, linear indexing starts with 0
ITA_BASE_API
int
SHDegreeOrder2Linear
(
const
int
m
,
const
int
n
);
// Returns degree and order of a basefunctions from a linear index, linear indexing starts with 0
ITA_BASE_API
void
SHLinear2DegreeOrder
(
const
int
iLinear
,
int
&
m
,
int
&
n
);
//
!
Returns degree and order of a basefunctions from a linear index, linear indexing starts with 0
ITA_BASE_API
void
SHLinear2DegreeOrder
(
const
int
iLinear
,
int
&
m
,
int
&
n
);
// Calculates the remax weightings up to a given order
ITA_BASE_API
std
::
vector
<
double
>
HOARemaxWeights
(
int
iTruncationOrder
);
//
!
Calculates the remax weightings up to a given order
ITA_BASE_API
std
::
vector
<
double
>
HOARemaxWeights
(
int
iTruncationOrder
);
//Calculates the realvalued Basefunctions of SH for e.g. Ambisonics
ITA_BASE_API
std
::
vector
<
double
>
SHRealvaluedBasefunctions
(
const
double
thetaRAD
,
const
double
azimuthRAD
,
const
int
maxOrder
);
//
!
Calculates the realvalued Basefunctions of SH for e.g. Ambisonics
ITA_BASE_API
std
::
vector
<
double
>
SHRealvaluedBasefunctions
(
const
double
thetaRAD
,
const
double
azimuthRAD
,
const
int
maxOrder
);
//Calculates the associated legendre polynomials
ITA_BASE_API
std
::
vector
<
double
>
SHAssociatedLegendre
(
const
int
N
,
const
double
mu
);
//
!
Calculates the associated legendre polynomials
ITA_BASE_API
std
::
vector
<
double
>
SHAssociatedLegendre
(
const
int
N
,
const
double
mu
);
#endif // INCLUDE_WATCHER_ITA_NUMERIC_UTILS
src/ITANumericUtils.cpp
View file @
01a43cb1
...
...
@@ -83,12 +83,12 @@ int uprmul( const int x, const int mul )
return
(
r
==
0
?
x
:
(
x
>
0
?
x
+
mul
-
r
:
x
-
r
)
);
}
unsigned
int
lwrmulu
(
const
unsigned
int
x
,
const
unsigned
int
mul
)
unsigned
int
lwrmulu
(
const
unsigned
int
x
,
const
unsigned
int
mul
)
{
return
x
-
(
x
%
mul
);
}
unsigned
int
uprmulu
(
const
unsigned
int
x
,
const
unsigned
int
mul
)
unsigned
int
uprmulu
(
const
unsigned
int
x
,
const
unsigned
int
mul
)
{
unsigned
int
r
=
x
%
mul
;
// Teilungsrest
return
(
r
==
0
?
x
:
x
+
mul
-
r
);
...
...
@@ -134,7 +134,7 @@ double grad2rad( const double phi )
float
correctAngle180
(
const
float
phi
)
{
if
(
fabs
(
phi
)
==
180.0
f
)
if
(
fabs
(
phi
)
==
180.0
f
)
return
phi
;
const
float
phi_temp
=
fmodf
(
phi
,
360.0
f
);
...
...
@@ -242,7 +242,7 @@ void csargpabs( const float in_re, const float in_im, const float dest_arg, floa
/* +----------- RAD -----------+ */
float
anglef_proj_0_2PI
(
const
float
alpha
)
{
float
alpha_temp
=
fmodf
(
alpha
,
2
*
PI_F
);
float
alpha_temp
=
fmodf
(
alpha
,
2
*
PI_F
);
if
(
alpha_temp
<
0
)
alpha_temp
+=
2
*
PI_F
;
return
alpha_temp
;
...
...
@@ -289,7 +289,7 @@ float anglef_mindiff_abs_0_360_DEG( const float alpha, const float beta )
}
void
convertYPR2VU
(
const
float
yaw
,
const
float
pitch
,
const
float
roll
,
float
&
vx
,
float
&
vy
,
float
&
vz
,
float
&
ux
,
float
&
uy
,
float
&
uz
)
void
convertYPR2VU
(
const
float
yaw
,
const
float
pitch
,
const
float
roll
,
float
&
vx
,
float
&
vy
,
float
&
vz
,
float
&
ux
,
float
&
uy
,
float
&
uz
)
{
double
vx_
,
vy_
,
vz_
,
ux_
,
uy_
,
uz_
;
convertYPR2VU
(
double
(
yaw
),
double
(
pitch
),
double
(
roll
),
vx_
,
vy_
,
vz_
,
ux_
,
uy_
,
uz_
);
...
...
@@ -301,7 +301,7 @@ void convertYPR2VU( const float yaw, const float pitch, const float roll, float&
uz
=
float
(
uz_
);
}
void
convertYPR2VU
(
const
double
yaw
,
const
double
pitch
,
const
double
roll
,
double
&
vx
,
double
&
vy
,
double
&
vz
,
double
&
ux
,
double
&
uy
,
double
&
uz
)
void
convertYPR2VU
(
const
double
yaw
,
const
double
pitch
,
const
double
roll
,
double
&
vx
,
double
&
vy
,
double
&
vz
,
double
&
ux
,
double
&
uy
,
double
&
uz
)
{
/*
* Yaw-pitch-roll (YPR) angles rotation order (referring to OpenGL axis)
...
...
@@ -323,7 +323,7 @@ void convertYPR2VU( const double yaw, const double pitch, const double roll, dou
uy
=
cp
*
cr
;
uz
=
-
sy
*
sr
+
cy
*
sp
*
cr
;
}
void
convertVU2YPR
(
const
float
vx
,
const
float
vy
,
const
float
vz
,
const
float
ux
,
const
float
uy
,
const
float
uz
,
float
&
yaw
,
float
&
pitch
,
float
&
roll
)
void
convertVU2YPR
(
const
float
vx
,
const
float
vy
,
const
float
vz
,
const
float
ux
,
const
float
uy
,
const
float
uz
,
float
&
yaw
,
float
&
pitch
,
float
&
roll
)
{
double
y
,
p
,
r
;
convertVU2YPR
(
double
(
vx
),
double
(
vy
),
double
(
vz
),
double
(
ux
),
double
(
uy
),
double
(
uz
),
y
,
p
,
r
);
...
...
@@ -332,7 +332,7 @@ void convertVU2YPR( const float vx, const float vy, const float vz, const float
roll
=
float
(
r
);
}
void
convertVU2YPR
(
const
double
vx
,
const
double
vy
,
const
double
vz
,
const
double
ux
,
const
double
uy
,
const
double
uz
,
double
&
yaw
,
double
&
pitch
,
double
&
roll
)
void
convertVU2YPR
(
const
double
vx
,
const
double
vy
,
const
double
vz
,
const
double
ux
,
const
double
uy
,
const
double
uz
,
double
&
yaw
,
double
&
pitch
,
double
&
roll
)
{
const
float
EPSILON
=
0.0001
F
;
...
...
@@ -407,7 +407,7 @@ void convertVU2YPR( const double vx, const double vy, const double vz, const dou
// Hint: cos(pitch) = cos( arcsin(vy) ) = sqrt(1-vy^2)
double
cp
=
sqrt
(
1
-
vy
*
vy
);
roll
=
(
zy
<=
0
?
acos
(
uy
/
cp
)
:
-
acos
(
uy
/
cp
)
);
/* debug
double v_norm = vx*vx + vy*vy + vz*vz;
double u_norm = ux*ux + uy*uy + uz*uz;
...
...
@@ -434,32 +434,32 @@ void pow2space( std::vector<int>& dest, const int a, const int b )
}
}
double
theta2elevation
(
const
double
dThetaRAD
)
double
theta2elevation
(
const
double
dThetaRAD
)
{
if
(
dThetaRAD
<
0
||
dThetaRAD
>
ITAConstants
::
PI_D
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"thetaRAD is only valid between 0 and PI"
);
if
(
dThetaRAD
<
0
||
dThetaRAD
>
ITAConstants
::
PI_D
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"thetaRAD is only valid between 0 and PI"
);
return
ITAConstants
::
PI_D
/
2
-
dThetaRAD
;
return
ITAConstants
::
PI_D
/
2
.0
f
-
dThetaRAD
;
}
double
elevation2theta
(
const
double
dElevationRAD
)
double
elevation2theta
(
const
double
dElevationRAD
)
{
if
(
abs
(
dElevationRAD
)
<
ITAConstants
::
PI_D
/
2
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"elevationRAD is only valid between -PI/2 and PI/2"
);
if
(
abs
(
dElevationRAD
)
<
ITAConstants
::
PI_D
/
2.0
f
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"elevationRAD is only valid between -PI/2 and PI/2"
);
return
ITAConstants
::
PI_D
/
2
-
dElevationRAD
;
return
ITAConstants
::
PI_D
/
2
.0
f
-
dElevationRAD
;
}
int
factorial
(
const
int
m
)
{
if
(
m
<
0
)
if
(
m
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Factorial can only be calculated for a positive integer"
);
return
(
m
<=
1
?
1
:
m
*
factorial
(
m
-
1
)
);
}
double
SHNormalizeConst
(
const
int
m
,
const
int
n
)
{
if
(
m
>
n
)
if
(
m
>
n
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Abs(degree) cannot be greater than order"
);
double
dRes
=
0
;
...
...
@@ -468,11 +468,11 @@ double SHNormalizeConst( const int m, const int n )
else
dRes
=
1
;
dRes
*=
sqrt
(
(
2.0
f
*
n
+
1
)
*
(
2
.0
f
-
SHKronecker
(
m
)
)
*
factorial
(
n
-
m
)
/
(
4.0
f
*
PI_F
*
factorial
(
n
+
m
)
)
);
dRes
*=
sqrt
(
(
2.0
f
*
n
+
1
)
*
(
2
-
SHKronecker
(
m
)
)
*
double
(
factorial
(
n
-
m
)
)
/
(
4.0
f
*
PI_F
*
double
(
factorial
(
n
+
m
)
)
)
);
return
dRes
;
}
int
SHKronecker
(
const
int
m
)
int
SHKronecker
(
const
int
m
)
{
if
(
m
==
0
)
return
1
;
...
...
@@ -480,31 +480,30 @@ int SHKronecker( const int m )
return
0
;
}
std
::
vector
<
double
>
SHRealvaluedBasefunctions
(
const
double
thetaRAD
,
const
double
azimuthRAD
,
const
int
maxOrder
)
std
::
vector
<
double
>
SHRealvaluedBasefunctions
(
const
double
thetaRAD
,
const
double
azimuthRAD
,
const
int
maxOrder
)
{
std
::
vector
<
double
>
Y
;
std
::
vector
<
double
>
Y
;
//std::vector<double> dNormalizing;
int
nmax
=
(
maxOrder
+
1
)
*
(
maxOrder
+
1
);
Y
.
resize
(
nmax
);
int
nmax
=
(
maxOrder
+
1
)
*
(
maxOrder
+
1
);
Y
.
resize
(
nmax
);
//dNormalizing.resize(nmax);
//dNormalizing = SHNormalizeConst();
Y
=
SHAssociatedLegendre
(
maxOrder
,
cos
(
thetaRAD
)
);
Y
=
SHAssociatedLegendre
(
maxOrder
,
cos
(
thetaRAD
)
);
for
(
int
n
=
0
;
n
<=
maxOrder
;
n
++
)
for
(
int
n
=
0
;
n
<=
maxOrder
;
n
++
)
{
Y
[
SHDegreeOrder2Linear
(
0
,
n
)]
*=
SHNormalizeConst
(
0
,
n
);
for
(
int
m
=
1
;
m
<=
n
;
m
++
)
Y
[
SHDegreeOrder2Linear
(
0
,
n
)
]
*=
SHNormalizeConst
(
0
,
n
);
for
(
int
m
=
1
;
m
<=
n
;
m
++
)
{
double
Normalizing
=
SHNormalizeConst
(
m
,
n
);
Y
[
SHDegreeOrder2Linear
(
m
,
n
)]
*=
cos
(
m
*
azimuthRAD
)
*
Normalizing
;
Y
[
SHDegreeOrder2Linear
(
-
m
,
n
)]
*=
sin
(
m
*
azimuthRAD
)
*
Normalizing
;
double
Normalizing
=
SHNormalizeConst
(
m
,
n
);
Y
[
SHDegreeOrder2Linear
(
m
,
n
)
]
*=
cos
(
m
*
azimuthRAD
)
*
Normalizing
;
Y
[
SHDegreeOrder2Linear
(
-
m
,
n
)
]
*=
sin
(
m
*
azimuthRAD
)
*
Normalizing
;
}
}
return
Y
;
}
std
::
vector
<
double
>
SHAssociatedLegendre
(
const
int
N
,
const
double
mu
)
{
std
::
vector
<
double
>
P
;
...
...
@@ -537,30 +536,30 @@ int SHDegreeOrder2Linear( const int m, const int n )
return
(
n
*
n
+
n
+
m
);
}
std
::
vector
<
double
>
HOARemaxWeights
(
int
iTruncationOrder
)
{
if
(
iTruncationOrder
>
20
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"ReMAx decoding only implemented up to Truncatrion Order 20"
);
std
::
vector
<
double
>
HOARemaxWeights
(
int
iTruncationOrder
)
{
if
(
iTruncationOrder
>
20
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"ReMAx decoding only implemented up to Truncatrion Order 20"
);
std
::
vector
<
double
>
vdRemax
;
double
dMaxRootTable
[
21
]
=
{
0.993752
,
0.993129
,
0.992407
,
0.991565
,
0.990575
,
0.989401
,
0.987993
,
0.986284
,
0.984183
,
0.978229
,
0.978229
,
0.973907
,
0.96816
,
0.96029
,
0.949108
,
0.93247
,
0.90618
,
0.861136
,
0.774597
,
0.57735
,
0
};
double
dMaxRoot
=
dMaxRootTable
[
21
-
iTruncationOrder
-
1
];
std
::
vector
<
double
>
vdAssoLegendre
=
(
SHAssociatedLegendre
(
iTruncationOrder
,
dMaxRoot
)
);
std
::
vector
<
double
>
vdRemax
;
double
dMaxRootTable
[
21
]
=
{
0.993752
,
0.993129
,
0.992407
,
0.991565
,
0.990575
,
0.989401
,
0.987993
,
0.986284
,
0.984183
,
0.978229
,
0.978229
,
0.973907
,
0.96816
,
0.96029
,
0.949108
,
0.93247
,
0.90618
,
0.861136
,
0.774597
,
0.57735
,
0
};
double
dMaxRoot
=
dMaxRootTable
[
21
-
iTruncationOrder
-
1
];
std
::
vector
<
double
>
vdAssoLegendre
=
(
SHAssociatedLegendre
(
iTruncationOrder
,
dMaxRoot
));
for
(
int
k
=
0
;
k
<=
iTruncationOrder
;
k
++
)
for
(
int
k
=
0
;
k
<=
iTruncationOrder
;
k
++
)
{
vdRemax
.
push_back
(
vdAssoLegendre
[
SHDegreeOrder2Linear
(
0
,
k
)]
);
vdRemax
.
push_back
(
vdAssoLegendre
[
SHDegreeOrder2Linear
(
0
,
k
)
]
);
}
return
vdRemax
;
}
void
SHLinear2DegreeOrder
(
const
int
iLinear
,
int
&
m
,
int
&
n
)
void
SHLinear2DegreeOrder
(
const
int
iLinear
,
int
&
m
,
int
&
n
)
{
if
(
iLinear
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"The linear index has to be higher than one"
);
if
(
iLinear
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"The linear index has to be higher than one"
);
std
::
vector
<
int
>
nm
;
n
=
(
floor
(
sqrt
(
iLinear
)));
m
=
(
iLinear
-
n
*
n
-
n
);
};
\ No newline at end of file
n
=
(
int
)
floor
(
sqrt
(
(
double
)
iLinear
)
);
m
=
(
iLinear
-
n
*
n
-
n
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment