iMSTK
Interactive Medical Simulation Toolkit
imstkPbdConstraintContainer.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkPbdConstraint.h"
10 
11 #include <unordered_set>
12 
13 namespace imstk
14 {
21 {
22 public:
23  PbdConstraintContainer() = default;
24  virtual ~PbdConstraintContainer() = default;
25 
26 public:
27  using iterator = std::vector<std::shared_ptr<PbdConstraint>>::iterator;
28  using const_iterator = std::vector<std::shared_ptr<PbdConstraint>>::const_iterator;
29 
30 public:
34  virtual void addConstraint(std::shared_ptr<PbdConstraint> constraint);
35 
39  virtual void removeConstraint(std::shared_ptr<PbdConstraint> constraint);
40 
44  virtual void removeConstraints(
45  std::shared_ptr<std::unordered_set<size_t>> vertices, const int bodyId);
46 
50  virtual iterator eraseConstraint(iterator iter);
51  virtual const_iterator eraseConstraint(const_iterator iter);
52 
58  virtual void reserve(const size_t n) { m_constraints.reserve(n); }
59 
63  const bool empty() const { return m_constraints.empty() && m_partitionedConstraints.empty(); }
64 
68  const std::vector<std::shared_ptr<PbdConstraint>>& getConstraints() const { return m_constraints; }
69  std::vector<std::shared_ptr<PbdConstraint>>& getConstraints() { return m_constraints; }
70 
74  const std::vector<std::vector<std::shared_ptr<PbdConstraint>>> getPartitionedConstraints() const { return m_partitionedConstraints; }
75 
80  void partitionConstraints(const int partitionThreshold);
81 
86 
87 protected:
88  std::vector<std::shared_ptr<PbdConstraint>> m_constraints;
89  std::vector<std::vector<std::shared_ptr<PbdConstraint>>> m_partitionedConstraints;
91 };
92 } // namespace imstk
The SpinLock class.
Definition: imstkSpinLock.h:20
std::vector< std::shared_ptr< PbdConstraint > > m_constraints
Not partitioned constraints.
Container for pbd constraints.
virtual void reserve(const size_t n)
Reserve an amount of constraints in the pool, if you know ahead of time the number of constraints...
std::vector< std::vector< std::shared_ptr< PbdConstraint > > > m_partitionedConstraints
Partitioned pbd constraints.
virtual iterator eraseConstraint(iterator iter)
Removes a constraint from the system by iterator, thread safe.
const std::vector< std::shared_ptr< PbdConstraint > > & getConstraints() const
Get the underlying container.
Compound Geometry.
ParallelUtils::SpinLock m_constraintLock
Used to deal with concurrent addition/removal of constraints.
void clearPartitions()
Clear the parition vectors.
const std::vector< std::vector< std::shared_ptr< PbdConstraint > > > getPartitionedConstraints() const
Get the partitioned constraints.
virtual void removeConstraints(std::shared_ptr< std::unordered_set< size_t >> vertices, const int bodyId)
Removes all constraints associated with vertex ids.
virtual void removeConstraint(std::shared_ptr< PbdConstraint > constraint)
Linear searches for and removes a constraint from the system, thread safe.
const bool empty() const
Returns if there are no constraints.
virtual void addConstraint(std::shared_ptr< PbdConstraint > constraint)
Adds a constraint to the system, thread safe.
void partitionConstraints(const int partitionThreshold)
Partitions pbd constraints into separate vectors via graph coloring.