[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58769] branches/soc-2013-cycles_volume: - added the library "cycles_kernel_textures" to build target;

Rafael Campos rafaelcdn at gmail.com
Wed Jul 31 17:48:10 CEST 2013


Revision: 58769
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58769
Author:   jehuty
Date:     2013-07-31 15:48:10 +0000 (Wed, 31 Jul 2013)
Log Message:
-----------
- added the library "cycles_kernel_textures" to build target;
- isolated OSL Services from VDB Volumes by adding the class VDBTextureSystem to hold API;

Modified Paths:
--------------
    branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp
    branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.h
    branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp
    branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h
    branches/soc-2013-cycles_volume/source/creator/CMakeLists.txt

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-07-31 14:15:40 UTC (rev 58768)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp	2013-07-31 15:48:10 UTC (rev 58769)
@@ -108,6 +108,7 @@
 {
 	kernel_globals = kernel_globals_;
 	osl_ts = osl_ts_;
+    vdb_ts = VDBTextureSystem::init();
 }
 
 bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time)
@@ -785,38 +786,38 @@
 	return status;
 }
 
-bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
-                                  OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
-                                  const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
-                                  const OSL::Vec3 &dPdz, float *result)
-{ 
-/*
-	//Are we dealing with an OpenVDB volume file?
-    if (ccl::OpenVDBUtil::is_vdb_volume_file(filename))
+    bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
+                                      OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
+                                      const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
+                                      const OSL::Vec3 &dPdz, float *result)
     {
-        // TODO:
-        // - check if file is open and mapped;
-        // - perform lookup;
-    } */
-	
-	OSL::TextureSystem *ts = osl_ts;
-	bool status = ts->texture3d(filename, options, P, dPdx, dPdy, dPdz, result);
+        bool status = false;
 
-	if(!status) {
-		if(options.nchannels == 3 || options.nchannels == 4) {
-			result[0] = 1.0f;
-			result[1] = 0.0f;
-			result[2] = 1.0f;
+        VDBTextureSystem *volume_ts = vdb_ts;
+        if (volume_ts->is_vdb_volume(filename))
+        {
+            volume_ts->perform_lookup(filename, options, sg, P, dPdx, dPdy, dPdz, result);
+        }
+        else
+        {
+            OSL::TextureSystem *ts = osl_ts;
+            status = ts->texture3d(filename, 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;
+                
+                if(options.nchannels == 4)
+                    result[3] = 1.0f;
+            }
+            
+        }
+        
+        return status;
+    }
 
-			if(options.nchannels == 4)
-				result[3] = 1.0f;
-		}
-
-	}
-
-	return status;
-}
-
 bool OSLRenderServices::environment(ustring filename, TextureOpt &options,
                                     OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
                                     const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result)

Modified: branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.h
===================================================================
--- branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.h	2013-07-31 14:15:40 UTC (rev 58768)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.h	2013-07-31 15:48:10 UTC (rev 58769)
@@ -30,7 +30,7 @@
 #include <OSL/oslexec.h>
 #include <OSL/oslclosure.h>
 
-//#include <textures/openvdb_volume.h>
+#include <textures/openvdb_volume.h>
 
 CCL_NAMESPACE_BEGIN
 
@@ -151,6 +151,7 @@
 private:
 	KernelGlobals *kernel_globals;
 	OSL::TextureSystem *osl_ts;
+    ccl::VDBTextureSystem *vdb_ts;
 };
 
 CCL_NAMESPACE_END

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-07-31 14:15:40 UTC (rev 58768)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp	2013-07-31 15:48:10 UTC (rev 58769)
@@ -16,51 +16,98 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+
 #include "openvdb_volume.h"
+#include <openvdb/openvdb.h>
 
 CCL_NAMESPACE_BEGIN
 
+typedef struct VDBVolumeFile {
+	openvdb::io::File file;
+    ustring version;
+    
+	openvdb::GridPtrVecPtr grids;
+    openvdb::MetaMap::Ptr meta;
+    
+    VDBVolumeFile(ustring filename) : file(filename.string())
+    {
+        file.open();
+        
+        grids = file.getGrids();
+        meta = file.getMetadata();
+        version = file.version();
+    }
+    ~VDBVolumeFile()
+    {
+        file.close();
+    }
+} VDBVolumeFile;
+
+class OpenVDBUtil
+{
+public:
+    static ustring u_openvdb_file_extension;
+    
+	static void initialize_library();
+	static bool open_file(OIIO::ustring filename, VDBVolumeFile &vdb_volume);
+	static bool is_vdb_volume_file(OIIO::ustring filename);
+    static VDBVolumeFile *get_volume_from_file(OIIO::ustring filename);
+    
+private:
+    static bool vdb_file_check_extension(ustring filename);
+    static bool vdb_file_check_valid_header(ustring filename);
+};
+
+
 /* static ustrings */
 ustring OpenVDBUtil::u_openvdb_file_extension(".vdb");
 
+class OpenVDBVolumeAccessor {
+public:
+private:
+	openvdb::GridBase::Ptr grid;
+	eOpenVDBGridType grid_type; // Is this really necessary? Check OpenVDB's generic programming guidelines.
+};
+
+
 void OpenVDBUtil::initialize_library()
