Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
wenqing
ogs
Commits
74b6501c
Commit
74b6501c
authored
Oct 13, 2020
by
wenqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Test] Added unit test for AdjustNodeCoordinates
parent
d4ce9ee5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
216 additions
and
0 deletions
+216
-0
Tests/MeshLib/TestAdjustNodeCoordinates.cpp
Tests/MeshLib/TestAdjustNodeCoordinates.cpp
+216
-0
No files found.
Tests/MeshLib/TestAdjustNodeCoordinates.cpp
0 → 100644
View file @
74b6501c
/**
* \file
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on October 12, 2020, 2:58 PM
*/
#include "gtest/gtest.h"
#include <vector>
#include "MeshLib/Utils/GetOutlineMagnitude.h"
#include "MeshLib/Utils/AdjustNodeCoordinates.h"
#include "MeshLib/Node.h"
#include "MeshLib/MeshSurfaceExtraction.h"
TEST
(
MeshLib
,
AdjustNodeCoordinates
)
{
std
::
vector
<
MeshLib
::
Node
*>
nodes
;
nodes
.
reserve
(
3
);
//-- Plane in 3D outline space
// Nodes on an inclined plane.
nodes
.
push_back
(
new
MeshLib
::
Node
(
1.0
,
0.0
,
0.
));
nodes
.
push_back
(
new
MeshLib
::
Node
(
0.0
,
1.0
,
0.
));
nodes
.
push_back
(
new
MeshLib
::
Node
(
0.0
,
0.0
,
1.
));
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
auto
const
x
=
nodes
[
i
]
->
getCoords
();
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
double
const
expected
=
(
i
==
k
)
?
1.0
:
0.0
;
ASSERT_EQ
(
expected
,
x
[
k
]);
}
}
}
//-- Plane in 2D outline space
// Nodes on x-y plane with an offset of 1.0 in z direction..
nodes
[
0
]
->
updateCoordinates
(
0.0
,
0.0
,
1.0
);
nodes
[
1
]
->
updateCoordinates
(
1.0
,
0.0
,
1.0
);
nodes
[
2
]
->
updateCoordinates
(
0.0
,
1.0
,
1.0
);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
auto
const
x0
=
nodes
[
0
]
->
getCoords
();
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
ASSERT_EQ
(
0.0
,
x0
[
k
]);
}
auto
const
x1
=
nodes
[
1
]
->
getCoords
();
ASSERT_EQ
(
1.0
,
x1
[
0
]);
ASSERT_EQ
(
0.0
,
x1
[
1
]);
ASSERT_EQ
(
0.0
,
x1
[
2
]);
auto
const
x2
=
nodes
[
2
]
->
getCoords
();
ASSERT_EQ
(
0.0
,
x2
[
0
]);
ASSERT_EQ
(
1.0
,
x2
[
1
]);
ASSERT_EQ
(
0.0
,
x2
[
2
]);
}
//-- Line in 3D outline space
// Nodes on a line.
nodes
[
0
]
->
updateCoordinates
(
0.0
,
0.0
,
0.0
);
nodes
[
1
]
->
updateCoordinates
(
1.0
,
1.0
,
1.0
);
nodes
[
2
]
->
updateCoordinates
(
2.0
,
2.0
,
2.0
);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
auto
const
x0
=
nodes
[
0
]
->
getCoords
();
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
ASSERT_EQ
(
0.0
,
x0
[
k
]);
}
auto
const
x1
=
nodes
[
1
]
->
getCoords
();
ASSERT_EQ
(
1.0
,
x1
[
0
]);
ASSERT_EQ
(
1.0
,
x1
[
1
]);
ASSERT_EQ
(
1.0
,
x1
[
2
]);
auto
const
x2
=
nodes
[
2
]
->
getCoords
();
ASSERT_EQ
(
2.0
,
x2
[
0
]);
ASSERT_EQ
(
2.0
,
x2
[
1
]);
ASSERT_EQ
(
2.0
,
x2
[
2
]);
}
//-- Lines in 2D outline space
// Nodes on a line on a plane parallel to z=0 plane.
nodes
[
0
]
->
updateCoordinates
(
0.0
,
0.0
,
1.0
);
nodes
[
1
]
->
updateCoordinates
(
1.0
,
1.0
,
1.0
);
nodes
[
2
]
->
updateCoordinates
(
2.0
,
2.0
,
1.0
);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
auto
const
x0
=
nodes
[
0
]
->
getCoords
();
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
ASSERT_EQ
(
0.0
,
x0
[
k
]);
}
auto
const
x1
=
nodes
[
1
]
->
getCoords
();
ASSERT_EQ
(
1.0
,
x1
[
0
]);
ASSERT_EQ
(
1.0
,
x1
[
1
]);
ASSERT_EQ
(
0.0
,
x1
[
2
]);
auto
const
x2
=
nodes
[
2
]
->
getCoords
();
ASSERT_EQ
(
2.0
,
x2
[
0
]);
ASSERT_EQ
(
2.0
,
x2
[
1
]);
ASSERT_EQ
(
0.0
,
x2
[
2
]);
}
// Nodes on x-z plane with an offset of 1.0 in y direction..
nodes
[
0
]
->
updateCoordinates
(
0.0
,
1.0
,
0.0
);
nodes
[
1
]
->
updateCoordinates
(
1.0
,
1.0
,
0.0
);
nodes
[
2
]
->
updateCoordinates
(
0.0
,
1.0
,
1.0
);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
auto
const
x0
=
nodes
[
0
]
->
getCoords
();
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
ASSERT_EQ
(
0.0
,
x0
[
k
]);
}
auto
const
x1
=
nodes
[
1
]
->
getCoords
();
ASSERT_EQ
(
1.0
,
x1
[
0
]);
ASSERT_EQ
(
0.0
,
x1
[
1
]);
ASSERT_EQ
(
0.0
,
x1
[
2
]);
auto
const
x2
=
nodes
[
2
]
->
getCoords
();
ASSERT_EQ
(
0.0
,
x2
[
0
]);
ASSERT_EQ
(
1.0
,
x2
[
1
]);
ASSERT_EQ
(
0.0
,
x2
[
2
]);
}
// Nodes on y-z plane with an offset of 1.0 in x direction.
nodes
[
0
]
->
updateCoordinates
(
1.0
,
0.0
,
0.0
);
nodes
[
1
]
->
updateCoordinates
(
1.0
,
1.0
,
0.0
);
nodes
[
2
]
->
updateCoordinates
(
1.0
,
0.0
,
1.0
);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
auto
const
x0
=
nodes
[
0
]
->
getCoords
();
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
ASSERT_EQ
(
0.0
,
x0
[
k
]);
}
auto
const
x1
=
nodes
[
1
]
->
getCoords
();
ASSERT_EQ
(
1.0
,
x1
[
0
]);
ASSERT_EQ
(
0.0
,
x1
[
1
]);
ASSERT_EQ
(
0.0
,
x1
[
2
]);
auto
const
x2
=
nodes
[
2
]
->
getCoords
();
ASSERT_EQ
(
0.0
,
x2
[
0
]);
ASSERT_EQ
(
1.0
,
x2
[
1
]);
ASSERT_EQ
(
0.0
,
x2
[
2
]);
}
//-- Line in 1D outline space
// Nodes on a line that is parallel to x axis, which has an offset of 1.0 in
// y direction, and
// an offset of 2.0 in z direction.
double
const
x_coord
[]
=
{
1.0
,
2.0
,
3.0
};
nodes
[
0
]
->
updateCoordinates
(
x_coord
[
0
],
1.0
,
2.0
);
nodes
[
1
]
->
updateCoordinates
(
x_coord
[
1
],
1.0
,
2.0
);
nodes
[
2
]
->
updateCoordinates
(
x_coord
[
2
],
1.0
,
2.0
);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
for
(
std
::
size_t
i
=
0
;
i
<
nodes
.
size
();
i
++
)
{
auto
const
x
=
nodes
[
i
]
->
getCoords
();
ASSERT_EQ
(
x_coord
[
i
],
x
[
0
]);
ASSERT_EQ
(
0.0
,
x
[
1
]);
ASSERT_EQ
(
0.0
,
x
[
2
]);
}
}
// Nodes on a line that is parallel to y axis, which has an offset of 1.0 in
// x direction, and
// an offset of 2.0 in z direction.
nodes
[
0
]
->
updateCoordinates
(
1.0
,
x_coord
[
0
],
2.0
);
nodes
[
1
]
->
updateCoordinates
(
1.0
,
x_coord
[
1
],
2.0
);
nodes
[
2
]
->
updateCoordinates
(
1.0
,
x_coord
[
2
],
2.0
);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
for
(
std
::
size_t
i
=
0
;
i
<
nodes
.
size
();
i
++
)
{
auto
const
x
=
nodes
[
i
]
->
getCoords
();
ASSERT_EQ
(
x_coord
[
i
],
x
[
0
]);
ASSERT_EQ
(
0.0
,
x
[
1
]);
ASSERT_EQ
(
0.0
,
x
[
2
]);
}
}
// Nodes on a line that is parallel to z axis, which has an offset of 1.0 in
// x direction, and an offset of 2.0 in y direction.
nodes
[
0
]
->
updateCoordinates
(
1.0
,
2.0
,
x_coord
[
0
]);
nodes
[
1
]
->
updateCoordinates
(
1.0
,
2.0
,
x_coord
[
1
]);
nodes
[
2
]
->
updateCoordinates
(
1.0
,
2.0
,
x_coord
[
2
]);
{
auto
const
&
x_magnitude
=
MeshLib
::
getOutlineMagnitude
(
nodes
);
MeshLib
::
adjustNodeCoordinates
(
x_magnitude
,
nodes
);
for
(
std
::
size_t
i
=
0
;
i
<
nodes
.
size
();
i
++
)
{
auto
const
x
=
nodes
[
i
]
->
getCoords
();
ASSERT_EQ
(
x_coord
[
i
],
x
[
0
]);
ASSERT_EQ
(
0.0
,
x
[
1
]);
ASSERT_EQ
(
0.0
,
x
[
2
]);
}
}
for
(
auto
node
:
nodes
)
{
delete
node
;
}
}
\ No newline at end of file
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