Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
otto-link committed Apr 28, 2024
2 parents 328cd84 + 4c79fc5 commit d9bbe92
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 142 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ find_package(Eigen3 REQUIRED)
find_package(GSL REQUIRED COMPONENTS gsl gslcblas)
find_package(PNG REQUIRED) # libpng
find_package(assimp REQUIRED)
find_package(glm REQUIRED) # by hmm

if(HIGHMAP_ENABLE_OPENCL)
find_package(OpenCL REQUIRED)
Expand Down
31 changes: 13 additions & 18 deletions HighMap/include/highmap/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,19 @@ std::vector<uint8_t> colorize_grayscale(const Array &array,
std::vector<uint8_t> colorize_histogram(const Array &array,
Vec2<int> step = {1, 1});

// /**
// * @brief Convert 3 array element values to a color data (3 channels RGB in
// [0,
// * 255]) use a multivariate colormap.
// *
// * @param c0 First array.
// * @param c1 Second array.
// * @param c2 Third array.
// * @param clut Colormap Lookup Table object.
// * @param hillshading Activate hillshading.
// * @return std::vector<uint8_t> Vector containing colors (size : shape[0] *
// * shape[1] * 3 channels for RGB).
// */
// std::vector<uint8_t> colorize_trivariate(const Array &c0,
// const Array &c1,
// const Array &c2,
// Clut3D &clut,
// bool hillshading);
/**
* @brief Export a pair of arrays to a 8 bit colored image.
* @param array1 Input array.
* @param array2 Input array.
* @return Output image.
*
* **Example**
* @include ex_colorize_vec2.cpp
*
* **Result**
* @image html ex_colorize_vec2.png
*/
std::vector<uint8_t> colorize_vec2(const Array &array1, const Array &array2);

void convert_rgb_to_ryb(Array &r,
Array &g,
Expand Down
4 changes: 2 additions & 2 deletions HighMap/include/highmap/noise_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#pragma once
#include <functional>

#include "AnyInterpolator.hpp"
#include "FastNoiseLite.h"
#include "Interpolate.hpp"
#include "libInterpolate/AnyInterpolator.hpp"
#include "libInterpolate/Interpolate.hpp"
#include "macrologger.h"

#include "highmap/op.hpp"
Expand Down
12 changes: 0 additions & 12 deletions HighMap/include/highmap/primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ Array noise(NoiseType noise_type,
* @param shape Array shape.
* @param kw Noise wavenumbers {kx, ky} for each directions.
* @param seed Random seed number.
* @param ratio Amplitude ratio between each Worley noise.
* @param k Transition smoothing parameter.
* @param octaves Number of octaves.
* @param weigth Octave weighting.
* @param persistence Octave persistence.
Expand Down Expand Up @@ -351,8 +349,6 @@ Array noise_fbm(NoiseType noise_type,
* @param shape Array shape.
* @param kw Noise wavenumbers {kx, ky} for each directions.
* @param seed Random seed number.
* @param ratio Amplitude ratio between each Worley noise.
* @param k Transition smoothing parameter.
* @param octaves Number of octaves.
* @param weigth Octave weighting.
* @param persistence Octave persistence.
Expand Down Expand Up @@ -392,8 +388,6 @@ Array noise_iq(NoiseType noise_type,
* @param shape Array shape.
* @param kw Noise wavenumbers {kx, ky} for each directions.
* @param seed Random seed number.
* @param ratio Amplitude ratio between each Worley noise.
* @param k Transition smoothing parameter.
* @param octaves Number of octaves.
* @param weigth Octave weighting.
* @param persistence Octave persistence.
Expand Down Expand Up @@ -439,8 +433,6 @@ Array noise_jordan(NoiseType noise_type,
* @param shape Array shape.
* @param kw Noise wavenumbers {kx, ky} for each directions.
* @param seed Random seed number.
* @param ratio Amplitude ratio between each Worley noise.
* @param k Transition smoothing parameter.
* @param octaves Number of octaves.
* @param weigth Octave weighting.
* @param persistence Octave persistence.
Expand Down Expand Up @@ -478,8 +470,6 @@ Array noise_pingpong(NoiseType noise_type,
* @param shape Array shape.
* @param kw Noise wavenumbers {kx, ky} for each directions.
* @param seed Random seed number.
* @param ratio Amplitude ratio between each Worley noise.
* @param k Transition smoothing parameter.
* @param octaves Number of octaves.
* @param weigth Octave weighting.
* @param persistence Octave persistence.
Expand Down Expand Up @@ -519,8 +509,6 @@ Array noise_ridged(NoiseType noise_type,
* @param shape Array shape.
* @param kw Noise wavenumbers {kx, ky} for each directions.
* @param seed Random seed number.
* @param ratio Amplitude ratio between each Worley noise.
* @param k Transition smoothing parameter.
* @param octaves Number of octaves.
* @param weigth Octave weighting.
* @param persistence Octave persistence.
Expand Down
4 changes: 2 additions & 2 deletions HighMap/src/geometry/cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <iomanip>
#include <string>

#include "AnyInterpolator.hpp"
#include "Interpolate.hpp"
#include "libInterpolate/AnyInterpolator.hpp"
#include "libInterpolate/Interpolate.hpp"
#include "macrologger.h"

#include "highmap/geometry.hpp"
Expand Down
2 changes: 1 addition & 1 deletion HighMap/src/heightmap/heightmap_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <future>
#include <thread>

#include "Interpolate.hpp"
#include "libInterpolate/Interpolate.hpp"
#include "macrologger.h"

#include "highmap/heightmap.hpp"
Expand Down
2 changes: 1 addition & 1 deletion HighMap/src/heightmap/heightmap_rgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <future>
#include <thread>

#include "Interpolate.hpp"
#include "libInterpolate/Interpolate.hpp"
#include "macrologger.h"

#include "highmap/colormaps.hpp"
Expand Down
2 changes: 1 addition & 1 deletion HighMap/src/heightmap/heightmap_rgba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <future>
#include <thread>

#include "Interpolate.hpp"
#include "libInterpolate/Interpolate.hpp"
#include "macrologger.h"

#include "highmap/colormaps.hpp"
Expand Down
139 changes: 45 additions & 94 deletions HighMap/src/io/colorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,99 +152,50 @@ std::vector<uint8_t> colorize_histogram(const Array &array, Vec2<int> step)
return img;
}

// std::vector<uint8_t> colorize_trivariate(const Array &c0,
// const Array &c1,
// const Array &c2,
// Clut3D &clut,
// bool hillshading)
// {
// std::vector<uint8_t> img(3 * c0.shape.x * c0.shape.y);

// // TODO vlim and clamping

// // normalization coefficients for each array
// float cmin = c0.min();
// float cmax = c0.max();
// float ac0 = 1.f / (cmax - cmin);
// float bc0 = -cmin / (cmax - cmin);

// cmin = c1.min();
// cmax = c1.max();
// float ac1 = 1.f / (cmax - cmin);
// float bc1 = -cmin / (cmax - cmin);

// cmin = c2.min();
// cmax = c2.max();
// float ac2 = 1.f / (cmax - cmin);
// float bc2 = -cmin / (cmax - cmin);

// int k = 0;

// for (int j = c0.shape.y - 1; j > -1; j--)
// for (int i = 0; i < c0.shape.x; i++)
// {
// // linear interpolation for the first criterion (generally
// // dominant)
// float u;
// int p1 = clut.get_index(ac0 * c0(i, j) + bc0, 0, u);
// int p2 = clut.get_index(ac1 * c1(i, j) + bc1, 1);
// int p3 = clut.get_index(ac2 * c2(i, j) + bc2, 2);

// UNPACK_COLOR(clut.value_at(p1, p2, p3),
// uint8_t r0,
// uint8_t g0,
// uint8_t b0);

// if (p1 < clut.shape[0] - 1)
// {
// UNPACK_COLOR(clut.value_at(p1 + 1, p2, p3),
// uint8_t r1,
// uint8_t g1,
// uint8_t b1);

// img[k++] = (1.f - u) * r0 + u * r1;
// img[k++] = (1.f - u) * g0 + u * g1;
// img[k++] = (1.f - u) * b0 + u * b1;
// }
// else
// {
// img[k++] = r0;
// img[k++] = g0;
// img[k++] = b0;
// }
// }

// // blur colors to smooth nearest interpolation
// {
// std::vector<uint8_t> delta(3 * c0.shape.x * c0.shape.y);

// for (int i = 1; i < c0.shape.x - 1; i++)
// for (int j = 1; j < c0.shape.y - 1; j++)
// {
// int k = j * 3 + i * 3 * c0.shape.y;
// int kn = (j + 1) * 3 + i * 3 * c0.shape.y; // north
// int ks = (j - 1) * 3 + i * 3 * c0.shape.y; // south
// int ke = j * 3 + (i - 1) * 3 * c0.shape.y; // east
// int kw = j * 3 + (i + 1) * 3 * c0.shape.y; // west

// for (int r = 0; r < 3; r++)
// delta[k + r] = (uint8_t)(0.25f * (img[kn + r] + img[ks + r] +
// img[ke + r] + img[kw + r])) -
// img[k + r];
// }

// std::transform(img.begin(),
// img.end(),
// delta.begin(),
// img.begin(),
// [](uint8_t i, uint8_t d) { return i + d; });
// }

// // add hillshading
// if (hillshading)
// apply_hillshade(img, c0);

// return img;
// }
std::vector<uint8_t> colorize_vec2(const Array &array1, const Array &array2)
{
// create image
std::vector<uint8_t> img(3 * array1.shape.x * array1.shape.y);

// normalization factors / 1
float a1 = 0.f;
float b1 = 0.f;
float vmin1 = array1.min();
float vmax1 = array1.max();

if (vmin1 != vmax1)
{
a1 = 1.f / (vmax1 - vmin1);
b1 = -vmin1 / (vmax1 - vmin1);
}

// normalization factors / 2
float a2 = 0.f;
float b2 = 0.f;
float vmin2 = array2.min();
float vmax2 = array2.max();

if (vmin2 != vmax2)
{
a2 = 1.f / (vmax2 - vmin2);
b2 = -vmin2 / (vmax2 - vmin2);
}

int k = 0;

for (int j = array1.shape.y - 1; j > -1; j--)
for (int i = 0; i < array1.shape.x; i++)
{
float u = a1 * array1(i, j) + b1;
float v = a2 * array2(i, j) + b2;
float w = u * v * (1.f - u) * (1.f - v);

img[k++] = (uint8_t)(255.f * u);
img[k++] = (uint8_t)(255.f * v);
img[k++] = (uint8_t)(255.f * w);
}

return img;
}

} // namespace hmap
11 changes: 9 additions & 2 deletions HighMap/src/op/boundaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void make_periodic(Array &array, int nbuffer)
for (int i = 0; i < nbuffer; i++)
{
float r = 0.5f * (float)i / ((float)nbuffer - 1.f);
r = 0.5f * smoothstep3(2.f * r);
for (int j = 0; j < nj; j++)
{
a1(i, j) = (0.5f + r) * array(i, j) + (0.5f - r) * array(ni - 1 - i, j);
Expand All @@ -103,6 +104,7 @@ void make_periodic(Array &array, int nbuffer)
for (int j = 0; j < nbuffer; j++)
{
float r = 0.5f * (float)j / ((float)nbuffer - 1);
r = 0.5f * smoothstep3(2.f * r);
for (int i = 0; i < ni; i++)
{
a2(i, j) = (0.5 + r) * a1(i, j) + (0.5 - r) * a1(i, nj - 1 - j);
Expand Down Expand Up @@ -168,8 +170,13 @@ Array make_periodic_stitching(Array &array, float overlap)
mask(i, j));
}

array_p = array_p.extract_slice(
Vec4<int>(0, array.shape.x - noverlap.x, 0, array.shape.y - noverlap.y));
int nx = (int)(0.5f * noverlap.x);
int ny = (int)(0.5f * noverlap.y);

array_p = array_p.extract_slice(Vec4<int>(nx,
array.shape.x - noverlap.x + nx,
ny,
array.shape.y - noverlap.y + ny));

array_p = array_p.resample_to_shape(shape);

Expand Down
4 changes: 2 additions & 2 deletions HighMap/src/op/filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void gamma_correction_local(Array &array, float gamma, int ir, float k)
for (int i = 0; i < array.shape.x; i++)
for (int j = 0; j < array.shape.y; j++)
{
float v = (array(i, j) - amin(i, j)) /
float v = std::abs(array(i, j) - amin(i, j)) /
(amax(i, j) - amin(i, j) + 1e-30);
v = std::sqrt(v * v + k);
array(i, j) = std::pow(v, gamma) * (amax(i, j) - amin(i, j)) +
Expand All @@ -324,7 +324,7 @@ void gamma_correction_local(Array &array, float gamma, int ir, float k)
for (int i = 0; i < array.shape.x; i++)
for (int j = 0; j < array.shape.y; j++)
{
float v = (array(i, j) - amin(i, j)) /
float v = std::abs(array(i, j) - amin(i, j)) /
(amax(i, j) - amin(i, j) + 1e-30);
array(i, j) = std::pow(v, gamma) * (amax(i, j) - amin(i, j)) +
amin(i, j);
Expand Down
4 changes: 2 additions & 2 deletions HighMap/src/op/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Public License. The full license is in the file LICENSE, distributed with
* this software. */

#include "Interpolate.hpp"
#include "AnyInterpolator.hpp"
#include "libInterpolate/Interpolate.hpp"
#include "libInterpolate/AnyInterpolator.hpp"
#include "macrologger.h"

#include "highmap/array.hpp"
Expand Down
2 changes: 1 addition & 1 deletion HighMap/src/op/recurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <cmath>
#include <random>

#include "Interpolate.hpp"
#include "libInterpolate/Interpolate.hpp"
#include "macrologger.h"

#include "highmap/array.hpp"
Expand Down
4 changes: 2 additions & 2 deletions HighMap/src/primitives/noise_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* this software. */
#include <cmath>

#include "AnyInterpolator.hpp"
#include "FastNoiseLite.h"
#include "Interpolate.hpp"
#include "libInterpolate/AnyInterpolator.hpp"
#include "libInterpolate/Interpolate.hpp"

#include "highmap/noise_function.hpp"
#include "highmap/primitives.hpp"
Expand Down
Binary file added doc/images/ex_colorize_vec2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/ex_colorize_vec2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(ex_colorize_vec2 ex_colorize_vec2.cpp)
target_link_libraries(ex_colorize_vec2 highmap)
13 changes: 13 additions & 0 deletions examples/ex_colorize_vec2/ex_colorize_vec2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "highmap.hpp"

int main(void)
{
hmap::Vec2<int> shape = {256, 256};

hmap::Array x = hmap::slope(shape, 0.f, 1.f);
hmap::Array y = hmap::slope(shape, 90.f, 1.f);

std::vector<uint8_t> img = hmap::colorize_vec2(x, y);

hmap::write_png_rgb_8bit("ex_colorize_vec2.png", img, shape);
}
2 changes: 2 additions & 0 deletions external/hmm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ add_library(${PROJECT_NAME} STATIC ${HMM_SRC})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} PUBLIC ${HMM_INCLUDE_DIR})

target_link_libraries(${PROJECT_NAME} glm::glm)
Loading

0 comments on commit d9bbe92

Please sign in to comment.