49 std::is_same<S, float>::value || std::is_same<S, double>::value,
50 "Height field needs to be double or float");
57 return getStaticType();
64 static const std::string
type
65 =
"HeightmapShape (" + std::string(
typeid(
S).
name()) +
")";
73 assert(scale[0] > 0.0);
74 assert(scale[1] > 0.0);
75 assert(scale[2] > 0.0);
77 mIsBoundingBoxDirty =
true;
78 mIsVolumeDirty =
true;
93 const std::size_t& width,
94 const std::size_t& depth,
95 const std::vector<S>& heights)
97 assert(heights.size() == width * depth);
98 if ((width * depth) != heights.size())
100 dterr <<
"[HeightmapShape] Size of height field needs to be width*depth="
101 << width * depth <<
"\n";
106 dtwarn <<
"Empty height field makes no sense.\n";
111 const Eigen::Map<const HeightField> data(heights.data(), depth, width);
113 setHeightField(data);
117 template <
typename S>
122 mMinHeight = heights.minCoeff();
123 mMaxHeight = heights.maxCoeff();
125 mIsBoundingBoxDirty =
true;
126 mIsVolumeDirty =
true;
132 template <
typename S>
139 template <
typename S>
146 template <
typename S>
149 mHeights = mHeights.colwise().reverse().eval();
153 template <
typename S>
160 template <
typename S>
167 template <
typename S>
170 return mHeights.cols();
174 template <
typename S>
177 return mHeights.rows();
181 template <
typename S>
188 template <
typename S>
191 if (mIsBoundingBoxDirty)
195 return BoxShape::computeInertia(getBoundingBox().computeFullExtents(), mass);
199 template <
typename S>
201 Eigen::Vector3d& min, Eigen::Vector3d& max)
const
203 const double dimX = getWidth() * mScale.x();
204 const double dimY = getDepth() * mScale.y();
205 const double dimZ = (mMaxHeight - mMinHeight) * mScale.z();
206 min = Eigen::Vector3d(-dimX * 0.5, -dimY * 0.5, mMinHeight * mScale.z());
207 max = min + Eigen::Vector3d(dimX, dimY, dimZ);
211 template <
typename S>
216 computeBoundingBox(min, max);
217 mBoundingBox.setMin(min);
218 mBoundingBox.setMax(max);
219 mIsBoundingBoxDirty =
false;
223 template <
typename S>
227 const Eigen::Vector3d size = mBoundingBox.getMax() - mBoundingBox.getMin();
228 mVolume = size.x() * size.y() * size.z();
229 mIsVolumeDirty =
false;
#define dterr
Output an error message.
Definition: Console.hpp:49
#define dtwarn
Output a warning message.
Definition: Console.hpp:46
std::string type
Definition: SdfParser.cpp:82
std::string * name
Definition: SkelParser.cpp:1697
Shape for a height map.
Definition: HeightmapShape.hpp:47
S S
Definition: HeightmapShape.hpp:49
HeightmapShape()
Constructor.
Definition: HeightmapShape-impl.hpp:46
const std::string & getType() const override
Returns a string representing the shape type.
Definition: HeightmapShape-impl.hpp:55
Eigen::Matrix< S, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > HeightField
Definition: HeightmapShape.hpp:53
Eigen::Matrix< S, 3, 1 > Vector3
Definition: HeightmapShape.hpp:51
Definition: BulletCollisionDetector.cpp:65