[Bf-blender-cvs] [f690c9b] openvdb: Cycles: cleanup util_volume, move non-inline functions definition from header to source file.
Kévin Dietrich
noreply at git.blender.org
Sun Jan 17 17:18:59 CET 2016
Commit: f690c9b6adcfa76070c8e2f81cda4a51cf96480a
Author: Kévin Dietrich
Date: Sun Jan 17 16:48:48 2016 +0100
Branches: openvdb
https://developer.blender.org/rBf690c9b6adcfa76070c8e2f81cda4a51cf96480a
Cycles: cleanup util_volume, move non-inline functions definition from
header to source file.
Also de-duplicate loop to free memory from the various maps.
===================================================================
M intern/cycles/util/CMakeLists.txt
A intern/cycles/util/util_volume.cpp
M intern/cycles/util/util_volume.h
===================================================================
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt
index ac2a363..de4fa32 100644
--- a/intern/cycles/util/CMakeLists.txt
+++ b/intern/cycles/util/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SRC
util_task.cpp
util_time.cpp
util_transform.cpp
+ util_volume.cpp
)
if(NOT CYCLES_STANDALONE_REPOSITORY)
diff --git a/intern/cycles/util/util_volume.cpp b/intern/cycles/util/util_volume.cpp
new file mode 100644
index 0000000..88293f5
--- /dev/null
+++ b/intern/cycles/util/util_volume.cpp
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2016 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "util_volume.h"
+
+CCL_NAMESPACE_BEGIN
+
+template <typename T>
+void release_map_memory(unordered_map<pthread_t, T> &map)
+{
+ typename unordered_map<pthread_t, T>::iterator iter;
+
+ for(iter = map.begin(); iter != map.end(); ++iter) {
+ delete iter->second;
+ }
+}
+
+template <typename IsectorType>
+void create_isectors_threads(unordered_map<pthread_t, IsectorType *> &isect_map,
+ const vector<pthread_t> &thread_ids,
+ const IsectorType &main_isect)
+{
+ pthread_t my_thread = pthread_self();
+
+ for (size_t i = 0; i < thread_ids.size(); ++i) {
+ IsectorType *isect = new IsectorType(main_isect);
+ pair<pthread_t, IsectorType *> inter(thread_ids[i], isect);
+ isect_map.insert(inter);
+ }
+
+ if (isect_map.find(my_thread) == isect_map.end()) {
+ IsectorType *isect = new IsectorType(main_isect);
+ pair<pthread_t, IsectorType *> inter(my_thread, isect);
+ isect_map.insert(inter);
+ }
+}
+
+template <typename SamplerType, typename AccessorType>
+void create_samplers_threads(unordered_map<pthread_t, SamplerType *> &sampler_map,
+ vector<AccessorType *> &accessors,
+ const vector<pthread_t> &thread_ids,
+ const openvdb::math::Transform *transform,
+ const AccessorType &main_accessor)
+{
+ pthread_t my_thread = pthread_self();
+
+ for (size_t i = 0; i < thread_ids.size(); ++i) {
+ AccessorType *accessor = new AccessorType(main_accessor);
+ accessors.push_back(accessor);
+ SamplerType *sampler = new SamplerType(*accessor, *transform);
+ pair<pthread_t, SamplerType *> sampl(thread_ids[i], sampler);
+ sampler_map.insert(sampl);
+ }
+
+ if (sampler_map.find(my_thread) == sampler_map.end()) {
+ AccessorType *accessor = new AccessorType(main_accessor);
+ accessors.push_back(accessor);
+ SamplerType *sampler = new SamplerType(*accessor, *transform);
+ pair<pthread_t, SamplerType *> sampl(my_thread, sampler);
+ sampler_map.insert(sampl);
+ }
+}
+
+/* ********** OpenVDB floating pointing scalar volume ************ */
+
+vdb_float_volume::vdb_float_volume(openvdb::FloatGrid::Ptr grid)
+ : transform(&grid->transform())
+{
+ accessor = new openvdb::FloatGrid::ConstAccessor(grid->getConstAccessor());
+
+ /* only grids with uniform voxels can be used with VolumeRayIntersector */
+ if(grid->hasUniformVoxels()) {
+ uniform_voxels = true;
+ /* 1 = size of the largest sampling kernel radius (BoxSampler) */
+ main_isector = new isector_t(*grid, 1);
+ }
+ else {
+ uniform_voxels = false;
+ main_isector = NULL;
+ }
+}
+
+vdb_float_volume::~vdb_float_volume()
+{
+ release_map_memory(point_samplers);
+ release_map_memory(box_samplers);
+
+ if(uniform_voxels) {
+ delete main_isector;
+ release_map_memory(isectors);
+ }
+
+ delete accessor;
+
+ for(size_t i = 0; i < accessors.size(); ++i) {
+ delete accessors[i];
+ }
+}
+
+void vdb_float_volume::create_threads_utils(const vector<pthread_t> &thread_ids)
+{
+ create_isectors_threads(isectors, thread_ids, *main_isector);
+ create_samplers_threads(point_samplers, accessors, thread_ids, transform, *accessor);
+ create_samplers_threads(box_samplers, accessors, thread_ids, transform, *accessor);
+}
+
+/* ********** OpenVDB vector volume ************ */
+
+vdb_float3_volume::vdb_float3_volume(openvdb::Vec3SGrid::Ptr grid)
+ : transform(&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()) {
+ uniform_voxels = true;
+ /* 1 = size of the largest sampling kernel radius (BoxSampler) */
+ main_isector = new isector_t(*grid, 1);
+ }
+ else {
+ uniform_voxels = false;
+ main_isector = NULL;
+ }
+}
+
+vdb_float3_volume::~vdb_float3_volume()
+{
+ release_map_memory(point_samplers);
+ release_map_memory(box_samplers);
+ release_map_memory(stag_point_samplers);
+ release_map_memory(stag_box_samplers);
+
+ if(uniform_voxels) {
+ delete main_isector;
+ release_map_memory(isectors);
+ }
+
+ delete accessor;
+
+ for(size_t i = 0; i < accessors.size(); ++i) {
+ delete accessors[i];
+ }
+}
+
+void vdb_float3_volume::create_threads_utils(const vector<pthread_t> &thread_ids)
+{
+ create_isectors_threads(isectors, thread_ids, *main_isector);
+ create_samplers_threads(point_samplers, accessors, thread_ids, transform, *accessor);
+ create_samplers_threads(box_samplers, accessors, thread_ids, transform, *accessor);
+ create_samplers_threads(stag_point_samplers, accessors, thread_ids, transform, *accessor);
+ create_samplers_threads(stag_box_samplers, accessors, thread_ids, transform, *accessor);
+}
+
+CCL_NAMESPACE_END
diff --git a/intern/cycles/util/util_volume.h b/intern/cycles/util/util_volume.h
index 1bc10a0..feaa269 100644
--- a/intern/cycles/util/util_volume.h
+++ b/intern/cycles/util/util_volume.h
@@ -1,9 +1,25 @@
+/*
+ * Copyright 2016 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#ifndef __UTIL_VOLUME_H__
#define __UTIL_VOLUME_H__
#include "util_types.h"
-#include "kernel_types.h"
+#include "../kernel/kernel_types.h"
CCL_NAMESPACE_BEGIN
@@ -64,52 +80,6 @@ using std::isfinite;
using boost::math::isfinite;
#endif
-template <typename IsectorType>
-void create_isectors_threads(unordered_map<pthread_t, IsectorType *> &isect_map,
- const vector<pthread_t> &thread_ids,
- const IsectorType &main_isect)
-{
- pthread_t my_thread = pthread_self();
-
- for (size_t i = 0; i < thread_ids.size(); ++i) {
- IsectorType *isect = new IsectorType(main_isect);
- pair<pthread_t, IsectorType *> inter(thread_ids[i], isect);
- isect_map.insert(inter);
- }
-
- if (isect_map.find(my_thread) == isect_map.end()) {
- IsectorType *isect = new IsectorType(main_isect);
- pair<pthread_t, IsectorType *> inter(my_thread, isect);
- isect_map.insert(inter);
- }
-}
-
-template <typename SamplerType, typename AccessorType>
-void create_samplers_threads(unordered_map<pthread_t, SamplerType *> &sampler_map,
- vector<AccessorType *> &accessors,
- const vector<pthread_t> &thread_ids,
- const openvdb::math::Transform *transform,
- const AccessorType &main_accessor)
-{
- pthread_t my_thread = pthread_self();
-
- for (size_t i = 0; i < thread_ids.size(); ++i) {
- AccessorType *accessor = new AccessorType(main_accessor);
- accessors.push_back(accessor);
- SamplerType *sampler = new SamplerType(*accessor, *transform);
- pair<pthread_t, SamplerType *> sampl(thread_ids[i], sampler);
- sampler_map.insert(sampl);
- }
-
- if (sampler_map.find(my_thread) == sampler_map.end()) {
- AccessorType *accessor = new AccessorType(main_accessor);
- accessors.push_back(accessor);
- SamplerType *sampler = new SamplerType(*accessor, *transform);
- pair<pthread_t, SamplerType *> sampl(my_thread, sampler);
- sampler_map.insert(sampl);
- }
-}
-
typedef openvdb::math::Ray<float> vdb_ray_t;
class vdb_float_volume : public float_volume {
@@ -140,63 +110,10 @@ class vdb_float_volume : public float_volume {
bool uniform_voxels;
public:
- vdb_float_volume(openvdb::FloatGrid::Ptr grid)
- : transform(&grid->transform())
- {
- accessor = new openvdb::FloatGrid::ConstAccessor(grid->getConstAccessor());
-
- /* only grids with uniform voxels can be used with VolumeRayIntersector */
- if(grid->hasUniformVoxels()) {
- uniform_voxels = true;
- /* 1 = size of the largest sampling kernel radius (BoxSampler) */
- main_isector = new isector_t(*grid, 1);
- }
- else {
- uniform_voxels = false;
- main_isector = NULL;
- }
- }
+ vdb_float_volume(openvdb::FloatGrid::Ptr grid);
+ ~vdb_float_volume();
- ~vdb_float_volume()
- {
- for(point_map::iterator iter = point_samplers.begin();
- iter != point_samplers.end();
- ++iter)
- {
- delete iter->second;
- }
-
- for(box_map::iterator iter = box_samplers.begin();
- iter != box_samplers.end();
- ++iter)
- {
- delete iter->second;
- }
-
- if(uniform_voxels) {
- delete main_isector;
-
- for(isect_map::iterator iter = isectors.begin();
- iter != isectors.end();
- ++iter)
- {
- delete iter->second;
- }
- }
-
- delete accessor;
-
- for(size_t i = 0; i < accessors.size(); ++i) {
- delete accessors[i];
- }
- }
-
- void create_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list