[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59211] branches/soc-2013-cycles_volume/ intern/cycles: - changed memory allocation of both VDBTextureSystem and each VDBVolumeFile stored in the VDBTextureSystem 's map to use smart pointers;
Rafael Campos
rafaelcdn at gmail.com
Sat Aug 17 15:10:35 CEST 2013
Revision: 59211
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59211
Author: jehuty
Date: 2013-08-17 13:10:35 +0000 (Sat, 17 Aug 2013)
Log Message:
-----------
- changed memory allocation of both VDBTextureSystem and each VDBVolumeFile stored in the VDBTextureSystem's map to use smart pointers;
- implemented naive interpolation for texture lookup (nearest neighbor);
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/intern/cycles/openvdb_app/CMakeLists.txt
branches/soc-2013-cycles_volume/intern/cycles/openvdb_app/cycles_openvdb_test.cpp
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-17 13:08:09 UTC (rev 59210)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp 2013-08-17 13:10:35 UTC (rev 59211)
@@ -102,6 +102,7 @@
OSLRenderServices::~OSLRenderServices()
{
+ VDBTextureSystem::destroy(vdb_ts);
}
void OSLRenderServices::thread_init(KernelGlobals *kernel_globals_, OSL::TextureSystem *osl_ts_)
@@ -793,10 +794,12 @@
{
bool status = false;
- VDBTextureSystem *volume_ts = vdb_ts;
+ VDBTextureSystem::Ptr volume_ts = vdb_ts;
if (volume_ts->is_vdb_volume(filename))
{
- volume_ts->perform_lookup(filename, options, sg, P, dPdx, dPdy, dPdz, result);
+ 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
{
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-08-17 13:08:09 UTC (rev 59210)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.h 2013-08-17 13:10:35 UTC (rev 59211)
@@ -151,7 +151,7 @@
private:
KernelGlobals *kernel_globals;
OSL::TextureSystem *osl_ts;
- ccl::VDBTextureSystem *vdb_ts;
+ ccl::VDBTextureSystem::Ptr 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-08-17 13:08:09 UTC (rev 59210)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp 2013-08-17 13:10:35 UTC (rev 59211)
@@ -22,13 +22,13 @@
CCL_NAMESPACE_BEGIN
-typedef struct VDBVolumeFile {
+typedef struct VDBVolumeFile {
openvdb::io::File file;
ustring version;
openvdb::GridPtrVecPtr grids;
openvdb::MetaMap::Ptr meta;
-
+
VDBVolumeFile(ustring filename) : file(filename.string())
{
file.open();
@@ -41,6 +41,23 @@
{
file.close();
}
+
+ VDBVolumeFile(const VDBVolumeFile& vdb_file) : file(vdb_file.file.filename())
+ {
+ // file should be open already;
+ if(file.isOpen())
+ {
+ std::cout << "Filename: " << this->file.filename() << ".\n";
+ // file.open();
+
+ grids = file.getGrids();
+ meta = file.getMetadata();
+ version = file.version();
+ }
+
+
+ }
+
} VDBVolumeFile;
class OpenVDBUtil
@@ -52,7 +69,8 @@
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);
- static int get_number_of_grids(VDBVolumeFile *vdb_volume);
+ static int get_number_of_grids(VDBVolumeFile vdb_volume);
+ static int nearest_neighbor(float worldCoord);
private:
static bool vdb_file_check_extension(ustring filename);
@@ -124,23 +142,36 @@
return &vdb_volume;
}
-int OpenVDBUtil::get_number_of_grids(VDBVolumeFile *vdb_volume)
+int OpenVDBUtil::get_number_of_grids(VDBVolumeFile vdb_volume)
{
- return vdb_volume->grids->size();
+ return vdb_volume.grids->size();
}
+int OpenVDBUtil::nearest_neighbor(float worldCoord)
+{
+ int x = static_cast<int>(floor(worldCoord + 0.5));
+ return x;
+}
// VDBTextureSystem
-VDBTextureSystem *VDBTextureSystem::init() {
+
+VDBTextureSystem::Ptr VDBTextureSystem::init() {
OpenVDBUtil::initialize_library();
- VDBTextureSystem vdb_ts;
- return &vdb_ts;
+ Ptr vdb_ts(new VDBTextureSystem());
+
+ return vdb_ts;
}
bool VDBTextureSystem::is_vdb_volume(ustring filename)
{
- if (vdb_files.find(filename) != vdb_files.end())
+
+ //testing things out
+ if (get_map().empty())
+ {
+ return OpenVDBUtil::is_vdb_volume_file(filename);
+ }
+ if (get_map().find(filename) != get_map().end())
return true;
else
return OpenVDBUtil::is_vdb_volume_file(filename);
@@ -152,35 +183,64 @@
float *result)
{
// - check if file is open;
- OpenVDBMap::const_iterator open_file = vdb_files.find(filename);
+ VDBMap::const_iterator open_file = vdb_files.find(filename);
if (open_file == vdb_files.end())
{
- VDBVolumeFile file(filename);
-
- // add it to map
- open_file = (vdb_files.insert(std::make_pair(filename, &file))).first;
+ open_file = add_vdb_to_map(filename);
}
- VDBVolumeFile *myVDB = open_file->second;
- openvdb::GridPtrVecIter iter = myVDB->grids->begin();
+ VDBFilePtr vdb_p = open_file->second;
- if (OpenVDBUtil::get_number_of_grids(myVDB) == 1) {
+ //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 (OpenVDBUtil::get_number_of_grids(myVDB) != 1) {
// Name of the grid will be unimportant if it's the only one present in the file.
- }
- else
- {
- for(iter = myVDB->grids->begin(); iter != myVDB->grids->end(); ++iter)
- {
- openvdb::GridBase::Ptr grid = *iter;
- // Traversal is needed to find the correct grid by name;
- }
- }
+
+ do {
+ ++iter;
+ } while (iter != myVDB.grids->end());
+
+ } */
// perform lookup.
- return false;
+ //return false;
}
+VDBTextureSystem::VDBMap::const_iterator VDBTextureSystem::add_vdb_to_map(ustring filename)
+{
+ VDBVolumeFile *vdb_sp = new VDBVolumeFile(filename);
+
+ return (vdb_files.insert(std::make_pair(filename, vdb_sp))).first;
+}
+
+VDBTextureSystem::VDBMap VDBTextureSystem::get_map()
+{
+ return vdb_files;
+}
+
+
+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-17 13:08:09 UTC (rev 59210)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h 2013-08-17 13:10:35 UTC (rev 59211)
@@ -36,32 +36,36 @@
OPENVDB_GRID_TYPE_VEC3F
} eOpenVDBGridType;
+
struct VDBVolumeFile;
class OpenVDBVolumeAccessor;
class OpenVDBUtil;
class VDBTextureSystem {
public:
- static VDBTextureSystem *init();
- static void terminate (VDBTextureSystem *vdb_ts);
+ typedef boost::shared_ptr<VDBVolumeFile> VDBFilePtr;
+ typedef unordered_map<ustring, VDBFilePtr, ustringHash> VDBMap;
+ typedef boost::shared_ptr<VDBTextureSystem> Ptr;
+ static VDBTextureSystem::Ptr init();
+ static void destroy (VDBTextureSystem::Ptr vdb_ts);
+
VDBTextureSystem() { }
- ~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);
+ VDBMap get_map();
private:
- OpenVDBMap vdb_files;
+ VDBMap vdb_files;
+ VDBMap::const_iterator add_vdb_to_map(ustring filename);
};
-
CCL_NAMESPACE_END
#endif /* __OPENVDB_VOLUME_H__ */
\ No newline at end of file
Modified: branches/soc-2013-cycles_volume/intern/cycles/openvdb_app/CMakeLists.txt
===================================================================
--- branches/soc-2013-cycles_volume/intern/cycles/openvdb_app/CMakeLists.txt 2013-08-17 13:08:09 UTC (rev 59210)
+++ branches/soc-2013-cycles_volume/intern/cycles/openvdb_app/CMakeLists.txt 2013-08-17 13:10:35 UTC (rev 59211)
@@ -3,10 +3,12 @@
.
)
set(INC_SYS
+ ../util
../kernel/textures
)
set(LIBRARIES
+ cycles_util
cycles_kernel_textures
${BOOST_LIBRARIES}
${OPENGL_LIBRARIES}
Modified: branches/soc-2013-cycles_volume/intern/cycles/openvdb_app/cycles_openvdb_test.cpp
===================================================================
--- branches/soc-2013-cycles_volume/intern/cycles/openvdb_app/cycles_openvdb_test.cpp 2013-08-17 13:08:09 UTC (rev 59210)
+++ branches/soc-2013-cycles_volume/intern/cycles/openvdb_app/cycles_openvdb_test.cpp 2013-08-17 13:10:35 UTC (rev 59211)
@@ -295,21 +295,14 @@
void
checkForValidFile(std::string filename)
{
- std::cout << "I was here! Yeah!" << std::endl;
+ std::cout << "Debug: Checking for file." << std::endl;
OpenImageIO::ustring u_filename(filename);
- if (ccl::OpenVDBUtil::is_vdb_volume_file(u_filename))
- std::cout << "Valid VDB file." << std::endl;
+ // if (ccl::OpenVDBUtil::is_vdb_volume_file(u_filename))
+ // std::cout << "Valid VDB file." << std::endl;
}
-/*void
-openVdbVolumeFile()
-{
- OIIO::ustring testFile("R:\Documents\Projects\openvdbProjects\OpenVDB_Hello_World\OpenVDB_Hello_World");
-// ccl::OpenVDBVolume::open_file(testFile);
-}
-*/
} // unnamed namespace
More information about the Bf-blender-cvs
mailing list