src
rviz
default_plugin
tools
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
"
39
#include "
rviz/viewport_mouse_event.h
"
40
#include "
rviz/display_context.h
"
41
#include "
rviz/selection/selection_manager.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
54
MeasureTool::~MeasureTool
()
55
{
56
delete
line_
;
57
}
58
59
void
MeasureTool::onInitialize
()
60
{
61
line_
=
new
Line
(
context_
->
getSceneManager
());
62
63
std_cursor_
=
getDefaultCursor
();
64
hit_cursor_
=
makeIconCursor
(
"package://rviz/icons/crosshair.svg"
);
65
}
66
67
void
MeasureTool::activate
()
68
{
69
state_
=
START
;
70
}
71
72
void
MeasureTool::deactivate
()
73
{
74
}
75
76
int
MeasureTool::processMouseEvent
(
ViewportMouseEvent
& event)
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
;
119
line_
->
setPoints
(
start_
,
end_
);
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
138
#include <
pluginlib/class_list_macros.hpp
>
139
PLUGINLIB_EXPORT_CLASS
(
rviz::MeasureTool
,
rviz::Tool
)
rviz::MeasureTool::deactivate
void deactivate() override
Definition:
measure_tool.cpp:72
selection_manager.h
rviz::Tool
Definition:
tool.h:56
measure_tool.h
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition:
viewport_mouse_event.h:145
rviz::makeIconCursor
QCursor makeIconCursor(QString url, bool fill_cache)
Definition:
load_resource.cpp:101
rviz::MeasureTool::hit_cursor_
QCursor hit_cursor_
Definition:
measure_tool.h:74
rviz::getDefaultCursor
QCursor getDefaultCursor(bool)
Definition:
load_resource.cpp:96
rviz::MeasureTool::length_
float length_
Definition:
measure_tool.h:71
load_resource.h
rviz
Definition:
add_display_dialog.cpp:54
rviz::ViewportMouseEvent::x
int x
Definition:
viewport_mouse_event.h:147
rviz::Tool::Render
Definition:
tool.h:102
rviz::MeasureTool::~MeasureTool
~MeasureTool() override
Definition:
measure_tool.cpp:54
display_context.h
class_list_macros.hpp
rviz::MeasureTool::state_
enum rviz::MeasureTool::@2 state_
rviz::Line
Definition:
line.h:52
rviz::MeasureTool::onInitialize
void onInitialize() override
Definition:
measure_tool.cpp:59
viewport_mouse_event.h
rviz::MeasureTool::processMouseEvent
int processMouseEvent(ViewportMouseEvent &event) override
Definition:
measure_tool.cpp:76
rviz::Line::setPoints
void setPoints(Ogre::Vector3 start, Ogre::Vector3 end)
Set the start and end point of the line.
Definition:
line.cpp:78
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
rviz::MeasureTool::MeasureTool
MeasureTool()
Definition:
measure_tool.cpp:50
rviz::ViewportMouseEvent::leftUp
bool leftUp()
Definition:
viewport_mouse_event.h:118
rviz::MeasureTool::START
Definition:
measure_tool.h:64
rviz::MeasureTool::std_cursor_
QCursor std_cursor_
Definition:
measure_tool.h:73
rviz::MeasureTool::activate
void activate() override
Definition:
measure_tool.cpp:67
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
rviz::MeasureTool::line_
Line * line_
Definition:
measure_tool.h:68
rviz::Tool::context_
DisplayContext * context_
Definition:
tool.h:207
rviz::Tool::setStatus
void setStatus(const QString &message)
Definition:
tool.cpp:101
rviz::MeasureTool::start_
Ogre::Vector3 start_
Definition:
measure_tool.h:69
rviz::ViewportMouseEvent::y
int y
Definition:
viewport_mouse_event.h:148
rviz::MeasureTool::END
Definition:
measure_tool.h:65
rviz::MeasureTool
Definition:
measure_tool.h:47
rviz::Tool::setCursor
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition:
tool.cpp:67
rviz::ViewportMouseEvent::rightUp
bool rightUp()
Definition:
viewport_mouse_event.h:126
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
rviz::ViewportMouseEvent
Definition:
viewport_mouse_event.h:45
rviz::MeasureTool::end_
Ogre::Vector3 end_
Definition:
measure_tool.h:70
rviz::SelectionManager::get3DPoint
bool get3DPoint(Ogre::Viewport *viewport, const int x, const int y, Ogre::Vector3 &result_point)
Definition:
selection_manager.cpp:178
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::Line::setVisible
void setVisible(bool visible)
Definition:
line.cpp:88
line.h
rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24