Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Directory_Frame_Sink Class Reference

Directory-backed sink for CA frames. More...

#include <ca-frame-stream.H>

Collaboration diagram for Aleph::CA::Directory_Frame_Sink:
[legend]

Public Member Functions

 Directory_Frame_Sink (Frame_Stream_Options opts)
 Build a frame sink.
 
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.
 
template<typename Lattice >
void accept (std::size_t step, const Lattice &frame)
 Accept a frame and write it if it passes the stride filter.
 
void flush () const
 Write the optional manifest.
 
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.
 

Private Member Functions

std::filesystem::path frame_path (std::size_t step) const
 
template<typename Lattice >
void write_one (std::ostream &out, const Lattice &frame) const
 

Private Attributes

Frame_Stream_Options opts_
 
Array< std::pair< std::size_t, std::filesystem::path > > written_
 

Detailed Description

Directory-backed sink for CA frames.

The sink is format-agnostic: accept(step, frame) picks the exporter configured in Frame_Stream_Options. A CSV manifest is kept in memory and written on flush(); it lists step, format and path for every frame.

Thread-safety
Not thread-safe. Use one sink per simulation thread or synchronise calls externally.

Definition at line 298 of file ca-frame-stream.H.

Constructor & Destructor Documentation

◆ Directory_Frame_Sink()

Aleph::CA::Directory_Frame_Sink::Directory_Frame_Sink ( Frame_Stream_Options  opts)
inlineexplicit

Build a frame sink.

The destination directory is created immediately.

Parameters
[in]optssink options.
Exceptions
std::domain_errorif stride == 0.
std::runtime_errorif the directory cannot be created.
Complexity
O(path length).

Definition at line 348 of file ca-frame-stream.H.

References ah_domain_error_if, ah_runtime_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Frame_Stream_Options::directory, opts_, and Aleph::CA::Frame_Stream_Options::stride.

Member Function Documentation

◆ accept()

template<typename Lattice >
void Aleph::CA::Directory_Frame_Sink::accept ( std::size_t  step,
const Lattice &  frame 
)
inline

Accept a frame and write it if it passes the stride filter.

Template Parameters
Lattice2D lattice type.
Parameters
[in]stepsimulation step.
[in]frameframe to export.
Exceptions
std::runtime_erroron file or exporter failure.
Complexity
O(rows * cols) when written, O(1) when skipped by stride.

Definition at line 384 of file ca-frame-stream.H.

References ah_runtime_error_if, Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), frame_path(), opts_, out, Aleph::CA::Frame_Stream_Options::stride, write_one(), and written_.

Referenced by main(), TEST(), and TEST().

◆ flush()

void Aleph::CA::Directory_Frame_Sink::flush ( ) const
inline

Write the optional manifest.

The manifest is a CSV file named manifest.csv with columns step,format,path.

Exceptions
std::runtime_erroron write failure.
Complexity
O(number of written frames).

Definition at line 408 of file ca-frame-stream.H.

References ah_runtime_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Frame_Stream_Options::directory, Aleph::CA::Frame_Stream_Options::format, Aleph::CA::ca_frame_stream_detail::format_name(), opts_, out, Aleph::CA::Frame_Stream_Options::write_manifest, and written_.

Referenced by main(), TEST(), and TEST().

◆ frame_path()

◆ montage_command_hint()

std::string Aleph::CA::Directory_Frame_Sink::montage_command_hint ( const std::string &  output_file = "ca.mp4",
unsigned  fps = 24 
) const
inline

Return an ffmpeg command hint for the current frame sequence.

The command is only a string; Aleph-w does not execute external encoders. It is meaningful for image formats (PGM/PPM).

Parameters
[in]output_filevideo filename to place in the command.
[in]fpsframes per second.
Returns
shell command hint.

Definition at line 449 of file ca-frame-stream.H.

References Aleph::blossom_maximum_cardinality_matching(), cmd, Aleph::CA::Frame_Stream_Options::directory, Aleph::CA::ca_frame_stream_detail::extension(), Aleph::CA::Frame_Stream_Options::format, opts_, Aleph::CA::Frame_Stream_Options::prefix, and Aleph::CA::Frame_Stream_Options::zero_pad.

Referenced by main(), and TEST().

◆ options()

const Frame_Stream_Options & Aleph::CA::Directory_Frame_Sink::options ( ) const
inlinenoexcept

Return the immutable sink options.

Returns
sink options.

Definition at line 360 of file ca-frame-stream.H.

References opts_.

◆ write_one()

◆ written_frames()

const Array< std::pair< std::size_t, std::filesystem::path > > & Aleph::CA::Directory_Frame_Sink::written_frames ( ) const
inlinenoexcept

Return the frame files written so far.

Returns
array of (step, path) entries.

Definition at line 368 of file ca-frame-stream.H.

References written_.

Referenced by main(), and TEST().

Member Data Documentation

◆ opts_

Frame_Stream_Options Aleph::CA::Directory_Frame_Sink::opts_
private

◆ written_

Array<std::pair<std::size_t, std::filesystem::path> > Aleph::CA::Directory_Frame_Sink::written_
private

Definition at line 301 of file ca-frame-stream.H.

Referenced by accept(), flush(), and written_frames().


The documentation for this class was generated from the following file: