Bullet Collision Detection & Physics Library: btDeformableContactProjection.h Source File

Bullet Collision Detection & Physics Library

btDeformableContactProjection.h
Go to the documentation of this file.
1 /*
2 Written by Xuchen Han <xuchenhan2015@u.northwestern.edu>
3
4 Bullet Continuous Collision Detection and Physics Library
5 Copyright (c) 2019 Google Inc. http://bulletphysics.org
6 This software is provided 'as-is', without any express or implied warranty.
7 In no event will the authors be held liable for any damages arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it freely,
10 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16 #ifndef BT_CONTACT_PROJECTION_H
17 #define BT_CONTACT_PROJECTION_H
18 #include "btCGProjection.h"
19 #include "btSoftBody.h"
20 #include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
21 #include "BulletDynamics/Featherstone/btMultiBodyConstraint.h"
22 #include "btDeformableContactConstraint.h"
23 #include "LinearMath/btHashMap.h"
24 #include "LinearMath/btReducedVector.h"
25 #include "LinearMath/btModifiedGramSchmidt.h"
26 #include <vector>
27
28 struct LagrangeMultiplier
29 {
30 int m_num_constraints; // Number of constraints
31 int m_num_nodes; // Number of nodes in these constraints
32 btScalar m_weights[3]; // weights of the nodes involved, same size as m_num_nodes
33 btVector3 m_dirs[3]; // Constraint directions, same size of m_num_constraints;
34 int m_indices[3]; // indices of the nodes involved, same size as m_num_nodes;
35 };
36
37 class btDeformableContactProjection
38 {
39 public:
40 typedef btAlignedObjectArray<btVector3> TVStack;
41 btAlignedObjectArray<btSoftBody*>& m_softBodies;
42
43 // all constraints involving face
44 btAlignedObjectArray<btDeformableContactConstraint*> m_allFaceConstraints;
45 #ifndef USE_MGS
46 // map from node index to projection directions
47 btHashMap<btHashInt, btAlignedObjectArray<btVector3> > m_projectionsDict;
48 #else
49 btAlignedObjectArray<btReducedVector> m_projections;
50 #endif
51
52 btAlignedObjectArray<LagrangeMultiplier> m_lagrangeMultipliers;
53
54 // map from node index to static constraint
55 btAlignedObjectArray<btAlignedObjectArray<btDeformableStaticConstraint> > m_staticConstraints;
56 // map from node index to node rigid constraint
57 btAlignedObjectArray<btAlignedObjectArray<btDeformableNodeRigidContactConstraint> > m_nodeRigidConstraints;
58 // map from node index to face rigid constraint
59 btAlignedObjectArray<btAlignedObjectArray<btDeformableFaceRigidContactConstraint> > m_faceRigidConstraints;
60 // map from node index to deformable constraint
61 btAlignedObjectArray<btAlignedObjectArray<btDeformableFaceNodeContactConstraint> > m_deformableConstraints;
62 // map from node index to node anchor constraint
63 btAlignedObjectArray<btAlignedObjectArray<btDeformableNodeAnchorConstraint> > m_nodeAnchorConstraints;
64
65 bool m_useStrainLimiting;
66
67 btDeformableContactProjection(btAlignedObjectArray<btSoftBody*>& softBodies)
68 : m_softBodies(softBodies)
69 {
70 }
71
72 virtual ~btDeformableContactProjection()
73 {
74 }
75
76 // apply the constraints to the rhs of the linear solve
77 virtual void project(TVStack& x);
78
79 // add friction force to the rhs of the linear solve
80 virtual void applyDynamicFriction(TVStack& f);
81
82 // update and solve the constraints
83 virtual btScalar update(btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);
84
85 // Add constraints to m_constraints. In addition, the constraints that each vertex own are recorded in m_constraintsDict.
86 virtual void setConstraints(const btContactSolverInfo& infoGlobal);
87
88 // Set up projections for each vertex by adding the projection direction to
89 virtual void setProjection();
90
91 virtual void reinitialize(bool nodeUpdated);
92
93 btScalar solveSplitImpulse(btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);
94
95 virtual void setLagrangeMultiplier();
96
97 void checkConstraints(const TVStack& x);
98 };
99 #endif /* btDeformableContactProjection_h */
LagrangeMultiplier::m_num_constraints
int m_num_constraints
Definition: btDeformableContactProjection.h:30
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:50
btDeformableContactProjection::m_staticConstraints
btAlignedObjectArray< btAlignedObjectArray< btDeformableStaticConstraint > > m_staticConstraints
Definition: btDeformableContactProjection.h:55
btDeformableContactProjection::reinitialize
virtual void reinitialize(bool nodeUpdated)
Definition: btDeformableContactProjection.cpp:614
btContactSolverInfo
Definition: btContactSolverInfo.h:76
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btDeformableContactProjection
Definition: btDeformableContactProjection.h:38
LagrangeMultiplier::m_dirs
btVector3 m_dirs[3]
Definition: btDeformableContactProjection.h:33
btModifiedGramSchmidt.h
btDeformableContactProjection::applyDynamicFriction
virtual void applyDynamicFriction(TVStack &f)
Definition: btDeformableContactProjection.cpp:563
btDeformableContactProjection::m_useStrainLimiting
bool m_useStrainLimiting
Definition: btDeformableContactProjection.h:65
btReducedVector.h
btDeformableContactProjection::setProjection
virtual void setProjection()
Definition: btDeformableContactProjection.cpp:202
btDeformableContactProjection::m_faceRigidConstraints
btAlignedObjectArray< btAlignedObjectArray< btDeformableFaceRigidContactConstraint > > m_faceRigidConstraints
Definition: btDeformableContactProjection.h:59
btDeformableContactProjection::solveSplitImpulse
btScalar solveSplitImpulse(btCollisionObject **deformableBodies, int numDeformableBodies, const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactProjection.cpp:61
btDeformableContactProjection::~btDeformableContactProjection
virtual ~btDeformableContactProjection()
Definition: btDeformableContactProjection.h:72
btDeformableContactProjection::TVStack
btAlignedObjectArray< btVector3 > TVStack
Definition: btDeformableContactProjection.h:40
btHashMap
The btHashMap template class implements a generic and lightweight hashmap.
Definition: btHashMap.h:220
btDeformableContactProjection::m_lagrangeMultipliers
btAlignedObjectArray< LagrangeMultiplier > m_lagrangeMultipliers
Definition: btDeformableContactProjection.h:52
LagrangeMultiplier::m_num_nodes
int m_num_nodes
Definition: btDeformableContactProjection.h:31
btDeformableContactProjection::m_projectionsDict
btHashMap< btHashInt, btAlignedObjectArray< btVector3 > > m_projectionsDict
Definition: btDeformableContactProjection.h:47
btDeformableContactProjection::m_nodeRigidConstraints
btAlignedObjectArray< btAlignedObjectArray< btDeformableNodeRigidContactConstraint > > m_nodeRigidConstraints
Definition: btDeformableContactProjection.h:57
btMultiBodyLinkCollider.h
btDeformableContactProjection::update
virtual btScalar update(btCollisionObject **deformableBodies, int numDeformableBodies, const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactProjection.cpp:20
btDeformableContactConstraint.h
btDeformableContactProjection::checkConstraints
void checkConstraints(const TVStack &x)
Definition: btDeformableContactProjection.cpp:442
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btDeformableContactProjection::m_softBodies
btAlignedObjectArray< btSoftBody * > & m_softBodies
Definition: btDeformableContactProjection.h:41
btDeformableContactProjection::project
virtual void project(TVStack &x)
Definition: btDeformableContactProjection.cpp:153
btAlignedObjectArray< btVector3 >
LagrangeMultiplier::m_indices
int m_indices[3]
Definition: btDeformableContactProjection.h:34
btHashMap.h
btCGProjection.h
btDeformableContactProjection::m_nodeAnchorConstraints
btAlignedObjectArray< btAlignedObjectArray< btDeformableNodeAnchorConstraint > > m_nodeAnchorConstraints
Definition: btDeformableContactProjection.h:63
btDeformableContactProjection::btDeformableContactProjection
btDeformableContactProjection(btAlignedObjectArray< btSoftBody * > &softBodies)
Definition: btDeformableContactProjection.h:67
LagrangeMultiplier::m_weights
btScalar m_weights[3]
Definition: btDeformableContactProjection.h:32
btDeformableContactProjection::m_allFaceConstraints
btAlignedObjectArray< btDeformableContactConstraint * > m_allFaceConstraints
Definition: btDeformableContactProjection.h:44
btMultiBodyConstraint.h
LagrangeMultiplier
Definition: btDeformableContactProjection.h:29
btDeformableContactProjection::setLagrangeMultiplier
virtual void setLagrangeMultiplier()
Definition: btDeformableContactProjection.cpp:460
btSoftBody.h
btDeformableContactProjection::setConstraints
virtual void setConstraints(const btContactSolverInfo &infoGlobal)
Definition: btDeformableContactProjection.cpp:90
btDeformableContactProjection::m_deformableConstraints
btAlignedObjectArray< btAlignedObjectArray< btDeformableFaceNodeContactConstraint > > m_deformableConstraints
Definition: btDeformableContactProjection.h:61