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 
void deactivate() override
QCursor makeIconCursor(QString url, bool fill_cache)
QCursor getDefaultCursor(bool)
~MeasureTool() override
enum rviz::MeasureTool::@2 state_
void onInitialize() override
int processMouseEvent(ViewportMouseEvent &event) override
void setPoints(Ogre::Vector3 start, Ogre::Vector3 end)
Set the start and end point of the line.
Definition: line.cpp:78
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
void activate() override
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
DisplayContext * context_
Definition: tool.h:207
void setStatus(const QString &message)
Definition: tool.cpp:101
Ogre::Vector3 start_
Definition: measure_tool.h:69
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:67
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:88


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24