[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59613] branches/soc-2013-cycles_volume/ intern/cycles/kernel: - added grid selection: if a grid is specified by name in OIIO's TextureOpt, we search for it, and return false in the lookup if it isn't found; if it isn' t specified by name, we take the first grid in the file;
Rafael Campos
rafaelcdn at gmail.com
Wed Aug 28 21:40:16 CEST 2013
Revision: 59613
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59613
Author: jehuty
Date: 2013-08-28 19:40:16 +0000 (Wed, 28 Aug 2013)
Log Message:
-----------
- added grid selection: if a grid is specified by name in OIIO's TextureOpt, we search for it, and return false in the lookup if it isn't found; if it isn't specified by name, we take the first grid in the file;
- code reorganization: code was split in more files, separating the utility functions from the VDBVolumeFile struct;
- initial version of a templated lookup method for compatibility with any vdb grid type.
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/CMakeLists.txt
Added Paths:
-----------
branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/vdb_definitions.h
branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/vdb_lookup.h
branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/vdb_util.h
branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/vdb_volume.cpp
branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/vdb_volume.h
Removed Paths:
-------------
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-28 19:23:15 UTC (rev 59612)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.cpp 2013-08-28 19:40:16 UTC (rev 59613)
@@ -818,10 +818,10 @@
if (VDBTextureSystem::valid_vdb_file(filename)) {
VDBTextureSystem::Ptr volume_ts = vdb_ts;
- //std::cout << "Before lookup. FILE: " << filename.string() << " ; POINT: " << P << std::endl;
+ 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;
+ 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-28 19:23:15 UTC (rev 59612)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/osl/osl_services.h 2013-08-28 19:40:16 UTC (rev 59613)
@@ -30,7 +30,7 @@
#include <OSL/oslexec.h>
#include <OSL/oslclosure.h>
-#include <textures/openvdb_volume.h>
+#include <textures/vdb_volume.h>
CCL_NAMESPACE_BEGIN
Modified: branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/CMakeLists.txt
===================================================================
--- branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/CMakeLists.txt 2013-08-28 19:23:15 UTC (rev 59612)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/CMakeLists.txt 2013-08-28 19:40:16 UTC (rev 59613)
@@ -13,11 +13,14 @@
)
set(SRC
- openvdb_volume.cpp
+ vdb_volume.cpp
)
set(HEADER_SRC
- openvdb_volume.h
+ vdb_definitions.h
+ vdb_volume.h
+ vdb_lookup.h
+ vdb_util.h
)
include_directories(${INC})
Deleted: 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-28 19:23:15 UTC (rev 59612)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.cpp 2013-08-28 19:40:16 UTC (rev 59613)
@@ -1,201 +0,0 @@
-/*
- * Copyright 2013, Blender Foundation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * 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);
- static int get_number_of_grids(VDBVolumeFile vdb_volume);
- static int nearest_neighbor(float worldCoord);
-
-private:
- static bool vdb_file_format(ustring filename);
- static bool valid_file(ustring filename);
-};
-
-
-/* static ustrings */
-ustring OpenVDBUtil::u_openvdb_file_extension(".vdb");
-
-
-void OpenVDBUtil::initialize_library()
-{
- openvdb::initialize();
-}
-
-// Open file to check header information and determine
-// if file is a valid VDB volume.
-bool OpenVDBUtil::valid_file(ustring filename)
-{
- OIIO::ustring openvdb_version;
- openvdb::io::File file(filename.string());
-
- 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;
- }
-
- if(openvdb_version.length() > 0)
- return true;
-
- return false;
-}
-
-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)
- return true;
-
- return false;
-}
-
-
-bool OpenVDBUtil::is_vdb_volume_file(OIIO::ustring filename)
-{
- if (vdb_file_format(filename)) {
- if (valid_file(filename))
- return true;
- }
-
- return false;
-}
-
-
-int OpenVDBUtil::get_number_of_grids(VDBVolumeFile vdb_volume)
-{
- return vdb_volume.grids->size();
-}
-
-int OpenVDBUtil::nearest_neighbor(float worldCoord)
-{
- int x = static_cast<int>(floor(worldCoord + 0.5));
- return x;
-}
-
-
-// VDBTextureSystem
-
-VDBTextureSystem::Ptr VDBTextureSystem::init() {
- OpenVDBUtil::initialize_library();
- Ptr vdb_ts(new VDBTextureSystem());
-
- return vdb_ts;
-}
-
-bool VDBTextureSystem::valid_vdb_file(ustring filename)
-{
- return OpenVDBUtil::is_vdb_volume_file(filename);
-}
-
-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;
- VDBMap::const_iterator open_file = vdb_files.find(filename);
-
- if (open_file == vdb_files.end())
- {
- open_file = add_vdb_to_map(filename);
- }
-
- VDBFilePtr vdb_p = open_file->second;
-
- 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)
-{
- VDBFilePtr vdb_sp(new VDBVolumeFile(filename));
-
- return (vdb_files.insert(std::make_pair(filename, vdb_sp))).first;
-}
-
-void VDBTextureSystem::free(VDBTextureSystem::Ptr &vdb_ts)
-{
- vdb_ts.reset();
-}
-
-CCL_NAMESPACE_END
Deleted: 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-28 19:23:15 UTC (rev 59612)
+++ branches/soc-2013-cycles_volume/intern/cycles/kernel/textures/openvdb_volume.h 2013-08-28 19:40:16 UTC (rev 59613)
@@ -1,59 +0,0 @@
-/*
- * Copyright 2013, Blender Foundation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef __OPENVDB_VOLUME_H__
-#define __OPENVDB_VOLUME_H__
-
-#include <OSL/oslexec.h>
-#include "util_map.h"
-
-using namespace OIIO;
-
-CCL_NAMESPACE_BEGIN
-
-struct VDBVolumeFile;
-class OpenVDBVolumeAccessor;
-class OpenVDBUtil;
-
-class VDBTextureSystem {
-public:
- 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 free (VDBTextureSystem::Ptr &vdb_ts);
-
- static bool valid_vdb_file (ustring filename);
-
- 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);
-
- VDBTextureSystem() { }
- ~VDBTextureSystem() { }
-
-private:
- 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
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list