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
bd99f305
Commit
bd99f305
authored
Jun 02, 2010
by
Alexander Wiebel
Browse files
[CHANGE] made getBoundingBox also feasible for rotated grids. Therefore also
corrected homongeneous transformation functions.
parent
050584a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
18 deletions
+48
-18
src/common/math/WLinearAlgebraFunctions.cpp
src/common/math/WLinearAlgebraFunctions.cpp
+16
-0
src/common/math/WLinearAlgebraFunctions.h
src/common/math/WLinearAlgebraFunctions.h
+11
-0
src/dataHandler/WGridRegular3D.cpp
src/dataHandler/WGridRegular3D.cpp
+21
-18
No files found.
src/common/math/WLinearAlgebraFunctions.cpp
View file @
bd99f305
...
...
@@ -42,6 +42,22 @@ WVector3D multMatrixWithVector3D( WMatrix<double> mat, WVector3D vec )
}
WVector3D
transformVector3DWithMatrix4D
(
WMatrix
<
double
>
mat
,
WVector3D
vec
)
{
WAssert
(
mat
.
getNbRows
()
==
4
&&
mat
.
getNbCols
()
==
4
,
"Matrix has wrong size."
);
std
::
vector
<
double
>
resultVec4D
(
4
);
resultVec4D
[
0
]
=
mat
(
0
,
0
)
*
vec
[
0
]
+
mat
(
0
,
1
)
*
vec
[
1
]
+
mat
(
0
,
2
)
*
vec
[
2
]
/* + mat( 0, 3 ) * 0 */
;
resultVec4D
[
1
]
=
mat
(
1
,
0
)
*
vec
[
0
]
+
mat
(
1
,
1
)
*
vec
[
1
]
+
mat
(
1
,
2
)
*
vec
[
2
]
/* + mat( 1, 3 ) * 0 */
;
resultVec4D
[
2
]
=
mat
(
2
,
0
)
*
vec
[
0
]
+
mat
(
2
,
1
)
*
vec
[
1
]
+
mat
(
2
,
2
)
*
vec
[
2
]
/* + mat( 2, 3 ) * 0 */
;
resultVec4D
[
3
]
=
mat
(
3
,
0
)
*
vec
[
0
]
+
mat
(
3
,
1
)
*
vec
[
1
]
+
mat
(
3
,
2
)
*
vec
[
2
]
/* + mat( 3, 3 ) * 0 */
;
wmath
::
WVector3D
result
;
result
[
0
]
=
resultVec4D
[
0
]
/
resultVec4D
[
3
];
result
[
1
]
=
resultVec4D
[
1
]
/
resultVec4D
[
3
];
result
[
2
]
=
resultVec4D
[
2
]
/
resultVec4D
[
3
];
return
result
;
}
WPosition
transformPosition3DWithMatrix4D
(
WMatrix
<
double
>
mat
,
WPosition
vec
)
{
WAssert
(
mat
.
getNbRows
()
==
4
&&
mat
.
getNbCols
()
==
4
,
"Matrix has wrong size."
);
std
::
vector
<
double
>
resultVec4D
(
4
);
...
...
src/common/math/WLinearAlgebraFunctions.h
View file @
bd99f305
...
...
@@ -28,6 +28,7 @@
namespace
wmath
{
class
WVector3D
;
typedef
WVector3D
WPosition
;
template
<
typename
>
class
WMatrix
;
/**
...
...
@@ -40,12 +41,22 @@ namespace wmath
/**
* Applies a coordinate transformation in homogenous coordinates to a vector.
* This differs from transformPosition3DWithMatrix4D in that it DOES NOT incorporate the translation
*
* \param mat 4x4 matrix
* \param vec vector
*/
WVector3D
transformVector3DWithMatrix4D
(
WMatrix
<
double
>
mat
,
WVector3D
vec
);
/**
* Applies a coordinate transformation in homogenous coordinates to a position.
* This differs from transformVector3DWithMatrix4D in that it incorporates the translation.
*
* \param mat 4x4 matrix
* \param vec vector
*/
WVector3D
transformPosition3DWithMatrix4D
(
WMatrix
<
double
>
mat
,
WPosition
vec
);
/**
* helper routine to invert a 3x3 matrix
*
...
...
src/dataHandler/WGridRegular3D.cpp
View file @
bd99f305
...
...
@@ -201,7 +201,7 @@ wmath::WMatrix< double > WGridRegular3D::getTransformationMatrix() const
wmath
::
WVector3D
WGridRegular3D
::
worldCoordToTexCoord
(
wmath
::
WPosition
point
)
{
wmath
::
WVector3D
r
(
wmath
::
transform
Vector
3DWithMatrix4D
(
m_matrixInverse
,
point
)
);
wmath
::
WVector3D
r
(
wmath
::
transform
Position
3DWithMatrix4D
(
m_matrixInverse
,
point
)
);
r
[
0
]
=
r
[
0
]
/
m_nbPosX
;
r
[
1
]
=
r
[
1
]
/
m_nbPosY
;
...
...
@@ -409,26 +409,29 @@ bool WGridRegular3D::encloses( const wmath::WPosition& pos ) const
std
::
pair
<
wmath
::
WPosition
,
wmath
::
WPosition
>
WGridRegular3D
::
getBoundingBox
()
const
{
WAssert
(
isNotRotatedOrSheared
(),
"The getBoundingBox() function is only feasible for grids that are only translated or scaled so far."
);
std
::
pair
<
wmath
::
WPosition
,
wmath
::
WPosition
>
bb
=
std
::
make_pair
(
getOrigin
(),
getOrigin
()
+
getDirectionX
()
*
(
getNbCoordsX
()
-
1
)
+
getDirectionY
()
*
(
getNbCoordsY
()
-
1
)
+
getDirectionZ
()
*
(
getNbCoordsZ
()
-
1
)
);
// As scaling with negative can mean a switch of the coordinate directions
// we nee to check for the right ordering in the bounding box. For
// each coordinate where the minimum position has a larger value than
// the maximum position we need to exchange their values.
for
(
size_t
i
=
0
;
i
<
3
;
i
++
)
// Get the transformed corner points of the regular grid
std
::
vector
<
wmath
::
WPosition
>
cornerPs
;
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
0.0
,
0.0
,
0.0
)
)
);
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
getNbCoordsX
()
-
1
,
0.0
,
0.0
)
)
);
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
0.0
,
getNbCoordsY
()
-
1
,
0.0
)
)
);
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
getNbCoordsX
()
-
1
,
getNbCoordsY
()
-
1
,
0.0
)
)
);
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
0.0
,
0.0
,
getNbCoordsZ
()
-
1
)
)
);
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
getNbCoordsX
()
-
1
,
0.0
,
getNbCoordsZ
()
-
1
)
)
);
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
0.0
,
getNbCoordsY
()
-
1
,
getNbCoordsZ
()
-
1
)
)
);
cornerPs
.
push_back
(
transformPosition3DWithMatrix4D
(
m_matrix
,
wmath
::
WPosition
(
getNbCoordsX
()
-
1
,
getNbCoordsY
()
-
1
,
getNbCoordsZ
()
-
1
)
)
);
wmath
::
WPosition
minBB
(
wlimits
::
MAX_DOUBLE
,
wlimits
::
MAX_DOUBLE
,
wlimits
::
MAX_DOUBLE
);
wmath
::
WPosition
maxBB
(
wlimits
::
MIN_DOUBLE
,
wlimits
::
MIN_DOUBLE
,
wlimits
::
MIN_DOUBLE
);
// Check the components of the corner points separately against the components of the current maxBB and minBB
for
(
size_t
posId
=
0
;
posId
<
cornerPs
.
size
();
++
posId
)
{
if
(
bb
.
first
[
i
]
>
bb
.
second
[
i
]
)
for
(
size_t
compId
=
0
;
compId
<
3
;
++
compId
)
{
double
tmp
=
bb
.
first
[
i
];
bb
.
first
[
i
]
=
bb
.
second
[
i
];
bb
.
second
[
i
]
=
tmp
;
minBB
[
compId
]
=
cornerPs
[
posId
][
compId
]
<
minBB
[
compId
]
?
cornerPs
[
posId
][
compId
]
:
minBB
[
compId
];
maxBB
[
compId
]
=
cornerPs
[
posId
][
compId
]
>
maxBB
[
compId
]
?
cornerPs
[
posId
][
compId
]
:
maxBB
[
compId
];
}
}
return
bb
;
return
std
::
make_pair
(
minBB
,
maxBB
)
;
}
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