From 0d9a472502a362b1c3a20f4251581f4d21c58343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Grzeczkowicz?= Date: Thu, 21 Sep 2023 11:27:40 +0000 Subject: [PATCH] Syntax improvment --- bridge.cpp | 31 +++++++++++++------------------ code.cpp | 14 +++++--------- edge_collapse.cpp | 16 +++++++--------- edge_collapse2.cpp | 46 +++++++++++++++++++++++----------------------- label.hpp | 4 ++-- main.cpp | 4 ++-- path.cpp | 6 +++--- raster.cpp | 7 ++++--- raster.hpp | 2 +- 9 files changed, 60 insertions(+), 70 deletions(-) diff --git a/bridge.cpp b/bridge.cpp index 48e7299..8d792b5 100644 --- a/bridge.cpp +++ b/bridge.cpp @@ -131,7 +131,7 @@ std::set link_paths(const Surface_mesh &mesh, const std::vector same_label_paths; - for (int i = 0; i < paths.size(); i++) { + for (std::size_t i = 0; i < paths.size(); i++) { if (label[paths[i].front()] == selected_label && medial_axes.count(i) == 1) { same_label_paths.push_back(i); } @@ -874,7 +874,6 @@ pathBridge bridge (pathLink link, const Surface_mesh &mesh, const AABB_tree &tre float dlN = sqrt(CGAL::squared_distance(link.second.point, left2_border.second)); float drN = sqrt(CGAL::squared_distance(link.second.point, right2_border.second)); - int N = int(sqrt(link_vector.squared_length ())); pathBridge bridge(link); for (int i = 0; i <= bridge.N; i++) { bridge.xl[i] = dl0 + ((float) i)/bridge.N*(dlN-dl0); @@ -1179,8 +1178,8 @@ pathBridge bridge (pathLink link, const Surface_mesh &mesh, const AABB_tree &tre { // Surface Surface_mesh bridge_mesh; - Surface_mesh::Vertex_index Xl[bridge.N+1]; - Surface_mesh::Vertex_index Xr[bridge.N+1]; + std::vector Xl(bridge.N+1); + std::vector Xr(bridge.N+1); // Add points for (int i = 0; i <= bridge.N; i++) { @@ -1270,9 +1269,6 @@ void close_surface_mesh(Surface_mesh &mesh) { } min_h -= 50; - float min_x; - float min_y; - std::vector borders_edge; CGAL::Polygon_mesh_processing::extract_boundary_cycles (mesh, std::back_inserter(borders_edge)); assert(borders_edge.size() == 1); @@ -1430,10 +1426,10 @@ Surface_mesh compute_remove_mesh(const pathBridge &bridge, const Surface_mesh_in auto n = l.perpendicular(CGAL::COUNTERCLOCKWISE); Surface_mesh bridge_mesh; - Surface_mesh::Vertex_index Xlb[bridge.N+1]; // X left bottom - Surface_mesh::Vertex_index Xrb[bridge.N+1]; // X right bottom - Surface_mesh::Vertex_index Xlt[bridge.N+1]; // X left top - Surface_mesh::Vertex_index Xrt[bridge.N+1]; // X right top + std::vector Xlb(bridge.N+1); // X left bottom + std::vector Xrb(bridge.N+1); // X right bottom + std::vector Xlt(bridge.N+1); // X left top + std::vector Xrt(bridge.N+1); // X right top // Add points for (int i = 0; i <= bridge.N; i++) { @@ -1505,10 +1501,10 @@ Surface_mesh compute_support_mesh(const pathBridge &bridge, const Surface_mesh_i auto n = l.perpendicular(CGAL::COUNTERCLOCKWISE); Surface_mesh bridge_mesh; - Surface_mesh::Vertex_index Xlb[bridge.N+1]; // X left bottom - Surface_mesh::Vertex_index Xrb[bridge.N+1]; // X right bottom - Surface_mesh::Vertex_index Xlt[bridge.N+1]; // X left top - Surface_mesh::Vertex_index Xrt[bridge.N+1]; // X right top + std::vector Xlb(bridge.N+1); // X left bottom + std::vector Xrb(bridge.N+1); // X right bottom + std::vector Xlt(bridge.N+1); // X left top + std::vector Xrt(bridge.N+1); // X right top // Add points for (int i = 0; i <= bridge.N; i++) { @@ -1583,7 +1579,7 @@ struct Extrudor { assert(has_exact_points); } - void operator()(const Surface_mesh::Vertex_index &vin, const Surface_mesh::Vertex_index &vout) const { + void operator()(const Surface_mesh::Vertex_index&, const Surface_mesh::Vertex_index &vout) const { if (top) { exact_point[vout] += CGAL::Exact_predicates_exact_constructions_kernel::Vector_3(0, 0, tunnel_height); } else { // bottom @@ -1617,7 +1613,6 @@ Surface_mesh compute_crossing_mesh(Surface_mesh mesh, const pathBridge &bridge, // Compute crossing border // Exact points - CGAL::Cartesian_converter to_exact; Surface_mesh::Property_map exact_points; bool created_point; @@ -1641,7 +1636,7 @@ Surface_mesh compute_crossing_mesh(Surface_mesh mesh, const pathBridge &bridge, return crossing_mesh; } -void add_bridge_to_mesh(Surface_mesh &mesh, const std::vector &bridges, const std::map> &path_polygon, const Surface_mesh_info &mesh_info) { +void add_bridge_to_mesh(Surface_mesh &mesh, const std::vector &bridges, const std::map> &/*path_polygon*/, const Surface_mesh_info &mesh_info) { // Label Surface_mesh::Property_map label; diff --git a/code.cpp b/code.cpp index 2cc6568..295a87a 100644 --- a/code.cpp +++ b/code.cpp @@ -66,10 +66,8 @@ void add_label(const Raster &raster, Surface_mesh &mesh) { CGAL::Vertex_around_face_iterator vbegin, vend; boost::tie(vbegin, vend) = vertices_around_face(mesh.halfedge(face), mesh); for (auto pixel : raster.triangle_to_pixel(mesh.point(*(vbegin++)), mesh.point(*(vbegin++)), mesh.point(*(vbegin++)))) { - if (raster.land_cover[pixel.second][pixel.first] > -1) { - sum_face_label++; - face_label[raster.land_cover[pixel.second][pixel.first]]++; - } + sum_face_label++; + face_label[raster.land_cover[pixel.second][pixel.first]]++; } auto argmax = std::max_element(face_label, face_label+LABELS.size()); @@ -83,7 +81,7 @@ void change_vertical_faces(Surface_mesh &mesh, const Raster &raster) { boost::tie(label, has_label) = mesh.property_map("label"); assert(has_label); - std::unordered_map new_label; + std::unordered_map new_label; std::list remove_face; for (auto face : mesh.faces()) { @@ -128,10 +126,8 @@ void change_vertical_faces(Surface_mesh &mesh, const Raster &raster) { CGAL::Vertex_around_face_iterator vbegin, vend; boost::tie(vbegin, vend) = vertices_around_face(mesh.halfedge(face), mesh); for (auto pixel : raster.triangle_to_pixel(mesh.point(*(vbegin++)), mesh.point(*(vbegin++)), mesh.point(*(vbegin++)))) { - if (raster.land_cover[pixel.second][pixel.first] > -1) { - sum_face_label++; - face_label[raster.land_cover[pixel.second][pixel.first]]++; - } + sum_face_label++; + face_label[raster.land_cover[pixel.second][pixel.first]]++; } if (face_label[4] > 0) { diff --git a/edge_collapse.cpp b/edge_collapse.cpp index c5f7692..a0c3829 100644 --- a/edge_collapse.cpp +++ b/edge_collapse.cpp @@ -23,14 +23,12 @@ float single_face_cost(const Raster &raster, const Point_3 &p0, const Point_3 &p int face_label[LABELS.size()] = {0}; int sum_face_label = 0; for (auto pixel : pixels) { - if (raster.land_cover[pixel.second][pixel.first] > -1) { - sum_face_label++; - face_label[raster.land_cover[pixel.second][pixel.first]]++; - } + sum_face_label++; + face_label[raster.land_cover[pixel.second][pixel.first]]++; } float entropy = 0; if (sum_face_label > 0) { - for (int i = 0; i < LABELS.size(); i++) { + for (std::size_t i = 0; i < LABELS.size(); i++) { if (face_label[i] > 0) { entropy += ((float) face_label[i])*log((float) face_label[i]); } @@ -170,7 +168,7 @@ class Custom_placement { Point_3 p[5] = {profile.p0(), profile.p0() + 0.25 * vector, profile.p0() + 0.5 * vector, profile.p0() + 0.75 * vector, profile.p1()}; float cost[5] = {0}; - /*for (int j = 0; j < 5; j++) { + /*for (unsigned char j = 0; j < 5; j++) { p[j] = best_point(raster, p[j].x(), p[j].y(), profile); }*/ @@ -178,7 +176,7 @@ class Custom_placement { if (he != profile.v0_v1() && he != profile.v0_vR()) { Point_3 A = get(profile.vertex_point_map(),CGAL::target(he, profile.surface_mesh())); Point_3 B = get(profile.vertex_point_map(),CGAL::target(CGAL::next(he, profile.surface_mesh()), profile.surface_mesh())); - for (int j = 0; j < 5; j++) { + for (unsigned char j = 0; j < 5; j++) { cost[j] += face_cost(raster, A, B, p[j]); } } @@ -187,13 +185,13 @@ class Custom_placement { if (he != profile.v1_v0() && he != profile.v1_vL()) { Point_3 A = get(profile.vertex_point_map(),CGAL::target(he, profile.surface_mesh())); Point_3 B = get(profile.vertex_point_map(),CGAL::target(CGAL::next(he, profile.surface_mesh()), profile.surface_mesh())); - for (int j = 0; j < 5; j++) { + for (unsigned char j = 0; j < 5; j++) { cost[j] += face_cost(raster, A, B, p[j]); } } } - for (int i = 0; i < 2; i++) { + for (unsigned char i = 0; i < 2; i++) { int min_cost = std::min_element(cost, cost + 5) - cost; if (min_cost == 0 || min_cost == 1) { diff --git a/edge_collapse2.cpp b/edge_collapse2.cpp index c6934a5..09a1d6f 100644 --- a/edge_collapse2.cpp +++ b/edge_collapse2.cpp @@ -166,7 +166,7 @@ std::list> label_preservation (const SMS::Edge_pr } int count_diff_label = 0; - for (int i = 0; i < LABELS.size(); i++) { + for (std::size_t i = 0; i < LABELS.size(); i++) { if (count_collapse_label[i] > 0) count_diff_label++; } @@ -179,7 +179,7 @@ std::list> label_preservation (const SMS::Edge_pr unsigned char label1, label2; bool first = true; - for (int i = 0; i < LABELS.size(); i++) { + for (std::size_t i = 0; i < LABELS.size(); i++) { if (count_collapse_label[i] > 0) { if (first) { label1 = i; @@ -233,10 +233,10 @@ std::list> label_preservation (const SMS::Edge_pr Exact_predicates_kernel::FT c = 1; Program qp (CGAL::EQUAL, true, 0, true, c); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { auto vr = Exact_predicates_kernel::Vector_3(CGAL::ORIGIN, point_cloud.point(points_for_svm[i])) * y[i]; qp.set_d(i, i, CGAL::scalar_product(vr,vr)); - for (int j = 0; j < i; j++) { + for (std::size_t j = 0; j < i; j++) { qp.set_d(i, j, CGAL::scalar_product(vr, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN, point_cloud.point(points_for_svm[j])) * y[j])); } qp.set_c(i, -1); @@ -249,7 +249,7 @@ std::list> label_preservation (const SMS::Edge_pr Exact_predicates_kernel::Vector_3 w(CGAL::NULL_VECTOR); auto value = s.variable_values_begin(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { w += y[i] * CGAL::to_double(*(value++)) * Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i])); } @@ -257,7 +257,7 @@ std::list> label_preservation (const SMS::Edge_pr int count = 0; Exact_predicates_kernel::FT min_positive = std::numeric_limits::max(); Exact_predicates_kernel::FT max_negative = std::numeric_limits::lowest(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { Exact_predicates_kernel::FT v = CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); if (y[i] > 0 && v < min_positive) min_positive = v; if (y[i] < 0 && v > max_negative) max_negative = v; @@ -268,7 +268,7 @@ std::list> label_preservation (const SMS::Edge_pr } if (count == 0) { value = s.variable_values_begin(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { double v = CGAL::to_double(*(value++)); if (v > 0 && v < c) { b += y[i] - CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); @@ -278,7 +278,7 @@ std::list> label_preservation (const SMS::Edge_pr } if (count == 0) { value = s.variable_values_begin(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { if (CGAL::to_double(*(value++)) > 0) { b += y[i] - CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); count++; @@ -286,7 +286,7 @@ std::list> label_preservation (const SMS::Edge_pr } } if (count == 0) { - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { b += y[i] - CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); count++; } @@ -299,7 +299,7 @@ std::list> label_preservation (const SMS::Edge_pr } else { - for (int i_label = 0; i_label < LABELS.size(); i_label++) { + for (std::size_t i_label = 0; i_label < LABELS.size(); i_label++) { if (count_collapse_label[i_label] > 0) { std::vector y; @@ -324,10 +324,10 @@ std::list> label_preservation (const SMS::Edge_pr Exact_predicates_kernel::FT c = 1; Program qp (CGAL::EQUAL, true, 0, true, c); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { auto vr = Exact_predicates_kernel::Vector_3(CGAL::ORIGIN, point_cloud.point(points_for_svm[i])) * y[i]; qp.set_d(i, i, CGAL::scalar_product(vr,vr)); - for (int j = 0; j < i; j++) { + for (std::size_t j = 0; j < i; j++) { qp.set_d(i, j, CGAL::scalar_product(vr, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN, point_cloud.point(points_for_svm[j])) * y[j])); } qp.set_c(i, -1); @@ -340,7 +340,7 @@ std::list> label_preservation (const SMS::Edge_pr Exact_predicates_kernel::Vector_3 w(CGAL::NULL_VECTOR); auto value = s.variable_values_begin(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { w += y[i] * CGAL::to_double(*(value++)) * Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i])); } @@ -348,7 +348,7 @@ std::list> label_preservation (const SMS::Edge_pr int count = 0; Exact_predicates_kernel::FT min_positive = std::numeric_limits::max(); Exact_predicates_kernel::FT max_negative = std::numeric_limits::lowest(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { Exact_predicates_kernel::FT v = CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); if (y[i] > 0 && v < min_positive) min_positive = v; if (y[i] < 0 && v > max_negative) max_negative = v; @@ -359,7 +359,7 @@ std::list> label_preservation (const SMS::Edge_pr } if (count == 0) { value = s.variable_values_begin(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { double v = CGAL::to_double(*(value++)); if (v > 0 && v < c) { b += y[i] - CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); @@ -369,7 +369,7 @@ std::list> label_preservation (const SMS::Edge_pr } if (count == 0) { value = s.variable_values_begin(); - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { if (CGAL::to_double(*(value++)) > 0) { b += y[i] - CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); count++; @@ -377,7 +377,7 @@ std::list> label_preservation (const SMS::Edge_pr } } if (count == 0) { - for (int i = 0; i < points_for_svm.size(); i++) { + for (std::size_t i = 0; i < points_for_svm.size(); i++) { b += y[i] - CGAL::scalar_product(w, Exact_predicates_kernel::Vector_3(CGAL::ORIGIN,point_cloud.point(points_for_svm[i]))); count++; } @@ -591,11 +591,11 @@ struct My_visitor : SMS::Edge_collapse_visitor_base { public: My_visitor(Surface_mesh &mesh, const Surface_mesh_info &mesh_info, const Point_set &point_cloud, std::map> &point_in_face) : mesh(mesh), mesh_info(mesh_info), point_cloud(point_cloud), point_in_face(point_in_face) {} - void OnStarted (Surface_mesh &mesh) { + void OnStarted (Surface_mesh&) { start_collecte = std::chrono::system_clock::now(); } - void OnCollected(const SMS::Edge_profile& profile, const boost::optional< SMS::Edge_profile::FT >& cost) { + void OnCollected(const SMS::Edge_profile&, const boost::optional< SMS::Edge_profile::FT >&) { start_collapse = std::chrono::system_clock::now(); i_collecte++; if (i_collecte%1000 == 0) { @@ -604,7 +604,7 @@ struct My_visitor : SMS::Edge_collapse_visitor_base { } } - void OnSelected (const SMS::Edge_profile &profile, boost::optional< SMS::Edge_profile::FT > cost, const SMS::Edge_profile::edges_size_type initial_edge_count, const SMS::Edge_profile::edges_size_type current_edge_count) { + void OnSelected (const SMS::Edge_profile&, boost::optional< SMS::Edge_profile::FT > cost, const SMS::Edge_profile::edges_size_type initial_edge_count, const SMS::Edge_profile::edges_size_type current_edge_count) { if (current_edge_count%100 == 0) { auto end = std::chrono::system_clock::now(); std::chrono::duration diff = end - start_collapse; @@ -703,7 +703,7 @@ struct My_visitor : SMS::Edge_collapse_visitor_base { }; - void OnCollapsing (const SMS::Edge_profile &profile, const boost::optional::Point>& placement) { + void OnCollapsing (const SMS::Edge_profile &profile, const boost::optional::Point>&) { // Called when an edge is about to be collapsed and replaced by a vertex whose position is *placement for(auto face: profile.triangles()) { auto fh = mesh.face(mesh.halfedge(face.v0, face.v1)); @@ -712,7 +712,7 @@ struct My_visitor : SMS::Edge_collapse_visitor_base { } }; - void OnCollapsed (const SMS::Edge_profile &profile, const Surface_mesh::Vertex_index vd) { + void OnCollapsed (const SMS::Edge_profile&, const Surface_mesh::Vertex_index vd) { // Called when an edge has been collapsed and replaced by the vertex vd CGAL::Cartesian_converter type_converter; @@ -876,7 +876,7 @@ std::tuple compute_meshes(const Raster &raster, cons Custom_placement pf(params, costs, point_cloud, point_in_face); Custom_cost cf(costs); SMS::Bounded_normal_change_filter<> filter; - int r = SMS::edge_collapse(mesh, stop, CGAL::parameters::get_cost(cf).filter(filter).get_placement(pf).visitor(My_visitor(mesh, mesh_info, point_cloud, point_in_face))); + SMS::edge_collapse(mesh, stop, CGAL::parameters::get_cost(cf).filter(filter).get_placement(pf).visitor(My_visitor(mesh, mesh_info, point_cloud, point_in_face))); std::cout << "\rMesh simplified " << std::endl; add_label(mesh, point_cloud, point_in_face); diff --git a/label.hpp b/label.hpp index f48564e..649b333 100644 --- a/label.hpp +++ b/label.hpp @@ -12,7 +12,7 @@ struct Label { unsigned char red; unsigned char green; unsigned char blue; - Label(int value, std::string label, unsigned char red, unsigned char green, unsigned char blue): value(value), label(label), red(red), green(green), blue(blue) {} + Label(unsigned char value, std::string label, unsigned char red, unsigned char green, unsigned char blue): value(value), label(label), red(red), green(green), blue(blue) {} }; static std::array LABELS { @@ -30,6 +30,6 @@ static std::array LABELS { Label(11, "rail crossing", 250, 150, 0) }; -const int LABEL_OTHER = 0; +const unsigned char LABEL_OTHER = 0; #endif /* !LABEL_H_ */ diff --git a/main.cpp b/main.cpp index 1282529..e274ef6 100644 --- a/main.cpp +++ b/main.cpp @@ -18,8 +18,8 @@ std::map>> compute_medial_ax #include "bridge.hpp" -Surface_mesh_info::Surface_mesh_info() : x_0(0), y_0(0) {}; -Surface_mesh_info::Surface_mesh_info(OGRSpatialReference crs, double x_0, double y_0) : crs(crs), x_0(x_0), y_0(y_0) {}; +Surface_mesh_info::Surface_mesh_info() : x_0(0), y_0(0) {} +Surface_mesh_info::Surface_mesh_info(OGRSpatialReference crs, double x_0, double y_0) : crs(crs), x_0(x_0), y_0(y_0) {} void Surface_mesh_info::save_mesh(const Surface_mesh &mesh, const char *filename) const { Surface_mesh output_mesh (mesh); diff --git a/path.cpp b/path.cpp index d4a9732..b5ad922 100644 --- a/path.cpp +++ b/path.cpp @@ -100,7 +100,7 @@ std::map> compute_path_ std::map> path_polygon; - for (int i = 0; i < paths.size(); i++) { + for (std::size_t i = 0; i < paths.size(); i++) { CGAL::Face_filtered_graph filtered_sm(mesh, i, path); @@ -174,7 +174,7 @@ std::map>> compute_medial_ax std::map>> medial_axes; - for (int i = 0; i < paths.size(); i++) { + for (std::size_t i = 0; i < paths.size(); i++) { if (path_polygon.count(i) > 0) { @@ -348,7 +348,7 @@ std::pair point_on_path_border(const Surface_ auto target = mesh.point(CGAL::target(he, filtered_mesh)); auto result = CGAL::intersection(segment, K::Segment_2(Point_2(source.x(), source.y()), Point_2(target.x(), target.y()))); assert(result); - if (const K::Segment_2* s = boost::get(&*result)) { + if (boost::get(&*result)) { if (CGAL::squared_distance(Point_2(source.x(), source.y()), segment.source()) < CGAL::squared_distance(Point_2(target.x(), target.y()), segment.source())) { return std::make_pair(face, Point_2(source.x(), source.y())); } else { diff --git a/raster.cpp b/raster.cpp index 2330dea..42fec08 100644 --- a/raster.cpp +++ b/raster.cpp @@ -15,7 +15,7 @@ std::pair Raster::grid_conversion(int P, int L, double grid_to_crs[6], } void Raster::align_land_cover_and_dsm() { - std::vector> new_land_cover = std::vector>(ySize, std::vector(xSize, -1)); + std::vector> new_land_cover = std::vector>(ySize, std::vector(xSize, LABEL_OTHER)); for (int L = 0; L < ySize; L++) { for (int P = 0; P < xSize; P++) { float neighboors_count[LABELS.size()] = {0}; @@ -138,7 +138,7 @@ Raster::Raster(char *dsm_path, char *dtm_path, char *land_cover_path) { std::cout << "DTM load" << std::endl; // Get land cover informations and CRS transform - land_cover = std::vector>(ySize, std::vector(xSize, -1)); + land_cover = std::vector>(ySize, std::vector(xSize, LABEL_OTHER)); GDALDataset *land_cover_dataset = (GDALDataset *) GDALOpen( land_cover_path, GA_ReadOnly ); if( dsm_dataset == NULL ) { throw std::invalid_argument(std::string("Unable to open ") + land_cover_path + "."); @@ -162,7 +162,8 @@ Raster::Raster(char *dsm_path, char *dtm_path, char *land_cover_path) { if (land_cover_dataset->GetRasterBand(1)->RasterIO(GF_Read, new_coord.first, new_coord.second, 1, 1, &value, 1, 1, GDT_Byte, 0, 0) >= CE_Failure) { throw std::invalid_argument(std::string(land_cover_path) + " can't be read."); } - land_cover[L][P] = (char) value; + if (value >= LABELS.size()) value = LABEL_OTHER; + land_cover[L][P] = value; } } } diff --git a/raster.hpp b/raster.hpp index 7378f3b..0c4dff3 100644 --- a/raster.hpp +++ b/raster.hpp @@ -8,7 +8,7 @@ class Raster { public: std::vector> dsm; std::vector> dtm; - std::vector> land_cover; + std::vector> land_cover; int xSize; int ySize;