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
ac3db61c
Commit
ac3db61c
authored
Nov 22, 2009
by
Alexander Wiebel
Browse files
[ADD] matrix representation of transformation of grid. Now Ralph can get the
matrix directly.
parent
55832a1a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
173 additions
and
6 deletions
+173
-6
src/dataHandler/WGridRegular3D.cpp
src/dataHandler/WGridRegular3D.cpp
+48
-6
src/dataHandler/WGridRegular3D.h
src/dataHandler/WGridRegular3D.h
+18
-0
src/dataHandler/test/WGridRegular3D_test.h
src/dataHandler/test/WGridRegular3D_test.h
+107
-0
No files found.
src/dataHandler/WGridRegular3D.cpp
View file @
ac3db61c
...
...
@@ -38,14 +38,31 @@ WGridRegular3D::WGridRegular3D( double originX, double originY, double originZ,
m_nbPosX
(
nbPosX
),
m_nbPosY
(
nbPosY
),
m_nbPosZ
(
nbPosZ
),
m_directionX
(
directionX
),
m_directionY
(
directionY
),
m_directionZ
(
directionZ
)
m_directionZ
(
directionZ
),
m_matrix
(
4
,
4
)
{
m_matrix
(
0
,
0
)
=
directionX
[
0
];
m_matrix
(
0
,
1
)
=
directionY
[
0
];
m_matrix
(
0
,
2
)
=
directionZ
[
0
];
m_matrix
(
1
,
0
)
=
directionX
[
1
];
m_matrix
(
1
,
1
)
=
directionY
[
1
];
m_matrix
(
1
,
2
)
=
directionZ
[
1
];
m_matrix
(
2
,
0
)
=
directionX
[
2
];
m_matrix
(
2
,
1
)
=
directionY
[
2
];
m_matrix
(
2
,
2
)
=
directionZ
[
2
];
m_matrix
(
0
,
3
)
=
originX
;
m_matrix
(
1
,
3
)
=
originY
;
m_matrix
(
2
,
3
)
=
originZ
;
m_matrix
(
3
,
3
)
=
1.
;
}
WGridRegular3D
::
WGridRegular3D
(
unsigned
int
nbPosX
,
unsigned
int
nbPosY
,
unsigned
int
nbPosZ
,
const
WMatrix
<
double
>&
mat
)
:
WGrid
(
nbPosX
*
nbPosY
*
nbPosZ
),
m_nbPosX
(
nbPosX
),
m_nbPosY
(
nbPosY
),
m_nbPosZ
(
nbPosZ
)
m_nbPosX
(
nbPosX
),
m_nbPosY
(
nbPosY
),
m_nbPosZ
(
nbPosZ
),
m_matrix
(
wmath
::
WMatrix
<
double
>
(
mat
)
)
{
assert
(
mat
.
getNbRows
()
==
4
&&
mat
.
getNbCols
()
==
4
);
// only affine transformations are allowed
...
...
@@ -56,6 +73,8 @@ WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsign
m_directionX
=
WVector3D
(
mat
(
0
,
0
)
/
mat
(
3
,
3
),
mat
(
1
,
0
)
/
mat
(
3
,
3
),
mat
(
2
,
0
)
/
mat
(
3
,
3
)
);
m_directionY
=
WVector3D
(
mat
(
0
,
1
)
/
mat
(
3
,
3
),
mat
(
1
,
1
)
/
mat
(
3
,
3
),
mat
(
2
,
1
)
/
mat
(
3
,
3
)
);
m_directionZ
=
WVector3D
(
mat
(
0
,
2
)
/
mat
(
3
,
3
),
mat
(
1
,
2
)
/
mat
(
3
,
3
),
mat
(
2
,
2
)
/
mat
(
3
,
3
)
);
m_matrix
=
mat
;
}
...
...
@@ -64,22 +83,41 @@ WGridRegular3D::WGridRegular3D( double originX, double originY, double originZ,
double
offsetX
,
double
offsetY
,
double
offsetZ
)
:
WGrid
(
nbPosX
*
nbPosY
*
nbPosZ
),
m_origin
(
WPosition
(
originX
,
originY
,
originZ
)
),
m_nbPosX
(
nbPosX
),
m_nbPosY
(
nbPosY
),
m_nbPosZ
(
nbPosZ
),
m_nbPosX
(
nbPosX
),
m_nbPosY
(
nbPosY
),
m_nbPosZ
(
nbPosZ
),
m_directionX
(
WVector3D
(
offsetX
,
0.
,
0.
)
),
m_directionY
(
WVector3D
(
0.
,
offsetY
,
0.
)
),
m_directionZ
(
WVector3D
(
0.
,
0.
,
offsetZ
)
)
m_directionZ
(
WVector3D
(
0.
,
0.
,
offsetZ
)
),
m_matrix
(
4
,
4
)
{
m_matrix
(
0
,
0
)
=
offsetX
;
m_matrix
(
1
,
1
)
=
offsetY
;
m_matrix
(
2
,
2
)
=
offsetZ
;
m_matrix
(
0
,
3
)
=
originX
;
m_matrix
(
1
,
3
)
=
originY
;
m_matrix
(
2
,
3
)
=
originZ
;
m_matrix
(
3
,
3
)
=
1.
;
}
WGridRegular3D
::
WGridRegular3D
(
unsigned
int
nbPosX
,
unsigned
int
nbPosY
,
unsigned
int
nbPosZ
,
double
offsetX
,
double
offsetY
,
double
offsetZ
)
:
WGrid
(
nbPosX
*
nbPosY
*
nbPosZ
),
m_origin
(
WPosition
(
0.
,
0.
,
0.
)
),
m_nbPosX
(
nbPosX
),
m_nbPosY
(
nbPosY
),
m_nbPosZ
(
nbPosZ
),
m_nbPosX
(
nbPosX
),
m_nbPosY
(
nbPosY
),
m_nbPosZ
(
nbPosZ
),
m_directionX
(
WVector3D
(
offsetX
,
0.
,
0.
)
),
m_directionY
(
WVector3D
(
0.
,
offsetY
,
0.
)
),
m_directionZ
(
WVector3D
(
0.
,
0.
,
offsetZ
)
)
m_directionZ
(
WVector3D
(
0.
,
0.
,
offsetZ
)
),
m_matrix
(
4
,
4
)
{
m_matrix
(
0
,
0
)
=
offsetX
;
m_matrix
(
1
,
1
)
=
offsetY
;
m_matrix
(
2
,
2
)
=
offsetZ
;
m_matrix
(
3
,
3
)
=
1.
;
}
WPosition
WGridRegular3D
::
getPosition
(
unsigned
int
i
)
const
...
...
@@ -91,3 +129,7 @@ WPosition WGridRegular3D::getPosition( unsigned int iX, unsigned int iY, unsigne
{
return
m_origin
+
iX
*
m_directionX
+
iY
*
m_directionY
+
iZ
*
m_directionZ
;
}
wmath
::
WMatrix
<
double
>
WGridRegular3D
::
getTransformationMatrix
()
const
{
return
m_matrix
;
}
src/dataHandler/WGridRegular3D.h
View file @
ac3db61c
...
...
@@ -39,6 +39,10 @@
*/
class
WGridRegular3D
:
public
WGrid
{
/**
* Only test are allowed as friends.
*/
friend
class
WGridRegular3DTest
;
public:
/**
* Defines the position of the origin of the grid, the number of
...
...
@@ -166,6 +170,13 @@ public:
*/
wmath
::
WPosition
getPosition
(
unsigned
int
iX
,
unsigned
int
iY
,
unsigned
int
iZ
)
const
;
/**
* Return the matrix storing the transformation of the grid. This information is redundant.
* Please use m_origin and m_direction? for all normal computations.
* Use matrix only where you really need a matrix for multiplication.
*/
wmath
::
WMatrix
<
double
>
getTransformationMatrix
()
const
;
protected:
private:
wmath
::
WPosition
m_origin
;
...
...
@@ -177,6 +188,13 @@ private:
wmath
::
WVector3D
m_directionX
;
wmath
::
WVector3D
m_directionY
;
wmath
::
WVector3D
m_directionZ
;
/**
* Matrix storing the transformation of the grid. This is redundant.
* Please use m_origin and m_direction? for all normal computations.
* Use matrix only where you really need a matrix for multiplication.
*/
wmath
::
WMatrix
<
double
>
m_matrix
;
};
#endif // WGRIDREGULAR3D_H
src/dataHandler/test/WGridRegular3D_test.h
View file @
ac3db61c
...
...
@@ -104,6 +104,113 @@ public:
TS_ASSERT_EQUALS
(
grid4
.
size
(),
27
);
}
/**
* After instantiation there should be the right vectors, matrix and origin.
*/
void
testOrientation
(
void
)
{
WGridRegular3D
grid
(
3
,
3
,
3
,
2.2
,
3.3
,
4.4
);
TS_ASSERT_EQUALS
(
grid
.
size
(),
27
);
TS_ASSERT_EQUALS
(
grid
.
m_origin
,
WPosition
(
0.
,
0.
,
0.
)
);
TS_ASSERT_EQUALS
(
grid
.
m_directionX
,
WVector3D
(
2.2
,
0.
,
0.
)
);
TS_ASSERT_EQUALS
(
grid
.
m_directionY
,
WVector3D
(
0.
,
3.3
,
0.
)
);
TS_ASSERT_EQUALS
(
grid
.
m_directionZ
,
WVector3D
(
0.
,
0.
,
4.4
)
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
0
,
0
),
2.2
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
0
,
1
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
0
,
2
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
0
,
3
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
1
,
0
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
1
,
1
),
3.3
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
1
,
2
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
1
,
3
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
2
,
0
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
2
,
1
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
2
,
2
),
4.4
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
2
,
3
),
0.0
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
3
,
0
),
0.
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
3
,
1
),
0.
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
3
,
2
),
0.
);
TS_ASSERT_EQUALS
(
grid
.
m_matrix
(
3
,
3
),
1.
);
WGridRegular3D
grid2
(
1.1
,
2.2
,
3.3
,
3
,
3
,
3
,
1.11
,
2.22
,
3.33
);
TS_ASSERT_EQUALS
(
grid2
.
size
(),
27
);
TS_ASSERT_EQUALS
(
grid2
.
m_origin
,
WPosition
(
1.1
,
2.2
,
3.3
)
);
TS_ASSERT_EQUALS
(
grid2
.
m_directionX
,
WVector3D
(
1.11
,
0.
,
0.
)
);
TS_ASSERT_EQUALS
(
grid2
.
m_directionY
,
WVector3D
(
0.
,
2.22
,
0.
)
);
TS_ASSERT_EQUALS
(
grid2
.
m_directionZ
,
WVector3D
(
0.
,
0.
,
3.33
)
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
0
,
0
),
1.11
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
0
,
1
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
0
,
2
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
0
,
3
),
1.1
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
1
,
0
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
1
,
1
),
2.22
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
1
,
2
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
1
,
3
),
2.2
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
2
,
0
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
2
,
1
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
2
,
2
),
3.33
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
2
,
3
),
3.3
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
3
,
0
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
3
,
1
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
3
,
2
),
0.
);
TS_ASSERT_EQUALS
(
grid2
.
m_matrix
(
3
,
3
),
1.
);
WGridRegular3D
grid3
(
2.22
,
3.33
,
4.44
,
3
,
3
,
3
,
WVector3D
(
3.1
,
1.1
,
2.1
),
WVector3D
(
1.2
,
3.2
,
2.2
),
WVector3D
(
1.3
,
2.3
,
3.3
)
);
TS_ASSERT_EQUALS
(
grid3
.
size
(),
27
);
TS_ASSERT_EQUALS
(
grid3
.
m_origin
,
WPosition
(
2.22
,
3.33
,
4.44
)
);
TS_ASSERT_EQUALS
(
grid3
.
m_directionX
,
WVector3D
(
3.1
,
1.1
,
2.1
)
);
TS_ASSERT_EQUALS
(
grid3
.
m_directionY
,
WVector3D
(
1.2
,
3.2
,
2.2
)
);
TS_ASSERT_EQUALS
(
grid3
.
m_directionZ
,
WVector3D
(
1.3
,
2.3
,
3.3
)
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
0
,
0
),
3.1
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
0
,
1
),
1.2
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
0
,
2
),
1.3
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
0
,
3
),
2.22
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
1
,
0
),
1.1
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
1
,
1
),
3.2
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
1
,
2
),
2.3
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
1
,
3
),
3.33
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
2
,
0
),
2.1
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
2
,
1
),
2.2
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
2
,
2
),
3.3
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
2
,
3
),
4.44
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
3
,
0
),
0.
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
3
,
1
),
0.
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
3
,
2
),
0.
);
TS_ASSERT_EQUALS
(
grid3
.
m_matrix
(
3
,
3
),
1.
);
// constructor taking matrix
WMatrix
<
double
>
mat
(
4
,
4
);
for
(
unsigned
int
i
=
0
;
i
<
4
;
++
i
)
{
for
(
unsigned
int
j
=
0
;
j
<
4
;
++
j
)
{
mat
(
i
,
j
)
=
1.1
+
i
+
0.1
*
j
;
// This make entries like (1,2)=2.3, (0,0)=1.1
}
}
mat
(
3
,
0
)
=
0
;
mat
(
3
,
1
)
=
0
;
mat
(
3
,
2
)
=
0
;
mat
(
3
,
3
)
=
1
;
double
delta
=
1e-8
;
WGridRegular3D
grid4
(
3
,
3
,
3
,
mat
);
TS_ASSERT_EQUALS
(
grid4
.
size
(),
27
);
TS_ASSERT_DELTA
(
grid4
.
m_origin
[
0
],
1.4
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_origin
[
1
],
2.4
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_origin
[
2
],
3.4
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionX
[
0
],
1.1
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionX
[
1
],
2.1
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionX
[
2
],
3.1
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionY
[
0
],
1.2
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionY
[
1
],
2.2
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionY
[
2
],
3.2
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionZ
[
0
],
1.3
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionZ
[
1
],
2.3
,
delta
);
TS_ASSERT_DELTA
(
grid4
.
m_directionZ
[
2
],
3.3
,
delta
);
TS_ASSERT_EQUALS
(
grid4
.
m_matrix
,
mat
);
}
/**
* getNbCoords should return the samples prescribed by the use of the constructor
*/
...
...
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