@@ -176,6 +176,20 @@ class WorldIDF {
176176 params_ = params;
177177 }
178178
179+ WorldIDF (Parameters const ¶ms, MapType const &world_map)
180+ : WorldIDF(params.pWorldMapSize) {
181+ params_ = params;
182+ if (world_map.rows () != params.pWorldMapSize ||
183+ world_map.cols () != params.pWorldMapSize ) {
184+ std::cout << " Error: World map size does not match the specified size"
185+ << std::endl;
186+ throw std::invalid_argument (
187+ " World map size does not match the specified size" );
188+ exit (1 );
189+ }
190+ world_map_ = world_map;
191+ }
192+
179193 WorldIDF (Parameters const ¶ms, std::string const &file_name)
180194 : WorldIDF(params.pWorldMapSize) {
181195 params_ = params;
@@ -201,14 +215,15 @@ class WorldIDF {
201215 } else if (type == " Uniform" ) {
202216 int num_vertices;
203217 file >> num_vertices;
218+ double importance;
219+ file >>
220+ importance; // importance moved here. Be careful with semantic file
204221 std::vector<Point2> vertices;
205222 for (int i = 0 ; i < num_vertices; ++i) {
206223 double x, y;
207224 file >> x >> y;
208225 vertices.push_back (Point2 (x, y));
209226 }
210- double importance;
211- file >> importance;
212227 AddUniformDistributionPolygon (PolygonFeature (vertices, importance));
213228 } else {
214229 std::cout << " Error: Unknown feature type " << type << std::endl;
@@ -305,74 +320,15 @@ class WorldIDF {
305320
306321 const MapType &GetWorldMap () const { return world_map_; }
307322
308- inline int WriteDistributions (std::string const &file_name) const {
309- std::ofstream file (file_name);
310- if (!file.is_open ()) {
311- std::cerr << " Could not open file: " << file_name << std::endl;
312- return -1 ;
313- }
314- file << std::setprecision (kMaxPrecision );
315- for (auto const &dist : normal_distributions_) {
316- Point2 sigma = dist.GetSigma ();
317- if (sigma.x () == sigma.y ()) {
318- file << " CircularBND" << std::endl;
319- file << dist.GetMean ().x () << " " << dist.GetMean ().y () << " "
320- << sigma.x () << " " << dist.GetScale () << std::endl;
321- } else {
322- file << " BND" << std::endl;
323- file << dist.GetMean ().x () << " " << dist.GetMean ().y () << " "
324- << dist.GetSigma ().x () << " " << dist.GetSigma ().y () << " "
325- << dist.GetRho () << " " << dist.GetScale () << std::endl;
326- }
327- }
328- file.close ();
329- return 0 ;
330- }
323+ MapType &GetWorldMapMutable () { return world_map_; }
324+
325+ int WriteDistributions (std::string const &file_name) const ;
331326
332327 auto GetNumFeatures () const {
333328 return normal_distributions_.size () + polygon_features_.size ();
334329 }
335330
336- /* ! Fills in values of the world_map_ with the total importance for each cell
337- */
338- void GenerateMapCPU () {
339- /* std::cout << "Generating map using CPU" << std::endl; */
340- float max_importance = 0 ;
341- float res = static_cast <float >(params_.pResolution );
342- for (int i = 0 ; i < params_.pWorldMapSize ; ++i) { // Row (x index)
343- float x1 = res * i; // Left x-coordinate of pixel
344- float x2 = x1 + res; // Right x-coordinate of pixel
345- for (int j = 0 ; j < params_.pWorldMapSize ; ++j) { // Column (y index)
346- float y1 = res * j; // Lower y-coordinate of pixel
347- float y2 = y1 + res; // Upper y-coordinate of pixel
348- float importance = ComputeImportanceBND<Point2f, float >(
349- Point2f (x1, y1), Point2f (x2, y2));
350- /* auto importance = ComputeImportanceBND(pt1, pt2); */
351- /* if (std::abs(importance) < kEps) { */
352- /* importance = 0; */
353- /* } */
354- world_map_ (i, j) = importance;
355- if (importance > max_importance) {
356- max_importance = importance;
357- }
358- }
359- }
360-
361- if (max_importance < kEps ) {
362- normalization_factor_ = static_cast <float >(params_.pNorm );
363- } else {
364- normalization_factor_ =
365- static_cast <float >(params_.pNorm ) / max_importance;
366- }
367-
368- // Normalize the world map
369- #pragma omp parallel for
370- for (int i = 0 ; i < params_.pWorldMapSize ; ++i) {
371- for (int j = 0 ; j < params_.pWorldMapSize ; ++j) {
372- world_map_ (i, j) *= normalization_factor_;
373- }
374- }
375- }
331+ void GenerateMapCPU ();
376332
377333#ifdef COVERAGECONTROL_WITH_CUDA
378334 void GenerateMapCuda () {
0 commit comments