Commit: cd301995cc18b86b6464b17b63b023b94d144d08
Author: Kévin Dietrich
Date:   Fri May 22 05:27:16 2015 +0200
Branches: openvdb
https://developer.blender.org/rBcd301995cc18b86b6464b17b63b023b94d144d08

A new function to split a vector grid into three scalar grids.

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

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

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

diff --git a/source/blender/blenkernel/intern/smoke.c 
b/source/blender/blenkernel/intern/smoke.c
index a52c276..9eb183e 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -3233,14 +3233,16 @@ static void OpenVDB_import_smoke(SmokeDomainSettings 
*sds, struct OpenVDBReader
                }
 
                if (fluid_fields & SM_ACTIVE_COLORS) {
-                       OpenVDB_import_grid_fl(reader, "red", &r, sds->res);
-                       OpenVDB_import_grid_fl(reader, "green", &g, sds->res);
-                       OpenVDB_import_grid_fl(reader, "blue", &b, sds->res);
+//                     OpenVDB_import_grid_fl(reader, "red", &r, sds->res);
+//                     OpenVDB_import_grid_fl(reader, "green", &g, sds->res);
+//                     OpenVDB_import_grid_fl(reader, "blue", &b, sds->res);
+                       OpenVDB_import_grid_vec(reader, "color", &r, &g, &b, 
sds->res);
                }
 
-               OpenVDB_import_grid_fl(reader, "vx", &vx, sds->res);
-               OpenVDB_import_grid_fl(reader, "vy", &vy, sds->res);
-               OpenVDB_import_grid_fl(reader, "vz", &vz, sds->res);
+//             OpenVDB_import_grid_fl(reader, "vx", &vx, sds->res);
+//             OpenVDB_import_grid_fl(reader, "vy", &vy, sds->res);
+//             OpenVDB_import_grid_fl(reader, "vz", &vz, sds->res);
+               OpenVDB_import_grid_vec(reader, "velocity", &vx, &vy, &vz, 
sds->res);
 
                OpenVDB_import_grid_ch(reader, "obstacles", &obstacles, 
sds->res);
        }
@@ -3250,7 +3252,7 @@ static void OpenVDB_import_smoke(SmokeDomainSettings 
*sds, struct OpenVDBReader
 
                smoke_turbulence_export(sds->wt, &dens, &react, &flame, &fuel, 
&r, &g, &b, &tcu, &tcv, &tcw);
 
-               OpenVDB_import_grid_fl(reader, "density", &dens, sds->res);
+               OpenVDB_import_grid_fl(reader, "density high", &dens, 
sds->res_wt);
 
                if (fluid_fields & SM_ACTIVE_FIRE) {
                        OpenVDB_import_grid_fl(reader, "flame high", &flame, 
sds->res_wt);
@@ -3259,14 +3261,16 @@ static void OpenVDB_import_smoke(SmokeDomainSettings 
*sds, struct OpenVDBReader
                }
 
                if (fluid_fields & SM_ACTIVE_COLORS) {
-                       OpenVDB_import_grid_fl(reader, "red high", &r, 
sds->res_wt);
-                       OpenVDB_import_grid_fl(reader, "green high", &g, 
sds->res_wt);
-                       OpenVDB_import_grid_fl(reader, "blue high", &b, 
sds->res_wt);
+//                     OpenVDB_import_grid_fl(reader, "red high", &r, 
sds->res_wt);
+//                     OpenVDB_import_grid_fl(reader, "green high", &g, 
sds->res_wt);
+//                     OpenVDB_import_grid_fl(reader, "blue high", &b, 
sds->res_wt);
+                       OpenVDB_import_grid_vec(reader, "color high", &r, &g, 
&b, sds->res_wt);
                }
 
-               OpenVDB_import_grid_fl(reader, "tcu", &tcu, sds->res);
-               OpenVDB_import_grid_fl(reader, "tcv", &tcv, sds->res);
-               OpenVDB_import_grid_fl(reader, "tcw", &tcw, sds->res);
+//             OpenVDB_import_grid_fl(reader, "tcu", &tcu, sds->res);
+//             OpenVDB_import_grid_fl(reader, "tcv", &tcv, sds->res);
+//             OpenVDB_import_grid_fl(reader, "tcw", &tcw, sds->res);
+               OpenVDB_import_grid_vec(reader, "tex_co", &tcu, &tcv, &tcw, 
sds->res);
        }
 }
 
diff --git a/source/blender/openvdb/intern/openvdb_smoke_export.cpp 
b/source/blender/openvdb/intern/openvdb_smoke_export.cpp
index cdb564c..38ef7af 100644
--- a/source/blender/openvdb/intern/openvdb_smoke_export.cpp
+++ b/source/blender/openvdb/intern/openvdb_smoke_export.cpp
@@ -116,28 +116,83 @@ void OpenVDB_export_vector_grid(OpenVDBWriter *writer,
        writer->insert(vecgrid);
 }
 
