Blender  V2.93
abc_util.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 #pragma once
17 
22 #include <Alembic/Abc/All.h>
23 #include <Alembic/AbcGeom/All.h>
24 
30 struct CacheReader {
31  int unused;
32 };
33 
34 using Alembic::Abc::chrono_t;
35 
36 struct ID;
37 struct Object;
38 
39 namespace blender::io::alembic {
40 
41 class AbcObjectReader;
42 struct ImportSettings;
43 
44 std::string get_id_name(const ID *const id);
45 std::string get_id_name(const Object *const ob);
46 std::string get_valid_abc_name(const char *name);
47 std::string get_object_dag_path_name(const Object *const ob, Object *dupli_parent);
48 
49 /* Convert from float to Alembic matrix representations. Does NOT convert from Z-up to Y-up. */
50 Imath::M44d convert_matrix_datatype(float mat[4][4]);
51 /* Convert from Alembic to float matrix representations. Does NOT convert from Y-up to Z-up. */
52 void convert_matrix_datatype(const Imath::M44d &xform, float r_mat[4][4]);
53 
54 void split(const std::string &s, const char delim, std::vector<std::string> &tokens);
55 
56 template<class TContainer> bool begins_with(const TContainer &input, const TContainer &match)
57 {
58  return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
59 }
60 
61 template<typename Schema>
62 void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
63 {
64  const Alembic::Abc::TimeSamplingPtr &time_samp = schema.getTimeSampling();
65 
66  if (!schema.isConstant()) {
67  const size_t num_samps = schema.getNumSamples();
68 
69  if (num_samps > 0) {
70  const chrono_t min_time = time_samp->getSampleTime(0);
71  min = std::min(min, min_time);
72 
73  const chrono_t max_time = time_samp->getSampleTime(num_samps - 1);
74  max = std::max(max, max_time);
75  }
76  }
77 }
78 
79 template<typename Schema>
80 void get_min_max_time(const Alembic::AbcGeom::IObject &object,
81  const Schema &schema,
82  chrono_t &min,
83  chrono_t &max)
84 {
85  get_min_max_time_ex(schema, min, max);
86 
87  const Alembic::AbcGeom::IObject &parent = object.getParent();
88  if (parent.valid() && Alembic::AbcGeom::IXform::matches(parent.getMetaData())) {
89  Alembic::AbcGeom::IXform xform(parent, Alembic::AbcGeom::kWrapExisting);
90  get_min_max_time_ex(xform.getSchema(), min, max);
91  }
92 }
93 
94 bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name);
95 
96 float get_weight_and_index(float time,
97  const Alembic::AbcCoreAbstract::TimeSamplingPtr &time_sampling,
98  int samples_number,
99  Alembic::AbcGeom::index_t &i0,
100  Alembic::AbcGeom::index_t &i1);
101 
102 AbcObjectReader *create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings);
103 
104 /* *************************** */
105 
106 #undef ABC_DEBUG_TIME
107 
108 class ScopeTimer {
109  const char *m_message;
110  double m_start;
111 
112  public:
113  ScopeTimer(const char *message);
114  ~ScopeTimer();
115 };
116 
117 #ifdef ABC_DEBUG_TIME
118 # define SCOPE_TIMER(message) ScopeTimer prof(message)
119 #else
120 # define SCOPE_TIMER(message)
121 #endif
122 
123 /* *************************** */
124 
135  std::ostringstream m_stream;
136 
137  public:
141  std::string str() const;
142 
146  void clear();
147 
152  std::ostringstream &stream();
153 };
154 
155 #define ABC_LOG(logger) logger.stream()
156 
160 std::ostream &operator<<(std::ostream &os, const SimpleLogger &logger);
161 
162 } // namespace blender::io::alembic
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint i1
ScopeTimer(const char *message)
Definition: abc_util.cc:228
std::ostringstream & stream()
Definition: abc_util.cc:251
double time
static void get_weight_and_index(CDStreamConfig &config, Alembic::AbcCoreAbstract::TimeSamplingPtr time_sampling, size_t samples_number)
bool begins_with(const TContainer &input, const TContainer &match)
Definition: abc_util.h:56
void get_min_max_time(const Alembic::AbcGeom::IObject &object, const Schema &schema, chrono_t &min, chrono_t &max)
Definition: abc_util.h:80
std::string get_valid_abc_name(const char *name)
Definition: abc_util.cc:57
std::ostream & operator<<(std::ostream &os, const SimpleLogger &logger)
Definition: abc_util.cc:256
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:75
std::string get_id_name(const Object *const ob)
Definition: abc_util.cc:43
Imath::M44d convert_matrix_datatype(float mat[4][4])
Definition: abc_util.cc:93
bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name)
Definition: abc_util.cc:129
void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
Definition: abc_util.h:62
AbcObjectReader * create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings)
Definition: abc_util.cc:174
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition: abc_util.cc:115
#define min(a, b)
Definition: sort.c:51
The CacheReader struct is only used for anonymous pointers, to interface between C and C++ code....
Definition: abc_util.h:30
int unused
Definition: abc_util.h:31
Definition: DNA_ID.h:273
float max