Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
handle surface holes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwastberg committed May 2, 2024
1 parent e167819 commit 7d30404
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if(MSVC)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg -DLLVM_ENABLE_ASSERTIONS=ON")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -DLLVM_ENABLE_ASSERTIONS=ON")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif()

Expand Down
20 changes: 17 additions & 3 deletions src/cpp/include/MeshBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ class MeshBuilder
bool weld = false)
{
std::vector<Mesh> multimesh(multi_surface.surfaces.size());
#pragma omp parallel for
// #pragma omp parallel for
for (size_t i = 0; i < multi_surface.surfaces.size(); i++)
{
multimesh[i] = mesh_surface(multi_surface.surfaces[i],
Expand Down Expand Up @@ -742,6 +742,19 @@ class MeshBuilder
auto e_v_prime = transform * e_v;
projected_surface.push_back(Vector2D(e_v_prime.x(), e_v_prime.y()));
}

for (const auto &hole : surface.holes)
{
std::vector<Vector2D> projected_hole;
for (const auto &v : hole)
{
auto e_v = Eigen::Vector3d(v.x, v.y, v.z);
auto e_v_prime = transform * e_v;
projected_hole.push_back(Vector2D(e_v_prime.x(), e_v_prime.y()));
}
sd.push_back(projected_hole);
}

call_triangle(mesh, projected_surface, sd, max_mesh_size, min_mesh_angle,
false);
for (auto &v : mesh.vertices)
Expand All @@ -756,16 +769,17 @@ class MeshBuilder

static void fast_mesh(Mesh &mesh, const Surface &surface)
{
bool has_holes = surface.holes.size() > 0;
if (surface.vertices.size() < 3)
return;
if (surface.vertices.size() == 3)
if (surface.vertices.size() == 3 && !has_holes)
{
mesh.vertices = surface.vertices;
mesh.faces.push_back(Simplex2D(0, 1, 2));
return;
}

if (Geometry::is_convex(surface))
if (Geometry::is_convex(surface) && !has_holes)
{
mesh.vertices = surface.vertices;
for (size_t i = 1; i < surface.vertices.size() - 1; i++)
Expand Down
22 changes: 20 additions & 2 deletions src/cpp/include/model/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,31 @@ class Grid : public Printable
// Compute grid cell containing point (lower left corner)
const double _x = p.x - bounding_box.P.x;
const double _y = p.y - bounding_box.P.y;
const long int ix = Utils::crop(std::lround(_x / xstep - 0.5), xsize, 1);
const long int iy = Utils::crop(std::lround(_y / ystep - 0.5), ysize, 1);
const long int ix = Utils::crop(std::lround( (_x / xstep) - 0.5), xsize, 0);

const long int iy = Utils::crop(std::lround( (_y / ystep) - 0.5), ysize, 0);
i = iy * xsize + ix;

// Map coordinates to [0, 1] x [0, 1] within grid cell
x = (_x - ix * xstep) / xstep;
y = (_y - iy * ystep) / ystep;
// if (y > 1.0)
// {
// info(this->__str__());
//
// info("c1 " + str( _y ) + " " + str(ystep) + " " + str(ysize) );
// info("c2 " + str(_y / ystep ) );
// info("c3 " + str( (_y / ystep) - 0.5 ) );
// info("c4 " + str( std::lround( (_y / ystep) - 0.5)) );
// info("c5 " + str( Utils::crop(std::lround( (_y / ystep) - 0.5), ysize, 0) ));
//
// info("Point p = " + str(p) + " is in cell " + str(i) + " with local " +
// "coordinates (" + str(x) + ", " + str(y) + ")");
// info("step = " + str(xstep) + ", " + str(ystep) + ", " + str(_x) + ", " +
// str(_y));
// info("_x = " + str(_x) + ", _y = " + str(_y));
// info("ix = " + str(ix) + ", iy = " + str(iy));
// }
assert(x >= 0.0 - Constants::epsilon);
assert(x <= 1.0 + Constants::epsilon);
assert(y >= 0.0 - Constants::epsilon);
Expand Down
3 changes: 3 additions & 0 deletions src/dtcc_builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
build_lod1_buildings,
)

from .building.modify import merge_building_footprints


from .geometry_builders.meshes import build_surface_mesh

Expand All @@ -44,4 +46,5 @@
"build_terrain_mesh",
"build_terrain_raster",
"flat_terrain",
"merge_building_footprints"
]

0 comments on commit 7d30404

Please sign in to comment.