13 m_threadPool(amountOfThreads), m_amountOfThreads(amountOfThreads), m_obstacleKeepDuration(1, 0) {
19 m_threadPool(4), m_obstacleKeepDuration(1, 0) {
83 void MapDataLayer::updateMap(
const sensor_msgs::msg::Image::ConstSharedPtr& laneDetectionSPtr,
Vector2f currentAbsoluteCarPositionCM,
double currentAbsoluteOrientation) {
89 int pixelLengthInBytes = laneDetectionSPtr->step / laneDetectionSPtr->width;
91 int arrayStartIndex = 0;
92 int arrayWindowSizePerThread = (laneDetectionSPtr->height * laneDetectionSPtr->step) /
m_amountOfThreads;
93 arrayWindowSizePerThread -= arrayWindowSizePerThread % pixelLengthInBytes;
94 int arrayEndIndex = arrayStartIndex + arrayWindowSizePerThread;
98 arrayEndIndex = (laneDetectionSPtr->height * laneDetectionSPtr->step) - 1;
100 arrayEndIndex = arrayStartIndex + arrayWindowSizePerThread;
105 arrayStartIndex = arrayEndIndex;
121 if(p_position[1] > mLeftTriangle * p_position[0] + nLeftTriangle) {
135 if(p_position[1] > mRightTriangle * p_position[0] + nRightTriangle) {
142 void MapDataLayer::preprocessPoints(
const sensor_msgs::msg::Image::ConstSharedPtr& laneDetectionSPtr,
Vector2f const& currentPositionCM,
int arrayOffsetStartIndex,
int arrayOffsetEndIndex,
double currentAbsoluteOrientation) {
145 Eigen::Rotation2Df rotationMatrix(-currentAbsoluteOrientation);
149 int pixelLengthInBytes = laneDetectionSPtr->step / laneDetectionSPtr->width;
150 for(
int index = arrayOffsetStartIndex; index < arrayOffsetEndIndex; index += pixelLengthInBytes) {
151 int posXOriginal = (index % laneDetectionSPtr->step) / pixelLengthInBytes;
152 int posYOriginal =
static_cast<int>(index / laneDetectionSPtr->step);
155 int posX = posXOriginal - laneDetectionSPtr->width / 2;
156 int posY = laneDetectionSPtr->height - posYOriginal;
158 absoluteCellPosition = rotationMatrix * absoluteCellPosition;
166 Vector2i absoluteCellPositionOnGrid =
Vector2i(std::round(absoluteCellPosition[0]), std::round(absoluteCellPosition[1]));
171 m_data[absoluteCellPositionOnGrid[0]][absoluteCellPositionOnGrid[1]].imageIgnoreField =
true;
174 updateCell(cellUpdate, absoluteCellPositionOnGrid);
182 if(position[0] < 0 || position[0] >=
m_mapSize[0] || position[1] < 0 || position[1] >=
m_mapSize[1]) {
183 log_warning(
"MapDataLayer::updateCell: cannot update Cell (out of bounds) at Position (", position[0],
",", position[1],
")");
232 if(decreaseValue < cellPtr->leftLine)
237 if(decreaseValue < cellPtr->centerLine)
242 if(decreaseValue < cellPtr->rightLine)
253 Eigen::Rotation2Df rotationMatrix(-absoluteOrientation);
254 Eigen::Rotation2Df reverseRotationMatrix(absoluteOrientation);
264 Vector2i absolutePositionInteger =
Vector2i(std::round(absolutePositionCM[0]), std::round(absolutePositionCM[1]));
269 marginX = rotationMatrix * marginX;
270 marginY = rotationMatrix * marginY;
272 std::array<Vector2f, 4> windowEdges;
273 windowEdges[0] = absolutePositionCM - lookBehindVector - marginX;
274 windowEdges[1] = absolutePositionCM - lookBehindVector + marginX;
275 windowEdges[2] = windowEdges[0] + marginY;
276 windowEdges[3] = windowEdges[1] + marginY;
282 if(largerWindowBottomLeftCorner[0] < 0) {
283 log_warning(
"MapDataLayer::getLineObject: lookup (axis aligned) window size out of map size (X smaller than 0)");
284 largerWindowBottomLeftCorner[1] = 0;
286 if(largerWindowTopRightCorner[0] >=
m_mapSize[0]) {
287 log_warning(
"MapDataLayer::getLineObject: lookup (axis aligned) window size out of map size (X larger than map)");
288 largerWindowTopRightCorner[0] =
m_mapSize[0] - 1;
290 if(largerWindowBottomLeftCorner[1] < 0) {
291 log_warning(
"MapDataLayer::getLineObject: lookup (axis aligned) window size out of map size (Y smaller than 0)");
292 largerWindowBottomLeftCorner[1] = 0;
294 if(largerWindowTopRightCorner[1] >=
m_mapSize[1]) {
295 log_warning(
"MapDataLayer::getLineObject: lookup (axis aligned) window size out of map size (Y larger than map)");
296 largerWindowTopRightCorner[1] =
m_mapSize[1] - 1;
299 int largerWindowStepsPerThread = (largerWindowTopRightCorner[0] - largerWindowBottomLeftCorner[0]) /
m_amountOfThreads;
301 int arrayStartX = largerWindowBottomLeftCorner[0];
302 int arrayEndX = arrayStartX + largerWindowStepsPerThread;
303 int arrayStartY = largerWindowBottomLeftCorner[1];
304 int arrayEndY = largerWindowTopRightCorner[1];
308 arrayEndX = largerWindowTopRightCorner[0] + 1;
310 arrayEndX = arrayStartX + largerWindowStepsPerThread;
315 arrayStartX = arrayEndX;
322 m_linesObjectSPtr->windowSize =
Vector2i(largerWindowTopRightCorner[0] - largerWindowBottomLeftCorner[0], largerWindowTopRightCorner[1] - largerWindowBottomLeftCorner[1]);
331 return (x2 - x1) * (yp - y1) - (xp - x1) * (y2 - y1);
336 for(
int x = arrayStartX; x < arrayEndX; ++x) {
337 for(
int y = arrayStartY; y <= arrayEndY; ++y) {
360 m_linesObjectSPtr->leftLine.insert(x - absoluteCarPosition[0], y - absoluteCarPosition[1]);
363 m_linesObjectSPtr->centerLine.insert(x - absoluteCarPosition[0], y - absoluteCarPosition[1]);
366 m_linesObjectSPtr->rightLine.insert(x - absoluteCarPosition[0], y - absoluteCarPosition[1]);
392 Vector2f obsPosition =
Vector2f(p_obstacle.pos_x * 100, p_obstacle.pos_y * 100);
393 Eigen::Rotation2Df rotationMat(-currentOrientation);
394 obsPosition = rotationMat * obsPosition;
395 obsPosition += absolutePositionCM;
397 bool obstacleUpdated =
false;
399 Vector2f distanceDiff = obsPosition - obstacleStatic.get_position_now();
402 obstacleStatic.update_position(timestamp, obsPosition);
403 obstacleUpdated =
true;
408 if(obstacleUpdated ==
false) {
409 StaticObstacle newObstacle(timestamp, obsPosition, p_obstacle.width * 100);