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;
91 const std::size_t& width,
92 const std::size_t& depth,
93 const std::vector<S>& heights)
95 assert(heights.size() == width * depth);
96 if ((width * depth) != heights.size())
98 dterr <<
"Size of height field needs to be width*depth=" << width * depth
104 dtwarn <<
"Empty height field makes no sense." << std::endl;
108 for (
size_t r = 0; r < depth; ++r)
110 for (
size_t c = 0; c < width; ++c)
112 mHeights(r, c) = heights[r * width + c];
117 mMinHeight = std::numeric_limits<S>::max();
118 mMaxHeight = -std::numeric_limits<S>::max();
119 for (
auto it = heights.begin(); it != heights.end(); ++it)
121 if (*it < mMinHeight)
123 if (*it > mMaxHeight)
126 mIsBoundingBoxDirty =
true;
127 mIsVolumeDirty =
true;
148 mHeights = mHeights.colwise().reverse().eval();
169 return mHeights.cols();
176 return mHeights.rows();
183 if (mIsBoundingBoxDirty)
193 Eigen::Vector3d& min, Eigen::Vector3d& max)
const
195 const double dimX = getWidth() * mScale.x();
196 const double dimY = getDepth() * mScale.y();
197 const double dimZ = (mMaxHeight - mMinHeight) * mScale.z();
198 min = Eigen::Vector3d(-dimX * 0.5, -dimY * 0.5, mMinHeight * mScale.z());
199 max = min + Eigen::Vector3d(dimX, dimY, dimZ);
208 computeBoundingBox(min, max);
209 mBoundingBox.setMin(min);
210 mBoundingBox.setMax(max);
211 mIsBoundingBoxDirty =
false;
219 const Eigen::Vector3d size = mBoundingBox.getMax() - mBoundingBox.getMin();
220 mVolume = size.x() * size.y() * size.z();
221 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:1642
static Eigen::Matrix3d computeInertia(const Eigen::Vector3d &size, double mass)
Compute moments of inertia of a box.
Definition BoxShape.cpp:75
const HeightField & getHeightField() const
Returns the height field.
Definition HeightmapShape-impl.hpp:132
const Eigen::Vector3d & getScale() const
Returns scale of this heightmap.
Definition HeightmapShape-impl.hpp:83
std::size_t getWidth() const
Returns the width dimension of the height field.
Definition HeightmapShape-impl.hpp:167
void setScale(const Eigen::Vector3d &scale)
Sets scale of this heightmap.
Definition HeightmapShape-impl.hpp:71
Eigen::Matrix3d computeInertia(double mass) const override
Computes the inertia.
Definition HeightmapShape-impl.hpp:181
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:192
void updateVolume() const override
Updates volume.
Definition HeightmapShape-impl.hpp:216
static const std::string & getStaticType()
Returns shape type for this class.
Definition HeightmapShape-impl.hpp:62
HeightField & getHeightFieldModifiable() const
Returns the modified height field. See also setHeightField().
Definition HeightmapShape-impl.hpp:139
void flipY() const
Flips the y values in the height field.
Definition HeightmapShape-impl.hpp:146
void updateBoundingBox() const override
Updates bounding box.
Definition HeightmapShape-impl.hpp:204
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:52
std::size_t getDepth() const
Returns the height dimension of the height field.
Definition HeightmapShape-impl.hpp:174
S getMinHeight() const
Returns the minimum height set by setHeightField()
Definition HeightmapShape-impl.hpp:160
S getMaxHeight() const
Returns the maximum height set by setHeightField()
Definition HeightmapShape-impl.hpp:153
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:90
Definition BulletCollisionDetector.cpp:63