Point Cloud Library (PCL) 1.13.1
Loading...
Searching...
No Matches
point_picking_event.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2010-2011, Willow Garage, Inc.
6 * Copyright (c) 2012-, Open Perception, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * 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 * * Neither the name of the copyright holder(s) nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39#pragma once
40
41#include <pcl/pcl_base.h>
42#include <pcl/pcl_macros.h>
43#include <pcl/types.h> // for pcl::Indices
44#include <pcl/visualization/common/actor_map.h>
45
46#include <vtkCommand.h>
47#include <vtkActor.h>
48
49#include <map>
50#include <vector>
51
52
53class vtkRenderWindowInteractor;
54
55namespace pcl
56{
57 namespace visualization
58 {
59 class PCL_EXPORTS PointPickingCallback : public vtkCommand
60 {
61 public:
63 {
64 return (new PointPickingCallback);
65 }
66
67 /** \brief Empty destructor */
68 ~PointPickingCallback () override = default;
69
70 void
71 Execute (vtkObject *caller, unsigned long eventid, void*) override;
72
74 performSinglePick (vtkRenderWindowInteractor *iren);
75
77 performSinglePick (vtkRenderWindowInteractor *iren, float &x, float &y, float &z);
78
80 performAreaPick (vtkRenderWindowInteractor *iren,
81 CloudActorMapPtr cam_ptr,
82 std::map<std::string, pcl::Indices>& cloud_indices) const;
83
84
85 private:
86 float x_{0}, y_{0}, z_{0};
88 bool pick_first_{false};
89 const vtkActor* actor_{nullptr};
90 };
91
92 /** /brief Class representing 3D point picking events. */
93 class PCL_EXPORTS PointPickingEvent
94 {
95 public:
97 PointPickingEvent (pcl::index_t idx, float x, float y, float z, const std::string& name = "") : idx_ (idx), idx2_ (-1), x_ (x), y_ (y), z_ (z), x2_ (), y2_ (), z2_ (), name_ (name) {}
98 PointPickingEvent (pcl::index_t idx1, pcl::index_t idx2, float x1, float y1, float z1, float x2, float y2, float z2) :
99 idx_ (idx1), idx2_ (idx2), x_ (x1), y_ (y1), z_ (z1), x2_ (x2), y2_ (y2), z2_ (z2)
100 {}
101
102 /** \brief Obtain the ID of a point that the user just clicked on.
103 * \warning If the cloud contains NaNs the index returned by this function will not correspond to the
104 * original indices. To get the correct index either sanitize the input cloud to remove NaNs or use the
105 * PointPickingEvent::getPoint function to get the x,y,z of the picked point and then search the original
106 * cloud for the correct index. An example of how to do this can be found in the pp_callback function in
107 * visualization/tools/pcd_viewer.cpp
108 */
109 inline pcl::index_t
111 {
112 return (idx_);
113 }
114
115 /** \brief Obtain the XYZ point coordinates of a point that the user just clicked on.
116 * \param[out] x the x coordinate of the point that got selected by the user
117 * \param[out] y the y coordinate of the point that got selected by the user
118 * \param[out] z the z coordinate of the point that got selected by the user
119 */
120 inline void
121 getPoint (float &x, float &y, float &z) const
122 {
123 x = x_; y = y_; z = z_;
124 }
125
126 /** \brief For situations when multiple points are selected in a sequence, return the point coordinates.
127 * \param[out] x1 the x coordinate of the first point that got selected by the user
128 * \param[out] y1 the y coordinate of the first point that got selected by the user
129 * \param[out] z1 the z coordinate of the first point that got selected by the user
130 * \param[out] x2 the x coordinate of the second point that got selected by the user
131 * \param[out] y2 the y coordinate of the second point that got selected by the user
132 * \param[out] z2 the z coordinate of the second point that got selected by the user
133 * \return true, if two points are available and have been clicked by the user, false otherwise
134 */
135 inline bool
136 getPoints (float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const
137 {
138 if (idx2_ == pcl::UNAVAILABLE)
139 return (false);
140 x1 = x_; y1 = y_; z1 = z_;
141 x2 = x2_; y2 = y2_; z2 = z2_;
142 return (true);
143 }
144
145 /** \brief For situations where multiple points are selected in a sequence, return the points indices.
146 * \param[out] index_1 index of the first point selected by user
147 * \param[out] index_2 index of the second point selected by user
148 * \return true, if two points are available and have been clicked by the user, false otherwise
149 * \warning If the cloud contains NaNs the index returned by this function will not correspond to the
150 * original indices. To get the correct index either sanitize the input cloud to remove NaNs or use the
151 * PointPickingEvent::getPoint function to get the x,y,z of the picked point and then search the original
152 * cloud for the correct index. An example of how to do this can be found in the pp_callback function in
153 * visualization/tools/pcd_viewer.cpp
154 */
155 inline bool
156 getPointIndices(pcl::index_t& index_1, pcl::index_t& index_2) const
157 {
158 if (idx2_ == pcl::UNAVAILABLE)
159 return (false);
160 index_1 = idx_;
161 index_2 = idx2_;
162 return (true);
163 }
164
165 /** \brief Get name of selected cloud.
166 * \return name of the cloud selected by the user
167 */
168 inline const std::string&
169 getCloudName () const { return name_; }
170
171 private:
172 pcl::index_t idx_, idx2_;
173
174 float x_, y_, z_;
175 float x2_, y2_, z2_;
176 std::string name_;
177 };
178 } //namespace visualization
179} //namespace pcl
pcl::index_t performAreaPick(vtkRenderWindowInteractor *iren, CloudActorMapPtr cam_ptr, std::map< std::string, pcl::Indices > &cloud_indices) const
pcl::index_t performSinglePick(vtkRenderWindowInteractor *iren, float &x, float &y, float &z)
static PointPickingCallback * New()
pcl::index_t performSinglePick(vtkRenderWindowInteractor *iren)
void Execute(vtkObject *caller, unsigned long eventid, void *) override
~PointPickingCallback() override=default
Empty destructor.
/brief Class representing 3D point picking events.
PointPickingEvent(pcl::index_t idx, float x, float y, float z, const std::string &name="")
const std::string & getCloudName() const
Get name of selected cloud.
bool getPoints(float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const
For situations when multiple points are selected in a sequence, return the point coordinates.
void getPoint(float &x, float &y, float &z) const
Obtain the XYZ point coordinates of a point that the user just clicked on.
PointPickingEvent(pcl::index_t idx1, pcl::index_t idx2, float x1, float y1, float z1, float x2, float y2, float z2)
bool getPointIndices(pcl::index_t &index_1, pcl::index_t &index_2) const
For situations where multiple points are selected in a sequence, return the points indices.
pcl::index_t getPointIndex() const
Obtain the ID of a point that the user just clicked on.
shared_ptr< CloudActorMap > CloudActorMapPtr
Definition actor_map.h:97
static constexpr index_t UNAVAILABLE
Definition pcl_base.h:62
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition types.h:112
Defines all the PCL and non-PCL macros used.
Defines basic non-point types used by PCL.