Commit: 4be4b5881661cc5332a2219fcd1c6439a861588d
Author: Sebastián Barschkis
Date:   Sat Jan 9 03:01:08 2016 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rB4be4b5881661cc5332a2219fcd1c6439a861588d

more manta api refactoring

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

M       intern/smoke/intern/FLUID_3D.cpp
M       intern/smoke/intern/MANTA.cpp
M       intern/smoke/intern/MANTA.h
M       intern/smoke/intern/WTURBULENCE.cpp
M       intern/smoke/intern/scenarios/smoke.h
M       intern/smoke/intern/smoke_API.cpp

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

diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index 7bb539e..86f4f2c 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -599,11 +599,22 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
        using_colors = false;
        
        smd->domain->fluid = this;
-//     vector<string> args;
-//     args.push_back("manta_scene.py");
-//     initializeMantaflow(args); /*need this to delete previous solvers and 
grids*/
+
        Manta_API::start_mantaflow();
-       Manta_API::run_manta_sim_file_lowRes(smd);
+       
+       // Base setup low res
+       std::string setup_script =
+               manta_import +
+               solver_setup_low +
+               alloc_base_grids_low +
+               noise_low +
+               prep_domain_low +
+               flags +
+               smoke_step_low;
+       std::string final_script = Manta_API::parse_script(setup_script, smd);
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       PyRun_SimpleString(final_script.c_str());
+       PyGILState_Release(gilstate);
        
        // Heat grids
        if (init_heat) {
@@ -626,9 +637,10 @@ void FLUID_3D::initHeat()
        if (!_heat) {
                using_heat = true;
                PyGILState_STATE gilstate = PyGILState_Ensure();
-               PyRun_SimpleString(smoke_init_heat_low.c_str());
+               PyRun_SimpleString(alloc_heat_low.c_str());
+               PyRun_SimpleString(with_heat.c_str());
                PyGILState_Release(gilstate);
-//             Manta_API::updatePointers(this);
+               Manta_API::update_pointers(this);
        }
 }
 
@@ -642,9 +654,11 @@ void FLUID_3D::initColors(float init_r, float init_g, 
float init_b)
                ss << "manta_color_g = " << init_g << endl;
                ss << "manta_color_b = " << init_b << endl;
                PyRun_SimpleString(ss.str().c_str());
-               PyRun_SimpleString(smoke_init_colors_low.c_str());
+               PyRun_SimpleString(alloc_colors_low.c_str());
+               PyRun_SimpleString(init_colors_low.c_str());
+               PyRun_SimpleString(with_fire.c_str());
                PyGILState_Release(gilstate);
-//             Manta_API::updatePointers(this);
+               Manta_API::update_pointers(this);
        }
 }
 
