pose_tool.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 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 <OgrePlane.h>
31 #include <OgreRay.h>
32 #include <OgreSceneNode.h>
33 #include <OgreViewport.h>
34 
35 #include "rviz/geometry.h"
38 #include "rviz/load_resource.h"
39 #include "rviz/render_panel.h"
40 
42 
43 namespace rviz
44 {
45 
47  : Tool()
48  , arrow_( NULL )
49 {
50 }
51 
53 {
54  delete arrow_;
55 }
56 
58 {
59  arrow_ = new Arrow( scene_manager_, NULL, 2.0f, 0.2f, 0.5f, 0.35f );
60  arrow_->setColor( 0.0f, 1.0f, 0.0f, 1.0f );
61  arrow_->getSceneNode()->setVisible( false );
62 }
63 
65 {
66  setStatus( "Click and drag mouse to set position/orientation." );
67  state_ = Position;
68 }
69 
71 {
72  arrow_->getSceneNode()->setVisible( false );
73 }
74 
76 {
77  int flags = 0;
78 
79  if( event.leftDown() )
80  {
82 
83  Ogre::Vector3 intersection;
84  Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0.0f );
86  ground_plane,
87  event.x, event.y, intersection ))
88  {
89  pos_ = intersection;
91 
93  flags |= Render;
94  }
95  }
96  else if( event.type == QEvent::MouseMove && event.left() )
97  {
98  if( state_ == Orientation )
99  {
100  //compute angle in x-y plane
101  Ogre::Vector3 cur_pos;
102  Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0.0f );
104  ground_plane,
105  event.x, event.y, cur_pos ))
106  {
107  double angle = atan2( cur_pos.y - pos_.y, cur_pos.x - pos_.x );
108 
109  arrow_->getSceneNode()->setVisible( true );
110 
111  //we need base_orient, since the arrow goes along the -z axis by default (for historical reasons)
112  Ogre::Quaternion orient_x = Ogre::Quaternion( Ogre::Radian(-Ogre::Math::HALF_PI), Ogre::Vector3::UNIT_Y );
113 
114  arrow_->setOrientation( Ogre::Quaternion( Ogre::Radian(angle), Ogre::Vector3::UNIT_Z ) * orient_x );
115 
116  flags |= Render;
117  }
118  }
119  }
120  else if( event.leftUp() )
121  {
122  if( state_ == Orientation )
123  {
124  //compute angle in x-y plane
125  Ogre::Vector3 cur_pos;
126  Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0.0f );
128  ground_plane,
129  event.x, event.y, cur_pos ))
130  {
131  double angle = atan2( cur_pos.y - pos_.y, cur_pos.x - pos_.x );
132 
133  onPoseSet(pos_.x, pos_.y, angle);
134 
135  flags |= (Finished|Render);
136  }
137  }
138  }
139 
140  return flags;
141 }
142 
143 }
144 
Ogre::SceneManager * scene_manager_
Definition: tool.h:174
#define NULL
Definition: global.h:37
virtual void activate()
Definition: pose_tool.cpp:64
Ogre::Vector3 pos_
Definition: pose_tool.h:71
f
virtual ~PoseTool()
Definition: pose_tool.cpp:52
virtual void deactivate()
Definition: pose_tool.cpp:70
Arrow * arrow_
Definition: pose_tool.h:62
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this arrow.
Definition: arrow.h:143
virtual void setPosition(const Ogre::Vector3 &position)
Set the position of the base of the arrow.
Definition: arrow.cpp:111
State state_
Definition: pose_tool.h:69
virtual void onPoseSet(double x, double y, double theta)=0
virtual void onInitialize()
Definition: pose_tool.cpp:57
virtual void setColor(float r, float g, float b, float a)
Set the color of this arrow. Sets both the head and shaft color to the same value. Values are in the range [0, 1].
Definition: arrow.cpp:86
virtual void setOrientation(const Ogre::Quaternion &orientation)
Set the orientation.
Definition: arrow.cpp:116
bool getPointOnPlaneFromWindowXY(Ogre::Viewport *viewport, Ogre::Plane &plane, int window_x, int window_y, Ogre::Vector3 &intersection_out)
Given a viewport and an x,y position in window-pixel coordinates, find the point on a plane directly ...
Definition: geometry.cpp:44
void setStatus(const QString &message)
Definition: tool.cpp:97
An arrow consisting of a cylinder and a cone.
Definition: arrow.h:59
#define ROS_ASSERT(cond)
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition: pose_tool.cpp:75


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