-
Notifications
You must be signed in to change notification settings - Fork 828
/
Copy pathGridMapMath.cpp
671 lines (581 loc) · 20.6 KB
/
GridMapMath.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/*
* GridMapMath.cpp
*
* Created on: Dec 2, 2013
* Author: Péter Fankhauser
* Institute: ETH Zurich, ANYbotics
*/
// fabs
#include <cmath>
// Limits
#include <limits>
#include <vector>
#include "grid_map_core/GridMapMath.hpp"
namespace grid_map
{
namespace internal
{
/*!
* Gets the vector from the center of the map to the origin
* of the map data structure.
* @param[out] vectorToOrigin the vector from the center of the map the origin of the map data structure.
* @param[in] mapLength the lengths in x and y direction.
* @return true if successful.
*/
inline bool getVectorToOrigin(Vector & vectorToOrigin, const Length & mapLength)
{
vectorToOrigin = (0.5 * mapLength).matrix();
return true;
}
/*!
* Gets the vector from the center of the map to the center
* of the first cell of the map data.
* @param[out] vectorToFirstCell the vector from the center of the cell to the center of the map.
* @param[in] mapLength the lengths in x and y direction.
* @param[in] resolution the resolution of the map.
* @return true if successful.
*/
inline bool getVectorToFirstCell(
Vector & vectorToFirstCell,
const Length & mapLength, const double & resolution)
{
Vector vectorToOrigin;
getVectorToOrigin(vectorToOrigin, mapLength);
// Vector to center of cell.
vectorToFirstCell = (vectorToOrigin.array() - 0.5 * resolution).matrix();
return true;
}
inline Eigen::Matrix2i getBufferOrderToMapFrameTransformation()
{
return -Eigen::Matrix2i::Identity();
}
inline Vector transformBufferOrderToMapFrame(const Index & index)
{
return {-index[0], -index[1]};
}
inline Eigen::Matrix2i getMapFrameToBufferOrderTransformation()
{
return getBufferOrderToMapFrameTransformation().transpose();
}
inline Index transformMapFrameToBufferOrder(const Vector & vector)
{
return {-vector[0], -vector[1]};
}
inline Index transformMapFrameToBufferOrder(const Eigen::Vector2i & vector)
{
return {-vector[0], -vector[1]};
}
inline bool checkIfStartIndexAtDefaultPosition(const Index & bufferStartIndex)
{
return (bufferStartIndex == 0).all();
}
inline Vector getIndexVectorFromIndex(
const Index & index,
const Size & bufferSize,
const Index & bufferStartIndex)
{
Index unwrappedIndex;
unwrappedIndex = getIndexFromBufferIndex(index, bufferSize, bufferStartIndex);
return transformBufferOrderToMapFrame(unwrappedIndex);
}
inline Index getIndexFromIndexVector(
const Vector & indexVector,
const Size & bufferSize,
const Index & bufferStartIndex)
{
Index index = transformMapFrameToBufferOrder(indexVector);
return getBufferIndexFromIndex(index, bufferSize, bufferStartIndex);
}
inline BufferRegion::Quadrant getQuadrant(const Index & index, const Index & bufferStartIndex)
{
if (index[0] >= bufferStartIndex[0] && index[1] >= bufferStartIndex[1]) {
return BufferRegion::Quadrant::TopLeft;
}
if (index[0] >= bufferStartIndex[0] && index[1] < bufferStartIndex[1]) {
return BufferRegion::Quadrant::TopRight;
}
if (index[0] < bufferStartIndex[0] && index[1] >= bufferStartIndex[1]) {
return BufferRegion::Quadrant::BottomLeft;
}
if (index[0] < bufferStartIndex[0] && index[1] < bufferStartIndex[1]) {
return BufferRegion::Quadrant::BottomRight;
}
return BufferRegion::Quadrant::Undefined;
}
} // namespace internal
bool getPositionFromIndex(
Position & position,
const Index & index,
const Length & mapLength,
const Position & mapPosition,
const double & resolution,
const Size & bufferSize,
const Index & bufferStartIndex)
{
if (!checkIfIndexInRange(index, bufferSize)) {return false;}
Vector offset;
internal::getVectorToFirstCell(offset, mapLength, resolution);
position = mapPosition + offset + resolution * internal::getIndexVectorFromIndex(
index, bufferSize,
bufferStartIndex);
return true;
}
bool getIndexFromPosition(
Index & index,
const Position & position,
const Length & mapLength,
const Position & mapPosition,
const double & resolution,
const Size & bufferSize,
const Index & bufferStartIndex)
{
Vector offset;
internal::getVectorToOrigin(offset, mapLength);
Vector indexVector = ((position - offset - mapPosition).array() / resolution).matrix();
index = internal::getIndexFromIndexVector(indexVector, bufferSize, bufferStartIndex);
return checkIfPositionWithinMap(position, mapLength, mapPosition) && checkIfIndexInRange(index,
bufferSize);
}
bool checkIfPositionWithinMap(
const Position & position,
const Length & mapLength,
const Position & mapPosition)
{
Vector offset;
internal::getVectorToOrigin(offset, mapLength);
Position positionTransformed = internal::getMapFrameToBufferOrderTransformation().cast<double>() *
(position - mapPosition - offset);
if (positionTransformed.x() >= 0.0 && positionTransformed.y() >= 0.0 &&
positionTransformed.x() < mapLength(0) && positionTransformed.y() < mapLength(1))
{
return true;
}
return false;
}
void getPositionOfDataStructureOrigin(
const Position & position,
const Length & mapLength,
Position & positionOfOrigin)
{
Vector vectorToOrigin;
internal::getVectorToOrigin(vectorToOrigin, mapLength);
positionOfOrigin = position + vectorToOrigin;
}
bool getIndexShiftFromPositionShift(
Index & indexShift,
const Vector & positionShift,
const double & resolution)
{
Vector indexShiftVectorTemp = (positionShift.array() / resolution).matrix();
Eigen::Vector2i indexShiftVector;
for (int i = 0; i < indexShiftVector.size(); i++) {
indexShiftVector[i] =
static_cast<int>(indexShiftVectorTemp[i] + 0.5 * (indexShiftVectorTemp[i] > 0 ? 1 : -1));
}
indexShift = internal::transformMapFrameToBufferOrder(indexShiftVector);
return true;
}
bool getPositionShiftFromIndexShift(
Vector & positionShift,
const Index & indexShift,
const double & resolution)
{
positionShift = internal::transformBufferOrderToMapFrame(indexShift) * resolution;
return true;
}
bool checkIfIndexInRange(const Index & index, const Size & bufferSize)
{
if (index[0] >= 0 && index[1] >= 0 && index[0] < bufferSize[0] && index[1] < bufferSize[1]) {
return true;
}
return false;
}
void boundIndexToRange(Index & index, const Size & bufferSize)
{
for (int i = 0; i < index.size(); i++) {
boundIndexToRange(index[i], bufferSize[i]);
}
}
void boundIndexToRange(int & index, const int & bufferSize)
{
if (index < 0) {index = 0;} else if (index >= bufferSize) {index = bufferSize - 1;}
}
void wrapIndexToRange(Index & index, const Size & bufferSize)
{
for (int i = 0; i < index.size(); i++) {
wrapIndexToRange(index[i], bufferSize[i]);
}
}
void wrapIndexToRange(int & index, int bufferSize)
{
index = index % bufferSize;
if (index < 0) {
index += bufferSize;
}
}
void boundPositionToRange(
Position & position, const Length & mapLength,
const Position & mapPosition)
{
Vector vectorToOrigin;
internal::getVectorToOrigin(vectorToOrigin, mapLength);
Position positionShifted = position - mapPosition + vectorToOrigin;
// We have to make sure to stay inside the map.
for (int i = 0; i < positionShifted.size(); i++) {
// TODO(needs_assignment): Why is the factor 10 necessary.
double epsilon = 10.0 * std::numeric_limits<double>::epsilon();
if (std::fabs(position(i)) > 1.0) {epsilon *= std::fabs(position(i));}
if (positionShifted(i) <= 0) {
positionShifted(i) = epsilon;
continue;
}
if (positionShifted(i) >= mapLength(i)) {
positionShifted(i) = mapLength(i) - epsilon;
continue;
}
}
position = positionShifted + mapPosition - vectorToOrigin;
}
const Eigen::Matrix2i getBufferOrderToMapFrameAlignment()
{
return internal::getBufferOrderToMapFrameTransformation().array().abs().matrix();
}
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)
{
// (Top left / bottom right corresponds to the position in the matrix, not the map frame)
const Eigen::Matrix2d halfTransform = 0.5 *
internal::getMapFrameToBufferOrderTransformation().cast<double>();
// Corners of submap.
Position topLeftPosition = requestedSubmapPosition - halfTransform *
requestedSubmapLength.matrix();
boundPositionToRange(topLeftPosition, mapLength, mapPosition);
if (!getIndexFromPosition(
submapTopLeftIndex, topLeftPosition, mapLength, mapPosition, resolution,
bufferSize, bufferStartIndex)) {return false;}
Index topLeftIndex;
topLeftIndex = getIndexFromBufferIndex(submapTopLeftIndex, bufferSize, bufferStartIndex);
Position bottomRightPosition = requestedSubmapPosition + halfTransform *
requestedSubmapLength.matrix();
boundPositionToRange(bottomRightPosition, mapLength, mapPosition);
Index bottomRightIndex;
if (!getIndexFromPosition(
bottomRightIndex, bottomRightPosition, mapLength, mapPosition,
resolution, bufferSize, bufferStartIndex)) {return false;}
bottomRightIndex = getIndexFromBufferIndex(bottomRightIndex, bufferSize, bufferStartIndex);
// Get the position of the top left corner of the generated submap.
Position topLeftCorner;
if (!getPositionFromIndex(
topLeftCorner, submapTopLeftIndex, mapLength, mapPosition, resolution,
bufferSize, bufferStartIndex)) {return false;}
topLeftCorner -= halfTransform * Position::Constant(resolution);
// Size of submap.
submapBufferSize = bottomRightIndex - topLeftIndex + Index::Ones();
// Length of the submap.
submapLength = submapBufferSize.cast<double>() * resolution;
// Position of submap.
Vector vectorToSubmapOrigin;
internal::getVectorToOrigin(vectorToSubmapOrigin, submapLength);
submapPosition = topLeftCorner - vectorToSubmapOrigin;
// Get the index of the cell which corresponds the requested
// position of the submap.
return getIndexFromPosition(
requestedIndexInSubmap, requestedSubmapPosition, submapLength,
submapPosition, resolution, submapBufferSize);
}
Size getSubmapSizeFromCornerIndeces(
const Index & topLeftIndex, const Index & bottomRightIndex,
const Size & bufferSize, const Index & bufferStartIndex)
{
const Index unwrappedTopLeftIndex = getIndexFromBufferIndex(
topLeftIndex, bufferSize,
bufferStartIndex);
const Index unwrappedBottomRightIndex = getIndexFromBufferIndex(
bottomRightIndex, bufferSize,
bufferStartIndex);
return Size(unwrappedBottomRightIndex - unwrappedTopLeftIndex + Size::Ones());
}
bool getBufferRegionsForSubmap(
std::vector<BufferRegion> & submapBufferRegions,
const Index & submapIndex,
const Size & submapBufferSize,
const Size & bufferSize,
const Index & bufferStartIndex)
{
if ((getIndexFromBufferIndex(
submapIndex, bufferSize,
bufferStartIndex) + submapBufferSize > bufferSize).any()) {return false;}
submapBufferRegions.clear();
Index bottomRightIndex = submapIndex + submapBufferSize - Index::Ones();
wrapIndexToRange(bottomRightIndex, bufferSize);
BufferRegion::Quadrant quadrantOfTopLeft = internal::getQuadrant(submapIndex, bufferStartIndex);
BufferRegion::Quadrant quadrantOfBottomRight = internal::getQuadrant(
bottomRightIndex,
bufferStartIndex);
if (quadrantOfTopLeft == BufferRegion::Quadrant::TopLeft) {
if (quadrantOfBottomRight == BufferRegion::Quadrant::TopLeft) {
submapBufferRegions.push_back(
BufferRegion(
submapIndex, submapBufferSize,
BufferRegion::Quadrant::TopLeft));
return true;
}
if (quadrantOfBottomRight == BufferRegion::Quadrant::TopRight) {
Size topLeftSize(submapBufferSize(0), bufferSize(1) - submapIndex(1));
submapBufferRegions.push_back(
BufferRegion(
submapIndex, topLeftSize,
BufferRegion::Quadrant::TopLeft));
Index topRightIndex(submapIndex(0), 0);
Size topRightSize(submapBufferSize(0), submapBufferSize(1) - topLeftSize(1));
submapBufferRegions.push_back(
BufferRegion(
topRightIndex, topRightSize,
BufferRegion::Quadrant::TopRight));
return true;
}
if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomLeft) {
Size topLeftSize(bufferSize(0) - submapIndex(0), submapBufferSize(1));
submapBufferRegions.push_back(
BufferRegion(
submapIndex, topLeftSize,
BufferRegion::Quadrant::TopLeft));
Index bottomLeftIndex(0, submapIndex(1));
Size bottomLeftSize(submapBufferSize(0) - topLeftSize(0), submapBufferSize(1));
submapBufferRegions.push_back(
BufferRegion(
bottomLeftIndex, bottomLeftSize,
BufferRegion::Quadrant::BottomLeft));
return true;
}
if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
Size topLeftSize(bufferSize(0) - submapIndex(0), bufferSize(1) - submapIndex(1));
submapBufferRegions.push_back(
BufferRegion(
submapIndex, topLeftSize,
BufferRegion::Quadrant::TopLeft));
Index topRightIndex(submapIndex(0), 0);
Size topRightSize(bufferSize(0) - submapIndex(0), submapBufferSize(1) - topLeftSize(1));
submapBufferRegions.push_back(
BufferRegion(
topRightIndex, topRightSize,
BufferRegion::Quadrant::TopRight));
Index bottomLeftIndex(0, submapIndex(1));
Size bottomLeftSize(submapBufferSize(0) - topLeftSize(0), bufferSize(1) - submapIndex(1));
submapBufferRegions.push_back(
BufferRegion(
bottomLeftIndex, bottomLeftSize,
BufferRegion::Quadrant::BottomLeft));
Index bottomRightIndex = Index::Zero();
Size bottomRightSize(bottomLeftSize(0), topRightSize(1));
submapBufferRegions.push_back(
BufferRegion(
bottomRightIndex, bottomRightSize,
BufferRegion::Quadrant::BottomRight));
return true;
}
} else if (quadrantOfTopLeft == BufferRegion::Quadrant::TopRight) {
if (quadrantOfBottomRight == BufferRegion::Quadrant::TopRight) {
submapBufferRegions.push_back(
BufferRegion(
submapIndex, submapBufferSize,
BufferRegion::Quadrant::TopRight));
return true;
}
if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
Size topRightSize(bufferSize(0) - submapIndex(0), submapBufferSize(1));
submapBufferRegions.push_back(
BufferRegion(
submapIndex, topRightSize,
BufferRegion::Quadrant::TopRight));
Index bottomRightIndex(0, submapIndex(1));
Size bottomRightSize(submapBufferSize(0) - topRightSize(0), submapBufferSize(1));
submapBufferRegions.push_back(
BufferRegion(
bottomRightIndex, bottomRightSize,
BufferRegion::Quadrant::BottomRight));
return true;
}
} else if (quadrantOfTopLeft == BufferRegion::Quadrant::BottomLeft) {
if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomLeft) {
submapBufferRegions.push_back(
BufferRegion(
submapIndex, submapBufferSize,
BufferRegion::Quadrant::BottomLeft));
return true;
}
if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
Size bottomLeftSize(submapBufferSize(0), bufferSize(1) - submapIndex(1));
submapBufferRegions.push_back(
BufferRegion(
submapIndex, bottomLeftSize,
BufferRegion::Quadrant::BottomLeft));
Index bottomRightIndex(submapIndex(0), 0);
Size bottomRightSize(submapBufferSize(0), submapBufferSize(1) - bottomLeftSize(1));
submapBufferRegions.push_back(
BufferRegion(
bottomRightIndex, bottomRightSize,
BufferRegion::Quadrant::BottomRight));
return true;
}
} else if (quadrantOfTopLeft == BufferRegion::Quadrant::BottomRight) {
if (quadrantOfBottomRight == BufferRegion::Quadrant::BottomRight) {
submapBufferRegions.push_back(
BufferRegion(
submapIndex, submapBufferSize,
BufferRegion::Quadrant::BottomRight));
return true;
}
}
return false;
}
bool incrementIndex(Index & index, const Size & bufferSize, const Index & bufferStartIndex)
{
Index unwrappedIndex = getIndexFromBufferIndex(index, bufferSize, bufferStartIndex);
// Increment index.
if (unwrappedIndex(1) + 1 < bufferSize(1)) {
// Same row.
unwrappedIndex[1]++;
} else {
// Next row.
unwrappedIndex[0]++;
unwrappedIndex[1] = 0;
}
// End of iterations reached.
if (!checkIfIndexInRange(unwrappedIndex, bufferSize)) {return false;}
// Return true iterated index.
index = getBufferIndexFromIndex(unwrappedIndex, bufferSize, bufferStartIndex);
return true;
}
bool incrementIndexForSubmap(
Index & submapIndex, Index & index, const Index & submapTopLeftIndex,
const Size & submapBufferSize, const Size & bufferSize,
const Index & bufferStartIndex)
{
// Copy the data first, only copy it back if everything is within range.
Index tempIndex = index;
Index tempSubmapIndex = submapIndex;
// Increment submap index.
if (tempSubmapIndex[1] + 1 < submapBufferSize[1]) {
// Same row.
tempSubmapIndex[1]++;
} else {
// Next row.
tempSubmapIndex[0]++;
tempSubmapIndex[1] = 0;
}
// End of iterations reached.
if (!checkIfIndexInRange(tempSubmapIndex, submapBufferSize)) {return false;}
// Get corresponding index in map.
Index unwrappedSubmapTopLeftIndex = getIndexFromBufferIndex(
submapTopLeftIndex, bufferSize,
bufferStartIndex);
tempIndex = getBufferIndexFromIndex(
unwrappedSubmapTopLeftIndex + tempSubmapIndex, bufferSize,
bufferStartIndex);
// Copy data back.
index = tempIndex;
submapIndex = tempSubmapIndex;
return true;
}
Index getIndexFromBufferIndex(
const Index & bufferIndex, const Size & bufferSize,
const Index & bufferStartIndex)
{
if (internal::checkIfStartIndexAtDefaultPosition(bufferStartIndex)) {return bufferIndex;}
Index index = bufferIndex - bufferStartIndex;
wrapIndexToRange(index, bufferSize);
return index;
}
Index getBufferIndexFromIndex(
const Index & index, const Size & bufferSize,
const Index & bufferStartIndex)
{
if (internal::checkIfStartIndexAtDefaultPosition(bufferStartIndex)) {return index;}
Index bufferIndex = index + bufferStartIndex;
wrapIndexToRange(bufferIndex, bufferSize);
return bufferIndex;
}
size_t getLinearIndexFromIndex(const Index & index, const Size & bufferSize, const bool rowMajor)
{
if (!rowMajor) {return index(1) * bufferSize(0) + index(0);}
return index(0) * bufferSize(1) + index(1);
}
Index getIndexFromLinearIndex(
const size_t linearIndex, const Size & bufferSize,
const bool rowMajor)
{
if (!rowMajor) {
return Index(
static_cast<int>(linearIndex) % bufferSize(
0), static_cast<int>(linearIndex) / bufferSize(0));
}
return Index(
static_cast<int>(linearIndex) / bufferSize(
1), static_cast<int>(linearIndex) % bufferSize(1));
}
// void getIndicesForRegion(
// const Index & regionIndex, const Size & regionSize,
// std::vector<Index> indices)
// {
// // for (int i = line.index_; col < line.endIndex(); col++) {
// // for (int i = 0; i < getSize()(0); i++) {
// //
// // }
// // }
// }
// void getIndicesForRegions(
// const std::vector<Index> & regionIndeces, const Size & regionSizes,
// std::vector<Index> indices)
// {
// }
bool colorValueToVector(const uint64_t & colorValue, Eigen::Vector3i & colorVector)
{
colorVector(0) = (colorValue >> 16) & 0x0000ff;
colorVector(1) = (colorValue >> 8) & 0x0000ff;
colorVector(2) = colorValue & 0x0000ff;
return true;
}
bool colorValueToVector(const uint64_t & colorValue, Eigen::Vector3f & colorVector)
{
Eigen::Vector3i tempColorVector;
colorValueToVector(colorValue, tempColorVector);
colorVector = ((tempColorVector.cast<float>()).array() / 255.0).matrix();
return true;
}
bool colorValueToVector(const float & colorValue, Eigen::Vector3f & colorVector)
{
// cppcheck-suppress invalidPointerCast
const uint64_t tempColorValue = *reinterpret_cast<const uint64_t *>(&colorValue);
colorValueToVector(tempColorValue, colorVector);
return true;
}
bool colorVectorToValue(const Eigen::Vector3i & colorVector, uint64_t & colorValue)
{
colorValue = static_cast<int>(colorVector(0)) << 16 | static_cast<int>(colorVector(1)) << 8 |
static_cast<int>(colorVector(2));
return true;
}
void colorVectorToValue(const Eigen::Vector3i & colorVector, float & colorValue)
{
uint64_t color = (colorVector(0) << 16) + (colorVector(1) << 8) + colorVector(2);
float * temp = reinterpret_cast<float *>(&color);
colorValue = *temp;
}
void colorVectorToValue(const Eigen::Vector3f & colorVector, float & colorValue)
{
Eigen::Vector3i tempColorVector = (colorVector * 255.0).cast<int>();
colorVectorToValue(tempColorVector, colorValue);
}
} // namespace grid_map