@@ -653,20 +667,27 @@ void FLUID_3D::initFire()
        if (!_flame) {
                using_fire = true;
                PyGILState_STATE gilstate = PyGILState_Ensure();
-               PyRun_SimpleString(smoke_init_fire_low.c_str());
+               PyRun_SimpleString(alloc_fire_low.c_str());
+               PyRun_SimpleString(with_fire.c_str());
                PyGILState_Release(gilstate);
-//             Manta_API::updatePointers(this);
+               Manta_API::update_pointers(this);
        }
 }
 
 FLUID_3D::~FLUID_3D()
 {
        cout << "~FLUID_3D" << endl;
+       
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       if (using_heat)
+               PyRun_SimpleString(del_heat_low.c_str());
+       if (using_fire)
+               PyRun_SimpleString(del_fire_low.c_str());
+       if (using_colors)
+               PyRun_SimpleString(del_colors_low.c_str());
+       PyRun_SimpleString(del_base_grids_low.c_str());
+       PyGILState_Release(gilstate);
 
-       if (using_heat) Manta_API::delete_heat_low();
-       if (using_fire) Manta_API::delete_fire_low();
-       if (using_colors) Manta_API::delete_colors_low();
-       Manta_API::delete_base_grids_low();
 
 //     if (_xVelocity) delete[] _xVelocity;
 //     if (_yVelocity) delete[] _yVelocity;
diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index b7f7ea9..09d80e1 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -380,72 +380,24 @@
 //     PyGILState_Release(gilstate);           
 //}
 
-std::string Manta_API::get_manta_smoke_script(SmokeModifierData *smd)
-{
-    std::string smoke_script = "";
-       
-       // Check if high res is enabled
-       // Need to check if wt exists and NOT just check if high res flag is 
set (smd->domain->flags & MOD_SMOKE_HIGHRES)
-       // because wt might not exist, i.e. when FLUID_3D constructor is called 
before WTURBULENCE constructor
-       if (smd->domain->wt) {
-               smoke_script = smoke_setup_high + smoke_import_high + 
smoke_step_high;
-       } else {
-               // TODO: Need to figure out how to handle liquids when high 
resolution grids are enabled, not just for low res grids
-               if (smd->domain->flags & MOD_SMOKE_MANTA_USE_LIQUID)
-                       smoke_script = smoke_setup_low  + liquid_step_low;
-               else
-                       smoke_script = smoke_setup_low + smoke_import_low + 
smoke_inflow_low + smoke_step_low ;
-       }
-       return smoke_script;
-}
-
-void Manta_API::run_manta_sim_file_lowRes(SmokeModifierData *smd)
-{
-       std::string smoke_script = get_manta_smoke_script(smd);
-       std::string final_script = parse_script(smoke_script, smd);
-       
-       PyGILState_STATE gilstate = PyGILState_Ensure();
-       PyRun_SimpleString(final_script.c_str());
-       PyGILState_Release(gilstate);
-}
-
-void Manta_API::run_manta_sim_file_highRes(SmokeModifierData *smd)
-{
-       std::string smoke_script = get_manta_smoke_script(smd);
-       std::string final_script = parse_script(smoke_script, smd);
-       
-       PyGILState_STATE gilstate = PyGILState_Ensure();
-       PyRun_SimpleString(final_script.c_str());
-       PyGILState_Release(gilstate);
-}
-
-void Manta_API::delete_colors_low()
-{
-       PyGILState_STATE gilstate = PyGILState_Ensure();
-       PyRun_SimpleString(del_colors_low.c_str());
-       PyGILState_Release(gilstate);
-}
-
-void Manta_API::delete_fire_low()
-{
-       PyGILState_STATE gilstate = PyGILState_Ensure();
-       PyRun_SimpleString(del_fire_low.c_str());
-       PyGILState_Release(gilstate);
-}
-
-void Manta_API::delete_heat_low()
-{
-       PyGILState_STATE gilstate = PyGILState_Ensure();
-       PyRun_SimpleString(del_heat_low.c_str());
-       PyGILState_Release(gilstate);
-}
-
-void Manta_API::delete_base_grids_low()
-{
-       PyGILState_STATE gilstate = PyGILState_Ensure();
-       PyRun_SimpleString(del_base_grids_low.c_str());
-       PyGILState_Release(gilstate);
-}
+//std::string Manta_API::get_manta_smoke_script(SmokeModifierData *smd)
+//{
+//    std::string smoke_script = "";
+//     
+//     // Check if high res is enabled
+//     // Need to check if wt exists and NOT just check if high res flag is 
set (smd->domain->flags & MOD_SMOKE_HIGHRES)
+//     // because wt might not exist, i.e. when FLUID_3D constructor is called 
before WTURBULENCE constructor
+//     if (smd->domain->wt) {
+//             smoke_script = smoke_setup_high + smoke_import_high + 
smoke_step_high;
+//     } else {
+//             // TODO: Need to figure out how to handle liquids when high 
resolution grids are enabled, not just for low res grids
+//             if (smd->domain->flags & MOD_SMOKE_MANTA_USE_LIQUID)
+//                     smoke_script = smoke_setup_low  + liquid_step_low;
+//             else
+//                     smoke_script = smoke_setup_low + smoke_import_low + 
smoke_inflow_low + smoke_step_low ;
+//     }
+//     return smoke_script;
+//}
 
 void Manta_API::start_mantaflow()
 {
@@ -530,17 +482,7 @@ std::string Manta_API::get_real_value( const std::string& 
varName, SmokeModifier
        } else if (varName == "VORTICITY") {
                ss << smd->domain->vorticity / 
smd->domain->fluid->_constantScaling;
        } else if (varName == "BOUNDCONDITIONS") {
-               // OLD SETUP. WHY LIKE THAT??
-               /*if(smd->domain->border_collisions == SM_BORDER_OPEN) ss << 
"xXyY";
-               else if (smd->domain->border_collisions == SM_BORDER_VERTICAL) 
ss << "xXyY";
-               else if (smd->domain->border_collisions == SM_BORDER_CLOSED) ss 
<< "xXyY";
-               
-               if (smd->domain->manta_solver_res == 3){
-                       if(smd->domain->border_collisions == SM_BORDER_OPEN) ss 
<< "z";
-                       else if (smd->domain->border_collisions == 
SM_BORDER_VERTICAL) ss << "z";
-                       else if (smd->domain->border_collisions == 
SM_BORDER_CLOSED) ss << "zZ";
-               }*/
-               if(smd->domain->border_collisions == SM_BORDER_OPEN) ss << 
"xXyY";
+               if (smd->domain->border_collisions == SM_BORDER_OPEN) ss << 
"xXyY";
                else if (smd->domain->border_collisions == SM_BORDER_VERTICAL) 
ss << "zZ";
                else if (smd->domain->border_collisions == SM_BORDER_CLOSED) ss 
<< "";
                
@@ -626,33 +568,72 @@ std::string Manta_API::parse_script(const string& 
setup_string, SmokeModifierDat
        return res.str();
 }
 
-void Manta_API::manta_export_grids(SmokeModifierData *smd)
+void Manta_API::manta_export_script(SmokeModifierData *smd)
 {
-       // Export the scene file
-       std::string smoke_script = get_manta_smoke_script(smd);
+       // Setup low
+       std::string manta_script =
+               manta_import +
+               solver_setup_low +
+               alloc_base_grids_low +
+               alloc_colors_low +
+               noise_low +
+               prep_domain_low +
+               flags;
+       
+       // Setup high
+       if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
+               manta_script +=
+                       solver_setup_high +
+                       alloc_base_grids_high +
+                       noise_high +
+                       prep_domain_high +
+                       wavelet_turbulence_noise;
+       }
        
-       std::string final_script = "";
+       // Import low
+       manta_script += smoke_import_low;
+       
+       // Import high
+       if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
+               manta_script += smoke_step_high;
+       }
+       
+       // Step low
+       manta_script += smoke_step_low;
+       
+       // Step high
        if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
-               final_script = Manta_API::parse_script(smoke_script, smd) + 
standalone_high;
-       } else {
-               final_script = Manta_API::parse_script(smoke_script, smd) + 
standalone_low;
+               manta_script += smoke_step_high;
        }
        
+       // Fill in missing variables in script
+       std::string final_script = Manta_API::parse_script(manta_script, smd);
+       
+       // Add standalone mode (for-loop, gui, ...)
+       final_script += standalone;
+       
+       // Write script
        ofstream myfile;
        myfile.open(smd->domain->_manta_filepath);
        myfile << final_script;
        myfile.close();
-       
-       // Run python environment to export grids, that is, create the grid 
files
+}
+
+void Manta_API::manta_export_grids(SmokeModifierData *smd)
+{
        PyGILState_STATE gilstate = PyGILState_Ensure();
+       
+       // Export low res grids
+       PyRun_SimpleString(Manta_API::parse_script(smoke_export_low, 
smd).c_str());
+
+       // Export high res grids
        if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
                PyRun_SimpleString(Manta_API::parse_script(smoke_export_high, 
smd).c_str());
-       } else {
-               PyRun_SimpleString(Manta_API::parse_script(smoke_export_low, 
smd).c_str());
        }
        PyGILState_Release(gilstate);
 }
 
+
 string Manta_API::get_grid_pointer(std::string gridName, std::string 
solverName)
 {
        if ((gridName == "") && (solverName == "")) {
@@ -694,7 +675,7 @@ string Manta_API::get_grid_pointer(std::string gridName, 
std::string solverName)
 //     _max_temp = flame_max_temp;
 //}
 
-void * Manta_API::pointer_from_string(const std::string& s){
+void* Manta_API::pointer_from_string(const std::string& s){
        stringstream ss(s);
        void *gridPointer = NULL;
        ss >> gridPointer;
diff --git a/intern/smoke/intern/MANTA.h b/intern/smoke/intern/MANTA.h
index 53fd56c..1ca23b5 100644
--- a/intern/smoke/intern/MANTA.h
+++ b/intern/smoke/intern/MANTA.h
@@ -25,17 +25,14 @@
 //void runScript(

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to