51 volatile int pushed_key;
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)
93 mrpt::make_aligned_shared<CObservationIMU>();
97 if (!hard_error && there_is_obs)
99 std::atomic_store(&
p.new_obs, obs);
100 std::atomic_store(&
p.new_obs_imu, obs_imu);
103 if (
p.pushed_key != 0)
105 switch (
p.pushed_key)
119 p.Hz = nImgs / tictac.
Tac();
125 catch (std::exception& e)
127 cout <<
"Exception in Kinect thread: " << e.what() << endl;
144 cout <<
"Waiting for sensor initialization...\n";
148 std::atomic_load(&thrPar.
new_obs);
152 std::this_thread::sleep_for(10ms);
153 }
while (!thrPar.
quit);
156 if (thrPar.
quit)
return;
162 win3D.setCameraAzimuthDeg(140);
163 win3D.setCameraElevationDeg(30);
164 win3D.setCameraZoom(10.0);
166 win3D.setCameraPointingToPoint(2.5, 0, 0);
170 mrpt::make_aligned_shared<mrpt::opengl::CPointCloudColoured>();
171 gl_points->setPointSize(2.5);
175 mrpt::make_aligned_shared<mrpt::opengl::CPlanarLaserScan>();
176 gl_2d_scan->enablePoints(
true);
177 gl_2d_scan->enableLine(
true);
178 gl_2d_scan->enableSurface(
true);
179 gl_2d_scan->setSurfaceColor(0, 0, 1, 0.3);
182 mrpt::make_aligned_shared<mrpt::opengl::CFrustum>(
183 0.2f, 5.0f, 90.0f, 5.0f, 2.0f,
true,
true);
185 const double aspect_ratio =
194 scene->insert(gl_points);
195 scene->insert(gl_2d_scan);
196 scene->insert(gl_frustum);
200 mrpt::make_aligned_shared<mrpt::opengl::CGridPlaneXY>();
201 gl_grid->setColor(0.6, 0.6, 0.6);
202 scene->insert(gl_grid);
207 gl_corner->setScale(0.2);
208 scene->insert(gl_corner);
213 const int VW_HEIGHT = aspect_ratio * VW_WIDTH;
214 const int VW_GAP = 30;
218 win3D.addTextMessage(
219 30, -25 - 1 * (VW_GAP + VW_HEIGHT),
"Range data",
TColorf(1, 1, 1),
221 viewRange = scene->createViewport(
"view2d_range");
222 viewRange->setViewportPosition(
223 5, -10 - 1 * (VW_GAP + VW_HEIGHT), VW_WIDTH, VW_HEIGHT);
225 win3D.addTextMessage(
226 30, -25 - 2 * (VW_GAP + VW_HEIGHT),
"Intensity data",
228 viewInt = scene->createViewport(
"view2d_int");
229 viewInt->setViewportPosition(
230 5, -10 - 2 * (VW_GAP + VW_HEIGHT), VW_WIDTH, VW_HEIGHT);
232 win3D.unlockAccess3DScene();
239 while (win3D.isOpen() && !thrPar.
quit)
242 std::atomic_load(&thrPar.
new_obs);
244 (!last_obs || possiblyNewObs->timestamp != last_obs->timestamp))
247 last_obs = possiblyNewObs;
248 last_obs_imu = std::atomic_load(&thrPar.
new_obs_imu);
251 bool do_refresh =
false;
254 if (last_obs->hasRangeImage)
261 range2D = last_obs->rangeImage *
264 img.setFromMatrix(range2D);
266 win3D.get3DSceneAndLock();
267 viewRange->setImageView_fast(
img);
268 win3D.unlockAccess3DScene();
273 if (last_obs->hasRangeImage)
277 mrpt::make_aligned_shared<CObservation2DRangeScan>();
283 sp.sensorLabel =
"KINECT_2D_SCAN";
285 last_obs->convertTo2DScan(*obs_2d, sp);
288 gl_2d_scan->setScan(*obs_2d);
292 if (last_obs->hasIntensityImage)
294 win3D.get3DSceneAndLock();
295 viewInt->setImageView(
296 last_obs->intensityImage);
299 win3D.unlockAccess3DScene();
304 if (last_obs->hasPoints3D)
306 win3D.get3DSceneAndLock();
310 last_obs->project3DPointsFromDepthImageInto(*gl_points, pp);
311 win3D.unlockAccess3DScene();
316 win3D.get3DSceneAndLock();
318 win3D.addTextMessage(
322 win3D.addTextMessage(
324 "'o'/'i'-zoom out/in, '2'/'3'/'f':show/hide 2D/3D/frustum " 325 "data, mouse: orbit 3D, ESC: quit",
328 win3D.addTextMessage(
330 "Show: 3D=%s 2D=%s Frustum=%s (vert. FOV=%.1fdeg)",
331 gl_points->isVisible() ?
"YES" :
"NO",
332 gl_2d_scan->isVisible() ?
"YES" :
"NO",
333 gl_frustum->isVisible() ?
"YES" :
"NO",
334 gl_frustum->getVertFOV()),
336 win3D.unlockAccess3DScene();
339 if (last_obs_imu && last_obs_imu->dataIsPresent[
IMU_X_ACC])
341 win3D.get3DSceneAndLock();
342 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 (std::exception& e)
418 std::cout <<
"EXCEPCION: " << e.what() << std::endl;
423 printf(
"Another exception!!");
double Tac() noexcept
Stops the stopwatch.
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.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
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 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().
virtual void initialize()
Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different par...
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.
A matrix of dynamic size.
std::shared_ptr< T > make_aligned_shared(Args &&... args)
Creates a shared_ptr with aligned memory via aligned_allocator_cpp11<>.
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
x-axis acceleration (local/vehicle frame) (m/sec2)
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.