50 volatile bool quit{
false};
51 volatile int pushed_key{0};
52 volatile double Hz{0};
71 cout <<
"Loading calibration from: " << cfgFile << endl;
75 cerr <<
"Warning: Calibration file [" << cfgFile
76 <<
"] not found -> Using default params.\n";
79 cout <<
"Calling CKinect::initialize()...";
85 bool there_is_obs =
true, hard_error =
false;
87 while (!hard_error && !
p.quit)
90 auto obs = CObservation3DRangeScan::Create();
96 if (!hard_error && there_is_obs)
98 std::atomic_store(&
p.new_obs, obs);
99 std::atomic_store(&
p.new_obs_imu, obs_imu);
102 if (
p.pushed_key != 0)
104 switch (
p.pushed_key)
118 p.Hz = nImgs / tictac.
Tac();
124 catch (
const std::exception& e)
126 cout <<
"Exception in Kinect thread: " << e.what() << endl;
143 cout <<
"Waiting for sensor initialization...\n";
147 std::atomic_load(&thrPar.
new_obs);
151 std::this_thread::sleep_for(10ms);
152 }
while (!thrPar.
quit);
155 if (thrPar.
quit)
return;
161 win3D.setCameraAzimuthDeg(140);
162 win3D.setCameraElevationDeg(30);
163 win3D.setCameraZoom(10.0);
165 win3D.setCameraPointingToPoint(2.5, 0, 0);
170 gl_points->setPointSize(2.5);
175 gl_2d_scan->enablePoints(
true);
176 gl_2d_scan->enableLine(
true);
177 gl_2d_scan->enableSurface(
true);
178 gl_2d_scan->setSurfaceColor(0, 0, 1, 0.3);
181 0.2f, 5.0f, 90.0f, 5.0f, 2.0f,
true,
true);
183 const double aspect_ratio =
192 scene->insert(gl_points);
193 scene->insert(gl_2d_scan);
194 scene->insert(gl_frustum);
199 gl_grid->setColor(0.6, 0.6, 0.6);
200 scene->insert(gl_grid);
205 gl_corner->setScale(0.2);
206 scene->insert(gl_corner);
211 const int VW_HEIGHT = aspect_ratio * VW_WIDTH;
212 const int VW_GAP = 30;
216 win3D.addTextMessage(
217 30, -25 - 1 * (VW_GAP + VW_HEIGHT),
"Range data",
TColorf(1, 1, 1),
219 viewRange = scene->createViewport(
"view2d_range");
220 viewRange->setViewportPosition(
221 5, -10 - 1 * (VW_GAP + VW_HEIGHT), VW_WIDTH, VW_HEIGHT);
223 win3D.addTextMessage(
224 30, -25 - 2 * (VW_GAP + VW_HEIGHT),
"Intensity data",
226 viewInt = scene->createViewport(
"view2d_int");
227 viewInt->setViewportPosition(
228 5, -10 - 2 * (VW_GAP + VW_HEIGHT), VW_WIDTH, VW_HEIGHT);
230 win3D.unlockAccess3DScene();
237 while (win3D.isOpen() && !thrPar.
quit)
240 std::atomic_load(&thrPar.
new_obs);
242 (!last_obs || possiblyNewObs->timestamp != last_obs->timestamp))
245 last_obs = possiblyNewObs;
246 last_obs_imu = std::atomic_load(&thrPar.
new_obs_imu);
249 bool do_refresh =
false;
252 if (last_obs->hasRangeImage)
259 range2D = last_obs->rangeImage;
260 range2D *= (1.0 / last_obs->maxRange);
262 img.setFromMatrix(range2D);
264 win3D.get3DSceneAndLock();
265 viewRange->setImageView(std::move(
img));
266 win3D.unlockAccess3DScene();
271 if (last_obs->hasRangeImage)
275 CObservation2DRangeScan::Create();
281 sp.sensorLabel =
"KINECT_2D_SCAN";
283 last_obs->convertTo2DScan(*obs_2d, sp);
286 gl_2d_scan->setScan(*obs_2d);
290 if (last_obs->hasIntensityImage)
292 win3D.get3DSceneAndLock();
293 viewInt->setImageView(
294 last_obs->intensityImage);
297 win3D.unlockAccess3DScene();
302 if (last_obs->hasPoints3D)
304 win3D.get3DSceneAndLock();
308 last_obs->project3DPointsFromDepthImageInto(*gl_points, pp);
309 win3D.unlockAccess3DScene();
314 win3D.get3DSceneAndLock();
316 win3D.addTextMessage(
320 win3D.addTextMessage(
322 "'o'/'i'-zoom out/in, '2'/'3'/'f':show/hide 2D/3D/frustum " 323 "data, mouse: orbit 3D, ESC: quit",
326 win3D.addTextMessage(
329 "Show: 3D=%s 2D=%s Frustum=%s (vert. FOV=%.1fdeg)",
330 gl_points->isVisible() ?
"YES" :
"NO",
331 gl_2d_scan->isVisible() ?
"YES" :
"NO",
332 gl_frustum->isVisible() ?
"YES" :
"NO",
333 gl_frustum->getVertFOV()),
335 win3D.unlockAccess3DScene();
338 if (last_obs_imu && last_obs_imu->dataIsPresent[
IMU_X_ACC])
340 win3D.get3DSceneAndLock();
341 win3D.addTextMessage(
344 "Acc: x=%.02f y=%.02f z=%.02f",
345 last_obs_imu->rawMeasurements[
IMU_X_ACC],
346 last_obs_imu->rawMeasurements[
IMU_Y_ACC],
347 last_obs_imu->rawMeasurements[
IMU_Z_ACC]),
349 win3D.unlockAccess3DScene();
354 if (do_refresh) win3D.repaint();
362 const int key = tolower(win3D.getPushedKey());
368 win3D.setCameraZoom(win3D.getCameraZoom() * 1.2);
372 win3D.setCameraZoom(win3D.getCameraZoom() / 1.2);
376 gl_2d_scan->setVisibility(!gl_2d_scan->isVisible());
379 gl_points->setVisibility(!gl_points->isVisible());
383 gl_frustum->setVisibility(!gl_frustum->isVisible());
386 gl_frustum->setVertFOV(gl_frustum->getVertFOV() + 1);
389 gl_frustum->setVertFOV(gl_frustum->getVertFOV() - 1);
398 std::this_thread::sleep_for(1ms);
401 cout <<
"Waiting for grabbing thread to exit...\n";
407 int main(
int argc,
char** argv)
413 std::this_thread::sleep_for(50ms);
416 catch (
const std::exception& e)
423 printf(
"Another exception!!");
double Tac() noexcept
Stops the stopwatch.
static Ptr Create(Args &&... args)
static Ptr Create(Args &&... args)
double DEG2RAD(const double x)
Degrees to radians.
This class allows loading and storing values and vectors of different types from ".ini" files easily.
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
A high-performance stopwatch, with typical resolution of nanoseconds.
CObservationIMU::Ptr new_obs_imu
Contains classes for various device interfaces.
y-axis acceleration (local/vehicle frame) (m/sec2)
z-axis acceleration (local/vehicle frame) (m/sec2)
volatile bool quit
In/Out variable: Forces the thread to exit or indicates an error in the thread that caused it to end...
A class for grabing "range images", intensity images (either RGB or IR) and other information from an...
This base provides a set of functions for maths stuff.
Used in CObservation3DRangeScan::convertTo2DScan()
This namespace contains representation of robot actions and observations.
void initialize() override
Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different par...
static Ptr Create(Args &&... args)
void loadConfig(const mrpt::config::CConfigFileBase &configSource, const std::string §ion)
Loads the generic settings common to any sensor (See CGenericSensor), then call to "loadConfig_sensor...
GLsizei const GLchar ** string
void getNextObservation(mrpt::obs::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error)
The main data retrieving function, to be called after calling loadConfig() and initialize().
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void thread_grabbing(TThreadParam &p)
Used in CObservation3DRangeScan::project3DPointsFromDepthImageInto()
A RGB color - floats in the range [0,1].
The namespace for 3D scene representation and rendering.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Classes for creating GUI windows for 2D and 3D visualization.
CObservation3DRangeScan::Ptr new_obs
RGB+D (+ optionally, 3D point cloud)
void Tic() noexcept
Starts the stopwatch.
renders glyphs as filled polygons
This template class provides the basic functionality for a general 2D any-size, resizable container o...
x-axis acceleration (local/vehicle frame) (m/sec2)
static Ptr Create(Args &&... args)
volatile double Hz
Out variable: Approx.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
bool takeIntoAccountSensorPoseOnRobot
(Default: false) If false, local (sensor-centric) coordinates of points are generated.
A class for storing images as grayscale or RGB bitmaps.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.