Skip to content

Commit

Permalink
Change LABEL values
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrzeczkowicz committed Oct 29, 2024
1 parent a263d3c commit 56965be
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
18 changes: 9 additions & 9 deletions bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ class SurfaceCost : public ceres::SizedCostFunction<1, 1, 1, 1> {
auto point_bottom = PMP::construct_point(location_bottom, mesh);
local_cost = abs(z[0] - ((double) point_bottom.z())) * normal_angle_coef[location_bottom.first];
if (grad != nullptr) *grad = (z[0] > point_bottom.z()) ? 1 : -1;
if (l != 0 && l != label) {
if (l != LABEL_OTHER && l != LABEL_UNKNOWN && l != label) {
if ((l != LABEL_RAIL && l != LABEL_ROAD) || (label != LABEL_RAIL && label != LABEL_ROAD)) {
local_cost += cost * normal_angle_coef[location_bottom.first];
}
Expand All @@ -622,7 +622,7 @@ class SurfaceCost : public ceres::SizedCostFunction<1, 1, 1, 1> {
auto point_bottom = PMP::construct_point(location_bottom, mesh);
local_cost = abs(z[0] - ((double) point_bottom.z())) * normal_angle_coef[location_bottom.first];
if (grad != nullptr) *grad = (z[0] > point_bottom.z()) ? 1 : -1;
if (l != 0 && l != label) {
if (l != LABEL_OTHER && l != LABEL_UNKNOWN && l != label) {
if ((l != LABEL_RAIL && l != LABEL_ROAD) || (label != LABEL_RAIL && label != LABEL_ROAD)) {
local_cost += cost * normal_angle_coef[location_bottom.first];
}
Expand All @@ -640,7 +640,7 @@ class SurfaceCost : public ceres::SizedCostFunction<1, 1, 1, 1> {
auto l = mesh_labels[location_top.first];
local_cost = (((double) point_top.z()) - z[0]) * normal_angle_coef[location_top.first];
if (grad != nullptr) *grad = -1;
if (l != 0 && l != label) {
if (l != LABEL_OTHER && l != LABEL_UNKNOWN && l != label) {
if ((l != LABEL_RAIL && l != LABEL_ROAD) || (label != LABEL_RAIL && label != LABEL_ROAD)) {
local_cost += cost * normal_angle_coef[location_top.first];
}
Expand Down Expand Up @@ -1096,7 +1096,7 @@ pathBridge bridge (pathLink link, const Surface_mesh &mesh, const AABB_tree &tre
auto l = label[location_bottom.first];
auto point_bottom = PMP::construct_point(location_bottom, mesh);
point_cost = abs(bridge.z_segment[i] - point_bottom.z()) * normal_angle_coef[location_bottom.first];
if (l != 0 && l != bridge.label) {
if (l != LABEL_OTHER && l != LABEL_UNKNOWN && l != bridge.label) {
if ((l != LABEL_RAIL && l != LABEL_ROAD) || (bridge.label != LABEL_RAIL && bridge.label != LABEL_ROAD)) {
point_cost += theta * normal_angle_coef[location_bottom.first];
}
Expand All @@ -1112,7 +1112,7 @@ pathBridge bridge (pathLink link, const Surface_mesh &mesh, const AABB_tree &tre
auto l = label[location_bottom.first];
auto point_bottom = PMP::construct_point(location_bottom, mesh);
point_cost = abs(bridge.z_segment[i] - point_bottom.z()) * normal_angle_coef[location_bottom.first];
if (l != 0 && l != bridge.label) {
if (l != LABEL_OTHER && l != LABEL_UNKNOWN && l != bridge.label) {
if ((l != LABEL_RAIL && l != LABEL_ROAD) || (bridge.label != LABEL_RAIL && bridge.label != LABEL_ROAD)) {
point_cost += theta * normal_angle_coef[location_bottom.first];
}
Expand All @@ -1129,7 +1129,7 @@ pathBridge bridge (pathLink link, const Surface_mesh &mesh, const AABB_tree &tre
if (point_top.z() - bridge.z_segment[i] < tunnel_height/2) {
auto l = label[location_top.first];
point_cost = abs(bridge.z_segment[i] - ((double) point_top.z())) * normal_angle_coef[location_top.first];
if (l != 0 && l != bridge.label) {
if (l != LABEL_OTHER && l != LABEL_UNKNOWN && l != bridge.label) {
if ((l != LABEL_RAIL && l != LABEL_ROAD) || (bridge.label != LABEL_RAIL && bridge.label != LABEL_ROAD)) {
point_cost += theta * normal_angle_coef[location_top.first];
}
Expand Down Expand Up @@ -1498,7 +1498,7 @@ Surface_mesh compute_remove_mesh(const pathBridge &bridge, const Surface_mesh_in
// Label
Surface_mesh::Property_map<Surface_mesh::Face_index, unsigned char> label;
bool created_label;
boost::tie(label, created_label) = bridge_mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", 0);
boost::tie(label, created_label) = bridge_mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", LABEL_UNKNOWN);
assert(created_label);

// Add faces
Expand Down Expand Up @@ -1573,7 +1573,7 @@ Surface_mesh compute_support_mesh(const pathBridge &bridge, const Surface_mesh_i
// Label
Surface_mesh::Property_map<Surface_mesh::Face_index, unsigned char> label;
bool created_label;
boost::tie(label, created_label) = bridge_mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", 0);
boost::tie(label, created_label) = bridge_mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", LABEL_UNKNOWN);
assert(created_label);

// Add faces
Expand Down Expand Up @@ -1803,7 +1803,7 @@ void add_bridge_to_mesh(Surface_mesh &mesh, Point_set &point_cloud, const std::v

for (auto &ph: point_to_checks[i]) {

if (point_cloud_label[ph] == 0 || point_cloud_label[ph] == LABEL_OTHER) {
if (point_cloud_label[ph] == LABEL_OTHER || point_cloud_label[ph] == LABEL_UNKNOWN) {
auto p = type_converter(point_cloud.point(ph));

const K::Ray_3 ray_top(p, K::Direction_3(0, 0, 1));
Expand Down
6 changes: 3 additions & 3 deletions code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::list<Polygon> get_LOD0_from_shapefile(char *path) {
void add_label(const Raster &raster, Surface_mesh &mesh) {
Surface_mesh::Property_map<Surface_mesh::Face_index, unsigned char> label;
bool created;
boost::tie(label, created) = mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label",0);
boost::tie(label, created) = mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", LABEL_UNKNOWN);
assert(created);

for (auto face : mesh.faces()) {
Expand Down Expand Up @@ -91,7 +91,7 @@ void change_vertical_faces(Surface_mesh &mesh) {

auto n = CGAL::orthogonal_vector(p0, p1, p2);
if (CGAL::scalar_product(n, K::Vector_3(0,0,1)) / CGAL::sqrt(n.squared_length()) < 0.98) {
label[face] = LABEL_OTHER;
label[face] = LABEL_UNKNOWN;
}
} else if (label[face] == LABEL_ROAD) {

Expand All @@ -103,7 +103,7 @@ void change_vertical_faces(Surface_mesh &mesh) {

auto n = CGAL::orthogonal_vector(p0, p1, p2);
if (CGAL::scalar_product(n, K::Vector_3(0,0,1)) / CGAL::sqrt(n.squared_length()) < 0.95) {
label[face] = LABEL_OTHER;
label[face] = LABEL_UNKNOWN;
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions edge_collapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void compute_stat(Surface_mesh &mesh, const Ablation_study &ablation, TimerUtils
Surface_mesh::Property_map<Surface_mesh::Face_index, unsigned char> mesh_label;
Surface_mesh::Property_map<Surface_mesh::Face_index, std::list<Point_set::Index>> point_in_face;
bool created_mesh_label, created_point_in_face;
boost::tie(mesh_label, created_mesh_label) = mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", LABEL_OTHER);
boost::tie(mesh_label, created_mesh_label) = mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", LABEL_UNKNOWN);

Point_set::Property_map<unsigned char> ground_truth_point_cloud_label;
bool has_ground_truth_point_cloud_label;
Expand Down Expand Up @@ -215,13 +215,13 @@ void add_label(Surface_mesh &mesh, const Point_set &point_cloud, const K::FT min
mesh_label[face] = argmax - face_label;

} else { // We don't have information about this face.
mesh_label[face] = LABEL_OTHER;
mesh_label[face] = LABEL_UNKNOWN;
}
} else {
if (min_point <= 1) { // It's probable that there is no point
faces_with_no_label.insert(face);
} else { // We don't have information about this face.
mesh_label[face] = LABEL_OTHER;
mesh_label[face] = LABEL_UNKNOWN;
}
}
}
Expand All @@ -239,7 +239,7 @@ void add_label(Surface_mesh &mesh, const Point_set &point_cloud, const K::FT min
}
}
if (no_neighbor) {
mesh_label[face] = LABEL_OTHER;
mesh_label[face] = LABEL_UNKNOWN;
face_to_be_removed.push_back(face);
} else {
auto argmax = std::max_element(face_label, face_label+LABELS.size());
Expand All @@ -254,7 +254,7 @@ void add_label(Surface_mesh &mesh, const Point_set &point_cloud, const K::FT min
}
if (face_to_be_removed.size() == 0) {
for (const auto &face_id: faces_with_no_label) {
mesh_label[face_id] = LABEL_OTHER;
mesh_label[face_id] = LABEL_UNKNOWN;
}
break;
} else {
Expand Down Expand Up @@ -1585,7 +1585,7 @@ boost::optional<SMS::Edge_profile<Surface_mesh>::FT> Custom_cost::operator()(con
boost::tie(point_cloud_label, has_label) = point_cloud.property_map<unsigned char>("p:label");
assert(has_label);

std::vector<unsigned char> new_face_label(new_faces.size(), LABEL_OTHER);
std::vector<unsigned char> new_face_label(new_faces.size(), LABEL_UNKNOWN);

// label new face and semantic error
std::set<std::size_t> faces_with_no_label;
Expand All @@ -1611,7 +1611,7 @@ boost::optional<SMS::Edge_profile<Surface_mesh>::FT> Custom_cost::operator()(con
new_face_label[face_id] = argmax - face_label;

} else { // We don't have information about this face.
new_face_label[face_id] = LABEL_OTHER;
new_face_label[face_id] = LABEL_UNKNOWN;
count_semantic_error += points_in_new_face[face_id].size();
new_face_cost[face_id] += beta * points_in_new_face[face_id].size();
// if (profile.v0_v1().idx() == 1710) std::cerr << "face_id: " << face_id << " (" << profile.surface_mesh().face(new_faces_border_halfedge[face_id]) << ") (beta2 x nb_error): " << beta * points_in_new_face[face_id].size() << "\n";
Expand All @@ -1620,7 +1620,7 @@ boost::optional<SMS::Edge_profile<Surface_mesh>::FT> Custom_cost::operator()(con
if (min_point <= 1) { // It's probable that there is no point
faces_with_no_label.insert(face_id);
} else { // We don't have information about this face.
new_face_label[face_id] = LABEL_OTHER;
new_face_label[face_id] = LABEL_UNKNOWN;
}
}
}
Expand Down Expand Up @@ -1649,7 +1649,7 @@ boost::optional<SMS::Edge_profile<Surface_mesh>::FT> Custom_cost::operator()(con
}
}
if (no_neighbor) {
new_face_label[face_id] = LABEL_OTHER;
new_face_label[face_id] = LABEL_UNKNOWN;
face_to_be_removed.push_back(face_id);
} else {
auto argmax = std::max_element(face_label, face_label+LABELS.size());
Expand All @@ -1664,7 +1664,7 @@ boost::optional<SMS::Edge_profile<Surface_mesh>::FT> Custom_cost::operator()(con
}
if (face_to_be_removed.size() == 0) {
for (const auto &face_id: faces_with_no_label) {
new_face_label[face_id] = LABEL_OTHER;
new_face_label[face_id] = LABEL_UNKNOWN;
}
break;
} else {
Expand Down Expand Up @@ -1815,7 +1815,7 @@ void My_visitor::OnStarted (Surface_mesh&) {
if (beta > 0 || gamma > 0 || params.semantic_border_optimization > 0) {
// Add label to face
bool created_label;
boost::tie(mesh_label, created_label) = mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", LABEL_OTHER);
boost::tie(mesh_label, created_label) = mesh.add_property_map<Surface_mesh::Face_index, unsigned char>("f:label", LABEL_UNKNOWN);
}

if (beta > 0 || gamma > 0 || params.label_preservation > 0 || params.semantic_border_optimization > 0) {
Expand Down Expand Up @@ -2049,14 +2049,14 @@ void My_visitor::OnStarted (Surface_mesh&) {
mesh_label[face] = argmax - face_label;

} else { // We don't have information about this face.
mesh_label[face] = LABEL_OTHER;
mesh_label[face] = LABEL_UNKNOWN;
face_costs[face] += beta * point_in_face[face].size();
}
} else {
if (min_point <= 1) { // It's probable that there is no point
faces_with_no_label.insert(face);
} else { // We don't have information about this face.
mesh_label[face] = LABEL_OTHER;
mesh_label[face] = LABEL_UNKNOWN;
}
}
}
Expand All @@ -2074,7 +2074,7 @@ void My_visitor::OnStarted (Surface_mesh&) {
}
}
if (no_neighbor) {
mesh_label[face] = LABEL_OTHER;
mesh_label[face] = LABEL_UNKNOWN;
face_to_be_removed.push_back(face);
} else {
auto argmax = std::max_element(face_label, face_label+LABELS.size());
Expand All @@ -2089,7 +2089,7 @@ void My_visitor::OnStarted (Surface_mesh&) {
}
if (face_to_be_removed.size() == 0) {
for (const auto &face_id: faces_with_no_label) {
mesh_label[face_id] = LABEL_OTHER;
mesh_label[face_id] = LABEL_UNKNOWN;
}
break;
} else {
Expand Down Expand Up @@ -2566,7 +2566,7 @@ Point_set compute_point_cloud (Surface_mesh& mesh) {
void associate_mesh_point_cloud (Surface_mesh& mesh, Point_set& point_cloud) {
Point_set::Property_map<unsigned char> point_cloud_label;
bool created_point_label;
boost::tie (point_cloud_label, created_point_label) = point_cloud.add_property_map<unsigned char>("p:label", LABEL_OTHER);
boost::tie (point_cloud_label, created_point_label) = point_cloud.add_property_map<unsigned char>("p:label", LABEL_UNKNOWN);

Surface_mesh::Property_map<Surface_mesh::Face_index, unsigned char> mesh_label;
bool has_mesh_label;
Expand Down
4 changes: 2 additions & 2 deletions label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static std::array<Label, 46> LABELS {
Label(45, "unknown", 250, 250, 150)
};

const unsigned char LABEL_OTHER = 45;

const unsigned char LABEL_OTHER = 0; // use when the label is nothing from the list
const unsigned char LABEL_UNKNOWN = 45; // use for face without data or not plane road or rails
const unsigned char LABEL_RAIL = 27;
const unsigned char LABEL_WATER = 21;
const unsigned char LABEL_ROAD = 28;
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ std::tuple<Surface_mesh, std::tuple<Surface_mesh, Point_set>> compute_meshes(con
Point_set point_cloud;
bool created_point_label;
Point_set::Property_map<unsigned char> point_cloud_label;
boost::tie (point_cloud_label, created_point_label) = point_cloud.add_property_map<unsigned char>("p:label", LABEL_OTHER);
boost::tie (point_cloud_label, created_point_label) = point_cloud.add_property_map<unsigned char>("p:label", LABEL_UNKNOWN);
assert(created_point_label);

// Add points
Expand Down
4 changes: 2 additions & 2 deletions main_edge_collapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int main(int argc, char **argv) {
// Get or create created_point_label
bool created_point_label;
Point_set::Property_map<unsigned char> point_cloud_label;
boost::tie (point_cloud_label, created_point_label) = point_cloud.add_property_map<unsigned char>("p:label", LABEL_OTHER);
boost::tie (point_cloud_label, created_point_label) = point_cloud.add_property_map<unsigned char>("p:label", LABEL_UNKNOWN);
if (created_point_label) {
std::cout << "Point cloud has no label" << std::endl;

Expand All @@ -288,7 +288,7 @@ int main(int argc, char **argv) {
assert(has_point_int_label);
for (auto ph: point_cloud) {
int value = int_label[ph];
if (value < 0 || ((unsigned int) value) >= LABELS.size()) value = LABEL_OTHER;
if (value < 0 || ((unsigned int) value) >= LABELS.size()) value = LABEL_UNKNOWN;
point_cloud_label[ph] = static_cast<unsigned char>(value);
}
std::cout << "Point cloud label from int_label property" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::pair<int,int> Raster::grid_conversion(int P, int L, double grid_to_crs[6],
}

void Raster::align_land_cover_and_dsm() {
std::vector<std::vector<unsigned char>> new_land_cover = std::vector<std::vector<unsigned char>>(ySize, std::vector<unsigned char>(xSize, LABEL_OTHER));
std::vector<std::vector<unsigned char>> new_land_cover = std::vector<std::vector<unsigned char>>(ySize, std::vector<unsigned char>(xSize, LABEL_UNKNOWN));
for (int L = 0; L < ySize; L++) {
for (int P = 0; P < xSize; P++) {
float neighboors_count[LABELS.size()] = {0};
Expand Down Expand Up @@ -334,7 +334,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<std::vector<unsigned char>>(ySize, std::vector<unsigned char>(xSize, LABEL_OTHER));
land_cover = std::vector<std::vector<unsigned char>>(ySize, std::vector<unsigned char>(xSize, LABEL_UNKNOWN));
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 + ".");
Expand All @@ -358,7 +358,7 @@ 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.");
}
if (value >= LABELS.size()) value = LABEL_OTHER;
if (value >= LABELS.size()) value = LABEL_UNKNOWN;
land_cover[L][P] = value;
}
}
Expand Down

0 comments on commit 56965be

Please sign in to comment.