[Bf-blender-cvs] [b3413a0] soc-2014-fluid: passing inflow adaptive grids without disk files

Roman Pogribnyi noreply at git.blender.org
Wed Oct 15 19:53:45 CEST 2014


Commit: b3413a07b4d1c32e0d0a5f4ca00a564094b390db
Author: Roman Pogribnyi
Date:   Wed Oct 15 19:51:35 2014 +0200
Branches: soc-2014-fluid
https://developer.blender.org/rBb3413a07b4d1c32e0d0a5f4ca00a564094b390db

passing inflow adaptive grids without disk files

===================================================================

M	intern/smoke/intern/MANTA.cpp
M	intern/smoke/intern/MANTA.h
M	intern/smoke/intern/scenarios/smoke.h
M	intern/smoke/intern/smoke_API.cpp
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
M	source/blender/python/manta_pp/pwrapper/pymain.cpp

===================================================================

diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index c73c746..38d8c5d 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -339,6 +339,51 @@ void Manta_API::stop_manta_sim()
 	pthread_cancel(manta_thread);
 }
 
+void Manta_API::addGrid(float * data, string name, int x, int y, int z)
+{
+	std::ostringstream stringStream;
+	stringStream << "temp_" << name;
+	std::string grid_name = stringStream.str();
+	stringStream.str("");
+	stringStream << grid_name << " = s.create(RealGrid)";
+	const std::string command_1 = stringStream.str();
+	stringStream.str("");
+	stringStream << grid_name << ".readGridFromMemory("<< data << "," << x << "," << z << "," << y << ")";
+	const std::string command_2 = stringStream.str();
+	const std::string command_3 = name + ".add(" + grid_name + ")";
+	PyGILState_STATE gilstate = PyGILState_Ensure();
+	PyRun_SimpleString(command_1.c_str());
+	PyRun_SimpleString(command_2.c_str());
+	PyRun_SimpleString(command_3.c_str());
+	PyGILState_Release(gilstate);		
+}
+
+void Manta_API::addAdaptiveGrid(float * data, string name, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
+{
+	if (data == NULL)
+	{
+		cout << "NULL pointer passed to grid addAdaptiveGrid for grid " << name <<endl;
+		return;
+	}
+	std::ostringstream stringStream;
+	stringStream << "temp_" << name;
+	std::string grid_name = stringStream.str();
+	stringStream.str("");
+	stringStream << grid_name << " = s.create(RealGrid)";
+	const std::string command_1 = stringStream.str();
+	stringStream.str("");
+	stringStream << grid_name << ".readAdaptiveGridFromMemory(\'"<< data << "\',\'" << name << "\', vec3(" << minX << "," << minY << "," << minZ << 
+	"), vec3(" << maxX << "," << maxY << "," << maxZ << ") )";
+	const std::string command_2 = stringStream.str();
+	const std::string command_3 = name + ".add(" + grid_name + ")";
+	PyGILState_STATE gilstate = PyGILState_Ensure();
+	PyRun_SimpleString("print('Reading Adaptive grid from memory')");
+	PyRun_SimpleString("print (s)");
+	PyRun_SimpleString(command_1.c_str());
+	PyRun_SimpleString(command_2.c_str());
+	PyRun_SimpleString(command_3.c_str());
+	PyGILState_Release(gilstate);		
+}
 
 void Manta_API::run_manta_sim_thread(void *arguments)
 {
diff --git a/intern/smoke/intern/MANTA.h b/intern/smoke/intern/MANTA.h
index 8d94213..de82be7 100644
--- a/intern/smoke/intern/MANTA.h
+++ b/intern/smoke/intern/MANTA.h
@@ -14,7 +14,7 @@
 #include "../../../source/blender/blenlib/BLI_path_util.h"
 
 void export_force_fields(int size_x, int size_y, int size_z, float *f_x, float*f_y, float*f_z);/*defined in pymain.cpp*/
-void export_em_fields(float flow_density, int min_x, int min_y, int min_z, int max_x, int max_y, int max_z, int d_x, int d_y, int d_z, float *inf, float *vel);/*defined in pymain.cpp*/
+void export_em_fields(float *em_map, float flow_density, int min_x, int min_y, int min_z, int max_x, int max_y, int max_z, int d_x, int d_y, int d_z, float *inf, float *vel);/*defined in pymain.cpp*/
 extern "C" void manta_write_effectors(struct Scene *s, struct SmokeModifierData *smd); /*defined in smoke_api.cpp*/
 void runMantaScript(const string& ss,vector<string>& args);//defined in manta_pp/pwrapper/pymain.cpp
 
@@ -38,6 +38,7 @@ private:
 	Manta_API(const Manta_API &);	 
 	Manta_API & operator=(const Manta_API &);
 public:
+	float *_emission_map;
 	static Manta_API *instance();
 	void step(float dt, float gravity[3]);
 //	void runMantaScript(const string&, vector<string>& args);//defined in manta_pp/pwrapper/pymain.cpp
@@ -81,6 +82,9 @@ public:
 	void parseFile(const string& setup_string, SmokeModifierData *sds);	
 	
 	pthread_t manta_thread;
+	
+	void addGrid(float * data,string name, int x, int y, int z);
+	static void addAdaptiveGrid(float * data, string name, int minX, int minY, int minZ, int maxX, int maxY, int maxZ);
 };
 
 
diff --git a/intern/smoke/intern/scenarios/smoke.h b/intern/smoke/intern/scenarios/smoke.h
index 29e1991..a6cf500 100644
--- a/intern/smoke/intern/scenarios/smoke.h
+++ b/intern/smoke/intern/scenarios/smoke.h
@@ -79,13 +79,15 @@ if $USE_WAVELETS$ and $UPRES$ > 0:\n\
 
 const string smoke_step_low = "def sim_step(t):\n\
   #load_once(source,'manta_flow.obj',dict_loaded)\n\
-  if t == 2:#loading data on first sim frame only\n\
-    print('First frame: loading flows and obstacles')\n\
-    source.load('manta_flow.obj')\n\
-    transform_back(source, gs)\n\
+  #if t == 2:#loading data on first sim frame only\n\
+  #  print('First frame: loading flows and obstacles')\n\
+  #  source.load('manta_flow.obj')\n\
+  #  transform_back(source, gs)\n\
+  print (\"Density \" , str(density))\n\
   #load emission data\n\
-  source_grid.load('manta_em_influence.uni')\n\
-  density.add(source_grid)\n\
+  #source_grid.load('manta_em_influence.uni')\n\
+  print (\"Source_Grid\" , str(source_grid))\n\
+  #density.add(source_grid)\n\
   #addForceField(flags=flags, vel=vel,force=forces)\n\
   \n\
   advectSemiLagrange(flags=flags, vel=vel, grid=density, order=$ADVECT_ORDER$)\n\
diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp
index 3182510..e5f420a 100644
--- a/intern/smoke/intern/smoke_API.cpp
+++ b/intern/smoke/intern/smoke_API.cpp
@@ -534,7 +534,9 @@ extern "C" void manta_write_effectors(struct Scene *s, struct SmokeModifierData
 extern "C" void manta_write_emitters(struct SmokeFlowSettings *sfs, int min_x, int min_y, int min_z, int max_x, int max_y, int max_z, int d_x, int d_y, int d_z,float *influence, float *vel)
 {
 //	manta_update_effectors(s, smd->domain->manta_obj, smd->domain, 0.1f);
-	export_em_fields(sfs->density, min_x,  min_y,  min_z,  max_x,  max_y,  max_z,  d_x,  d_y,  d_z,  influence,  vel);
+	Manta_API::addAdaptiveGrid(influence, "density", 
+										   min_x, min_y, min_z, max_x, max_y, max_z);
+//	export_em_fields(Manta_API::instance()->_emission_map,sfs->density, min_x,  min_y,  min_z,  max_x,  max_y,  max_z,  d_x,  d_y,  d_z,  influence,  vel);
 }
 
 extern "C" void smoke_mantaflow_stop_sim()
diff --git a/source/blender/python/manta_pp/grid.cpp b/source/blender/python/manta_pp/grid.cpp
index e5173d4..d72c9d6 100644
--- a/source/blender/python/manta_pp/grid.cpp
+++ b/source/blender/python/manta_pp/grid.cpp
@@ -127,6 +127,14 @@ void Grid<T>::save(string name) {
 		errMsg("file '" + name +"' filetype not supported");
 }
 
+template<class T>
+void Grid<T>::loadIncrement(string name) {
+	Grid<T> temp(*this);
+	temp.load(name);
+	for(int i=0; i< mSize[0] * mSize[1] * mSize[2]; ++i){
+		mData[i] += temp[i];
+	}
+}
 //******************************************************************************
 // Grid<T> operators
 
@@ -321,7 +329,7 @@ template<class T> void Grid<T>::printGrid(int zSlice, bool printIndex) {
 }
 
 
-template<class T> void Grid<T>::writeGridToMemory(const std::string& memLoc, const string& sizeAllowed)
+template<class T> void Grid<T>::writeGridToMemory(const std::string& memLoc, const std::string& sizeAllowed)
 {
 	if (memLoc == "" ||memLoc == "0" ){
 		debMsg("Cant write grid to NULL pointer",1);
@@ -339,6 +347,53 @@ template<class T> void Grid<T>::writeGridToMemory(const std::string& memLoc, con
 	ss >> gridPointer;
 	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)
+{
+	if (memLoc == "" ||memLoc == "0" ){
+		debMsg("Can not write grid to NULL pointer",1);
+		return;
+	}
+	if (x != mSize.x || y != mSize.y || z != mSize.z)
+	{
+		debMsg("Can not write grid with different domain size",1);
+		return;
+	}
+	stringstream ss(memLoc);
+	void *gridPointer = NULL;
+	ss >> gridPointer;
+	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)
+{
+	if (memLoc == "" ||memLoc == "0" ){
+		debMsg("Can not write grid to NULL pointer",1);
+		return;
+	}
+	if (minSize.x < 0 || minSize.y < 0 || minSize.z < 0){
+		debMsg("Adaptive grid smaller than 0",1);
+		return;
+	}
+	if (maxSize.x > mSize.x || maxSize.y > mSize.y || maxSize.z > mSize.z){
+		debMsg("Adaptive grid larger than current",1);
+		return;
+	}
+	Vec3i adaptiveSize = maxSize - minSize;
+	stringstream ss(memLoc);
+	void *gridPointer = NULL;
+	ss >> gridPointer;
+	float *data_Array = (float* )gridPointer;
+	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)];
+			}
+		}
+	}
+}
+
+
 // helper functions for UV grid data (stored grid coordinates as Vec3 values, and uv weight in entry zero)
 
 // make uv weight accesible in python
diff --git a/source/blender/python/manta_pp/grid.h b/source/blender/python/manta_pp/grid.h
index 9b7585f..9ba0a7c 100644
--- a/source/blender/python/manta_pp/grid.h
+++ b/source/blender/python/manta_pp/grid.h
@@ -106,9 +106,10 @@ template<class T> class Grid : public GridBase {public:
 	
 	void save(std::string name); static PyObject* _W_2 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::save"); PyObject *_retval = 0; { ArgLocker _lock; std::string name = _args.get<std::string >("name",0,&_lock);  pbo->_args.copy(_args);  _retval = getPyNone(); pbo->save(name);  pbo->_args.check(); } pbFinalizePlugin(pbo->getParent(),"Grid::save"); r [...]
 	void load(std::string name); static PyObject* _W_3 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); Grid* pbo = dynamic_cast<Grid*>(Pb::objFromPy(_self)); pbPreparePlugin(pbo->getParent(), "Grid::load"); PyObject *_retval = 0; { ArgLocker _lock; std::string name = _args.get<std::string >("name",0,&_lock);  pbo->_args.copy(_args);  _retval = getPyNone(); pbo->load(name);  pbo->_args.check(); } pbFinalizePlugin(pbo->getParent(),"Grid::load"); ret

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list