9 #include "imstkAbstractDynamicalModel.h" 10 #include "imstkPbdBody.h" 11 #include "imstkPbdConstraint.h" 13 #include <unordered_map> 14 #include <unordered_set> 18 class PbdConstraintContainer;
52 void configure(std::shared_ptr<PbdModelConfig> params);
57 std::shared_ptr<PbdBody>
addBody();
58 void removeBody(std::shared_ptr<PbdBody> body);
64 std::shared_ptr<PbdBody>
getBody(
size_t index)
const;
66 PbdState& getBodies() {
return m_state; }
73 const Vec3d& pos,
const Quatd& orientation,
74 const double mass,
const Mat3d inertia,
75 const Vec3d& velocity = Vec3d::Zero(),
const Vec3d& angularVelocity = Vec3d::Zero(),
76 const bool persist =
false);
83 const Vec3d& pos,
const double mass,
84 const Vec3d& velocity = Vec3d::Zero(),
85 const bool persist =
false);
95 std::shared_ptr<PbdModelConfig>
getConfig()
const;
103 void addConstraints(std::shared_ptr<std::unordered_set<size_t>> vertices,
const int bodyId);
159 std::shared_ptr<TaskNode> getIntegratePositionNode()
const {
return m_integrationPositionNode; }
160 std::shared_ptr<TaskNode> getSolveNode()
const {
return m_solveConstraintsNode; }
161 std::shared_ptr<TaskNode> getUpdateVelocityNode()
const {
return m_updateVelocityNode; }
175 void initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink)
override;
179 bool m_modified =
true;
186 std::shared_ptr<PbdModelConfig>
m_config =
nullptr;
191 std::shared_ptr<TaskNode> m_integrationPositionNode =
nullptr;
192 std::shared_ptr<TaskNode> m_solveConstraintsNode =
nullptr;
193 std::shared_ptr<TaskNode> m_updateVelocityNode =
nullptr;
Represents a pbd body in the model. This is a data only object. It does no function. PbdBody can be of different types. The types effect what properties it has.
This class implements the position based dynamics model. The PbdModel is a constraint based model tha...
void configure(std::shared_ptr< PbdModelConfig > params)
Set simulation parameters.
void setVelocityThreshold(double velCap)
Set/Get filter value for velocity, default is 10 in meters/second.
double m_velocityThreshold
Limit on velocity, assumes units in Meters. If any component of velocity exceeds value set here it wi...
std::pair< int, int > PbdParticleId
Index pair that refers to a particle in a PbdState. Index 0 is the body id, Index 1 is the particle i...
void addConstraints(std::shared_ptr< std::unordered_set< size_t >> vertices, const int bodyId)
Add/generate constraints for given set of vertices on the body, useful for topology changes...
void setTimeStep(const double timeStep) override
Set the time step size.
void clearVirtualParticles()
Resize 0 the virtual particles.
std::shared_ptr< PbdConstraintContainer > m_constraints
The set of constraints to update/use.
void setConstraintPartitionThreshold(size_t threshold)
Set the threshold for constraint partitioning.
Abstract class for mathematical model of the physics governing the dynamic object.
void updateVelocity()
Time integrate the velocity.
bool initialize() override
Initialize the PBD model.
std::shared_ptr< PbdSolver > getSolver() const
Returns the solver used for internal constraints.
void resizeBodyParticles(PbdBody &body, const int particleCount)
Resize the amount of particles for a body.
int m_iterKey
Iterative key used for body ids.
PbdParticleId addVirtualParticle(const Vec3d &pos, const Quatd &orientation, const double mass, const Mat3d inertia, const Vec3d &velocity=Vec3d::Zero(), const Vec3d &angularVelocity=Vec3d::Zero(), const bool persist=false)
Add a particle to a virtual pool/buffer of particles for quick removal/insertion The persist flag ind...
void setModelGeometry(std::shared_ptr< Geometry > geometry)
Sets the model geometry.
std::shared_ptr< PbdSolver > m_pbdSolver
PBD solver.
std::shared_ptr< PbdBody > getBody(size_t index) const
void setSolver(std::shared_ptr< PbdSolver > solver)
Sets the solver used for internal constraints.
void integratePosition()
Time integrate the position.
std::shared_ptr< PbdModelConfig > m_config
Model parameters, must be set before simulation.
void solveConstraints()
Solve the internal constraints.
void resetToInitialState() override
Reset the current state to the initial state.
size_t m_partitionThreshold
Threshold for constraint partitioning.
std::shared_ptr< PbdModelConfig > getConfig() const
Get the simulation parameters.
std::shared_ptr< PbdConstraintContainer > getConstraints()
Return all constraints that are solved sequentially.
double getTimeStep() const override
Returns the time step size.
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
std::shared_ptr< PbdBody > addBody()
Add/remove PbdBody.
void initGraphEdges()
Initializes the edges of the graph.