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);
122 mMinHeight = heights.minCoeff();
123 mMaxHeight = heights.maxCoeff();
125 mIsBoundingBoxDirty =
true;
126 mIsVolumeDirty =
true;
149 mHeights = mHeights.colwise().reverse().eval();
170 return mHeights.cols();
177 return mHeights.rows();
191 if (mIsBoundingBoxDirty)
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);
216 computeBoundingBox(min, max);
217 mBoundingBox.setMin(min);
218 mBoundingBox.setMax(max);
219 mIsBoundingBoxDirty =
false;
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
static Eigen::Matrix3d computeInertia(const Eigen::Vector3d &size, double mass)
Compute moments of inertia of a box.
Definition BoxShape.cpp:73
const HeightField & getHeightField() const
Returns the height field.
Definition HeightmapShape-impl.hpp:133
std::size_t getWidth() const
Returns the width dimension of the height field.
Definition HeightmapShape-impl.hpp:168
Eigen::Matrix3d computeInertia(double mass) const override
Computes the inertia.
Definition HeightmapShape-impl.hpp:189
S S
Definition HeightmapShape.hpp:49
void computeBoundingBox(Eigen::Vector3d &min, Eigen::Vector3d &max) const
Computes the bounding box of the height field.
Definition HeightmapShape-impl.hpp:200
void updateVolume() const override
Updates volume.
Definition HeightmapShape-impl.hpp:224
static const std::string & getStaticType()
Returns shape type for this class.
Definition HeightmapShape-impl.hpp:62
const Vector3 & getScale() const
Returns scale of this heightmap.
Definition HeightmapShape-impl.hpp:85
HeightField & getHeightFieldModifiable() const
Returns the modified height field. See also setHeightField().
Definition HeightmapShape-impl.hpp:140
void flipY() const
Flips the y values in the height field.
Definition HeightmapShape-impl.hpp:147
void updateBoundingBox() const override
Updates bounding box.
Definition HeightmapShape-impl.hpp:212
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
void notifyColorUpdated(const Eigen::Vector4d &color) override
Set the color of this arrow.
Definition HeightmapShape-impl.hpp:182
std::size_t getDepth() const
Returns the height dimension of the height field.
Definition HeightmapShape-impl.hpp:175
S getMinHeight() const
Returns the minimum height set by setHeightField()
Definition HeightmapShape-impl.hpp:161
void setScale(const Vector3 &scale)
Sets scale of this heightmap.
Definition HeightmapShape-impl.hpp:71
S getMaxHeight() const
Returns the maximum height set by setHeightField()
Definition HeightmapShape-impl.hpp:154
void setHeightField(const std::size_t &width, const std::size_t &depth, const std::vector< S > &heights)
Sets the height field.
Definition HeightmapShape-impl.hpp:92
Eigen::Matrix< S, 3, 1 > Vector3
Definition HeightmapShape.hpp:51
Definition BulletCollisionDetector.cpp:65