forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_object.cc
129 lines (103 loc) · 3.58 KB
/
query_object.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "drake/geometry/query_object.h"
#include "drake/common/default_scalars.h"
#include "drake/common/drake_assert.h"
#include "drake/geometry/scene_graph.h"
namespace drake {
namespace geometry {
using math::RigidTransform;
template <typename T>
QueryObject<T>::QueryObject(const QueryObject& query_object) {
*this = query_object;
}
template <typename T>
QueryObject<T>& QueryObject<T>::operator=(const QueryObject<T>& query_object) {
if (this == &query_object) return *this;
DRAKE_DEMAND(query_object.is_copyable());
context_ = nullptr;
scene_graph_ = nullptr;
state_.reset();
if (query_object.state_) {
// Share the underlying baked state.
state_ = query_object.state_;
} else if (query_object.context_ && query_object.scene_graph_) {
// Create a new baked state; make sure the source is fully updated.
query_object.FullPoseUpdate();
state_ = std::make_shared<GeometryState<T>>(query_object.geometry_state());
}
inspector_.set(state_.get());
// If `query_object` is default, then this will likewise be default.
return *this;
}
template <typename T>
RigidTransform<T> QueryObject<T>::X_WF(FrameId id) const {
ThrowIfNotCallable();
FullPoseUpdate();
const GeometryState<T>& state = geometry_state();
return RigidTransform<T>(state.get_pose_in_world(id));
}
template <typename T>
RigidTransform<T> QueryObject<T>::X_PF(FrameId id) const {
ThrowIfNotCallable();
FullPoseUpdate();
const GeometryState<T>& state = geometry_state();
return RigidTransform<T>(state.get_pose_in_parent(id));
}
template <typename T>
RigidTransform<T> QueryObject<T>::X_WG(GeometryId id) const {
ThrowIfNotCallable();
FullPoseUpdate();
const GeometryState<T>& state = geometry_state();
return RigidTransform<T>(state.get_pose_in_world(id));
}
template <typename T>
std::vector<ContactSurface<T>>
QueryObject<T>::ComputeContactSurfaces() const {
ThrowIfNotCallable();
// TODO(DamrongGuoy): Modify this when the cache system is in place.
FullPoseUpdate();
const GeometryState<T>& state = geometry_state();
return state.ComputeContactSurfaces();
}
template <typename T>
std::vector<PenetrationAsPointPair<double>>
QueryObject<T>::ComputePointPairPenetration() const {
ThrowIfNotCallable();
// TODO(SeanCurtis-TRI): Modify this when the cache system is in place.
FullPoseUpdate();
const GeometryState<T>& state = geometry_state();
return state.ComputePointPairPenetration();
}
template <typename T>
std::vector<SignedDistancePair<T>>
QueryObject<T>::ComputeSignedDistancePairwiseClosestPoints(
const double max_distance) const {
ThrowIfNotCallable();
// TODO(SeanCurtis-TRI): Modify this when the cache system is in place.
FullPoseUpdate();
const GeometryState<T>& state = geometry_state();
return state.ComputeSignedDistancePairwiseClosestPoints(max_distance);
}
template <typename T>
std::vector<SignedDistanceToPoint<T>>
QueryObject<T>::ComputeSignedDistanceToPoint(
const Vector3<T>& p_WQ,
const double threshold) const {
ThrowIfNotCallable();
FullPoseUpdate();
const GeometryState<T>& state = geometry_state();
return state.ComputeSignedDistanceToPoint(p_WQ, threshold);
}
template <typename T>
const GeometryState<T>& QueryObject<T>::geometry_state() const {
// Some extra insurance in case some query *hadn't* called this.
DRAKE_ASSERT_VOID(ThrowIfNotCallable());
if (context_) {
return scene_graph_->geometry_state(*context_);
} else {
return *state_;
}
}
} // namespace geometry
} // namespace drake
DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS(
class ::drake::geometry::QueryObject)