[Bf-blender-cvs] [77246e2] openvdb: More flexible feedback function for reading header and metadata from OpenVDB files.

Lukas Tönne noreply at git.blender.org
Tue Jun 9 12:13:53 CEST 2015


Commit: 77246e2b936e4a179c7c0c3dd561c80664d333ce
Author: Lukas Tönne
Date:   Mon Jun 8 15:55:36 2015 +0200
Branches: openvdb
https://developer.blender.org/rB77246e2b936e4a179c7c0c3dd561c80664d333ce

More flexible feedback function for reading header and metadata from
OpenVDB files.

Instead of fixed-size arrays (risking overrun) the function now uses a
callback, which allows callers to store the info in their own data
structures as needed. Nodes use this to create a list of grid info
structs and adding node sockets accordingly.

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

M	intern/openvdb/openvdb_capi.cpp
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/nodes/shader/nodes/node_shader_openvdb.c

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

diff --git a/intern/openvdb/openvdb_capi.cpp b/intern/openvdb/openvdb_capi.cpp
index 686ef54..6eca100 100644
--- a/intern/openvdb/openvdb_capi.cpp
+++ b/intern/openvdb/openvdb_capi.cpp
@@ -42,26 +42,24 @@ void OpenVDB_get_grid_info(const char *filename, OpenVDBGridInfoCallback cb, voi
 {
 	int ret = OPENVDB_NO_ERROR;
 	initialize();
-
+	
 	try {
 		io::File file(filename);
 		file.open();
-
+		
 		GridPtrVecPtr grids = file.getGrids();
 		int grid_num = grids->size();
-
+		
 		for (size_t i = 0; i < grid_num; ++i) {
 			GridBase::ConstPtr grid = (*grids)[i];
-
-			const char *name = strdup(grid->getName().c_str());
-			const char *value_type = strdup(grid->valueType().c_str());
+			
+			std::string name = grid->getName();
+			std::string value_type = grid->valueType();
 			bool is_color = false;
-
-			if (grid->getMetadata< TypedMetadata<bool> >("is_color")) {
+			if (grid->getMetadata< TypedMetadata<bool> >("is_color"))
 				is_color = grid->metaValue<bool>("is_color");
-			}
-
-			cb(userdata, name, value_type, is_color);
+			
+			cb(userdata, name.c_str(), value_type.c_str(), is_color);
 		}
 	}
 	catch (...) {
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index dc497f3..55e18b7 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -857,7 +857,7 @@ typedef struct NodeShaderUVMap {
 
 typedef struct OpenVDBGridInfo {
 	struct OpenVDBGridInfo *next, *prev;
-
+	
 	char name[64]; /* MAX_NAME */
 	short flag;
 	short type;
@@ -865,21 +865,21 @@ typedef struct OpenVDBGridInfo {
 } OpenVDBGridInfo;
 
 typedef enum eOpenVDBGridInfo_Flag {
-	OPENVDB_FLAG_UNIFORM_VOXELS  = (1 << 0),
+	OPENVDB_FLAG_UNIFORM_VOXELS         = (1 << 0),
 } eOpenVDBGridInfo_Flag;
 
 typedef enum eOpenVDBGridInfo_Type {
-	OPENVDB_TYPE_UNKNOWN = 0,
-	OPENVDB_TYPE_FLOAT   = 1,
-	OPENVDB_TYPE_VEC3    = 2,
-	OPENVDB_TYPE_COLOR   = 3,
+	OPENVDB_TYPE_UNKNOWN                = 0,
+	OPENVDB_TYPE_FLOAT                  = 1,
+	OPENVDB_TYPE_VEC3                   = 2,
+	OPENVDB_TYPE_COLOR                  = 3,
 } eOpenVDBGridInfo_Type;
 
 typedef struct NodeShaderOpenVDB {
 	char filename[1024];
 	short sampling, source;
 	int pad;
-
+	
 	ListBase grid_info;
 } NodeShaderOpenVDB;
 
diff --git a/source/blender/nodes/shader/nodes/node_shader_openvdb.c b/source/blender/nodes/shader/nodes/node_shader_openvdb.c
index 2d5db09..2b2c1f5 100644
--- a/source/blender/nodes/shader/nodes/node_shader_openvdb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_openvdb.c
@@ -55,7 +55,7 @@ static void node_shader_copy_openvdb(bNodeTree *UNUSED(dest_ntree), bNode *dst_n
 	if (dst_node->storage) {
 		NodeShaderOpenVDB *src_vdb = src_node->storage;
 		NodeShaderOpenVDB *dst_vdb = dst_node->storage;
-
+		
 		BLI_duplicatelist(&dst_vdb->grid_info, &src_vdb->grid_info);
 	}
 }
@@ -78,7 +78,7 @@ static void node_openvdb_get_info(void *userdata, const char *name, const char *
 {
 	NodeShaderOpenVDB *vdb = userdata;
 	OpenVDBGridInfo *info = MEM_callocN(sizeof(OpenVDBGridInfo), "openvdb grid info");
-
+	
 	BLI_strncpy(info->name, name, sizeof(info->name));
 	if (STREQ(value_type, "float"))
 		info->type = OPENVDB_TYPE_FLOAT;
@@ -90,9 +90,9 @@ static void node_openvdb_get_info(void *userdata, const char *name, const char *
 	}
 	else
 		info->type = OPENVDB_TYPE_UNKNOWN;
-
+	
 	info->flag = 0;
-
+	
 	BLI_addtail(&vdb->grid_info, info);
 }
 
@@ -114,7 +114,7 @@ static void node_openvdb_get_sockets(Main *bmain, bNodeTree *ntree, bNode *node)
 
 	BLI_freelistN(&vdb->grid_info);
 	OpenVDB_get_grid_info(filename, node_openvdb_get_info, vdb);
-
+	
 	for (info = vdb->grid_info.first; info; info = info->next) {
 		switch (info->type) {
 			case OPENVDB_TYPE_FLOAT:




More information about the Bf-blender-cvs mailing list