Visual Servoing Platform version 3.5.0
vpOccipitalStructure.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2021 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See http://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * libStructure interface.
33 *
34 * Authors:
35 * Joudy Nader
36 *
37 *****************************************************************************/
38
39#ifndef _vpOccipitalStructure_h_
40#define _vpOccipitalStructure_h_
41
42#include <visp3/core/vpConfig.h>
43
44#if defined(VISP_HAVE_OCCIPITAL_STRUCTURE) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
45#include <mutex>
46#include <condition_variable>
47
48#include <ST/CaptureSession.h>
49
50#ifdef VISP_HAVE_PCL
51#include <pcl/common/common_headers.h>
52#endif
53
54#include <visp3/core/vpCameraParameters.h>
55#include <visp3/core/vpImage.h>
56
200struct SessionDelegate : ST::CaptureSessionDelegate {
201 std::mutex m_sampleLock;
202 std::condition_variable cv_sampleLock;
203
204 ST::ColorFrame m_visibleFrame;
205 ST::DepthFrame m_depthFrame;
206 ST::InfraredFrame m_infraredFrame;
207 ST::AccelerometerEvent m_accelerometerEvent;
208 ST::GyroscopeEvent m_gyroscopeEvent;
209 ST::StructureCoreCameraType m_cameraType;
210 ST::CaptureSessionUSBVersion m_USBVersion;
211 std::string m_serialNumber;
212
214
215 void captureSessionEventDidOccur(ST::CaptureSession *session, ST::CaptureSessionEventId event) override {
216 switch (event) {
217 case ST::CaptureSessionEventId::Booting: break;
218 case ST::CaptureSessionEventId::Connected:
219 printf("Starting streams...\n");
220 session->startStreaming();
221 // The following wait function will let the capture session load correctly.
222 vpTime::wait(1000);
223
224 // Getting details about capture session.
225 // (USB Version, Serial Number of the camera connected, Camera Monochorme/Color)
226 m_USBVersion = session->USBVersion();
227 m_serialNumber = session->sensorInfo().serialNumber;
228 m_cameraType = session->getCameraType();
229 break;
230 case ST::CaptureSessionEventId::Disconnected:
231 break;
232 case ST::CaptureSessionEventId::Error:
233 throw vpException(vpException::fatalError, "Capture session error");
234 break;
235 default:
236 printf("Capture session event unhandled\n");
237 }
238 }
239
240 void captureSessionDidOutputSample(ST::CaptureSession *, const ST::CaptureSessionSample& sample) override {
241 // acquire sampleLock mutex.
242 std::lock_guard<std::mutex> u(m_sampleLock);
243
244 // Perform the modification needed on the shared variables.
245 if(sample.visibleFrame.isValid())
246 m_visibleFrame = sample.visibleFrame;
247
248 if(sample.depthFrame.isValid())
249 m_depthFrame = sample.depthFrame;
250
251 if(sample.infraredFrame.isValid())
252 m_infraredFrame = sample.infraredFrame;
253
254 if(sample.type == ST::CaptureSessionSample::Type::AccelerometerEvent)
255 m_accelerometerEvent = sample.accelerometerEvent;
256
257 if(sample.type == ST::CaptureSessionSample::Type::GyroscopeEvent)
258 m_gyroscopeEvent = sample.gyroscopeEvent;
259
260 // If any thread is waiting on `cv_sampleLock`, the following instruction will unblock it.
261 // In our case, `open()` and `acquire()` will be blocked on `cv_sampleLock`.
262 cv_sampleLock.notify_one();
263 }
264};
265
266class VISP_EXPORT vpOccipitalStructure
267{
268 public:
269 typedef enum
270 {
274 imu
275 } vpOccipitalStructureStream;
276
279
280 void acquire(vpImage<unsigned char> &gray, bool undistorted=false, double *ts=NULL);
281 void acquire(vpImage<vpRGBa> &rgb, bool undistorted=false, double *ts=NULL);
282
283 void acquire(vpImage<vpRGBa> *rgb, vpImage<vpRGBa> *depth, vpColVector *acceleration_data=NULL, vpColVector *gyroscope_data=NULL,
284 bool undistorted=false, double *ts=NULL);
285 void acquire(vpImage<unsigned char> *gray, vpImage<vpRGBa> *depth, vpColVector *acceleration_data=NULL, vpColVector *gyroscope_data=NULL,
286 bool undistorted=false, double *ts=NULL);
287
288 void acquire(unsigned char *const data_image, unsigned char *const data_depth,
289 std::vector<vpColVector> *const data_pointCloud=NULL, unsigned char *const data_infrared=NULL,
290 vpColVector *acceleration_data=NULL, vpColVector *gyroscope_data=NULL,
291 bool undistorted=true, double *ts=NULL);
292
293 #ifdef VISP_HAVE_PCL
294 void acquire(unsigned char *const data_image, unsigned char *const data_depth,
295 std::vector<vpColVector> *const data_pointCloud, pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud,
296 unsigned char *const data_infrared=NULL, vpColVector *acceleration_data=NULL, vpColVector *gyroscope_data=NULL,
297 bool undistorted=true,double *ts=NULL);
298 void acquire(unsigned char *const data_image, unsigned char *const data_depth,
299 std::vector<vpColVector> *const data_pointCloud, pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud,
300 unsigned char *const data_infrared=NULL, vpColVector *acceleration_data=NULL, vpColVector *gyroscope_data=NULL,
301 bool undistorted=true,double *ts=NULL);
302 #endif
303
304 void getIMUVelocity(vpColVector *imu_vel, double *ts);
305 void getIMUAcceleration(vpColVector *imu_acc, double *ts);
306 void getIMUData(vpColVector *imu_vel, vpColVector *imu_acc, double *ts=NULL);
307
308 bool open(const ST::CaptureSessionSettings &settings);
309 void close();
310
314 ST::StructureCoreCameraType getCameraType() const { return m_delegate.m_cameraType; }
315
316 ST::CaptureSessionUSBVersion getUSBVersion() const { return m_delegate.m_USBVersion; }
317 std::string getSerialNumber() const { return m_delegate.m_serialNumber; }
318 ST::CaptureSession &getCaptureSession() { return m_captureSession; }
319 ST::CaptureSessionSettings &getCaptureSessionSettings() { return m_captureSessionSettings; }
320
321 unsigned int getWidth(vpOccipitalStructureStream stream_type);
322 unsigned int getHeight(vpOccipitalStructureStream stream_type);
323
324 // Returns depth in millimeters at (x,y) if it exists, NAN otherwise.
325 float getDepth(int x, int y);
326
327 vpPoint unprojectPoint(int row, int col);
328
329 vpHomogeneousMatrix getTransform(const vpOccipitalStructureStream from, const vpOccipitalStructureStream to);
330
331 ST::Intrinsics getIntrinsics(const vpOccipitalStructureStream stream_type) const;
332
333 vpCameraParameters getCameraParameters(const vpOccipitalStructureStream stream_type,
335
336 void saveDepthImageAsPointCloudMesh(std::string &filename);
337
338 protected:
339 bool m_init;
341 float m_maxZ;
342
343 ST::CaptureSession m_captureSession;
344 ST::CaptureSessionSettings m_captureSessionSettings;
346 vpCameraParameters m_visible_camera_parameters, m_depth_camera_parameters;
347
348 void getPointcloud(std::vector<vpColVector> &pointcloud);
349 #ifdef VISP_HAVE_PCL
350 void getPointcloud(pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud);
351 void getColoredPointcloud(pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud);
352 #endif
353};
354
355#endif
356#endif
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ fatalError
Fatal error.
Definition: vpException.h:96
Implementation of an homogeneous matrix and operations on such kind of matrices.
ST::CaptureSessionUSBVersion getUSBVersion() const
ST::StructureCoreCameraType getCameraType() const
vpCameraParameters m_depth_camera_parameters
ST::CaptureSession & getCaptureSession()
ST::CaptureSession m_captureSession
std::string getSerialNumber() const
ST::CaptureSessionSettings m_captureSessionSettings
@ infrared
Infrared stream.
ST::CaptureSessionSettings & getCaptureSessionSettings()
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:82
VISP_EXPORT int wait(double t0, double t)
ST::CaptureSessionUSBVersion m_USBVersion
ST::AccelerometerEvent m_accelerometerEvent
std::string m_serialNumber
ST::StructureCoreCameraType m_cameraType
ST::DepthFrame m_depthFrame
void captureSessionDidOutputSample(ST::CaptureSession *, const ST::CaptureSessionSample &sample) override
std::condition_variable cv_sampleLock
ST::ColorFrame m_visibleFrame
void captureSessionEventDidOccur(ST::CaptureSession *session, ST::CaptureSessionEventId event) override
ST::GyroscopeEvent m_gyroscopeEvent
ST::InfraredFrame m_infraredFrame