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


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:09