Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
iMSTK
iMSTK
Commits
e7dfcb23
Commit
e7dfcb23
authored
Jun 10, 2021
by
Harald Scheirich
Browse files
ENH: Add tests for neighbor vertices and triangles
parent
c9f002ec
Pipeline
#232684
failed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Source/Geometry/Testing/imstkSurfaceMeshTest.cpp
View file @
e7dfcb23
...
...
@@ -27,7 +27,7 @@
#include
"imstkVecDataArray.h"
#include
<gtest/gtest.h>
#include
<gmock/gmock.h>
using
namespace
imstk
;
namespace
...
...
@@ -61,23 +61,59 @@ std::unordered_map<std::string, std::shared_ptr<AbstractDataArray>> attributes =
{
"float3"
,
floatArray3
},
{
"double3"
,
doubleArray3
},
{
"float2"
,
floatArray2
},
{
"double2"
,
doubleArray2
}
};
}
class
imstkSurfaceMeshTest
:
public
::
testing
::
Test
// A Rectangle with the vertices along the long sides
// 0****1
// * **
// * * *
// * * *
// ** *
// 2****3
// * **
// 4 5
// ...
std
::
shared_ptr
<
SurfaceMesh
>
makeRect
()
{
protected:
SurfaceMesh
m_surfMesh
;
};
imstk
::
VecDataArray
<
double
,
3
>
points
;
auto
scalars
=
std
::
make_shared
<
imstk
::
DataArray
<
float
>>
();
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
points
.
push_back
({
0
,
0
,
static_cast
<
double
>
(
i
)
});
scalars
->
push_back
(
i
);
points
.
push_back
({
1
,
0
,
static_cast
<
double
>
(
i
)
});
scalars
->
push_back
(
i
);
}
auto
mesh
=
std
::
make_shared
<
imstk
::
SurfaceMesh
>
();
imstk
::
VecDataArray
<
int
,
3
>
tris
;
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
int
j
=
i
*
2
;
tris
.
push_back
({
j
+
2
,
j
+
1
,
j
});
tris
.
push_back
({
j
+
3
,
j
+
1
,
j
+
2
});
}
mesh
->
initialize
(
std
::
make_shared
<
VecDataArray
<
double
,
3
>>
(
points
),
std
::
make_shared
<
VecDataArray
<
int
,
3
>>
(
tris
));
mesh
->
setVertexAttribute
(
"scalars"
,
scalars
);
mesh
->
setVertexScalars
(
"scalars"
);
return
mesh
;
}
}
TEST
_F
(
imstkSurfaceMeshTest
,
CellNormalAttributes
)
TEST
(
imstkSurfaceMeshTest
,
CellNormalAttributes
)
{
m_surfMesh
.
setCellAttributes
(
attributes
);
m_surfMesh
.
setCellNormals
(
"double3"
);
EXPECT_EQ
(
doubleArray3
,
m_surfMesh
.
getCellNormals
());
SurfaceMesh
surfMesh
;
surfMesh
.
setCellAttributes
(
attributes
);
surfMesh
.
setCellNormals
(
"double3"
);
EXPECT_EQ
(
doubleArray3
,
surfMesh
.
getCellNormals
());
// Normals want doubles, test with floats
m_
surfMesh
.
setCellNormals
(
"float3"
);
auto
normals
=
m_
surfMesh
.
getCellNormals
();
surfMesh
.
setCellNormals
(
"float3"
);
auto
normals
=
surfMesh
.
getCellNormals
();
ASSERT_NE
(
nullptr
,
normals
);
EXPECT_NE
(
floatArray3
->
getVoidPointer
(),
normals
->
getVoidPointer
());
EXPECT_EQ
(
3
,
normals
->
size
());
...
...
@@ -88,19 +124,47 @@ TEST_F(imstkSurfaceMeshTest, CellNormalAttributes)
// This could work we'd need to make the DataArray a little bit more standards compliant
// EXPECT_THAT(*normals, ElementsAreArray(doubleArray3->begin(), doubleArray3->end()));
// HS 2021-apr-04 Death tests don't work with the current infrastructure
//ASSERT_DEATH(p.setVertexNormals("float2"), ".*");
//ASSERT_DEATH(surfMesh.setVertexNormals("float2"), ".*");
}
TEST
(
imstkSurfaceMeshTest
,
VertexNeighbors
)
{
using
testing
::
UnorderedElementsAre
;
auto
mesh
=
makeRect
();
mesh
->
computeVertexNeighborVertices
();
auto
neighbors
=
mesh
->
getVertexNeighborVertices
();
EXPECT_THAT
(
neighbors
[
0
],
UnorderedElementsAre
(
1
,
2
));
EXPECT_THAT
(
neighbors
[
1
],
UnorderedElementsAre
(
0
,
2
,
3
));
EXPECT_THAT
(
neighbors
[
3
],
UnorderedElementsAre
(
1
,
2
,
4
,
5
));
}
TEST
_F
(
imstkSurfaceMeshTest
,
CellTangentAttribute
s
)
TEST
(
imstkSurfaceMeshTest
,
TriangleNeigbor
s
)
{
m_surfMesh
.
setCellAttributes
(
attributes
);
m_surfMesh
.
setCellTangents
(
"double3"
);
EXPECT_EQ
(
doubleArray3
,
m_surfMesh
.
getCellTangents
());
using
testing
::
UnorderedElementsAre
;
auto
mesh
=
makeRect
();
mesh
->
computeVertexNeighborTriangles
();
auto
neighbors
=
mesh
->
getVertexNeighborTriangles
();
EXPECT_THAT
(
neighbors
[
0
],
UnorderedElementsAre
(
0
));
EXPECT_THAT
(
neighbors
[
1
],
UnorderedElementsAre
(
0
,
1
));
EXPECT_THAT
(
neighbors
[
3
],
UnorderedElementsAre
(
1
,
2
,
3
));
}
TEST
(
imstkSurfaceMeshTest
,
CellTangentAttributes
)
{
SurfaceMesh
surfMesh
;
surfMesh
.
setCellAttributes
(
attributes
);
surfMesh
.
setCellTangents
(
"double3"
);
EXPECT_EQ
(
doubleArray3
,
surfMesh
.
getCellTangents
());
// Tangents want floats, test with doubles
m_
surfMesh
.
setCellTangents
(
"float3"
);
auto
tangents
=
m_
surfMesh
.
getCellTangents
();
surfMesh
.
setCellTangents
(
"float3"
);
auto
tangents
=
surfMesh
.
getCellTangents
();
ASSERT_NE
(
nullptr
,
tangents
);
EXPECT_NE
(
floatArray3
->
getVoidPointer
(),
tangents
->
getVoidPointer
());
EXPECT_EQ
(
3
,
tangents
->
size
());
...
...
@@ -113,11 +177,9 @@ TEST_F(imstkSurfaceMeshTest, CellTangentAttributes)
//ASSERT_DEATH(p.setVertexTangents("float2"), ".*");
}
///
/// \brief Tests the correct computation of face normals
///
TEST_F
(
imstkSurfaceMeshTest
,
ComputeTriangleNormals
)
TEST
(
imstkSurfaceMeshTest
,
ComputeTriangleNormals
)
{
SurfaceMesh
surfMesh
;
// This is counter clockwise, when looking down on y, so normal should be directly up
// opengl coordinate system with -z going "out" from identity view
auto
verticesPtr
=
std
::
make_shared
<
VecDataArray
<
double
,
3
>>
(
3
);
...
...
@@ -127,17 +189,17 @@ TEST_F(imstkSurfaceMeshTest, ComputeTriangleNormals)
auto
indicesPtr
=
std
::
make_shared
<
VecDataArray
<
int
,
3
>>
(
1
);
(
*
indicesPtr
)[
0
]
=
Vec3i
(
0
,
1
,
2
);
m_
surfMesh
.
initialize
(
verticesPtr
,
indicesPtr
);
surfMesh
.
initialize
(
verticesPtr
,
indicesPtr
);
m_
surfMesh
.
computeTrianglesNormals
();
auto
normalsPtr
=
m_
surfMesh
.
getCellNormals
();
surfMesh
.
computeTrianglesNormals
();
auto
normalsPtr
=
surfMesh
.
getCellNormals
();
EXPECT_NE
(
nullptr
,
normalsPtr
);
EXPECT_EQ
(
1
,
normalsPtr
->
size
());
EXPECT_EQ
(
Vec3d
(
0.0
,
1.0
,
0.0
),
(
*
normalsPtr
)[
0
]);
}
TEST
_F
(
imstkSurfaceMeshTest
,
ComputeVertexNormals
)
TEST
(
imstkSurfaceMeshTest
,
ComputeVertexNormals
)
{
//
// /|\
...
...
@@ -154,11 +216,13 @@ TEST_F(imstkSurfaceMeshTest, ComputeVertexNormals)
auto
indicesPtr
=
std
::
make_shared
<
VecDataArray
<
int
,
3
>>
(
2
);
(
*
indicesPtr
)[
0
]
=
Vec3i
(
0
,
1
,
2
);
(
*
indicesPtr
)[
1
]
=
Vec3i
(
0
,
3
,
1
);
m_surfMesh
.
initialize
(
verticesPtr
,
indicesPtr
);
SurfaceMesh
surfMesh
;
surfMesh
.
initialize
(
verticesPtr
,
indicesPtr
);
// Should make 45 degrees 1, 1 edge
m_
surfMesh
.
computeVertexNormals
();
auto
normalsPtr
=
m_
surfMesh
.
getVertexNormals
();
surfMesh
.
computeVertexNormals
();
auto
normalsPtr
=
surfMesh
.
getVertexNormals
();
const
Vec3d
results1
=
Vec3d
(
1.0
,
1.0
,
0.0
).
normalized
();
const
Vec3d
results2
=
Vec3d
(
-
1.0
,
1.0
,
0.0
).
normalized
();
...
...
@@ -177,10 +241,7 @@ TEST_F(imstkSurfaceMeshTest, ComputeVertexNormals)
EXPECT_EQ
(
Vec3d
(
0.0
,
1.0
,
0.0
),
(
*
normalsPtr
)[
1
]);
}
///
/// \brief Tests the correct computation of volume
///
TEST_F
(
imstkSurfaceMeshTest
,
GetVolume
)
TEST
(
imstkSurfaceMeshTest
,
GetVolume
)
{
std
::
shared_ptr
<
SurfaceMesh
>
cubeSurfMesh
=
GeometryUtils
::
toSurfaceMesh
(
std
::
make_shared
<
OrientedBox
>
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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