Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Dobarro <pablodp606@gmail.com>2019-04-23 18:51:51 +0300
committerPablo Dobarro <pablodp606@gmail.com>2019-04-23 18:53:45 +0300
commitab0be1b72084010f853060cce4b39bd8de94dfa4 (patch)
tree2847410a19a0913df81185282058ef1c1372b0a9 /intern/openvdb
parenteab72c52429596df978e5af4a9975079c1854848 (diff)
parente12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (diff)
Merge commit 'e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1' into sculpt-mode-features
Diffstat (limited to 'intern/openvdb')
-rw-r--r--intern/openvdb/CMakeLists.txt78
-rw-r--r--intern/openvdb/intern/openvdb_dense_convert.cc248
-rw-r--r--intern/openvdb/intern/openvdb_dense_convert.h154
-rw-r--r--intern/openvdb/intern/openvdb_level_set.cc246
-rw-r--r--intern/openvdb/intern/openvdb_level_set.h56
-rw-r--r--intern/openvdb/intern/openvdb_reader.cc122
-rw-r--r--intern/openvdb/intern/openvdb_reader.h32
-rw-r--r--intern/openvdb/intern/openvdb_transform.cc12
-rw-r--r--intern/openvdb/intern/openvdb_transform.h25
-rw-r--r--intern/openvdb/intern/openvdb_writer.cc106
-rw-r--r--intern/openvdb/intern/openvdb_writer.h34
-rw-r--r--intern/openvdb/openvdb_capi.cc411
-rw-r--r--intern/openvdb/openvdb_capi.h235
-rw-r--r--intern/openvdb/openvdb_util.cc9
-rw-r--r--intern/openvdb/openvdb_util.h22
15 files changed, 950 insertions, 840 deletions
diff --git a/intern/openvdb/CMakeLists.txt b/intern/openvdb/CMakeLists.txt
index 5d4fe95d7ee..412dade0f1a 100644
--- a/intern/openvdb/CMakeLists.txt
+++ b/intern/openvdb/CMakeLists.txt
@@ -19,62 +19,62 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- intern
- ../guardedalloc
+ .
+ intern
+ ../guardedalloc
)
set(INC_SYS
)
set(SRC
- openvdb_capi.h
+ openvdb_capi.h
)
set(LIB
)
if(WITH_OPENVDB)
- add_definitions(
- -DWITH_OPENVDB
- ${OPENVDB_DEFINITIONS}
- )
+ add_definitions(
+ -DWITH_OPENVDB
+ ${OPENVDB_DEFINITIONS}
+ )
- if(WITH_OPENVDB_3_ABI_COMPATIBLE)
- add_definitions(
- -DOPENVDB_3_ABI_COMPATIBLE
- )
- endif()
+ if(WITH_OPENVDB_3_ABI_COMPATIBLE)
+ add_definitions(
+ -DOPENVDB_3_ABI_COMPATIBLE
+ )
+ endif()
- list(APPEND INC_SYS
- ${BOOST_INCLUDE_DIR}
- ${TBB_INCLUDE_DIRS}
- ${OPENEXR_INCLUDE_DIRS}
- ${OPENVDB_INCLUDE_DIRS}
- )
+ list(APPEND INC_SYS
+ ${BOOST_INCLUDE_DIR}
+ ${TBB_INCLUDE_DIRS}
+ ${OPENEXR_INCLUDE_DIRS}
+ ${OPENVDB_INCLUDE_DIRS}
+ )
- list(APPEND SRC
- intern/openvdb_dense_convert.cc
- intern/openvdb_reader.cc
- intern/openvdb_writer.cc
- intern/openvdb_level_set.cc
- intern/openvdb_transform.cc
- openvdb_capi.cc
- openvdb_util.cc
+ list(APPEND SRC
+ intern/openvdb_dense_convert.cc
+ intern/openvdb_reader.cc
+ intern/openvdb_writer.cc
+ intern/openvdb_level_set.cc
+ intern/openvdb_transform.cc
+ openvdb_capi.cc
+ openvdb_util.cc
- intern/openvdb_dense_convert.h
- intern/openvdb_reader.h
- intern/openvdb_writer.h
- intern/openvdb_level_set.h
- intern/openvdb_transform.h
- openvdb_util.h
- )
+ intern/openvdb_dense_convert.h
+ intern/openvdb_reader.h
+ intern/openvdb_writer.h
+ intern/openvdb_level_set.h
+ intern/openvdb_transform.h
+ openvdb_util.h
+ )
- if(WITH_OPENVDB_BLOSC)
- add_definitions(
- -DWITH_OPENVDB_BLOSC
- )
- endif()
+ if(WITH_OPENVDB_BLOSC)
+ add_definitions(
+ -DWITH_OPENVDB_BLOSC
+ )
+ endif()
endif()
blender_add_lib(bf_intern_openvdb "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/intern/openvdb/intern/openvdb_dense_convert.cc b/intern/openvdb/intern/openvdb_dense_convert.cc
index 56e856b19e6..085c04f1c81 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.cc
+++ b/intern/openvdb/intern/openvdb_dense_convert.cc
@@ -19,158 +19,168 @@
#include "openvdb_dense_convert.h"
-#include <openvdb/tools/ValueTransformer.h> /* for tools::foreach */
+#include <openvdb/tools/ValueTransformer.h> /* for tools::foreach */
namespace internal {
openvdb::Mat4R convertMatrix(const float mat[4][4])
{
- return openvdb::Mat4R(
- mat[0][0], mat[0][1], mat[0][2], mat[0][3],
- mat[1][0], mat[1][1], mat[1][2], mat[1][3],
- mat[2][0], mat[2][1], mat[2][2], mat[2][3],
- mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
+ return openvdb::Mat4R(mat[0][0],
+ mat[0][1],
+ mat[0][2],
+ mat[0][3],
+ mat[1][0],
+ mat[1][1],
+ mat[1][2],
+ mat[1][3],
+ mat[2][0],
+ mat[2][1],
+ mat[2][2],
+ mat[2][3],
+ mat[3][0],
+ mat[3][1],
+ mat[3][2],
+ mat[3][3]);
}
-
class MergeScalarGrids {
- typedef openvdb::FloatTree ScalarTree;
-
- openvdb::tree::ValueAccessor<const ScalarTree> m_acc_x, m_acc_y, m_acc_z;
-
-public:
- MergeScalarGrids(const ScalarTree *x_tree, const ScalarTree *y_tree, const ScalarTree *z_tree)
- : m_acc_x(*x_tree)
- , m_acc_y(*y_tree)
- , m_acc_z(*z_tree)
- {}
-
- MergeScalarGrids(const MergeScalarGrids &other)
- : m_acc_x(other.m_acc_x)
- , m_acc_y(other.m_acc_y)
- , m_acc_z(other.m_acc_z)
- {}
-
- void operator()(const openvdb::Vec3STree::ValueOnIter &it) const
- {
- using namespace openvdb;
-
- const math::Coord xyz = it.getCoord();
- float x = m_acc_x.getValue(xyz);
- float y = m_acc_y.getValue(xyz);
- float z = m_acc_z.getValue(xyz);
-
- it.setValue(math::Vec3s(x, y, z));
- }
+ typedef openvdb::FloatTree ScalarTree;
+
+ openvdb::tree::ValueAccessor<const ScalarTree> m_acc_x, m_acc_y, m_acc_z;
+
+ public:
+ MergeScalarGrids(const ScalarTree *x_tree, const ScalarTree *y_tree, const ScalarTree *z_tree)
+ : m_acc_x(*x_tree), m_acc_y(*y_tree), m_acc_z(*z_tree)
+ {
+ }
+
+ MergeScalarGrids(const MergeScalarGrids &other)
+ : m_acc_x(other.m_acc_x), m_acc_y(other.m_acc_y), m_acc_z(other.m_acc_z)
+ {
+ }
+
+ void operator()(const openvdb::Vec3STree::ValueOnIter &it) const
+ {
+ using namespace openvdb;
+
+ const math::Coord xyz = it.getCoord();
+ float x = m_acc_x.getValue(xyz);
+ float y = m_acc_y.getValue(xyz);
+ float z = m_acc_z.getValue(xyz);
+
+ it.setValue(math::Vec3s(x, y, z));
+ }
};
-openvdb::GridBase *OpenVDB_export_vector_grid(
- OpenVDBWriter *writer,
- const openvdb::Name &name,
- const float *data_x, const float *data_y, const float *data_z,
- const int res[3],
- float fluid_mat[4][4],
- openvdb::VecType vec_type,
- const bool is_color,
- const float clipping,
- const openvdb::FloatGrid *mask)
+openvdb::GridBase *OpenVDB_export_vector_grid(OpenVDBWriter *writer,
+ const openvdb::Name &name,
+ const float *data_x,
+ const float *data_y,
+ const float *data_z,
+ const int res[3],
+ float fluid_mat[4][4],
+ openvdb::VecType vec_type,
+ const bool is_color,
+ const float clipping,
+ const openvdb::FloatGrid *mask)
{
- using namespace openvdb;
+ using namespace openvdb;
- math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 1));
- Mat4R mat = convertMatrix(fluid_mat);
- math::Transform::Ptr transform = math::Transform::createLinearTransform(mat);
+ math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 1));
+ Mat4R mat = convertMatrix(fluid_mat);
+ math::Transform::Ptr transform = math::Transform::createLinearTransform(mat);
- FloatGrid::Ptr grid[3];
+ FloatGrid::Ptr grid[3];
- grid[0] = FloatGrid::create(0.0f);
- tools::Dense<const float, tools::LayoutXYZ> dense_grid_x(bbox, data_x);
- tools::copyFromDense(dense_grid_x, grid[0]->tree(), clipping);
+ grid[0] = FloatGrid::create(0.0f);
+ tools::Dense<const float, tools::LayoutXYZ> dense_grid_x(bbox, data_x);
+ tools::copyFromDense(dense_grid_x, grid[0]->tree(), clipping);
- grid[1] = FloatGrid::create(0.0f);
- tools::Dense<const float, tools::LayoutXYZ> dense_grid_y(bbox, data_y);
- tools::copyFromDense(dense_grid_y, grid[1]->tree(), clipping);
+ grid[1] = FloatGrid::create(0.0f);
+ tools::Dense<const float, tools::LayoutXYZ> dense_grid_y(bbox, data_y);
+ tools::copyFromDense(dense_grid_y, grid[1]->tree(), clipping);
- grid[2] = FloatGrid::create(0.0f);
- tools::Dense<const float, tools::LayoutXYZ> dense_grid_z(bbox, data_z);
- tools::copyFromDense(dense_grid_z, grid[2]->tree(), clipping);
+ grid[2] = FloatGrid::create(0.0f);
+ tools::Dense<const float, tools::LayoutXYZ> dense_grid_z(bbox, data_z);
+ tools::copyFromDense(dense_grid_z, grid[2]->tree(), clipping);
- Vec3SGrid::Ptr vecgrid = Vec3SGrid::create(Vec3s(0.0f));
+ Vec3SGrid::Ptr vecgrid = Vec3SGrid::create(Vec3s(0.0f));
- /* Activate voxels in the vector grid based on the scalar grids to ensure
- * thread safety later on */
- for (int i = 0; i < 3; ++i) {
- vecgrid->tree().topologyUnion(grid[i]->tree());
- }
+ /* Activate voxels in the vector grid based on the scalar grids to ensure
+ * thread safety later on */
+ for (int i = 0; i < 3; ++i) {
+ vecgrid->tree().topologyUnion(grid[i]->tree());
+ }
- MergeScalarGrids op(&(grid[0]->tree()), &(grid[1]->tree()), &(grid[2]->tree()));
- tools::foreach(vecgrid->beginValueOn(), op, true, false);
+ MergeScalarGrids op(&(grid[0]->tree()), &(grid[1]->tree()), &(grid[2]->tree()));
+ tools::foreach (vecgrid->beginValueOn(), op, true, false);
- vecgrid->setTransform(transform);
+ vecgrid->setTransform(transform);
- /* Avoid clipping against an empty grid. */
- if (mask && !mask->tree().empty()) {
- vecgrid = tools::clip(*vecgrid, *mask);
- }
+ /* Avoid clipping against an empty grid. */
+ if (mask && !mask->tree().empty()) {
+ vecgrid = tools::clip(*vecgrid, *mask);
+ }
- vecgrid->setName(name);
- vecgrid->setIsInWorldSpace(false);
- vecgrid->setVectorType(vec_type);
- vecgrid->insertMeta("is_color", BoolMetadata(is_color));
- vecgrid->setGridClass(GRID_STAGGERED);
+ vecgrid->setName(name);
+ vecgrid->setIsInWorldSpace(false);
+ vecgrid->setVectorType(vec_type);
+ vecgrid->insertMeta("is_color", BoolMetadata(is_color));
+ vecgrid->setGridClass(GRID_STAGGERED);
- writer->insert(vecgrid);
+ writer->insert(vecgrid);
- return vecgrid.get();
+ return vecgrid.get();
}
-void OpenVDB_import_grid_vector(
- OpenVDBReader *reader,
- const openvdb::Name &name,
- float **data_x, float **data_y, float **data_z,
- const int res[3])
+void OpenVDB_import_grid_vector(OpenVDBReader *reader,
+ const openvdb::Name &name,
+ float **data_x,
+ float **data_y,
+ float **data_z,
+ const int res[3])
{
- using namespace openvdb;
-
- if (!reader->hasGrid(name)) {
- std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", name.c_str());
- memset(*data_x, 0, sizeof(float) * res[0] * res[1] * res[2]);
- memset(*data_y, 0, sizeof(float) * res[0] * res[1] * res[2]);
- memset(*data_z, 0, sizeof(float) * res[0] * res[1] * res[2]);
- return;
- }
-
- Vec3SGrid::Ptr vgrid = gridPtrCast<Vec3SGrid>(reader->getGrid(name));
- Vec3SGrid::ConstAccessor acc = vgrid->getConstAccessor();
- math::Coord xyz;
- int &x = xyz[0], &y = xyz[1], &z = xyz[2];
-
- size_t index = 0;
- for (z = 0; z < res[2]; ++z) {
- for (y = 0; y < res[1]; ++y) {
- for (x = 0; x < res[0]; ++x, ++index) {
- math::Vec3s value = acc.getValue(xyz);
- (*data_x)[index] = value.x();
- (*data_y)[index] = value.y();
- (*data_z)[index] = value.z();
- }
- }
- }
+ using namespace openvdb;
+
+ if (!reader->hasGrid(name)) {
+ std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", name.c_str());
+ memset(*data_x, 0, sizeof(float) * res[0] * res[1] * res[2]);
+ memset(*data_y, 0, sizeof(float) * res[0] * res[1] * res[2]);
+ memset(*data_z, 0, sizeof(float) * res[0] * res[1] * res[2]);
+ return;
+ }
+
+ Vec3SGrid::Ptr vgrid = gridPtrCast<Vec3SGrid>(reader->getGrid(name));
+ Vec3SGrid::ConstAccessor acc = vgrid->getConstAccessor();
+ math::Coord xyz;
+ int &x = xyz[0], &y = xyz[1], &z = xyz[2];
+
+ size_t index = 0;
+ for (z = 0; z < res[2]; ++z) {
+ for (y = 0; y < res[1]; ++y) {
+ for (x = 0; x < res[0]; ++x, ++index) {
+ math::Vec3s value = acc.getValue(xyz);
+ (*data_x)[index] = value.x();
+ (*data_y)[index] = value.y();
+ (*data_z)[index] = value.z();
+ }
+ }
+ }
}
openvdb::Name do_name_versionning(const openvdb::Name &name)
{
- openvdb::Name temp_name = name;
+ openvdb::Name temp_name = name;
- if (temp_name.find("_low", temp_name.size() - 4, 4) == temp_name.size() - 4) {
- return temp_name.replace(temp_name.size() - 4, 4, " low");
- }
+ if (temp_name.find("_low", temp_name.size() - 4, 4) == temp_name.size() - 4) {
+ return temp_name.replace(temp_name.size() - 4, 4, " low");
+ }
- if (temp_name.find("_old", temp_name.size() - 4, 4) == temp_name.size() - 4) {
- return temp_name.replace(temp_name.size() - 4, 4, " old");
- }
+ if (temp_name.find("_old", temp_name.size() - 4, 4) == temp_name.size() - 4) {
+ return temp_name.replace(temp_name.size() - 4, 4, " old");
+ }
- return temp_name;
+ return temp_name;
}
-} /* namespace internal */
+} /* namespace internal */
diff --git a/intern/openvdb/intern/openvdb_dense_convert.h b/intern/openvdb/intern/openvdb_dense_convert.h
index fe57ea86789..fbad15eae04 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.h
+++ b/intern/openvdb/intern/openvdb_dense_convert.h
@@ -36,97 +36,97 @@ openvdb::Name do_name_versionning(const openvdb::Name &name);
openvdb::Mat4R convertMatrix(const float mat[4][4]);
-template <typename GridType, typename T>
-GridType *OpenVDB_export_grid(
- OpenVDBWriter *writer,
- const openvdb::Name &name,
- const T *data,
- const int res[3],
- float fluid_mat[4][4],
- const float clipping,
- const openvdb::FloatGrid *mask)
+template<typename GridType, typename T>
+GridType *OpenVDB_export_grid(OpenVDBWriter *writer,
+ const openvdb::Name &name,
+ const T *data,
+ const int res[3],
+ float fluid_mat[4][4],
+ const float clipping,
+ const openvdb::FloatGrid *mask)
{
- using namespace openvdb;
+ using namespace openvdb;
- math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 1));
- Mat4R mat = convertMatrix(fluid_mat);
- math::Transform::Ptr transform = math::Transform::createLinearTransform(mat);
+ math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 1));
+ Mat4R mat = convertMatrix(fluid_mat);
+ math::Transform::Ptr transform = math::Transform::createLinearTransform(mat);
- typename GridType::Ptr grid = GridType::create(T(0));
+ typename GridType::Ptr grid = GridType::create(T(0));
- tools::Dense<const T, openvdb::tools::LayoutXYZ> dense_grid(bbox, data);
- tools::copyFromDense(dense_grid, grid->tree(), static_cast<T>(clipping));
+ tools::Dense<const T, openvdb::tools::LayoutXYZ> dense_grid(bbox, data);
+ tools::copyFromDense(dense_grid, grid->tree(), static_cast<T>(clipping));
- grid->setTransform(transform);
+ grid->setTransform(transform);
- /* Avoid clipping against an empty grid. */
- if (mask && !mask->tree().empty()) {
- grid = tools::clip(*grid, *mask);
- }
+ /* Avoid clipping against an empty grid. */
+ if (mask && !mask->tree().empty()) {
+ grid = tools::clip(*grid, *mask);
+ }
- grid->setName(name);
- grid->setIsInWorldSpace(false);
- grid->setVectorType(openvdb::VEC_INVARIANT);
+ grid->setName(name);
+ grid->setIsInWorldSpace(false);
+ grid->setVectorType(openvdb::VEC_INVARIANT);
- writer->insert(grid);
+ writer->insert(grid);
- return grid.get();
+ return grid.get();
}
-template <typename GridType, typename T>
-void OpenVDB_import_grid(
- OpenVDBReader *reader,
- const openvdb::Name &name,
- T **data,
- const int res[3])
+template<typename GridType, typename T>
+void OpenVDB_import_grid(OpenVDBReader *reader,
+ const openvdb::Name &name,
+ T **data,
+ const int res[3])
{
- using namespace openvdb;
-
- openvdb::Name temp_name = name;
-
- if (!reader->hasGrid(temp_name)) {
- temp_name = do_name_versionning(temp_name);
-
- if (!reader->hasGrid(temp_name)) {
- std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", temp_name.c_str());
- memset(*data, 0, sizeof(T) * res[0] * res[1] * res[2]);
- return;
- }
- }
-
- typename GridType::Ptr grid = gridPtrCast<GridType>(reader->getGrid(temp_name));
- typename GridType::ConstAccessor acc = grid->getConstAccessor();
-
- math::Coord xyz;
- int &x = xyz[0], &y = xyz[1], &z = xyz[2];
-
- size_t index = 0;
- for (z = 0; z < res[2]; ++z) {
- for (y = 0; y < res[1]; ++y) {
- for (x = 0; x < res[0]; ++x, ++index) {
- (*data)[index] = acc.getValue(xyz);
- }
- }
- }
+ using namespace openvdb;
+
+ openvdb::Name temp_name = name;
+
+ if (!reader->hasGrid(temp_name)) {
+ temp_name = do_name_versionning(temp_name);
+
+ if (!reader->hasGrid(temp_name)) {
+ std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", temp_name.c_str());
+ memset(*data, 0, sizeof(T) * res[0] * res[1] * res[2]);
+ return;
+ }
+ }
+
+ typename GridType::Ptr grid = gridPtrCast<GridType>(reader->getGrid(temp_name));
+ typename GridType::ConstAccessor acc = grid->getConstAccessor();
+
+ math::Coord xyz;
+ int &x = xyz[0], &y = xyz[1], &z = xyz[2];
+
+ size_t index = 0;
+ for (z = 0; z < res[2]; ++z) {
+ for (y = 0; y < res[1]; ++y) {
+ for (x = 0; x < res[0]; ++x, ++index) {
+ (*data)[index] = acc.getValue(xyz);
+ }
+ }
+ }
}
openvdb::GridBase *OpenVDB_export_vector_grid(OpenVDBWriter *writer,
- const openvdb::Name &name,
- const float *data_x, const float *data_y, const float *data_z,
- const int res[3],
- float fluid_mat[4][4],
- openvdb::VecType vec_type,
- const bool is_color,
- const float clipping,
- const openvdb::FloatGrid *mask);
-
-
-void OpenVDB_import_grid_vector(
- OpenVDBReader *reader,
- const openvdb::Name &name,
- float **data_x, float **data_y, float **data_z,
- const int res[3]);
-
-} /* namespace internal */
+ const openvdb::Name &name,
+ const float *data_x,
+ const float *data_y,
+ const float *data_z,
+ const int res[3],
+ float fluid_mat[4][4],
+ openvdb::VecType vec_type,
+ const bool is_color,
+ const float clipping,
+ const openvdb::FloatGrid *mask);
+
+void OpenVDB_import_grid_vector(OpenVDBReader *reader,
+ const openvdb::Name &name,
+ float **data_x,
+ float **data_y,
+ float **data_z,
+ const int res[3]);
+
+} /* namespace internal */
#endif /* __OPENVDB_DENSE_CONVERT_H__ */
diff --git a/intern/openvdb/intern/openvdb_level_set.cc b/intern/openvdb/intern/openvdb_level_set.cc
index 0205d142108..ac4a041c193 100644
--- a/intern/openvdb/intern/openvdb_level_set.cc
+++ b/intern/openvdb/intern/openvdb_level_set.cc
@@ -17,7 +17,6 @@
* All rights reserved.
*/
-
#include "openvdb_level_set.h"
#include "openvdb_util.h"
#include "openvdb_capi.h"
@@ -26,130 +25,155 @@
OpenVDBLevelSet::OpenVDBLevelSet()
{
- openvdb::initialize();
+ openvdb::initialize();
}
OpenVDBLevelSet::~OpenVDBLevelSet()
-{}
-
-void OpenVDBLevelSet::OpenVDB_mesh_to_level_set(const float *vertices, const unsigned int *faces, const unsigned int totvertices,
- const unsigned int totfaces, openvdb::math::Transform::Ptr xform)
{
- std::vector<openvdb::Vec3s> points;
- std::vector<openvdb::Vec3I > triangles;
- std::vector<openvdb::Vec4I > quads;
-
- for(unsigned int i = 0; i < totvertices; i++) {
- openvdb::Vec3s v(vertices[i * 3 ], vertices[i * 3 + 1], vertices[i * 3 + 2]);
- points.push_back(v);
- }
-
- for(unsigned int i = 0; i < totfaces; i++) {
- openvdb::Vec3I f(faces[i * 3 ], faces[i * 3 + 1], faces[i * 3 + 2]);
- triangles.push_back(f);
- }
+}
- this->grid = openvdb::tools::meshToLevelSet<openvdb::FloatGrid>(*xform, points, triangles, quads, 1);
+void OpenVDBLevelSet::OpenVDB_mesh_to_level_set(const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ openvdb::math::Transform::Ptr xform)
+{
+ std::vector<openvdb::Vec3s> points;
+ std::vector<openvdb::Vec3I> triangles;
+ std::vector<openvdb::Vec4I> quads;
+
+ for (unsigned int i = 0; i < totvertices; i++) {
+ openvdb::Vec3s v(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]);
+ points.push_back(v);
+ }
+
+ for (unsigned int i = 0; i < totfaces; i++) {
+ openvdb::Vec3I f(faces[i * 3], faces[i * 3 + 1], faces[i * 3 + 2]);
+ triangles.push_back(f);
+ }
+
+ this->grid = openvdb::tools::meshToLevelSet<openvdb::FloatGrid>(
+ *xform, points, triangles, quads, 1);
}
-void OpenVDBLevelSet::OpenVDB_volume_to_mesh(OpenVDBVolumeToMeshData *mesh, const double isovalue, const double adaptivity, const bool relax_disoriented_triangles)
+void OpenVDBLevelSet::OpenVDB_volume_to_mesh(OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles)
{
- std::vector<openvdb::Vec3s> out_points;
- std::vector<openvdb::Vec4I > out_quads;
- std::vector<openvdb::Vec3I > out_tris;
- openvdb::tools::volumeToMesh<openvdb::FloatGrid>(*this->grid, out_points, out_tris, out_quads, isovalue,
- adaptivity, relax_disoriented_triangles);
- mesh->vertices = (float *)MEM_malloc_arrayN(out_points.size(), 3 * sizeof (float), "openvdb remesher out verts");
- mesh->quads = (unsigned int*)MEM_malloc_arrayN(out_quads.size(), 4 * sizeof (unsigned int), "openvdb remesh out quads");
- mesh->triangles = NULL;
- if (out_tris.size() > 0) {
- mesh->triangles = (unsigned int*)MEM_malloc_arrayN(out_tris.size(), 3 * sizeof (unsigned int), "openvdb remesh out tris");
- }
-
- mesh->totvertices = out_points.size();
- mesh->tottriangles = out_tris.size();
- mesh->totquads = out_quads.size();
-
- for(unsigned int i = 0; i < out_points.size(); i++) {
- mesh->vertices[i * 3] = out_points[i].x();
- mesh->vertices[i * 3 + 1] = out_points[i].y();
- mesh->vertices[i * 3 + 2] = out_points[i].z();
- }
-
- for(unsigned int i = 0; i < out_quads.size(); i++) {
- mesh->quads[i * 4] = out_quads[i].x();
- mesh->quads[i * 4 + 1] = out_quads[i].y();
- mesh->quads[i * 4 + 2] = out_quads[i].z();
- mesh->quads[i * 4 + 3] = out_quads[i].w();
- }
-
- for(unsigned int i = 0; i < out_tris.size(); i++) {
- mesh->triangles[i * 3] = out_tris[i].x();
- mesh->triangles[i * 3 + 1] = out_tris[i].y();
- mesh->triangles[i * 3 + 2] = out_tris[i].z();
- }
+ std::vector<openvdb::Vec3s> out_points;
+ std::vector<openvdb::Vec4I> out_quads;
+ std::vector<openvdb::Vec3I> out_tris;
+ openvdb::tools::volumeToMesh<openvdb::FloatGrid>(*this->grid,
+ out_points,
+ out_tris,
+ out_quads,
+ isovalue,
+ adaptivity,
+ relax_disoriented_triangles);
+ mesh->vertices = (float *)MEM_malloc_arrayN(
+ out_points.size(), 3 * sizeof(float), "openvdb remesher out verts");
+ mesh->quads = (unsigned int *)MEM_malloc_arrayN(
+ out_quads.size(), 4 * sizeof(unsigned int), "openvdb remesh out quads");
+ mesh->triangles = NULL;
+ if (out_tris.size() > 0) {
+ mesh->triangles = (unsigned int *)MEM_malloc_arrayN(
+ out_tris.size(), 3 * sizeof(unsigned int), "openvdb remesh out tris");
+ }
+
+ mesh->totvertices = out_points.size();
+ mesh->tottriangles = out_tris.size();
+ mesh->totquads = out_quads.size();
+
+ for (unsigned int i = 0; i < out_points.size(); i++) {
+ mesh->vertices[i * 3] = out_points[i].x();
+ mesh->vertices[i * 3 + 1] = out_points[i].y();
+ mesh->vertices[i * 3 + 2] = out_points[i].z();
+ }
+
+ for (unsigned int i = 0; i < out_quads.size(); i++) {
+ mesh->quads[i * 4] = out_quads[i].x();
+ mesh->quads[i * 4 + 1] = out_quads[i].y();
+ mesh->quads[i * 4 + 2] = out_quads[i].z();
+ mesh->quads[i * 4 + 3] = out_quads[i].w();
+ }
+
+ for (unsigned int i = 0; i < out_tris.size(); i++) {
+ mesh->triangles[i * 3] = out_tris[i].x();
+ mesh->triangles[i * 3 + 1] = out_tris[i].y();
+ mesh->triangles[i * 3 + 2] = out_tris[i].z();
+ }
}
-void OpenVDBLevelSet::OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter_type, int width, int iterations, int filter_bias){
-
- if (!this->grid) {
- return;
- }
-
- if (this->grid && this->grid->getGridClass() != openvdb::GRID_LEVEL_SET) {
- return;
- }
-
- openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filter(*this->grid);
- filter.setSpatialScheme((openvdb::math::BiasedGradientScheme)filter_bias);
- switch (filter_type) {
- case OPENVDB_LEVELSET_FILTER_GAUSSIAN:
- filter.gaussian(width);
- break;
- case OPENVDB_LEVELSET_FILTER_MEDIAN:
- filter.median(width);
- break;
- case OPENVDB_LEVELSET_FILTER_MEAN:
- filter.mean(width);
- break;
- case OPENVDB_LEVELSET_FILTER_MEAN_CURVATURE:
- filter.meanCurvature();
- break;
- case OPENVDB_LEVELSET_FILTER_LAPLACIAN:
- filter.laplacian();
- break;
- case OPENVDB_LEVELSET_FILTER_DILATE:
- filter.offset(-iterations/100.0);
- break;
- case OPENVDB_LEVELSET_FILTER_ERODE:
- filter.offset(iterations/100.0);
- break;
- }
+void OpenVDBLevelSet::OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ int filter_bias)
+{
+
+ if (!this->grid) {
+ return;
+ }
+
+ if (this->grid && this->grid->getGridClass() != openvdb::GRID_LEVEL_SET) {
+ return;
+ }
+
+ openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filter(*this->grid);
+ filter.setSpatialScheme((openvdb::math::BiasedGradientScheme)filter_bias);
+ switch (filter_type) {
+ case OPENVDB_LEVELSET_FILTER_GAUSSIAN:
+ filter.gaussian(width);
+ break;
+ case OPENVDB_LEVELSET_FILTER_MEDIAN:
+ filter.median(width);
+ break;
+ case OPENVDB_LEVELSET_FILTER_MEAN:
+ filter.mean(width);
+ break;
+ case OPENVDB_LEVELSET_FILTER_MEAN_CURVATURE:
+ filter.meanCurvature();
+ break;
+ case OPENVDB_LEVELSET_FILTER_LAPLACIAN:
+ filter.laplacian();
+ break;
+ case OPENVDB_LEVELSET_FILTER_DILATE:
+ filter.offset(-iterations / 100.0);
+ break;
+ case OPENVDB_LEVELSET_FILTER_ERODE:
+ filter.offset(iterations / 100.0);
+ break;
+ }
}
-openvdb::FloatGrid::Ptr OpenVDBLevelSet::OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr gridA, openvdb::FloatGrid::Ptr gridB, OpenVDBLevelSet_CSGOperation operation)
+openvdb::FloatGrid::Ptr OpenVDBLevelSet::OpenVDB_CSG_operation(
+ openvdb::FloatGrid::Ptr gridA,
+ openvdb::FloatGrid::Ptr gridB,
+ OpenVDBLevelSet_CSGOperation operation)
{
- openvdb::FloatGrid::Ptr gridA_copy = gridA;//->deepCopy();
- openvdb::FloatGrid::Ptr gridB_copy = gridB;//->deepCopy();
-
- switch (operation) {
- case OPENVDB_LEVELSET_CSG_UNION:
- openvdb::tools::csgUnion(*gridA_copy, *gridB_copy);
- break;
- case OPENVDB_LEVELSET_CSG_DIFFERENCE:
- openvdb::tools::csgDifference(*gridA_copy, *gridB_copy);
- break;
- case OPENVDB_LEVELSET_CSG_INTERSECTION:
- openvdb::tools::csgIntersection(*gridA_copy, *gridB_copy);
- break;
- }
-
- return gridA_copy;
+ openvdb::FloatGrid::Ptr gridA_copy = gridA; //->deepCopy();
+ openvdb::FloatGrid::Ptr gridB_copy = gridB; //->deepCopy();
+
+ switch (operation) {
+ case OPENVDB_LEVELSET_CSG_UNION:
+ openvdb::tools::csgUnion(*gridA_copy, *gridB_copy);
+ break;
+ case OPENVDB_LEVELSET_CSG_DIFFERENCE:
+ openvdb::tools::csgDifference(*gridA_copy, *gridB_copy);
+ break;
+ case OPENVDB_LEVELSET_CSG_INTERSECTION:
+ openvdb::tools::csgIntersection(*gridA_copy, *gridB_copy);
+ break;
+ }
+
+ return gridA_copy;
}
-openvdb::FloatGrid::Ptr OpenVDBLevelSet::OpenVDB_level_set_get_grid(){
- return this->grid;
+openvdb::FloatGrid::Ptr OpenVDBLevelSet::OpenVDB_level_set_get_grid()
+{
+ return this->grid;
}
-void OpenVDBLevelSet::OpenVDB_level_set_set_grid(openvdb::FloatGrid::Ptr grid){
- this->grid = grid;
+void OpenVDBLevelSet::OpenVDB_level_set_set_grid(openvdb::FloatGrid::Ptr grid)
+{
+ this->grid = grid;
}
diff --git a/intern/openvdb/intern/openvdb_level_set.h b/intern/openvdb/intern/openvdb_level_set.h
index a4779bd1308..01d1b8e538a 100644
--- a/intern/openvdb/intern/openvdb_level_set.h
+++ b/intern/openvdb/intern/openvdb_level_set.h
@@ -28,29 +28,47 @@
#include <openvdb/tools/GridTransformer.h>
#include "openvdb_capi.h"
-
struct OpenVDBLevelSet {
-private:
- openvdb::FloatGrid::Ptr grid;
+ private:
+ openvdb::FloatGrid::Ptr grid;
-public:
- OpenVDBLevelSet();
- ~OpenVDBLevelSet();
- openvdb::FloatGrid::Ptr OpenVDB_level_set_get_grid();
- void OpenVDB_level_set_set_grid(openvdb::FloatGrid::Ptr);
- void OpenVDB_mesh_to_level_set(const float *vertices, const unsigned int *faces, const unsigned int totvertices,
- const unsigned int totfaces, const double voxel_size);
+ public:
+ OpenVDBLevelSet();
+ ~OpenVDBLevelSet();
+ openvdb::FloatGrid::Ptr OpenVDB_level_set_get_grid();
+ void OpenVDB_level_set_set_grid(openvdb::FloatGrid::Ptr);
+ void OpenVDB_mesh_to_level_set(const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ const double voxel_size);
- void OpenVDB_mesh_to_level_set(const float *vertices, const unsigned int *faces, const unsigned int totvertices,
- const unsigned int totfaces, openvdb::math::Transform::Ptr transform);
+ void OpenVDB_mesh_to_level_set(const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ openvdb::math::Transform::Ptr transform);
- void OpenVDB_volume_to_mesh(float *vertices, unsigned int *quads, unsigned int *triangles,
- unsigned int *totvertices, unsigned int *totfaces, unsigned int *tottriangles,
- const double isovalue, const double adaptivity, const bool relax_disoriented_triangles);
- void OpenVDB_volume_to_mesh(struct OpenVDBVolumeToMeshData *mesh, const double isovalue, const double adaptivity, const bool relax_disoriented_triangles);
- void OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter_type, int width, int iterations, int filter_bias);
- openvdb::FloatGrid::Ptr OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr gridA, openvdb::FloatGrid::Ptr gridB,
- OpenVDBLevelSet_CSGOperation operation);
+ void OpenVDB_volume_to_mesh(float *vertices,
+ unsigned int *quads,
+ unsigned int *triangles,
+ unsigned int *totvertices,
+ unsigned int *totfaces,
+ unsigned int *tottriangles,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles);
+ void OpenVDB_volume_to_mesh(struct OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles);
+ void OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ int filter_bias);
+ openvdb::FloatGrid::Ptr OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr gridA,
+ openvdb::FloatGrid::Ptr gridB,
+ OpenVDBLevelSet_CSGOperation operation);
};
#endif /* __OPENVDB_LEVEL_SET_H__ */
diff --git a/intern/openvdb/intern/openvdb_reader.cc b/intern/openvdb/intern/openvdb_reader.cc
index 3fdad2a553f..934b6e8869d 100644
--- a/intern/openvdb/intern/openvdb_reader.cc
+++ b/intern/openvdb/intern/openvdb_reader.cc
@@ -20,111 +20,109 @@
#include "openvdb_reader.h"
#include "openvdb_util.h"
-OpenVDBReader::OpenVDBReader()
- : m_meta_map(new openvdb::MetaMap)
- , m_file(NULL)
+OpenVDBReader::OpenVDBReader() : m_meta_map(new openvdb::MetaMap), m_file(NULL)
{
- /* Although it is safe, it may not be good to have this here, could be done
- * once instead of everytime we read a file. */
- openvdb::initialize();
+ /* Although it is safe, it may not be good to have this here, could be done
+ * once instead of everytime we read a file. */
+ openvdb::initialize();
}
OpenVDBReader::~OpenVDBReader()
{
- cleanupFile();
+ cleanupFile();
}
void OpenVDBReader::open(const openvdb::Name &filename)
{
- cleanupFile();
-
- try {
- m_file = new openvdb::io::File(filename);
- m_file->setCopyMaxBytes(0);
- m_file->open();
-
- m_meta_map = m_file->getMetadata();
- }
- /* Mostly to catch exceptions related to Blosc not being supported. */
- catch (const openvdb::IoError &e) {
- std::cerr << e.what() << '\n';
- cleanupFile();
- }
+ cleanupFile();
+
+ try {
+ m_file = new openvdb::io::File(filename);
+ m_file->setCopyMaxBytes(0);
+ m_file->open();
+
+ m_meta_map = m_file->getMetadata();
+ }
+ /* Mostly to catch exceptions related to Blosc not being supported. */
+ catch (const openvdb::IoError &e) {
+ std::cerr << e.what() << '\n';
+ cleanupFile();
+ }
}
void OpenVDBReader::floatMeta(const openvdb::Name &name, float &value) const
{
- try {
- value = m_meta_map->metaValue<float>(name);
- }
- CATCH_KEYERROR;
+ try {
+ value = m_meta_map->metaValue<float>(name);
+ }
+ CATCH_KEYERROR;
}
void OpenVDBReader::intMeta(const openvdb::Name &name, int &value) const
{
- try {
- value = m_meta_map->metaValue<int>(name);
- }
- CATCH_KEYERROR;
+ try {
+ value = m_meta_map->metaValue<int>(name);
+ }
+ CATCH_KEYERROR;
}
void OpenVDBReader::vec3sMeta(const openvdb::Name &name, float value[3]) const
{
- try {
- openvdb::Vec3s meta_val = m_meta_map->metaValue<openvdb::Vec3s>(name);
-
- value[0] = meta_val.x();
- value[1] = meta_val.y();
- value[2] = meta_val.z();
- }
- CATCH_KEYERROR;
+ try {
+ openvdb::Vec3s meta_val = m_meta_map->metaValue<openvdb::Vec3s>(name);
+
+ value[0] = meta_val.x();
+ value[1] = meta_val.y();
+ value[2] = meta_val.z();
+ }
+ CATCH_KEYERROR;
}
void OpenVDBReader::vec3IMeta(const openvdb::Name &name, int value[3]) const
{
- try {
- openvdb::Vec3i meta_val = m_meta_map->metaValue<openvdb::Vec3i>(name);
-
- value[0] = meta_val.x();
- value[1] = meta_val.y();
- value[2] = meta_val.z();
- }
- CATCH_KEYERROR;
+ try {
+ openvdb::Vec3i meta_val = m_meta_map->metaValue<openvdb::Vec3i>(name);
+
+ value[0] = meta_val.x();
+ value[1] = meta_val.y();
+ value[2] = meta_val.z();
+ }
+ CATCH_KEYERROR;
}
void OpenVDBReader::mat4sMeta(const openvdb::Name &name, float value[4][4]) const
{
- try {
- openvdb::Mat4s meta_val = m_meta_map->metaValue<openvdb::Mat4s>(name);
-
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- value[i][j] = meta_val[i][j];
- }
- }
- }
- CATCH_KEYERROR;
+ try {
+ openvdb::Mat4s meta_val = m_meta_map->metaValue<openvdb::Mat4s>(name);
+
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ value[i][j] = meta_val[i][j];
+ }
+ }
+ }
+ CATCH_KEYERROR;
}
bool OpenVDBReader::hasGrid(const openvdb::Name &name) const
{
- return m_file->hasGrid(name);
+ return m_file->hasGrid(name);
}
openvdb::GridBase::Ptr OpenVDBReader::getGrid(const openvdb::Name &name) const
{
- return m_file->readGrid(name);
+ return m_file->readGrid(name);
}
size_t OpenVDBReader::numGrids() const
{
- return m_file->getGrids()->size();
+ return m_file->getGrids()->size();
}
void OpenVDBReader::cleanupFile()
{
- if (m_file) {
- m_file->close();
- delete m_file;
- }
+ if (m_file) {
+ m_file->close();
+ delete m_file;
+ }
}
diff --git a/intern/openvdb/intern/openvdb_reader.h b/intern/openvdb/intern/openvdb_reader.h
index 39fbf6cd15a..f8c16cea141 100644
--- a/intern/openvdb/intern/openvdb_reader.h
+++ b/intern/openvdb/intern/openvdb_reader.h
@@ -23,27 +23,27 @@
#include <openvdb/openvdb.h>
struct OpenVDBReader {
-private:
- openvdb::MetaMap::Ptr m_meta_map;
- openvdb::io::File *m_file;
+ private:
+ openvdb::MetaMap::Ptr m_meta_map;
+ openvdb::io::File *m_file;
- void cleanupFile();
+ void cleanupFile();
-public:
- OpenVDBReader();
- ~OpenVDBReader();
+ public:
+ OpenVDBReader();
+ ~OpenVDBReader();
- void open(const openvdb::Name &filename);
+ void open(const openvdb::Name &filename);
- void floatMeta(const openvdb::Name &name, float &value) const;
- void intMeta(const openvdb::Name &name, int &value) const;
- void vec3sMeta(const openvdb::Name &name, float value[3]) const;
- void vec3IMeta(const openvdb::Name &name, int value[3]) const;
- void mat4sMeta(const openvdb::Name &name, float value[4][4]) const;
+ void floatMeta(const openvdb::Name &name, float &value) const;
+ void intMeta(const openvdb::Name &name, int &value) const;
+ void vec3sMeta(const openvdb::Name &name, float value[3]) const;
+ void vec3IMeta(const openvdb::Name &name, int value[3]) const;
+ void mat4sMeta(const openvdb::Name &name, float value[4][4]) const;
- bool hasGrid(const openvdb::Name &name) const;
- openvdb::GridBase::Ptr getGrid(const openvdb::Name &name) const;
- size_t numGrids() const;
+ bool hasGrid(const openvdb::Name &name) const;
+ openvdb::GridBase::Ptr getGrid(const openvdb::Name &name) const;
+ size_t numGrids() const;
};
#endif /* __OPENVDB_READER_H__ */
diff --git a/intern/openvdb/intern/openvdb_transform.cc b/intern/openvdb/intern/openvdb_transform.cc
index 76b9343b00e..5fbd2c298b1 100644
--- a/intern/openvdb/intern/openvdb_transform.cc
+++ b/intern/openvdb/intern/openvdb_transform.cc
@@ -20,22 +20,24 @@
#include "openvdb_transform.h"
OpenVDBTransform::OpenVDBTransform()
-{}
+{
+}
OpenVDBTransform::~OpenVDBTransform()
-{}
+{
+}
void OpenVDBTransform::OpenVDB_transform_create_linear_transform(double voxel_size)
{
- this->transform = openvdb::math::Transform::createLinearTransform(voxel_size);
+ this->transform = openvdb::math::Transform::createLinearTransform(voxel_size);
}
openvdb::math::Transform::Ptr OpenVDBTransform::OpenVDB_transform_get_transform()
{
- return this->transform;
+ return this->transform;
}
void OpenVDBTransform::OpenVDB_transform_set_transform(openvdb::math::Transform::Ptr transform)
{
- this->transform = transform;
+ this->transform = transform;
}
diff --git a/intern/openvdb/intern/openvdb_transform.h b/intern/openvdb/intern/openvdb_transform.h
index f0b92775310..71db0083cd0 100644
--- a/intern/openvdb/intern/openvdb_transform.h
+++ b/intern/openvdb/intern/openvdb_transform.h
@@ -17,22 +17,21 @@
* All rights reserved.
*/
- #ifndef OPENVDB_TRANSFORM_H
- #define OPENVDB_TRANSFORM_H
-
+#ifndef OPENVDB_TRANSFORM_H
+#define OPENVDB_TRANSFORM_H
+
#include <openvdb/openvdb.h>
struct OpenVDBTransform {
-private:
- openvdb::math::Transform::Ptr transform;
+ private:
+ openvdb::math::Transform::Ptr transform;
-public:
- OpenVDBTransform();
- ~OpenVDBTransform();
- void OpenVDB_transform_create_linear_transform(double voxel_size);
- openvdb::math::Transform::Ptr OpenVDB_transform_get_transform();
- void OpenVDB_transform_set_transform(openvdb::math::Transform::Ptr transform);
+ public:
+ OpenVDBTransform();
+ ~OpenVDBTransform();
+ void OpenVDB_transform_create_linear_transform(double voxel_size);
+ openvdb::math::Transform::Ptr OpenVDB_transform_get_transform();
+ void OpenVDB_transform_set_transform(openvdb::math::Transform::Ptr transform);
};
-
- #endif // OPENVDB_TRANSFORM_H
+#endif // OPENVDB_TRANSFORM_H
diff --git a/intern/openvdb/intern/openvdb_writer.cc b/intern/openvdb/intern/openvdb_writer.cc
index 900c5371682..9c6ff9ed226 100644
--- a/intern/openvdb/intern/openvdb_writer.cc
+++ b/intern/openvdb/intern/openvdb_writer.cc
@@ -21,96 +21,106 @@
#include "openvdb_util.h"
OpenVDBWriter::OpenVDBWriter()
- : m_grids(new openvdb::GridPtrVec())
- , m_meta_map(new openvdb::MetaMap())
- , m_save_as_half(false)
+ : m_grids(new openvdb::GridPtrVec()), m_meta_map(new openvdb::MetaMap()), m_save_as_half(false)
{
- m_meta_map->insertMeta("creator", openvdb::StringMetadata("Blender/Smoke"));
+ m_meta_map->insertMeta("creator", openvdb::StringMetadata("Blender/Smoke"));
}
OpenVDBWriter::~OpenVDBWriter()
-{}
+{
+}
void OpenVDBWriter::insert(const openvdb::GridBase::Ptr &grid)
{
- grid->setSaveFloatAsHalf(m_save_as_half);
- m_grids->push_back(grid);
+ grid->setSaveFloatAsHalf(m_save_as_half);
+ m_grids->push_back(grid);
}
void OpenVDBWriter::insert(const openvdb::GridBase &grid)
{
#if (OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER <= 3) || defined(OPENVDB_3_ABI_COMPATIBLE)
- m_grids->push_back(grid.copyGrid());
+ m_grids->push_back(grid.copyGrid());
#else
- m_grids->push_back(grid.copyGridWithNewTree());
+ m_grids->push_back(grid.copyGridWithNewTree());
#endif
}
void OpenVDBWriter::insertFloatMeta(const openvdb::Name &name, const float value)
{
- try {
- m_meta_map->insertMeta(name, openvdb::FloatMetadata(value));
- }
- CATCH_KEYERROR;
+ try {
+ m_meta_map->insertMeta(name, openvdb::FloatMetadata(value));
+ }
+ CATCH_KEYERROR;
}
void OpenVDBWriter::insertIntMeta(const openvdb::Name &name, const int value)
{
- try {
- m_meta_map->insertMeta(name, openvdb::Int32Metadata(value));
- }
- CATCH_KEYERROR;
+ try {
+ m_meta_map->insertMeta(name, openvdb::Int32Metadata(value));
+ }
+ CATCH_KEYERROR;
}
void OpenVDBWriter::insertVec3sMeta(const openvdb::Name &name, const openvdb::Vec3s &value)
{
- try {
- m_meta_map->insertMeta(name, openvdb::Vec3SMetadata(value));
- }
- CATCH_KEYERROR;
+ try {
+ m_meta_map->insertMeta(name, openvdb::Vec3SMetadata(value));
+ }
+ CATCH_KEYERROR;
}
void OpenVDBWriter::insertVec3IMeta(const openvdb::Name &name, const openvdb::Vec3I &value)
{
- try {
- m_meta_map->insertMeta(name, openvdb::Vec3IMetadata(value));
- }
- CATCH_KEYERROR;
+ try {
+ m_meta_map->insertMeta(name, openvdb::Vec3IMetadata(value));
+ }
+ CATCH_KEYERROR;
}
void OpenVDBWriter::insertMat4sMeta(const openvdb::Name &name, const float value[4][4])
{
- openvdb::Mat4s mat = openvdb::Mat4s(
- value[0][0], value[0][1], value[0][2], value[0][3],
- value[1][0], value[1][1], value[1][2], value[1][3],
- value[2][0], value[2][1], value[2][2], value[2][3],
- value[3][0], value[3][1], value[3][2], value[3][3]);
+ openvdb::Mat4s mat = openvdb::Mat4s(value[0][0],
+ value[0][1],
+ value[0][2],
+ value[0][3],
+ value[1][0],
+ value[1][1],
+ value[1][2],
+ value[1][3],
+ value[2][0],
+ value[2][1],
+ value[2][2],
+ value[2][3],
+ value[3][0],
+ value[3][1],
+ value[3][2],
+ value[3][3]);
- try {
- m_meta_map->insertMeta(name, openvdb::Mat4SMetadata(mat));
- }
- CATCH_KEYERROR;
+ try {
+ m_meta_map->insertMeta(name, openvdb::Mat4SMetadata(mat));
+ }
+ CATCH_KEYERROR;
}
void OpenVDBWriter::setFlags(const int compression, const bool save_as_half)
{
- m_compression_flags = compression;
- m_save_as_half = save_as_half;
+ m_compression_flags = compression;
+ m_save_as_half = save_as_half;
}
void OpenVDBWriter::write(const openvdb::Name &filename) const
{
- try {
- openvdb::io::File file(filename);
- file.setCompression(m_compression_flags);
- file.write(*m_grids, *m_meta_map);
- file.close();
+ try {
+ openvdb::io::File file(filename);
+ file.setCompression(m_compression_flags);
+ file.write(*m_grids, *m_meta_map);
+ file.close();
- /* Should perhaps be an option at some point */
- m_grids->clear();
- }
- /* Mostly to catch exceptions related to Blosc not being supported. */
- catch (const openvdb::IoError &e) {
- std::cerr << e.what() << '\n';
- }
+ /* Should perhaps be an option at some point */
+ m_grids->clear();
+ }
+ /* Mostly to catch exceptions related to Blosc not being supported. */
+ catch (const openvdb::IoError &e) {
+ std::cerr << e.what() << '\n';
+ }
}
diff --git a/intern/openvdb/intern/openvdb_writer.h b/intern/openvdb/intern/openvdb_writer.h
index 4205807a89c..d0e022b4b7a 100644
--- a/intern/openvdb/intern/openvdb_writer.h
+++ b/intern/openvdb/intern/openvdb_writer.h
@@ -23,29 +23,29 @@
#include <openvdb/openvdb.h>
struct OpenVDBWriter {
-private:
- openvdb::GridPtrVecPtr m_grids;
- openvdb::MetaMap::Ptr m_meta_map;
+ private:
+ openvdb::GridPtrVecPtr m_grids;
+ openvdb::MetaMap::Ptr m_meta_map;
- int m_compression_flags;
- bool m_save_as_half;
+ int m_compression_flags;
+ bool m_save_as_half;
-public:
- OpenVDBWriter();
- ~OpenVDBWriter();
+ public:
+ OpenVDBWriter();
+ ~OpenVDBWriter();
- void insert(const openvdb::GridBase::Ptr &grid);
- void insert(const openvdb::GridBase &grid);
+ void insert(const openvdb::GridBase::Ptr &grid);
+ void insert(const openvdb::GridBase &grid);
- void insertFloatMeta(const openvdb::Name &name, const float value);
- void insertIntMeta(const openvdb::Name &name, const int value);
- void insertVec3sMeta(const openvdb::Name &name, const openvdb::Vec3s &value);
- void insertVec3IMeta(const openvdb::Name &name, const openvdb::Vec3I &value);
- void insertMat4sMeta(const openvdb::Name &name, const float value[4][4]);
+ void insertFloatMeta(const openvdb::Name &name, const float value);
+ void insertIntMeta(const openvdb::Name &name, const int value);
+ void insertVec3sMeta(const openvdb::Name &name, const openvdb::Vec3s &value);
+ void insertVec3IMeta(const openvdb::Name &name, const openvdb::Vec3I &value);
+ void insertMat4sMeta(const openvdb::Name &name, const float value[4][4]);
- void setFlags(const int compression, const bool save_as_half);
+ void setFlags(const int compression, const bool save_as_half);
- void write(const openvdb::Name &filename) const;
+ void write(const openvdb::Name &filename) const;
};
#endif /* __OPENVDB_WRITER_H__ */
diff --git a/intern/openvdb/openvdb_capi.cc b/intern/openvdb/openvdb_capi.cc
index d5ff181c067..fea1f6034f0 100644
--- a/intern/openvdb/openvdb_capi.cc
+++ b/intern/openvdb/openvdb_capi.cc
@@ -23,343 +23,360 @@
#include "openvdb_level_set.h"
#include "openvdb_transform.h"
-struct OpenVDBIntGrid { int unused; };
-struct OpenVDBVectorGrid { int unused; };
+struct OpenVDBIntGrid {
+ int unused;
+};
+struct OpenVDBVectorGrid {
+ int unused;
+};
int OpenVDB_getVersionHex()
{
- return openvdb::OPENVDB_LIBRARY_VERSION;
+ return openvdb::OPENVDB_LIBRARY_VERSION;
}
-OpenVDBFloatGrid *OpenVDB_export_grid_fl(
- OpenVDBWriter *writer,
- const char *name, float *data,
- const int res[3], float matrix[4][4], const float clipping,
- OpenVDBFloatGrid *mask)
+OpenVDBFloatGrid *OpenVDB_export_grid_fl(OpenVDBWriter *writer,
+ const char *name,
+ float *data,
+ const int res[3],
+ float matrix[4][4],
+ const float clipping,
+ OpenVDBFloatGrid *mask)
{
- Timer(__func__);
+ Timer(__func__);
- using openvdb::FloatGrid;
+ using openvdb::FloatGrid;
- FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
- FloatGrid *grid = internal::OpenVDB_export_grid<FloatGrid>(
- writer,
- name,
- data,
- res,
- matrix,
- clipping,
- mask_grid);
+ FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
+ FloatGrid *grid = internal::OpenVDB_export_grid<FloatGrid>(
+ writer, name, data, res, matrix, clipping, mask_grid);
- return reinterpret_cast<OpenVDBFloatGrid *>(grid);
+ return reinterpret_cast<OpenVDBFloatGrid *>(grid);
}
-OpenVDBIntGrid *OpenVDB_export_grid_ch(
- OpenVDBWriter *writer,
- const char *name, unsigned char *data,
- const int res[3], float matrix[4][4], const float clipping,
- OpenVDBFloatGrid *mask)
+OpenVDBIntGrid *OpenVDB_export_grid_ch(OpenVDBWriter *writer,
+ const char *name,
+ unsigned char *data,
+ const int res[3],
+ float matrix[4][4],
+ const float clipping,
+ OpenVDBFloatGrid *mask)
{
- Timer(__func__);
+ Timer(__func__);
- using openvdb::FloatGrid;
- using openvdb::Int32Grid;
+ using openvdb::FloatGrid;
+ using openvdb::Int32Grid;
- FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
- Int32Grid *grid = internal::OpenVDB_export_grid<Int32Grid>(
- writer,
- name,
- data,
- res,
- matrix,
- clipping,
- mask_grid);
+ FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
+ Int32Grid *grid = internal::OpenVDB_export_grid<Int32Grid>(
+ writer, name, data, res, matrix, clipping, mask_grid);
- return reinterpret_cast<OpenVDBIntGrid *>(grid);
+ return reinterpret_cast<OpenVDBIntGrid *>(grid);
}
OpenVDBVectorGrid *OpenVDB_export_grid_vec(struct OpenVDBWriter *writer,
- const char *name,
- const float *data_x, const float *data_y, const float *data_z,
- const int res[3], float matrix[4][4], short vec_type, const float clipping,
- const bool is_color, OpenVDBFloatGrid *mask)
+ const char *name,
+ const float *data_x,
+ const float *data_y,
+ const float *data_z,
+ const int res[3],
+ float matrix[4][4],
+ short vec_type,
+ const float clipping,
+ const bool is_color,
+ OpenVDBFloatGrid *mask)
{
- Timer(__func__);
+ Timer(__func__);
- using openvdb::GridBase;
- using openvdb::FloatGrid;
- using openvdb::VecType;
+ using openvdb::FloatGrid;
+ using openvdb::GridBase;
+ using openvdb::VecType;
- FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
- GridBase *grid = internal::OpenVDB_export_vector_grid(
- writer,
- name,
- data_x,
- data_y,
- data_z,
- res,
- matrix,
- static_cast<VecType>(vec_type),
- is_color,
- clipping,
- mask_grid);
+ FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
+ GridBase *grid = internal::OpenVDB_export_vector_grid(writer,
+ name,
+ data_x,
+ data_y,
+ data_z,
+ res,
+ matrix,
+ static_cast<VecType>(vec_type),
+ is_color,
+ clipping,
+ mask_grid);
- return reinterpret_cast<OpenVDBVectorGrid *>(grid);
+ return reinterpret_cast<OpenVDBVectorGrid *>(grid);
}
-void OpenVDB_import_grid_fl(
- OpenVDBReader *reader,
- const char *name, float **data,
- const int res[3])
+void OpenVDB_import_grid_fl(OpenVDBReader *reader,
+ const char *name,
+ float **data,
+ const int res[3])
{
- Timer(__func__);
+ Timer(__func__);
- internal::OpenVDB_import_grid<openvdb::FloatGrid>(reader, name, data, res);
+ internal::OpenVDB_import_grid<openvdb::FloatGrid>(reader, name, data, res);
}
-void OpenVDB_import_grid_ch(
- OpenVDBReader *reader,
- const char *name, unsigned char **data,
- const int res[3])
+void OpenVDB_import_grid_ch(OpenVDBReader *reader,
+ const char *name,
+ unsigned char **data,
+ const int res[3])
{
- internal::OpenVDB_import_grid<openvdb::Int32Grid>(reader, name, data, res);
+ internal::OpenVDB_import_grid<openvdb::Int32Grid>(reader, name, data, res);
}
-void OpenVDB_import_grid_vec(
- struct OpenVDBReader *reader,
- const char *name,
- float **data_x, float **data_y, float **data_z,
- const int res[3])
+void OpenVDB_import_grid_vec(struct OpenVDBReader *reader,
+ const char *name,
+ float **data_x,
+ float **data_y,
+ float **data_z,
+ const int res[3])
{
- Timer(__func__);
+ Timer(__func__);
- internal::OpenVDB_import_grid_vector(reader, name, data_x, data_y, data_z, res);
+ internal::OpenVDB_import_grid_vector(reader, name, data_x, data_y, data_z, res);
}
OpenVDBWriter *OpenVDBWriter_create()
{
- return new OpenVDBWriter();
+ return new OpenVDBWriter();
}
void OpenVDBWriter_free(OpenVDBWriter *writer)
{
- delete writer;
+ delete writer;
}
void OpenVDBWriter_set_flags(OpenVDBWriter *writer, const int flag, const bool half)
{
- int compression_flags = openvdb::io::COMPRESS_ACTIVE_MASK;
+ int compression_flags = openvdb::io::COMPRESS_ACTIVE_MASK;
#ifdef WITH_OPENVDB_BLOSC
- if (flag == 0) {
- compression_flags |= openvdb::io::COMPRESS_BLOSC;
- }
- else
+ if (flag == 0) {
+ compression_flags |= openvdb::io::COMPRESS_BLOSC;
+ }
+ else
#endif
- if (flag == 1) {
- compression_flags |= openvdb::io::COMPRESS_ZIP;
- }
- else {
- compression_flags = openvdb::io::COMPRESS_NONE;
- }
+ if (flag == 1) {
+ compression_flags |= openvdb::io::COMPRESS_ZIP;
+ }
+ else {
+ compression_flags = openvdb::io::COMPRESS_NONE;
+ }
- writer->setFlags(compression_flags, half);
+ writer->setFlags(compression_flags, half);
}
void OpenVDBWriter_add_meta_fl(OpenVDBWriter *writer, const char *name, const float value)
{
- writer->insertFloatMeta(name, value);
+ writer->insertFloatMeta(name, value);
}
void OpenVDBWriter_add_meta_int(OpenVDBWriter *writer, const char *name, const int value)
{
- writer->insertIntMeta(name, value);
+ writer->insertIntMeta(name, value);
}
void OpenVDBWriter_add_meta_v3(OpenVDBWriter *writer, const char *name, const float value[3])
{
- writer->insertVec3sMeta(name, value);
+ writer->insertVec3sMeta(name, value);
}
void OpenVDBWriter_add_meta_v3_int(OpenVDBWriter *writer, const char *name, const int value[3])
{
- writer->insertVec3IMeta(name, value);
+ writer->insertVec3IMeta(name, value);
}
void OpenVDBWriter_add_meta_mat4(OpenVDBWriter *writer, const char *name, float value[4][4])
{
- writer->insertMat4sMeta(name, value);
+ writer->insertMat4sMeta(name, value);
}
void OpenVDBWriter_write(OpenVDBWriter *writer, const char *filename)
{
- writer->write(filename);
+ writer->write(filename);
}
OpenVDBReader *OpenVDBReader_create()
{
- return new OpenVDBReader();
+ return new OpenVDBReader();
}
void OpenVDBReader_free(OpenVDBReader *reader)
{
- delete reader;
+ delete reader;
}
void OpenVDBReader_open(OpenVDBReader *reader, const char *filename)
{
- reader->open(filename);
+ reader->open(filename);
}
void OpenVDBReader_get_meta_fl(OpenVDBReader *reader, const char *name, float *value)
{
- reader->floatMeta(name, *value);
+ reader->floatMeta(name, *value);
}
void OpenVDBReader_get_meta_int(OpenVDBReader *reader, const char *name, int *value)
{
- reader->intMeta(name, *value);
+ reader->intMeta(name, *value);
}
void OpenVDBReader_get_meta_v3(OpenVDBReader *reader, const char *name, float value[3])
{
- reader->vec3sMeta(name, value);
+ reader->vec3sMeta(name, value);
}
void OpenVDBReader_get_meta_v3_int(OpenVDBReader *reader, const char *name, int value[3])
{
- reader->vec3IMeta(name, value);
+ reader->vec3IMeta(name, value);
}
void OpenVDBReader_get_meta_mat4(OpenVDBReader *reader, const char *name, float value[4][4])
{
- reader->mat4sMeta(name, value);
+ reader->mat4sMeta(name, value);
}
-
OpenVDBLevelSet *OpenVDBLevelSet_create(bool initGrid, OpenVDBTransform *xform)
{
- OpenVDBLevelSet* level_set = new OpenVDBLevelSet();
- if (initGrid) {
- openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();
- grid->setGridClass(openvdb::GRID_LEVEL_SET);
- if (xform) {
- grid->setTransform(xform->OpenVDB_transform_get_transform());
- }
- level_set->OpenVDB_level_set_set_grid(grid);
- }
- return level_set;
+ OpenVDBLevelSet *level_set = new OpenVDBLevelSet();
+ if (initGrid) {
+ openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();
+ grid->setGridClass(openvdb::GRID_LEVEL_SET);
+ if (xform) {
+ grid->setTransform(xform->OpenVDB_transform_get_transform());
+ }
+ level_set->OpenVDB_level_set_set_grid(grid);
+ }
+ return level_set;
}
-OpenVDBTransform* OpenVDBTransform_create()
+OpenVDBTransform *OpenVDBTransform_create()
{
- return new OpenVDBTransform();
+ return new OpenVDBTransform();
}
void OpenVDBTransform_free(OpenVDBTransform *transform)
{
- delete transform;
+ delete transform;
}
void OpenVDBTransform_create_linear_transform(OpenVDBTransform *transform, double voxel_size)
{
- transform->OpenVDB_transform_create_linear_transform(voxel_size);
+ transform->OpenVDB_transform_create_linear_transform(voxel_size);
}
void OpenVDBLevelSet_free(OpenVDBLevelSet *level_set)
{
- delete level_set;
+ delete level_set;
}
-void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set, const float *vertices, const unsigned int *faces,
- const unsigned int totvertices, const unsigned int totfaces, OpenVDBTransform *xform)
+void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ OpenVDBTransform *xform)
{
- level_set->OpenVDB_mesh_to_level_set(vertices, faces, totvertices, totfaces, xform->OpenVDB_transform_get_transform());
+ level_set->OpenVDB_mesh_to_level_set(
+ vertices, faces, totvertices, totfaces, xform->OpenVDB_transform_get_transform());
}
-void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set, const float *vertices, const unsigned int *faces,
- const unsigned int totvertices, const unsigned int totfaces, struct OpenVDBTransform *transform)
+void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ struct OpenVDBTransform *transform)
{
- level_set->OpenVDB_mesh_to_level_set(vertices, faces, totvertices, totfaces, transform->OpenVDB_transform_get_transform());
+ level_set->OpenVDB_mesh_to_level_set(
+ vertices, faces, totvertices, totfaces, transform->OpenVDB_transform_get_transform());
}
-void OpenVDBLevelSet_volume_to_mesh(struct OpenVDBLevelSet *level_set, struct OpenVDBVolumeToMeshData *mesh,
- const double isovalue, const double adaptivity, const bool relax_disoriented_triangles)
+void OpenVDBLevelSet_volume_to_mesh(struct OpenVDBLevelSet *level_set,
+ struct OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles)
{
- level_set->OpenVDB_volume_to_mesh(mesh, isovalue, adaptivity, relax_disoriented_triangles);
+ level_set->OpenVDB_volume_to_mesh(mesh, isovalue, adaptivity, relax_disoriented_triangles);
}
-void OpenVDBLevelSet_filter(struct OpenVDBLevelSet *level_set, OpenVDBLevelSet_FilterType filter_type, int width,
- int iterations, OpenVDBLevelSet_FilterBias bias)
+void OpenVDBLevelSet_filter(struct OpenVDBLevelSet *level_set,
+ OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ OpenVDBLevelSet_FilterBias bias)
{
- level_set->OpenVDB_level_set_filter(filter_type, width, iterations, bias);
+ level_set->OpenVDB_level_set_filter(filter_type, width, iterations, bias);
}
-void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out, struct OpenVDBLevelSet *gridA, struct OpenVDBLevelSet *gridB,
- OpenVDBLevelSet_CSGOperation operation)
+void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out,
+ struct OpenVDBLevelSet *gridA,
+ struct OpenVDBLevelSet *gridB,
+ OpenVDBLevelSet_CSGOperation operation)
{
- openvdb::FloatGrid::Ptr grid = out->OpenVDB_CSG_operation(gridA->OpenVDB_level_set_get_grid(),
- gridB->OpenVDB_level_set_get_grid(),
- operation);
- out->OpenVDB_level_set_set_grid(grid);
+ openvdb::FloatGrid::Ptr grid = out->OpenVDB_CSG_operation(
+ gridA->OpenVDB_level_set_get_grid(), gridB->OpenVDB_level_set_get_grid(), operation);
+ out->OpenVDB_level_set_set_grid(grid);
}
-OpenVDBLevelSet* OpenVDBLevelSet_transform_and_resample(struct OpenVDBLevelSet *level_setA,
+OpenVDBLevelSet *OpenVDBLevelSet_transform_and_resample(struct OpenVDBLevelSet *level_setA,
struct OpenVDBLevelSet *level_setB,
- char sampler, float isolevel)
-{
- openvdb::FloatGrid::Ptr sourceGrid = level_setA->OpenVDB_level_set_get_grid();
- openvdb::FloatGrid::Ptr targetGrid = level_setB->OpenVDB_level_set_get_grid()->deepCopy();
-
- const openvdb::math::Transform
- &sourceXform = sourceGrid->transform(),
- &targetXform = targetGrid->transform();
-
- // Compute a source grid to target grid transform.
- // (For this example, we assume that both grids' transforms are linear,
- // so that they can be represented as 4 x 4 matrices.)
- openvdb::Mat4R xform =
- sourceXform.baseMap()->getAffineMap()->getMat4()*
- targetXform.baseMap()->getAffineMap()->getMat4().inverse();
-
- // Create the transformer.
- openvdb::tools::GridTransformer transformer(xform);
-
- switch (sampler) {
- case OPENVDB_LEVELSET_GRIDSAMPLER_POINT:
- // Resample using nearest-neighbor interpolation.
- transformer.transformGrid<openvdb::tools::PointSampler, openvdb::FloatGrid>(
- *sourceGrid, *targetGrid);
- // Prune the target tree for optimal sparsity.
- targetGrid->tree().prune();
- break;
-
- case OPENVDB_LEVELSET_GRIDSAMPLER_BOX:
- // Resample using trilinear interpolation.
- transformer.transformGrid<openvdb::tools::BoxSampler, openvdb::FloatGrid>(
- *sourceGrid, *targetGrid);
- // Prune the target tree for optimal sparsity.
- targetGrid->tree().prune();
- break;
-
- case OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC:
- // Resample using triquadratic interpolation.
- transformer.transformGrid<openvdb::tools::QuadraticSampler, openvdb::FloatGrid>(
- *sourceGrid, *targetGrid);
- // Prune the target tree for optimal sparsity.
- targetGrid->tree().prune();
- break;
-
- case OPENVDB_LEVELSET_GRIDSAMPLER_NONE:
- //targetGrid = sourceGrid->deepCopy();
- break;
- }
-
- targetGrid = openvdb::tools::levelSetRebuild(*targetGrid, isolevel, 1.0f);
- openvdb::tools::pruneLevelSet(targetGrid->tree());
-
- OpenVDBLevelSet* level_set = OpenVDBLevelSet_create(false, NULL);
- level_set->OpenVDB_level_set_set_grid(targetGrid);
-
- return level_set;
+ char sampler,
+ float isolevel)
+{
+ openvdb::FloatGrid::Ptr sourceGrid = level_setA->OpenVDB_level_set_get_grid();
+ openvdb::FloatGrid::Ptr targetGrid = level_setB->OpenVDB_level_set_get_grid()->deepCopy();
+
+ const openvdb::math::Transform &sourceXform = sourceGrid->transform(),
+ &targetXform = targetGrid->transform();
+
+ // Compute a source grid to target grid transform.
+ // (For this example, we assume that both grids' transforms are linear,
+ // so that they can be represented as 4 x 4 matrices.)
+ openvdb::Mat4R xform = sourceXform.baseMap()->getAffineMap()->getMat4() *
+ targetXform.baseMap()->getAffineMap()->getMat4().inverse();
+
+ // Create the transformer.
+ openvdb::tools::GridTransformer transformer(xform);
+
+ switch (sampler) {
+ case OPENVDB_LEVELSET_GRIDSAMPLER_POINT:
+ // Resample using nearest-neighbor interpolation.
+ transformer.transformGrid<openvdb::tools::PointSampler, openvdb::FloatGrid>(*sourceGrid,
+ *targetGrid);
+ // Prune the target tree for optimal sparsity.
+ targetGrid->tree().prune();
+ break;
+
+ case OPENVDB_LEVELSET_GRIDSAMPLER_BOX:
+ // Resample using trilinear interpolation.
+ transformer.transformGrid<openvdb::tools::BoxSampler, openvdb::FloatGrid>(*sourceGrid,
+ *targetGrid);
+ // Prune the target tree for optimal sparsity.
+ targetGrid->tree().prune();
+ break;
+
+ case OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC:
+ // Resample using triquadratic interpolation.
+ transformer.transformGrid<openvdb::tools::QuadraticSampler, openvdb::FloatGrid>(*sourceGrid,
+ *targetGrid);
+ // Prune the target tree for optimal sparsity.
+ targetGrid->tree().prune();
+ break;
+
+ case OPENVDB_LEVELSET_GRIDSAMPLER_NONE:
+ //targetGrid = sourceGrid->deepCopy();
+ break;
+ }
+
+ targetGrid = openvdb::tools::levelSetRebuild(*targetGrid, isolevel, 1.0f);
+ openvdb::tools::pruneLevelSet(targetGrid->tree());
+
+ OpenVDBLevelSet *level_set = OpenVDBLevelSet_create(false, NULL);
+ level_set->OpenVDB_level_set_set_grid(targetGrid);
+
+ return level_set;
}
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index 3e96d072e7a..4ebf9d85461 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -26,37 +26,36 @@ extern "C" {
/* Level Set Filters */
typedef enum OpenVDBLevelSet_FilterType {
- OPENVDB_LEVELSET_FILTER_NONE = 0,
- OPENVDB_LEVELSET_FILTER_GAUSSIAN = 1,
- OPENVDB_LEVELSET_FILTER_MEAN = 2,
- OPENVDB_LEVELSET_FILTER_MEDIAN = 3,
- OPENVDB_LEVELSET_FILTER_MEAN_CURVATURE = 4,
- OPENVDB_LEVELSET_FILTER_LAPLACIAN = 5,
- OPENVDB_LEVELSET_FILTER_DILATE = 6,
- OPENVDB_LEVELSET_FILTER_ERODE = 7,
+ OPENVDB_LEVELSET_FILTER_NONE = 0,
+ OPENVDB_LEVELSET_FILTER_GAUSSIAN = 1,
+ OPENVDB_LEVELSET_FILTER_MEAN = 2,
+ OPENVDB_LEVELSET_FILTER_MEDIAN = 3,
+ OPENVDB_LEVELSET_FILTER_MEAN_CURVATURE = 4,
+ OPENVDB_LEVELSET_FILTER_LAPLACIAN = 5,
+ OPENVDB_LEVELSET_FILTER_DILATE = 6,
+ OPENVDB_LEVELSET_FILTER_ERODE = 7,
} OpenVDBLevelSet_FilterType;
-typedef enum OpenVDBLevelSet_FilterBias{
- OPENVDB_LEVELSET_FIRST_BIAS = 0,
- OPENVDB_LEVELSET_SECOND_BIAS,
- OPENVDB_LEVELSET_THIRD_BIAS,
- OPENVDB_LEVELSET_WENO5_BIAS,
- OPENVDB_LEVELSET_HJWENO5_BIAS,
-}OpenVDBLevelSet_FilterBias;
-
+typedef enum OpenVDBLevelSet_FilterBias {
+ OPENVDB_LEVELSET_FIRST_BIAS = 0,
+ OPENVDB_LEVELSET_SECOND_BIAS,
+ OPENVDB_LEVELSET_THIRD_BIAS,
+ OPENVDB_LEVELSET_WENO5_BIAS,
+ OPENVDB_LEVELSET_HJWENO5_BIAS,
+} OpenVDBLevelSet_FilterBias;
/* Level Set CSG Operations */
typedef enum OpenVDBLevelSet_CSGOperation {
- OPENVDB_LEVELSET_CSG_UNION = 0,
- OPENVDB_LEVELSET_CSG_DIFFERENCE = 1,
- OPENVDB_LEVELSET_CSG_INTERSECTION = 2,
+ OPENVDB_LEVELSET_CSG_UNION = 0,
+ OPENVDB_LEVELSET_CSG_DIFFERENCE = 1,
+ OPENVDB_LEVELSET_CSG_INTERSECTION = 2,
} OpenVDBLevelSet_CSGOperation;
typedef enum OpenVDBLevelSet_GridSampler {
- OPENVDB_LEVELSET_GRIDSAMPLER_NONE = 0,
- OPENVDB_LEVELSET_GRIDSAMPLER_POINT = 1,
- OPENVDB_LEVELSET_GRIDSAMPLER_BOX = 2,
- OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC = 3,
+ OPENVDB_LEVELSET_GRIDSAMPLER_NONE = 0,
+ OPENVDB_LEVELSET_GRIDSAMPLER_POINT = 1,
+ OPENVDB_LEVELSET_GRIDSAMPLER_BOX = 2,
+ OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC = 3,
} OpenVDBLevelSet_Gridsampler;
struct OpenVDBReader;
@@ -67,90 +66,106 @@ struct OpenVDBFloatGrid;
struct OpenVDBIntGrid;
struct OpenVDBVectorGrid;
struct OpenVDBVolumeToMeshData {
- int tottriangles;
- int totquads;
- int totvertices;
+ int tottriangles;
+ int totquads;
+ int totvertices;
- float *vertices;
- unsigned int *quads;
- unsigned int *triangles;
+ float *vertices;
+ unsigned int *quads;
+ unsigned int *triangles;
};
struct OpenVDBRemeshData {
- float *verts;
- unsigned int *faces;
- int totfaces;
- int totverts;
-
- float *out_verts;
- unsigned int *out_faces;
- unsigned int *out_tris;
- int out_totverts;
- int out_totfaces;
- int out_tottris;
- int filter_type;
- int filter_bias;
- int filter_width; /*parameter for gaussian, median, mean*/
-
- float voxel_size;
- float isovalue;
- float adaptivity;
- int relax_disoriented_triangles;
+ float *verts;
+ unsigned int *faces;
+ int totfaces;
+ int totverts;
+
+ float *out_verts;
+ unsigned int *out_faces;
+ unsigned int *out_tris;
+ int out_totverts;
+ int out_totfaces;
+ int out_tottris;
+ int filter_type;
+ int filter_bias;
+ int filter_width; /*parameter for gaussian, median, mean*/
+
+ float voxel_size;
+ float isovalue;
+ float adaptivity;
+ int relax_disoriented_triangles;
};
-
int OpenVDB_getVersionHex(void);
enum {
- VEC_INVARIANT = 0,
- VEC_COVARIANT = 1,
- VEC_COVARIANT_NORMALIZE = 2,
- VEC_CONTRAVARIANT_RELATIVE = 3,
- VEC_CONTRAVARIANT_ABSOLUTE = 4,
+ VEC_INVARIANT = 0,
+ VEC_COVARIANT = 1,
+ VEC_COVARIANT_NORMALIZE = 2,
+ VEC_CONTRAVARIANT_RELATIVE = 3,
+ VEC_CONTRAVARIANT_ABSOLUTE = 4,
};
-struct OpenVDBFloatGrid *OpenVDB_export_grid_fl(
- struct OpenVDBWriter *writer,
- const char *name, float *data,
- const int res[3], float matrix[4][4], const float clipping,
- struct OpenVDBFloatGrid *mask);
+struct OpenVDBFloatGrid *OpenVDB_export_grid_fl(struct OpenVDBWriter *writer,
+ const char *name,
+ float *data,
+ const int res[3],
+ float matrix[4][4],
+ const float clipping,
+ struct OpenVDBFloatGrid *mask);
struct OpenVDBIntGrid *OpenVDB_export_grid_ch(struct OpenVDBWriter *writer,
- const char *name, unsigned char *data,
- const int res[3], float matrix[4][4], const float clipping,
- struct OpenVDBFloatGrid *mask);
+ const char *name,
+ unsigned char *data,
+ const int res[3],
+ float matrix[4][4],
+ const float clipping,
+ struct OpenVDBFloatGrid *mask);
struct OpenVDBVectorGrid *OpenVDB_export_grid_vec(struct OpenVDBWriter *writer,
- const char *name,
- const float *data_x, const float *data_y, const float *data_z,
- const int res[3], float matrix[4][4], short vec_type, const float clipping,
- const bool is_color,
- struct OpenVDBFloatGrid *mask);
-
-void OpenVDB_import_grid_fl(
- struct OpenVDBReader *reader,
- const char *name, float **data,
- const int res[3]);
-
-void OpenVDB_import_grid_ch(
- struct OpenVDBReader *reader,
- const char *name, unsigned char **data,
- const int res[3]);
-
-void OpenVDB_import_grid_vec(
- struct OpenVDBReader *reader,
- const char *name,
- float **data_x, float **data_y, float **data_z,
- const int res[3]);
+ const char *name,
+ const float *data_x,
+ const float *data_y,
+ const float *data_z,
+ const int res[3],
+ float matrix[4][4],
+ short vec_type,
+ const float clipping,
+ const bool is_color,
+ struct OpenVDBFloatGrid *mask);
+
+void OpenVDB_import_grid_fl(struct OpenVDBReader *reader,
+ const char *name,
+ float **data,
+ const int res[3]);
+
+void OpenVDB_import_grid_ch(struct OpenVDBReader *reader,
+ const char *name,
+ unsigned char **data,
+ const int res[3]);
+
+void OpenVDB_import_grid_vec(struct OpenVDBReader *reader,
+ const char *name,
+ float **data_x,
+ float **data_y,
+ float **data_z,
+ const int res[3]);
struct OpenVDBWriter *OpenVDBWriter_create(void);
void OpenVDBWriter_free(struct OpenVDBWriter *writer);
void OpenVDBWriter_set_flags(struct OpenVDBWriter *writer, const int flag, const bool half);
void OpenVDBWriter_add_meta_fl(struct OpenVDBWriter *writer, const char *name, const float value);
void OpenVDBWriter_add_meta_int(struct OpenVDBWriter *writer, const char *name, const int value);
-void OpenVDBWriter_add_meta_v3(struct OpenVDBWriter *writer, const char *name, const float value[3]);
-void OpenVDBWriter_add_meta_v3_int(struct OpenVDBWriter *writer, const char *name, const int value[3]);
-void OpenVDBWriter_add_meta_mat4(struct OpenVDBWriter *writer, const char *name, float value[4][4]);
+void OpenVDBWriter_add_meta_v3(struct OpenVDBWriter *writer,
+ const char *name,
+ const float value[3]);
+void OpenVDBWriter_add_meta_v3_int(struct OpenVDBWriter *writer,
+ const char *name,
+ const int value[3]);
+void OpenVDBWriter_add_meta_mat4(struct OpenVDBWriter *writer,
+ const char *name,
+ float value[4][4]);
void OpenVDBWriter_write(struct OpenVDBWriter *writer, const char *filename);
struct OpenVDBReader *OpenVDBReader_create(void);
@@ -160,30 +175,48 @@ void OpenVDBReader_get_meta_fl(struct OpenVDBReader *reader, const char *name, f
void OpenVDBReader_get_meta_int(struct OpenVDBReader *reader, const char *name, int *value);
void OpenVDBReader_get_meta_v3(struct OpenVDBReader *reader, const char *name, float value[3]);
void OpenVDBReader_get_meta_v3_int(struct OpenVDBReader *reader, const char *name, int value[3]);
-void OpenVDBReader_get_meta_mat4(struct OpenVDBReader *reader, const char *name, float value[4][4]);
+void OpenVDBReader_get_meta_mat4(struct OpenVDBReader *reader,
+ const char *name,
+ float value[4][4]);
struct OpenVDBTransform *OpenVDBTransform_create(void);
void OpenVDBTransform_free(struct OpenVDBTransform *transform);
-void OpenVDBTransform_create_linear_transform(struct OpenVDBTransform *transform, double voxel_size);
+void OpenVDBTransform_create_linear_transform(struct OpenVDBTransform *transform,
+ double voxel_size);
struct OpenVDBLevelSet *OpenVDBLevelSet_create(bool initGrid, struct OpenVDBTransform *xform);
void OpenVDBLevelSet_free(struct OpenVDBLevelSet *level_set);
-void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set, const float *vertices, const unsigned int *faces,
- const unsigned int totvertices, const unsigned int totfaces,
+void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
struct OpenVDBTransform *xform);
-void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set, const float *vertices, const unsigned int *faces,
- const unsigned int totvertices, const unsigned int totfaces, struct OpenVDBTransform *transform);
-void OpenVDBLevelSet_volume_to_mesh(struct OpenVDBLevelSet *level_set, struct OpenVDBVolumeToMeshData *mesh,
- const double isovalue, const double adaptivity, const bool relax_disoriented_triangles);
-void OpenVDBLevelSet_filter(struct OpenVDBLevelSet *level_set, OpenVDBLevelSet_FilterType filter_type, int width,
- int iterations, OpenVDBLevelSet_FilterBias bias);
-void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out, struct OpenVDBLevelSet *gridA, struct OpenVDBLevelSet *gridB,
- OpenVDBLevelSet_CSGOperation operation);
+void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ struct OpenVDBTransform *transform);
+void OpenVDBLevelSet_volume_to_mesh(struct OpenVDBLevelSet *level_set,
+ struct OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles);
+void OpenVDBLevelSet_filter(struct OpenVDBLevelSet *level_set,
+ OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ OpenVDBLevelSet_FilterBias bias);
+void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out,
+ struct OpenVDBLevelSet *gridA,
+ struct OpenVDBLevelSet *gridB,
+ OpenVDBLevelSet_CSGOperation operation);
struct OpenVDBLevelSet *OpenVDBLevelSet_transform_and_resample(struct OpenVDBLevelSet *level_setA,
- struct OpenVDBLevelSet *level_setB,
- char sampler, float isolevel);
-
+ struct OpenVDBLevelSet *level_setB,
+ char sampler,
+ float isolevel);
#ifdef __cplusplus
}
diff --git a/intern/openvdb/openvdb_util.cc b/intern/openvdb/openvdb_util.cc
index 5d8dcbf41f9..a221a537851 100644
--- a/intern/openvdb/openvdb_util.cc
+++ b/intern/openvdb/openvdb_util.cc
@@ -21,12 +21,11 @@
#include <cstdio>
-ScopeTimer::ScopeTimer(const std::string &message)
- : m_message(message)
- , m_timer()
-{}
+ScopeTimer::ScopeTimer(const std::string &message) : m_message(message), m_timer()
+{
+}
ScopeTimer::~ScopeTimer()
{
- std::printf("%s: %fms\n", m_message.c_str(), m_timer.delta());
+ std::printf("%s: %fms\n", m_message.c_str(), m_timer.delta());
}
diff --git a/intern/openvdb/openvdb_util.h b/intern/openvdb/openvdb_util.h
index 13c2ac610cb..7a19d588068 100644
--- a/intern/openvdb/openvdb_util.h
+++ b/intern/openvdb/openvdb_util.h
@@ -24,28 +24,28 @@
#include <openvdb/util/CpuTimer.h>
#define CATCH_KEYERROR \
- catch (const openvdb::KeyError &e) { \
- std::cerr << e.what() << '\n'; \
- }
+ catch (const openvdb::KeyError &e) \
+ { \
+ std::cerr << e.what() << '\n'; \
+ }
//#define DEBUG_TIME
/* A utility class which prints the time elapsed during its lifetime, useful for
* e.g. timing the overall execution time of a function */
class ScopeTimer {
- std::string m_message;
- openvdb::util::CpuTimer m_timer;
+ std::string m_message;
+ openvdb::util::CpuTimer m_timer;
-public:
- ScopeTimer(const std::string &message);
- ~ScopeTimer();
+ public:
+ ScopeTimer(const std::string &message);
+ ~ScopeTimer();
};
#ifdef DEBUG_TIME
-# define Timer(x) \
- ScopeTimer prof(x);
+# define Timer(x) ScopeTimer prof(x);
#else
-# define Timer(x)
+# define Timer(x)
#endif
#endif /* __OPENVDB_UTIL_H__ */