Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
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
51
MeasureTool::MeasureTool
() :
52
state_(START),
53
length_(-1)
54
{
55
}
56
57
MeasureTool::~MeasureTool
()
58
{
59
delete
line_
;
60
}
61
62
void
MeasureTool::onInitialize
()
63
{
64
line_
=
new
Line
(
context_
->
getSceneManager
());
65
66
std_cursor_
=
getDefaultCursor
();
67
hit_cursor_
=
makeIconCursor
(
"package://rviz/icons/crosshair.svg"
);
68
}
69
70
void
MeasureTool::activate
()
71
{
72
state_
=
START
;
73
}
74
75
void
MeasureTool::deactivate
()
76
{
77
}
78
79
int
MeasureTool::processMouseEvent
(
ViewportMouseEvent
& event )
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
;
122
line_
->
setPoints
(
start_
,
end_
);
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
141
#include <
pluginlib/class_list_macros.hpp
>
142
PLUGINLIB_EXPORT_CLASS
(
rviz::MeasureTool
,
rviz::Tool
)
rviz::MeasureTool::deactivate
virtual void deactivate()
Definition:
measure_tool.cpp:75
selection_manager.h
rviz::Tool
Definition:
tool.h:55
measure_tool.h
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition:
viewport_mouse_event.h:108
rviz::makeIconCursor
QCursor makeIconCursor(QString url, bool fill_cache)
Definition:
load_resource.cpp:102
rviz::MeasureTool::hit_cursor_
QCursor hit_cursor_
Definition:
measure_tool.h:74
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:110
rviz::Tool::Render
Definition:
tool.h:91
display_context.h
class_list_macros.hpp
rviz::MeasureTool::state_
enum rviz::MeasureTool::@2 state_
rviz::Line
Definition:
line.h:53
rviz::MeasureTool::~MeasureTool
virtual ~MeasureTool()
Definition:
measure_tool.cpp:57
viewport_mouse_event.h
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::getDefaultCursor
QCursor getDefaultCursor(bool fill_cache)
Definition:
load_resource.cpp:97
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
rviz::MeasureTool::MeasureTool
MeasureTool()
Definition:
measure_tool.cpp:51
rviz::ViewportMouseEvent::leftUp
bool leftUp()
Definition:
viewport_mouse_event.h:99
rviz::MeasureTool::START
Definition:
measure_tool.h:64
rviz::MeasureTool::std_cursor_
QCursor std_cursor_
Definition:
measure_tool.h:73
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:175
rviz::Tool::setStatus
void setStatus(const QString &message)
Definition:
tool.cpp:97
rviz::MeasureTool::processMouseEvent
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition:
measure_tool.cpp:79
rviz::MeasureTool::start_
Ogre::Vector3 start_
Definition:
measure_tool.h:69
rviz::ViewportMouseEvent::y
int y
Definition:
viewport_mouse_event.h:111
rviz::MeasureTool::END
Definition:
measure_tool.h:65
rviz::MeasureTool
Definition:
measure_tool.h:48
rviz::Tool::setCursor
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition:
tool.cpp:69
rviz::MeasureTool::onInitialize
virtual void onInitialize()
Definition:
measure_tool.cpp:62
rviz::ViewportMouseEvent::rightUp
bool rightUp()
Definition:
viewport_mouse_event.h:101
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
rviz::ViewportMouseEvent
Definition:
viewport_mouse_event.h:46
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:176
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::Line::setVisible
void setVisible(bool visible)
Definition:
line.cpp:89
rviz::MeasureTool::activate
virtual void activate()
Definition:
measure_tool.cpp:70
line.h
rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51