[Bf-blender-cvs] [d845e157500] functions: move integrator to seprate file
Jacques Lucke
noreply at git.blender.org
Tue Jul 9 18:01:18 CEST 2019
Commit: d845e1575005489253010078d3997ae019cc15cd
Author: Jacques Lucke
Date: Tue Jul 9 12:02:11 2019 +0200
Branches: functions
https://developer.blender.org/rBd845e1575005489253010078d3997ae019cc15cd
move integrator to seprate file
===================================================================
M source/blender/simulations/CMakeLists.txt
M source/blender/simulations/bparticles/c_wrapper.cpp
A source/blender/simulations/bparticles/integrator.cpp
A source/blender/simulations/bparticles/integrator.hpp
===================================================================
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index dbbbfa4cff5..f9518a5890b 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -37,6 +37,8 @@ set(SRC
bparticles/c_wrapper.cpp
bparticles/step_description.hpp
bparticles/world_state.hpp
+ bparticles/integrator.hpp
+ bparticles/integrator.cpp
)
set(LIB
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 3aacb7eb699..9a425aedfa7 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -8,6 +8,7 @@
#include "simulate.hpp"
#include "world_state.hpp"
#include "step_description.hpp"
+#include "integrator.hpp"
#include "BLI_timeit.hpp"
#include "BLI_listbase.h"
@@ -78,73 +79,6 @@ void BParticles_world_state_free(BParticlesWorldState world_state_c)
delete unwrap(world_state_c);
}
-class EulerIntegrator : public Integrator {
- private:
- AttributesInfo m_offset_attributes_info;
-
- public:
- SmallVector<Force *> m_forces;
-
- EulerIntegrator() : m_offset_attributes_info({}, {}, {"Position", "Velocity"})
- {
- }
-
- ~EulerIntegrator()
- {
- for (Force *force : m_forces) {
- delete force;
- }
- }
-
- AttributesInfo &offset_attributes_info() override
- {
- return m_offset_attributes_info;
- }
-
- void integrate(IntegratorInterface &interface) override
- {
- ParticlesBlock &block = interface.block();
- AttributeArrays r_offsets = interface.offset_targets();
- ArrayRef<float> durations = interface.durations();
-
- ArrayAllocator::Array<float3> combined_force(interface.array_allocator());
- this->compute_combined_force(block, combined_force);
-
- auto last_velocities = block.attributes().get_float3("Velocity");
-
- auto position_offsets = r_offsets.get_float3("Position");
- auto velocity_offsets = r_offsets.get_float3("Velocity");
- this->compute_offsets(
- durations, last_velocities, combined_force, position_offsets, velocity_offsets);
- }
-
- BLI_NOINLINE void compute_combined_force(ParticlesBlock &block, ArrayRef<float3> r_force)
- {
- r_force.fill({0, 0, 0});
-
- for (Force *force : m_forces) {
- force->add_force(block, r_force);
- }
- }
-
- BLI_NOINLINE void compute_offsets(ArrayRef<float> durations,
- ArrayRef<float3> last_velocities,
- ArrayRef<float3> combined_force,
- ArrayRef<float3> r_position_offsets,
- ArrayRef<float3> r_velocity_offsets)
- {
- uint amount = durations.size();
- for (uint pindex = 0; pindex < amount; pindex++) {
- float mass = 1.0f;
- float duration = durations[pindex];
-
- r_velocity_offsets[pindex] = duration * combined_force[pindex] / mass;
- r_position_offsets[pindex] = duration *
- (last_velocities[pindex] + r_velocity_offsets[pindex] * 0.5f);
- }
- }
-};
-
using EmitterInserter = std::function<void(bNode *bnode,
IndexedNodeTree &indexed_tree,
FN::DataFlowNodes::GeneratedGraph &data_graph,
@@ -443,7 +377,7 @@ static void INSERT_FORCE_gravity(bNode *force_node,
bNode *type_node = linked.node;
EulerIntegrator *integrator = reinterpret_cast<EulerIntegrator *>(
step_description.m_types.lookup_ref(type_node->name)->m_integrator);
- integrator->m_forces.append(force);
+ integrator->add_force(std::unique_ptr<Force>(force));
}
}
@@ -470,7 +404,7 @@ static void INSERT_FORCE_turbulence(bNode *force_node,
bNode *type_node = linked.node;
EulerIntegrator *integrator = reinterpret_cast<EulerIntegrator *>(
step_description.m_types.lookup_ref(type_node->name)->m_integrator);
- integrator->m_forces.append(force);
+ integrator->add_force(std::unique_ptr<Force>(force));
}
}
diff --git a/source/blender/simulations/bparticles/integrator.cpp b/source/blender/simulations/bparticles/integrator.cpp
new file mode 100644
index 00000000000..7ad24637b03
--- /dev/null
+++ b/source/blender/simulations/bparticles/integrator.cpp
@@ -0,0 +1,65 @@
+#include "integrator.hpp"
+
+namespace BParticles {
+
+EulerIntegrator::EulerIntegrator() : m_offset_attributes_info({}, {}, {"Position", "Velocity"})
+{
+}
+
+EulerIntegrator::~EulerIntegrator()
+{
+ for (Force *force : m_forces) {
+ delete force;
+ }
+}
+
+AttributesInfo &EulerIntegrator::offset_attributes_info()
+{
+ return m_offset_attributes_info;
+}
+
+void EulerIntegrator::integrate(IntegratorInterface &interface)
+{
+ ParticlesBlock &block = interface.block();
+ AttributeArrays r_offsets = interface.offset_targets();
+ ArrayRef<float> durations = interface.durations();
+
+ ArrayAllocator::Array<float3> combined_force(interface.array_allocator());
+ this->compute_combined_force(block, combined_force);
+
+ auto last_velocities = block.attributes().get_float3("Velocity");
+
+ auto position_offsets = r_offsets.get_float3("Position");
+ auto velocity_offsets = r_offsets.get_float3("Velocity");
+ this->compute_offsets(
+ durations, last_velocities, combined_force, position_offsets, velocity_offsets);
+}
+
+BLI_NOINLINE void EulerIntegrator::compute_combined_force(ParticlesBlock &block,
+ ArrayRef<float3> r_force)
+{
+ r_force.fill({0, 0, 0});
+
+ for (Force *force : m_forces) {
+ force->add_force(block, r_force);
+ }
+}
+
+BLI_NOINLINE void EulerIntegrator::compute_offsets(ArrayRef<float> durations,
+ ArrayRef<float3> last_velocities,
+ ArrayRef<float3> combined_force,
+ ArrayRef<float3> r_position_offsets,
+ ArrayRef<float3> r_velocity_offsets)
+{
+ uint amount = durations.size();
+ for (uint pindex = 0; pindex < amount; pindex++) {
+ float mass = 1.0f;
+ float duration = durations[pindex];
+
+ r_velocity_offsets[pindex] = duration * combined_force[pindex] / mass;
+ r_position_offsets[pindex] = duration *
+ (last_velocities[pindex] + r_velocity_offsets[pindex] * 0.5f);
+ }
+}
+
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/integrator.hpp b/source/blender/simulations/bparticles/integrator.hpp
new file mode 100644
index 00000000000..d45d39cc566
--- /dev/null
+++ b/source/blender/simulations/bparticles/integrator.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "forces.hpp"
+#include "core.hpp"
+
+namespace BParticles {
+
+class EulerIntegrator : public Integrator {
+ private:
+ AttributesInfo m_offset_attributes_info;
+ SmallVector<Force *> m_forces;
+
+ public:
+ EulerIntegrator();
+ ~EulerIntegrator();
+
+ AttributesInfo &offset_attributes_info() override;
+ void integrate(IntegratorInterface &interface) override;
+
+ void add_force(std::unique_ptr<Force> force)
+ {
+ m_forces.append(force.release());
+ }
+
+ private:
+ void compute_combined_force(ParticlesBlock &block, ArrayRef<float3> r_force);
+
+ void compute_offsets(ArrayRef<float> durations,
+ ArrayRef<float3> last_velocities,
+ ArrayRef<float3> combined_force,
+ ArrayRef<float3> r_position_offsets,
+ ArrayRef<float3> r_velocity_offsets);
+};
+
+} // namespace BParticles
More information about the Bf-blender-cvs
mailing list