22 const double resolution,
25 pcl::PointCloud < pcl::PointXYZ > cloud;
26 pcl::fromPCLPointCloud2(mesh.cloud, cloud);
27 pcl::PointXYZ minBound;
28 pcl::PointXYZ maxBound;
29 pcl::getMinMax3D(cloud, minBound, maxBound);
33 (maxBound.y + minBound.y) / 2.0);
40 const std::string& layer,
46 pcl::PointCloud <pcl::PointXYZ> cloud;
47 pcl::fromPCLPointCloud2(mesh.cloud, cloud);
49 const Eigen::Vector3f ray = -Eigen::Vector3f::UnitZ();
50 pcl::PointXYZ minBound;
51 pcl::PointXYZ maxBound;
52 pcl::getMinMax3D(cloud, minBound, maxBound);
55 for (
const pcl::Vertices& polygon : mesh.polygons) {
57 assert(polygon.vertices.size() == 3);
59 Eigen::Matrix3f triangleVertexMatrix;
60 triangleVertexMatrix.row(0) = cloud[polygon.vertices[0]].getVector3fMap();
61 triangleVertexMatrix.row(1) = cloud[polygon.vertices[1]].getVector3fMap();
62 triangleVertexMatrix.row(2) = cloud[polygon.vertices[2]].getVector3fMap();
64 float maxX = triangleVertexMatrix.col(0).maxCoeff();
65 float minX = triangleVertexMatrix.col(0).minCoeff();
66 float maxY = triangleVertexMatrix.col(1).maxCoeff();
67 float minY = triangleVertexMatrix.col(1).minCoeff();
77 const Index index(*iterator);
81 Eigen::Vector3f point(vertexPositionXY.x(), vertexPositionXY.y(),
84 Eigen::Vector3f intersectionPoint;
87 if (gridMap.
isValid(index, layer)) {
88 gridMap.
at(layer, index) = std::max(gridMap.
at(layer, index), intersectionPoint.z());
90 gridMap.
at(layer, index) = intersectionPoint.z();
101 const Eigen::Vector3f& point,
const Eigen::Vector3f& ray,
102 const Eigen::Matrix3f& triangleVertexMatrix,
103 Eigen::Vector3f& intersectionPoint) {
112 const Eigen::Vector3f a = triangleVertexMatrix.row(0);
113 const Eigen::Vector3f b = triangleVertexMatrix.row(1);
114 const Eigen::Vector3f c = triangleVertexMatrix.row(2);
115 const Eigen::Vector3f u = b - a;
116 const Eigen::Vector3f v = c - a;
117 const Eigen::Vector3f n = u.cross(v);
118 const float n_dot_ray = n.dot(ray);
120 if (std::fabs(n_dot_ray) < 1e-9)
return false;
122 const float r = n.dot(a - point) / n_dot_ray;
124 if (r < 0)
return false;
129 constexpr
float delta = 1e-5;
131 const Eigen::Vector3f
w = point + r * ray - a;
132 const float denominator = u.dot(v) * u.dot(v) - u.dot(u) * v.dot(v);
133 const float s_numerator = u.dot(v) * w.dot(v) - v.dot(v) * w.dot(u);
134 const float s = s_numerator / denominator;
135 if (s < (0 - delta) || s > (1 + delta))
return false;
137 const float t_numerator = u.dot(v) * w.dot(u) - u.dot(u) * w.dot(v);
138 const float t = t_numerator / denominator;
139 if (t < (0 - delta) || s + t > (1 + delta))
return false;
141 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
virtual ~GridMapPclConverter()
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)