14 using Tmap = std::vector<signed char>;
33 template <
int U = Dim>
35 return pn(0) +
dim_(0) * pn(1);
38 template <
int U = Dim>
40 return pn(0) +
dim_(0) * pn(1) +
dim_(0) *
dim_(1) * pn(2);
52 for (
int i = 0; i < Dim; i++)
53 if (pn(i) < 0 || pn(i) >=
dim_(i))
return true;
95 std::cout <<
"MapUtil Info ========================== " << std::endl;
96 std::cout <<
" res: [" <<
res_ <<
"]" << std::endl;
97 std::cout <<
" origin: [" <<
origin_d_.transpose() <<
"]" << std::endl;
98 std::cout <<
" range: [" << range.transpose() <<
"]" << std::endl;
99 std::cout <<
" dim: [" <<
dim_.transpose() <<
"]" << std::endl;
105 for (
int i = 0; i < Dim; i++)
120 int max_diff = (diff /
res_).
template lpNorm<Eigen::Infinity>() / k;
126 for (
int n = 1; n < max_diff; n++) {
130 if (new_pn != prev_pn) pns.push_back(new_pn);
137 template <
int U = Dim>
138 typename std::enable_if<U == 3, vec_Vec3f>::type
getCloud() {
141 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
142 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
143 for (n(2) = 0; n(2) <
dim_(2); n(2)++) {
151 template <
int U = Dim>
152 typename std::enable_if<U == 2, vec_Vec2f>::type
getCloud() {
156 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
157 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
165 template <
int U = Dim>
169 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
170 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
171 for (n(2) = 0; n(2) <
dim_(2); n(2)++) {
180 template <
int U = Dim>
184 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
185 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
193 template <
int U = Dim>
197 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
198 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
199 for (n(2) = 0; n(2) <
dim_(2); n(2)++) {
208 template <
int U = Dim>
212 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
213 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
221 template <
int U = Dim>
222 typename std::enable_if<U == 3>::type
dilate(
226 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
227 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
228 for (n(2) = 0; n(2) <
dim_(2); n(2)++) {
230 for (
const auto &it : dilate_neighbor) {
240 template <
int U = Dim>
241 typename std::enable_if<U == 2>::type
dilate(
245 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
246 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
248 for (
const auto &it : dilate_neighbor) {
262 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
263 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
264 for (n(2) = 0; n(2) <
dim_(2); n(2)++) {
269 }
else if (Dim == 2) {
270 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
271 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
282 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
283 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
284 for (n(2) = 0; n(2) <
dim_(2); n(2)++) {
289 }
else if (Dim == 2) {
290 for (n(0) = 0; n(0) <
dim_(0); n(0)++) {
291 for (n(1) = 0; n(1) <
dim_(1); n(1)++) {
Veci< Dim > getDim()
Get dimensions.
Definition: map_util.h:29
std::enable_if< U==3, vec_Vec3f >::type getCloud()
Get occupied voxels for 3D.
Definition: map_util.h:138
void freeAll()
Free all voxels.
Definition: map_util.h:279
Definition: map_util.h:12
Veci< Dim > floatToInt(const Vecf< Dim > &pt)
Float position to discrete cell coordinate.
Definition: map_util.h:103
bool isFree(int idx)
Check if the cell is free by index.
Definition: map_util.h:44
decimal_t res_
Map resolution.
Definition: map_util.h:300
void freeUnknown()
Free unknown voxels.
Definition: map_util.h:259
std::enable_if< U==3, int >::type getIndex(const Veci< Dim > &pn)
Get index of a cell for 3D.
Definition: map_util.h:39
decimal_t getRes()
Get resolution.
Definition: map_util.h:27
std::vector< signed char > Tmap
The type of map data Tmap is defined as a 1D array.
Definition: map_util.h:14
vec_Veci< Dim > rayTrace(const Vecf< Dim > &pt1, const Vecf< Dim > &pt2)
Raytrace from float point pt1 to pt2.
Definition: map_util.h:117
bool isUnknown(const Veci< Dim > &pn)
Check if the given cell is unknown by coordinate.
Definition: map_util.h:71
bool isOccupied(int idx)
Check if the cell is occupied by index.
Definition: map_util.h:48
Vecf< Dim > intToFloat(const Veci< Dim > &pn)
Discrete cell coordinate to float position.
Definition: map_util.h:110
bool isOutside(const Veci< Dim > &pn)
Check if the cell is outside by coordinate.
Definition: map_util.h:51
void info()
Print basic information about the util.
Definition: map_util.h:93
vec_E< Vecf< N > > vec_Vecf
Vector of Eigen 1D float vector.
Definition: data_type.h:70
Veci< Dim > dim_
Dimension, int type.
Definition: map_util.h:304
bool isOccupied(const Veci< Dim > &pn)
Check if the given cell is occupied by coordinate.
Definition: map_util.h:64
Eigen::Matrix< int, N, 1 > Veci
Eigen 1D int vector of size N.
Definition: data_type.h:59
double decimal_t
Rename the float type used in lib.
Definition: data_type.h:49
MapUtil()
Simple constructor.
Definition: map_util.h:23
std::enable_if< U==3 >::type dilate(const vec_Veci< Dim > &dilate_neighbor)
Dilate occupied cells.
Definition: map_util.h:222
Vecf< Dim > getOrigin()
Get origin.
Definition: map_util.h:31
Vecf< Dim > origin_d_
Origin, float type.
Definition: map_util.h:302
bool isFree(const Veci< Dim > &pn)
Check if the given cell is free by coordinate.
Definition: map_util.h:57
vec_E< Veci< N > > vec_Veci
Vector of Eigen 1D int vector.
Definition: data_type.h:73
Defines all data types used in this lib.
Eigen::Matrix< decimal_t, N, 1 > Vecf
Eigen 1D float vector of size N.
Definition: data_type.h:56
void setMap(const Vecf< Dim > &ori, const Veci< Dim > &dim, const Tmap &map, decimal_t res)
Set map.
Definition: map_util.h:84
int8_t val_free
Assume free cell has value 0.
Definition: map_util.h:311
std::enable_if< U==2, vec_Vec2f >::type getUnknownCloud()
Get unknown voxels for 2D.
Definition: map_util.h:209
int8_t val_occ
Assume occupied cell has value 100.
Definition: map_util.h:309
std::enable_if< U==2, vec_Vec2f >::type getFreeCloud()
Get free voxels for 2D.
Definition: map_util.h:181
std::enable_if< U==2, int >::type getIndex(const Veci< Dim > &pn)
Get index of a cell for 2D.
Definition: map_util.h:34
int8_t val_unknown
Assume unknown cell has value -1.
Definition: map_util.h:313
std::enable_if< U==3, vec_Vec3f >::type getFreeCloud()
Get free voxels for 3D.
Definition: map_util.h:166
Definition: map_util.h:20
std::enable_if< U==2, vec_Vec2f >::type getCloud()
Get occupied voxels for 2D.
Definition: map_util.h:152
Tmap map_
Map entity.
Definition: map_util.h:306
std::enable_if< U==3, vec_Vec3f >::type getUnknownCloud()
Get unknown voxels for 3D.
Definition: map_util.h:194
bool isUnknown(int idx)
Check if the cell is unknown by index.
Definition: map_util.h:46
Tmap getMap()
Get map data.
Definition: map_util.h:25