[Bf-blender-cvs] [8b9abeb] soc-2014-fluid: methods for adding texture values to grids, working for Real type
Roman Pogribnyi
noreply at git.blender.org
Tue Oct 21 23:09:44 CEST 2014
Commit: 8b9abeb8e05942ce5b55f3683e772c1789eb6b70
Author: Roman Pogribnyi
Date: Fri Oct 17 17:37:53 2014 +0200
Branches: soc-2014-fluid
https://developer.blender.org/rB8b9abeb8e05942ce5b55f3683e772c1789eb6b70
methods for adding texture values to grids, working for Real type
===================================================================
M source/blender/python/manta_pp/grid.cpp
M source/blender/python/manta_pp/grid.h
M source/blender/python/manta_pp/grid.h.reg
M source/blender/python/manta_pp/grid.h.reg.cpp
===================================================================
diff --git a/source/blender/python/manta_pp/grid.cpp b/source/blender/python/manta_pp/grid.cpp
index d72c9d6..1f1d698 100644
--- a/source/blender/python/manta_pp/grid.cpp
+++ b/source/blender/python/manta_pp/grid.cpp
@@ -348,7 +348,7 @@ template<class T> void Grid<T>::writeGridToMemory(const std::string& memLoc, con
memcpy(gridPointer, mData, sizeAllowed_num);
}
-template<class T> void Grid<T>::readGridFromMemory(const std::string& memLoc, const std::string gridName, int x, int y, int z)
+template<class T> void Grid<T>::readGridFromMemory(const std::string& memLoc, const std::string& gridName, int x, int y, int z)
{
if (memLoc == "" ||memLoc == "0" ){
debMsg("Can not write grid to NULL pointer",1);
@@ -365,7 +365,7 @@ template<class T> void Grid<T>::readGridFromMemory(const std::string& memLoc, co
memcpy(mData, gridPointer, sizeof(T) * x * y * z);
}
-template<class T> void Grid<T>::readAdaptiveGridFromMemory(const std::string& memLoc, const std::string gridName, Vec3i minSize, Vec3i maxSize)
+template<class T> void Grid<T>::readAdaptiveGridFromMemory(const std::string& memLoc, const std::string& gridname, Vec3i minSize, Vec3i maxSize)
{
if (memLoc == "" ||memLoc == "0" ){
debMsg("Can not write grid to NULL pointer",1);
@@ -379,7 +379,7 @@ template<class T> void Grid<T>::readAdaptiveGridFromMemory(const std::string& me
debMsg("Adaptive grid larger than current",1);
return;
}
- Vec3i adaptiveSize = maxSize - minSize;
+ Vec3i adaptiveSize = maxSize - minSize + Vec3i(1);
stringstream ss(memLoc);
void *gridPointer = NULL;
ss >> gridPointer;
@@ -387,12 +387,27 @@ template<class T> void Grid<T>::readAdaptiveGridFromMemory(const std::string& me
for (int x = 0; x < adaptiveSize.x; ++x){
for (int y = 0; y < adaptiveSize.y; ++y){
for (int z = 0; z < adaptiveSize.z; ++z){
- get(x + minSize.x, y + minSize.y, z + minSize.z) = data_Array[(x) + adaptiveSize.x * (y ) + adaptiveSize.x * adaptiveSize.y * (z)];
+ get(x + minSize.x, y + minSize.y, z + minSize.z) = data_Array[(x + minSize.x) + adaptiveSize.x * (y + minSize.y) + adaptiveSize.x * adaptiveSize.y * (z + minSize.z)];
}
}
}
}
+//! Kernel: Apply a texture to a grid, setting texture(ijk)*value where texture(ijk) > 0
+//note: can not use template kernel here, because of Blender classes
+
+ struct ApplyTextureToRealGrid : public KernelBase { ApplyTextureToRealGrid(Grid<Real> *grid, Grid<Real> *texture, Real value, FlagGrid* respectFlags) : KernelBase(grid,0) ,grid(grid),texture(texture),value(value),respectFlags(respectFlags) { run(); } inline void op(int i, int j, int k, Grid<Real> *grid, Grid<Real> *texture, Real value, FlagGrid* respectFlags ) {
+ if (respectFlags && respectFlags->isObstacle(i,j,k))
+ return;
+ if ((*texture)(i,j,k) > 0)
+ (*grid)(i,j,k) = (*texture)(i,j,k) * value;
+} inline Grid<Real> * getArg0() { return grid; } typedef Grid<Real> type0;inline Grid<Real> * getArg1() { return texture; } typedef Grid<Real> type1;inline Real& getArg2() { return value; } typedef Real type2;inline FlagGrid* getArg3() { return respectFlags; } typedef FlagGrid type3; void run() { const int _maxX = maxX; const int _maxY = maxY; for (int k=minZ; k< maxZ; k++) for (int j=0; j< _maxY; j++) for (int i=0; i< _maxX; i++) op(i,j,k, grid,texture,value,respectFlags); } Grid< [...]
+
+template<class T> void Grid<T>::applyToGrid(GridBase *grid, FlagGrid* respectFlags)
+{
+ if (this->getType() & GridBase::TypeReal)
+ ApplyTextureToRealGrid((Grid<Real>*)grid, (Grid<Real>*)this, _args.get<Real>("value"), respectFlags);
+}
// helper functions for UV grid data (stored grid coordinates as Vec3 values, and uv weight in entry zero)
diff --git a/source/blender/python/manta_pp/grid.h b/source/blender/python/manta_pp/grid.h
index 9ba0a7c..97b1b86 100644
--- a/source/blender/python/manta_pp/grid.h
+++ b/source/blender/python/manta_pp/grid.h
@@ -33,7 +33,8 @@
namespace Manta {
class LevelsetGrid;
-
+class FlagGrid;
+
//! Base class for all grids
class GridBase : public PbClass {public:
enum GridType { TypeNone = 0, TypeReal = 1, TypeInt = 2, TypeVec3 = 4, TypeMAC = 8, TypeLevelset = 16, TypeFlags = 32 };
@@ -188,8 +189,10 @@ template<class T> class Grid : public GridBase {public:
//! write and read grid data to pointed memory
void writeGridToMemory(const std::string& memLoc, const std::string& sizeAllowed); static PyObject* _W_19 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::writeGridToMemory"); PyObject *_retval = 0; { ArgLocker _lock; const std::string& memLoc = _args.get<std::string >("memLoc",0,&_lock); const std::string& sizeAllowed = _args.get<std::string >("si [...]
- void readGridFromMemory(const std::string& memLoc, const std::string gridName, int x, int y, int z); static PyObject* _W_20 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::readGridFromMemory"); PyObject *_retval = 0; { ArgLocker _lock; const std::string& memLoc = _args.get<std::string >("memLoc",0,&_lock); const std::string gridName = _args.get<st [...]
- void readAdaptiveGridFromMemory(const std::string& memLoc, const std::string gridName, Vec3i min, Vec3i max); static PyObject* _W_21 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::readAdaptiveGridFromMemory"); PyObject *_retval = 0; { ArgLocker _lock; const std::string& memLoc = _args.get<std::string >("memLoc",0,&_lock); const std::string gridNa [...]
+ void readGridFromMemory(const std::string& memLoc, const std::string& gridname, int x, int y, int z); static PyObject* _W_20 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::readGridFromMemory"); PyObject *_retval = 0; { ArgLocker _lock; const std::string& memLoc = _args.get<std::string >("memLoc",0,&_lock); const std::string& gridname = _args.get< [...]
+ void readAdaptiveGridFromMemory(const std::string& memLoc, const std::string& gridname, Vec3i min, Vec3i max); static PyObject* _W_21 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::readAdaptiveGridFromMemory"); PyObject *_retval = 0; { ArgLocker _lock; const std::string& memLoc = _args.get<std::string >("memLoc",0,&_lock); const std::string& grid [...]
+ //! Applies texture to grid, as in Shape::applyToGrid
+ void applyToGrid(GridBase *grid, FlagGrid* respectFlags = 0); static PyObject* _W_22 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::applyToGrid"); PyObject *_retval = 0; { ArgLocker _lock; GridBase* grid = _args.getPtr<GridBase >("grid",0,&_lock); FlagGrid* respectFlags = _args.getPtrOpt<FlagGrid >("respectFlags",1,0,&_lock); pbo->_args.copy(_ar [...]
// c++ only operators
template<class S> Grid<T>& operator+=(const Grid<S>& a);
template<class S> Grid<T>& operator+=(const S& a);
@@ -216,7 +219,7 @@ protected: T* mData; public: PbArgs _args;}
//! Special function for staggered grids
class MACGrid : public Grid<Vec3> {public:
MACGrid(FluidSolver* parent, bool show=true) :Grid<Vec3>(parent,show){
- mType = (GridType)(TypeMAC | TypeVec3); } static int _W_22 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list