Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
fdc07bd7
Commit
fdc07bd7
authored
Mar 22, 2013
by
Sebastian Eichelbaum
Browse files
[MERGE]
parents
036ad863
0cdc95f4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
1 deletion
+92
-1
src/core/common/math/WMath.h
src/core/common/math/WMath.h
+15
-0
src/core/common/math/WMatrix.h
src/core/common/math/WMatrix.h
+40
-0
src/core/common/math/WSymmetricSphericalHarmonic.cpp
src/core/common/math/WSymmetricSphericalHarmonic.cpp
+3
-1
src/core/common/math/test/WMath_test.h
src/core/common/math/test/WMath_test.h
+12
-0
src/core/common/math/test/WMatrix_test.h
src/core/common/math/test/WMatrix_test.h
+22
-0
No files found.
src/core/common/math/WMath.h
View file @
fdc07bd7
...
...
@@ -156,6 +156,21 @@ T factorial( T i )
return
res
;
}
/**
* Checks if two values are equal within a given delta.
*
* \tparam The floating point type.
* \param a The first value.
* \param b The second value.
* \param delta The tolerance parameter.
* \return True if both values are equal within the delta, otherwise false.
*/
template
<
typename
T
>
T
areEqual
(
T
a
,
T
b
,
T
delta
=
T
(
0
)
)
{
return
(
std
::
fabs
(
a
-
b
)
<=
delta
);
}
template
<
typename
T
>
inline
int
signum
(
const
T
&
value
)
{
if
(
value
<
0
)
...
...
src/core/common/math/WMatrix.h
View file @
fdc07bd7
...
...
@@ -195,6 +195,19 @@ public:
}
}
/**
* Returns true if the matrix is a square matrix.
* \return true for square matrixes, otherwise false.
*/
bool
isSquare
()
const
;
/**
* Returns true if the matrix is a identity matrix.
* \param delta - tolerance parameter when checking the values.
* \return true for identity matrixes, otherwise false.
*/
bool
isIdentity
(
T
delta
=
T
(
0.0
)
)
const
;
protected:
private:
size_t
m_nbCols
;
//!< Number of columns of the matrix. The number of rows will be computed by (size/m_nbCols).
...
...
@@ -454,6 +467,33 @@ template< typename T > WVector3d WMatrix< T >::operator*( const WVector3d& rhs )
return
result
;
}
template
<
typename
T
>
bool
WMatrix
<
T
>::
isSquare
()
const
{
return
getNbRows
()
==
getNbCols
();
}
template
<
typename
T
>
bool
WMatrix
<
T
>::
isIdentity
(
T
delta
)
const
{
if
(
!
isSquare
()
)
{
return
false
;
}
for
(
size_t
row
=
0
;
row
<
getNbRows
();
row
++
)
{
for
(
size_t
col
=
0
;
col
<
getNbCols
();
col
++
)
{
T
val
=
(
*
this
)(
row
,
col
);
T
expected
=
(
row
==
col
?
T
(
1.0
)
:
T
(
0.0
)
);
if
(
std
::
fabs
(
val
-
expected
)
>
delta
)
{
return
false
;
}
}
}
return
true
;
}
template
<
typename
T
>
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
WMatrix
<
T
>&
m
)
{
...
...
src/core/common/math/WSymmetricSphericalHarmonic.cpp
View file @
fdc07bd7
...
...
@@ -152,7 +152,7 @@ double WSymmetricSphericalHarmonic::calcGFA( std::vector< WUnitSphereCoordinates
double
d
=
0.0
;
double
gfa
=
0.0
;
double
mean
=
0.0
;
double
v
[
15
]
;
std
::
vector
<
double
>
v
(
orientations
.
size
()
)
;
for
(
std
::
size_t
i
=
0
;
i
<
orientations
.
size
();
++
i
)
{
...
...
@@ -513,6 +513,8 @@ WMatrix< double > WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( std::siz
WMatrix
<
double
>
p
=
pseudoInverse
(
TEMat
);
WAssert
(
(
TEMat
*
p
).
isIdentity
(
1e-3
),
"Test of inverse matrix failed. Are the given orientations linear independent?"
);
return
p
*
calcBaseMatrix
(
ori2
,
order
);
}
...
...
src/core/common/math/test/WMath_test.h
View file @
fdc07bd7
...
...
@@ -265,6 +265,18 @@ public:
TS_ASSERT_EQUALS
(
factorial
(
7
),
5040
);
TS_ASSERT_EQUALS
(
factorial
(
8
),
40320
);
}
/**
* Test the areEqual function.
*/
void
testAreEqual
(
void
)
{
TS_ASSERT_EQUALS
(
areEqual
(
1.0
,
1.0
),
true
);
TS_ASSERT_EQUALS
(
areEqual
(
1.0
,
1.0
,
1e-3
),
true
);
TS_ASSERT_EQUALS
(
areEqual
(
1.0
,
1.0
+
1e-3
,
1e-3
),
true
);
TS_ASSERT_EQUALS
(
areEqual
(
1.0
,
1.0
+
2e-3
,
1e-3
),
false
);
TS_ASSERT_EQUALS
(
areEqual
(
1.0
,
1.0
+
1e-3
),
false
);
}
};
#endif // WMATH_TEST_H
src/core/common/math/test/WMatrix_test.h
View file @
fdc07bd7
...
...
@@ -247,6 +247,28 @@ public:
for
(
size_t
col
=
0
;
col
<
nbCols
;
col
++
)
TS_ASSERT_EQUALS
(
matrixTransposed
(
col
,
row
),
(
row
+
1
)
*
10
+
col
+
1
);
}
/**
* Test isIdentity method of WMatrix
*/
void
testIsIdentity
(
void
)
{
WMatrix
<
double
>
a
(
3
,
2
);
a
.
makeIdentity
();
TS_ASSERT_EQUALS
(
a
.
isIdentity
(),
false
);
WMatrix
<
double
>
b
(
3
,
3
);
b
.
makeIdentity
();
TS_ASSERT_EQUALS
(
b
.
isIdentity
(),
true
);
b
(
0
,
0
)
+=
1e-3
;
TS_ASSERT_EQUALS
(
b
.
isIdentity
(),
false
);
TS_ASSERT_EQUALS
(
b
.
isIdentity
(
1e-3
),
true
);
b
(
0
,
1
)
+=
2e-3
;
TS_ASSERT_EQUALS
(
b
.
isIdentity
(
1e-3
),
false
);
TS_ASSERT_EQUALS
(
b
.
isIdentity
(
2e-3
),
true
);
}
};
#endif // WMATRIX_TEST_H
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