Skip to content

Commit 90a1edb

Browse files
committed
Merge branch 'dev'
2 parents 9ca4a35 + 3fb9c7a commit 90a1edb

603 files changed

Lines changed: 21013 additions & 11206 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/
2+
build_clang/
23
.cache
3-
.vscode
4+
.vscode

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@
2929
[submodule "external/nanoflann"]
3030
path = external/nanoflann
3131
url = https://github.com/jlblancoc/nanoflann.git
32+
[submodule "external/terrain-descriptors"]
33+
path = external/terrain-descriptors
34+
url = git@github.com:otto-link/terrain-descriptors.git

CMakeLists.txt

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,139 @@
11
cmake_minimum_required(VERSION 3.22)
22

3-
project(highmap-root)
3+
# -----------------------------------------------------------------------------
4+
# Optional: force clang Usage: cmake -B build -DCMAKE_C_COMPILER=clang
5+
# -DCMAKE_CXX_COMPILER=clang++
6+
# -----------------------------------------------------------------------------
7+
8+
project(highmap-root LANGUAGES C CXX)
9+
10+
# -----------------------------------------------------------------------------
11+
# Options
12+
# -----------------------------------------------------------------------------
413

514
option(HIGHMAP_ENABLE_OPENCL "" ON)
615
option(HIGHMAP_ENABLE_EXAMPLES "" ON)
716
option(HIGHMAP_ENABLE_TESTS "" ON)
17+
option(HIGHMAP_ENABLE_BENCHMARKS "" ON)
18+
19+
# -----------------------------------------------------------------------------
20+
# C++
21+
# -----------------------------------------------------------------------------
822

923
set(CMAKE_CXX_STANDARD 20)
24+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
25+
set(CMAKE_CXX_EXTENSIONS OFF)
26+
27+
# -----------------------------------------------------------------------------
28+
# Compiler flags
29+
# -----------------------------------------------------------------------------
30+
31+
if(MSVC)
32+
33+
message(STATUS "Compiler: MSVC")
34+
35+
add_definitions(-DHMAP_MSVC)
36+
37+
add_compile_options(/W4 /Od)
38+
39+
add_compile_definitions(M_PI=3.14159265358979323846)
40+
41+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
42+
43+
message(STATUS "Compiler: Clang")
44+
45+
add_compile_options(
46+
-Wall
47+
-Wextra
48+
-Wpedantic
49+
-O3
50+
-Ofast
51+
-ffast-math
52+
-pthread
53+
-fPIC
54+
-Wno-deprecated-enum-enum-conversion)
55+
56+
add_compile_definitions(LOG_LEVEL=3)
57+
58+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
59+
60+
message(STATUS "Compiler: GCC")
61+
62+
add_compile_options(
63+
-Wall
64+
-Wextra
65+
-O3
66+
-Ofast
67+
-ffast-math
68+
-pthread
69+
-fPIC
70+
-Wno-free-nonheap-object
71+
-Wno-deprecated-enum-enum-conversion)
72+
73+
add_compile_definitions(LOG_LEVEL=3)
1074

11-
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
12-
# MSVC compiler options
13-
set(CMAKE_CXX_FLAGS
14-
"${CMAKE_CXX_FLAGS} /W4 /Od /D M_PI=3.14159265358979323846")
15-
16-
message(STATUS "MSVC compiler...")
17-
add_definitions("-DHMAP_MSVC")
18-
else()
19-
# GNU compiler options
20-
set(CMAKE_CXX_FLAGS
21-
"${CMAKE_CXX_FLAGS} -Wall -Wextra -O3 -Ofast -ffast-math -pthread -fPIC -DLOG_LEVEL=3 -Wno-free-nonheap-object -Wno-deprecated-enum-enum-conversion"
22-
)
2375
endif()
2476

77+
# -----------------------------------------------------------------------------
78+
# Output
79+
# -----------------------------------------------------------------------------
80+
2581
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
2682

27-
# --- dependencies
83+
# -----------------------------------------------------------------------------
84+
# Dependencies
85+
# -----------------------------------------------------------------------------
2886

