33#ifdef COVERAGECONTROL_WITH_CUDA
43 std::vector<Polygon_2> cgal_polygons;
44 cgal_polygons.reserve(polygon_features_.size());
45 for (
auto const &poly : polygon_features_) {
47 for (
auto const &pt : poly.poly) {
50 cgal_polygons.push_back(cgal_poly);
52 float max_importance = 0;
53 float res =
static_cast<float>(params_.
pResolution);
62 float importance = ComputeImportanceBND<Point2f, float>(pt1, pt2);
65 float importance_poly = 0;
66 for (
size_t k = 0; k < cgal_polygons.size(); ++k) {
67 auto &poly = cgal_polygons[k];
68 if (poly.bounded_side(mid) == CGAL::ON_BOUNDED_SIDE) {
69 importance_poly = std::max(importance_poly, polygon_features_[k].imp);
72 importance += importance_poly;
77 world_map_(i, j) = importance;
78 if (importance > max_importance) {
79 max_importance = importance;
84 if (max_importance <
kEps) {
85 normalization_factor_ =
static_cast<float>(params_.
pNorm);
87 normalization_factor_ =
static_cast<float>(params_.
pNorm) / max_importance;
90 if (not(normalization_factor_ > 1e-5)) {
95#pragma omp parallel for
98 world_map_(i, j) *= normalization_factor_;
103#ifdef COVERAGECONTROL_WITH_CUDA
104void WorldIDF::GenerateMapCuda(
float const resolution,
float const truncation,
105 int const map_size) {
106 int num_dists = normal_distributions_.size();
113 for (
int i = 0; i < num_dists; ++i) {
114 Point2 mean = normal_distributions_[i].GetMean();
115 host_dists[i].
mean_x =
static_cast<float>(mean.x());
116 host_dists[i].
mean_y =
static_cast<float>(mean.y());
117 Point2 sigma = normal_distributions_[i].GetSigma();
118 host_dists[i].
sigma_x =
static_cast<float>(sigma.x());
119 host_dists[i].
sigma_y =
static_cast<float>(sigma.y());
120 host_dists[i].
rho =
static_cast<float>(normal_distributions_[i].GetRho());
121 host_dists[i].
scale =
122 static_cast<float>(normal_distributions_[i].GetScale());
125 Polygons_Cuda_Host host_polygons;
126 for (
auto const &poly_feature : polygon_features_) {
127 std::vector<PointVector> partition_polys;
129 for (
auto const &poly : partition_polys) {
131 for (Point2
const &pt : poly) {
132 float x =
static_cast<float>(pt.x());
133 float y =
static_cast<float>(pt.y());
134 host_polygons.x.push_back(x);
135 host_polygons.y.push_back(y);
136 if (x < bounds.xmin) {
139 if (y < bounds.ymin) {
142 if (x > bounds.xmax) {
145 if (y > bounds.ymax) {
149 host_polygons.imp.push_back(poly_feature.imp);
150 host_polygons.sz.push_back(poly.size());
151 host_polygons.bounds.push_back(bounds);
155 host_polygons.num_pts = host_polygons.x.size();
156 host_polygons.num_polygons = host_polygons.imp.size();
160 resolution, truncation, params_.
pNorm,
161 world_map_.data(), f_norm);
162 normalization_factor_ =
static_cast<double>(f_norm);
167 std::ofstream file(file_name);
168 if (!file.is_open()) {
169 std::cerr <<
"Could not open file: " << file_name << std::endl;
173 for (
auto const &dist : normal_distributions_) {
174 Point2 sigma = dist.GetSigma();
175 if (sigma.x() == sigma.y()) {
176 file <<
"CircularBND" << std::endl;
177 file << dist.GetMean().x() <<
" " << dist.GetMean().y() <<
" "
178 << sigma.x() <<
" " << dist.GetScale() << std::endl;
180 file <<
"BND" << std::endl;
181 file << dist.GetMean().x() <<
" " << dist.GetMean().y() <<
" "
182 << dist.GetSigma().x() <<
" " << dist.GetSigma().y() <<
" "
183 << dist.GetRho() <<
" " << dist.GetScale() << std::endl;
186 for (
auto const &poly : polygon_features_) {
187 file <<
"Uniform" << std::endl;
188 file << poly.poly.size() <<
" " << poly.imp << std::endl;
189 for (
auto const &pt : poly.poly) {
190 file << pt.x() <<
" " << pt.y() << std::endl;
int WriteDistributions(std::string const &file_name) const
Contains the configuration for the CGAL library.
CGAL::Polygon_2< K > Polygon_2
Constants for the CoverageControl library.
Contains structs and functions to interface with the CUDA code to generate the world map.
constexpr auto kMaxPrecision
Namespace for the CoverageControl library.
void PolygonYMonotonePartition(PointVector const &polygon, std::vector< PointVector > &y_monotone_polygons)
Partition a polygon into y-monotone polygons.
void generate_world_map_cuda(BND_Cuda *, Polygons_Cuda_Host const &, int const, int const, float const, float const, float const, float *importance_vec, float &)
Function to generate the world map on the device.
Provides utilities for polygon manipulation using CGAL.
Structure to store the parameters of the Bivariate Normal Distribution.
Contains the class for Importance Density Function (IDF) for the world.