14 pcl::PointCloud<pcl::PointXYZ> cloud;
15 pcl::fromPCLPointCloud2(mesh.cloud, cloud);
16 pcl::PointXYZ minBound;
17 pcl::PointXYZ maxBound;
18 pcl::getMinMax3D(cloud, minBound, maxBound);
31 pcl::PointCloud<pcl::PointXYZ> cloud;
32 pcl::fromPCLPointCloud2(mesh.cloud, cloud);
34 const Eigen::Vector3f ray = -Eigen::Vector3f::UnitZ();
35 pcl::PointXYZ minBound;
36 pcl::PointXYZ maxBound;
37 pcl::getMinMax3D(cloud, minBound, maxBound);
40 for (
const pcl::Vertices& polygon : mesh.polygons) {
42 assert(polygon.vertices.size() == 3);
44 Eigen::Matrix3f triangleVertexMatrix;
45 triangleVertexMatrix.row(0) = cloud[polygon.vertices[0]].getVector3fMap();
46 triangleVertexMatrix.row(1) = cloud[polygon.vertices[1]].getVector3fMap();
47 triangleVertexMatrix.row(2) = cloud[polygon.vertices[2]].getVector3fMap();
49 float maxX = triangleVertexMatrix.col(0).maxCoeff();
50 float minX = triangleVertexMatrix.col(0).minCoeff();
51 float maxY = triangleVertexMatrix.col(1).maxCoeff();
52 float minY = triangleVertexMatrix.col(1).minCoeff();
61 const Index index(*iterator);
65 Eigen::Vector3f point(vertexPositionXY.x(), vertexPositionXY.y(), maxBound.z + 1.0);
67 Eigen::Vector3f intersectionPoint;
70 if (gridMap.
isValid(index, layer)) {
71 gridMap.
at(layer, index) = std::max(gridMap.
at(layer, index), intersectionPoint.z());
73 gridMap.
at(layer, index) = intersectionPoint.z();
84 const Eigen::Matrix3f& triangleVertexMatrix, Eigen::Vector3f& intersectionPoint) {
93 const Eigen::Vector3f a = triangleVertexMatrix.row(0);
94 const Eigen::Vector3f b = triangleVertexMatrix.row(1);
95 const Eigen::Vector3f c = triangleVertexMatrix.row(2);
96 const Eigen::Vector3f u = b - a;
97 const Eigen::Vector3f v = c - a;
98 const Eigen::Vector3f n = u.cross(v);
99 const float n_dot_ray = n.dot(ray);
101 if (std::fabs(n_dot_ray) < 1e-9) {
105 const float r = n.dot(a - point) / n_dot_ray;
114 constexpr
float delta = 1e-5;
116 const Eigen::Vector3f
w = point + r * ray - a;
117 const float denominator = u.dot(v) * u.dot(v) - u.dot(u) * v.dot(v);
118 const float s_numerator = u.dot(v) * w.dot(v) - v.dot(v) * w.dot(u);
119 const float s = s_numerator / denominator;
120 if (s < (0 - delta) || s > (1 + delta)) {
124 const float t_numerator = u.dot(v) * w.dot(u) - u.dot(u) * w.dot(v);
125 const float t = t_numerator / denominator;
126 if (t < (0 - delta) || s + t > (1 + delta)) {
130 intersectionPoint = a + s * u + t * v;
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
bool getPosition(const Index &index, Position &position) const
bool isValid(const Index &index) const
float & at(const std::string &layer, const Index &index)
TFSIMD_FORCE_INLINE const tfScalar & w() const
void add(const std::string &layer, const double value=NAN)
static bool rayTriangleIntersect(const Eigen::Vector3f &point, const Eigen::Vector3f &ray, const Eigen::Matrix3f &triangleVertices, Eigen::Vector3f &intersectionPoint)
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
static bool addLayerFromPolygonMesh(const pcl::PolygonMesh &mesh, const std::string &layer, grid_map::GridMap &gridMap)
static bool initializeFromPolygonMesh(const pcl::PolygonMesh &mesh, const double resolution, grid_map::GridMap &gridMap)