Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ipadjen committed Jun 7, 2024
1 parent ad2ee27 commit ccc2a7d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 57 deletions.
5 changes: 3 additions & 2 deletions include/roofer/reconstruction/ArrangementBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ namespace roofer::reconstruction {
new_face->data().is_footprint_hole = false;
old_face->data().in_footprint = true;
old_face->data().is_footprint_hole = false;
// std::cout << "Ignored input footprint hole that is touching "
// "footprint exterior\n";
// std::cout << "Ignored input footprint hole that is
// touching "
// "footprint exterior\n";
} else { // normal holes that do not touch outer_ccb of existing face
new_face->data().in_footprint = !hole_mode;
new_face->data().is_footprint_hole = hole_mode;
Expand Down
24 changes: 11 additions & 13 deletions include/roofer/roofer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ namespace roofer {
* //todo doc
*/
template <typename Footprint>
std::vector<Mesh> reconstruct_single_instance(const PointCollection& points_roof,
const PointCollection& points_ground,
Footprint& footprint,
ReconstructionConfig cfg = ReconstructionConfig()) {
std::vector<Mesh> reconstruct_single_instance(
const PointCollection& points_roof, const PointCollection& points_ground,
Footprint& footprint, ReconstructionConfig cfg = ReconstructionConfig()) {
try {
// check if configuration is valid
if (!cfg.is_valid()) {
Expand Down Expand Up @@ -123,7 +122,7 @@ namespace roofer {
}
auto PlaneDetector_ground = roofer::reconstruction::createPlaneDetector();
if (!points_ground.empty()) {
PlaneDetector_ground->detect(points_ground);
PlaneDetector_ground->detect(points_ground);
}

auto AlphaShaper = roofer::reconstruction::createAlphaShaper();
Expand Down Expand Up @@ -209,19 +208,18 @@ namespace roofer {
* //todo doc
*/
template <typename Footprint>
std::vector<Mesh> reconstruct_single_instance(const PointCollection& points_roof,
Footprint& footprint,
ReconstructionConfig cfg = ReconstructionConfig()) {
std::vector<Mesh> reconstruct_single_instance(
const PointCollection& points_roof, Footprint& footprint,
ReconstructionConfig cfg = ReconstructionConfig()) {
PointCollection points_ground = PointCollection();
return reconstruct_single_instance(points_roof,
points_ground,
footprint,
return reconstruct_single_instance(points_roof, points_ground, footprint,
cfg);
}

//todo maybe move to another location
// todo maybe move to another location
TriangleCollection triangulate_mesh(const Mesh& mesh) {
auto MeshTriangulator = roofer::reconstruction::createMeshTriangulatorLegacy();
auto MeshTriangulator =
roofer::reconstruction::createMeshTriangulatorLegacy();
MeshTriangulator->compute({mesh});

return MeshTriangulator->triangles;
Expand Down
12 changes: 6 additions & 6 deletions rooferpy/example_rooferpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ def read_wkt_from_file(file_path):
def wkt_polygon_to_rings(wkt_str, x_offset=0, y_offset=0):
# Parse WKT string to a shapely geometry object
geom = wkt.loads(wkt_str)

# Ensure the geometry is a Polygon
if geom.geom_type != 'Polygon':
raise ValueError("The WKT geometry is not a Polygon, it is a {0}".format(geom.geom_type))

# Function to convert coordinates to list of lists of 3-element arrays
def coords_to_ring(coords):
return [[float(coord[0]) + x_offset, float(coord[1]) + y_offset, float(coord[2]) if len(coord) == 3 else 0.0] for coord in coords]

# Extract exterior ring
exterior_ring = coords_to_ring(geom.exterior.coords)

# Extract interior rings (if any)
interior_rings = [coords_to_ring(interior.coords) for interior in geom.interiors]

# Combine exterior and interior rings into a single list
all_rings = [exterior_ring] + interior_rings

return all_rings

# Define offsets to avoid truncation errors
Expand Down
74 changes: 40 additions & 34 deletions rooferpy/rooferpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace roofer {
}
}

std::vector<PyMesh> convert_meshes_to_py_meshes(const std::vector<Mesh>& meshes) {
std::vector<PyMesh> convert_meshes_to_py_meshes(
const std::vector<Mesh>& meshes) {
std::vector<PyMesh> py_meshes;
for (const auto& roofer_mesh : meshes) {
PyMesh py_mesh;
Expand Down Expand Up @@ -77,11 +78,10 @@ namespace roofer {
return mesh;
}

std::vector<PyMesh>
py_reconstruct_single_instance(const PyPointCollection& points_roof,
const PyPointCollection & points_ground,
const PyLinearRing& footprint,
ReconstructionConfig cfg = ReconstructionConfig()) {
std::vector<PyMesh> py_reconstruct_single_instance(
const PyPointCollection& points_roof,
const PyPointCollection& points_ground, const PyLinearRing& footprint,
ReconstructionConfig cfg = ReconstructionConfig()) {
PointCollection points_roof_pc, points_ground_pc;
for (const auto& pt : points_roof) {
points_roof_pc.push_back({pt[0], pt[1], pt[2]});
Expand All @@ -91,14 +91,14 @@ namespace roofer {
}
roofer::LinearRing linear_ring;
convert_to_linear_ring(footprint, linear_ring);
auto meshes = reconstruct_single_instance(points_roof_pc, points_ground_pc, linear_ring, cfg);
auto meshes = reconstruct_single_instance(points_roof_pc, points_ground_pc,
linear_ring, cfg);
return convert_meshes_to_py_meshes(meshes);
}

std::vector<PyMesh>
py_reconstruct_single_instance(const PyPointCollection & points_roof,
const PyLinearRing& footprint,
ReconstructionConfig cfg = ReconstructionConfig()) {
std::vector<PyMesh> py_reconstruct_single_instance(
const PyPointCollection& points_roof, const PyLinearRing& footprint,
ReconstructionConfig cfg = ReconstructionConfig()) {
PointCollection points_roof_pc;
for (const auto& pt : points_roof) {
points_roof_pc.push_back({pt[0], pt[1], pt[2]});
Expand All @@ -109,9 +109,9 @@ namespace roofer {
return convert_meshes_to_py_meshes(meshes);
}

//todo move vertex-face data struct to cpp api?
std::tuple<PyPointCollection, PyFaceCollection>
py_triangulate_mesh(const PyMesh& mesh) {
// todo move vertex-face data struct to cpp api?
std::tuple<PyPointCollection, PyFaceCollection> py_triangulate_mesh(
const PyMesh& mesh) {
Mesh roofer_mesh = convert_py_mesh_to_mesh(mesh);
auto tri_mesh = triangulate_mesh(roofer_mesh);

Expand All @@ -125,41 +125,47 @@ namespace roofer {
vertices.push_back(vertex);
}
}
faces.push_back({vertex_map[triangle[0]], vertex_map[triangle[1]], vertex_map[triangle[2]]});
faces.push_back({vertex_map[triangle[0]], vertex_map[triangle[1]],
vertex_map[triangle[2]]});
}
return std::make_tuple(vertices, faces);
}

} // namespace roofer
} // namespace roofer

PYBIND11_MODULE(rooferpy, m) {
py::class_<roofer::ReconstructionConfig>(m, "ReconstructionConfig")
.def(py::init<>())
.def_readwrite("complexity_factor", &roofer::ReconstructionConfig::lambda)
.def_readwrite("clip_ground", &roofer::ReconstructionConfig::clip_ground)
.def_readwrite("lod", &roofer::ReconstructionConfig::lod)
.def_readwrite("lod13_step_height", &roofer::ReconstructionConfig::lod13_step_height)
.def_readwrite("floor_elevation", &roofer::ReconstructionConfig::floor_elevation)
.def_readwrite("override_with_floor_elevation", &roofer::ReconstructionConfig::override_with_floor_elevation)
.def_readwrite("lod13_step_height",
&roofer::ReconstructionConfig::lod13_step_height)
.def_readwrite("floor_elevation",
&roofer::ReconstructionConfig::floor_elevation)
.def_readwrite(
"override_with_floor_elevation",
&roofer::ReconstructionConfig::override_with_floor_elevation)
.def("is_valid", &roofer::ReconstructionConfig::is_valid);

m.def("reconstruct_single_instance",
py::overload_cast<const PyPointCollection&,
const PyPointCollection&,
const PyLinearRing&,
roofer::ReconstructionConfig>(&roofer::py_reconstruct_single_instance),
"Reconstruct a single instance of a building from a point cloud with ground points",
py::arg("points_roof"), py::arg("points_ground"), py::arg("footprint"), py::arg("cfg") = roofer::ReconstructionConfig());
py::overload_cast<const PyPointCollection&, const PyPointCollection&,
const PyLinearRing&, roofer::ReconstructionConfig>(
&roofer::py_reconstruct_single_instance),
"Reconstruct a single instance of a building from a point cloud with "
"ground points",
py::arg("points_roof"), py::arg("points_ground"), py::arg("footprint"),
py::arg("cfg") = roofer::ReconstructionConfig());

m.def("reconstruct_single_instance",
py::overload_cast<const PyPointCollection&,
const PyLinearRing&,
roofer::ReconstructionConfig>(&roofer::py_reconstruct_single_instance),
"Reconstruct a single instance of a building from a point cloud without ground points",
py::arg("points_roof"), py::arg("footprint"), py::arg("cfg") = roofer::ReconstructionConfig());
py::overload_cast<const PyPointCollection&, const PyLinearRing&,
roofer::ReconstructionConfig>(
&roofer::py_reconstruct_single_instance),
"Reconstruct a single instance of a building from a point cloud "
"without ground points",
py::arg("points_roof"), py::arg("footprint"),
py::arg("cfg") = roofer::ReconstructionConfig());

m.def("triangulate_mesh",
&roofer::py_triangulate_mesh,
"Triangulate a mesh",
m.def("triangulate_mesh", &roofer::py_triangulate_mesh, "Triangulate a mesh",
py::arg("mesh"));
}
}
3 changes: 1 addition & 2 deletions src/core/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,7 @@ namespace roofer {
void pop_back_if_equal_to_front(LinearRing& poly) {
auto it = poly.end();
--it;
if((*poly.begin()) == *it)
poly.erase(it);
if ((*poly.begin()) == *it) poly.erase(it);
}

std::time_t Date::to_time_t() {
Expand Down

0 comments on commit ccc2a7d

Please sign in to comment.