HighMap library (C++)
Loading...
Searching...
No Matches
functions.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
16#pragma once
17#include <algorithm>
18#include <cmath>
19#include <cstdint>
20#include <functional>
21#include <memory>
22#include <utility>
23#include <vector>
24
25#include "highmap/array.hpp"
27#include "highmap/math/core.hpp"
29
34#define HMAP_FCT_XY_TYPE std::function<float(float, float, float)>
35
36#define HMAP_GRADIENT_OFFSET 0.001f
37
38namespace hmap
39{
40
54std::function<float(float, float)> make_xy_function_from_array(
55 const Array &array,
56 const BBox2D &bbox = BBox2D::unit());
57
82
83//----------------------------------------
84// Function functors
85//----------------------------------------
86
97{
98public:
99 float operator()(float x, float y, float ctrl_param = 0.f) const;
100
109 ArrayFunction(Array array, glm::vec2 kw, bool periodic = true);
110
116 void set_array(Array new_array)
117 {
118 this->array = new_array;
119 }
120
121protected:
122 glm::vec2 kw;
123 bool periodic;
124
125private:
126 Array array;
127};
128
137{
138public:
139 float operator()(float x, float y, float ctrl_param = 0.f) const;
140
147 BiquadFunction(float gain, glm::vec2 center);
148
149protected:
150 float gain;
151 glm::vec2 center;
152};
153
162{
163public:
164 float operator()(float x, float y, float ctrl_param = 0.f) const;
165
172 BumpFunction(float gain, glm::vec2 center);
173
174protected:
175 float gain;
176 glm::vec2 center;
177};
178
187{
188public:
189 float operator()(float x, float y, float ctrl_param = 0.f) const;
190
204 float depth,
205 float lip_decay,
206 float lip_height_ratio,
207 glm::vec2 center);
208
209protected:
210 float radius;
211 float depth;
212 float lip_decay;
214 glm::vec2 center;
215};
216
222{
223public:
224 float operator()(float x, float y, float ctrl_param = 0.f) const;
225
233 DiskFunction(float radius, float slope, glm::vec2 center);
234
235protected:
236 float radius;
237 float slope;
238 glm::vec2 center;
239};
240
249{
250public:
251 float operator()(float x, float y, float ctrl_param = 0.f) const;
252
259 GaussianPulseFunction(float sigma, glm::vec2 center);
260
266 void set_sigma(float new_sigma)
267 {
268 this->sigma = new_sigma;
269 this->inv_sigma2 = 1.f / (this->sigma * this->sigma);
270 }
271
272protected:
273 float sigma;
274 glm::vec2 center;
275
276private:
277 float inv_sigma2;
278};
279
289{
290public:
291 float operator()(float x, float y, float ctrl_param = 0.f) const;
292
301 QuadSurfaceFunction(float c00, float c10, float c01, float c11);
302
303protected:
304 float c00;
305 float c10;
306 float c01;
307 float c11;
309};
310
316{
317public:
318 float operator()(float x, float y, float ctrl_param = 0.f) const;
319
329 RectangleFunction(float rx,
330 float ry,
331 float angle,
332 float slope,
333 glm::vec2 center);
334
340 void set_angle(float new_angle)
341 {
342 this->angle = new_angle;
343 this->ca = std::cos(angle / 180.f * cte::pi);
344 this->sa = std::sin(angle / 180.f * cte::pi);
345 }
346
347protected:
348 float rx, ry;
349 float angle;
350 float slope;
351 glm::vec2 center;
352
353private:
354 float ca;
355 float sa;
356};
357
366{
367public:
368 float operator()(float x, float y, float ctrl_param = 0.f) const;
369
379 RiftFunction(float angle,
380 float slope,
381 float width,
382 bool sharp_bottom,
383 glm::vec2 center);
384
390 void set_angle(float new_angle)
391 {
392 this->angle = new_angle;
393 this->ca = std::cos(angle / 180.f * cte::pi);
394 this->sa = std::sin(angle / 180.f * cte::pi);
395 }
396
397protected:
398 float angle;
399 float slope;
400 float width;
402 glm::vec2 center;
403
404private:
405 float ca;
406 float sa;
407};
408
417{
418public:
419 float operator()(float x, float y, float ctrl_param = 0.f) const;
420
428 SlopeFunction(float angle, float slope, glm::vec2 center);
429
435 void set_angle(float new_angle)
436 {
437 this->angle = new_angle;
438 this->ca = std::cos(angle / 180.f * cte::pi);
439 this->sa = std::sin(angle / 180.f * cte::pi);
440 }
441
442protected:
443 float angle;
444 float slope;
445 glm::vec2 center;
446
447private:
448 float ca;
449 float sa;
450};
451
460{
461public:
462 float operator()(float x, float y, float ctrl_param = 0.f) const;
463
471 StepFunction(float angle, float slope, glm::vec2 center);
472
478 void set_angle(float new_angle)
479 {
480 this->angle = new_angle;
481 this->ca = std::cos(angle / 180.f * cte::pi);
482 this->sa = std::sin(angle / 180.f * cte::pi);
483 }
484
485protected:
486 float angle;
487 float slope;
488 glm::vec2 center;
489
490private:
491 float ca;
492 float sa;
493};
494
504{
505public:
506 float operator()(float x, float y, float ctrl_param = 0.f) const;
507
521 WaveDuneFunction(glm::vec2 kw,
522 float angle,
523 float xtop,
524 float xbottom,
525 float phase_shift,
526 glm::vec2 center = {0.5f, 0.5f});
527
533 void set_angle(float new_angle)
534 {
535 this->angle = new_angle;
536 this->ca = std::cos(angle / 180.f * cte::pi);
537 this->sa = std::sin(angle / 180.f * cte::pi);
538 }
539
540protected:
541 glm::vec2 kw;
542 float angle;
543 float xtop;
544 float xbottom;
547 glm::vec2 center;
548
549private:
550 float ca;
551 float sa;
552};
553
562{
563public:
564 float operator()(float x, float y, float ctrl_param = 0.f) const;
565
575 WaveSineFunction(glm::vec2 kw,
576 float angle,
577 float phase_shift,
578 glm::vec2 center = {0.5f, 0.5f});
579
585 void set_angle(float new_angle)
586 {
587 this->angle = new_angle;
588 this->ca = std::cos(angle / 180.f * cte::pi);
589 this->sa = std::sin(angle / 180.f * cte::pi);
590 }
591
592protected:
593 glm::vec2 kw;
594 float angle;
596 glm::vec2 center;
597
598private:
599 float ca;
600 float sa;
601};
602
611{
612public:
613 float operator()(float x, float y, float ctrl_param = 0.f) const;
614
624 WaveSquareFunction(glm::vec2 kw,
625 float angle,
626 float phase_shift,
627 glm::vec2 center = {0.5f, 0.5f});
628
634 void set_angle(float new_angle)
635 {
636 this->angle = new_angle;
637 this->ca = std::cos(angle / 180.f * cte::pi);
638 this->sa = std::sin(angle / 180.f * cte::pi);
639 }
640
641protected:
642 glm::vec2 kw;
643 float angle;
645 glm::vec2 center;
646
647private:
648 float ca;
649 float sa;
650};
651
661{
662public:
663 float operator()(float x, float y, float ctrl_param = 0.f) const;
664
675 WaveTriangularFunction(glm::vec2 kw,
676 float angle,
677 float slant_ratio,
678 float phase_shift,
679 glm::vec2 center = {0.5f, 0.5f});
680
686 void set_angle(float new_angle)
687 {
688 this->angle = new_angle;
689 this->ca = std::cos(angle / 180.f * cte::pi);
690 this->sa = std::sin(angle / 180.f * cte::pi);
691 }
692
693protected:
694 glm::vec2 kw;
695 float angle;
698 glm::vec2 center;
699
700private:
701 float ca;
702 float sa;
703};
704
705//----------------------------------------
706// NoiseFunction class and derived
707//----------------------------------------
708
719{
720public:
725 NoiseFunction() : kw(glm::vec2(0.f, 0.f)), seed(0)
726 {
727 }
728
733 NoiseFunction(glm::vec2 kw) : kw(kw), seed(0)
734 {
735 }
736
742 NoiseFunction(glm::vec2 kw, std::uint32_t seed) : kw(kw), seed(seed)
743 {
744 }
745
750 glm::vec2 get_kw() const
751 {
752 return this->kw;
753 }
754
759 std::uint32_t get_seed() const
760 {
761 return this->seed;
762 }
763
768 void set_seed(std::uint32_t new_seed)
769 {
770 this->seed = new_seed;
771 }
772
777 void set_kw(glm::vec2 new_kw)
778 {
779 this->kw = new_kw;
780 }
781
782protected:
783 glm::vec2 kw;
784 std::uint32_t seed;
785};
786
787//----------------------------------------
788// Actual functions
789//----------------------------------------
790
795{
796public:
797 float operator()(float x, float y, float ctrl_param = 0.f) const;
798
802 float mu;
803
812 ParberryFunction(glm::vec2 kw, std::uint32_t seed, float mu);
813
817 void initialize();
818
824 void set_seed(std::uint32_t /*new_seed*/)
825 {
826 // FIX ME seed cannot be changed with current implemtantion.
827 }
828
829private:
833 int perlin_b = 0X100;
834
838 int perlin_bm = 0xff;
839
843 int perlin_n = 0x100;
844
848 std::vector<int> p;
849
853 std::vector<std::vector<float>> g2;
854
858 std::vector<float> m;
859};
860
865{
866public:
867 float operator()(float x, float y, float ctrl_param = 0.f) const;
868
876 PerlinFunction(glm::vec2 kw, std::uint32_t seed);
877
883 void set_seed(std::uint32_t new_seed)
884 {
885 NoiseFunction::set_seed(new_seed);
886 }
887
888private:
889 bool return_cell_value = false;
890};
891
896{
897public:
898 float operator()(float x, float y, float ctrl_param = 0.f) const;
899
907 PerlinBillowFunction(glm::vec2 kw, std::uint32_t seed);
908
914 void set_seed(std::uint32_t new_seed)
915 {
916 NoiseFunction::set_seed(new_seed);
917 }
918
919private:
920 bool return_cell_value = false;
921};
922
927{
928public:
929 float operator()(float x, float y, float ctrl_param = 0.f) const;
930
931 float k;
932
941 PerlinHalfFunction(glm::vec2 kw, std::uint32_t seed, float k);
942
948 void set_seed(std::uint32_t new_seed)
949 {
950 NoiseFunction::set_seed(new_seed);
951 }
952
953private:
954 bool return_cell_value = false;
955};
956
961{
962public:
963 float operator()(float x, float y, float ctrl_param = 0.f) const;
964
972 PerlinMixFunction(glm::vec2 kw, std::uint32_t seed);
973
979 void set_seed(std::uint32_t new_seed)
980 {
981 NoiseFunction::set_seed(new_seed);
982 }
983
984private:
985 bool return_cell_value = false;
986};
987
992{
993public:
994 float operator()(float x, float y, float ctrl_param = 0.f) const;
995
1003 Simplex2Function(glm::vec2 kw, std::uint32_t seed);
1004
1010 void set_seed(std::uint32_t new_seed)
1011 {
1012 NoiseFunction::set_seed(new_seed);
1013 }
1014
1015private:
1016 bool return_cell_value = false;
1017};
1018
1023{
1024public:
1025 float operator()(float x, float y, float ctrl_param = 0.f) const;
1026
1034 Simplex2SFunction(glm::vec2 kw, std::uint32_t seed);
1035
1041 void set_seed(std::uint32_t new_seed)
1042 {
1043 NoiseFunction::set_seed(new_seed);
1044 }
1045
1046private:
1047 bool return_cell_value = false;
1048};
1049
1054{
1055public:
1056 float operator()(float x, float y, float ctrl_param = 0.f) const;
1057
1065 ValueNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1066
1072 void set_seed(std::uint32_t new_seed)
1073 {
1074 NoiseFunction::set_seed(new_seed);
1075 }
1076
1077private:
1078 bool return_cell_value = false;
1079};
1080
1085{
1086public:
1087 float operator()(float x, float y, float ctrl_param = 0.f) const;
1088
1096 ValueCubicNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1097
1103 void set_seed(std::uint32_t new_seed)
1104 {
1105 NoiseFunction::set_seed(new_seed);
1106 }
1107
1108private:
1109 bool return_cell_value = false;
1110};
1111
1116{
1117public:
1118 float operator()(float x, float y, float ctrl_param = 0.f) const;
1119
1126 ValueDelaunayNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1127
1133 void set_kw(glm::vec2 new_kw)
1134 {
1135 NoiseFunction::set_kw(new_kw);
1137 }
1138
1144 void set_seed(std::uint32_t new_seed)
1145 {
1146 NoiseFunction::set_seed(new_seed);
1148 }
1149
1154 std::function<float(float, float, float)> itp_fct;
1155};
1156
1161{
1162public:
1163 float operator()(float x, float y, float ctrl_param = 0.f) const;
1164
1171 ValueLinearNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1172
1178 void set_kw(glm::vec2 new_kw)
1179 {
1180 NoiseFunction::set_kw(new_kw);
1182 }
1183
1189 void set_seed(std::uint32_t new_seed)
1190 {
1191 NoiseFunction::set_seed(new_seed);
1193 }
1194
1199 std::function<float(float, float, float)> itp_fct;
1200};
1201
1206{
1207public:
1208 float operator()(float x, float y, float ctrl_param = 0.f) const;
1209
1217 WorleyFunction(glm::vec2 kw,
1218 std::uint32_t seed,
1219 bool return_cell_value = false);
1220
1226 void set_seed(std::uint32_t new_seed)
1227 {
1228 NoiseFunction::set_seed(new_seed);
1229 }
1230
1231private:
1232 bool return_cell_value = false;
1233};
1234
1239{
1240public:
1241 float operator()(float x, float y, float ctrl_param = 0.f) const;
1242
1246 float ratio;
1247
1251 float k;
1252
1262 WorleyDoubleFunction(glm::vec2 kw, std::uint32_t seed, float ratio, float k);
1263
1269 void set_seed(std::uint32_t new_seed)
1270 {
1271 NoiseFunction::set_seed(new_seed);
1272 }
1273
1274private:
1275 bool return_cell_value = false;
1276};
1277
1278//----------------------------------------
1279// Composite functions
1280//----------------------------------------
1281
1291template <typename BaseFn> class GenericFractalFunction : public NoiseFunction
1292{
1293public:
1303 explicit GenericFractalFunction(BaseFn base,
1304 int octaves,
1305 float weight,
1306 float persistence,
1307 float lacunarity);
1308
1314 void set_kw(glm::vec2 new_kw)
1315 {
1316 NoiseFunction::set_kw(new_kw);
1317 this->base.set_kw(new_kw);
1318 }
1319
1325 void set_lacunarity(float new_lacunarity)
1326 {
1327 this->lacunarity = new_lacunarity;
1328 }
1329
1335 void set_octaves(int new_octaves)
1336 {
1337 this->octaves = new_octaves;
1338 this->update_amp0();
1339 }
1340
1346 void set_persistence(float new_persistence)
1347 {
1348 this->persistence = new_persistence;
1349 this->update_amp0();
1350 }
1351
1357 void set_seed(std::uint32_t new_seed)
1358 {
1359 NoiseFunction::set_seed(new_seed);
1360 this->base.set_seed(new_seed);
1361 }
1362
1368 void scale_amp0(float scale)
1369 {
1370 this->amp0 *= scale;
1371 }
1372
1380 void set_stretch(float new_angle,
1381 float new_stretch,
1382 float new_stretch_decay = 0.f)
1383 {
1384 this->angle = new_angle;
1385 this->stretch = new_stretch;
1386 this->stretch_decay = new_stretch_decay;
1387
1388 float theta = new_angle * 3.14159265358979323846f / 180.f;
1389 this->cos_a = std::cos(theta);
1390 this->sin_a = std::sin(theta);
1391 }
1392
1398 float get_lacunarity() const
1399 {
1400 return this->lacunarity;
1401 }
1402
1408 int get_octaves() const
1409 {
1410 return this->octaves;
1411 }
1412
1418 float get_persistence() const
1419 {
1420 return this->persistence;
1421 }
1422
1428 float get_weight() const
1429 {
1430 return this->weight;
1431 }
1432
1433protected:
1438 void update_amp0();
1439
1443 void apply_stretch(float &x, float &y, int octave) const
1444 {
1445 if (this->stretch == 1.f) return;
1446
1447 float decay = std::pow(1.f - std::clamp(this->stretch_decay, 0.f, 1.f),
1448 static_cast<float>(octave));
1449 float stretch_k = 1.f + (this->stretch - 1.f) * decay;
1450 float inv_stretch = 1.f / std::max(stretch_k, 1e-6f);
1451
1452 float xl = x * this->cos_a + y * this->sin_a;
1453 float yl = -x * this->sin_a + y * this->cos_a;
1454 xl *= inv_stretch;
1455 x = xl * this->cos_a - yl * this->sin_a;
1456 y = xl * this->sin_a + yl * this->cos_a;
1457 }
1458
1459protected:
1460 BaseFn base;
1462 float weight;
1465 float amp0;
1466 float angle = 0.f;
1467 float stretch = 1.f;
1468 float stretch_decay = 0.f;
1469 float cos_a = 1.f;
1470 float sin_a = 0.f;
1471};
1472
1477template <typename BaseFn>
1479{
1480public:
1481 float operator()(float x, float y, float ctrl_param = 0.f) const;
1482
1492 FbmFunction(BaseFn base,
1493 int octaves,
1494 float weight,
1495 float persistence,
1496 float lacunarity);
1497};
1498
1503template <typename BaseFn>
1505{
1506public:
1507 float operator()(float x, float y, float ctrl_param = 0.f) const;
1508
1519 FbmIqFunction(BaseFn base,
1520 int octaves,
1521 float weight,
1522 float persistence,
1523 float lacunarity,
1524 float gradient_scale);
1525
1531 void set_gradient_scale(float new_gradient_scale)
1532 {
1533 this->gradient_scale = new_gradient_scale;
1534 }
1535
1536protected:
1538};
1539
1544template <typename BaseFn>
1546{
1547public:
1548 float operator()(float x, float y, float ctrl_param = 0.f) const;
1549
1563 FbmJordanFunction(BaseFn base,
1564 int octaves,
1565 float weight,
1566 float persistence,
1567 float lacunarity,
1568 float warp0,
1569 float damp0,
1570 float warp_scale,
1571 float damp_scale);
1572
1578 void set_warp0(float new_warp0)
1579 {
1580 this->warp0 = new_warp0;
1581 }
1582
1588 void set_damp0(float new_damp0)
1589 {
1590 this->damp0 = new_damp0;
1591 }
1592
1598 void set_warp_scale(float new_warp_scale)
1599 {
1600 this->warp_scale = new_warp_scale;
1601 }
1602
1608 void set_damp_scale(float new_damp_scale)
1609 {
1610 this->damp_scale = new_damp_scale;
1611 }
1612
1613protected:
1614 float warp0;
1615 float damp0;
1618};
1619
1624template <typename BaseFn>
1626{
1627public:
1628 float operator()(float x, float y, float ctrl_param = 0.f) const;
1629
1640 int octaves,
1641 float weight,
1642 float persistence,
1643 float lacunarity);
1644
1650 void set_k_smoothing(float new_k_smoothing)
1651 {
1652 this->k_smoothing = new_k_smoothing;
1653 }
1654
1655protected:
1657};
1658
1663template <typename BaseFn>
1665{
1666public:
1667 float operator()(float x, float y, float ctrl_param = 0.f) const;
1668
1679 FbmRidgedFunction(BaseFn base,
1680 int octaves,
1681 float weight,
1682 float persistence,
1683 float lacunarity,
1684 float k_smoothing);
1685
1691 void set_k_smoothing(float new_k_smoothing)
1692 {
1693 this->k_smoothing = new_k_smoothing;
1694 }
1695
1696protected:
1698};
1699
1707template <typename BaseFn>
1709{
1710public:
1711 float operator()(float x, float y, float ctrl_param = 0.f) const;
1712
1727 FbmSlopeFunction(BaseFn base,
1728 int octaves,
1729 float weight,
1730 float persistence,
1731 float lacunarity,
1732 float gradient_scale,
1733 float slope_power,
1734 float octave_blend,
1735 float bias_angle = 0.f,
1736 float bias_strength = 0.f);
1737
1744 void set_bias(float new_bias_angle, float new_bias_strength)
1745 {
1746 this->bias_angle = new_bias_angle;
1747 this->bias_strength = std::clamp(new_bias_strength, 0.f, 1.f);
1748 float theta = new_bias_angle * 3.14159265358979323846f / 180.f;
1749 this->bias_cos = std::cos(theta);
1750 this->bias_sin = std::sin(theta);
1751 }
1752
1758 void set_gradient_scale(float new_gradient_scale)
1759 {
1760 this->gradient_scale = new_gradient_scale;
1761 }
1762
1768 void set_slope_power(float new_slope_power)
1769 {
1770 this->slope_power = new_slope_power;
1771 }
1772
1778 void set_octave_blend(float new_octave_blend)
1779 {
1780 this->octave_blend = new_octave_blend;
1781 }
1782
1783protected:
1787 float bias_angle = 0.f;
1788 float bias_strength = 0.f;
1789 float bias_cos = 1.f;
1790 float bias_sin = 0.f;
1791};
1792
1797template <typename BaseFn>
1799{
1800public:
1801 float operator()(float x, float y, float ctrl_param = 0.f) const;
1802
1813 FbmSwissFunction(BaseFn base,
1814 int octaves,
1815 float weight,
1816 float persistence,
1817 float lacunarity,
1818 float warp_scale);
1819
1825 void set_warp_scale(float new_warp_scale)
1826 {
1827 this->warp_scale = new_warp_scale;
1828 this->warp_scale_normalized = new_warp_scale / this->kw.x;
1829 }
1830
1831protected:
1834};
1835
1836//----------------------------------------
1837// Field functions
1838//----------------------------------------
1839
1844template <typename BaseFn> class FieldFunction
1845{
1846public:
1847 float operator()(float x, float y, float ctrl_param = 0.f) const;
1848
1854 explicit FieldFunction(BaseFn base);
1855
1868 FieldFunction(BaseFn base,
1869 std::vector<float> xr,
1870 std::vector<float> yr,
1871 std::vector<float> zr);
1872
1878 void set_xr(std::vector<float> new_xr)
1879 {
1880 this->xr = new_xr;
1881 }
1882
1888 void set_yr(std::vector<float> new_yr)
1889 {
1890 this->yr = new_yr;
1891 }
1892
1899 void set_zr(std::vector<float> new_zr)
1900 {
1901 this->zr = new_zr;
1902 }
1903
1904protected:
1905 std::vector<float> xr;
1907 std::vector<float> yr;
1909 std::vector<float> zr;
1911
1912private:
1913 BaseFn base;
1914};
1915
1916//----------------------------------------
1917// Helpers
1918//----------------------------------------
1919
1930template <typename Fn>
1931decltype(auto) with_noise_function(NoiseType noise_type,
1932 glm::vec2 kw,
1933 std::uint32_t seed,
1934 Fn &&fn);
1935
1936} // namespace hmap
1937
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Axis-aligned 2D bounding box in world coordinates.
ArrayFunction(Array array, glm::vec2 kw, bool periodic=true)
Construct a new ArrayFunction object.
Definition functions.cpp:48
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:53
bool periodic
Flag indicating whether the domain is periodic or not.
Definition functions.hpp:123
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:122
void set_array(Array new_array)
Set the array object.
Definition functions.hpp:116
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:31
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:97
BiquadFunction(float gain, glm::vec2 center)
Construct a new Biquad Function object.
Definition functions.cpp:92
glm::vec2 center
Primitive reference center.
Definition functions.hpp:151
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:150
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:116
glm::vec2 center
Primitive reference center.
Definition functions.hpp:176
BumpFunction(float gain, glm::vec2 center)
Construct a new Bump Function object.
Definition functions.cpp:111
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:175
CraterFunction(float radius, float depth, float lip_decay, float lip_height_ratio, glm::vec2 center)
Construct a new Crater Function object.
Definition functions.cpp:132
float depth
Depth of the crater.
Definition functions.hpp:211
float lip_decay
Decay rate of the crater's lip.
Definition functions.hpp:212
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:145
glm::vec2 center
Primitive reference center.
Definition functions.hpp:214
float radius
Radius of the crater.
Definition functions.hpp:210
float lip_height_ratio
Height ratio of the crater's lip.
Definition functions.hpp:213
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:165
glm::vec2 center
Primitive reference center.
Definition functions.hpp:238
float radius
Radius of the disk.
Definition functions.hpp:236
float slope
Slope of the disk.
Definition functions.hpp:237
DiskFunction(float radius, float slope, glm::vec2 center)
Construct a new Disk Function object.
Definition functions.cpp:160
FbmFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity)
Construct a new Fbm Function object.
Definition functions.inl:46
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:60
void set_gradient_scale(float new_gradient_scale)
Set the gradient scale.
Definition functions.hpp:1531
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:104
FbmIqFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity, float gradient_scale)
Construct a new Fbm Iq Function object.
Definition functions.inl:88
float gradient_scale
Gradient scale influence.
Definition functions.hpp:1537
void set_damp_scale(float new_damp_scale)
Set the damp scale.
Definition functions.hpp:1608
void set_damp0(float new_damp0)
Set the initial damp.
Definition functions.hpp:1588
float warp0
Initial warp.
Definition functions.hpp:1614
float warp_scale
Warp scale.
Definition functions.hpp:1616
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:167
void set_warp0(float new_warp0)
Set the initial warp.
Definition functions.hpp:1578
float damp_scale
Damp scale.
Definition functions.hpp:1617
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1598
FbmJordanFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity, float warp0, float damp0, float warp_scale, float damp_scale)
Construct a new Fbm Jordan Function object.
Definition functions.inl:145
float damp0
Initial damp.
Definition functions.hpp:1615
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1650
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:240
FbmPingpongFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity)
Construct a new Fbm Pingpong Function object.
Definition functions.inl:226
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1656
FbmRidgedFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity, float k_smoothing)
Construct a new Fbm Ridged Function object.
Definition functions.inl:270
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1691
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1697
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:286
float bias_cos
Cosine of directional bias angle.
Definition functions.hpp:1789
FbmSlopeFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity, float gradient_scale, float slope_power, float octave_blend, float bias_angle=0.f, float bias_strength=0.f)
Construct a new Fbm Slope Function object.
Definition functions.inl:314
float bias_angle
Preferred slope direction angle in degrees.
Definition functions.hpp:1787
void set_gradient_scale(float new_gradient_scale)
Set the gradient scale.
Definition functions.hpp:1758
void set_bias(float new_bias_angle, float new_bias_strength)
Set the directional bias.
Definition functions.hpp:1744
void set_octave_blend(float new_octave_blend)
Set the octave blend rate.
Definition functions.hpp:1778
float gradient_scale
Gradient scale influence.
Definition functions.hpp:1784
float bias_strength
Directional bias strength in [0, 1].
Definition functions.hpp:1788
float bias_sin
Sine of directional bias angle.
Definition functions.hpp:1790
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:337
void set_slope_power(float new_slope_power)
Set the slope power.
Definition functions.hpp:1768
float slope_power
Exponent controlling slope transition sharpness.
Definition functions.hpp:1785
float octave_blend
Rate at which higher octaves become slope-masked.
Definition functions.hpp:1786
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1825
float warp_scale
Warping scale.
Definition functions.hpp:1832
float warp_scale_normalized
Normalized warping scale.
Definition functions.hpp:1833
FbmSwissFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity, float warp_scale)
Construct a new Fbm Swiss Function object.
Definition functions.inl:396
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:412
FieldFunction(BaseFn base)
Construct a new FieldFunction object.
Definition functions.inl:456
void set_yr(std::vector< float > new_yr)
Set the y coordinates representing the centers of the primitive.
Definition functions.hpp:1888
std::vector< float > yr
Definition functions.hpp:1907
void set_zr(std::vector< float > new_zr)
Set the z coordinates used to scale the primitive in x and y directions, and also to scale the primit...
Definition functions.hpp:1899
std::vector< float > zr
directions, and to scale the primitive amplitude if requested.
Definition functions.hpp:1909
void set_xr(std::vector< float > new_xr)
Set the x coordinates representing the centers of the primitive.
Definition functions.hpp:1878
std::vector< float > xr
Definition functions.hpp:1905
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.inl:474
glm::vec2 center
Primitive reference center.
Definition functions.hpp:274
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:186
float sigma
Pulse half-width.
Definition functions.hpp:273
GaussianPulseFunction(float sigma, glm::vec2 center)
Construct a new GaussianPulse Function object.
Definition functions.cpp:180
void set_sigma(float new_sigma)
Set the half-width.
Definition functions.hpp:266
float stretch_decay
Stretching decay across octaves.
Definition functions.hpp:1468
void set_seed(std::uint32_t new_seed)
Set a new random seed for the noise generation.
Definition functions.hpp:1357
float get_persistence() const
Get the persistence of the fractal noise.
Definition functions.hpp:1418
BaseFn base
Unique pointer to the base noise function.
Definition functions.hpp:1460
GenericFractalFunction(BaseFn base, int octaves, float weight, float persistence, float lacunarity)
Construct a new GenericFractalFunction object.
Definition functions.inl:18
float persistence
Persistence of the fractal noise.
Definition functions.hpp:1463
float lacunarity
Lacunarity of the fractal noise.
Definition functions.hpp:1464
int get_octaves() const
Get the number of octaves in the fractal noise.
Definition functions.hpp:1408
float angle
Direction angle in degrees.
Definition functions.hpp:1466
void update_amp0()
Update the initial amplitude (amp0) based on the current octaves and persistence.
Definition functions.inl:33
void scale_amp0(float scale)
Scale the initial amplitude of the fractal noise.
Definition functions.hpp:1368
void set_stretch(float new_angle, float new_stretch, float new_stretch_decay=0.f)
Configure directional stretching for the fractal noise.
Definition functions.hpp:1380
void apply_stretch(float &x, float &y, int octave) const
Apply directional stretching to coordinates for a given octave.
Definition functions.hpp:1443
float weight
Weight of the base noise function.
Definition functions.hpp:1462
float cos_a
Cosine of direction angle.
Definition functions.hpp:1469
float amp0
Initial amplitude of the fractal noise.
Definition functions.hpp:1465
void set_lacunarity(float new_lacunarity)
Set the lacunarity of the fractal noise.
Definition functions.hpp:1325
float get_weight() const
Get the weight of the fractal noise.
Definition functions.hpp:1428
float get_lacunarity() const
Get the lacunarity of the fractal noise.
Definition functions.hpp:1398
int octaves
Number of octaves in the fractal noise.
Definition functions.hpp:1461
void set_octaves(int new_octaves)
Set the number of octaves in the fractal noise.
Definition functions.hpp:1335
float stretch
Stretching factor along the direction.
Definition functions.hpp:1467
void set_kw(glm::vec2 new_kw)
Set the frequency scaling vector.
Definition functions.hpp:1314
float sin_a
Sine of direction angle.
Definition functions.hpp:1470
void set_persistence(float new_persistence)
Set the persistence of the fractal noise.
Definition functions.hpp:1346
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:783
glm::vec2 get_kw() const
Get the frequency scaling vector.
Definition functions.hpp:750
void set_kw(glm::vec2 new_kw)
Set a new frequency scaling vector.
Definition functions.hpp:777
std::uint32_t get_seed() const
Get the random seed.
Definition functions.hpp:759
NoiseFunction(glm::vec2 kw, std::uint32_t seed)
Constructor to initialize with specific frequency scaling and seed.
Definition functions.hpp:742
NoiseFunction()
Default constructor. Initializes with default frequency scaling and seed.
Definition functions.hpp:725
NoiseFunction(glm::vec2 kw)
Constructor to initialize with specific frequency scaling.
Definition functions.hpp:733
void set_seed(std::uint32_t new_seed)
Set a new random seed for noise generation.
Definition functions.hpp:768
std::uint32_t seed
Random seed for noise generation.
Definition functions.hpp:784
void initialize()
Initialize generator.
Definition parberry_function.cpp:30
ParberryFunction(glm::vec2 kw, std::uint32_t seed, float mu)
Construct a new Perlin Function object.
Definition parberry_function.cpp:20
float mu
Gradient magnitude exponent.
Definition functions.hpp:802
float operator()(float x, float y, float ctrl_param=0.f) const
Definition parberry_function.cpp:68
void set_seed(std::uint32_t)
Set the seed attribute.
Definition functions.hpp:824
PerlinBillowFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new Perlin Function object.
Definition noise_functions.cpp:292
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:914
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:297
PerlinFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new Perlin Function object.
Definition noise_functions.cpp:282
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:883
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:287
PerlinHalfFunction(glm::vec2 kw, std::uint32_t seed, float k)
Construct a new Perlin Function object.
Definition noise_functions.cpp:303
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:310
float k
Definition functions.hpp:931
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:948
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:321
PerlinMixFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new Perlin Function object.
Definition noise_functions.cpp:316
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:979
float c11
Top-right value.
Definition functions.hpp:307
QuadSurfaceFunction(float c00, float c10, float c01, float c11)
Construct a new QuadSurface Function object.
Definition functions.cpp:196
float c10
Bottom-right value.
Definition functions.hpp:305
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:204
float c00
Bottom-left value.
Definition functions.hpp:304
BBox2D bbox
Domain bounding box.
Definition functions.hpp:308
float c01
Top-left value.
Definition functions.hpp:306
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:221
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:340
float rx
Definition functions.hpp:348
float ry
Radius of the rectangle.
Definition functions.hpp:348
float slope
Slope of the rectangle.
Definition functions.hpp:350
glm::vec2 center
Primitive reference center.
Definition functions.hpp:351
float angle
Angle of the rectangle.
Definition functions.hpp:349
RectangleFunction(float rx, float ry, float angle, float slope, glm::vec2 center)
Construct a new Rectangle Function object.
Definition functions.cpp:211
bool sharp_bottom
Rift bottom sharpness.
Definition functions.hpp:401
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:398
glm::vec2 center
Primitive reference center.
Definition functions.hpp:402
RiftFunction(float angle, float slope, float width, bool sharp_bottom, glm::vec2 center)
Construct a new Rift Function object.
Definition functions.cpp:254
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:264
float width
Rift width.
Definition functions.hpp:400
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:390
float slope
Rift slope.
Definition functions.hpp:399
Simplex2Function(glm::vec2 kw, std::uint32_t seed)
Construct a new Perlin Function object.
Definition noise_functions.cpp:327
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:332
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1010
Simplex2SFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new Perlin Function object.
Definition noise_functions.cpp:337
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1041
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:342
float slope
Step slope.
Definition functions.hpp:444
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:288
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:435
SlopeFunction(float angle, float slope, glm::vec2 center)
Construct a new Slope Function object.
Definition functions.cpp:282
glm::vec2 center
Primitive reference center.
Definition functions.hpp:445
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:443
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:486
StepFunction(float angle, float slope, glm::vec2 center)
Construct a new Step Function object.
Definition functions.cpp:294
glm::vec2 center
Primitive reference center.
Definition functions.hpp:488
float slope
Step slope.
Definition functions.hpp:487
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:300
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:478
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:363
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1103
ValueCubicNoiseFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new ValueCubicNoiseFunction object.
Definition noise_functions.cpp:357
void update_interpolation_function()
Update base interpolation.
Definition noise_functions.cpp:377
ValueDelaunayNoiseFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new ValueNoiseFunction object.
Definition noise_functions.cpp:368
void set_kw(glm::vec2 new_kw)
Set the wavenumber attribute.
Definition functions.hpp:1133
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1144
std::function< float(float, float, float)> itp_fct
Definition functions.hpp:1154
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:454
ValueLinearNoiseFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new ValueLinearNoiseFunction object.
Definition noise_functions.cpp:461
std::function< float(float, float, float)> itp_fct
Definition functions.hpp:1199
void update_interpolation_function()
Update base interpolation.
Definition noise_functions.cpp:470
void set_kw(glm::vec2 new_kw)
Set the wavenumber attribute.
Definition functions.hpp:1178
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1189
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:523
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:352
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1072
ValueNoiseFunction(glm::vec2 kw, std::uint32_t seed)
Construct a new ValueNoiseFunction object.
Definition noise_functions.cpp:347
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:541
glm::vec2 center
Primitive reference center.
Definition functions.hpp:547
float xbottom
1]).
Definition functions.hpp:544
float xtop
Relative location of the top of the dune profile (in [0, 1]).
Definition functions.hpp:543
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:542
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:533
float phase_shift
Phase shift (in radians).
Definition functions.hpp:546
WaveDuneFunction(glm::vec2 kw, float angle, float xtop, float xbottom, float phase_shift, glm::vec2 center={0.5f, 0.5f})
Construct a new Wave Dune Function object.
Definition functions.cpp:317
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:332
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:593
WaveSineFunction(glm::vec2 kw, float angle, float phase_shift, glm::vec2 center={0.5f, 0.5f})
Construct a new Wave Sine Function object.
Definition functions.cpp:353
glm::vec2 center
Primitive reference center.
Definition functions.hpp:596
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:585
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:362
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:594
float phase_shift
Phase shift (in radians).
Definition functions.hpp:595
WaveSquareFunction(glm::vec2 kw, float angle, float phase_shift, glm::vec2 center={0.5f, 0.5f})
Construct a new Wave Square Function object.
Definition functions.cpp:369
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:378
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:634
float phase_shift
Phase shift (in radians).
Definition functions.hpp:644
glm::vec2 center
Primitive reference center.
Definition functions.hpp:645
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:642
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:643
WaveTriangularFunction(glm::vec2 kw, float angle, float slant_ratio, float phase_shift, glm::vec2 center={0.5f, 0.5f})
Construct a new Wave Triangular Function object.
Definition functions.cpp:385
float slant_ratio
Relative location of the triangle apex, in [0, 1].
Definition functions.hpp:696
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:694
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:695
float phase_shift
Phase shift (in radians).
Definition functions.hpp:697
float operator()(float x, float y, float ctrl_param=0.f) const
Definition functions.cpp:395
glm::vec2 center
Primitive reference center.
Definition functions.hpp:698
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:686
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:538
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1269
float ratio
Amplitude ratio between each Worley noise.
Definition functions.hpp:1246
WorleyDoubleFunction(glm::vec2 kw, std::uint32_t seed, float ratio, float k)
Construct a new Worley Double Function object.
Definition noise_functions.cpp:530
float k
Transition smoothing parameter.
Definition functions.hpp:1251
float operator()(float x, float y, float ctrl_param=0.f) const
Definition noise_functions.cpp:559
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1226
WorleyFunction(glm::vec2 kw, std::uint32_t seed, bool return_cell_value=false)
Construct a new Worley Function object.
Definition noise_functions.cpp:552
constexpr float pi
Definition constants.hpp:16
Definition opencv.hpp:20
std::function< float(float, float)> make_xy_function_from_array(const Array &array, const BBox2D &bbox=BBox2D::unit())
Create a continuous 2D function from a sampled array.
Definition functions.cpp:16
Cloud scale(const Cloud &cloud, glm::vec2 scale, glm::vec2 center={0.5f, 0.5f})
Scales the point coordinates in a cloud relative to a center point.
Definition cloud_functions.cpp:163
NoiseType
Enumeration of various noise types used for procedural generation.
Definition functions.hpp:67
@ WORLEY
Worley.
Definition functions.hpp:78
@ SIMPLEX2S
OpenSimplex2S.
Definition functions.hpp:73
@ WORLEY_DOUBLE
Worley double.
Definition functions.hpp:79
@ VALUE_DELAUNAY
Value (delaunay).
Definition functions.hpp:76
@ PERLIN_BILLOW
Perlin billow.
Definition functions.hpp:70
@ PARBERRY
Parberry (Perlin variant).
Definition functions.hpp:68
@ WORLEY_VALUE
Worley (cell value return).
Definition functions.hpp:80
@ PERLIN
Perlin.
Definition functions.hpp:69
@ SIMPLEX2
OpenSimplex2.
Definition functions.hpp:72
@ PERLIN_HALF
Perlin half.
Definition functions.hpp:71
@ VALUE_LINEAR
Value (linear).
Definition functions.hpp:77
@ VALUE_CUBIC
Value (cubic).
Definition functions.hpp:75
@ VALUE
Value.
Definition functions.hpp:74
decltype(auto) with_noise_function(NoiseType noise_type, glm::vec2 kw, std::uint32_t seed, Fn &&fn)
Dispatch a noise functor based on the specified noise type.
Definition functions.inl:493
Axis-aligned 2D bounding box in world coordinates.
Definition bbox2d.hpp:25
static constexpr BBox2D unit()
Definition bbox2d.hpp:39