Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
gray_scott_patterns.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11*/
12
18#include <cstddef>
19#include <cstdint>
20#include <filesystem>
21#include <fstream>
22#include <iomanip>
23#include <iostream>
24#include <string>
25
27
28using namespace Aleph::CA;
29using namespace Aleph::CA::Reproductions;
30
31#ifndef ALEPH_REPRODUCTIONS_SOURCE_DIR
32# define ALEPH_REPRODUCTIONS_SOURCE_DIR "reproductions"
33#endif
34
35int main(int argc, char **argv)
36{
37 constexpr ca_size_t side = 128;
38 constexpr std::size_t steps = 4000;
39 constexpr std::uint64_t seed = 0x5eed1234abcddcbaull;
40 const bool update_golden = argc == 2 and std::string(argv[1]) == "--update-golden";
41 if (argc > 1 and not update_golden)
42 {
43 std::cerr << "Usage: gray_scott_patterns [--update-golden]\n";
44 return 1;
45 }
46
47 const std::filesystem::path root = ALEPH_REPRODUCTIONS_SOURCE_DIR;
48 const std::filesystem::path generated_dir = root / "figures" / "generated";
49 const std::filesystem::path reference_dir = root / "figures" / "reference";
50 std::filesystem::create_directories(generated_dir);
51 std::filesystem::create_directories(reference_dir);
52 std::filesystem::create_directories(root / "results");
53 std::ofstream summary(root / "results" / "gray_scott_summary.csv");
54 if (not summary)
55 {
56 std::cerr << "Cannot write Gray-Scott summary\n";
57 return 1;
58 }
59 summary << "preset,side,steps,mean_channel_difference\n";
60
62 {
64 const std::filesystem::path generated = generated_dir / (std::string(preset.name) + ".png");
65 const std::filesystem::path reference = reference_dir / (std::string(preset.name) + ".png");
67 if (update_golden)
68 {
69 std::filesystem::copy_file(generated, reference,
70 std::filesystem::copy_options::overwrite_existing);
71 std::cout << "Updated " << reference << '\n';
72 continue;
73 }
74
75 const double difference
77 summary << preset.name << ',' << side << ',' << steps << ','
78 << std::setprecision(12) << difference << '\n';
79 std::cout << "Gray-Scott " << preset.name << ": mean channel difference="
80 << std::fixed << std::setprecision(6) << difference << '\n';
81 if (difference >= 0.01)
82 {
83 std::cerr << "Gray-Scott " << preset.name << " differs from golden by at least 1%\n";
84 return 2;
85 }
86 }
87 return 0;
88}
int main()
size_t steps
Definition ca-c-api.h:126
Internal helpers shared by the cellular-automata reproductions.
Lattice that adds boundary-aware access on top of a storage.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Definition gmpfrxx.h:4071
#define ALEPH_REPRODUCTIONS_SOURCE_DIR
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
constexpr std::array< Gray_Scott_Preset, 3 > gray_scott_presets
Canonical visual presets used by the weekly Gray-Scott reproduction.
Gray_Scott_Lattice run_gray_scott(const Gray_Scott_Preset &preset, const ca_size_t side, const std::size_t steps, const std::uint64_t master_seed)
Run one Gray-Scott preset from the shared deterministic seed.
double mean_channel_difference(const Native_Png &lhs, const Native_Png &rhs)
Compute normalized mean absolute per-channel PNG difference.
void write_gray_scott_png(const std::filesystem::path &path, const Gray_Scott_Lattice &frame)
Write a Gray-Scott frame as a native Aleph RGB PNG.
Native_Png read_native_png(const std::filesystem::path &path)
Read and decode a native Aleph PNG.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Definition ca-traits.H:63
and
Check uniqueness with explicit hash + equality functors.
One named Gray-Scott parameter preset.
ValueArg< size_t > seed
Definition testHash.C:53