[Bf-blender-cvs] [6364cee] openvdb: Cycles: add support for sampling staggered vector grids.
Kévin Dietrich
noreply at git.blender.org
Sat Jun 13 03:45:56 CEST 2015
Commit: 6364ceea301cad8e629c77564865390f9f75ccf7
Author: Kévin Dietrich
Date: Sat Jun 13 03:07:05 2015 +0200
Branches: openvdb
https://developer.blender.org/rB6364ceea301cad8e629c77564865390f9f75ccf7
Cycles: add support for sampling staggered vector grids.
===================================================================
M intern/cycles/util/util_volume.h
===================================================================
diff --git a/intern/cycles/util/util_volume.h b/intern/cycles/util/util_volume.h
index 148ac02..94a6b2a 100644
--- a/intern/cycles/util/util_volume.h
+++ b/intern/cycles/util/util_volume.h
@@ -230,11 +230,12 @@ public:
}
};
-/* Same as above, except for vector grids */
-/* TODO(kevin): staggered velocity grid sampling */
+/* Same as above, except for vector grids, including staggered grids */
class vdb_float3_volume : public float3_volume {
typedef openvdb::tools::GridSampler<openvdb::Vec3SGrid::ConstAccessor, openvdb::tools::PointSampler> point_sampler_t;
typedef openvdb::tools::GridSampler<openvdb::Vec3SGrid::ConstAccessor, openvdb::tools::BoxSampler> box_sampler_t;
+ typedef openvdb::tools::GridSampler<openvdb::Vec3SGrid::ConstAccessor, openvdb::tools::StaggeredPointSampler> stag_point_sampler_t;
+ typedef openvdb::tools::GridSampler<openvdb::Vec3SGrid::ConstAccessor, openvdb::tools::StaggeredBoxSampler> stag_box_sampler_t;
typedef openvdb::tools::VolumeRayIntersector<openvdb::Vec3SGrid> isector_t;
typedef isector_t::RayType vdb_ray_t;
@@ -243,9 +244,13 @@ class vdb_float3_volume : public float3_volume {
typedef unordered_map<pthread_t, isector_t *> isect_map;
typedef unordered_map<pthread_t, point_sampler_t *> point_map;
typedef unordered_map<pthread_t, box_sampler_t *> box_map;
+ typedef unordered_map<pthread_t, stag_point_sampler_t *> stag_point_map;
+ typedef unordered_map<pthread_t, stag_box_sampler_t *> stag_box_map;
isect_map isectors;
point_map point_samplers;
box_map box_samplers;
+ stag_point_map stag_point_samplers;
+ stag_box_map stag_box_samplers;
openvdb::Vec3SGrid::ConstAccessor *accessor;
openvdb::math::Transform *transfrom;
@@ -255,13 +260,14 @@ class vdb_float3_volume : public float3_volume {
* generated from a copy of it. */
isector_t *main_isector;
- bool uniform_voxels;
+ bool uniform_voxels, staggered;
public:
vdb_float3_volume(openvdb::Vec3SGrid::Ptr grid)
: transfrom(&grid->transform())
{
accessor = new openvdb::Vec3SGrid::ConstAccessor(grid->getConstAccessor());
+ staggered = (grid->getGridClass() == openvdb::GRID_STAGGERED);
/* only grids with uniform voxels can be used with VolumeRayIntersector */
if(grid->hasUniformVoxels()) {
@@ -290,6 +296,20 @@ public:
delete iter->second;
}
+ for(stag_point_map::iterator iter = stag_point_samplers.begin();
+ iter != stag_point_samplers.end();
+ ++iter)
+ {
+ delete iter->second;
+ }
+
+ for(stag_box_map::iterator iter = stag_box_samplers.begin();
+ iter != stag_box_samplers.end();
+ ++iter)
+ {
+ delete iter->second;
+ }
+
if(uniform_voxels) {
delete main_isector;
@@ -302,7 +322,48 @@ public:
}
}
- ccl_always_inline float3 sample(float x, float y, float z, int sampling)
+ ccl_always_inline float3 sample_staggered(float x, float y, float z, int sampling)
+ {
+ openvdb::Vec3s r;
+ pthread_t thread = pthread_self();
+
+ if(sampling == OPENVDB_SAMPLE_POINT) {
+ stag_point_map::iterator iter = stag_point_samplers.find(thread);
+ stag_point_sampler_t *sampler;
+
+ if(iter == stag_point_samplers.end()) {
+ openvdb::Vec3SGrid::ConstAccessor *acc = new openvdb::Vec3SGrid::ConstAccessor(*accessor);
+ sampler = new stag_point_sampler_t(*acc, *transfrom);
+ pair<pthread_t, stag_point_sampler_t *> sampl(thread, sampler);
+ stag_point_samplers.insert(sampl);
+ }
+ else {
+ sampler = iter->second;
+ }
+
+ r = sampler->wsSample(openvdb::Vec3d(x, y, z));
+ }
+ else {
+ stag_box_map::iterator iter = stag_box_samplers.find(thread);
+ stag_box_sampler_t *sampler;
+
+ if(iter == stag_box_samplers.end()) {
+ openvdb::Vec3SGrid::ConstAccessor *acc = new openvdb::Vec3SGrid::ConstAccessor(*accessor);
+ sampler = new stag_box_sampler_t(*acc, *transfrom);
+ pair<pthread_t, stag_box_sampler_t *> sampl(thread, sampler);
+ stag_box_samplers.insert(sampl);
+ }
+ else {
+ sampler = iter->second;
+ }
+
+ r = sampler->wsSample(openvdb::Vec3d(x, y, z));
+ }
+
+ return make_float3(r.x(), r.y(), r.z());
+ }
+
+ ccl_always_inline float3 sample_ex(float x, float y, float z, int sampling)
{
openvdb::Vec3s r;
pthread_t thread = pthread_self();
@@ -343,6 +404,14 @@ public:
return make_float3(r.x(), r.y(), r.z());
}
+ ccl_always_inline float3 sample(float x, float y, float z, int sampling)
+ {
+ if(staggered)
+ return sample_staggered(x, y, z, sampling);
+ else
+ return sample_ex(x, y, z, sampling);
+ }
+
ccl_always_inline bool intersect(const Ray *ray, Intersection */*isect*/)
{
pthread_t thread = pthread_self();
More information about the Bf-blender-cvs
mailing list