Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
iMSTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ben Boeckel
iMSTK
Commits
ecb09ddf
Commit
ecb09ddf
authored
3 years ago
by
Sreekanth Arikatla
Committed by
Andrew Wilson
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Add tetra to line mesh tests
parent
146713c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Source/CollisionDetection/Testing/imstkTetraToLineMeshCDTest.cpp
+166
-0
166 additions, 0 deletions
...CollisionDetection/Testing/imstkTetraToLineMeshCDTest.cpp
with
166 additions
and
0 deletions
Source/CollisionDetection/Testing/imstkTetraToLineMeshCDTest.cpp
0 → 100644
+
166
−
0
View file @
ecb09ddf
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#include
"gtest/gtest.h"
#include
"imstkLineMesh.h"
#include
"imstkTetrahedralMesh.h"
#include
"imstkTetraToLineMeshCD.h"
using
namespace
imstk
;
std
::
shared_ptr
<
TetrahedralMesh
>
makeUnitTetrahedron
()
{
// Create tetrahedron
auto
verticesPtr
=
std
::
make_shared
<
VecDataArray
<
double
,
3
>>
(
4
);
auto
indicesPtr
=
std
::
make_shared
<
VecDataArray
<
int
,
4
>>
(
1
);
(
*
verticesPtr
)[
0
]
=
Vec3d
(
0.0
,
0.0
,
0.0
);
(
*
verticesPtr
)[
1
]
=
Vec3d
(
1.0
,
0.0
,
0.0
);
(
*
verticesPtr
)[
2
]
=
Vec3d
(
0.0
,
1.0
,
0.0
);
(
*
verticesPtr
)[
3
]
=
Vec3d
(
0.0
,
0.0
,
1.0
);
(
*
indicesPtr
)[
0
]
=
Vec4i
(
0
,
1
,
2
,
3
);
auto
tetMesh
=
std
::
make_shared
<
TetrahedralMesh
>
();
tetMesh
->
initialize
(
verticesPtr
,
indicesPtr
);
return
tetMesh
;
}
std
::
shared_ptr
<
LineMesh
>
makeOneSegmentLineMesh
(
const
Vec3d
&
a
,
const
Vec3d
&
b
)
{
auto
lineMesh
=
std
::
make_shared
<
LineMesh
>
();
auto
verxPtr
=
std
::
make_shared
<
VecDataArray
<
double
,
3
>>
(
2
);
auto
indicesPtr
=
std
::
make_shared
<
VecDataArray
<
int
,
2
>>
(
1
);
(
*
verxPtr
)[
0
]
=
a
;
(
*
verxPtr
)[
1
]
=
b
;
(
*
indicesPtr
)[
0
]
=
Vec2i
(
0
,
1
);
lineMesh
->
initialize
(
verxPtr
,
indicesPtr
);
return
lineMesh
;
}
TEST
(
imstkTetraToLineMeshCDTest
,
IntersectionTestAB_enclosed
)
{
// Create tetrahedron
auto
tetMesh
=
makeUnitTetrahedron
();
// Create enclosed line mesh
auto
lineMesh
=
makeOneSegmentLineMesh
(
Vec3d
(
0.05
,
0.05
,
0.05
),
Vec3d
(
0.07
,
0.07
,
0.07
));
// create collision
TetraToLineMeshCD
m_tetraToLineMeshCD
;
m_tetraToLineMeshCD
.
setInput
(
lineMesh
,
0
);
m_tetraToLineMeshCD
.
setInput
(
tetMesh
,
1
);
m_tetraToLineMeshCD
.
setGenerateCD
(
true
,
true
);
// Generate both A and B
m_tetraToLineMeshCD
.
update
();
std
::
shared_ptr
<
CollisionData
>
colData
=
m_tetraToLineMeshCD
.
getCollisionData
();
// Should be one element on side A, 1 on side B
EXPECT_EQ
(
1
,
colData
->
elementsA
.
getSize
());
EXPECT_EQ
(
1
,
colData
->
elementsB
.
getSize
());
// That element should be a point directional element
EXPECT_EQ
(
CollisionElementType
::
CellIndex
,
colData
->
elementsA
[
0
].
m_type
);
EXPECT_EQ
(
CollisionElementType
::
CellIndex
,
colData
->
elementsB
[
0
].
m_type
);
// Check cell types
EXPECT_EQ
(
IMSTK_EDGE
,
colData
->
elementsA
[
0
].
m_element
.
m_CellIndexElement
.
cellType
);
EXPECT_EQ
(
IMSTK_TETRAHEDRON
,
colData
->
elementsB
[
0
].
m_element
.
m_CellIndexElement
.
cellType
);
// Check cell types
EXPECT_EQ
(
0
,
colData
->
elementsA
[
0
].
m_element
.
m_CellIndexElement
.
ids
[
0
]);
EXPECT_EQ
(
0
,
colData
->
elementsB
[
0
].
m_element
.
m_CellIndexElement
.
ids
[
0
]);
}
TEST
(
imstkTetraToLineMeshCDTest
,
IntersectionTestAB_intersecting
)
{
// Create tetrahedron
auto
tetMesh
=
makeUnitTetrahedron
();
// Create intersecting line mesh
auto
lineMesh
=
makeOneSegmentLineMesh
(
Vec3d
(
-
1.0
,
-
1.0
,
-
1.0
),
Vec3d
(
1.0
,
1.0
,
1.0
));
// create collision
TetraToLineMeshCD
m_tetraToLineMeshCD
;
m_tetraToLineMeshCD
.
setInput
(
lineMesh
,
0
);
m_tetraToLineMeshCD
.
setInput
(
tetMesh
,
1
);
m_tetraToLineMeshCD
.
setGenerateCD
(
true
,
true
);
// Generate both A and B
m_tetraToLineMeshCD
.
update
();
std
::
shared_ptr
<
CollisionData
>
colData
=
m_tetraToLineMeshCD
.
getCollisionData
();
// Should be one element on side A, 1 on side B
EXPECT_EQ
(
1
,
colData
->
elementsA
.
getSize
());
EXPECT_EQ
(
1
,
colData
->
elementsB
.
getSize
());
// That element should be a point directional element
EXPECT_EQ
(
CollisionElementType
::
CellIndex
,
colData
->
elementsA
[
0
].
m_type
);
EXPECT_EQ
(
CollisionElementType
::
CellIndex
,
colData
->
elementsB
[
0
].
m_type
);
// Check cell types
EXPECT_EQ
(
IMSTK_EDGE
,
colData
->
elementsA
[
0
].
m_element
.
m_CellIndexElement
.
cellType
);
EXPECT_EQ
(
IMSTK_TETRAHEDRON
,
colData
->
elementsB
[
0
].
m_element
.
m_CellIndexElement
.
cellType
);
// Check cell types
EXPECT_EQ
(
0
,
colData
->
elementsA
[
0
].
m_element
.
m_CellIndexElement
.
ids
[
0
]);
EXPECT_EQ
(
0
,
colData
->
elementsB
[
0
].
m_element
.
m_CellIndexElement
.
ids
[
0
]);
}
TEST
(
imstkTetraToLineMeshCDTest
,
NonIntersectionTestAB
)
{
// Create unit tetrahedron
auto
tetMesh
=
makeUnitTetrahedron
();
// Create non-intersecting line mesh
auto
lineMesh
=
makeOneSegmentLineMesh
(
Vec3d
(
1.0
,
1.0
,
1.0
),
Vec3d
(
2.0
,
2.0
,
2.0
));
// create collision
TetraToLineMeshCD
m_tetraToLineMeshCD
;
m_tetraToLineMeshCD
.
setInput
(
lineMesh
,
0
);
m_tetraToLineMeshCD
.
setInput
(
tetMesh
,
1
);
m_tetraToLineMeshCD
.
setGenerateCD
(
true
,
true
);
// Generate both A and B
m_tetraToLineMeshCD
.
update
();
std
::
shared_ptr
<
CollisionData
>
colData
=
m_tetraToLineMeshCD
.
getCollisionData
();
// Should have no elements
EXPECT_EQ
(
0
,
colData
->
elementsA
.
getSize
());
EXPECT_EQ
(
0
,
colData
->
elementsB
.
getSize
());
}
int
imstkTetraToLineMeshCDTest
(
int
argc
,
char
*
argv
[])
{
// Init Google Test & Mock
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
// Run tests with gtest
return
RUN_ALL_TESTS
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment