Skip to content

Commit ad56383

Browse files
authored
Remove last usage of date_time and replace it with std::chrono (PointCloudLibrary#5596)
* Remove last usage of date_time and replace it with std::chrono * Added new header with getTimestamp method. Added unit test to ensure it returns as expected, like boost format. Changed tools to use the new function. * Fix us printout. * Use frametime and not current time. * Minor doc correction. * Renaming. * Remove posix_time in additional files. Add parsing of string to time_point. Return timestamp in local timezone instead of UTC. rename from timestamp_generator to timestamp, since it can also parse now. * Add duration parse to microseconds, to get correct difference. * Doxygen Faster find using a char instead of string, per clang-tidy. * Remove last occurrences of date-time and only call pcl::getTimestamp once in openni_save_image.cpp. * Fix if check for position of dot in iso timestamp string. * Address reviews:�getTime returns time in seconds, don't multiply with 1000 in kinfu. Lowercase timestamp test in test/io/CMakeLists.txt Call getTimestamp once in openni_image.
1 parent 64ac461 commit ad56383

27 files changed

+297
-148
lines changed

.dev/docker/env/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ RUN apt-get update \
3030
clang-tidy \
3131
libbenchmark-dev \
3232
libblas-dev \
33-
libboost-date-time-dev \
33+
libboost-serialization-dev \
3434
libboost-filesystem-dev \
3535
libboost-iostreams-dev \
3636
libflann-dev \

.dev/docker/release/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN sed -i 's/^deb \(.*\)$/deb \1\ndeb-src \1/' /etc/apt/sources.list \
1515
dpkg-dev \
1616
git \
1717
g++ \
18-
libboost-date-time-dev \
18+
libboost-serialization-dev \
1919
libboost-filesystem-dev \
2020
libboost-iostreams-dev \
2121
libeigen3-dev \

.dev/docker/ubuntu-variety/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ENV DEBIAN_FRONTEND=noninteractive
1515
RUN apt update
1616
RUN apt install -y git cmake ${COMPILER_PACKAGE}
1717
RUN apt install -y libeigen3-dev libflann-dev
18-
RUN apt install -y libboost-filesystem-dev libboost-date-time-dev libboost-iostreams-dev
18+
RUN apt install -y libboost-filesystem-dev libboost-serialization-dev libboost-iostreams-dev
1919
RUN apt install -y libgtest-dev libbenchmark-dev
2020
RUN apt install -y qtbase5-dev libvtk${VTK_VERSION}-dev libvtk${VTK_VERSION}-qt-dev
2121

apps/src/openni_grab_frame.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <pcl/console/print.h>
4141
#include <pcl/io/openni_grabber.h>
4242
#include <pcl/io/pcd_io.h>
43+
#include <pcl/io/timestamp.h>
4344
#include <pcl/visualization/pcl_visualizer.h>
4445
#include <pcl/point_cloud.h>
4546
#include <pcl/point_types.h>
@@ -157,8 +158,7 @@ class OpenNIGrabFrame {
157158
saveCloud()
158159
{
159160
FPS_CALC("I/O");
160-
const std::string time = boost::posix_time::to_iso_string(
161-
boost::posix_time::microsec_clock::local_time());
161+
const std::string time = pcl::getTimestamp();
162162
const std::string filepath = dir_name_ + '/' + file_name_ + '_' + time + ".pcd";
163163

164164
if (format_ & 1) {

apps/src/openni_grab_images.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ class OpenNIGrabFrame {
117117
void
118118
saveImages()
119119
{
120-
std::string time = boost::posix_time::to_iso_string(
121-
boost::posix_time::microsec_clock::local_time());
120+
const std::string time = pcl::getTimestamp();
122121
openni_wrapper::Image::Ptr image;
123122
openni_wrapper::DepthImage::Ptr depth_image;
124123

@@ -204,8 +203,7 @@ class OpenNIGrabFrame {
204203

205204
// wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1);
206205
while (!image_viewer_.wasStopped() && !quit_) {
207-
std::string time = boost::posix_time::to_iso_string(
208-
boost::posix_time::microsec_clock::local_time());
206+
const std::string time = pcl::getTimestamp();
209207
openni_wrapper::Image::Ptr image;
210208
openni_wrapper::DepthImage::Ptr depth_image;
211209

apps/src/openni_klt.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
#include <pcl/console/print.h>
4040
#include <pcl/io/openni_grabber.h>
4141
#include <pcl/io/pcd_io.h>
42+
#include <pcl/io/timestamp.h>
4243
#include <pcl/keypoints/harris_2d.h>
4344
#include <pcl/tracking/pyramidal_klt.h>
4445
#include <pcl/visualization/image_viewer.h>
4546

46-
#include <boost/date_time/posix_time/posix_time.hpp> // for to_iso_string, local_time
47-
4847
#include <mutex>
4948

5049
#define SHOW_FPS 1
@@ -175,9 +174,7 @@ class OpenNIViewer {
175174
if ((event.getKeyCode() == 's') || (event.getKeyCode() == 'S')) {
176175
std::lock_guard<std::mutex> lock(cloud_mutex_);
177176
frame.str("frame-");
178-
frame << boost::posix_time::to_iso_string(
179-
boost::posix_time::microsec_clock::local_time())
180-
<< ".pcd";
177+
frame << pcl::getTimestamp() << ".pcd";
181178
writer.writeBinaryCompressed(frame.str(), *cloud_);
182179
PCL_INFO("Written cloud %s.\n", frame.str().c_str());
183180
}

cmake/pcl_find_boost.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if(Boost_SERIALIZATION_FOUND)
2626
endif()
2727

2828
# Required boost modules
29-
set(BOOST_REQUIRED_MODULES filesystem date_time iostreams system)
29+
set(BOOST_REQUIRED_MODULES filesystem iostreams system)
3030
find_package(Boost 1.65.0 REQUIRED COMPONENTS ${BOOST_REQUIRED_MODULES})
3131

3232
if(Boost_FOUND)

cmake/pcl_pclconfig.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ foreach(_ss ${PCL_SUBSYSTEMS_MODULES})
7878
endforeach()
7979

8080
#Boost modules
81-
set(PCLCONFIG_AVAILABLE_BOOST_MODULES "system filesystem date_time iostreams")
81+
set(PCLCONFIG_AVAILABLE_BOOST_MODULES "system filesystem iostreams")
8282
if(Boost_SERIALIZATION_FOUND)
8383
string(APPEND PCLCONFIG_AVAILABLE_BOOST_MODULES " serialization")
8484
endif()

common/include/pcl/common/boost.h

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ PCL_DEPRECATED_HEADER(1, 15, "Please include the needed boost headers directly."
4747
// Marking all Boost headers as system headers to remove warnings
4848
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
4949
#include <boost/mpl/size.hpp>
50-
#include <boost/date_time/posix_time/posix_time.hpp>
5150
#include <boost/signals2.hpp>
5251
#include <boost/signals2/slot.hpp>
5352
#include <boost/algorithm/string.hpp>

doc/tutorials/content/building_pcl.rst

+25-25
Original file line numberDiff line numberDiff line change
@@ -198,31 +198,31 @@ then a sample value is given for reference.
198198

199199
* Boost
200200

201-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
202-
| cache variable | meaning | sample value |
203-
+==================================+===============================================================+==========================================+
204-
| Boost_DATE_TIME_LIBRARY | full path to boost_date-time.[so,lib,a] | /usr/local/lib/libboost_date_time.so |
205-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
206-
| Boost_DATE_TIME_LIBRARY_DEBUG | full path to boost_date-time.[so,lib,a] (debug version) | /usr/local/lib/libboost_date_time-gd.so |
207-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
208-
| Boost_DATE_TIME_LIBRARY_RELEASE | full path to boost_date-time.[so,lib,a] (release version) | /usr/local/lib/libboost_date_time.so |
209-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
210-
| Boost_FILESYSTEM_LIBRARY | full path to boost_filesystem.[so,lib,a] | /usr/local/lib/libboost_filesystem.so |
211-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
212-
| Boost_FILESYSTEM_LIBRARY_DEBUG | full path to boost_filesystem.[so,lib,a] (debug version) | /usr/local/lib/libboost_filesystem-gd.so |
213-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
214-
| Boost_FILESYSTEM_LIBRARY_RELEASE | full path to boost_filesystem.[so,lib,a] (release version) | /usr/local/lib/libboost_filesystem.so |
215-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
216-
| Boost_INCLUDE_DIR | path to boost headers directory | /usr/local/include |
217-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
218-
| Boost_LIBRARY_DIRS | path to boost libraries directory | /usr/local/lib |
219-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
220-
| Boost_SYSTEM_LIBRARY | full path to boost_system.[so,lib,a] | /usr/local/lib/libboost_system.so |
221-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
222-
| Boost_SYSTEM_LIBRARY_DEBUG | full path to boost_system.[so,lib,a] (debug version) | /usr/local/lib/libboost_system-gd.so |
223-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
224-
| Boost_SYSTEM_LIBRARY_RELEASE | full path to boost_system.[so,lib,a] (release version) | /usr/local/lib/libboost_system.so |
225-
+----------------------------------+---------------------------------------------------------------+------------------------------------------+
201+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
202+
| cache variable | meaning | sample value |
203+
+=====================================+===============================================================+=============================================+
204+
| Boost_SERIALIZATION_LIBRARY | full path to boost_serialization.[so,lib,a] | /usr/local/lib/libboost_serialization.so |
205+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
206+
| Boost_SERIALIZATION_LIBRARY_DEBUG | full path to boost_serialization.[so,lib,a] (debug version) | /usr/local/lib/libboost_serialization-gd.so |
207+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
208+
| Boost_SERIALIZATION_LIBRARY_RELEASE | full path to boost_serialization.[so,lib,a] (release version) | /usr/local/lib/libboost_serialization.so |
209+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
210+
| Boost_FILESYSTEM_LIBRARY | full path to boost_filesystem.[so,lib,a] | /usr/local/lib/libboost_filesystem.so |
211+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
212+
| Boost_FILESYSTEM_LIBRARY_DEBUG | full path to boost_filesystem.[so,lib,a] (debug version) | /usr/local/lib/libboost_filesystem-gd.so |
213+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
214+
| Boost_FILESYSTEM_LIBRARY_RELEASE | full path to boost_filesystem.[so,lib,a] (release version) | /usr/local/lib/libboost_filesystem.so |
215+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
216+
| Boost_INCLUDE_DIR | path to boost headers directory | /usr/local/include |
217+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
218+
| Boost_LIBRARY_DIRS | path to boost libraries directory | /usr/local/lib |
219+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
220+
| Boost_SYSTEM_LIBRARY | full path to boost_system.[so,lib,a] | /usr/local/lib/libboost_system.so |
221+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
222+
| Boost_SYSTEM_LIBRARY_DEBUG | full path to boost_system.[so,lib,a] (debug version) | /usr/local/lib/libboost_system-gd.so |
223+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
224+
| Boost_SYSTEM_LIBRARY_RELEASE | full path to boost_system.[so,lib,a] (release version) | /usr/local/lib/libboost_system.so |
225+
+-------------------------------------+---------------------------------------------------------------+---------------------------------------------+
226226

227227

228228
* CMinpack

doc/tutorials/content/dinast_grabber.rst

+55-51
Original file line numberDiff line numberDiff line change
@@ -41,69 +41,73 @@ The code from *apps/src/dinast_grabber_example.cpp* will be used for this tutori
4141
:linenos:
4242
4343
#include <pcl/common/time.h>
44-
#include <pcl/point_types.h>
4544
#include <pcl/io/dinast_grabber.h>
4645
#include <pcl/visualization/cloud_viewer.h>
46+
#include <pcl/point_types.h>
47+
48+
#include <chrono>
49+
#include <thread>
50+
51+
using namespace std::chrono_literals;
4752
4853
template <typename PointType>
49-
class DinastProcessor
50-
{
51-
public:
52-
53-
typedef pcl::PointCloud<PointType> Cloud;
54-
typedef typename Cloud::ConstPtr CloudConstPtr;
55-
56-
DinastProcessor(pcl::Grabber& grabber) : interface(grabber), viewer("Dinast Cloud Viewer") {}
57-
58-
void
59-
cloud_cb_ (CloudConstPtr cloud_cb)
60-
{
61-
static unsigned count = 0;
62-
static double last = pcl::getTime ();
63-
if (++count == 30)
64-
{
65-
double now = pcl::getTime ();
66-
std::cout << "Average framerate: " << double(count)/double(now - last) << " Hz" << std::endl;
67-
count = 0;
68-
last = now;
69-
}
70-
if (!viewer.wasStopped())
71-
viewer.showCloud(cloud_cb);
54+
class DinastProcessor {
55+
public:
56+
using Cloud = pcl::PointCloud<PointType>;
57+
using CloudConstPtr = typename Cloud::ConstPtr;
58+
59+
DinastProcessor(pcl::Grabber& grabber)
60+
: interface(grabber), viewer("Dinast Cloud Viewer")
61+
{}
62+
63+
void
64+
cloud_cb_(CloudConstPtr cloud_cb)
65+
{
66+
static unsigned count = 0;
67+
static double last = pcl::getTime();
68+
if (++count == 30) {
69+
double now = pcl::getTime();
70+
std::cout << "Average framerate: " << double(count) / double(now - last) << " Hz"
71+
<< std::endl;
72+
count = 0;
73+
last = now;
7274
}
73-
74-
int
75-
run ()
76-
{
77-
78-
std::function<void (const CloudConstPtr&)> f =
79-
[this] (const CloudConstPtr& cloud) { cloud_cb_ (cloud); };
80-
81-
boost::signals2::connection c = interface.registerCallback (f);
75+
if (!viewer.wasStopped())
76+
viewer.showCloud(cloud_cb);
77+
}
8278
83-
interface.start ();
84-
85-
while (!viewer.wasStopped())
86-
{
87-
boost::this_thread::sleep (boost::posix_time::seconds (1));
88-
}
89-
90-
interface.stop ();
91-
92-
return(0);
79+
int
80+
run()
81+
{
82+
83+
std::function<void(const CloudConstPtr&)> f = [this](const CloudConstPtr& cloud) {
84+
cloud_cb_(cloud);
85+
};
86+
87+
boost::signals2::connection c = interface.registerCallback(f);
88+
89+
interface.start();
90+
91+
while (!viewer.wasStopped()) {
92+
std::this_thread::sleep_for(1s);
9393
}
94-
95-
pcl::Grabber& interface;
96-
pcl::visualization::CloudViewer viewer;
97-
94+
95+
interface.stop();
96+
97+
return 0;
98+
}
99+
100+
pcl::Grabber& interface;
101+
pcl::visualization::CloudViewer viewer;
98102
};
99103
100104
int
101-
main ()
105+
main()
102106
{
103107
pcl::DinastGrabber grabber;
104-
DinastProcessor<pcl::PointXYZI> v (grabber);
105-
v.run ();
106-
return (0);
108+
DinastProcessor<pcl::PointXYZI> v(grabber);
109+
v.run();
110+
return 0;
107111
}
108112
109113
The explanation

doc/tutorials/content/openni_grabber.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ the OpenNI Grabber.
3636

3737
<iframe title="PCL OpenNI Viewer example" width="480" height="390" src="https://www.youtube.com/embed/x3SaWQkPsPI?rel=0" frameborder="0" allowfullscreen></iframe>
3838

39-
So let's look at the code. From *visualization/tools/openni_viewer_simple.cpp*
39+
So let's look at the code. From *tools/openni_viewer_simple.cpp*
4040

4141
.. code-block:: cpp
4242
:linenos:
4343
4444
#include <pcl/io/openni_grabber.h>
4545
#include <pcl/visualization/cloud_viewer.h>
46+
47+
48+
#include <chrono>
49+
#include <thread>
50+
51+
using namespace std::chrono_literals;
52+
4653
4754
class SimpleOpenNIViewer
4855
{
@@ -68,7 +75,7 @@ So let's look at the code. From *visualization/tools/openni_viewer_simple.cpp*
6875
6976
while (!viewer.wasStopped())
7077
{
71-
boost::this_thread::sleep (boost::posix_time::seconds (1));
78+
std::this_thread::sleep_for(1s);
7279
}
7380
7481
interface->stop ();

doc/tutorials/content/pcl_visualizer.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ found at the bottom of the sample:
145145
while (!viewer->wasStopped ())
146146
{
147147
viewer->spinOnce (100);
148-
boost::this_thread::sleep (boost::posix_time::microseconds (100000));
148+
std::this_thread::sleep_for(100ms);
149149
}
150150
...
151151

0 commit comments

Comments
 (0)