-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to get link AABB from its collisions #2787
base: gz-sim9
Are you sure you want to change the base?
Changes from 2 commits
40c0324
9c45098
7cbf8a3
469a446
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1032,3 +1032,83 @@ TEST_F(UtilTest, LoadMesh) | |
EXPECT_NE(nullptr, optimizedMesh); | ||
EXPECT_EQ(16u, optimizedMesh->SubMeshCount()); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
TEST_F(UtilTest, MeshAxisAlignedBoundingBox) | ||
{ | ||
sdf::Mesh meshSdf; | ||
math::AxisAlignedBox emptyBox, aab; | ||
EXPECT_EQ(emptyBox, meshAxisAlignedBox(meshSdf)); | ||
|
||
meshSdf.SetUri("invalid_uri"); | ||
meshSdf.SetFilePath("invalid_filepath"); | ||
EXPECT_EQ(emptyBox, meshAxisAlignedBox(meshSdf)); | ||
|
||
meshSdf.SetUri("name://unit_box"); | ||
aab = meshAxisAlignedBox(meshSdf); | ||
EXPECT_NE(emptyBox, aab); | ||
EXPECT_EQ(aab.Size(), math::Vector3d::One); | ||
EXPECT_EQ(aab.Min(), math::Vector3d(-0.5, -0.5, -0.5)); | ||
EXPECT_EQ(aab.Max(), math::Vector3d(0.5, 0.5, 0.5)); | ||
EXPECT_EQ(aab.Center(), math::Vector3d::Zero); | ||
|
||
meshSdf.SetUri("duck.dae"); | ||
std::string filePath = common::joinPaths(std::string(PROJECT_SOURCE_PATH), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 469a446 |
||
"test", "media", "duck.dae"); | ||
meshSdf.SetFilePath(filePath); | ||
aab = meshAxisAlignedBox(meshSdf); | ||
EXPECT_NE(emptyBox, aab); | ||
|
||
// Expected values obtained from the mesh file using Blender: | ||
auto minExp = math::Vector3d(-69.2985, 9.92937, -61.3282) * 1e-2; | ||
auto maxExp = math::Vector3d(96.1799, 163.9700, 53.9252) * 1e-2; | ||
|
||
EXPECT_EQ(minExp, aab.Min()); | ||
EXPECT_EQ(maxExp, aab.Max()); | ||
EXPECT_EQ((minExp + maxExp) / 2, aab.Center()); | ||
EXPECT_EQ(maxExp - minExp, aab.Size()); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
TEST_F(UtilTest, TransformAxisAlignedBoxFrame) | ||
{ | ||
// Creates a pseudo-random vector with values between -max and max | ||
std::srand(std::time(nullptr)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 469a446 |
||
auto randomVector3d = [](int max = 1) -> math::Vector3d | ||
{ | ||
return ( | ||
math::Vector3d( | ||
static_cast<double>(std::rand()), | ||
static_cast<double>(std::rand()), | ||
static_cast<double>(std::rand()) | ||
) / RAND_MAX - 0.5 * math::Vector3d::One | ||
) * 2 * max; | ||
}; | ||
|
||
math::AxisAlignedBox aab(randomVector3d(3), randomVector3d(2)); | ||
|
||
// Trivial case: identity transform should not change the box | ||
math::Pose3d transform = math::Pose3d::Zero; | ||
math::AxisAlignedBox aabExp = aab; | ||
EXPECT_EQ(aabExp, transformAxisAlignedBox(aab, transform)); | ||
|
||
// Pure translation offset | ||
transform.Pos() = randomVector3d(10); | ||
aabExp = aab + transform.Pos(); | ||
EXPECT_EQ(aabExp, transformAxisAlignedBox(aab, transform)); | ||
|
||
// Pure rotation of 90 degrees around the z-axis | ||
// x -> y, y -> -x, z -> z | ||
transform.Reset(); | ||
transform.Rot() = math::Quaterniond(0, 0, GZ_PI_2); | ||
aabExp = math::AxisAlignedBox( | ||
math::Vector3d(-aab.Max().Y(), aab.Min().X(), aab.Min().Z()), | ||
math::Vector3d(-aab.Min().Y(), aab.Max().X(), aab.Max().Z()) | ||
); | ||
EXPECT_EQ(aabExp, transformAxisAlignedBox(aab, transform)); | ||
|
||
// Full transform: translation and rotation | ||
transform.Pos() = randomVector3d(150); | ||
aabExp = aabExp + transform.Pos(); | ||
EXPECT_EQ(aabExp, transformAxisAlignedBox(aab, transform)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 7cbf8a3