forked from gazebosim/gz-physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Steve Peters <[email protected]> Signed-off-by: Louise Poubel <[email protected]> Co-authored-by: Steve Peters <[email protected]>
- Loading branch information
Showing
14 changed files
with
431 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2021 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 "CustomHeightmapShape.hh" | ||
|
||
#include <vector> | ||
#include <ignition/common/Console.hh> | ||
#include <ignition/common/ImageHeightmap.hh> | ||
#include <ignition/math/eigen3/Conversions.hh> | ||
|
||
namespace ignition { | ||
namespace physics { | ||
namespace dartsim { | ||
|
||
///////////////////////////////////////////////// | ||
CustomHeightmapShape::CustomHeightmapShape( | ||
const common::HeightmapData &_input, | ||
const Eigen::Vector3d &_size, | ||
int _subSampling) | ||
: dart::dynamics::HeightmapShape<float>() | ||
{ | ||
double heightmapSizeZ = _input.MaxElevation(); | ||
const bool flipY = false; | ||
const int vertSize = (_input.Width() * _subSampling) - _subSampling + 1; | ||
math::Vector3d scale; | ||
scale.X(_size(0) / vertSize); | ||
scale.Y(_size(1) / vertSize); | ||
|
||
if (math::equal(heightmapSizeZ, 0.0)) | ||
scale.Z(1.0); | ||
else | ||
scale.Z(fabs(_size(2)) / heightmapSizeZ); | ||
|
||
auto sizeIgn = ignition::math::eigen3::convert(_size); | ||
|
||
// We need to make a copy here in order to use the non-const FillHeightMap | ||
// function | ||
common::ImageHeightmap copyData; | ||
try | ||
{ | ||
const auto &image = dynamic_cast<const common::ImageHeightmap &>(_input); | ||
copyData.Load(image.Filename()); | ||
} | ||
catch(const std::bad_cast &) | ||
{ | ||
ignerr << "Only image heightmaps are supported at the moment." << std::endl; | ||
return; | ||
} | ||
|
||
std::vector<float> heightsFloat; | ||
copyData.FillHeightMap(_subSampling, vertSize, sizeIgn, scale, flipY, | ||
heightsFloat); | ||
|
||
this->setHeightField(vertSize, vertSize, heightsFloat); | ||
this->setScale(Vector3(scale.X(), scale.Y(), 1)); | ||
} | ||
} | ||
} | ||
} |
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,48 @@ | ||
/* | ||
* Copyright (C) 2021 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. | ||
* | ||
*/ | ||
|
||
#ifndef IGNITION_PHYSICS_DARTSIM_SRC_CUSTOMHEIGHTMAPSHAPE_HH_ | ||
#define IGNITION_PHYSICS_DARTSIM_SRC_CUSTOMHEIGHTMAPSHAPE_HH_ | ||
|
||
#include <dart/dynamics/HeightmapShape.hpp> | ||
#include <ignition/common/HeightmapData.hh> | ||
|
||
namespace ignition { | ||
namespace physics { | ||
namespace dartsim { | ||
|
||
/// \brief This class creates a custom derivative of dartsim's HeightmapShape | ||
/// class which allows an ignition::common::Heightmap to be converted into a | ||
/// HeightmapShape that can be used by dartsim. | ||
/// Using float precision because Bullet's collision detector doesn't support | ||
/// double. common::HeightmapData also holds floats. | ||
class CustomHeightmapShape : public dart::dynamics::HeightmapShape<float> | ||
{ | ||
/// \brief Constructor | ||
/// \param[in] _input Holds heightmap data. | ||
/// \param[in] _size Heightmap size in meters. | ||
/// \param[in] _subSampling How much to subsample. | ||
public: CustomHeightmapShape( | ||
const common::HeightmapData &_input, | ||
const Eigen::Vector3d &_size, | ||
const int _subSampling); | ||
}; | ||
} | ||
} | ||
} | ||
|
||
#endif // IGNITION_PHYSICS_DARTSIM_SRC_CUSTOMHEIGHTMAPSHAPE_HH_ |
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,10 @@ | ||
ign_add_component(heightmap INTERFACE | ||
GET_TARGET_NAME heightmap) | ||
|
||
target_link_libraries(${heightmap} | ||
INTERFACE | ||
ignition-common${IGN_COMMON_VER}::graphics) | ||
|
||
install( | ||
DIRECTORY include/ | ||
DESTINATION "${IGN_INCLUDE_INSTALL_DIR_FULL}") |
Oops, something went wrong.