59 bool _is_online,
const string& _rawlog_file =
string(),
60 bool _generate_3D_pointcloud_in_this_thread =
false)
61 : is_online(_is_online),
62 rawlog_file(_rawlog_file),
63 generate_3D_pointcloud_in_this_thread(
64 _generate_3D_pointcloud_in_this_thread),
73 const string rawlog_file;
76 const bool generate_3D_pointcloud_in_this_thread;
101 typedef std::unique_ptr<CKinect>
118 kinect->enableGrabRGB(
true);
119 kinect->enableGrabDepth(
true);
120 kinect->enableGrabAccelerometers(
false);
121 kinect->enableGrab3DPoints(
p.generate_3D_pointcloud_in_this_thread);
124 cout <<
"Calling CKinect::initialize()...";
125 kinect->initialize();
132 if (!dataset.
open(
p.rawlog_file))
133 throw std::runtime_error(
134 "Couldn't open rawlog dataset file for input...");
137 CImage::setImagesPathBase(
138 CRawlog::detectImagesDirectory(
p.rawlog_file));
149 bool there_is_obs =
true, hard_error =
false;
155 kinect->getNextObservation(*obs, there_is_obs, hard_error);
158 throw std::runtime_error(
159 "Sensor returned 'hardware error'");
160 else if (there_is_obs)
163 std::atomic_store(&
p.new_obs, obs);
176 catch (std::exception& e)
178 throw std::runtime_error(
180 "\nError reading from dataset file (EOF?):\n") +
199 #ifndef FAKE_KINECT_FPS_RATE 200 const double At_dataset =
203 const double At_dataset = 1.0 / FAKE_KINECT_FPS_RATE;
206 my_last_read_obs_tim, now_tim);
208 const double need_to_wait_ms =
209 1000. * (At_dataset - At_actual);
212 if (need_to_wait_ms > 0)
213 std::this_thread::sleep_for(
214 std::chrono::duration<double, std::milli>(
219 std::atomic_store(&
p.new_obs, obs3D);
221 dataset_prev_tim = cur_tim;
229 p.Hz = nImgs / tictac.
Tac();
235 catch (std::exception& e)
237 cout <<
"Exception in Kinect thread: " << e.what() << endl;
246 bool is_online,
const string& rawlog_file =
string())
251 is_online, rawlog_file,
260 cout <<
"Waiting for sensor initialization...\n";
267 std::this_thread::sleep_for(10ms);
268 }
while (!thrPar.quit);
271 if (thrPar.quit)
return;
272 cout <<
"OK! Sensor started to emit observations.\n";
278 win3D.setCameraAzimuthDeg(140);
279 win3D.setCameraElevationDeg(20);
280 win3D.setCameraZoom(8.0);
282 win3D.setCameraPointingToPoint(2.5, 0, 0);
285 mrpt::make_aligned_shared<mrpt::opengl::CPointCloudColoured>();
286 gl_points->setPointSize(2.5);
294 scene->insert(gl_points);
295 scene->insert(mrpt::make_aligned_shared<mrpt::opengl::CGridPlaneXY>());
298 const double aspect_ratio = 480.0 / 640.0;
301 const int VW_HEIGHT = aspect_ratio * VW_WIDTH;
304 viewInt = scene->createViewport(
"view2d_int");
305 viewInt->setViewportPosition(5, 30, VW_WIDTH, VW_HEIGHT);
306 win3D.addTextMessage(
307 10, 30 + VW_HEIGHT + 10,
"Intensity data",
TColorf(1, 1, 1), 2,
310 win3D.addTextMessage(
311 5, 5,
format(
"'o'/'i'-zoom out/in, ESC: quit"),
TColorf(0, 0, 1),
314 win3D.unlockAccess3DScene();
320 while (win3D.isOpen() && !thrPar.quit)
324 newObs->timestamp != last_obs_tim)
327 last_obs_tim = newObs->timestamp;
331 win3D.get3DSceneAndLock();
334 win3D.addTextMessage(
340 win3D.addTextMessage(
345 if (newObs->hasIntensityImage)
347 viewInt->setImageView(newObs->intensityImage);
354 win3D.unlockAccess3DScene();
364 if (newObs->hasRangeImage)
367 logger.
enter(
"RGBD->3D");
371 static pcl::PointCloud<pcl::PointXYZ> cloud;
372 logger.
enter(
"RGBD->3D.projectInto");
373 newObs->project3DPointsFromDepthImageInto(cloud,
false );
374 logger.
leave(
"RGBD->3D.projectInto");
376 win3D.get3DSceneAndLock();
377 logger.
enter(
"RGBD->3D.load in OpenGL");
378 gl_points->loadFromPointsMap(&cloud);
379 logger.
leave(
"RGBD->3D.load in OpenGL");
380 win3D.unlockAccess3DScene();
385 static pcl::PointCloud<pcl::PointXYZRGB> cloud;
386 logger.
enter(
"RGBD->3D.projectInto");
387 newObs->project3DPointsFromDepthImageInto(cloud,
false );
388 logger.
leave(
"RGBD->3D.projectInto");
390 win3D.get3DSceneAndLock();
391 logger.
enter(
"RGBD->3D.load in OpenGL");
392 gl_points->loadFromPointsMap(&cloud);
393 logger.
leave(
"RGBD->3D.load in OpenGL");
394 win3D.unlockAccess3DScene();
399 win3D.get3DSceneAndLock();
400 logger.
enter(
"RGBD->3D.projectInto");
404 newObs->project3DPointsFromDepthImageInto(*gl_points, pp);
406 logger.
leave(
"RGBD->3D.projectInto");
407 win3D.unlockAccess3DScene();
413 win3D.get3DSceneAndLock();
414 logger.
enter(
"RGBD->3D.projectInto");
415 newObs->project3DPointsFromDepthImageInto(*gl_points,
false , &globalPose);
416 logger.
leave(
"RGBD->3D.projectInto");
417 win3D.unlockAccess3DScene();
424 if (!newObs->hasPoints3D)
426 logger.
enter(
"RGBD->3D.projectInto");
427 newObs->project3DPointsFromDepthImage();
428 logger.
leave(
"RGBD->3D.projectInto");
431 CColouredPointsMap pntsMap;
432 pntsMap.colorScheme.scheme = CColouredPointsMap::cmFromIntensityImage;
433 pntsMap.loadFromRangeScan(*newObs);
435 win3D.get3DSceneAndLock();
436 logger.
enter(
"RGBD->3D.load in OpenGL");
437 gl_points->loadFromPointsMap(&pntsMap);
438 logger.
leave(
"RGBD->3D.load in OpenGL");
439 win3D.unlockAccess3DScene();
442 logger.
leave(
"RGBD->3D");
452 const int key = tolower(win3D.getPushedKey());
458 win3D.setCameraZoom(win3D.getCameraZoom() * 1.2);
462 win3D.setCameraZoom(win3D.getCameraZoom() / 1.2);
473 std::this_thread::sleep_for(1ms);
476 cout <<
"Waiting for grabbing thread to exit...\n";
482 int main(
int argc,
char** argv)
487 if (argc != 1 && argc != 2)
490 << argv[0] <<
" --> Online grab from sensor\n" 491 << argv[0] <<
" [DATASET.rawlog] --> Offline from dataset\n";
498 cout <<
"Using online operation" << endl;
504 cout <<
"Using offline operation with: " << argv[1] << endl;
508 std::this_thread::sleep_for(50ms);
511 catch (std::exception& e)
513 std::cout <<
"EXCEPCION: " << e.what() << std::endl;
518 printf(
"Another exception!!");
double Tac() noexcept
Stops the stopwatch.
double DEG2RAD(const double x)
Degrees to radians.
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.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream
#define ASSERT_(f)
Defines an assertion mechanism.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
A class for grabing "range images", intensity images (either RGB or IR) and other information from an...
This namespace contains representation of robot actions and observations.
void Test_KinectOnlineOffline(bool is_online, const string &rawlog_file=string())
double leave(const char *func_name)
End of a named section.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
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)
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
Used in CObservation3DRangeScan::project3DPointsFromDepthImageInto()
A RGB color - floats in the range [0,1].
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.
double timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
void Tic() noexcept
Starts the stopwatch.
std::string dateTimeLocalToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
renders glyphs as filled polygons
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
bool takeIntoAccountSensorPoseOnRobot
(Default: false) If false, local (sensor-centric) coordinates of points are generated.
void enter(const char *func_name)
Start of a named section.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.