32 vectorToOrigin = (0.5 * mapLength).matrix();
45 const Length& mapLength,
const double& resolution)
51 vectorToFirstCell = (vectorToOrigin.array() - 0.5 * resolution).matrix();
57 return -Eigen::Matrix2i::Identity();
67 return ((bufferStartIndex == 0).all());
72 const Size& bufferSize,
73 const Index& bufferStartIndex)
82 const Size& bufferSize,
83 const Index& bufferStartIndex)
91 if (index[0] >= bufferStartIndex[0] && index[1] >= bufferStartIndex[1])
return BufferRegion::Quadrant::TopLeft;
92 if (index[0] >= bufferStartIndex[0] && index[1] < bufferStartIndex[1])
return BufferRegion::Quadrant::TopRight;
93 if (index[0] < bufferStartIndex[0] && index[1] >= bufferStartIndex[1])
return BufferRegion::Quadrant::BottomLeft;
94 if (index[0] < bufferStartIndex[0] && index[1] < bufferStartIndex[1])
return BufferRegion::Quadrant::BottomRight;
95 return BufferRegion::Quadrant::Undefined;
100 using namespace internal;
106 const double& resolution,
107 const Size& bufferSize,
108 const Index& bufferStartIndex)
121 const double& resolution,
122 const Size& bufferSize,
123 const Index& bufferStartIndex)
127 Vector indexVector = ((position - offset - mapPosition).array() / resolution).matrix();
141 if (positionTransformed.x() >= 0.0 && positionTransformed.y() >= 0.0
142 && positionTransformed.x() < mapLength(0) && positionTransformed.y() < mapLength(1)) {
154 positionOfOrigin = position + vectorToOrigin;
158 const Vector& positionShift,
159 const double& resolution)
161 Vector indexShiftVectorTemp = (positionShift.array() / resolution).matrix();
162 Eigen::Vector2i indexShiftVector;
164 for (
int i = 0; i < indexShiftVector.size(); i++) {
165 indexShiftVector[i] =
static_cast<int>(indexShiftVectorTemp[i] + 0.5 * (indexShiftVectorTemp[i] > 0 ? 1 : -1));
173 const Index& indexShift,
174 const double& resolution)
182 if (index[0] >= 0 && index[1] >= 0 && index[0] < bufferSize[0] && index[1] < bufferSize[1])
191 for (
int i = 0; i < index.size(); i++) {
198 if (index < 0) index = 0;
199 else if (index >= bufferSize) index = bufferSize - 1;
204 for (
int i = 0; i < index.size(); i++) {
211 if (index < 0) index += ((-index / bufferSize) + 1) * bufferSize;
212 index = index % bufferSize;
219 Position positionShifted = position - mapPosition + vectorToOrigin;
222 for (
int i = 0; i < positionShifted.size(); i++) {
224 double epsilon = 10.0 * numeric_limits<double>::epsilon();
225 if (std::fabs(position(i)) > 1.0) epsilon *= std::fabs(position(i));
227 if (positionShifted(i) <= 0) {
228 positionShifted(i) = epsilon;
231 if (positionShifted(i) >= mapLength(i)) {
232 positionShifted(i) = mapLength(i) - epsilon;
237 position = positionShifted + mapPosition - vectorToOrigin;
246 Size& submapBufferSize,
249 Index& requestedIndexInSubmap,
250 const Position& requestedSubmapPosition,
251 const Length& requestedSubmapLength,
254 const double& resolution,
255 const Size& bufferSize,
256 const Index& bufferStartIndex)
262 Position topLeftPosition = requestedSubmapPosition - transform * 0.5 * requestedSubmapLength.matrix();
264 if(!
getIndexFromPosition(submapTopLeftIndex, topLeftPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex))
return false;
268 Position bottomRightPosition = requestedSubmapPosition + transform * 0.5 * requestedSubmapLength.matrix();
270 Index bottomRightIndex;
271 if(!
getIndexFromPosition(bottomRightIndex, bottomRightPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex))
return false;
276 if(!
getPositionFromIndex(topLeftCorner, submapTopLeftIndex, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex))
return false;
277 topLeftCorner -= transform * Position::Constant(0.5 * resolution);
280 submapBufferSize = bottomRightIndex - topLeftIndex + Index::Ones();
283 submapLength = submapBufferSize.cast<
double>() * resolution;
286 Vector vectorToSubmapOrigin;
288 submapPosition = topLeftCorner - vectorToSubmapOrigin;
292 if(!
getIndexFromPosition(requestedIndexInSubmap, requestedSubmapPosition, submapLength, submapPosition, resolution, submapBufferSize))
return false;
298 const Size& bufferSize,
const Index& bufferStartIndex)
302 return Size(unwrappedBottomRightIndex - unwrappedTopLeftIndex + Size::Ones());
306 const Index& submapIndex,
307 const Size& submapBufferSize,
308 const Size& bufferSize,
309 const Index& bufferStartIndex)
311 if ((
getIndexFromBufferIndex(submapIndex, bufferSize, bufferStartIndex) + submapBufferSize > bufferSize).any())
return false;
313 submapBufferRegions.clear();
315 Index bottomRightIndex = submapIndex + submapBufferSize - Index::Ones();
321 if (quadrantOfTopLeft == BufferRegion::Quadrant::TopLeft) {
323 if (quadrantOfBottomRight == BufferRegion::Quadrant::TopLeft) {
324 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::TopLeft));
328 if (quadrantOfBottomRight == BufferRegion::Quadrant::TopRight) {
329 Size topLeftSize(submapBufferSize(0), bufferSize(1) - submapIndex(1));
330 submapBufferRegions.push_back(
BufferRegion(submapIndex, topLeftSize, BufferRegion::Quadrant::TopLeft));
332 Index topRightIndex(submapIndex(0), 0);
333 Size topRightSize(submapBufferSize(0), submapBufferSize(1) - topLeftSize(1));
334 submapBufferRegions.push_back(
BufferRegion(topRightIndex, topRightSize, BufferRegion::Quadrant::TopRight));
338 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomLeft) {
339 Size topLeftSize(bufferSize(0) - submapIndex(0), submapBufferSize(1));
340 submapBufferRegions.push_back(
BufferRegion(submapIndex, topLeftSize, BufferRegion::Quadrant::TopLeft));
342 Index bottomLeftIndex(0, submapIndex(1));
343 Size bottomLeftSize(submapBufferSize(0) - topLeftSize(0), submapBufferSize(1));
344 submapBufferRegions.push_back(
BufferRegion(bottomLeftIndex, bottomLeftSize, BufferRegion::Quadrant::BottomLeft));
348 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
349 Size topLeftSize(bufferSize(0) - submapIndex(0), bufferSize(1) - submapIndex(1));
350 submapBufferRegions.push_back(
BufferRegion(submapIndex, topLeftSize, BufferRegion::Quadrant::TopLeft));
352 Index topRightIndex(submapIndex(0), 0);
353 Size topRightSize(bufferSize(0) - submapIndex(0), submapBufferSize(1) - topLeftSize(1));
354 submapBufferRegions.push_back(
BufferRegion(topRightIndex, topRightSize, BufferRegion::Quadrant::TopRight));
356 Index bottomLeftIndex(0, submapIndex(1));
357 Size bottomLeftSize(submapBufferSize(0) - topLeftSize(0), bufferSize(1) - submapIndex(1));
358 submapBufferRegions.push_back(
BufferRegion(bottomLeftIndex, bottomLeftSize, BufferRegion::Quadrant::BottomLeft));
360 Index bottomRightIndex = Index::Zero();
361 Size bottomRightSize(bottomLeftSize(0), topRightSize(1));
362 submapBufferRegions.push_back(
BufferRegion(bottomRightIndex, bottomRightSize, BufferRegion::Quadrant::BottomRight));
366 }
else if (quadrantOfTopLeft == BufferRegion::Quadrant::TopRight) {
368 if (quadrantOfBottomRight == BufferRegion::Quadrant::TopRight) {
369 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::TopRight));
373 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
375 Size topRightSize(bufferSize(0) - submapIndex(0), submapBufferSize(1));
376 submapBufferRegions.push_back(
BufferRegion(submapIndex, topRightSize, BufferRegion::Quadrant::TopRight));
378 Index bottomRightIndex(0, submapIndex(1));
379 Size bottomRightSize(submapBufferSize(0) - topRightSize(0), submapBufferSize(1));
380 submapBufferRegions.push_back(
BufferRegion(bottomRightIndex, bottomRightSize, BufferRegion::Quadrant::BottomRight));
384 }
else if (quadrantOfTopLeft == BufferRegion::Quadrant::BottomLeft) {
386 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomLeft) {
387 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::BottomLeft));
391 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
392 Size bottomLeftSize(submapBufferSize(0), bufferSize(1) - submapIndex(1));
393 submapBufferRegions.push_back(
BufferRegion(submapIndex, bottomLeftSize, BufferRegion::Quadrant::BottomLeft));
395 Index bottomRightIndex(submapIndex(0), 0);
396 Size bottomRightSize(submapBufferSize(0), submapBufferSize(1) - bottomLeftSize(1));
397 submapBufferRegions.push_back(
BufferRegion(bottomRightIndex, bottomRightSize, BufferRegion::Quadrant::BottomRight));
401 }
else if (quadrantOfTopLeft == BufferRegion::Quadrant::BottomRight) {
403 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
404 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::BottomRight));
418 if (unwrappedIndex(1) + 1 < bufferSize(1)) {
424 unwrappedIndex[1] = 0;
436 const Size& submapBufferSize,
const Size& bufferSize,
437 const Index& bufferStartIndex)
440 Index tempIndex = index;
441 Index tempSubmapIndex = submapIndex;
444 if (tempSubmapIndex[1] + 1 < submapBufferSize[1]) {
446 tempSubmapIndex[1]++;
449 tempSubmapIndex[0]++;
450 tempSubmapIndex[1] = 0;
458 tempIndex =
getBufferIndexFromIndex(unwrappedSubmapTopLeftIndex + tempSubmapIndex, bufferSize, bufferStartIndex);
462 submapIndex = tempSubmapIndex;
470 Index index = bufferIndex - bufferStartIndex;
479 Index bufferIndex = index + bufferStartIndex;
486 if (!rowMajor)
return index(1) * bufferSize(0) + index(0);
487 return index(0) * bufferSize(1) + index(1);
492 if (!rowMajor)
return Index((
int)linearIndex % bufferSize(0), (
int)linearIndex / bufferSize(0));
493 return Index((
int)linearIndex / bufferSize(1), (
int)linearIndex % bufferSize(1));
497 std::vector<Index> indices)
507 std::vector<Index> indices)
513 colorVector(0) = (colorValue >> 16) & 0x0000ff;
514 colorVector(1) = (colorValue >> 8) & 0x0000ff;
515 colorVector(2) = colorValue & 0x0000ff;
521 Eigen::Vector3i tempColorVector;
523 colorVector = ((tempColorVector.cast<
float>()).array() / 255.0).matrix();
530 const unsigned long tempColorValue = *
reinterpret_cast<const unsigned long*
>(&colorValue);
537 colorValue = ((int)colorVector(0)) << 16 | ((
int)colorVector(1)) << 8 | ((
int)colorVector(2));
543 unsigned long color = (colorVector(0) << 16) + (colorVector(1) << 8) + colorVector(2);
545 colorValue = *
reinterpret_cast<float*
>(&color);
550 Eigen::Vector3i tempColorVector = (colorVector * 255.0).cast<
int>();
bool incrementIndexForSubmap(Index &submapIndex, Index &index, const Index &submapTopLeftIndex, const Size &submapBufferSize, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
void wrapIndexToRange(Index &index, const Size &bufferSize)
bool getBufferRegionsForSubmap(std::vector< BufferRegion > &submapBufferRegions, const Index &submapIndex, const Size &submapBufferSize, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
Index getIndexFromBufferIndex(const Index &bufferIndex, const Size &bufferSize, const Index &bufferStartIndex)
bool getSubmapInformation(Index &submapTopLeftIndex, Size &submapBufferSize, Position &submapPosition, Length &submapLength, Index &requestedIndexInSubmap, const Position &requestedSubmapPosition, const Length &requestedSubmapLength, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
void getIndicesForRegions(const std::vector< Index > ®ionIndeces, const Size ®ionSizes, std::vector< Index > indices)
Index getIndexFromIndexVector(const Vector &indexVector, const Size &bufferSize, const Index &bufferStartIndex)
bool getIndexFromPosition(Index &index, const Position &position, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
Eigen::Matrix2i getBufferOrderToMapFrameTransformation()
bool checkIfPositionWithinMap(const Position &position, const Length &mapLength, const Position &mapPosition)
bool getPositionShiftFromIndexShift(Vector &positionShift, const Index &indexShift, const double &resolution)
bool colorVectorToValue(const Eigen::Vector3i &colorVector, unsigned long &colorValue)
bool incrementIndex(Index &index, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
Size getSubmapSizeFromCornerIndeces(const Index &topLeftIndex, const Index &bottomRightIndex, const Size &bufferSize, const Index &bufferStartIndex)
const Eigen::Matrix2i getBufferOrderToMapFrameAlignment()
bool getVectorToOrigin(Vector &vectorToOrigin, const Length &mapLength)
void getPositionOfDataStructureOrigin(const Position &position, const Length &mapLength, Position &positionOfOrigin)
Index getIndexFromLinearIndex(const size_t linearIndex, const Size &bufferSize, const bool rowMajor=false)
BufferRegion::Quadrant getQuadrant(const Index &index, const Index &bufferStartIndex)
void boundIndexToRange(Index &index, const Size &bufferSize)
bool checkIfIndexInRange(const Index &index, const Size &bufferSize)
Vector getIndexVectorFromIndex(const Index &index, const Size &bufferSize, const Index &bufferStartIndex)
size_t getLinearIndexFromIndex(const Index &index, const Size &bufferSize, const bool rowMajor=false)
bool getPositionFromIndex(Position &position, const Index &index, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
void getIndicesForRegion(const Index ®ionIndex, const Size ®ionSize, std::vector< Index > indices)
Index getBufferIndexFromIndex(const Index &index, const Size &bufferSize, const Index &bufferStartIndex)
bool getVectorToFirstCell(Vector &vectorToFirstCell, const Length &mapLength, const double &resolution)
void boundPositionToRange(Position &position, const Length &mapLength, const Position &mapPosition)
bool colorValueToVector(const unsigned long &colorValue, Eigen::Vector3i &colorVector)
bool getIndexShiftFromPositionShift(Index &indexShift, const Vector &positionShift, const double &resolution)
Eigen::Matrix2i getMapFrameToBufferOrderTransformation()
bool checkIfStartIndexAtDefaultPosition(const Index &bufferStartIndex)