Point Cloud Library (PCL)  1.14.1-dev
davidsdk_grabber.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2014-, Open Perception, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Author: Victor Lamoine (victor.lamoine@gmail.com)
37  */
38 
39 #pragma once
40 
41 #include <pcl/pcl_config.h>
42 
43 #include <pcl/common/time.h>
44 #include <pcl/common/io.h>
45 #include <pcl/PolygonMesh.h>
46 #include <pcl/io/grabber.h>
47 
48 #include <david.h>
49 
50 #include <thread>
51 
52 namespace pcl
53 {
54  struct PointXYZ;
55  template <typename T> class PointCloud;
56 
57  /** @brief Grabber for davidSDK structured light compliant devices.\n
58  * The [davidSDK SDK](http://www.david-3d.com/en/products/david-sdk) allows to use a structured light scanner to
59  * fetch clouds/meshes.\n
60  * The purpose of this grabber is NOT to provide all davidSDK functionalities but rather provide a PCL-unified interface to the sensor for
61  * basic operations.\n
62  * Please consult the [David-3d wiki](http://wiki.david-3d.com/david-wiki) for more information.
63  * @author Victor Lamoine (victor.lamoine@gmail.com)\n
64  * @ingroup io
65  */
67  {
68  public:
69  /** @cond */
70  using Ptr = shared_ptr<DavidSDKGrabber>;
71  using ConstPtr = shared_ptr<const DavidSDKGrabber>;
72 
73  // Define callback signature typedefs
74  using sig_cb_davidsdk_point_cloud = void(const pcl::PointCloud<pcl::PointXYZ>::Ptr &);
75 
76  using sig_cb_davidsdk_mesh = void(const pcl::PolygonMesh::Ptr &);
77 
78  using sig_cb_davidsdk_image = void(const pcl::PCLImage::Ptr &);
79 
80  using sig_cb_davidsdk_point_cloud_image = void(const pcl::PointCloud<pcl::PointXYZ>::Ptr &, const pcl::PCLImage::Ptr &);
81 
82  using sig_cb_davidsdk_mesh_image = void(const pcl::PolygonMesh::Ptr &, const pcl::PCLImage::Ptr &);
83 
84  /** @endcond */
85 
86  /** @brief Constructor */
88 
89  /** @brief Destructor inherited from the Grabber interface. It never throws. */
90  virtual
91  ~DavidSDKGrabber () noexcept;
92 
93  /** @brief [Connect](http://docs.david-3d.com/sdk/en/classdavid_1_1_client_json_rpc.html#a4b948e57a2e5e7f9cdcf1171c500aa24) client
94  * @param[in] address
95  * @param[in] port
96  * @return Server info*/
97  david::ServerInfo
98  connect (const std::string & address = "127.0.0.1",
99  std::uint16_t port = david::DAVID_SDK_DefaultPort);
100 
101  /** @brief [Disconnect](http://docs.david-3d.com/sdk/en/classdavid_1_1_client_json_rpc.html#a2770728a6de2c708df767bedf8be0814) client
102  * @param[in] stop_server */
103  void
104  disconnect (const bool stop_server);
105 
106  /** @brief Start the point cloud and or image acquisition */
107  void
108  start ();
109 
110  /** @brief Stop the data acquisition */
111  void
112  stop ();
113 
114  /** @brief Check if the data acquisition is still running
115  * @return True if running, false otherwise */
116  bool
117  isRunning () const;
118 
119  /** @brief Check if the client is connected
120  * @return True if connected, false otherwise */
121  bool
122  isConnected () const;
123 
124  /** @brief Get class name
125  * @returns A string containing the class name */
126  std::string
127  getName () const;
128 
129  /** @brief Get @ref local_path_ path directory
130  * @returns the path */
131  std::string
132  getLocalPath ();
133 
134  /** @brief Get @ref remote_path_ path directory
135  * @returns the path */
136  std::string
137  getRemotePath ();
138 
139  /** @brief Set @ref file_format_ to "obj" */
140  void
141  setFileFormatToOBJ ();
142 
143  /** @brief Set @ref file_format_ to "ply"
144  * @warning This format is NOT available with trial versions of the davidSDK server! */
145  void
146  setFileFormatToPLY ();
147 
148  /** @brief Set @ref file_format_ to "stl" */
149  void
150  setFileFormatToSTL ();
151 
152  /** @brief Get @ref file_format_
153  * @returns the file format */
154  std::string
155  getFileFormat ();
156 
157  /** @brief Set @ref local_path_ path directory for scanning files
158  * @param[in] path The directory path
159  *
160  * If the path is empty, using default value ("C:/temp") */
161  void
162  setLocalPath (std::string path);
163 
164  /** @brief Set @ref remote_path_ path directory for scanning files
165  * @param[in] path The directory path
166  *
167  * If the string is empty, @ref remote_path_ = @ref local_path_ */
168  void
169  setRemotePath (std::string path);
170 
171  /** @brief Set @ref local_path_ and @ref remote_path_ directory paths
172  * @param[in] local_path
173  * @param[in] remote_path
174  *
175  * If the path is empty, using default value ("C:/temp") */
176  void
177  setLocalAndRemotePaths (std::string local_path,
178  std::string remote_path);
179 
180  /** @brief Calibrate the scanner
181  * @param[in] grid_size Size of the calibration grid in millimeters
182  * @return True if successful, false otherwise
183  *
184  * More information [here](http://wiki.david-3d.com/david3_user_manual/structured_light).\n
185  * Also see [ImportCalibration](http://docs.david-3d.com/sdk/en/classdavid_1_1_i_structured_light_scanner.html#a68e888636883d90aac7891d2ef9e6b27).\n
186  * and [ExportCalibration](http://docs.david-3d.com/sdk/en/classdavid_1_1_i_structured_light_scanner.html#a66817b07227f9a8852663d9141ae48db).
187  *
188  * @warning You MUST perform calibration each time you modify the camera/projector focus or move the camera relatively to the projector.\n
189  */
190  bool
191  calibrate (double grid_size);
192 
193  /** @brief Capture a single point cloud and store it
194  * @param[out] cloud The cloud to be filled
195  * @return True if successful, false otherwise
196  * @warning Calls [DeleteAllMeshes()](http://docs.david-3d.com/sdk/en/classdavid_1_1_i_shape_fusion.html#aed22e458b51f1361803360c02c2d1403) */
197  bool
198  grabSingleCloud (pcl::PointCloud<pcl::PointXYZ> &cloud);
199 
200  /** @brief Capture a single mesh and store it
201  * @param[out] mesh The mesh to be filled
202  * @return True if successful, false otherwise
203  * @warning Calls [DeleteAllMeshes()](http://docs.david-3d.com/sdk/en/classdavid_1_1_i_shape_fusion.html#aed22e458b51f1361803360c02c2d1403) */
204  bool
205  grabSingleMesh (pcl::PolygonMesh &mesh);
206 
207  /** @brief Obtain the number of frames per second (FPS) */
208  float
209  getFramesPerSecond () const;
210 
211  /** @brief davidSDK client */
212  david::Client david_;
213 
214  protected:
215  /** @brief Grabber thread */
216  std::thread grabber_thread_;
217 
218  /** @brief Boost point cloud signal */
219  boost::signals2::signal<sig_cb_davidsdk_point_cloud>* point_cloud_signal_;
220 
221  /** @brief Boost mesh signal */
222  boost::signals2::signal<sig_cb_davidsdk_mesh>* mesh_signal_;
223 
224  /** @brief Boost image signal */
225  boost::signals2::signal<sig_cb_davidsdk_image>* image_signal_;
226 
227  /** @brief Boost image + point cloud signal */
228  boost::signals2::signal<sig_cb_davidsdk_point_cloud_image>* point_cloud_image_signal_;
229 
230  /** @brief Boost mesh + image signal */
231  boost::signals2::signal<sig_cb_davidsdk_mesh_image>* mesh_image_signal_;
232 
233  /** @brief Whether the client is connected */
234  bool client_connected_;
235 
236  /** @brief Whether an davidSDK device is running or not */
237  bool running_;
238 
239  /** @brief Local path of directory where the scanning file will be located.
240  * @note Default value is @c C:/temp */
241  std::string local_path_;
242 
243  /** @brief Remote path of directory where the scanning file will be located.
244  * @note If this is empty, the @ref local_path_ will be used instead
245  * Default value is @c C:/temp */
246  std::string remote_path_;
247 
248  /** @brief Export file extension, available formats are STL, OBJ, PLY */
249  std::string file_format_;
250 
251  /** @brief processGrabbing capture/processing frequency */
252  pcl::EventFrequency frequency_;
253 
254  /** @brief Mutual exclusion for FPS computation */
255  mutable std::mutex fps_mutex_;
256 
257  /** @brief Continuously asks for images and or point clouds/meshes data from the device and publishes them if available. */
258  void
259  processGrabbing ();
260  };
261 } // namespace pcl
Grabber for davidSDK structured light compliant devices.
virtual ~DavidSDKGrabber() noexcept
Destructor inherited from the Grabber interface.
DavidSDKGrabber()
Constructor.
A helper class to measure frequency of a certain event.
Definition: time.h:133
Grabber interface for PCL 1.x device drivers.
Definition: grabber.h:60
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
Define methods for measuring time spent in code blocks.
#define PCL_EXPORTS
Definition: pcl_macros.h:323
shared_ptr< ::pcl::PCLImage > Ptr
Definition: PCLImage.h:25
A point structure representing Euclidean xyz coordinates.
shared_ptr< ::pcl::PolygonMesh > Ptr
Definition: PolygonMesh.h:96