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 {
45 
47  : target_scene_node_( NULL )
48 {
50  "TF frame whose motion this view will follow.", this, NULL, true );
51 }
52 
54 {
56 
57  target_scene_node_ = context_->getSceneManager()->getRootSceneNode()->createChildSceneNode();
58  camera_->detachFromParent();
59  target_scene_node_->attachObject( camera_ );
60 }
61 
63 {
64  context_->getSceneManager()->destroySceneNode( target_scene_node_ );
65 }
66 
68 {
70 
71  // Before activation, changes to target frame property should have
72  // no side-effects. After activation, changing target frame
73  // property has the side effect (typically) of changing an offset
74  // property so that the view does not jump. Therefore we make the
75  // signal/slot connection from the property here in onActivate()
76  // instead of in the constructor.
77  connect( target_frame_property_, SIGNAL( changed() ), this, SLOT( updateTargetFrame() ));
78 }
79 
80 void FramePositionTrackingViewController::update(float dt, float ros_dt)
81 {
83 }
84 
86 {
87  Ogre::Vector3 old_position = target_scene_node_->getPosition();
88  Ogre::Quaternion old_orientation = target_scene_node_->getOrientation();
89 
91 
92  onTargetFrameChanged( old_position, old_orientation );
93 }
94 
96 {
97  Ogre::Vector3 new_reference_position;
98  Ogre::Quaternion new_reference_orientation;
99 
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  {
114  target_scene_node_->setPosition( reference_position_ );
115 
117  }
118 
119 // Need to incorporate this functionality somehow.... Maybe right into TfFrameProperty itself.
130 
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
virtual void onTargetFrameChanged(const Ogre::Vector3 &old_reference_position, const Ogre::Quaternion &old_reference_orientation)
Override to implement the change in properties which nullifies the change in target frame...
#define NULL
Definition: global.h:37
virtual void mimic(ViewController *source_view)
Configure the settings of this view controller to give, as much as possible, a similar view as that g...
void changed()
Emitted by setValue() just after the value has changed.
std::string target_frame
virtual bool setValue(const QVariant &new_value)
Override from Property to resolve the frame name on the way in.
Ogre::Camera * camera_
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:174
virtual void update(float dt, float ros_dt)
Called at 30Hz by ViewManager::update() while this view is active. Override with code that needs to r...
std::string getFrameStd() const
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.
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:145
void setFrameManager(FrameManager *frame_manager)
virtual void onInitialize()
Do subclass-specific initialization. Called by ViewController::initialize after context_, target_scene_node_, and camera_ are set. This version calls updateTargetSceneNode().
virtual void updateTargetSceneNode()
Update the position of the target_scene_node_ from the TF frame specified in the Target Frame propert...
DisplayContext * context_


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:41