Skip to content

Commit f80b418

Browse files
authored
Merge pull request #33 from AlpineMapsOrg/dag-builder
Dag builder
2 parents 0912bbf + d220711 commit f80b418

74 files changed

Lines changed: 3621 additions & 1940 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ jobs:
8888
- name: Install LLVM 23
8989
if: matrix.cxx == 'clang++-23'
9090
run: |
91-
wget -qO /tmp/llvm.sh https://apt.llvm.org/llvm.sh
92-
chmod +x /tmp/llvm.sh
93-
sudo /tmp/llvm.sh 23
94-
sudo apt-get install -y --no-install-recommends libclang-rt-23-dev
91+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null
92+
echo "deb https://apt.llvm.org/noble/ llvm-toolchain-noble-23 main" | sudo tee /etc/apt/sources.list.d/llvm-23.list
93+
sudo apt-get update
94+
sudo apt-get install -y --no-install-recommends clang-23 lld-23 libclang-rt-23-dev
9595
9696
- name: Install GCC ${{ matrix.cxx }}
9797
if: matrix.cxx == 'g++-16'

src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
set(CMAKE_CXX_STANDARD 20)
2+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3+
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
4+
15
# Dependencies used by the unconditional terrainlib umbrella target.
26
find_package(ZLIB REQUIRED)
37

