Blender V4.3
abc_util.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
10#include "abc_reader_object.h"
11
12#include <Alembic/Abc/Foundation.h>
13#include <Alembic/Abc/ICompoundProperty.h>
14#include <Alembic/Abc/IObject.h>
15#include <Alembic/Abc/ISampleSelector.h>
16#include <Alembic/Abc/TypedArraySample.h>
17#include <Alembic/AbcCoreAbstract/Foundation.h>
18#include <Alembic/AbcCoreAbstract/TimeSampling.h>
19#include <Alembic/AbcGeom/IXform.h>
20
21#include <fstream>
22#include <optional>
23#include <string>
24#include <vector>
25
26using Alembic::Abc::chrono_t;
27using Alembic::Abc::V3fArraySamplePtr;
28
29struct ID;
30struct Object;
31
32namespace blender::io::alembic {
33
34class AbcObjectReader;
35struct ImportSettings;
36
37std::string get_id_name(const ID *const id);
38std::string get_id_name(const Object *const ob);
39std::string get_valid_abc_name(const char *name);
49std::string get_object_dag_path_name(const Object *const ob, Object *dupli_parent);
50
51/* Convert from float to Alembic matrix representations. Does NOT convert from Z-up to Y-up. */
52Imath::M44d convert_matrix_datatype(const float mat[4][4]);
53/* Convert from Alembic to float matrix representations. Does NOT convert from Y-up to Z-up. */
54void convert_matrix_datatype(const Imath::M44d &xform, float r_mat[4][4]);
55
56void split(const std::string &s, char delim, std::vector<std::string> &tokens);
57
58template<class TContainer> bool begins_with(const TContainer &input, const TContainer &match)
59{
60 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
61}
62
63template<typename Schema>
64void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
65{
66 const Alembic::Abc::TimeSamplingPtr &time_samp = schema.getTimeSampling();
67
68 if (!schema.isConstant()) {
69 const size_t num_samps = schema.getNumSamples();
70
71 if (num_samps > 0) {
72 const chrono_t min_time = time_samp->getSampleTime(0);
73 min = std::min(min, min_time);
74
75 const chrono_t max_time = time_samp->getSampleTime(num_samps - 1);
76 max = std::max(max, max_time);
77 }
78 }
79}
80
81template<typename Schema>
82void get_min_max_time(const Alembic::AbcGeom::IObject &object,
83 const Schema &schema,
84 chrono_t &min,
85 chrono_t &max)
86{
87 get_min_max_time_ex(schema, min, max);
88
89 const Alembic::AbcGeom::IObject &parent = object.getParent();
90 if (parent.valid() && Alembic::AbcGeom::IXform::matches(parent.getMetaData())) {
91 Alembic::AbcGeom::IXform xform(parent, Alembic::AbcGeom::kWrapExisting);
92 get_min_max_time_ex(xform.getSchema(), min, max);
93 }
94}
95
96bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name);
97V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema,
98 const Alembic::AbcGeom::ISampleSelector &selector,
99 const std::string &name);
100
106 /* Index of the first ("floor") sample. */
107 Alembic::AbcGeom::index_t index;
108 /* Index of the second ("ceil") sample. */
109 Alembic::AbcGeom::index_t ceil_index;
110 /* Factor to interpolate between the `index` and `ceil_index`. */
111 double weight;
112};
113
120std::optional<SampleInterpolationSettings> get_sample_interpolation_settings(
121 const Alembic::AbcGeom::ISampleSelector &selector,
122 const Alembic::AbcCoreAbstract::TimeSamplingPtr &time_sampling,
123 size_t samples_number);
124
125AbcObjectReader *create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings);
126
127/* *************************** */
128
129#undef ABC_DEBUG_TIME
130
132 const char *m_message;
133 double m_start;
134
135 public:
136 ScopeTimer(const char *message);
137 ~ScopeTimer();
138};
139
140#ifdef ABC_DEBUG_TIME
141# define SCOPE_TIMER(message) ScopeTimer prof(message)
142#else
143# define SCOPE_TIMER(message)
144#endif
145
146/* *************************** */
147
158 std::ostringstream m_stream;
159
160 public:
164 std::string str() const;
165
169 void clear();
170
175 std::ostringstream &stream();
176};
177
178#define ABC_LOG(logger) logger.stream()
179
183std::ostream &operator<<(std::ostream &os, const SimpleLogger &logger);
184
185} // namespace blender::io::alembic
ScopeTimer(const char *message)
Definition abc_util.cc:244
std::ostringstream & stream()
Definition abc_util.cc:266
bool begins_with(const TContainer &input, const TContainer &match)
Definition abc_util.h:58
void get_min_max_time(const Alembic::AbcGeom::IObject &object, const Schema &schema, chrono_t &min, chrono_t &max)
Definition abc_util.h:82
std::string get_valid_abc_name(const char *name)
Definition abc_util.cc:47
std::ostream & operator<<(std::ostream &os, const SimpleLogger &logger)
Definition abc_util.cc:271
std::string get_object_dag_path_name(const Object *const ob, Object *dupli_parent)
get_object_dag_path_name returns the name under which the object will be exported in the Alembic file...
Definition abc_util.cc:56
V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema, const Alembic::AbcGeom::ISampleSelector &selector, const std::string &name)
Definition abc_util.cc:119
std::string get_id_name(const Object *const ob)
Definition abc_util.cc:33
Imath::M44d convert_matrix_datatype(const float mat[4][4])
Definition abc_util.cc:74
bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name)
Definition abc_util.cc:110
void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
Definition abc_util.h:64
AbcObjectReader * create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings)
Definition abc_util.cc:190
std::optional< SampleInterpolationSettings > get_sample_interpolation_settings(const Alembic::AbcGeom::ISampleSelector &selector, const Alembic::AbcCoreAbstract::TimeSamplingPtr &time_sampling, size_t samples_number)
Definition abc_util.cc:157
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:96
#define min(a, b)
Definition sort.c:32
Definition DNA_ID.h:413