measure_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  * measure_tool.cpp
31  *
32  * Created on: Aug 8, 2012
33  * Author: gossow
34  */
35 
36 #include "measure_tool.h"
37 
38 #include "rviz/ogre_helpers/line.h"
40 #include "rviz/display_context.h"
42 #include "rviz/load_resource.h"
43 
44 #include <OgreSceneNode.h>
45 
46 #include <sstream>
47 
48 namespace rviz
49 {
50 
52  state_(START),
53  length_(-1)
54 {
55 }
56 
58 {
59  delete line_;
60 }
61 
63 {
65 
67  hit_cursor_ = makeIconCursor( "package://rviz/icons/crosshair.svg" );
68 }
69 
71 {
72  state_ = START;
73 }
74 
76 {
77 }
78 
80 {
81  int flags = 0;
82 
83  Ogre::Vector3 pos;
84 
85  std::stringstream ss;
86 
87  bool success = context_->getSelectionManager()->get3DPoint( event.viewport, event.x, event.y, pos );
88  setCursor( success ? hit_cursor_ : std_cursor_ );
89 
90  switch ( state_ )
91  {
92  case START:
93  break;
94  case END:
95  if ( success )
96  {
97  line_->setPoints(start_,pos);
98  length_ = (start_-pos).length();
99  }
100  break;
101  }
102 
103  if ( length_ > 0.0 )
104  {
105  ss << "[Length: " << length_ << "m] ";
106  }
107 
108  ss << "Click on two points to measure their distance. Right-click to reset.";
109  setStatus( QString( ss.str().c_str() ) );
110 
111  if( event.leftUp() && success )
112  {
113  switch ( state_ )
114  {
115  case START:
116  start_ = pos;
117  state_ = END;
118  break;
119  case END:
120  end_ = pos;
121  state_ = START;
123  break;
124  }
125 
126  flags |= Render;
127  }
128 
129  if ( event.rightUp() )
130  {
131  state_ = START;
132  line_->setVisible(false);
133  }
134 
135  return flags;
136 }
137 
138 } /* namespace rviz */
139 
140 
virtual void deactivate()
QCursor makeIconCursor(QString url, bool fill_cache)
enum rviz::MeasureTool::@2 state_
virtual ~MeasureTool()
void setPoints(Ogre::Vector3 start, Ogre::Vector3 end)
Set the start and end point of the line.
Definition: line.cpp:79
QCursor getDefaultCursor(bool fill_cache)
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
DisplayContext * context_
Definition: tool.h:175
void setStatus(const QString &message)
Definition: tool.cpp:97
virtual int processMouseEvent(ViewportMouseEvent &event)
Ogre::Vector3 start_
Definition: measure_tool.h:69
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:69
virtual void onInitialize()
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
Ogre::Vector3 end_
Definition: measure_tool.h:70
bool get3DPoint(Ogre::Viewport *viewport, const int x, const int y, Ogre::Vector3 &result_point)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void setVisible(bool visible)
Definition: line.cpp:89
virtual void activate()


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51