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 ==
131 polyImg.push_back(pair<unsigned, unsigned>(
132 planeIndices[j] % frame->width,
133 planeIndices[j] / frame->width));
140 unsigned left = polyImg[0].first, right = polyImg[0].first,
141 up = polyImg[0].second, down = polyImg[0].second;
142 for (
unsigned i = 1; i < polyImg.size(); i++)
144 if (polyImg[i].
first < left)
145 left = polyImg[i].first;
146 else if (polyImg[i].
first > right)
147 right = polyImg[i].first;
148 if (polyImg[i].second < down)
149 down = polyImg[i].second;
150 else if (polyImg[i].second > up)
151 up = polyImg[i].second;
153 pair<int, int> center((left + right) / 2, (up + down) / 2);
157 vector<Eigen::Vector2i> outerPolygon;
158 unsigned Threshold = threshold * frame->width / 640;
159 for (
unsigned i = 1; i < polyImg.size(); i++)
162 double normDir = sqrt(
double(
163 (polyImg[i].
first - center.first) *
164 (polyImg[i].first - center.first) +
165 (polyImg[i].second - center.second) *
166 (polyImg[i].second - center.second)));
167 dir[0] = (polyImg[i].first - center.first) / normDir;
168 dir[1] = (polyImg[i].second - center.second) / normDir;
173 Eigen::Vector2i outVertex;
174 outVertex[0] =
dir[0] * Threshold + polyImg[i].first;
175 outVertex[1] =
dir[1] * Threshold + polyImg[i].second;
176 if (outVertex[0] < 0)
178 else if (outVertex[0] >= static_cast<int>(frame->width))
179 outVertex[0] = frame->width - 1;
180 if (outVertex[1] < 0)
182 else if (outVertex[1] >= static_cast<int>(frame->height))
183 outVertex[1] = frame->height - 1;
185 outerPolygon.push_back(outVertex);
190 for (
unsigned i = 1; i < outerPolygon.size(); i++)
192 double edgeLenght = std::sqrt(static_cast<double>(
193 (outerPolygon[i][0] - outerPolygon[i - 1][0]) *
194 (outerPolygon[i][0] - outerPolygon[i - 1][0]) +
195 (outerPolygon[i][1] - outerPolygon[i - 1][1]) *
196 (outerPolygon[i][1] - outerPolygon[i - 1][1])));
197 Eigen::Vector2f direction;
199 (outerPolygon[i][0] - outerPolygon[i - 1][0]) / edgeLenght;
201 (outerPolygon[i][1] - outerPolygon[i - 1][1]) / edgeLenght;
208 Eigen::Vector2i outContour;
209 for (
unsigned j = 0; j < edgeLenght; j++)
211 outContour[0] = outerPolygon[i - 1][0] + int(direction[0] * j);
212 outContour[1] = outerPolygon[i - 1][1] + int(direction[1] * j);
214 pcl::PointXYZRGBA& outerPt =
215 frame->points[outContour[0] + outContour[1] * frame->width];
216 if (!pcl_isfinite(outerPt.x))
continue;
220 double dist2Plane = plane.
v3normal.dot(
222 if (dist2Plane > 0.1)
return false;
236 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)