47#ifndef CA_FRAME_STREAM_H
48#define CA_FRAME_STREAM_H
79template <
typename Sink,
typename Lattice>
80concept Frame_Sink =
requires(
Sink &sink, std::size_t step,
const Lattice &frame)
82 sink.accept(step, frame);
121namespace ca_frame_stream_detail {
163inline std::string
padded_step(std::size_t step, std::size_t width)
165 std::ostringstream
out;
171 const std::size_t step,
172 const std::size_t zero_pad)
174 std::string text = pattern.string();
180 while ((pos = text.find(
needle, pos)) != std::string::npos)
190 return std::filesystem::path(text);
192 return std::filesystem::path(text);
213 const std::size_t step,
214 const std::size_t zero_pad = 6)
231template <
typename...
Sinks>
246 template <std::
size_t I>
249 return std::get<I>(
sinks_);
256 template <std::
size_t I>
259 return std::get<I>(
sinks_);
267 template <
typename Lattice>
271 "Every child sink must satisfy Frame_Sink<Sink, Lattice>");
272 std::apply([&](
auto &...sink)
274 (sink.accept(step, frame), ...);
281 std::apply([](
auto &...sink)
310 template <
typename Lattice>
383 template <
typename Lattice>
388 const std::filesystem::path path =
frame_path(step);
389 std::ofstream
out(path, std::ios::binary);
394 << path.string() <<
"'";
412 const std::filesystem::path path =
opts_.
directory /
"manifest.csv";
413 std::ofstream
out(path);
416 out <<
"step,format,path\n";
417 for (
const auto &[step, frame] :
written_)
422 const std::string raw = frame.string();
424 quoted.reserve(raw.size() + 2);
426 for (
const char c : raw)
437 << path.string() <<
"'";
450 unsigned fps = 24)
const
452 std::ostringstream
cmd;
453 cmd <<
"ffmpeg -y -framerate " << fps <<
" -i "
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
size_t size_t int32_t value
size_t size_t int32_t * out
File-format readers and writers for cellular-automata frames.
TikZ renderers for cellular-automata frames.
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Fan-out sink that forwards every frame to several sinks.
void accept(const std::size_t step, const Lattice &frame)
Forward a frame to every child sink.
void flush()
Flush every child sink in tuple order.
auto & get() noexcept
Return child sink I.
Composite_Frame_Sink(Sinks... sinks)
Construct the composite sink.
const auto & get() const noexcept
Return child sink I.
std::tuple< Sinks... > sinks_
Directory-backed sink for CA frames.
std::filesystem::path frame_path(std::size_t step) const
std::string montage_command_hint(const std::string &output_file="ca.mp4", unsigned fps=24) const
Return an ffmpeg command hint for the current frame sequence.
void accept(std::size_t step, const Lattice &frame)
Accept a frame and write it if it passes the stride filter.
Frame_Stream_Options opts_
Array< std::pair< std::size_t, std::filesystem::path > > written_
const Frame_Stream_Options & options() const noexcept
Return the immutable sink options.
const Array< std::pair< std::size_t, std::filesystem::path > > & written_frames() const noexcept
Return the frame files written so far.
void flush() const
Write the optional manifest.
void write_one(std::ostream &out, const Lattice &frame) const
Directory_Frame_Sink(Frame_Stream_Options opts)
Build a frame sink.
Lattice that adds boundary-aware access on top of a storage.
Concept implemented by sinks that consume CA frames.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::string padded_step(std::size_t step, std::size_t width)
const char * extension(Frame_Output_Format format) noexcept
std::filesystem::path format_step_path(const std::filesystem::path &pattern, const std::size_t step, const std::size_t zero_pad)
const char * format_name(Frame_Output_Format format) noexcept
void write_pgm(std::ostream &out, const Lattice &frame, Mapper &&mapper, const NetPBM_Write_Options &opts={})
Write a binary PGM (P5) image.
Frame_Output_Format
File format used by Directory_Frame_Sink.
@ JSON
JSON snapshot (.json)
@ PPM
binary NetPBM RGB (.ppm)
@ TikZ
TikZ picture (.tex)
@ PGM
binary NetPBM grayscale (.pgm)
void write_rle(std::ostream &out, const Lattice &frame, const RLE_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
Write a 2D frame in Conway RLE format.
void write_ppm(std::ostream &out, const Lattice &frame, Mapper &&mapper, const NetPBM_Write_Options &opts={})
Write a binary PPM (P6) image.
std::filesystem::path format_step_path(const std::filesystem::path &pattern, const std::size_t step, const std::size_t zero_pad=6)
Format a step-indexed file path.
void write_csv(std::ostream &out, const Lattice &frame, const CSV_Options &opts={})
Write a numeric CSV snapshot.
void write_json(std::ostream &out, const Lattice &frame, const JSON_Write_Options &opts={})
Write a JSON snapshot.
void render_lattice_tikz(std::ostream &out, const Lattice &frame, Palette &&palette, const Rect_Tikz_Options &opts={})
Render any supported 2D CA lattice as TikZ.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Options controlling CSV output and input.
Options for directory-backed frame streams.
NetPBM_Write_Options netpbm_options
PGM/PPM options.
std::filesystem::path directory
destination directory
Frame_Output_Format format
exporter format
RLE_Write_Options rle_options
RLE options when format is RLE.
CSV_Options csv_options
CSV options when format is CSV.
std::string prefix
filename prefix
std::size_t stride
write every Nth step
JSON_Write_Options json_options
JSON options when format is JSON.
bool write_manifest
write manifest.csv
std::size_t zero_pad
step field width in filenames
Rect_Tikz_Options tikz_options
TikZ options when format is TikZ.
Options controlling JSON snapshot output.
Options controlling NetPBM output.
Options controlling Conway RLE output.
TikZ rendering options for rectangular frames.
Dynamic array container with automatic resizing.