-
Notifications
You must be signed in to change notification settings - Fork 41
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
[Citadel] [TPE] Add function to get an Entity's bounding box #59
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2020 Open Source Robotics Foundation | ||
* | ||
* 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 | ||
* | ||
* 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 "Utils.hh" | ||
|
||
namespace ignition { | ||
namespace physics { | ||
namespace tpelib { | ||
|
||
////////////////////////////////////////////////// | ||
math::AxisAlignedBox transformAxisAlignedBox( | ||
const math::AxisAlignedBox &_box, const math::Pose3d &_pose) | ||
{ | ||
if (_box == math::AxisAlignedBox()) | ||
return _box; | ||
|
||
// transform each corner and merge the result | ||
math::Vector3d oldMin = _box.Min(); | ||
math::Vector3d oldMax = _box.Max(); | ||
math::Vector3d newMin(math::MAX_D, math::MAX_D, math::MAX_D); | ||
math::Vector3d newMax(math::LOW_D, math::LOW_D, math::LOW_D); | ||
|
||
// min min min | ||
math::Vector3d corner = oldMin; | ||
auto v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
// min min max | ||
corner.Z() = oldMax.Z(); | ||
v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
// min max max | ||
corner.Y() = oldMax.Y(); | ||
v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
// min max min | ||
corner.Z() = oldMin.Z(); | ||
v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
// max max min | ||
corner.X() = oldMax.X(); | ||
v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
// max max max | ||
corner.Z() = oldMax.Z(); | ||
v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
// max min max | ||
corner.Y() = oldMin.Y(); | ||
v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
// max min min | ||
corner.Z() = oldMin.Z(); | ||
v = _pose.Rot() * corner + _pose.Pos(); | ||
newMin.Min(v); | ||
newMax.Max(v); | ||
|
||
return math::AxisAlignedBox(newMin, newMax); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2020 Open Source Robotics Foundation | ||
* | ||
* 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 | ||
* | ||
* 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 <ignition/math/AxisAlignedBox.hh> | ||
#include <ignition/math/Pose3.hh> | ||
|
||
namespace ignition { | ||
namespace physics { | ||
namespace tpelib { | ||
|
||
/// \brief Transform an axis aligned box by pose | ||
/// \param[in] _box Axis aligned box to be transformed | ||
/// \param[in] _pose Transform to be applied | ||
/// \return New axis aligned box that surrounds the transformed version of | ||
/// the old box | ||
math::AxisAlignedBox transformAxisAlignedBox( | ||
const math::AxisAlignedBox &_box, const math::Pose3d &_pose); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2020 Open Source Robotics Foundation | ||
* | ||
* 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 | ||
* | ||
* 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 "Utils.hh" | ||
|
||
using namespace ignition; | ||
using namespace physics; | ||
using namespace tpelib; | ||
|
||
///////////////////////////////////////////////// | ||
TEST(Utils, TransformAxisAlignedBox) | ||
{ | ||
math::Pose3d p(2, 3, 4, 0, IGN_PI * 0.5, 0); | ||
math::AxisAlignedBox box; | ||
math::AxisAlignedBox boxTransformed = transformAxisAlignedBox(box, p); | ||
EXPECT_EQ(math::AxisAlignedBox(), boxTransformed); | ||
|
||
// box2 centered at [0, 0, 0] with size [2, 4, 6] | ||
math::AxisAlignedBox box2( | ||
math::Vector3d(-1, -2, -3), math::Vector3d(1, 2, 3)); | ||
|
||
// translate box2 | ||
math::Pose3d poseNoRot(2, 2, 2, 0, 0, 0, 0); | ||
math::AxisAlignedBox box2Transformed = | ||
transformAxisAlignedBox(box2, poseNoRot); | ||
EXPECT_EQ(math::Vector3d(2, 2, 2), box2Transformed.Center()); | ||
EXPECT_EQ(box2.Size(), box2Transformed.Size()); | ||
EXPECT_EQ(math::AxisAlignedBox(math::Vector3d(1, 0, -1), | ||
math::Vector3d(3, 4, 5)), box2Transformed); | ||
|
||
// translate and rotate box2 | ||
math::Pose3d pose(2, 2, 2, 0, IGN_PI * 0.5, 0); | ||
math::AxisAlignedBox box2TransformedRot = | ||
transformAxisAlignedBox(box2, pose); | ||
EXPECT_EQ(math::Vector3d(2, 2, 2), box2TransformedRot.Center()); | ||
EXPECT_EQ((pose.Rot() * box2.Size()).Abs(), box2TransformedRot.Size()); | ||
EXPECT_EQ(math::AxisAlignedBox(math::Vector3d(-1, 0, 1), | ||
math::Vector3d(5, 4, 3)), box2TransformedRot); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we add more documentation on the math behind this function? I find it a bit hard to understand by just reading the code.
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.
added more doc and testing linker fix in 558cbb7