2987
find_package(GSL REQUIRED COMPONENTS gsl gslcblas)
3088
find_package(assimp REQUIRED)
3189
find_package(glm REQUIRED)
3290
find_package(OpenMP REQUIRED)
3391
find_package(OpenCV REQUIRED)
3492
find_package(OpenCL REQUIRED)
93+
3594
include_directories(${OpenCV_INCLUDE_DIRS})
3695

37-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
96+
# OpenMP
97+
add_compile_options(${OpenMP_CXX_FLAGS})
3898

99+
# OpenCL
39100
add_compile_definitions(CL_HPP_MINIMUM_OPENCL_VERSION=120
40101
CL_HPP_TARGET_OPENCL_VERSION=120)
41102

103+
# -----------------------------------------------------------------------------
104+
# External libs
105+
# -----------------------------------------------------------------------------
106+
42107
add_subdirectory(external)
43108

44-
# --- library
109+
# -----------------------------------------------------------------------------
110+
# Library
111+
# -----------------------------------------------------------------------------
45112

46113
add_subdirectory(HighMap)
47114

48-
# --- everything else...
115+
# -----------------------------------------------------------------------------
116+
# Examples
117+
# -----------------------------------------------------------------------------
49118

50119
if(HIGHMAP_ENABLE_EXAMPLES)
51-
add_subdirectory(${PROJECT_SOURCE_DIR}/examples)
120+
add_subdirectory(examples)
52121
endif()
53122

123+
# -----------------------------------------------------------------------------
124+
# Tests
125+
# -----------------------------------------------------------------------------
126+
54127
if(HIGHMAP_ENABLE_TESTS)
55128
message(STATUS "HighMap tests enabled")
56-
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
129+
add_subdirectory(tests)
130+
endif()
131+
132+
# -----------------------------------------------------------------------------
133+
# Benchmarks
134+
# -----------------------------------------------------------------------------
135+
136+
if(HIGHMAP_ENABLE_BENCHMARKS)
137+
message(STATUS "HighMap benchmarks enabled")
138+
add_subdirectory(benchmarks)
57139
endif()

HighMap/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ target_link_libraries(
3838
nanoflann::nanoflann
3939
nn-c::nn-c
4040
NoiseLib
41+
terrain-descriptors
4142
OpenMP::OpenMP_CXX
4243
${OpenCV_LIBS}
4344
point_sampler

HighMap/include/highmap.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "highmap/authoring.hpp"
1717
#include "highmap/blending.hpp"
1818
#include "highmap/boundary.hpp"
19+
#include "highmap/carving.hpp"
1920
#include "highmap/colorize.hpp"
2021
#include "highmap/colormaps.hpp"
2122
#include "highmap/convolve.hpp"
@@ -40,12 +41,14 @@
4041
#include "highmap/interpolate_array.hpp"
4142
#include "highmap/interpolate_curve.hpp"
4243
#include "highmap/kernels.hpp"
43-
#include "highmap/math.hpp"
44+
#include "highmap/local_metrics.hpp"
45+
#include "highmap/math/core.hpp"
4446
#include "highmap/morphology.hpp"
4547
#include "highmap/multiscale/downscaling.hpp"
4648
#include "highmap/multiscale/pyramid.hpp"
4749
#include "highmap/multiscale/upscaling.hpp"
4850
#include "highmap/opencl/gpu_opencl.hpp"
51+
#include "highmap/openmp.hpp"
4952
#include "highmap/operator.hpp"
5053
#include "highmap/primitives.hpp"
5154
#include "highmap/random.hpp"
@@ -55,6 +58,7 @@
5558
#include "highmap/selector.hpp"
5659
#include "highmap/shadows.hpp"
5760
#include "highmap/shortest_path.hpp"
61+
#include "highmap/statistics.hpp"
5862
#include "highmap/synthesis.hpp"
5963
#include "highmap/tensor.hpp"
6064
#include "highmap/terrain_tri_mesh.hpp"

HighMap/include/highmap/algebra.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ struct IVec2Hash
123123
}
124124
};
125125

