6 #include "../core/interaction.h" 7 #include "../core/log.h" 8 #include "../core/workspace.h" 9 #include "../displays/interactive.h" 10 #include "../displays/shapes.h" 11 #include "../render/mesh.h" 15 SceneAnnotationBase::SceneAnnotationBase() {}
17 bool SceneAnnotationBase::selected() {
18 return LockScope()->selection().contains(shared_from_this());
21 std::shared_ptr<SceneNode> SceneAnnotationBase::node() {
27 _node = std::make_shared<SceneNode>();
30 std::weak_ptr<Object> me = shared_from_this();
31 LockScope()->modified.connect(_node, [
this, me, s]() {
32 if (
auto me__ = me.lock()) {
35 LOG_DEBUG(
"selection " <<
int(s) <<
" " <<
int(v));
37 GlobalEvents::instance()->redraw();
45 void SceneAnnotationBase::renderSync(
47 const std::shared_ptr<AnnotationSpan> &span) {
49 _context = std::make_shared<SceneContext>();
51 _context->nodes.clear();
52 node()->renderSyncRecursive(context, *_context);
58 for (
auto &node : _context->nodes) {
60 node->renderAsync(context);
65 bool SceneAnnotationBase::pick(uint32_t
id)
const {
67 return _node->pick(
id);
73 bool SceneAnnotationBase::interact(
const Interaction &interaction) {
75 bool rs = _node->interact(interaction);
94 std::shared_ptr<InteractiveMarkerArray> _markers;
97 std::shared_ptr<SceneNode> _visual;
98 std::shared_ptr<Material> _material;
102 PROPERTY(
double, scale, 1.0, min = 0.0);
104 const std::shared_ptr<InteractiveMarkerArray> &
105 markers(
const std::shared_ptr<SceneNode> &node) {
108 std::make_shared<InteractiveMarkerParameters>());
112 virtual void update(
const std::shared_ptr<SceneNode> &node)
override {
113 SceneAnnotationBase::update(node);
116 virtual Eigen::Isometry3d virtualPose()
const = 0;
117 virtual void virtualPose(
const Eigen::Isometry3d &pose) = 0;
120 const std::shared_ptr<TrackBase> &track,
121 const std::shared_ptr<AnnotationSpan> &span)
override {
123 auto p = virtualPose();
124 p.linear() *= scale();
129 auto color = QColor::fromHsvF(track->color(), 0.8, 0.8);
130 _material->color() =
Color3(color.redF(), color.greenF(), color.blueF());
133 if (
auto m = _markers->marker(
"")) {
137 SceneAnnotationBase::renderSync(context, track, span);
139 virtual bool interact(
const Interaction &interaction)
override {
140 if (SceneAnnotationBase::interact(interaction)) {
142 if (
auto m = _markers->marker(
"")) {
143 if (interaction.finished) {
145 virtualPose(Eigen::Isometry3d(m->pose().matrix()));
149 virtualPose(Eigen::Isometry3d(m->pose().matrix()));
163 PROPERTY(Eigen::Vector3d, position);
164 virtual Eigen::Isometry3d virtualPose()
const override {
165 Eigen::Isometry3d pose = Eigen::Isometry3d::Identity();
166 pose.translation() = position();
169 virtual void virtualPose(
const Eigen::Isometry3d &pose)
override {
170 position() = pose.translation();
174 virtual void update(
const std::shared_ptr<SceneNode> &node)
override {
175 InteractiveSceneAnnotationBase::update(node);
177 _material = std::make_shared<Material>();
181 static auto mesh = std::make_shared<Mesh>(makeSphere().scale(0.22));
189 visualization_msgs::InteractiveMarker marker;
191 visualization_msgs::InteractiveMarkerControl control;
192 control.interaction_mode =
193 visualization_msgs::InteractiveMarkerControl::MOVE_3D;
194 control.always_visible =
true;
196 visualization_msgs::Marker marker;
197 marker.type = visualization_msgs::Marker::SPHERE;
198 marker.scale.x = 0.45;
199 marker.scale.y = 0.45;
200 marker.scale.z = 0.45;
201 marker.color.r = 0.5;
202 marker.color.g = 0.5;
203 marker.color.b = 0.5;
204 marker.color.a = 0.2;
205 control.markers.push_back(marker);
207 marker.controls.push_back(control);
210 visualization_msgs::InteractiveMarkerControl control;
211 control.orientation.w = 1;
212 control.orientation.x = 1;
213 control.orientation.y = 0;
214 control.orientation.z = 0;
215 control.name =
"move_x";
216 control.interaction_mode =
217 visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
218 marker.controls.push_back(control);
221 visualization_msgs::InteractiveMarkerControl control;
222 control.orientation.w = 1;
223 control.orientation.x = 0;
224 control.orientation.y = 1;
225 control.orientation.z = 0;
226 control.name =
"move_z";
227 control.interaction_mode =
228 visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
229 marker.controls.push_back(control);
232 visualization_msgs::InteractiveMarkerControl control;
233 control.orientation.w = 1;
234 control.orientation.x = 0;
235 control.orientation.y = 0;
236 control.orientation.z = 1;
237 control.name =
"move_y";
238 control.interaction_mode =
239 visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
240 marker.controls.push_back(control);
242 visualization_msgs::InteractiveMarkerInit init;
243 init.markers.push_back(marker);
244 markers(node)->init(init);