![]() |
ImFusion C++ SDK 4.5.0
|
#include <ImFusion/Stream/BackgroundImageExporter.h>
Writes image data to disk in a background thread using the ImFusionImage async interface. More...
Writes image data to disk in a background thread using the ImFusionImage async interface.
This class provides non-blocking image export functionality, allowing images to be queued for saving to disk independent of the recording to memory. The exporter runs in a separate thread with its own OpenGL context, enabling safe handling of OpenGL-based images through GL::SyncObject synchronization.
The typical workflow consists of three steps:
The class internally uses the async functionality of ImFusionImage.
Public Member Functions | |
| BackgroundImageExporter () | |
| Constructs a new BackgroundImageExporter instance. | |
| virtual | ~BackgroundImageExporter () |
| Destroys the exporter. | |
| void | initializeFile (SharedImageSet *container, const std::string &path, bool ffv1Compression) |
| Initializes a file for live recording. | |
| void | addImage (std::shared_ptr< const SharedImage > img, double timestamp, std::optional< GL::SyncObject > glSync=std::nullopt) |
| Adds an image to the save queue. | |
| void | finalizeFile () |
| Finalizes the file recording and waits for all images to be saved. | |
| bool | isInitialized () const |
| Returns true if the exporter is initialized and ready to accept images. | |
| ImFusion::BackgroundImageExporter::BackgroundImageExporter | ( | ) |
Constructs a new BackgroundImageExporter instance.
Launches a background thread with its own OpenGL context for saving the images. The exporter is ready to use after construction, but initializeFile() must be called before adding images.
|
virtual |
Destroys the exporter.
| void ImFusion::BackgroundImageExporter::initializeFile | ( | SharedImageSet * | container, |
| const std::string & | path, | ||
| bool | ffv1Compression ) |
Initializes a file for live recording.
Sets up the output file and prepares the exporter for image saving. The provided SharedImageSet must contain at least one image to ensure correct metadata extraction. This method is blocking and will open the file immediately.
| container | SharedImageSet containing at least one image for metadata extraction. The container is cloned internally to decouple its lifetime from the background export task. |
| path | File path where images will be saved. The file is opened in binary mode. |
| ffv1Compression | If true, enables FFV1 codec compression for the saved images. If false, images are saved in uncompressed raw format. |
| void ImFusion::BackgroundImageExporter::addImage | ( | std::shared_ptr< const SharedImage > | img, |
| double | timestamp, | ||
| std::optional< GL::SyncObject > | glSync = std::nullopt ) |
Adds an image to the save queue.
Queues an image for saving in the background thread. This method is non-blocking and returns immediately. The image is saved asynchronously by the background thread.
| img | Shared pointer to the image to save. Must be of unsigned char type. Images with other pixel types will be skipped with a warning. |
| timestamp | Timestamp associated with the image, stored for later retrieval. |
| glSync | Optional GL::SyncObject for synchronizing OpenGL contexts when the image contains OpenGL-based images. If provided, the background thread will wait for the sync object before accessing the image data. |
| void ImFusion::BackgroundImageExporter::finalizeFile | ( | ) |
Finalizes the file recording and waits for all images to be saved.
This method is blocking and will not return until all images have been saved.
After calling this method, the exporter is reset and isInitialized returns false.