35 bool PlaneInferredInfo::searchTheFloor(
36 Eigen::Matrix4f& poseSensor,
Plane& plane)
43 double cosGravityDir = poseSensor.col(1).head(3).dot(plane.
v3normal);
44 if (cosGravityDir < -0.94)
49 if (sensorHeight < 0.7 || sensorHeight > 2.0)
return false;
51 mPbMap.FloorPlane = plane.
id;
54 else if (cosGravityDir > 0.94)
56 else if (fabs(cosGravityDir) < 0.34)
63 for (
unsigned i = 0; i < mPbMap.vPlanes.size(); i++)
65 if (plane.
id == mPbMap.vPlanes[i].id)
continue;
85 bool PlaneInferredInfo::isPlaneCutbyImage(
86 vector<int>& planeIndices,
unsigned& widthSampledImage,
87 unsigned& heightSampledImage,
unsigned threshold)
89 unsigned upperLimWidth = widthSampledImage - threshold;
90 unsigned upperLimHeight = heightSampledImage - threshold;
94 for (
unsigned i = 0; i < planeIndices.size(); i++)
96 u = planeIndices[i] % widthSampledImage;
97 v = planeIndices[i] / widthSampledImage;
100 if (u < threshold || u > upperLimWidth ||
v < threshold ||
114 bool PlaneInferredInfo::isSurroundingBackground(
115 Plane& plane, pcl::PointCloud<pcl::PointXYZRGBA>::Ptr& frame,
116 vector<int>& planeIndices,
unsigned threshold)
121 vector<pair<unsigned, unsigned>> polyImg;
123 for (
unsigned j = 0; j < planeIndices.size(); j++)
124 if (frame->points[planeIndices[j]].x ==
126 frame->points[planeIndices[j]].y ==
128 frame->points[planeIndices[j]].z ==
132 pair<unsigned, unsigned>(
133 planeIndices[j] % frame->width,
134 planeIndices[j] / frame->width));
141 unsigned left = polyImg[0].first, right = polyImg[0].first,
142 up = polyImg[0].second, down = polyImg[0].second;
143 for (
unsigned i = 1; i < polyImg.size(); i++)
145 if (polyImg[i].
first < left)
146 left = polyImg[i].first;
147 else if (polyImg[i].
first > right)
148 right = polyImg[i].first;
149 if (polyImg[i].second < down)
150 down = polyImg[i].second;
151 else if (polyImg[i].second > up)
152 up = polyImg[i].second;
154 pair<int, int> center((left + right) / 2, (up + down) / 2);
158 vector<Eigen::Vector2i> outerPolygon;
159 unsigned Threshold = threshold * frame->width / 640;
160 for (
unsigned i = 1; i < polyImg.size(); i++)
163 double normDir = sqrt(
165 (polyImg[i].
first - center.first) *
166 (polyImg[i].first - center.first) +
167 (polyImg[i].second - center.second) *
168 (polyImg[i].second - center.second)));
169 dir[0] = (polyImg[i].first - center.first) / normDir;
170 dir[1] = (polyImg[i].second - center.second) / normDir;
175 Eigen::Vector2i outVertex;
176 outVertex[0] =
dir[0] * Threshold + polyImg[i].first;
177 outVertex[1] =
dir[1] * Threshold + polyImg[i].second;
178 if (outVertex[0] < 0)
180 else if (outVertex[0] >= static_cast<int>(frame->width))
181 outVertex[0] = frame->width - 1;
182 if (outVertex[1] < 0)
184 else if (outVertex[1] >= static_cast<int>(frame->height))
185 outVertex[1] = frame->height - 1;
187 outerPolygon.push_back(outVertex);
192 for (
unsigned i = 1; i < outerPolygon.size(); i++)
194 double edgeLenght = std::sqrt(
196 (outerPolygon[i][0] - outerPolygon[i - 1][0]) *
197 (outerPolygon[i][0] - outerPolygon[i - 1][0]) +
198 (outerPolygon[i][1] - outerPolygon[i - 1][1]) *
199 (outerPolygon[i][1] - outerPolygon[i - 1][1])));
200 Eigen::Vector2f direction;
202 (outerPolygon[i][0] - outerPolygon[i - 1][0]) / edgeLenght;
204 (outerPolygon[i][1] - outerPolygon[i - 1][1]) / edgeLenght;
211 Eigen::Vector2i outContour;
212 for (
unsigned j = 0; j < edgeLenght; j++)
214 outContour[0] = outerPolygon[i - 1][0] + int(direction[0] * j);
215 outContour[1] = outerPolygon[i - 1][1] + int(direction[1] * j);
217 pcl::PointXYZRGBA& outerPt =
218 frame->points[outContour[0] + outContour[1] * frame->width];
219 if (!pcl_isfinite(outerPt.x))
continue;
223 double dist2Plane = plane.
v3normal.dot(
225 if (dist2Plane > 0.1)
return false;
239 void PlaneInferredInfo::isFullExtent(
Plane& plane,
double newArea)
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr polygonContourPtr
A class used to store a planar feature (Plane for short).
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr outerPolygonPtr
unsigned id
! Parameters to allow the plane-based representation of the map by a graph
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Eigen::Vector3f v3center
! Geometric description
unsigned nFramesAreaIsStable
Eigen::Vector3f getVector3fromPointXYZ(pointPCL &pt)