2#include "ClassUsingDisplayPCL.h"
4#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_VISUALIZATION) && defined(VISP_HAVE_PCL_IO)
6#include <pcl/io/pcd_io.h>
9#include <visp3/core/vpTime.h>
10#include <visp3/core/vpGaussRand.h>
11#include <visp3/core/vpRobust.h>
12#include <visp3/gui/vpColorBlindFriendlyPalette.h>
13#include <visp3/io/vpKeyboard.h>
15#ifdef ENABLE_VISP_NAMESPACE
20double zFunction(
const double &x,
const double &y,
const unsigned int order)
22 const double offset(0.5);
25 for (
unsigned int n = 0; n <= order; n++) {
26 for (
unsigned int k = 0; k <= order - n; k++) {
28 z += std::pow(x, n) * std::pow(y, k);
43 , m_R(M_PI_4, M_PI_4, M_PI_4)
45 , m_minX(xlimits.first)
46 , m_maxX(xlimits.second)
48 , m_minY(ylimits.first)
49 , m_maxY(ylimits.second)
50 , m_m(nbPoints.second)
51 , m_visualizer(0, 0,
"Grid of points")
53 m_dX = (m_maxX - m_minX) / (
static_cast<double>(m_n) - 1.);
54 m_dY = (m_maxY - m_minY) / (
static_cast<double>(m_m) - 1.);
64void ClassUsingDisplayPCL::generateControlPoints(
const double &addedNoise,
const unsigned int &order, pcl::PointCloud<PointType>::Ptr &base, pcl::PointCloud<PointType>::Ptr &rotated)
67 bool initialize_base = (base ? false :
true);
68 if (initialize_base) {
69 base = std::make_shared<pcl::PointCloud<PointType>>(m_n, m_m);
71 bool initialize_rotated = (rotated ? false :
true);
72 if (initialize_rotated) {
73 rotated = std::make_shared<pcl::PointCloud<PointType>>(m_n, m_m);
78 r.setSigmaMean(addedNoise, 0.);
81 for (
unsigned int j = 0;
j < m_m;
j++) {
82 for (
unsigned int i = 0;
i < m_n;
i++) {
84 double oX = m_minX +
static_cast<double>(
i) * m_dX;
85 double oY = m_minY +
static_cast<double>(
j) * m_dY;
86 double oZ = zFunction(oX, oY, order);
90 std::vector<double> point = { oX, oY, oZ,1. };
91 vpColVector oCoords = vpColVector(point);
92 if (initialize_base) {
93 (*base)(
i,
j).x = oCoords[0];
94 (*base)(
i,
j).y = oCoords[1];
95 (*base)(
i,
j).z = oCoords[2];
99 vpColVector cCoords = m_cMo * oCoords;
100 (*rotated)(
i,
j).x = cCoords[0];
101 (*rotated)(
i,
j).y = cCoords[1];
105 (*rotated)(
i,
j).z = cCoords[2] + noise;
114 pcl::PointCloud<PointType>::Ptr base, rotated;
115 generateControlPoints(addedNoise, order, base, rotated);
119 std::mutex mutex_base;
121 m_visualizer.addPointCloud(mutex_base, base,
"Base", color_base.
to_vpColor());
124 std::mutex mutex_rotated;
126 m_visualizer.addPointCloud(mutex_rotated, rotated,
"RotatedWithNoise", color.to_vpColor());
129 if (!useMonothread) {
131 m_visualizer.startThread(
false);
135 bool wantToStop =
false;
138 std::cout <<
"Press any key in the console to stop the program." << std::endl;
140 while (!wantToStop) {
145 std::lock_guard lg_base(mutex_base);
146 std::lock_guard lg_rotated(mutex_rotated);
147 generateControlPoints(addedNoise, order, base, rotated);
153 const bool blocking_mode =
false;
154 m_visualizer.display(blocking_mode);
158 if (keyboard.
kbhit()) {
167void dummy_class_using_pcl_visualizer()
void runDemo(const double &addedNoise, const unsigned int &order, const bool &useMonothread)
Demonstration on how to use a vpDisplayPCL in threaded mode.
ClassUsingDisplayPCL(std::pair< double, double > xlimits={ -2.5, 2.5 }, std::pair< double, double > ylimits={ -2.5, 2.5 }, std::pair< unsigned int, unsigned int > nbPoints={ 50, 50 })
Construct a new object.
~ClassUsingDisplayPCL()
[Constructor]
Class that furnishes a set of colors that color blind people should be able to distinguish one from a...
vpColor to_vpColor() const
Cast a vpColorBlindFriendlyPalette in a vpColor object. A vpColorBlindFriendlyPalette::Palette::COUNT...
Keyboard management under unix (Linux or OSX). This class is not available under windows.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMicros()