[Bf-blender-cvs] [623b8bc] openvdb: Exporter: clip grids based on the density field to save on file size.

Kévin Dietrich noreply at git.blender.org
Fri Jun 5 14:08:57 CEST 2015


Commit: 623b8bcc9b6237a51e817daca9a15727d351b183
Author: Kévin Dietrich
Date:   Fri Jun 5 13:47:59 2015 +0200
Branches: openvdb
https://developer.blender.org/rB623b8bcc9b6237a51e817daca9a15727d351b183

Exporter: clip grids based on the density field to save on file size.

Patch by @lukastoenne.

===================================================================

M	intern/openvdb/intern/openvdb_dense_convert.cpp
M	intern/openvdb/intern/openvdb_dense_convert.h
M	intern/openvdb/openvdb_capi.cpp
M	intern/openvdb/openvdb_capi.h
M	source/blender/blenkernel/intern/smoke.c

===================================================================

diff --git a/intern/openvdb/intern/openvdb_dense_convert.cpp b/intern/openvdb/intern/openvdb_dense_convert.cpp
index e7f61df..340629f 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.cpp
+++ b/intern/openvdb/intern/openvdb_dense_convert.cpp
@@ -62,12 +62,14 @@ public:
 	}
 };
 
-void OpenVDB_export_vector_grid(OpenVDBWriter *writer,
-                                const std::string &name,
-                                const float *data_x, const float *data_y, const float *data_z,
-                                const int res[3],
-                                float fluid_mat[4][4],
-                                VecType vec_type, const bool is_color)
+GridBase *OpenVDB_export_vector_grid(OpenVDBWriter *writer,
+                                     const std::string &name,
+                                     const float *data_x, const float *data_y, const float *data_z,
+                                     const int res[3],
+                                     float fluid_mat[4][4],
+                                     VecType vec_type,
+                                     const bool is_color,
+                                     const FloatGrid *mask)
 {
 
 	math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 1));
