35 #include "dart/dynamics/HeightmapShape.hpp" 40 #include "dart/common/Console.hpp" 41 #include "dart/dynamics/BoxShape.hpp" 51 std::is_same<S, float>::value || std::is_same<S, double>::value,
52 "Height field needs to be double or float");
59 return getStaticType();
66 static const std::string type
67 =
"HeightmapShape (" + std::string(
typeid(S).name()) +
")";
75 assert(scale[0] > 0.0);
76 assert(scale[1] > 0.0);
77 assert(scale[2] > 0.0);
79 mIsBoundingBoxDirty =
true;
80 mIsVolumeDirty =
true;
95 const std::size_t& width,
96 const std::size_t& depth,
97 const std::vector<S>& heights)
99 assert(heights.size() == width * depth);
100 if ((width * depth) != heights.size())
102 dterr <<
"[HeightmapShape] Size of height field needs to be width*depth=" 103 << width * depth <<
"\n";
108 dtwarn <<
"Empty height field makes no sense.\n";
113 const Eigen::Map<const HeightField> data(heights.data(), depth, width);
115 setHeightField(data);
119 template <
typename S>
124 mMinHeight = heights.minCoeff();
125 mMaxHeight = heights.maxCoeff();
127 mIsBoundingBoxDirty =
true;
128 mIsVolumeDirty =
true;
134 template <
typename S>
141 template <
typename S>
148 template <
typename S>
151 mHeights = mHeights.colwise().reverse().eval();
155 template <
typename S>
162 template <
typename S>
169 template <
typename S>
172 return mHeights.cols();
176 template <
typename S>
179 return mHeights.rows();
183 template <
typename S>
190 template <
typename S>
193 if (mIsBoundingBoxDirty)
197 return BoxShape::computeInertia(getBoundingBox().computeFullExtents(), mass);
201 template <
typename S>
203 Eigen::Vector3d& min, Eigen::Vector3d& max)
const 205 const double dimX = getWidth() * mScale.x();
206 const double dimY = getDepth() * mScale.y();
207 const double dimZ = (mMaxHeight - mMinHeight) * mScale.z();
208 min = Eigen::Vector3d(-dimX * 0.5, -dimY * 0.5, mMinHeight * mScale.z());
209 max = min + Eigen::Vector3d(dimX, dimY, dimZ);
213 template <
typename S>
218 computeBoundingBox(min, max);
219 mBoundingBox.setMin(min);
220 mBoundingBox.setMax(max);
221 mIsBoundingBoxDirty =
false;
225 template <
typename S>
229 const Eigen::Vector3d size = mBoundingBox.getMax() - mBoundingBox.getMin();
230 mVolume = size.x() * size.y() * size.z();
231 mIsVolumeDirty =
false;
Shape for a height map.
Definition: HeightmapShape.hpp:46
Definition: Aspect.cpp:40
HeightmapShape()
Constructor.
Definition: HeightmapShape-impl.hpp:48