-{ //any additional configuration needed?
+{
+    //any additional configuration needed?
 	openvdb::initialize();
 }
 
 
-bool OpenVDBUtil::open_file(OIIO::ustring filename, OpenVDBVolume &vdb_volume)
+bool OpenVDBUtil::open_file(OIIO::ustring filename, VDBVolumeFile &vdb_volume)
 {
-	openvdb::io::File file(filename.string());
-
-	file.open();
-	openvdb::GridPtrVecPtr grids = file.getGrids();
+    // Assumes file has been checked for existence and integrity.
+    VDBVolumeFile myFileHandle(filename);
+    
+    
+	//openvdb::GridPtrVecPtr grids = file.getGrids();
 	
-	file.close();
-
 	// Build OpenVDBVolume
 	//OpenVDBVolume vdb_volume(file, grids);
-
+    
 	//return vdb_volume;
 	return true;
-} 
+}
 
 bool OpenVDBUtil::vdb_file_check_valid_header(ustring filename)
 {
     OpenVDBUtil::initialize_library();
-		openvdb::io::File file(filename.string());
-		file.open();
-        
-        OIIO::ustring openvdb_version;
-
-		openvdb_version.empty();
-		openvdb_version = file.version();
-        
-        file.close();
-
-		if(openvdb_version.length() > 0)
-			return true;
-
+    openvdb::io::File file(filename.string());
+    file.open();
+    
+    OIIO::ustring openvdb_version;
+    
+    openvdb_version.empty();
+    openvdb_version = file.version();
+    
+    file.close();
+    
+    if(openvdb_version.length() > 0)
+        return true;
+    
 	return false;
 }
 
@@ -73,6 +120,7 @@
     return false;
 }
 
+
 bool OpenVDBUtil::is_vdb_volume_file(OIIO::ustring filename)
 {
     OIIO::ustring openvdb_version;
@@ -85,4 +133,50 @@
     return false;
 }
 
-CCL_NAMESPACE_END
\ No newline at end of file
+VDBVolumeFile *OpenVDBUtil::get_volume_from_file(ustring filename)
+{
+    VDBVolumeFile vdb_volume(filename);
+    return &vdb_volume;
+}
+
+// VDBTextureSystem
+VDBTextureSystem *VDBTextureSystem::init() {
+    OpenVDBUtil::initialize_library();
+    VDBTextureSystem vdb_ts;
+    
+    return &vdb_ts;
+}
+
+bool VDBTextureSystem::is_vdb_volume(ustring 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)
+{
+    // TODO:
+    // - check if file is open and mapped;
+    OpenVDBMap::const_iterator open_file = vdb_files.find(filename);
+    
+    if (open_file == vdb_files.end())
+    {
+        // open file;
+        // add it to map
+    }
+    else
+    {
+        // file is open;
+    }
+
+    // perform lookup.
+    
+    return false;
+}
+
+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-07-31 14:15:40 UTC (rev 58768)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h	2013-07-31 15:48:10 UTC (rev 58769)
@@ -19,9 +19,10 @@
 #ifndef __OPENVDB_VOLUME_H__
 #define __OPENVDB_VOLUME_H__
 
-#include <openvdb/openvdb.h>
 #include <OSL/oslexec.h>
+#include "util_map.h"
 
+
 CCL_NAMESPACE_BEGIN
 
 using namespace OIIO;
@@ -35,40 +36,32 @@
 	OPENVDB_GRID_TYPE_VEC3F
 } eOpenVDBGridType;
 
-typedef struct OpenVDBVolume { //increasingly, it seems OpenVDBVolume should actually be OpenVDBVolumeCollection; checking with Brecht.
-	//TODO: wip: handles for file, sampling mechanism and pointer to grid(s): each file might contain more than 1 grid;
-	openvdb::io::File file;
-	openvdb::GridPtrVecPtr grids;
+struct VDBVolumeFile;
+class OpenVDBVolumeAccessor;
+class OpenVDBUtil;
 
-	
-} OpenVDBVolume;
-
-class OpenVDBVolumeAccessor {
+class VDBTextureSystem {
 public:
+    static VDBTextureSystem *init();
+    static void terminate (VDBTextureSystem *vdb_ts);
+    
+    VDBTextureSystem() { }
+    ~VDBTextureSystem() { }
+    
+    typedef unordered_map<ustring, VDBVolumeFile*, ustringHash> OpenVDBMap;
+    
+    bool is_vdb_volume (ustring filename);
+    
+    bool 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);
+    
 private:
-	openvdb::GridBase::Ptr grid;
-	eOpenVDBGridType grid_type; // Is this really necessary? Check OpenVDB's generic programming guidelines.
-	
+    OpenVDBMap vdb_files;
 };
 
-class OpenVDBUtil
-{
-public:
-	static void initialize_library();
-	static bool open_file(OIIO::ustring filename, OpenVDBVolume &vdb_volume);
-	
 
-    static bool is_vdb_volume_file(OIIO::ustring filename);
-
-	static ustring u_openvdb_file_extension;
-private:
-    static bool vdb_file_check_extension(ustring filename);
-    static bool vdb_file_check_valid_header(ustring filename);
-	int i;
-};
-
-
-
 CCL_NAMESPACE_END
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list