@@ -105,6 +107,10 @@ void OpenVDB_export_vector_grid(OpenVDBWriter *writer,
 	MergeScalarGrids op(&(grid[0]->tree()), &(grid[1]->tree()), &(grid[2]->tree()));
 	tools::foreach(vecgrid->beginValueOn(), op, true, false);
 
+	if (mask) {
+		vecgrid = tools::clip(*vecgrid, *mask);
+	}
+
 	vecgrid->setName(name);
 	vecgrid->setTransform(transform);
 	vecgrid->setIsInWorldSpace(false);
@@ -112,6 +118,8 @@ void OpenVDB_export_vector_grid(OpenVDBWriter *writer,
 	vecgrid->insertMeta("is_color", BoolMetadata(is_color));
 
 	writer->insert(vecgrid);
+
+	return vecgrid.get();
 }
 
 class SplitVectorGrid {
diff --git a/intern/openvdb/intern/openvdb_dense_convert.h b/intern/openvdb/intern/openvdb_dense_convert.h
index 019c3f1..2cf3090 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.h
+++ b/intern/openvdb/intern/openvdb_dense_convert.h
@@ -28,7 +28,9 @@
 #ifndef __OPENVDB_DENSE_CONVERT_H__
 #define __OPENVDB_DENSE_CONVERT_H__
 
+#include <openvdb/openvdb.h>
 #include <openvdb/tools/Dense.h>
+#include <openvdb/tools/Clip.h>
 
 #include "openvdb_reader.h"
 #include "openvdb_writer.h"
@@ -36,11 +38,12 @@
 namespace internal {
 
 template <typename GridType, typename T>
-void OpenVDB_export_grid(OpenVDBWriter *writer,
-                         const std::string &name,
-                         const T *data,
-                         const int res[3],
-                         float fluid_mat[4][4])
+GridType *OpenVDB_export_grid(OpenVDBWriter *writer,
+                              const std::string &name,
+                              const T *data,
+                              const int res[3],
+                              float fluid_mat[4][4],
+                              const openvdb::FloatGrid *mask)
 {
 	using namespace openvdb;
 
@@ -59,11 +62,17 @@ void OpenVDB_export_grid(OpenVDBWriter *writer,
 	tools::Dense<const T, openvdb::tools::LayoutXYZ> dense_grid(bbox, data);
 	tools::copyFromDense(dense_grid, grid->tree(), 1e-3f, true);
 
+	if (mask) {
+		grid = tools::clip(*grid, *mask);
+	}
+
 	grid->setName(name);
 	grid->setTransform(transform);
 	grid->setIsInWorldSpace(false);
 
 	writer->insert(grid);
+
+	return grid.get();
 }
 
 template <typename GridType, typename T>
@@ -97,12 +106,14 @@ void OpenVDB_import_grid(OpenVDBReader *reader,
 #endif
 }
 
-void OpenVDB_export_vector_grid(OpenVDBWriter *writer,
-                                const std::string &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);
+openvdb::GridBase *OpenVDB_export_vector_grid(OpenVDBWriter *writer,
+                                              const std::string &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 openvdb::FloatGrid *mask);
 
 
 void OpenVDB_import_grid_vector(OpenVDBReader *reader,
diff --git a/intern/openvdb/openvdb_capi.cpp b/intern/openvdb/openvdb_capi.cpp
index b69b481..3e30c31 100644
--- a/intern/openvdb/openvdb_capi.cpp
+++ b/intern/openvdb/openvdb_capi.cpp
@@ -29,6 +29,10 @@
 
 using namespace openvdb;
 
+struct OpenVDBFloatGrid { int unused; };
+struct OpenVDBIntGrid { int unused; };
+struct OpenVDBVectorGrid { int unused; };
+
 int OpenVDB_getVersionHex()
 {
     return OPENVDB_LIBRARY_VERSION;
@@ -85,29 +89,38 @@ void OpenVDB_update_fluid_transform(const char *filename,
 	}
 }
 
-void OpenVDB_export_grid_fl(OpenVDBWriter *writer,
-                            const char *name, float *data,
-                            const int res[3], float matrix[4][4])
+OpenVDBFloatGrid *OpenVDB_export_grid_fl(OpenVDBWriter *writer,
+                                         const char *name, float *data,
+                                         const int res[3], float matrix[4][4],
+                                         OpenVDBFloatGrid *mask)
 {
-	internal::OpenVDB_export_grid<FloatGrid>(writer, name, data, res, matrix);
+	OpenVDBFloatGrid *grid =
+	        (OpenVDBFloatGrid *)internal::OpenVDB_export_grid<FloatGrid>(writer, name, data, res, matrix, (FloatGrid *)mask);
+	return grid;
 }
 
-void OpenVDB_export_grid_ch(OpenVDBWriter *writer,
-                            const char *name, unsigned char *data,
-                            const int res[3], float matrix[4][4])
+OpenVDBIntGrid *OpenVDB_export_grid_ch(OpenVDBWriter *writer,
+                                       const char *name, unsigned char *data,
+                                       const int res[3], float matrix[4][4],
+                                       OpenVDBFloatGrid *mask)
 {
-	internal::OpenVDB_export_grid<Int32Grid>(writer, name, data, res, matrix);
+	OpenVDBIntGrid *grid =
+	        (OpenVDBIntGrid *)internal::OpenVDB_export_grid<Int32Grid>(writer, name, data, res, matrix, (FloatGrid *)mask);
+	return grid;
 }
 
-void 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 bool is_color)
+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 bool is_color, OpenVDBFloatGrid *mask)
 {
-	internal::OpenVDB_export_vector_grid(writer, name,
+	OpenVDBVectorGrid *grid =
+	(OpenVDBVectorGrid *)internal::OpenVDB_export_vector_grid(writer, name,
 	                                     data_x, data_y, data_z, res, matrix,
 	                                     static_cast<openvdb::VecType>(vec_type),
-	                                     is_color);
+	                                     is_color, (FloatGrid *)mask);
+	return grid;
 }
 
 void OpenVDB_import_grid_fl(OpenVDBReader *reader,
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index 8424275..ef5ed98 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -34,6 +34,9 @@ struct bNode;
 struct bNodeTree;
 struct OpenVDBReader;
 struct OpenVDBWriter;
+struct OpenVDBFloatGrid;
+struct OpenVDBIntGrid;
+struct OpenVDBVectorGrid;
 
 int OpenVDB_getVersionHex(void);
 
@@ -66,18 +69,22 @@ void OpenVDB_update_fluid_transform(const char *filename,
                                     float matrix[4][4],
                                     float matrix_high[4][4]);
 
-void OpenVDB_export_grid_fl(struct OpenVDBWriter *writer,
-                            const char *name, float *data,
-                            const int res[3], float matrix[4][4]);
-
-void OpenVDB_export_grid_ch(struct OpenVDBWriter *writer,
-                            const char *name, unsigned char *data,
-                            const int res[3], float matrix[4][4]);
-
-void 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 bool is_color);
+struct OpenVDBFloatGrid *OpenVDB_export_grid_fl(struct OpenVDBWriter *writer,
+                                                const char *name, float *data,
+                                                const int res[3], float matrix[4][4],
+                                                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],
+                                              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 bool is_color,
+                       

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list