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
1e8451f9
Commit
1e8451f9
authored
May 03, 2011
by
Sebastian Eichelbaum
Browse files
[FIX] - fixed several tests
parent
e0a1948b
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
84 additions
and
32 deletions
+84
-32
src/common/math/WLine.cpp
src/common/math/WLine.cpp
+2
-2
src/common/math/WLinearAlgebraFunctions.cpp
src/common/math/WLinearAlgebraFunctions.cpp
+1
-1
src/common/math/WLinearAlgebraFunctions.h
src/common/math/WLinearAlgebraFunctions.h
+1
-1
src/common/math/WPlane.cpp
src/common/math/WPlane.cpp
+5
-1
src/common/math/linearAlgebra/WMatrixFixed.h
src/common/math/linearAlgebra/WMatrixFixed.h
+58
-13
src/common/math/linearAlgebra/WPosition.h
src/common/math/linearAlgebra/WPosition.h
+1
-0
src/common/math/linearAlgebra/WVectorFixed.h
src/common/math/linearAlgebra/WVectorFixed.h
+0
-1
src/common/math/test/WLine_test.h
src/common/math/test/WLine_test.h
+3
-3
src/dataHandler/WGridRegular3D.cpp
src/dataHandler/WGridRegular3D.cpp
+9
-6
src/dataHandler/test/WDataSetScalar_test.h
src/dataHandler/test/WDataSetScalar_test.h
+1
-1
src/dataHandler/test/WDataSetVector_test.h
src/dataHandler/test/WDataSetVector_test.h
+3
-3
No files found.
src/common/math/WLine.cpp
View file @
1e8451f9
...
...
@@ -155,7 +155,7 @@ void WLine::resampleBySegmentLength( double newSegmentLength )
{
if
(
length
(
newLine
.
back
()
-
(
*
this
)[
i
]
)
>
newSegmentLength
)
{
const
W
Vector3d
_2
&
pred
=
(
*
this
)[
i
-
1
];
const
W
Position
_2
&
pred
=
(
*
this
)[
i
-
1
];
if
(
pred
==
newLine
.
back
()
)
{
// Then there is no triangle and the old Segment Length is bigger as the new segment
...
...
@@ -239,7 +239,7 @@ double maxSegmentLength( const WLine& line )
}
for
(
size_t
i
=
0
;
i
<
line
.
size
()
-
1
;
++
i
)
{
result
=
std
::
max
(
result
,
length
(
line
[
i
]
-
line
[
i
+
1
]
)
);
result
=
std
::
max
(
result
,
static_cast
<
double
>
(
length
(
line
[
i
]
-
line
[
i
+
1
]
)
)
);
}
return
result
;
}
...
...
src/common/math/WLinearAlgebraFunctions.cpp
View file @
1e8451f9
...
...
@@ -67,7 +67,7 @@ WPosition_2 transformPosition3DWithMatrix4D( WMatrix<double> mat, WPosition_2 ve
resultVec4D
[
2
]
=
mat
(
2
,
0
)
*
vec
[
0
]
+
mat
(
2
,
1
)
*
vec
[
1
]
+
mat
(
2
,
2
)
*
vec
[
2
]
+
mat
(
2
,
3
)
*
1
;
resultVec4D
[
3
]
=
mat
(
3
,
0
)
*
vec
[
0
]
+
mat
(
3
,
1
)
*
vec
[
1
]
+
mat
(
3
,
2
)
*
vec
[
2
]
+
mat
(
3
,
3
)
*
1
;
W
Vector3d
_2
result
;
W
Position
_2
result
;
result
[
0
]
=
resultVec4D
[
0
]
/
resultVec4D
[
3
];
result
[
1
]
=
resultVec4D
[
1
]
/
resultVec4D
[
3
];
result
[
2
]
=
resultVec4D
[
2
]
/
resultVec4D
[
3
];
...
...
src/common/math/WLinearAlgebraFunctions.h
View file @
1e8451f9
...
...
@@ -55,7 +55,7 @@ WVector3d_2 OWCOMMON_EXPORT transformVector3DWithMatrix4D( WMatrix<double> mat,
* \param mat 4x4 matrix
* \param vec vector
*/
W
Vector3d
_2
OWCOMMON_EXPORT
transformPosition3DWithMatrix4D
(
WMatrix
<
double
>
mat
,
WPosition_2
vec
);
W
Position
_2
OWCOMMON_EXPORT
transformPosition3DWithMatrix4D
(
WMatrix
<
double
>
mat
,
WPosition_2
vec
);
/**
* helper routine to invert a 3x3 matrix
...
...
src/common/math/WPlane.cpp
View file @
1e8451f9
...
...
@@ -149,7 +149,11 @@ boost::shared_ptr< std::set< WPosition_2 > > WPlane::samplePoints( double stepWi
WPosition_2
WPlane
::
getPointInPlane
(
double
x
,
double
y
)
const
{
return
m_pos
+
x
*
m_first
+
y
*
m_second
;
WVector3d_2
sd
=
m_pos
+
x
*
m_first
+
y
*
m_second
;
return
sd
;
}
void
WPlane
::
setPlaneVectors
(
const
WVector3d_2
&
first
,
const
WVector3d_2
&
second
)
...
...
src/common/math/linearAlgebra/WMatrixFixed.h
View file @
1e8451f9
...
...
@@ -195,12 +195,19 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Default constructor. The values are
un-
initialized
!
Use the static methods \ref zero(), \ref identity() or any of the predefined
* Default constructor. The values are initialized
with 0.
Use the static methods \ref zero(), \ref identity() or any of the predefined
* transformations if an initialized matrix is wished.
*/
WMatrixFixed
()
{
// No initialization needed. Matrix values are initialized by ValueStoreT.
// initialize to zero
for
(
size_t
row
=
0
;
row
<
Rows
;
++
row
)
{
for
(
size_t
col
=
0
;
col
<
Cols
;
++
col
)
{
operator
()(
row
,
col
)
=
ValueT
(
0
);
}
}
}
/**
...
...
@@ -237,6 +244,19 @@ public:
operator
[](
3
)
=
w
;
}
/**
* Copy construction casting the given value type. This is useful to create matrices with matrices using another value type.
*
* \tparam RHSValueT Value type of the given matrix to copy
* \tparam RHSValueStoreT Valuestore type of the given matrix to copy
* \param m the matrix to copy
*/
template
<
typename
RHSValueT
,
ValueStoreTemplate
RHSValueStoreT
>
explicit
WMatrixFixed
(
const
WMatrixFixed
<
RHSValueT
,
Rows
,
Cols
,
RHSValueStoreT
>&
m
)
// NOLINT - we do not want it explicit
{
setValues
(
m
.
m_values
);
}
/**
* Returns an identity matrix.
*
...
...
@@ -479,6 +499,22 @@ public:
return
m2
;
}
/**
* Cast to matrix of same size with different value type.
*
* \tparam ResultValueType resulting value type
* \tparam ResultValueStore resulting value store
*
* \return the converted matrix.
*/
template
<
typename
ResultValueType
,
ValueStoreTemplate
ResultValueStore
>
operator
WMatrixFixed
<
ResultValueType
,
Rows
,
Cols
,
ResultValueStore
>
()
const
{
WMatrixFixed
<
ResultValueType
,
Rows
,
Cols
,
ResultValueStore
>
result
;
result
.
setValues
(
m_values
);
return
result
;
}
/**
* Creates a WMatrix from a given Eigen3 Matrix
*
...
...
@@ -994,10 +1030,7 @@ public:
// For compatibility to the old vec/matrix types. They are ALL deprecated and will be removed
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double
normalize
()
// 28 files use this
{
return
0.0
;
}
double
normalize
();
private:
/**
...
...
@@ -1051,9 +1084,9 @@ typedef WMatrixFixed< float, 4, 4 > WMatrix4f_2;
* \return scaled matrix.
*/
template
<
typename
ScalarT
,
typename
Matrix
ValueT
,
size_t
Matrix
Rows
,
size_t
Matrix
Cols
,
ValueStoreTemplate
Matrix
ValueStoreT
>
WMatrixFixed
<
MatrixValueT
,
MatrixRows
,
MatrixCols
,
Matrix
ValueStoreT
>
operator
*
(
const
ScalarT
n
,
const
WMatrixFixed
<
Matrix
ValueT
,
MatrixRows
,
MatrixCols
,
Matrix
ValueStoreT
>&
mat
)
typename
RHS
ValueT
,
size_t
RHS
Rows
,
size_t
RHS
Cols
,
ValueStoreTemplate
RHS
ValueStoreT
>
WMatrixFixed
<
typename
WTypeTraits
::
TypePromotion
<
ScalarT
,
RHSValueT
>::
Result
,
RHSRows
,
RHSCols
,
RHS
ValueStoreT
>
operator
*
(
const
ScalarT
n
,
const
WMatrixFixed
<
RHS
ValueT
,
RHSRows
,
RHSCols
,
RHS
ValueStoreT
>&
mat
)
{
return
mat
*
n
;
}
...
...
@@ -1197,15 +1230,27 @@ ValueT length( const WMatrixFixed< ValueT, 1, Cols, ValueStoreT >& a )
/**
* Normalizes the given vector.
*
* \tparam MatrixType type of matrix. This type needs to be supported by length().
* \tparam RHSValueT given matrix value type
* \tparam Rows given row number
* \tparam Cols given col number
* \tparam RHSValueStoreT given matrix' valuestore
* \param m the vector
*
* \return normalized vector
*/
template
<
typename
MatrixType
>
MatrixType
normalize
(
const
MatrixType
&
m
)
template
<
typename
RHSValueT
,
size_t
Rows
,
size_t
Cols
,
ValueStoreTemplate
RHSValueStoreT
>
WMatrixFixed
<
RHSValueT
,
Rows
,
Cols
,
RHSValueStoreT
>
normalize
(
const
WMatrixFixed
<
RHSValueT
,
Rows
,
Cols
,
RHSValueStoreT
>&
m
)
{
// NOTE: the static cast ensures that the returned matrix value type is the same as the input one.
return
m
*
static_cast
<
RHSValueT
>
(
1.0
/
length
(
m
)
);
}
template
<
typename
ValueT
,
size_t
Rows
,
size_t
Cols
,
ValueStoreTemplate
ValueStoreT
>
double
WMatrixFixed
<
ValueT
,
Rows
,
Cols
,
ValueStoreT
>::
normalize
()
{
return
m
*
(
1.0
/
length
(
m
)
);
ValueT
l
=
length
(
*
this
);
operator
/=
(
l
);
return
l
;
}
/**
...
...
src/common/math/linearAlgebra/WPosition.h
View file @
1e8451f9
...
...
@@ -34,6 +34,7 @@
* WPosition_2 such is just another name for WVector3d_2 to indicate the specific use
* for positions in some places.
*/
typedef
WVector3d_2
WPosition_2
;
#endif // WPOSITION_H
src/common/math/linearAlgebra/WVectorFixed.h
View file @
1e8451f9
...
...
@@ -37,7 +37,6 @@ typedef WMatrixFixed< double, 4, 1 > WVector4d_2;
typedef
WMatrixFixed
<
double
,
1
,
2
>
WVector2dRow_2
;
typedef
WMatrixFixed
<
double
,
1
,
3
>
WVector3dRow_2
;
typedef
WMatrixFixed
<
double
,
1
,
4
>
WVector4dRow_2
;
typedef
WMatrixFixed
<
double
,
3
,
1
>
WPosition_2
;
// Float vectors
typedef
WMatrixFixed
<
float
,
2
,
1
>
WVector2f_2
;
...
...
src/common/math/test/WLine_test.h
View file @
1e8451f9
...
...
@@ -100,9 +100,9 @@ public:
l
.
push_back
(
WPosition_2
(
1.0
,
1.0
,
3.1415
)
);
l
.
push_back
(
WPosition_2
(
0.0
,
0.0
,
0.44
)
);
l
.
push_back
(
WPosition_2
(
1.0
,
1.0
,
1.0
)
);
std
::
string
expected
(
"[
[
1.0000000000000000e+00
,
1.0000000000000000e+00
,
3.1415000000000002e+00
]
, "
"
[
0.0000000000000000e+00
,
0.0000000000000000e+00
,
4.4000000000000000e-01
]
, "
"
[
1.0000000000000000e+00
,
1.0000000000000000e+00
,
1.0000000000000000e+00
]
]"
);
std
::
string
expected
(
"[1.0000000000000000e+00
;
1.0000000000000000e+00
;
3.1415000000000002e+00
;
, "
"0.0000000000000000e+00
;
0.0000000000000000e+00
;
4.4000000000000000e-01
;
, "
"1.0000000000000000e+00
;
1.0000000000000000e+00
;
1.0000000000000000e+00
;
]"
);
std
::
stringstream
ss
;
ss
<<
l
;
TS_ASSERT_EQUALS
(
expected
,
ss
.
str
()
);
...
...
src/dataHandler/WGridRegular3D.cpp
View file @
1e8451f9
...
...
@@ -128,27 +128,30 @@ int WGridRegular3D::getXVoxelCoord( const WPosition_2& pos ) const
WPosition_2
v
=
m_transform
.
positionToGridSpace
(
pos
);
// this part could be refactored into an inline function
v
[
2
]
=
modf
(
v
[
0
]
+
0.5
,
&
v
[
1
]
);
double
d
;
v
[
2
]
=
modf
(
v
[
0
]
+
0.5
,
&
d
);
int
i
=
static_cast
<
int
>
(
v
[
0
]
>=
0.0
&&
v
[
0
]
<
m_nbPosX
-
1.0
);
return
-
1
+
i
*
static_cast
<
int
>
(
1.0
+
v
[
1
]
);
return
-
1
+
i
*
static_cast
<
int
>
(
1.0
+
d
);
}
int
WGridRegular3D
::
getYVoxelCoord
(
const
WPosition_2
&
pos
)
const
{
WPosition_2
v
=
m_transform
.
positionToGridSpace
(
pos
);
v
[
0
]
=
modf
(
v
[
1
]
+
0.5
,
&
v
[
2
]
);
double
d
;
v
[
0
]
=
modf
(
v
[
1
]
+
0.5
,
&
d
);
int
i
=
static_cast
<
int
>
(
v
[
1
]
>=
0.0
&&
v
[
1
]
<
m_nbPosY
-
1.0
);
return
-
1
+
i
*
static_cast
<
int
>
(
1.0
+
v
[
2
]
);
return
-
1
+
i
*
static_cast
<
int
>
(
1.0
+
d
);
}
int
WGridRegular3D
::
getZVoxelCoord
(
const
WPosition_2
&
pos
)
const
{
WPosition_2
v
=
m_transform
.
positionToGridSpace
(
pos
);
v
[
0
]
=
modf
(
v
[
2
]
+
0.5
,
&
v
[
1
]
);
double
d
;
v
[
0
]
=
modf
(
v
[
2
]
+
0.5
,
&
d
);
int
i
=
static_cast
<
int
>
(
v
[
2
]
>=
0.0
&&
v
[
2
]
<
m_nbPosZ
-
1.0
);
return
-
1
+
i
*
static_cast
<
int
>
(
1.0
+
v
[
1
]
);
return
-
1
+
i
*
static_cast
<
int
>
(
1.0
+
d
);
}
WValue
<
int
>
WGridRegular3D
::
getVoxelCoord
(
const
WPosition_2
&
pos
)
const
...
...
src/dataHandler/test/WDataSetScalar_test.h
View file @
1e8451f9
...
...
@@ -64,7 +64,7 @@ public:
bool
success
=
false
;
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
(),
&
success
),
(
*
data
)[
0
]
);
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
::
zero
(),
&
success
),
(
*
data
)[
0
]
);
TS_ASSERT
(
success
);
TS_ASSERT_DELTA
(
ds
.
interpolate
(
WPosition_2
(
1
,
0
,
0
),
&
success
),
(
*
data
)[
1
],
1e-9
);
TS_ASSERT
(
success
);
...
...
src/dataHandler/test/WDataSetVector_test.h
View file @
1e8451f9
...
...
@@ -63,9 +63,9 @@ public:
bool
success
=
false
;
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
(),
&
success
)[
0
],
(
*
data
)[
0
]
);
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
(),
&
success
)[
1
],
(
*
data
)[
1
]
);
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
(),
&
success
)[
2
],
(
*
data
)[
2
]
);
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
(
0
,
0
,
0
),
&
success
)[
0
],
(
*
data
)[
0
]
);
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
(
0
,
0
,
0
),
&
success
)[
1
],
(
*
data
)[
1
]
);
TS_ASSERT_EQUALS
(
ds
.
interpolate
(
WPosition_2
(
0
,
0
,
0
),
&
success
)[
2
],
(
*
data
)[
2
]
);
TS_ASSERT
(
success
);
TS_ASSERT_DELTA
(
ds
.
interpolate
(
WPosition_2
(
1
,
0
,
0
),
&
success
)[
0
],
(
*
data
)[
3
],
1e-9
);
TS_ASSERT_DELTA
(
ds
.
interpolate
(
WPosition_2
(
1
,
0
,
0
),
&
success
)[
1
],
(
*
data
)[
4
],
1e-9
);
...
...
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