@@ -10,7 +14,7 @@ target_include_directories(Eigen3 SYSTEM INTERFACE ${eigen_SOURCE_DIR})
1014
alp_setup_cmake_project(boost URL https://github.com/boostorg/boost.git COMMITISH "boost-1.88.0" CMAKE_ARGUMENTS -DBOOST_ENABLE_PYTHON=OFF -DBUILD_TESTING=OFF "-DBOOST_INCLUDE_LIBRARIES='graph\;multiprecision\;heap\;format\;logic'")
1115
find_package(Boost CONFIG REQUIRED)
1216

13-
alp_setup_cmake_project(tbb URL https://github.com/uxlfoundation/oneTBB.git COMMITISH v2023.1.0 CMAKE_ARGUMENTS -DTBB_TEST=OFF)
17+
alp_setup_cmake_project(tbb URL https://github.com/uxlfoundation/oneTBB.git COMMITISH v2023.1.0 CMAKE_ARGUMENTS -DTBB_TEST=OFF -DTBBMALLOC_BUILD=OFF)
1418
find_package(TBB REQUIRED)
1519

1620
include(../cmake/SetupGDAL.cmake)
@@ -41,6 +45,7 @@ target_include_directories(tl_expected SYSTEM INTERFACE ${tl_expected_SOURCE_DIR
4145

4246
set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "SPDLOG_FMT_EXTERNAL" FORCE)
4347
alp_add_git_repository(spdlog URL https://github.com/gabime/spdlog.git COMMITISH v1.17.0)
48+
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
4449

4550
alp_add_git_repository(zpp_bits URL https://github.com/eyalz800/zpp_bits.git COMMITISH v4.7.3 DO_NOT_ADD_SUBPROJECT)
4651
add_library(zpp_bits INTERFACE)
@@ -50,6 +55,8 @@ alp_add_git_repository(libassert URL https://github.com/jeremy-rifkin/libassert.
5055
alp_add_git_repository(magic_enum URL https://github.com/Neargye/magic_enum.git COMMITISH v0.9.7)
5156
alp_add_git_repository(meshoptimizer URL https://github.com/zeux/meshoptimizer.git COMMITISH v1.0.1)
5257

58+
alp_add_git_repository(wideinteger URL https://github.com/ckormanyos/wide-integer.git COMMITISH 719cbbd557fe974f48b055568e2b149b2444bee9)
59+
5360
set(LIBIGL_COPYLEFT_CORE ON)
5461
set(LIBIGL_RESTRICTED_TRIANGLE ON)
5562
alp_add_git_repository(libigl URL https://github.com/libigl/libigl.git COMMITISH v2.6.0)

src/dag_builder/Partitioning.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
struct [[nodiscard]] Partitioning {
88
uint32_t partition_count = 0;
9+
uint32_t clusters_per_partition = 0; // nominal size the partitioning targeted
910
std::vector<uint32_t> cluster_partitions; // original cluster index -> partition index
1011
};

src/dag_builder/atlas/Packer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ inline void normalize_uvs(std::span<glm::dvec2> uvs) {
3838

3939
struct Packer::Impl {
4040
std::unique_ptr<xatlas::Atlas, decltype(&xatlas::Destroy)> atlas;
41-
double total_effective_pixel_area = 0.0;
4241

4342
Impl() : atlas(xatlas::Create(), xatlas::Destroy) {}
4443

4544
void add_uv_mesh(const UvMesh& mesh) {
46-
this->total_effective_pixel_area += glm::compMul(glm::dvec2(mesh.texture_size));
47-
4845
std::vector<glm::vec2> scaled_uvs = transform_vector(mesh.uvs, [&](const glm::dvec2 &uv) {
4946
const glm::dvec2 scaled = uv * glm::dvec2(mesh.texture_size);
5047
return glm::vec2(scaled);
@@ -91,7 +88,11 @@ struct Packer::Impl {
9188

9289
normalize_uvs(uvs.flat());
9390

94-
return Packing(uvs, this->atlas->utilization[0]);
91+
const glm::dvec2 atlas_size(this->atlas->width, this->atlas->height);
92+
const double aspect = atlas_size.y > 0 ? atlas_size.x / atlas_size.y : 1.0;
93+
const double utilization = this->atlas->utilization[0];
94+
95+
return Packing(uvs, utilization, aspect);
9596
}
9697
};
9798

src/dag_builder/atlas/Packer.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <glm/glm.hpp>
99

10-
#include "number_utils.h"
1110
#include "SegmentedBuffer.h"
1211

1312
namespace atlas {
@@ -21,10 +20,10 @@ struct UvMesh {
2120
class Packing {
2221
public:
2322
Packing() = default;
24-
Packing(std::vector<glm::dvec2> uvs, const double effective_pixel_area, const float utilization = 1.0f)
25-
: Packing(SegmentedBuffer<glm::dvec2>(std::move(uvs)), effective_pixel_area, utilization) {}
26-
Packing(SegmentedBuffer<glm::dvec2> uvs, const double effective_pixel_area, const float utilization = 1.0f)
27-
: _uvs(std::move(uvs)), _effective_pixel_area(effective_pixel_area), _utilization(utilization) {}
23+
Packing(std::vector<glm::dvec2> uvs, const double utilization = 1.0, const double aspect = 1.0)
24+
: Packing(SegmentedBuffer<glm::dvec2>(std::move(uvs)), utilization, aspect) {}
25+
Packing(SegmentedBuffer<glm::dvec2> uvs, const double utilization = 1.0, const double aspect = 1.0)
26+
: _uvs(std::move(uvs)), _utilization(utilization), _aspect(aspect) {}
2827

2928
std::span<const glm::dvec2> uvs_for_mesh(const uint32_t mesh_index) const {
3029
return this->_uvs.segment(mesh_index);
@@ -37,22 +36,18 @@ class Packing {
3736
return this->_uvs.backing();
3837
}
3938

40-
// Sum of effective input pixels (source-texture pixels actually covered by UVs) across all packed meshes.
41-
double effective_pixel_area() const {
42-
return this->_effective_pixel_area;
39+
double utilization() const {
40+
return this->_utilization;
4341
}
4442

45-
// Fraction of the packed atlas actually covered by charts. 1.0 for
46-
// packings that were not produced by the chart packer (e.g. a single
47-
// mesh's own UVs), since there is no wasted atlas space to account for.
48-
float utilization() const {
49-
return this->_utilization;
43+
double aspect() const {
44+
return this->_aspect;
5045
}
5146

5247
private:
5348
SegmentedBuffer<glm::dvec2> _uvs;
54-
double _effective_pixel_area = 0.0;
55-
float _utilization = 1.0f;
49+
double _utilization = 1.0;
50+
double _aspect = 1.0;
5651
};
5752

5853
class Packer {

0 commit comments

Comments
 (0)