[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59553] branches/soc-2013-cycles_volume/ intern/cycles/kernel: - added error handling for when vdb file can' t be opened;
Rafael Campos
rafaelcdn at gmail.com
Tue Aug 27 16:52:48 CEST 2013
Revision: 59553
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59553
Author: jehuty
Date: 2013-08-27 14:52:47 +0000 (Tue, 27 Aug 2013)
Log Message:
-----------
- added error handling for when vdb file can't be opened;
- minor corrections
Modified Paths:
--------------
branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp
branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp
branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h
Modified: branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp
===================================================================
--- branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp 2013-08-27 14:19:26 UTC (rev 59552)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp 2013-08-27 14:52:47 UTC (rev 59553)
@@ -815,34 +815,36 @@
OSLThreadData *tdata = kg->osl_tdata;
OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
+ if (VDBTextureSystem::valid_vdb_file(filename)) {
VDBTextureSystem::Ptr volume_ts = vdb_ts;
- if (volume_ts->is_vdb_volume(filename))
- {
- std::cout << "Before lookup. FILE: " << filename.string() << " ; POINT: " << P << std::endl;
- status = volume_ts->perform_lookup(filename, options, sg, P, dPdx, dPdy, dPdz, result);
- std::cout << "After lookup. Status: " << status << " ; Result: " << *result << std::endl;
- }
- else
- {
- OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
+
+ //std::cout << "Before lookup. FILE: " << filename.string() << " ; POINT: " << P << std::endl;
+ status = volume_ts->perform_lookup(filename, thread_info,
+ options, P, dPdx, dPdy, dPdz, result);
+ //std::cout << "After lookup. Status: " << status << " ; Result: " << *result << std::endl;
+ }
+ else
+ {
+ OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
+
+ status = ts->texture3d(th, thread_info,
+ options, P, dPdx, dPdy, dPdz, result);
+ }
+
+ if(!status) {
+ if(options.nchannels == 3 || options.nchannels == 4) {
+ result[0] = 1.0f;
+ result[1] = 0.0f;
+ result[2] = 1.0f;
- status = ts->texture3d(th, thread_info,
- options, P, dPdx, dPdy, dPdz, result);
+ if(options.nchannels == 4)
+ result[3] = 1.0f;
}
- if(!status) {
- if(options.nchannels == 3 || options.nchannels == 4) {
- result[0] = 1.0f;
- result[1] = 0.0f;
- result[2] = 1.0f;
-
- if(options.nchannels == 4)
- result[3] = 1.0f;
- }
-
- }
- return status;
}
+
+ return status;
+}
bool OSLRenderServices::environment(ustring filename, TextureOpt &options,
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
Modified: branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp
===================================================================
--- branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp 2013-08-27 14:19:26 UTC (rev 59552)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp 2013-08-27 14:52:47 UTC (rev 59553)
@@ -57,8 +57,8 @@
static int nearest_neighbor(float worldCoord);
private:
- static bool vdb_file_check_extension(ustring filename);
- static bool vdb_file_check_valid_header(ustring filename);
+ static bool vdb_file_format(ustring filename);
+ static bool valid_file(ustring filename);
};
@@ -71,26 +71,33 @@
openvdb::initialize();
}
-bool OpenVDBUtil::vdb_file_check_valid_header(ustring filename)
+// Open file to check header information and determine
+// if file is a valid VDB volume.
+bool OpenVDBUtil::valid_file(ustring filename)
{
- OpenVDBUtil::initialize_library();
+ OIIO::ustring openvdb_version;
openvdb::io::File file(filename.string());
- file.open();
- OIIO::ustring openvdb_version;
+ try {
+ file.open();
+
+ openvdb_version.empty();
+ openvdb_version = file.version();
+
+ file.close();
+
+ } catch (openvdb::IoError error) {
+ std::cout << "ERROR: VDB file could not be opened (" << filename << ")." << std::endl;
+ return false;
+ }
- openvdb_version.empty();
- openvdb_version = file.version();
-
- file.close();
-
if(openvdb_version.length() > 0)
return true;
return false;
}
-bool OpenVDBUtil::vdb_file_check_extension(ustring filename)
+bool OpenVDBUtil::vdb_file_format(ustring filename)
{
if (filename.substr(filename.length() - u_openvdb_file_extension.length(),
u_openvdb_file_extension.length()) == u_openvdb_file_extension)
@@ -102,10 +109,8 @@
bool OpenVDBUtil::is_vdb_volume_file(OIIO::ustring filename)
{
- OIIO::ustring openvdb_version;
-
- if (vdb_file_check_extension(filename)) {
- if (vdb_file_check_valid_header(filename))
+ if (vdb_file_format(filename)) {
+ if (valid_file(filename))
return true;
}
@@ -129,30 +134,22 @@
VDBTextureSystem::Ptr VDBTextureSystem::init() {
OpenVDBUtil::initialize_library();
-
Ptr vdb_ts(new VDBTextureSystem());
return vdb_ts;
}
-bool VDBTextureSystem::is_vdb_volume(ustring filename)
+bool VDBTextureSystem::valid_vdb_file(ustring filename)
{
- if (vdb_files.empty())
- {
return OpenVDBUtil::is_vdb_volume_file(filename);
- }
- if (vdb_files.find(filename) != vdb_files.end())
- return true;
- else
- return OpenVDBUtil::is_vdb_volume_file(filename);
}
-bool VDBTextureSystem::perform_lookup(ustring filename, TextureOpt &options, OSL::ShaderGlobals *sg,
- const Imath::V3f &P, const Imath::V3f &dPdx,
- const Imath::V3f &dPdy, const Imath::V3f &dPdz,
- float *result)
+bool VDBTextureSystem::perform_lookup(ustring filename, OIIO::TextureSystem::Perthread *thread_info,
+ TextureOpt &options, const Imath::V3f &P,
+ const Imath::V3f &dPdx,const Imath::V3f &dPdy,
+ const Imath::V3f &dPdz, float *result)
{
- // - check if file is open;
+ // check if file is open;
VDBMap::const_iterator open_file = vdb_files.find(filename);
if (open_file == vdb_files.end())
@@ -162,24 +159,31 @@
VDBFilePtr vdb_p = open_file->second;
- //decide on type of grid; let's say it's a float grid.
- openvdb::GridPtrVec::const_iterator it = vdb_p->grids->begin();
- const openvdb::GridBase::Ptr grid = *it;
-
- openvdb::FloatGrid::Ptr floatGrid = openvdb::gridPtrCast<openvdb::FloatGrid>(grid);
-
- openvdb::FloatGrid::Accessor accessor = floatGrid->getAccessor();
-
- float x, y, z = 0;
- x = OpenVDBUtil::nearest_neighbor(P[0]);
- y = OpenVDBUtil::nearest_neighbor(P[1]);
- z = OpenVDBUtil::nearest_neighbor(P[2]);
-
- openvdb::Coord point((int)x, (int)y, (int)z);
-
- const float myResult(accessor.getValue(point));
- *result = myResult;
- return true;
+ if (!vdb_p) {
+ return false;
+ }
+ else
+ {
+ //decide on type of grid; let's say it's a float grid.
+ openvdb::GridPtrVec::const_iterator it = vdb_p->grids->begin();
+ const openvdb::GridBase::Ptr grid = *it;
+
+ openvdb::FloatGrid::Ptr floatGrid = openvdb::gridPtrCast<openvdb::FloatGrid>(grid);
+
+ openvdb::FloatGrid::Accessor accessor = floatGrid->getAccessor();
+
+ float x, y, z = 0;
+ x = OpenVDBUtil::nearest_neighbor(P[0]);
+ y = OpenVDBUtil::nearest_neighbor(P[1]);
+ z = OpenVDBUtil::nearest_neighbor(P[2]);
+
+ openvdb::Coord point((int)x, (int)y, (int)z);
+
+ const float myResult(accessor.getValue(point));
+ *result = myResult;
+
+ return true;
+ }
}
VDBTextureSystem::VDBMap::const_iterator VDBTextureSystem::add_vdb_to_map(ustring filename)
@@ -189,12 +193,9 @@
return (vdb_files.insert(std::make_pair(filename, vdb_sp))).first;
}
-void VDBTextureSystem::free(VDBTextureSystem::Ptr vdb_ts)
+void VDBTextureSystem::free(VDBTextureSystem::Ptr &vdb_ts)
{
vdb_ts.reset();
}
-VDBTextureSystem::~VDBTextureSystem(){
-}
-
CCL_NAMESPACE_END
Modified: branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h
===================================================================
--- branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h 2013-08-27 14:19:26 UTC (rev 59552)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h 2013-08-27 14:52:47 UTC (rev 59553)
@@ -37,18 +37,17 @@
typedef boost::shared_ptr<VDBTextureSystem> Ptr;
static VDBTextureSystem::Ptr init();
- static void free (VDBTextureSystem::Ptr vdb_ts);
+ static void free (VDBTextureSystem::Ptr &vdb_ts);
- VDBTextureSystem() { }
- ~VDBTextureSystem();
+ static bool valid_vdb_file (ustring filename);
- bool is_vdb_volume (ustring filename);
-
- bool perform_lookup (ustring filename, TextureOpt &options, OSL::ShaderGlobals *sg,
- const Imath::V3f &P, const Imath::V3f &dPdx,
+ bool perform_lookup (ustring filename, OIIO::TextureSystem::Perthread *thread_info,
+ TextureOpt &options, const Imath::V3f &P, const Imath::V3f &dPdx,
const Imath::V3f &dPdy, const Imath::V3f &dPdz,
float *result);
- VDBMap get_map();
+
+ VDBTextureSystem() { }
+ ~VDBTextureSystem() { }
private:
VDBMap vdb_files;
More information about the Bf-blender-cvs
mailing list