MCPcopy Create free account
hub / github.com/ANYbotics/grid_map / atPositionLinearInterpolated

Method atPositionLinearInterpolated

grid_map_core/src/GridMap.cpp:766–833  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764}
765
766bool GridMap::atPositionLinearInterpolated(const std::string& layer, const Position& position, float& value) const {
767 Position point;
768 Index indices[4];
769 bool idxTempDir;
770 size_t idxShift[4];
771
772 getIndex(position, indices[0]);
773 getPosition(indices[0], point);
774
775 if (position.x() >= point.x()) {
776 indices[1] = indices[0] + Index(-1, 0); // Second point is above first point.
777 idxTempDir = true;
778 } else {
779 indices[1] = indices[0] + Index(+1, 0);
780 idxTempDir = false;
781 }
782 if (position.y() >= point.y()) {
783 indices[2] = indices[0] + Index(0, -1); // Third point is right of first point.
784 if (idxTempDir) {
785 idxShift[0] = 0;
786 idxShift[1] = 1;
787 idxShift[2] = 2;
788 idxShift[3] = 3;
789 } else {
790 idxShift[0] = 1;
791 idxShift[1] = 0;
792 idxShift[2] = 3;
793 idxShift[3] = 2;
794 }
795
796 } else {
797 indices[2] = indices[0] + Index(0, +1);
798 if (idxTempDir) {
799 idxShift[0] = 2;
800 idxShift[1] = 3;
801 idxShift[2] = 0;
802 idxShift[3] = 1;
803 } else {
804 idxShift[0] = 3;
805 idxShift[1] = 2;
806 idxShift[2] = 1;
807 idxShift[3] = 0;
808 }
809 }
810 indices[3].x() = indices[1].x();
811 indices[3].y() = indices[2].y();
812
813 const Size& mapSize = getSize();
814 const size_t bufferSize = mapSize(0) * mapSize(1);
815 const size_t startIndexLin = getLinearIndexFromIndex(startIndex_, mapSize);
816 const size_t endIndexLin = startIndexLin + bufferSize;
817 const auto& layerMat = operator[](layer);
818 float f[4];
819
820 for (size_t i = 0; i < 4; ++i) {
821 const size_t indexLin = getLinearIndexFromIndex(indices[idxShift[i]], mapSize);
822 if ((indexLin < startIndexLin) || (indexLin > endIndexLin)) return false;
823 f[i] = layerMat(indexLin);

Callers

nothing calls this directly

Calls 1

getLinearIndexFromIndexFunction · 0.85

Tested by

no test coverage detected