Commit: ac21e600ee877333840813c8314b7248ea4e2d33
Author: Geraldine Chua
Date: Thu Aug 2 23:39:28 2018 +0800
Branches: soc-2018-cycles-volumes
https://developer.blender.org/rBac21e600ee877333840813c8314b7248ea4e2d33
Remove Cycles dependency on intern/openvdb.
For this, several functions from intern now have simplified copies
in Cycles, since the dependency is otherwise difficult to maintain.
===================================================================
M intern/cycles/CMakeLists.txt
M intern/cycles/blender/blender_mesh.cpp
M intern/cycles/render/openvdb.cpp
M intern/cycles/render/openvdb.h
M intern/cycles/render/scene.h
===================================================================
diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index 13538caf54c..8d9f7300563 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -279,7 +279,6 @@ if(WITH_OPENVDB)
include_directories(
SYSTEM
${OPENVDB_INCLUDE_DIRS}
- ../openvdb
)
endif()
diff --git a/intern/cycles/blender/blender_mesh.cpp
b/intern/cycles/blender/blender_mesh.cpp
index e78aab9dc54..77a82ae4a19 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -31,6 +31,10 @@
#include "util/util_logging.h"
#include "util/util_math.h"
+#ifdef WITH_OPENVDB
+#include "render/openvdb.h"
+#endif
+
#include "mikktspace.h"
CCL_NAMESPACE_BEGIN
@@ -375,9 +379,13 @@ static void create_mesh_volume_attributes(Scene *scene,
void *builtin_data;
if(b_domain.is_openvdb()) {
+ if(!scene->params.intialized_openvdb) {
+ openvdb_initialize();
+ scene->params.intialized_openvdb = true;
+ }
+
BL::ID b_id = b_ob.data();
- filename = blender_absolute_path(b_data,
- b_id,
+ filename = blender_absolute_path(b_data, b_id,
b_domain.openvdb_filepath());
builtin_data = NULL;
}
diff --git a/intern/cycles/render/openvdb.cpp b/intern/cycles/render/openvdb.cpp
index 1f58f3783c7..0beb64ba6fa 100644
--- a/intern/cycles/render/openvdb.cpp
+++ b/intern/cycles/render/openvdb.cpp
@@ -2,12 +2,9 @@
#include <openvdb/openvdb.h>
#include <openvdb/tools/GridTransformer.h>
+#include "render/attribute.h"
#include "render/openvdb.h"
-#include "intern/openvdb_reader.h"
-#include "intern/openvdb_dense_convert.h"
-#include "openvdb_capi.h"
-
#include "util/util_logging.h"
#include "util/util_path.h"
#include "util/util_sparse_grid.h"
@@ -18,22 +15,86 @@ struct OpenVDBReader;
CCL_NAMESPACE_BEGIN
+namespace {
+
/* Misc internal helper functions. */
-static bool operator >=(const openvdb::math::Vec3s &a, const float &b)
+bool operator >=(const openvdb::math::Vec3s &a, const float &b)
{
return a.x() >= b || a.y() >= b || a.z() >= b;
}
-static const int tile_index(openvdb::math::Coord start, const int tiled_res[3])
+void copy(float *des, const float *src)
+{
+ *des = *src;
+}
+
+void copy(float *des, const openvdb::math::Vec3s *src)
{
- return compute_index(start.x() / TILE_SIZE, start.y() / TILE_SIZE,
- start.z() / TILE_SIZE, tiled_res[0], tiled_res[1]);
+ *(des + 0) = src->x();
+ *(des + 1) = src->y();
+ *(des + 2) = src->z();
+ *(des + 3) = 1.0f;
+}
+
+const int get_tile_index(const openvdb::math::Coord &start,
+ const openvdb::math::Coord &tiled_res)
+{
+ return compute_index(start.x() / TILE_SIZE,
+ start.y() / TILE_SIZE,
+ start.z() / TILE_SIZE,
+ tiled_res.x(),
+ tiled_res.y());
+}
+
+const int coord_product(const openvdb::math::Coord &c)
+{
+ return c.x() * c.y() * c.z();
+}
+
+const openvdb::math::Coord get_tile_dim(const openvdb::math::Coord
&tile_min_bound,
+ const openvdb::math::Coord &image_res,
+ const openvdb::math::Coord &remainder)
+{
+ openvdb::math::Coord tile_dim;
+ for(int i = 0; i < 3; ++i) {
+ tile_dim[i] = (tile_min_bound[i] + TILE_SIZE > image_res[i]) ?
remainder[i] : TILE_SIZE;
+ }
+ return tile_dim;
+}
+
+void expand_bbox(openvdb::io::File *vdb_file,
+ openvdb::math::CoordBBox *bbox,
+ AttributeStandard std)
+{
+ const char *grid_name = Attribute::standard_name(std);
+ if(vdb_file->hasGrid(grid_name)) {
+
bbox->expand(vdb_file->readGrid(grid_name)->evalActiveVoxelBoundingBox());
+ }
+}
+
+void get_bounds(openvdb::io::File *vdb_file,
+ openvdb::math::Coord &resolution,
+ openvdb::math::Coord &min_bound)
+{
+ openvdb::math::CoordBBox bbox(openvdb::math::Coord(0, 0, 0),
+ openvdb::math::Coord(0, 0, 0));
+
+ /* Get the combined bounding box of all possible smoke grids in the
file. */
+ expand_bbox(vdb_file, &bbox, ATTR_STD_VOLUME_DENSITY);
+ expand_bbox(vdb_file, &bbox, ATTR_STD_VOLUME_COLOR);
+ expand_bbox(vdb_file, &bbox, ATTR_STD_VOLUME_FLAME);
+ expand_bbox(vdb_file, &bbox, ATTR_STD_VOLUME_HEAT);
+ expand_bbox(vdb_file, &bbox, ATTR_STD_VOLUME_TEMPERATURE);
+ expand_bbox(vdb_file, &bbox, ATTR_STD_VOLUME_VELOCITY);
+
+ resolution = bbox.dim();
+ min_bound = bbox.getStart();
}
/* Simple range shift for grids with non-zero background values. May have
* strange results depending on the grid. */
-static void shift_range(openvdb::Vec3SGrid::Ptr grid)
+void shift_range(openvdb::Vec3SGrid::Ptr grid)
{
using namespace openvdb;
const math::Vec3s background_value = grid->background();
@@ -45,7 +106,7 @@ static void shift_range(openvdb::Vec3SGrid::Ptr grid)
}
}
-static void shift_range(openvdb::FloatGrid::Ptr grid)
+void shift_range(openvdb::FloatGrid::Ptr grid)
{
using namespace openvdb;
const float background_value = grid->background();
@@ -57,28 +118,58 @@ static void shift_range(openvdb::FloatGrid::Ptr grid)
}
}
-template<typename GridType>
-static bool get_grid(const string& filepath,
- const string& grid_name,
- typename GridType::Ptr& grid,
- int resolution[3],
- int min_bound[3])
+/* File and Grid IO */
+
+void cleanup_file(openvdb::io::File *vdb_file)
{
- using namespace openvdb;
+ if(vdb_file) {
+ vdb_file->close();
+ delete vdb_file;
+ vdb_file = NULL;
+ }
+}
+openvdb::io::File *load_file(const string &filepath)
+{
if(!path_exists(filepath) || path_is_directory(filepath)) {
- return false;
+ return NULL;
}
- struct OpenVDBReader *reader = OpenVDBReader_create();
- OpenVDBReader_open(reader, filepath.c_str());
+ openvdb::io::File *vdb_file = NULL;
+ try {
+ vdb_file = new openvdb::io::File(filepath);
+ vdb_file->setCopyMaxBytes(0);
+ vdb_file->open();
+ }
+ /* Mostly to catch exceptions related to Blosc not being supported. */
+ catch (const openvdb::IoError &e) {
+ std::cerr << e.what() << '\n';
+ cleanup_file(vdb_file);
+ }
+
+ return vdb_file;
+}
+
+template<typename GridType>
+bool get_grid(const string &filepath,
+ const string &grid_name,
+ typename GridType::Ptr &grid,
+ openvdb::math::Coord &resolution,
+ openvdb::math::Coord &min_bound)
+{
+ using namespace openvdb;
- if (!OpenVDBReader_has_grid(reader, grid_name.c_str())) {
- OpenVDBReader_free(reader);
+ io::File *vdb_file = load_file(filepath);
+
+ if(!vdb_file) {
+ return false;
+ }
+ if (!vdb_file->hasGrid(grid_name)) {
+ cleanup_file(vdb_file);
return false;
}
- grid = gridPtrCast<GridType>(reader->getGrid(grid_name));
+ grid = gridPtrCast<GridType>(vdb_file->readGrid(grid_name));
/* Verify that leaf dimensions match internal tile dimensions. */
typename GridType::TreeType::LeafCIter iter = grid->tree().cbeginLeaf();
@@ -89,7 +180,7 @@ static bool get_grid(const string& filepath,
VLOG(1) << "Cannot load grid " << grid->getName() << "
from "
<< filepath << ", leaf dimensions are "
<< dim[0] << "x" << dim[1] << "x" << dim[2];
- OpenVDBReader_free(reader);
+ cleanup_file(vdb_file);
return false;
}
}
@@ -99,90 +190,56 @@ static bool get_grid(const string& filepath,
shift_range(grid);
/* Retrieve bound data. */
- OpenVDBReader_get_bounds(reader, min_bound, NULL, resolution, NULL,
NULL, NULL);
+ get_bounds(vdb_file, resolution, min_bound);
- OpenVDBReader_free(reader);
+ cleanup_file(vdb_file);
return true;
}
-/* Misc external helper functions. These all assume that the file exists and is
- * a valid .vdb file. Logging should be done by callers. */
-
-bool openvdb_has_grid(const string& filepath, const string& grid_name)
-{
- if(grid_name.empty()) {
- return false;
- }
-
- struct OpenVDBReader *reader = OpenVDBReader_create();
- OpenVDBReader_open(reader, filepath.c_str());
-
- bool has_grid = OpenVDBReader_has_grid(reader, grid_name.c_str());
-
- OpenVDBReader_free(reader);
- return has_grid;
-}
-
-int3 openvdb_get_resolution(const string& filepath)
-{
- struct OpenVDBReader *reader = OpenVDBReader_create();
- OpenVDBReader_open(reader, filepath.c_str());
-
- int res[3];
- OpenVDBReader_get_bounds(reader, NULL, NULL, res, NULL, NULL, NULL);
- OpenVDBReader_free(reader);
+/* Load OpenVDB grid to texture. */
- return make_int3(res[0], res[1], res[2]);
-}
-
-/* Load OpenVDB file to texture grid. */
template<typename GridType, typename T>
-static void openvdb_load_preprocess(const string& filepath,
- const string& grid_name,
- const int channels,
- const float threshold,
- vector<int> *sparse_index,
- int &sparse_size)
+void image_load_preprocess(const string &filepath,
+ const string &grid_name,
+ const int channels,
+ const float threshold,
+ vector<int> *sparse_indexes,
+ int &sparse_size)
{
using namespace openvdb;
+ if(channels != 1 && channels != 4) {
+ return;
+ }
+
typename GridType::Ptr grid = GridType::create();
- int res[3], min_bound[3];
+ math::Coord resolution, min_bound, tiled_res, remainder;
- if(!get_grid<GridType>(filepath, grid_name, grid, res, min_bound) ||
- !(channels == 4 || channels == 1))
- {
+ if(!get_grid<GridType>(filepath, grid_name, grid, resolution,
min_bound)) {
return;
}
- const int tiled_res[3] = {get_tile_res(res[0]),
- get_tile_res(res[1]),
- get_tile_res(res[2])};
- const int remainder[3] = {res[0] % TILE_SIZE,
- res[1] % TILE_SIZE,
- res[2] % TILE_SIZE};
- const int tile_count = tiled_res[0] * tiled_res[1] * tiled_res[2];
+ for(int i = 0; i < 3; ++i) {
+ tiled_res[i] = get_tile_res(resolution[i]);
+ remainder[i] = resolution[i] %
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs