@@ -132,18 +132,12 @@ class CollisionObjectWrapper : public btCollisionObject
132
132
using Ptr = std::shared_ptr<CollisionObjectWrapper>;
133
133
using ConstPtr = std::shared_ptr<const CollisionObjectWrapper>;
134
134
135
+ CollisionObjectWrapper () = default ;
135
136
CollisionObjectWrapper (std::string name,
136
137
const int & type_id,
137
138
CollisionShapesConst shapes,
138
139
tesseract_common::VectorIsometry3d shape_poses);
139
140
140
- /* * @brief This is a special constructor used by the clone method */
141
- CollisionObjectWrapper (std::string name,
142
- const int & type_id,
143
- CollisionShapesConst shapes,
144
- tesseract_common::VectorIsometry3d shape_poses,
145
- std::vector<std::shared_ptr<void >> data);
146
-
147
141
short int m_collisionFilterGroup;
148
142
short int m_collisionFilterMask;
149
143
bool m_enabled;
@@ -188,7 +182,12 @@ class CollisionObjectWrapper : public btCollisionObject
188
182
*/
189
183
std::shared_ptr<CollisionObjectWrapper> clone ()
190
184
{
191
- auto clone_cow = std::make_shared<CollisionObjectWrapper>(m_name, m_type_id, m_shapes, m_shape_poses, m_data);
185
+ auto clone_cow = std::make_shared<CollisionObjectWrapper>();
186
+ clone_cow->m_name = m_name;
187
+ clone_cow->m_type_id = m_type_id;
188
+ clone_cow->m_shapes = m_shapes;
189
+ clone_cow->m_shape_poses = m_shape_poses;
190
+ clone_cow->m_data = m_data;
192
191
clone_cow->setCollisionShape (getCollisionShape ());
193
192
clone_cow->setWorldTransform (getWorldTransform ());
194
193
clone_cow->m_collisionFilterGroup = m_collisionFilterGroup;
@@ -198,25 +197,16 @@ class CollisionObjectWrapper : public btCollisionObject
198
197
return clone_cow;
199
198
}
200
199
201
- template <class T >
202
- void manage (T* t)
203
- { // manage memory of this object
204
- m_data.push_back (std::shared_ptr<T>(t));
205
- }
206
- template <class T >
207
- void manage (std::shared_ptr<T> t)
208
- {
209
- m_data.push_back (t);
210
- }
200
+ void manage (const std::shared_ptr<btCollisionShape>& t) { m_data.push_back (t); }
211
201
212
202
protected:
213
203
std::string m_name; /* *< @brief The name of the collision object */
214
204
int m_type_id; /* *< @brief A user defined type id */
215
205
CollisionShapesConst m_shapes; /* *< @brief The shapes that define the collison object */
216
206
tesseract_common::VectorIsometry3d m_shape_poses; /* *< @brief The shpaes poses information */
217
207
218
- std::vector<std::shared_ptr< void >> m_data; /* *< @brief This manages the collision shape pointer so they get destroyed
219
- */
208
+ /* * @brief This manages the collision shape pointer so they get destroyed */
209
+ std::vector<std::shared_ptr<btCollisionShape>> m_data;
220
210
};
221
211
222
212
using COW = CollisionObjectWrapper;
@@ -898,9 +888,9 @@ class TesseractOverlapFilterCallback : public btOverlapFilterCallback
898
888
* bullet collision shape by calling getUserIndex function.
899
889
* @return Bullet collision shape.
900
890
*/
901
- btCollisionShape* createShapePrimitive (const CollisionShapeConstPtr& geom,
902
- CollisionObjectWrapper* cow,
903
- int shape_index);
891
+ std::shared_ptr< btCollisionShape> createShapePrimitive (const CollisionShapeConstPtr& geom,
892
+ CollisionObjectWrapper* cow,
893
+ int shape_index);
904
894
905
895
/* *
906
896
* @brief Update a collision objects filters
@@ -939,7 +929,7 @@ inline COW::Ptr createCollisionObject(const std::string& name,
939
929
return nullptr ;
940
930
}
941
931
942
- COW::Ptr new_cow ( new COW (name, type_id, shapes, shape_poses) );
932
+ auto new_cow = std::make_shared< COW> (name, type_id, shapes, shape_poses);
943
933
944
934
new_cow->m_enabled = enabled;
945
935
new_cow->setContactProcessingThreshold (BULLET_DEFAULT_CONTACT_DISTANCE);
@@ -1036,17 +1026,18 @@ inline COW::Ptr makeCastCollisionObject(const COW::Ptr& cow)
1036
1026
assert (convex->getShapeType () != CUSTOM_CONVEX_SHAPE_TYPE); // This checks if the collision object is already a
1037
1027
// cast collision object
1038
1028
1039
- auto * shape = new CastHullShape (convex, tf);
1029
+ auto shape = std::make_shared< CastHullShape> (convex, tf);
1040
1030
assert (shape != nullptr );
1041
1031
1042
1032
new_cow->manage (shape);
1043
- new_cow->setCollisionShape (shape);
1033
+ new_cow->setCollisionShape (shape. get () );
1044
1034
}
1045
1035
else if (btBroadphaseProxy::isCompound (new_cow->getCollisionShape ()->getShapeType ()))
1046
1036
{
1047
1037
assert (dynamic_cast <btCompoundShape*>(new_cow->getCollisionShape ()) != nullptr );
1048
1038
auto * compound = static_cast <btCompoundShape*>(new_cow->getCollisionShape ());
1049
- auto * new_compound = new btCompoundShape (BULLET_COMPOUND_USE_DYNAMIC_AABB, compound->getNumChildShapes ());
1039
+ auto new_compound =
1040
+ std::make_shared<btCompoundShape>(BULLET_COMPOUND_USE_DYNAMIC_AABB, compound->getNumChildShapes ());
1050
1041
1051
1042
for (int i = 0 ; i < compound->getNumChildShapes (); ++i)
1052
1043
{
@@ -1057,18 +1048,18 @@ inline COW::Ptr makeCastCollisionObject(const COW::Ptr& cow)
1057
1048
1058
1049
btTransform geomTrans = compound->getChildTransform (i);
1059
1050
1060
- auto * subshape = new CastHullShape (convex, tf);
1051
+ auto subshape = std::make_shared< CastHullShape> (convex, tf);
1061
1052
assert (subshape != nullptr );
1062
1053
1063
1054
new_cow->manage (subshape);
1064
1055
subshape->setMargin (BULLET_MARGIN);
1065
- new_compound->addChildShape (geomTrans, subshape);
1056
+ new_compound->addChildShape (geomTrans, subshape. get () );
1066
1057
}
1067
1058
else if (btBroadphaseProxy::isCompound (compound->getChildShape (i)->getShapeType ()))
1068
1059
{
1069
1060
auto * second_compound = static_cast <btCompoundShape*>(compound->getChildShape (i));
1070
- auto * new_second_compound =
1071
- new btCompoundShape (BULLET_COMPOUND_USE_DYNAMIC_AABB, second_compound->getNumChildShapes ());
1061
+ auto new_second_compound =
1062
+ std::make_shared< btCompoundShape> (BULLET_COMPOUND_USE_DYNAMIC_AABB, second_compound->getNumChildShapes ());
1072
1063
for (int j = 0 ; j < second_compound->getNumChildShapes (); ++j)
1073
1064
{
1074
1065
assert (!btBroadphaseProxy::isCompound (second_compound->getChildShape (j)->getShapeType ()));
@@ -1079,12 +1070,12 @@ inline COW::Ptr makeCastCollisionObject(const COW::Ptr& cow)
1079
1070
1080
1071
btTransform geomTrans = second_compound->getChildTransform (j);
1081
1072
1082
- auto * subshape = new CastHullShape (convex, tf);
1073
+ auto subshape = std::make_shared< CastHullShape> (convex, tf);
1083
1074
assert (subshape != nullptr );
1084
1075
1085
1076
new_cow->manage (subshape);
1086
1077
subshape->setMargin (BULLET_MARGIN);
1087
- new_second_compound->addChildShape (geomTrans, subshape);
1078
+ new_second_compound->addChildShape (geomTrans, subshape. get () );
1088
1079
}
1089
1080
1090
1081
btTransform geomTrans = compound->getChildTransform (i);
@@ -1095,7 +1086,7 @@ inline COW::Ptr makeCastCollisionObject(const COW::Ptr& cow)
1095
1086
// but has an effect when
1096
1087
// negative
1097
1088
1098
- new_compound->addChildShape (geomTrans, new_second_compound);
1089
+ new_compound->addChildShape (geomTrans, new_second_compound. get () );
1099
1090
}
1100
1091
else
1101
1092
{
@@ -1108,7 +1099,7 @@ inline COW::Ptr makeCastCollisionObject(const COW::Ptr& cow)
1108
1099
// but has an effect when
1109
1100
// negative
1110
1101
new_cow->manage (new_compound);
1111
- new_cow->setCollisionShape (new_compound);
1102
+ new_cow->setCollisionShape (new_compound. get () );
1112
1103
new_cow->setWorldTransform (cow->getWorldTransform ());
1113
1104
}
1114
1105
else
0 commit comments