29#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_WORLD_IDF_H_
30#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_WORLD_IDF_H_
40#include "CoverageControl/Config.h"
63 std::vector<BivariateNormalDistribution> normal_distributions_;
64 std::vector<PolygonFeature> polygon_features_;
67 float normalization_factor_ = 0;
68 bool is_cuda_available_ =
false;
73 template <
class Po
intType = Po
int2,
typename NumType =
double>
74 NumType ComputeImportanceBND(PointType
const &bottom_left,
75 PointType
const &top_right)
const {
76 PointType bottom_right(top_right.x(), bottom_left.y());
77 PointType top_left(bottom_left.x(), top_right.y());
78 NumType importance = 0;
79 PointType mid_point = (bottom_left + top_right) / 2.f;
81 NumType trun_sqr = trun_f * trun_f;
82 for (
auto const &normal_distribution : normal_distributions_) {
83 PointType mid_transformed = normal_distribution.TransformPoint(mid_point);
84 if (mid_transformed[0] * mid_transformed[0] +
85 mid_transformed[1] * mid_transformed[1] >
89 importance += normal_distribution.IntegrateQuarterPlane(bottom_left);
90 importance -= normal_distribution.IntegrateQuarterPlane(bottom_right);
91 importance -= normal_distribution.IntegrateQuarterPlane(top_left);
92 importance += normal_distribution.IntegrateQuarterPlane(top_right);
97#ifdef COVERAGECONTROL_WITH_CUDA
98 void GenerateMapCuda(
float const resolution,
float const truncation,
106 is_cuda_available_ =
true;
108 is_cuda_available_ =
false;
121 std::cout <<
"Error: World map size does not match the specified size"
123 throw std::invalid_argument(
124 "World map size does not match the specified size");
127 world_map_ = world_map;
135 std::ifstream file(file_name);
136 if (!file.is_open()) {
137 std::cout <<
"Error: Could not open file " << file_name << std::endl;
141 while (file >> type) {
143 double x, y, sigma_x, sigma_y, rho, scale;
144 file >> x >> y >> sigma_x >> sigma_y >> rho >> scale;
147 }
else if (type ==
"CircularBND") {
148 double x, y, sigma, scale;
149 file >> x >> y >> sigma >> scale;
152 }
else if (type ==
"Uniform") {
154 file >> num_vertices;
158 std::vector<Point2> vertices;
159 for (
int i = 0; i < num_vertices; ++i) {
162 vertices.push_back(
Point2(x, y));
166 std::cout <<
"Error: Unknown feature type " << type << std::endl;
175 world_map_ = other.world_map_;
176 params_ = other.params_;
177 normalization_factor_ = other.normalization_factor_;
178 is_cuda_available_ = other.is_cuda_available_;
179 normal_distributions_ = other.normal_distributions_;
180 polygon_features_ = other.polygon_features_;
184 if (
this != &other) {
185 world_map_ = other.world_map_;
186 params_ = other.params_;
187 normalization_factor_ = other.normalization_factor_;
188 is_cuda_available_ = other.is_cuda_available_;
189 normal_distributions_ = other.normal_distributions_;
190 polygon_features_ = other.polygon_features_;
196 std::ifstream file(file_name);
197 if (!file.is_open()) {
198 std::cout <<
"Error: Could not open file " << file_name << std::endl;
203 file >> world_map_(i, j);
210 polygon_features_.push_back(poly_feature);
215 normal_distributions_.push_back(distribution);
220 std::vector<BivariateNormalDistribution>
const &dists) {
221 normal_distributions_.reserve(normal_distributions_.size() + dists.size());
222 for (
auto const &dist : dists) {
223 normal_distributions_.push_back(dist);
229#ifdef COVERAGECONTROL_WITH_CUDA
231 if (is_cuda_available_) {
248 world_map_, sensor_size, submap);
252 std::cout <<
"World map size: " << world_map_.rows() <<
" "
253 << world_map_.cols() << std::endl;
265 return normal_distributions_.size() + polygon_features_.size();
270#ifdef COVERAGECONTROL_WITH_CUDA
271 void GenerateMapCuda() {
273 GenerateMapCuda(
static_cast<float>(params_.
pResolution),
Class for Bivariate Normal Distribution.
Class for Bivariate Normal Distribution.
static bool InitializeCUDA()
Initializes a CUDA device use_cuda_ must be set to true before calling this function.
Class to store parameters.
Class for Importance Density Function (IDF) for the world.
void GetSubWorldMap(Point2 const &pos, int const sensor_size, MapType &submap) const
MapType & GetWorldMapMutable()
int WriteDistributions(std::string const &file_name) const
void AddNormalDistribution(std::vector< BivariateNormalDistribution > const &dists)
auto GetNumFeatures() const
WorldIDF & operator=(WorldIDF const &other)
auto GetNormalizationFactor() const
const MapType & GetWorldMap() const
WorldIDF(Parameters const ¶ms, MapType const &world_map)
void PrintMapSize() const
void LoadMap(std::string const &file_name)
void AddNormalDistribution(BivariateNormalDistribution const &distribution)
int WriteWorldMap(std::string const &file_name) const
void AddUniformDistributionPolygon(PolygonFeature const &poly_feature)
WorldIDF(WorldIDF const &other)
WorldIDF(Parameters const ¶ms, std::string const &file_name)
WorldIDF(Parameters const ¶ms)
Utility functions for CUDA.
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MapType
Utility functions for transforming maps.
void GetSubMap(double const resolution, Point2 const &pos, int const map_size, T const &map, int const submap_size, T &submap)
int WriteMap(MapType const &map, std::string const &file_name)
Write the world map to a file.
Namespace for the CoverageControl library.
A struct to store a polygon feature and a uniform importance value.
Contains typedefs for the library.