4#ifndef OPENVDB_IO_CODEC_HAS_BEEN_INCLUDED
5#define OPENVDB_IO_CODEC_HAS_BEEN_INCLUDED
8#include <unordered_map>
118 using Ptr = std::shared_ptr<ReadTypedOptions>;
135 return *
static_cast<T*
>(data.get());
179 std::unordered_map<std::string, ReadTypedOptions::Ptr>
typeData;
214 std::lock_guard<std::mutex> lock(other.mMutex);
215 mEnabled = other.mEnabled;
216 mDiagnostics = other.mDiagnostics;
219 if (
this != &other) {
220 std::scoped_lock lock(mMutex, other.mMutex);
221 mEnabled = other.mEnabled;
222 mDiagnostics = other.mDiagnostics;
228 void addWarning(
const std::string& context,
const std::string& message) {
229 if (!mEnabled)
return;
230 std::lock_guard<std::mutex> lock(mMutex);
236 std::lock_guard<std::mutex> lock(mMutex);
237 mDiagnostics.clear();
246 const std::vector<ReadDiagnostic>&
diagnostics()
const {
return mDiagnostics; }
248 bool empty()
const {
return mDiagnostics.empty(); }
250 bool mEnabled =
false;
251 std::vector<ReadDiagnostic> mDiagnostics;
252 mutable std::mutex mMutex;
301 using Ptr = std::unique_ptr<CodecData>;
396 using Ptr = std::unique_ptr<Codec>;
503 template <
typename CodecT>
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Abstract base class for typed grids.
Definition Grid.h:79
DiagnosticSeverity
Severity level for a read diagnostic.
Definition Codec.h:193
@ Warning
Definition Codec.h:193
ReadMode
Controls how grid data is read.
Definition Codec.h:61
@ Original
Definition Codec.h:65
@ Mask
Definition Codec.h:79
@ TopologyOnly
Definition Codec.h:92
@ Bool
Definition Codec.h:74
@ Half
Definition Codec.h:70
@ MetadataOnly
Definition Codec.h:96
CodecMode
Controls which operations a codec exposes.
Definition Codec.h:46
@ ReadOnly
Definition Codec.h:52
@ ReadWrite
Definition Codec.h:49
void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types....
void uninitialize()
Global deregistration of native Grid, Transform, Metadata and Point attribute types.
math::BBox< Vec3d > BBoxd
Definition Types.h:65
std::shared_ptr< T > SharedPtr
Definition Types.h:95
Definition Exceptions.h:13
Mutable per-operation state created by Codec::createData() and passed into every read and write call ...
Definition Codec.h:300
std::unique_ptr< CodecData > Ptr
Definition Codec.h:301
SharedPtr< GridBase > grid
The grid being populated on read, or being serialized on write.
Definition Codec.h:306
virtual ~CodecData()=default
A thread-safe, process-global registry that maps codec names to Codec instances.
Definition Codec.h:491
static Codec * get(const std::string &name)
static void clear()
Deregister all codecs and reset the registry to an empty state.
static bool isRegistered(const std::string &name)
Return true if a codec with the given name has been registered.
static void registerCodecByName(const std::string &name, Codec::Ptr &&codec)
static void registerCodec()
Definition Codec.h:504
Abstract base class for grid I/O codecs.
Definition Codec.h:395
virtual void writeBuffers(std::ostream &, const GridBase &, const WriteOptions &) const
Serialize all voxel-value buffers from grid to os.
Definition Codec.h:471
virtual void readBuffers(std::istream &, int64_t, CodecData &, const ReadOptions &, ReadDiagnostics &) const
Deserialize all voxel-value buffers from is into the grid held by data.
Definition Codec.h:443
virtual void beginRead(CodecData &, const ReadOptions &, ReadDiagnostics &) const
Begin a read. Called by the I/O layer once before the first phase of every read of a grid,...
Definition Codec.h:421
virtual void finishRead(CodecData &, const ReadOptions &, ReadDiagnostics &) const
Finish a read. Called by the I/O layer after the last phase of every read of a grid,...
Definition Codec.h:455
virtual void writeTopology(std::ostream &, const GridBase &, const WriteOptions &) const
Serialize the grid topology (tree structure and active-voxel mask) from grid to os.
Definition Codec.h:464
virtual void readTopology(std::istream &, CodecData &, const ReadOptions &, ReadDiagnostics &) const
Deserialize the grid topology (tree structure and active-voxel mask) from is into the grid held by da...
Definition Codec.h:426
std::unique_ptr< Codec > Ptr
Definition Codec.h:396
virtual CodecData::Ptr createData()=0
Allocate per-operation codec state, including the target grid.
A single read diagnostic message.
Definition Codec.h:198
std::string message
Definition Codec.h:201
DiagnosticSeverity severity
Definition Codec.h:199
std::string context
Definition Codec.h:200
Thread-safe collection of read diagnostics accumulated during a codec read.
Definition Codec.h:211
ReadDiagnostics & operator=(const ReadDiagnostics &other)
Definition Codec.h:218
void enable()
Enable diagnostic recording.
Definition Codec.h:240
const std::vector< ReadDiagnostic > & diagnostics() const
Return the list of recorded diagnostics.
Definition Codec.h:246
bool empty() const
Return true if no diagnostics have been recorded.
Definition Codec.h:248
void addWarning(const std::string &context, const std::string &message)
Append a warning diagnostic. No-op if the object is disabled.
Definition Codec.h:228
ReadDiagnostics(const ReadDiagnostics &other)
Definition Codec.h:213
void disable()
Disable diagnostic recording.
Definition Codec.h:242
ReadDiagnostics()=default
void clear()
Remove all recorded diagnostics.
Definition Codec.h:235
bool enabled() const
Return true if diagnostic recording is enabled.
Definition Codec.h:244
Global read configuration passed to every codec during deserialization.
Definition Codec.h:167
BBoxd clipBBox
Definition Codec.h:170
ReadMode readMode
Definition Codec.h:174
std::unordered_map< std::string, ReadTypedOptions::Ptr > typeData
Definition Codec.h:179
Base class for per-grid-type, codec-specific read options.
Definition Codec.h:117
static T & cast(const Ptr &data)
Downcast a ReadTypedOptions::Ptr to a concrete derived type.
Definition Codec.h:133
virtual ~ReadTypedOptions()=default
std::shared_ptr< ReadTypedOptions > Ptr
Definition Codec.h:118
Global write configuration passed to every codec during serialization.
Definition Codec.h:188
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:286