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();
61 return {-index[0], -index[1]};
70 return {-vector[0], -vector[1]};
74 return {-vector[0], -vector[1]};
79 return ((bufferStartIndex == 0).all());
84 const Size& bufferSize,
85 const Index& bufferStartIndex)
94 const Size& bufferSize,
95 const Index& bufferStartIndex)
103 if (index[0] >= bufferStartIndex[0] && index[1] >= bufferStartIndex[1])
return BufferRegion::Quadrant::TopLeft;
104 if (index[0] >= bufferStartIndex[0] && index[1] < bufferStartIndex[1])
return BufferRegion::Quadrant::TopRight;
105 if (index[0] < bufferStartIndex[0] && index[1] >= bufferStartIndex[1])
return BufferRegion::Quadrant::BottomLeft;
106 if (index[0] < bufferStartIndex[0] && index[1] < bufferStartIndex[1])
return BufferRegion::Quadrant::BottomRight;
107 return BufferRegion::Quadrant::Undefined;
112 using namespace internal;
118 const double& resolution,
119 const Size& bufferSize,
120 const Index& bufferStartIndex)
133 const double& resolution,
134 const Size& bufferSize,
135 const Index& bufferStartIndex)
139 Vector indexVector = ((position - offset - mapPosition).array() / resolution).matrix();
152 if (positionTransformed.x() >= 0.0 && positionTransformed.y() >= 0.0
153 && positionTransformed.x() < mapLength(0) && positionTransformed.y() < mapLength(1)) {
165 positionOfOrigin = position + vectorToOrigin;
169 const Vector& positionShift,
170 const double& resolution)
172 Vector indexShiftVectorTemp = (positionShift.array() / resolution).matrix();
173 Eigen::Vector2i indexShiftVector;
175 for (
int i = 0; i < indexShiftVector.size(); i++) {
176 indexShiftVector[i] =
static_cast<int>(indexShiftVectorTemp[i] + 0.5 * (indexShiftVectorTemp[i] > 0 ? 1 : -1));
184 const Index& indexShift,
185 const double& resolution)
193 if (index[0] >= 0 && index[1] >= 0 && index[0] < bufferSize[0] && index[1] < bufferSize[1])
202 for (
int i = 0; i < index.size(); i++) {
209 if (index < 0) index = 0;
210 else if (index >= bufferSize) index = bufferSize - 1;
215 for (
int i = 0; i < index.size(); i++) {
223 if (index < bufferSize){
226 }
else if(index >= -bufferSize){
230 index = index % bufferSize;
233 }
else if(index < bufferSize*2){
237 index = index % bufferSize;
245 Position positionShifted = position - mapPosition + vectorToOrigin;
248 for (
int i = 0; i < positionShifted.size(); i++) {
250 double epsilon = 10.0 * numeric_limits<double>::epsilon();
251 if (std::fabs(position(i)) > 1.0) epsilon *= std::fabs(position(i));
253 if (positionShifted(i) <= 0) {
254 positionShifted(i) = epsilon;
257 if (positionShifted(i) >= mapLength(i)) {
258 positionShifted(i) = mapLength(i) - epsilon;
263 position = positionShifted + mapPosition - vectorToOrigin;
272 Size& submapBufferSize,
275 Index& requestedIndexInSubmap,
276 const Position& requestedSubmapPosition,
277 const Length& requestedSubmapLength,
280 const double& resolution,
281 const Size& bufferSize,
282 const Index& bufferStartIndex)
288 Position topLeftPosition = requestedSubmapPosition - halfTransform * requestedSubmapLength.matrix();
290 if(!
getIndexFromPosition(submapTopLeftIndex, topLeftPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex))
return false;
294 Position bottomRightPosition = requestedSubmapPosition + halfTransform * requestedSubmapLength.matrix();
296 Index bottomRightIndex;
297 if(!
getIndexFromPosition(bottomRightIndex, bottomRightPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex))
return false;
302 if(!
getPositionFromIndex(topLeftCorner, submapTopLeftIndex, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex))
return false;
303 topLeftCorner -= halfTransform * Position::Constant(resolution);
306 submapBufferSize = bottomRightIndex - topLeftIndex + Index::Ones();
309 submapLength = submapBufferSize.cast<
double>() * resolution;
312 Vector vectorToSubmapOrigin;
314 submapPosition = topLeftCorner - vectorToSubmapOrigin;
318 return getIndexFromPosition(requestedIndexInSubmap, requestedSubmapPosition, submapLength, submapPosition, resolution, submapBufferSize);
322 const Size& bufferSize,
const Index& bufferStartIndex)
326 return Size(unwrappedBottomRightIndex - unwrappedTopLeftIndex + Size::Ones());
330 const Index& submapIndex,
331 const Size& submapBufferSize,
332 const Size& bufferSize,
333 const Index& bufferStartIndex)
335 if ((
getIndexFromBufferIndex(submapIndex, bufferSize, bufferStartIndex) + submapBufferSize > bufferSize).any())
return false;
337 submapBufferRegions.clear();
339 Index bottomRightIndex = submapIndex + submapBufferSize - Index::Ones();
345 if (quadrantOfTopLeft == BufferRegion::Quadrant::TopLeft) {
347 if (quadrantOfBottomRight == BufferRegion::Quadrant::TopLeft) {
348 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::TopLeft));
352 if (quadrantOfBottomRight == BufferRegion::Quadrant::TopRight) {
353 Size topLeftSize(submapBufferSize(0), bufferSize(1) - submapIndex(1));
354 submapBufferRegions.push_back(
BufferRegion(submapIndex, topLeftSize, BufferRegion::Quadrant::TopLeft));
356 Index topRightIndex(submapIndex(0), 0);
357 Size topRightSize(submapBufferSize(0), submapBufferSize(1) - topLeftSize(1));
358 submapBufferRegions.push_back(
BufferRegion(topRightIndex, topRightSize, BufferRegion::Quadrant::TopRight));
362 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomLeft) {
363 Size topLeftSize(bufferSize(0) - submapIndex(0), submapBufferSize(1));
364 submapBufferRegions.push_back(
BufferRegion(submapIndex, topLeftSize, BufferRegion::Quadrant::TopLeft));
366 Index bottomLeftIndex(0, submapIndex(1));
367 Size bottomLeftSize(submapBufferSize(0) - topLeftSize(0), submapBufferSize(1));
368 submapBufferRegions.push_back(
BufferRegion(bottomLeftIndex, bottomLeftSize, BufferRegion::Quadrant::BottomLeft));
372 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
373 Size topLeftSize(bufferSize(0) - submapIndex(0), bufferSize(1) - submapIndex(1));
374 submapBufferRegions.push_back(
BufferRegion(submapIndex, topLeftSize, BufferRegion::Quadrant::TopLeft));
376 Index topRightIndex(submapIndex(0), 0);
377 Size topRightSize(bufferSize(0) - submapIndex(0), submapBufferSize(1) - topLeftSize(1));
378 submapBufferRegions.push_back(
BufferRegion(topRightIndex, topRightSize, BufferRegion::Quadrant::TopRight));
380 Index bottomLeftIndex(0, submapIndex(1));
381 Size bottomLeftSize(submapBufferSize(0) - topLeftSize(0), bufferSize(1) - submapIndex(1));
382 submapBufferRegions.push_back(
BufferRegion(bottomLeftIndex, bottomLeftSize, BufferRegion::Quadrant::BottomLeft));
384 Index bottomRightIndex = Index::Zero();
385 Size bottomRightSize(bottomLeftSize(0), topRightSize(1));
386 submapBufferRegions.push_back(
BufferRegion(bottomRightIndex, bottomRightSize, BufferRegion::Quadrant::BottomRight));
390 }
else if (quadrantOfTopLeft == BufferRegion::Quadrant::TopRight) {
392 if (quadrantOfBottomRight == BufferRegion::Quadrant::TopRight) {
393 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::TopRight));
397 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
399 Size topRightSize(bufferSize(0) - submapIndex(0), submapBufferSize(1));
400 submapBufferRegions.push_back(
BufferRegion(submapIndex, topRightSize, BufferRegion::Quadrant::TopRight));
402 Index bottomRightIndex(0, submapIndex(1));
403 Size bottomRightSize(submapBufferSize(0) - topRightSize(0), submapBufferSize(1));
404 submapBufferRegions.push_back(
BufferRegion(bottomRightIndex, bottomRightSize, BufferRegion::Quadrant::BottomRight));
408 }
else if (quadrantOfTopLeft == BufferRegion::Quadrant::BottomLeft) {
410 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomLeft) {
411 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::BottomLeft));
415 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
416 Size bottomLeftSize(submapBufferSize(0), bufferSize(1) - submapIndex(1));
417 submapBufferRegions.push_back(
BufferRegion(submapIndex, bottomLeftSize, BufferRegion::Quadrant::BottomLeft));
419 Index bottomRightIndex(submapIndex(0), 0);
420 Size bottomRightSize(submapBufferSize(0), submapBufferSize(1) - bottomLeftSize(1));
421 submapBufferRegions.push_back(
BufferRegion(bottomRightIndex, bottomRightSize, BufferRegion::Quadrant::BottomRight));
425 }
else if (quadrantOfTopLeft == BufferRegion::Quadrant::BottomRight) {
427 if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
428 submapBufferRegions.push_back(
BufferRegion(submapIndex, submapBufferSize, BufferRegion::Quadrant::BottomRight));
442 if (unwrappedIndex(1) + 1 < bufferSize(1)) {
448 unwrappedIndex[1] = 0;
460 const Size& submapBufferSize,
const Size& bufferSize,
461 const Index& bufferStartIndex)
464 Index tempIndex = index;
465 Index tempSubmapIndex = submapIndex;
468 if (tempSubmapIndex[1] + 1 < submapBufferSize[1]) {
470 tempSubmapIndex[1]++;
473 tempSubmapIndex[0]++;
474 tempSubmapIndex[1] = 0;
482 tempIndex =
getBufferIndexFromIndex(unwrappedSubmapTopLeftIndex + tempSubmapIndex, bufferSize, bufferStartIndex);
486 submapIndex = tempSubmapIndex;
494 Index index = bufferIndex - bufferStartIndex;
503 Index bufferIndex = index + bufferStartIndex;
510 if (!rowMajor)
return index(1) * bufferSize(0) + index(0);
511 return index(0) * bufferSize(1) + index(1);
516 if (!rowMajor)
return Index((
int)linearIndex % bufferSize(0), (
int)linearIndex / bufferSize(0));
517 return Index((
int)linearIndex / bufferSize(1), (
int)linearIndex % bufferSize(1));
522 colorVector(0) = (colorValue >> 16) & 0x0000ff;
523 colorVector(1) = (colorValue >> 8) & 0x0000ff;
524 colorVector(2) = colorValue & 0x0000ff;
530 Eigen::Vector3i tempColorVector;
532 colorVector = ((tempColorVector.cast<
float>()).array() / 255.0).matrix();
539 const unsigned long tempColorValue = *
reinterpret_cast<const unsigned long*
>(&colorValue);
546 colorValue = ((int)colorVector(0)) << 16 | ((
int)colorVector(1)) << 8 | ((
int)colorVector(2));
553 colors.
longColor = (colorVector(0) << 16) + (colorVector(1) << 8) + colorVector(2);
559 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())
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)
Vector transformBufferOrderToMapFrame(const Index &index)
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())
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)
Index transformMapFrameToBufferOrder(const Eigen::Vector2i &vector)