MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ write_curves_sample()

bool MayaFlux::IO::SpatialCache::write_curves_sample ( const std::string &  stream_name,
const SpatialSample sample 
)
private

Definition at line 286 of file SpatialCache.cpp.

287{
288 const size_t expected_vertex_count = std::accumulate(
289 sample.vertex_counts_per_curve.begin(), sample.vertex_counts_per_curve.end(), size_t { 0 },
290 [](size_t acc, int32_t n) { return acc + static_cast<size_t>(n); });
291 if (expected_vertex_count != sample.positions.size()) {
292 set_error("write: vertex_counts_per_curve sum does not match positions.size()");
294 "SpatialCache::write: '{}': {}", stream_name, get_last_error());
295 return false;
296 }
297
298 auto it = m_impl->curves_streams.find(stream_name);
299 if (it == m_impl->curves_streams.end()) {
300 MetaData md;
301 auto mit = m_impl->pending_metadata.find(stream_name);
302 if (mit != m_impl->pending_metadata.end()) {
303 md = mit->second;
304 m_impl->pending_metadata.erase(mit);
305 }
306 auto stream = std::make_unique<CurvesStream>();
307 stream->object = OCurves(m_impl->archive->getTop(), stream_name, md);
308 it = m_impl->curves_streams.emplace(stream_name, std::move(stream)).first;
309 }
310 auto& stream = *it->second;
311 auto& schema = stream.object.getSchema();
312
313 const P3fArraySample pos_sample(
314 reinterpret_cast<const V3f*>(sample.positions.data()), sample.positions.size());
315 const Int32ArraySample nverts_sample(
316 sample.vertex_counts_per_curve.data(), sample.vertex_counts_per_curve.size());
317
318 schema.set(OCurvesSchema::Sample(pos_sample, nverts_sample, kLinear, kNonPeriodic));
319
320 for (const auto& attr : sample.attributes) {
321 const size_t expected = curves_attribute_count(
322 attr.scope, sample.positions.size(), sample.vertex_counts_per_curve.size());
323 if (!set_attribute(stream.geom_params, schema.getArbGeomParams(), attr, expected)) {
324 set_error("write: attribute '" + attr.name + "' has an unsupported type, wrong "
325 + "element count, or was redeclared with a different type");
327 "SpatialCache::write: '{}': {}", stream_name, get_last_error());
328 return false;
329 }
330 }
331
332 return true;
333}
#define MF_ERROR(comp, ctx,...)
Core::GlobalStreamInfo stream
Definition Config.cpp:36
std::unique_ptr< Impl > m_impl
std::string get_last_error() const
void set_error(std::string msg) const
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

References MayaFlux::IO::SpatialSample::attributes, MayaFlux::Journal::FileIO, get_last_error(), MayaFlux::Journal::IO, m_impl, MF_ERROR, MayaFlux::IO::SpatialSample::positions, set_error(), stream, and MayaFlux::IO::SpatialSample::vertex_counts_per_curve.

Referenced by write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: