ClusterLabelTool.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Robot Operating System code by the University of Osnabrück
5  * Copyright (c) 2015, University of Osnabrück
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  *
21  * 3. Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  *
39  *
40  * ClusterLabelTool.hpp
41  *
42  * authors:
43  * Kristin Schmidt <krschmidt@uos.de>
44  * Jan Philipp Vogtherr <jvogtherr@uos.de>
45  *
46  */
47 
48 #ifndef CLUSTER_LABEL_TOOL_HPP
49 #define CLUSTER_LABEL_TOOL_HPP
50 
51 // enable exceptions for OpenCL
52 #define CL_HPP_TARGET_OPENCL_VERSION 120
53 #define CL_HPP_MINIMUM_OPENCL_VERSION 110
54 #define CL_HPP_ENABLE_EXCEPTIONS
55 
56 #include <Types.hpp>
57 
58 #include <CL/cl2.hpp>
59 
60 #include <vector>
61 #include <map>
62 #include <memory>
63 #include <boost/lexical_cast.hpp>
64 #include <boost/optional.hpp>
65 
66 #include <QMessageBox>
67 #include <QApplication>
68 #include <QIcon>
69 #include <QObject>
70 #include <QWidget>
71 #include <QFrame>
72 
73 #include <ros/console.h>
76 #include <rviz/geometry.h>
77 
78 #include <rviz/display_context.h>
79 #include <rviz/frame_manager.h>
80 #include <rviz/display.h>
81 
82 #include <rviz/tool.h>
83 #include <rviz/tool_manager.h>
84 #include <rviz/display_group.h>
85 
86 #include <mesh_msgs/MeshFaceClusterStamped.h>
87 
88 #ifndef Q_MOC_RUN
89 #include <rviz/mesh_loader.h>
90 
91 #include <OGRE/OgreManualObject.h>
92 #include <OGRE/OgreSceneNode.h>
93 #include <OGRE/OgreSceneManager.h>
94 #include <OGRE/OgreEntity.h>
95 #include <OGRE/OgreStringConverter.h>
96 #include <OGRE/OgreMaterialManager.h>
97 #include <OGRE/OgreRay.h>
98 #include <OGRE/OgreSceneQuery.h>
99 
100 #endif
101 
102 namespace rviz
103 {
104 class RosTopicProperty;
105 class ColorProperty;
106 } // namespace rviz
107 
108 // OGRE stuff
109 namespace Ogre
110 {
111 // Forward declaration
112 class Vector3;
113 } // namespace Ogre
114 
115 namespace rviz_map_plugin
116 {
117 // Forward declarations
118 class ClusterLabelDisplay;
119 class ClusterLabelVisual;
120 
126 {
127  Q_OBJECT
128 public:
133 
138 
142  virtual void onInitialize();
143 
147  virtual void activate();
148 
152  virtual void deactivate();
153 
159  virtual int processMouseEvent(rviz::ViewportMouseEvent& event);
160 
165  void setDisplay(ClusterLabelDisplay* display);
166 
171  void setVisual(std::shared_ptr<ClusterLabelVisual> visual);
172 
177  void setSphereSize(float size);
178 
179 public Q_SLOTS:
180 
185  void publishLabel(std::string name);
186 
191  std::vector<uint32_t> getSelectedFaces();
192 
196  void resetFaces();
197 
201  void resetVisual();
202 
203 private:
204  std::vector<uint32_t> m_selectedFaces;
205  std::vector<bool> m_faceSelectedArray;
208  std::shared_ptr<ClusterLabelVisual> m_visual;
209  std::shared_ptr<Geometry> m_meshGeometry;
210  float m_sphereSize = 1.0f;
211 
212  // Selection Box
214  Ogre::SceneNode* m_sceneNode;
215  Ogre::ManualObject* m_selectionBox;
216  Ogre::MaterialPtr m_selectionBoxMaterial;
217  Ogre::Vector2 m_selectionStart;
218  Ogre::Vector2 m_selectionStop;
219  bool m_multipleSelect = false;
220  bool m_singleSelect = false;
221  bool m_singleDeselect = false;
222 
223  std::vector<Ogre::Vector3> m_vertexPositions;
224 
225  void updateSelectionBox();
228  void selectMultipleFaces(rviz::ViewportMouseEvent& event, bool selectMode);
229  void selectFacesInBoxParallel(Ogre::PlaneBoundedVolume& volume, bool selectMode);
230  void selectSingleFace(rviz::ViewportMouseEvent& event, bool selectMode);
231  void selectSingleFaceParallel(Ogre::Ray& ray, bool selectMode);
232  void selectSphereFaces(rviz::ViewportMouseEvent& event, bool selectMode);
233  void selectSphereFacesParallel(Ogre::Ray& ray, bool selectMode);
234  boost::optional<std::pair<uint32_t, float>> getClosestIntersectedFaceParallel(Ogre::Ray& ray);
235 
237 
238  std::vector<float> m_vertexData;
239  std::array<float, 6> m_rayData;
240  std::array<float, 4> m_sphereData;
241  std::array<float, 3> m_startNormalData;
242  std::vector<float> m_boxData;
243  std::vector<float> m_resultDistances;
244 
245  // OpenCL
246  cl::Device m_clDevice;
247  cl::Context m_clContext;
248  cl::Program::Sources m_clProgramSources;
249  cl::Program m_clProgram;
250  cl::CommandQueue m_clQueue;
251  cl::Buffer m_clVertexBuffer;
252  cl::Buffer m_clResultBuffer;
253  cl::Buffer m_clRayBuffer;
254  cl::Buffer m_clSphereBuffer;
255  cl::Buffer m_clBoxBuffer;
258  cl::Kernel m_clKernelSphere;
259  cl::Kernel m_clKernelBox;
261 };
262 } // end namespace rviz_map_plugin
263 
264 #endif
rviz_map_plugin::ClusterLabelTool
Tool for selecting faces.
Definition: ClusterLabelTool.hpp:125
rviz_map_plugin::ClusterLabelTool::selectionBoxMove
void selectionBoxMove(rviz::ViewportMouseEvent &event)
Definition: ClusterLabelTool.cpp:357
rviz_map_plugin::ClusterLabelTool::m_faceSelectedArray
std::vector< bool > m_faceSelectedArray
Definition: ClusterLabelTool.hpp:205
rviz_map_plugin::ClusterLabelTool::m_displayInitialized
bool m_displayInitialized
Definition: ClusterLabelTool.hpp:206
Ogre
ros::Publisher
rviz_map_plugin::ClusterLabelTool::selectMultipleFaces
void selectMultipleFaces(rviz::ViewportMouseEvent &event, bool selectMode)
Definition: ClusterLabelTool.cpp:364
rviz::Tool
rviz_map_plugin::ClusterLabelTool::m_display
ClusterLabelDisplay * m_display
Definition: ClusterLabelTool.hpp:207
display_group.h
rviz_map_plugin::ClusterLabelTool::m_startNormalData
std::array< float, 3 > m_startNormalData
Definition: ClusterLabelTool.hpp:241
mesh_loader.h
rviz_map_plugin::ClusterLabelTool::m_selectedFaces
std::vector< uint32_t > m_selectedFaces
Definition: ClusterLabelTool.hpp:204
rviz_map_plugin::ClusterLabelTool::selectSphereFacesParallel
void selectSphereFacesParallel(Ogre::Ray &ray, bool selectMode)
Definition: ClusterLabelTool.cpp:532
rviz::ViewportMouseEvent
frame_manager.h
rviz_map_plugin::ClusterLabelTool::selectSingleFaceParallel
void selectSingleFaceParallel(Ogre::Ray &ray, bool selectMode)
Definition: ClusterLabelTool.cpp:464
rviz_map_plugin::ClusterLabelTool::publishLabel
void publishLabel(std::string name)
Publish a label with a given namen.
Definition: ClusterLabelTool.cpp:636
rviz_map_plugin::ClusterLabelTool::m_clKernelDirAndDist
cl::Kernel m_clKernelDirAndDist
Definition: ClusterLabelTool.hpp:260
viewport_mouse_event.h
rviz_map_plugin::ClusterLabelTool::selectionBoxStart
void selectionBoxStart(rviz::ViewportMouseEvent &event)
Definition: ClusterLabelTool.cpp:348
rviz_map_plugin::ClusterLabelTool::m_visual
std::shared_ptr< ClusterLabelVisual > m_visual
Definition: ClusterLabelTool.hpp:208
rviz_map_plugin::ClusterLabelTool::m_singleSelect
bool m_singleSelect
Definition: ClusterLabelTool.hpp:220
rviz_map_plugin::ClusterLabelTool::m_selectionStart
Ogre::Vector2 m_selectionStart
Definition: ClusterLabelTool.hpp:217
display.h
rviz_map_plugin::ClusterLabelTool::m_boxData
std::vector< float > m_boxData
Definition: ClusterLabelTool.hpp:242
rviz_map_plugin::ClusterLabelTool::m_clKernelSphere
cl::Kernel m_clKernelSphere
Definition: ClusterLabelTool.hpp:258
rviz_map_plugin::ClusterLabelTool::~ClusterLabelTool
~ClusterLabelTool()
Destructor.
Definition: ClusterLabelTool.cpp:82
visualization_manager.h
rviz_map_plugin::ClusterLabelTool::m_sphereSize
float m_sphereSize
Definition: ClusterLabelTool.hpp:210
rviz_map_plugin::ClusterLabelTool::resetVisual
void resetVisual()
Resets the current visual.
Definition: ClusterLabelTool.cpp:732
tool_manager.h
rviz_map_plugin::ClusterLabelTool::m_vertexPositions
std::vector< Ogre::Vector3 > m_vertexPositions
Definition: ClusterLabelTool.hpp:223
rviz_map_plugin::ClusterLabelTool::m_clKernelSingleRay
cl::Kernel m_clKernelSingleRay
Definition: ClusterLabelTool.hpp:257
rviz_map_plugin::ClusterLabelTool::m_clVertexBuffer
cl::Buffer m_clVertexBuffer
Definition: ClusterLabelTool.hpp:251
rviz_map_plugin::ClusterLabelDisplay
Display class for the map plugin.
Definition: ClusterLabelDisplay.hpp:136
console.h
rviz_map_plugin::ClusterLabelTool::selectSingleFace
void selectSingleFace(rviz::ViewportMouseEvent &event, bool selectMode)
Definition: ClusterLabelTool.cpp:457
rviz_map_plugin::ClusterLabelTool::selectFacesInBoxParallel
void selectFacesInBoxParallel(Ogre::PlaneBoundedVolume &volume, bool selectMode)
Definition: ClusterLabelTool.cpp:399
rviz_map_plugin::ClusterLabelTool::getSelectedFaces
std::vector< uint32_t > getSelectedFaces()
Returns a list of selected face ID's.
Definition: ClusterLabelTool.cpp:709
rviz_map_plugin::ClusterLabelTool::m_clQueue
cl::CommandQueue m_clQueue
Definition: ClusterLabelTool.hpp:250
rviz_map_plugin::ClusterLabelTool::setSphereSize
void setSphereSize(float size)
Adjust the sphere size for the brush tool.
Definition: ClusterLabelTool.cpp:247
rviz_map_plugin::ClusterLabelTool::getClosestIntersectedFaceParallel
boost::optional< std::pair< uint32_t, float > > getClosestIntersectedFaceParallel(Ogre::Ray &ray)
Definition: ClusterLabelTool.cpp:589
rviz_map_plugin::ClusterLabelTool::m_clResultBuffer
cl::Buffer m_clResultBuffer
Definition: ClusterLabelTool.hpp:252
rviz_map_plugin::ClusterLabelTool::m_sceneNode
Ogre::SceneNode * m_sceneNode
Definition: ClusterLabelTool.hpp:214
rviz
rviz_map_plugin::ClusterLabelTool::m_clRayBuffer
cl::Buffer m_clRayBuffer
Definition: ClusterLabelTool.hpp:253
rviz_map_plugin::ClusterLabelTool::resetFaces
void resetFaces()
Resets the list of selected faces.
Definition: ClusterLabelTool.cpp:723
Vector3
rviz_map_plugin::ClusterLabelTool::ClusterLabelTool
ClusterLabelTool()
Constructor.
Definition: ClusterLabelTool.cpp:74
rviz_map_plugin::ClusterLabelTool::m_clStartNormalBuffer
cl::Buffer m_clStartNormalBuffer
Definition: ClusterLabelTool.hpp:256
rviz_map_plugin::ClusterLabelTool::m_meshGeometry
std::shared_ptr< Geometry > m_meshGeometry
Definition: ClusterLabelTool.hpp:209
rviz_map_plugin::ClusterLabelTool::deactivate
virtual void deactivate()
Definition: ClusterLabelTool.cpp:257
rviz_map_plugin::ClusterLabelTool::m_clBoxBuffer
cl::Buffer m_clBoxBuffer
Definition: ClusterLabelTool.hpp:255
rviz_map_plugin::ClusterLabelTool::m_displayContext
rviz::DisplayContext * m_displayContext
Definition: ClusterLabelTool.hpp:213
rviz_map_plugin::ClusterLabelTool::m_labelPublisher
ros::Publisher m_labelPublisher
Definition: ClusterLabelTool.hpp:236
rviz_map_plugin::ClusterLabelTool::updateSelectionBox
void updateSelectionBox()
Definition: ClusterLabelTool.cpp:328
rviz::DisplayContext
Types.hpp
rviz_map_plugin::ClusterLabelTool::m_selectionBox
Ogre::ManualObject * m_selectionBox
Definition: ClusterLabelTool.hpp:215
rviz_map_plugin::ClusterLabelTool::setDisplay
void setDisplay(ClusterLabelDisplay *display)
Connects this tool with a given display.
Definition: ClusterLabelTool.cpp:261
rviz_map_plugin::ClusterLabelTool::m_vertexData
std::vector< float > m_vertexData
Definition: ClusterLabelTool.hpp:238
geometry.h
rviz_map_plugin::ClusterLabelTool::m_selectionBoxMaterial
Ogre::MaterialPtr m_selectionBoxMaterial
Definition: ClusterLabelTool.hpp:216
rviz_map_plugin::ClusterLabelTool::m_resultDistances
std::vector< float > m_resultDistances
Definition: ClusterLabelTool.hpp:243
rviz_map_plugin::ClusterLabelTool::setVisual
void setVisual(std::shared_ptr< ClusterLabelVisual > visual)
Connects this tool with a given visual.
Definition: ClusterLabelTool.cpp:231
rviz_map_plugin::ClusterLabelTool::activate
virtual void activate()
RViz callback for activating.
Definition: ClusterLabelTool.cpp:253
rviz_map_plugin::ClusterLabelTool::onInitialize
virtual void onInitialize()
RViz callback on initialize.
Definition: ClusterLabelTool.cpp:92
rviz_map_plugin
Definition: ClusterLabelDisplay.hpp:120
rviz_map_plugin::ClusterLabelTool::m_sphereData
std::array< float, 4 > m_sphereData
Definition: ClusterLabelTool.hpp:240
rviz_map_plugin::ClusterLabelTool::m_multipleSelect
bool m_multipleSelect
Definition: ClusterLabelTool.hpp:219
rviz_map_plugin::ClusterLabelTool::m_rayData
std::array< float, 6 > m_rayData
Definition: ClusterLabelTool.hpp:239
rviz_map_plugin::ClusterLabelTool::m_clProgramSources
cl::Program::Sources m_clProgramSources
Definition: ClusterLabelTool.hpp:248
rviz_map_plugin::ClusterLabelTool::selectSphereFaces
void selectSphereFaces(rviz::ViewportMouseEvent &event, bool selectMode)
Definition: ClusterLabelTool.cpp:525
rviz_map_plugin::ClusterLabelTool::m_clContext
cl::Context m_clContext
Definition: ClusterLabelTool.hpp:247
rviz_map_plugin::ClusterLabelTool::processMouseEvent
virtual int processMouseEvent(rviz::ViewportMouseEvent &event)
RViz callback for mouse events.
Definition: ClusterLabelTool.cpp:651
rviz_map_plugin::ClusterLabelTool::m_clKernelBox
cl::Kernel m_clKernelBox
Definition: ClusterLabelTool.hpp:259
rviz_map_plugin::ClusterLabelTool::m_clProgram
cl::Program m_clProgram
Definition: ClusterLabelTool.hpp:249
rviz_map_plugin::ClusterLabelTool::m_singleDeselect
bool m_singleDeselect
Definition: ClusterLabelTool.hpp:221
tool.h
rviz_map_plugin::ClusterLabelTool::m_clSphereBuffer
cl::Buffer m_clSphereBuffer
Definition: ClusterLabelTool.hpp:254
rviz_map_plugin::ClusterLabelTool::m_clDevice
cl::Device m_clDevice
Definition: ClusterLabelTool.hpp:246
display_context.h
rviz_map_plugin::ClusterLabelTool::m_selectionStop
Ogre::Vector2 m_selectionStop
Definition: ClusterLabelTool.hpp:218


rviz_map_plugin
Author(s): Sebastian Pütz , Kristin Schmidt , Jan Philipp Vogtherr , Malte kleine Piening
autogenerated on Sun Jan 21 2024 04:06:25