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