Point Cloud Library (PCL)  1.11.1-dev
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_macros.h>
42 #include <pcl/types.h> // for pcl::Indices
43 
44 #include <vtkCommand.h>
45 class vtkRenderWindowInteractor;
46 
47 namespace pcl
48 {
49  namespace visualization
50  {
51  class PCL_EXPORTS PointPickingCallback : public vtkCommand
52  {
53  public:
55  {
56  return (new PointPickingCallback);
57  }
58 
59  PointPickingCallback () : x_ (0), y_ (0), z_ (0), idx_ (-1), pick_first_ (false) {}
60 
61  /** \brief Empty destructor */
63 
64  void
65  Execute (vtkObject *caller, unsigned long eventid, void*) override;
66 
67  int
68  performSinglePick (vtkRenderWindowInteractor *iren);
69 
70  int
71  performSinglePick (vtkRenderWindowInteractor *iren, float &x, float &y, float &z);
72 
73  int
74  performAreaPick (vtkRenderWindowInteractor *iren, pcl::Indices &indices) const;
75 
76  private:
77  float x_, y_, z_;
78  int idx_;
79  bool pick_first_;
80  };
81 
82  /** /brief Class representing 3D point picking events. */
84  {
85  public:
86  PointPickingEvent (int idx) : idx_ (idx), idx2_ (-1), x_ (), y_ (), z_ (), x2_ (), y2_ (), z2_ () {}
87  PointPickingEvent (int idx, float x, float y, float z) : idx_ (idx), idx2_ (-1), x_ (x), y_ (y), z_ (z), x2_ (), y2_ (), z2_ () {}
88 
89  PointPickingEvent (int idx1, int idx2, float x1, float y1, float z1, float x2, float y2, float z2) :
90  idx_ (idx1), idx2_ (idx2), x_ (x1), y_ (y1), z_ (z1), x2_ (x2), y2_ (y2), z2_ (z2)
91  {}
92 
93  /** \brief Obtain the ID of a point that the user just clicked on.
94  * \warning If the cloud contains NaNs the index returned by this function will not correspond to the
95  * original indices. To get the correct index either sanitize the input cloud to remove NaNs or use the
96  * PointPickingEvent::getPoint function to get the x,y,z of the picked point and then search the original
97  * cloud for the correct index. An example of how to do this can be found in the pp_callback function in
98  * visualization/tools/pcd_viewer.cpp
99  */
100  inline int
101  getPointIndex () const
102  {
103  return (idx_);
104  }
105 
106  /** \brief Obtain the XYZ point coordinates of a point that the user just clicked on.
107  * \param[out] x the x coordinate of the point that got selected by the user
108  * \param[out] y the y coordinate of the point that got selected by the user
109  * \param[out] z the z coordinate of the point that got selected by the user
110  */
111  inline void
112  getPoint (float &x, float &y, float &z) const
113  {
114  x = x_; y = y_; z = z_;
115  }
116 
117  /** \brief For situations when multiple points are selected in a sequence, return the point coordinates.
118  * \param[out] x1 the x coordinate of the first point that got selected by the user
119  * \param[out] y1 the y coordinate of the first point that got selected by the user
120  * \param[out] z1 the z coordinate of the first point that got selected by the user
121  * \param[out] x2 the x coordinate of the second point that got selected by the user
122  * \param[out] y2 the y coordinate of the second point that got selected by the user
123  * \param[out] z2 the z coordinate of the second point that got selected by the user
124  * \return true, if two points are available and have been clicked by the user, false otherwise
125  */
126  inline bool
127  getPoints (float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const
128  {
129  if (idx2_ == -1)
130  return (false);
131  x1 = x_; y1 = y_; z1 = z_;
132  x2 = x2_; y2 = y2_; z2 = z2_;
133  return (true);
134  }
135 
136  /** \brief For situations where multiple points are selected in a sequence, return the points indices.
137  * \param[out] index_1 index of the first point selected by user
138  * \param[out] index_2 index of the second point selected by user
139  * \return true, if two points are available and have been clicked by the user, false otherwise
140  * \warning If the cloud contains NaNs the index returned by this function will not correspond to the
141  * original indices. To get the correct index either sanitize the input cloud to remove NaNs or use the
142  * PointPickingEvent::getPoint function to get the x,y,z of the picked point and then search the original
143  * cloud for the correct index. An example of how to do this can be found in the pp_callback function in
144  * visualization/tools/pcd_viewer.cpp
145  */
146  inline bool
147  getPointIndices (int &index_1, int &index_2) const
148  {
149  if (idx2_ == -1)
150  return (false);
151  index_1 = idx_;
152  index_2 = idx2_;
153  return (true);
154  }
155 
156  private:
157  int idx_, idx2_;
158 
159  float x_, y_, z_;
160  float x2_, y2_, z2_;
161  };
162  } //namespace visualization
163 } //namespace pcl
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
Definition: convolution.h:46
pcl::visualization::PointPickingEvent::getPoints
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.
Definition: point_picking_event.h:127
types.h
Defines basic non-point types used by PCL.
pcl::visualization::PointPickingEvent::PointPickingEvent
PointPickingEvent(int idx1, int idx2, float x1, float y1, float z1, float x2, float y2, float z2)
Definition: point_picking_event.h:89
pcl::visualization::PointPickingEvent::getPointIndex
int getPointIndex() const
Obtain the ID of a point that the user just clicked on.
Definition: point_picking_event.h:101
pcl::visualization::PointPickingEvent::getPointIndices
bool getPointIndices(int &index_1, int &index_2) const
For situations where multiple points are selected in a sequence, return the points indices.
Definition: point_picking_event.h:147
pcl::visualization::PointPickingCallback
Definition: point_picking_event.h:51
pcl::visualization::PointPickingEvent::PointPickingEvent
PointPickingEvent(int idx)
Definition: point_picking_event.h:86
pcl::visualization::PointPickingCallback::~PointPickingCallback
~PointPickingCallback()
Empty destructor.
Definition: point_picking_event.h:62
pcl::visualization::PointPickingCallback::PointPickingCallback
PointPickingCallback()
Definition: point_picking_event.h:59
pcl::visualization::PointPickingEvent
/brief Class representing 3D point picking events.
Definition: point_picking_event.h:83
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:131
pcl::visualization::PointPickingCallback::New
static PointPickingCallback * New()
Definition: point_picking_event.h:54
pcl::visualization::PointPickingEvent::getPoint
void getPoint(float &x, float &y, float &z) const
Obtain the XYZ point coordinates of a point that the user just clicked on.
Definition: point_picking_event.h:112
pcl::visualization::PointPickingEvent::PointPickingEvent
PointPickingEvent(int idx, float x, float y, float z)
Definition: point_picking_event.h:87
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:323