126+
struct IVec2Eq
127+
{
128+
bool operator()(const glm::ivec2 &a, const glm::ivec2 &b) const noexcept
129+
{
130+
return a == b;
131+
}
132+
};
133+
126134
// for glm::ivec4 map
127135
struct IVec4Hash
128136
{
@@ -154,6 +162,11 @@ inline glm::vec4 adjust(const glm::vec4 &v,
154162
return glm::vec4{v.x + dx, v.y + dy, v.z + dz, v.w + dw};
155163
}
156164

165+
inline glm::vec4 adjust(const glm::vec4 &v, float dr)
166+
{
167+
return glm::vec4{v.x - dr, v.y + dr, v.z - dr, v.w + dr};
168+
}
169+
157170
/**
158171
* @brief Mat class for basic manipulation of 2D matrices.
159172
*

HighMap/include/highmap/array.hpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
typedef unsigned int uint;
1515

1616
#include <functional>
17-
#include <opencv2/core/mat.hpp>
1817
#include <random>
1918

19+
#include <opencv2/core/mat.hpp>
20+
2021
#include "highmap/algebra.hpp"
2122
#include "highmap/colormaps.hpp"
2223

@@ -60,6 +61,9 @@ class Array
6061
Array(glm::ivec2 shape); ///< @overload
6162
Array(glm::ivec2 shape, float value); ///< @overload
6263
Array(const std::string &filename, bool flip_j = false); ///< @overload
64+
Array(const std::vector<std::vector<float>> &data); ///< @overload
65+
Array(const std::initializer_list<std::initializer_list<float>>
66+
&data); ///< @overload
6367

6468
//----------------------------------------
6569
// overload
@@ -99,7 +103,6 @@ class Array
99103
* @return Array& Reference to the current Array object.
100104
*/
101105
Array &operator+=(const float value);
102-
103106
Array &operator+=(const Array &array); ///< @overload
104107

105108
/**
@@ -304,13 +307,6 @@ class Array
304307
*/
305308
std::vector<float> col_to_vector(int j);
306309

307-
/**
308-
* @brief Return the number of non-zero elements in the array.
309-
*
310-
* @return int The number of non-zero elements.
311-
*/
312-
int count_non_zero();
313-
314310
/**
315311
* @brief Distribute a value 'amount' around the four cells (i, j), (i + 1,
316312
* j), (i, j + 1), (i + 1, j + 1) by "reversing" the bilinear interpolation.
@@ -352,7 +348,7 @@ class Array
352348
/**
353349
* @brief Debug tool, dump array content as an ASCII histogram to the consol.
354350
*/
355-
void dump_histogram(const std::string &msg = "") const;
351+
void dump_histogram(int bins = 32, const std::string &msg = "") const;
356352

357353
/**
358354
* @brief Extracts a subarray defined by the slice indices {i1, i2, j1, j2}
@@ -640,6 +636,12 @@ class Array
640636
*/
641637
float mean() const;
642638

639+
/**
640+
* @brief Return the median value of the elements in the array.
641+
* @return float The median value of the elements in the array.
642+
*/
643+
float median() const;
644+
643645
/**
644646
* @brief Return the value of the smallest element in the array.
645647
*
@@ -990,6 +992,24 @@ class Array
990992
std::vector<float> unique_values() const;
991993
};
992994

995+
// ==========================================================================
996+
// Functions
997+
// ==========================================================================
998+
999+
/**
1000+
* @brief Count the number of non-zero elements in the array.
1001+
* @param array Input array.
1002+
* @return Number of elements not equal to 0.
1003+
*/
1004+
size_t count_non_zero(const Array &array);
1005+
1006+
/**
1007+
* @brief Count the number of zero elements in the array.
1008+
* @param array Input array.
1009+
* @return Number of elements equal to 0.
1010+
*/
1011+
size_t count_zero(const Array &array);
1012+
9931013
/**
9941014
* @brief Converts an OpenCV `cv::Mat` to a 2D `Array` with optional value
9951015
* scaling to \[0, 1\].
@@ -1018,9 +1038,9 @@ Array cv_mat_to_array(const cv::Mat &mat,
10181038
bool remap_values = true,
10191039
bool flip_j = false);
10201040

1021-
//-----------------------------------
1041+
// ==========================================================================
10221042
// per cell operations wrapper(s)
1023-
//-----------------------------------
1043+
// ==========================================================================
10241044

10251045
/// Apply a function to every cell (mutable).
10261046
template <typename Fn> inline void for_each_cell(Array &a, Fn &&fn)

0 commit comments

Comments
 (0)