frame_position_tracking_view_controller.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <OgreCamera.h>
31 #include <OgreSceneManager.h>
32 #include <OgreSceneNode.h>
33 
34 #include "rviz/display_context.h"
35 #include "rviz/frame_manager.h"
39 #include "rviz/view_manager.h"
40 
42 
43 namespace rviz
44 {
46 {
49  "TF frame whose motion this view will follow.", this, nullptr, true);
50 }
51 
53 {
55 
56  target_scene_node_ = context_->getSceneManager()->getRootSceneNode()->createChildSceneNode();
57  camera_->detachFromParent();
58  target_scene_node_->attachObject(camera_);
59 }
60 
62 {
63  context_->getSceneManager()->destroySceneNode(target_scene_node_);
64 }
65 
67 {
69 
70  // Before activation, changes to target frame property should have
71  // no side-effects. After activation, changing target frame
72  // property has the side effect (typically) of changing an offset
73  // property so that the view does not jump. Therefore we make the
74  // signal/slot connection from the property here in onActivate()
75  // instead of in the constructor.
76  connect(target_frame_property_, SIGNAL(changed()), this, SLOT(updateTargetFrame()));
77 }
78 
79 void FramePositionTrackingViewController::update(float /*dt*/, float /*ros_dt*/)
80 {
82 }
83 
85 {
86  Ogre::Vector3 old_position = target_scene_node_->getPosition();
87  Ogre::Quaternion old_orientation = target_scene_node_->getOrientation();
88 
90 
91  onTargetFrameChanged(old_position, old_orientation);
92 }
93 
95 {
96  Ogre::Vector3 new_reference_position;
97  Ogre::Quaternion new_reference_orientation;
98 
99  bool got_transform =
101  new_reference_position, new_reference_orientation);
102  if (got_transform)
103  {
104  reference_position_ = new_reference_position;
105  reference_orientation_ = new_reference_orientation;
106  }
107  return got_transform;
108 }
109 
111 {
112  if (getNewTransform())
113  {
115 
117  }
118 
119  // Need to incorporate this functionality somehow.... Maybe right into TfFrameProperty itself.
131 }
132 
134 {
135  QVariant target_frame = source_view->subProp("Target Frame")->getValue();
136  if (target_frame.isValid())
137  {
138  target_frame_property_->setValue(target_frame);
139  }
140 }
141 
142 } // end namespace rviz
std::string getFrameStd() const
void changed()
Emitted by setValue() just after the value has changed.
std::string target_frame
Ogre::Camera * camera_
bool setValue(const QVariant &new_value) override
Override from Property to resolve the frame name on the way in.
void onInitialize() override
Do subclass-specific initialization.
virtual Property * subProp(const QString &sub_name)
Return the first child Property with the given name, or the FailureProperty if no child has the name...
Definition: property.cpp:179
virtual void onTargetFrameChanged(const Ogre::Vector3 &, const Ogre::Quaternion &)
Override to implement the change in properties which nullifies the change in target frame...
void update(float dt, float ros_dt) override
Called at 30Hz by ViewManager::update() while this view is active. Override with code that needs to r...
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
static const QString FIXED_FRAME_STRING
virtual void updateTargetFrame()
Called when Target Frame property changes while view is active. Purpose is to change values in the vi...
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Return the pose for a header, relative to the fixed frame, in Ogre classes.
void setFrameManager(FrameManager *frame_manager)
virtual void updateTargetSceneNode()
Update the position of the target_scene_node_ from the TF frame specified in the Target Frame propert...
void mimic(ViewController *source_view) override
Configure the settings of this view controller to give, as much as possible, a similar view as that g...
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
Definition: property.cpp:150
DisplayContext * context_


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24