-static void OpenVDB_import_grid_vector(GridBase::Ptr &grid,
-                                       float *data_x, float *data_y, float 
*data_z,
-                                       const math::CoordBBox &bbox)
-{
-       math::Coord res = bbox.max();
-       Vec3SGrid::Ptr vgrid = gridPtrCast<Vec3SGrid>(grid);
-       Vec3SGrid::Accessor acc = vgrid->getAccessor();
-
-       int index = 0;
-       for (int z = 0; z <= res.z(); ++z) {
-               for (int y = 0; y <= res.y(); ++y) {
-                       for (int x = 0; x <= res.x(); ++x, ++index) {
-                               math::Coord xyz(x, y, z);
-                               Vec3s val = acc.getValue(xyz);
-                               data_x[index] = val.x();
-                               data_y[index] = val.y();
-                               data_z[index] = val.z();
-                       }
-               }
+class SplitVectorGrid {
+       FloatGrid::Ptr m_grid_x, m_grid_y, m_grid_z;
+
+public:
+       SplitVectorGrid()
+       {}
+
+       void operator()(const Vec3SGrid::Ptr &vecgrid)
+       {
+               Vec3s bg = vecgrid->background();
+               m_grid_x = FloatGrid::create(bg.x());
+               m_grid_y = FloatGrid::create(bg.y());
+               m_grid_z = FloatGrid::create(bg.z());
+
+               if (math::Transform::Ptr xform = vecgrid->transform().copy()) {
+            m_grid_x->setTransform(xform);
+            m_grid_y->setTransform(xform);
+            m_grid_z->setTransform(xform);
+        }
+
+               FloatGrid::Accessor acc_x = m_grid_x->getAccessor(),
+                                   acc_y = m_grid_y->getAccessor(),
+                                   acc_z = m_grid_z->getAccessor();
+
+               CoordBBox bbox;
+               for (Vec3SGrid::ValueOnCIter it = vecgrid->cbeginValueOn(); it; 
++it) {
+            if (!it.getBoundingBox(bbox)) continue;
+
+            const Vec3s &val = it.getValue();
+
+            if (it.isTileValue()) {
+                m_grid_x->fill(bbox, val.x());
+                m_grid_y->fill(bbox, val.y());
+                m_grid_z->fill(bbox, val.z());
+            }
+                       else {
+                acc_x.setValueOn(bbox.min(), val.x());
+                acc_y.setValueOn(bbox.min(), val.y());
+                acc_z.setValueOn(bbox.min(), val.z());
+            }
+        }
        }
-}
 
+       const FloatGrid::Ptr &grid_x() { return m_grid_x; }
+    const FloatGrid::Ptr &grid_y() { return m_grid_y; }
+    const FloatGrid::Ptr &grid_z() { return m_grid_z; }
+};
+
+void OpenVDB_import_grid_vector(OpenVDBReader *reader,
+                                const std::string &name,
+                                float **data_x, float **data_y, float **data_z,
+                                const int res[3])
+{
+       Vec3SGrid::Ptr vgrid = gridPtrCast<Vec3SGrid>(reader->getGrid(name));
+
+       SplitVectorGrid vector_split;
+       vector_split(vgrid);
+
+       FloatGrid::Ptr grid[3];
+
+       math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 
1));
+
+       grid[0] = vector_split.grid_x();
+       tools::Dense<float, tools::LayoutXYZ> dense_grid_x(bbox);
+       tools::copyToDense(*grid[0], dense_grid_x);
+       *data_x = dense_grid_x.data();
+
+       grid[1] = vector_split.grid_y();
+       tools::Dense<float, tools::LayoutXYZ> dense_grid_y(bbox);
+       tools::copyToDense(*grid[1], dense_grid_y);
+       *data_y = dense_grid_y.data();
+
+       grid[2] = vector_split.grid_z();
+       tools::Dense<float, tools::LayoutXYZ> dense_grid_z(bbox);
+       tools::copyToDense(*grid[2], dense_grid_z);
+       *data_z = dense_grid_z.data();
+}
 
 void OpenVDB_update_fluid_transform(const char *filename, FluidDomainDescr 
descr)
 {
diff --git a/source/blender/openvdb/openvdb_capi.cpp 
b/source/blender/openvdb/openvdb_capi.cpp
index e487765..d919668 100644
--- a/source/blender/openvdb/openvdb_capi.cpp
+++ b/source/blender/openvdb/openvdb_capi.cpp
@@ -129,6 +129,14 @@ void OpenVDB_import_grid_ch(OpenVDBReader *reader,
        internal::OpenVDB_import_grid<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])
+{
+       internal::OpenVDB_import_grid_vector(reader, name, data_x, data_y, 
data_z, res);
+}
+
 OpenVDBWriter *OpenVDBWriter_create()
 {
        return new OpenVDBWriter();
diff --git a/source/blender/openvdb/openvdb_capi.h 
b/source/blender/openvdb/openvdb_capi.h
index 10992aa..812b3f9 100644
--- a/source/blender/openvdb/openvdb_capi.h
+++ b/source/blender/openvdb/openvdb_capi.h
@@ -96,6 +96,11 @@ 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_compression(struct OpenVDBWriter *writer, const int 
flags);
diff --git a/source/blender/openvdb/openvdb_intern.h 
b/source/blender/openvdb/openvdb_intern.h
index 62d556d..6c17145 100644
--- a/source/blender/openvdb/openvdb_intern.h
+++ b/source/blender/openvdb/openvdb_intern.h
@@ -105,6 +105,12 @@ void OpenVDB_export_vector_grid(OpenVDBWriter *writer,
                                 const int res[3],
                                 float fluid_mat[4][4]);
 
+
+void OpenVDB_import_grid_vector(OpenVDBReader *reader,
+                                const std::string &name,
+                                float **data_x, float **data_y, float **data_z,
+                                const int res[3]);
+
 void OpenVDB_update_fluid_transform(const char *filename, FluidDomainDescr 
descr);
 
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to