Skip to content

Commit 1d8c3f9

Browse files
fjonath1cpaxton
authored andcommitted
Limit overlaps to 0.3 object bounding box volume
1 parent 58bffe1 commit 1d8c3f9

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

include/scene_physics_engine.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct OverlappingObjectSensor : public btCollisionWorld::ContactResultCallback
177177
std::string object_id_;
178178
double total_intersecting_volume_;
179179
double total_penetration_depth_;
180+
double bounding_box_volume_;
180181

181182
//! Called with each contact for your own processing (e.g. test if contacts fall in within sensor parameters)
182183
virtual btScalar addSingleResult(btManifoldPoint& cp,
@@ -188,25 +189,30 @@ struct OverlappingObjectSensor : public btCollisionWorld::ContactResultCallback
188189

189190
btVector3 pt; // will be set to point of collision relative to body
190191
std::string other_id;
192+
bool other_object_is_1;
191193
if (colObj0->m_collisionObject==&body_)
192194
{
193195
pt = cp.m_localPointA;
196+
other_object_is_1 = true;
194197
other_id = getObjectIDFromCollisionObject(obj_1);
195198
}
196199
else
197200
{
198201
assert(colObj1->m_collisionObject==&body_ && "body does not match either collision object");
199202
pt = cp.m_localPointB;
203+
other_object_is_1 = false;
200204
other_id = getObjectIDFromCollisionObject(obj_0);
201205
}
202206

207+
btAABB shapeAABB_0 = getCollisionAABB(colObj0->getCollisionObject(), cp, true, index0);
208+
btAABB shapeAABB_1 = getCollisionAABB(colObj1->getCollisionObject(), cp, false, index1);
209+
bounding_box_volume_ = other_object_is_1 ? getBoundingBoxVolume(shapeAABB_0) : getBoundingBoxVolume(shapeAABB_1);
203210
if (other_id == "unrecognized_object" || other_id == "background" || other_id == object_id_) return 0;
204211

205212
// do stuff with the collision point
206213
total_penetration_depth_ += cp.getDistance() < 0 ? -cp.getDistance() : 0;
207-
btAABB shapeAABB_0 = getCollisionAABB(colObj0->getCollisionObject(), cp, true, index0);
208-
btAABB shapeAABB_1 = getCollisionAABB(colObj1->getCollisionObject(), cp, false, index1);
209-
214+
215+
210216
total_intersecting_volume_ += getIntersectingVolume(shapeAABB_0,shapeAABB_1);
211217

212218
return 0; // There was a planned purpose for the return value of addSingleResult, but it is not used so you can ignore it.

include/scene_physics_support.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ void assignAllConnectedToParentVertices(SceneSupportGraph &input_graph, const ve
124124

125125
btAABB getCollisionAABB(const btCollisionObject* obj, const btManifoldPoint &pt, const bool &is_body_0, int &shape_index);
126126

127+
double getBoundingBoxVolume(const btAABB &shapeAABB);
128+
127129
double getIntersectingVolume(const btAABB &shapeAABB_a, const btAABB &shapeAABB_b);
128130

129131
SceneSupportGraph generateObjectSupportGraph(btDynamicsWorld *world,

src/scene_physics_support.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ double getIntersectingVolume(const btAABB &shapeAABB_a, const btAABB &shapeAABB_
155155
{
156156
btAABB intersecting_box;
157157
shapeAABB_a.find_intersection(shapeAABB_b,intersecting_box);
158-
btVector3 &m_min = intersecting_box.m_min, &m_max = intersecting_box.m_max;
158+
159+
return getBoundingBoxVolume(intersecting_box);
160+
}
161+
162+
double getBoundingBoxVolume(const btAABB &shapeAABB)
163+
{
164+
const btVector3 &m_min = shapeAABB.m_min, &m_max = shapeAABB.m_max;
159165
double volume = 1;
160166
for (int i = 0; i < 3 ; i++) volume *= m_max[i] - m_min[i];
161167
return std::abs(volume);

src/sequential_scene_hypothesis.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ bool SequentialSceneHypothesis::checkObjectObstruction(const std::string &model_
214214
}
215215

216216
std::cerr << " number of obstructed points: " << num_point_obstructed << "/" << model_cloud->size() << std::endl;
217-
return num_point_obstructed > 0.6 * model_cloud->size();
217+
return num_point_obstructed > 0.4 * model_cloud->size();
218218
}
219219

220220
bool SequentialSceneHypothesis::checkObjectReplaced(const std::string &object_name,
@@ -247,14 +247,15 @@ bool SequentialSceneHypothesis::checkObjectReplaced(const std::string &object_na
247247
Object target_model = obj_database_->getObjectProperty(model_name);
248248
col_obj->setCollisionShape(target_model.getCollisionShape());
249249
col_obj->setWorldTransform(object_pose);
250-
250+
// Replace AABB with OBB!!
251251
OverlappingObjectSensor result(*col_obj, object_name);
252252
this->physics_engine_->contactTest(col_obj,result);
253253

254254
delete col_obj;
255-
std::cerr << "Overlaps: " << result.total_penetration_depth_ << "; " << result.total_intersecting_volume_ << std::endl;
255+
std::cerr << "Overlaps: " << result.total_penetration_depth_ << "; " << result.total_intersecting_volume_
256+
<< " >? " << 0.3 * result.bounding_box_volume_ << std::endl;
256257

257-
return false;
258+
return result.total_intersecting_volume_ > 0.3 * result.bounding_box_volume_;
258259
}
259260

260261

0 commit comments

Comments
 (0)