Skip to content

Commit 6cc2d8d

Browse files
committed
Use YARP logging in sceneReconstruction app
1 parent 67df128 commit 6cc2d8d

File tree

6 files changed

+75
-103
lines changed

6 files changed

+75
-103
lines changed

programs/sceneReconstruction/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ if(ENABLE_sceneReconstruction)
2424
YARP::YARP_dev
2525
YARP::YARP_sig
2626
YARP::YARP_cv
27-
opencv_rgbd
28-
ROBOTICSLAB::ColorDebug)
27+
opencv_rgbd)
2928

3029
if(OpenCV_VERSION VERSION_GREATER_EQUAL 4.2)
3130
target_sources(sceneReconstruction PRIVATE DynaFu.cpp)

programs/sceneReconstruction/DynaFu.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "KinectFusionImpl.hpp"
44

5-
#include <opencv2/rgbd/dynafu.hpp>
5+
#include <yarp/os/LogStream.h>
66

7-
#include <ColorDebug.h>
7+
#include <opencv2/rgbd/dynafu.hpp>
88

99
namespace roboticslab
1010
{
@@ -15,10 +15,10 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
1515

1616
auto params = Params::defaultParams();
1717

18-
CD_INFO("algorithm: DynaFu\n");
18+
yInfo() << "algorithm: DynaFu";
1919

2020
params->frameSize = cv::Size(width, height);
21-
CD_INFO("dimensions: width = %d, height = %d\n", width, height);
21+
yInfo() << "dimensions: width =" << width << "x height =" << height;
2222

2323
float fx = intrinsic.focalLengthX;
2424
float fy = intrinsic.focalLengthY;
@@ -29,7 +29,7 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
2929
0, fy, cy,
3030
0, 0, 1);
3131

32-
CD_INFO("intrinsic params: fx = %f, fy = %f, cx = %f, cy = %f\n", fx, fy, cx, cy);
32+
yInfo() << "intrinsic params: fx =" << fx << "fy =" << fy << "cx =" << cx << "cy =" << cy;
3333

3434
updateParam(*params, &Params::depthFactor, config, "depthFactor", "pre-scale per 1 meter for input values");
3535
updateParam(*params, &Params::voxelSize, config, "voxelSize", "size of voxel in meters");
@@ -41,17 +41,17 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
4141

4242
if (volumeDims == nullptr || volumeDims->size() != 3)
4343
{
44-
CD_ERROR("Parameter volumeDims must be a list of 3 integers.\n");
44+
yError() << "Parameter volumeDims must be a list of 3 integers";
4545
return nullptr;
4646
}
4747

4848
params->volumeDims = cv::Vec3i(volumeDims->get(0).asInt32(), volumeDims->get(1).asInt32(), volumeDims->get(2).asInt32());
49-
CD_INFO("volumeDims: (%s)\n", volumeDims->toString().c_str());
49+
yInfo() << "volumeDims =" << volumeDims->toString();
5050
}
5151
else
5252
{
5353
const auto & cvDims = params->volumeDims;
54-
CD_INFO("volumeDims (DEFAULT): (%d %d %d)\n", cvDims[0], cvDims[1], cvDims[2]);
54+
yInfo() << "volumeDims (DEFAULT) =" << cvDims[0] << cvDims[1] << cvDims[2];
5555
}
5656

5757
if (config.check("lightPose", "light pose for rendering in meters"))
@@ -60,17 +60,17 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
6060

6161
if (lightPose == nullptr || lightPose->size() != 3)
6262
{
63-
CD_ERROR("Parameter lightPose must be a list of 3 floats.\n");
63+
yError() << "Parameter lightPose must be a list of 3 floats";
6464
return nullptr;
6565
}
6666

6767
params->lightPose = cv::Vec3f(lightPose->get(0).asFloat32(), lightPose->get(1).asFloat32(), lightPose->get(2).asFloat32());
68-
CD_INFO("lightPose: (%s)\n", lightPose->toString().c_str());
68+
yInfo() << "lightPose =" << lightPose->toString();
6969
}
7070
else
7171
{
7272
const auto & cvLight = params->lightPose;
73-
CD_INFO("lightPose (DEFAULT): (%f %f %f)\n", cvLight[0], cvLight[1], cvLight[2]);
73+
yInfo() << "lightPose (DEFAULT) =" << cvLight[0] << cvLight[1] << cvLight[2];
7474
}
7575

7676
if (config.check("volumePoseTransl", "volume pose (translation vector) in meters"))
@@ -79,18 +79,18 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
7979

8080
if (volumePoseTransl == nullptr || volumePoseTransl->size() != 3)
8181
{
82-
CD_ERROR("Parameter volumePoseTransl must be a list of 3 floats.\n");
82+
yError() << "Parameter volumePoseTransl must be a list of 3 floats";
8383
return nullptr;
8484
}
8585

8686
auto transl = cv::Vec3f(volumePoseTransl->get(0).asFloat32(), volumePoseTransl->get(1).asFloat32(), volumePoseTransl->get(2).asFloat32());
8787
params->volumePose.translation(transl);
88-
CD_INFO("volumePoseTransl: (%s)\n", volumePoseTransl->toString().c_str());
88+
yInfo() << "volumePoseTransl =" << volumePoseTransl->toString();
8989
}
9090
else
9191
{
9292
const auto & transl = params->volumePose.translation();
93-
CD_INFO("volumePoseTransl (DEFAULT): (%f %f %f)\n", transl[0], transl[1], transl[2]);
93+
yInfo() << "volumePoseTransl (DEFAULT) =" << transl[0] << transl[1] << transl[2];
9494
}
9595

9696
if (config.check("volumePoseRot", "volume pose (rotation matrix) in radians"))
@@ -99,7 +99,7 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
9999

100100
if (volumePoseRot == nullptr || volumePoseRot->size() != 9)
101101
{
102-
CD_ERROR("Parameter volumePoseRot must be a list of 9 floats (3x3 matrix).\n");
102+
yError() << "Parameter volumePoseRot must be a list of 9 floats (3x3 matrix)";
103103
return nullptr;
104104
}
105105

@@ -108,12 +108,12 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
108108
volumePoseRot->get(6).asFloat32(), volumePoseRot->get(7).asFloat32(), volumePoseRot->get(8).asFloat32());
109109

110110
params->volumePose.rotation(rot);
111-
CD_INFO("volumePoseRot: (%s)\n", volumePoseRot->toString().c_str());
111+
yInfo() << "volumePoseRot =" << volumePoseRot->toString();
112112
}
113113
else
114114
{
115115
const auto & rot = params->volumePose.rotation();
116-
CD_INFO("volumePoseRot (DEFAULT): (%f %f %f %f %f %f %f %f %f)\n", rot(0,0), rot(0,1), rot(0,2), rot(1,0), rot(1,1), rot(1,2), rot(2,0), rot(2,1), rot(2,2));
116+
yInfo() << "volumePoseRot (DEFAULT) =" << rot(0,0) << rot(0,1) << rot(0,2) << rot(1,0) << rot(1,1) << rot(1,2) << rot(2,0) << rot(2,1) << rot(2,2);
117117
}
118118

119119
updateParam(*params, &Params::truncateThreshold, config, "truncateThreshold", "threshold for depth truncation in meters");
@@ -132,7 +132,7 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
132132

133133
if (icpIterations == nullptr)
134134
{
135-
CD_ERROR("Parameter icpIterations must be a list.\n");
135+
yError() << "Parameter icpIterations must be a list";
136136
return nullptr;
137137
}
138138

@@ -143,11 +143,11 @@ std::unique_ptr<KinectFusion> makeDynaFu(const yarp::os::Searchable & config, co
143143
params->icpIterations[i] = icpIterations->get(i).asInt32();
144144
}
145145

146-
CD_INFO("icpIterations: (%s)\n", icpIterations->toString().c_str());
146+
yInfo() << "icpIterations =" << icpIterations->toString();
147147
}
148148
else
149149
{
150-
CD_INFO("icpIterations (DEFAULT): (%s)\n", vectorToString(params->icpIterations).c_str());
150+
yInfo() << "icpIterations (DEFAULT) =" << params->icpIterations;
151151
}
152152

153153
updateParam(*params, &Params::tsdf_max_weight, config, "tsdfMaxWeight", "max number of frames per voxel");

programs/sceneReconstruction/KinFu.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
#include <map>
66

7+
#include <yarp/os/LogStream.h>
8+
79
#include <opencv2/core/version.hpp>
810
#include <opencv2/rgbd/kinfu.hpp>
911

10-
#include <ColorDebug.h>
11-
1212
#if CV_VERSION_MINOR >= 4
1313
namespace
1414
{
@@ -28,10 +28,10 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
2828

2929
auto params = Params::defaultParams();
3030

31-
CD_INFO("algorithm: KinFu\n");
31+
yInfo() << "algorithm: KinFu";
3232

3333
params->frameSize = cv::Size(width, height);
34-
CD_INFO("dimensions: width = %d, height = %d\n", width, height);
34+
yInfo() << "dimensions: width =" << width << "x height =" << height;
3535

3636
float fx = intrinsic.focalLengthX;
3737
float fy = intrinsic.focalLengthY;
@@ -42,7 +42,7 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
4242
0, fy, cy,
4343
0, 0, 1);
4444

45-
CD_INFO("intrinsic params: fx = %f, fy = %f, cx = %f, cy = %f\n", fx, fy, cx, cy);
45+
yInfo() << "intrinsic params: fx =" << fx << "fy =" << fy << "cx =" << cx << "cy =" << cy;
4646

4747
updateParam(*params, &Params::depthFactor, config, "depthFactor", "pre-scale per 1 meter for input values");
4848
updateParam(*params, &Params::voxelSize, config, "voxelSize", "size of voxel in meters");
@@ -54,17 +54,17 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
5454

5555
if (volumeDims == nullptr || volumeDims->size() != 3)
5656
{
57-
CD_ERROR("Parameter volumeDims must be a list of 3 integers.\n");
57+
yError() << "Parameter volumeDims must be a list of 3 integers";
5858
return nullptr;
5959
}
6060

6161
params->volumeDims = cv::Vec3i(volumeDims->get(0).asInt32(), volumeDims->get(1).asInt32(), volumeDims->get(2).asInt32());
62-
CD_INFO("volumeDims: (%s)\n", volumeDims->toString().c_str());
62+
yInfo() << "volumeDims =" << volumeDims->toString();
6363
}
6464
else
6565
{
6666
const auto & cvDims = params->volumeDims;
67-
CD_INFO("volumeDims (DEFAULT): (%d %d %d)\n", cvDims[0], cvDims[1], cvDims[2]);
67+
yInfo() << "volumeDims (DEFAULT) =" << cvDims[0] << cvDims[1] << cvDims[2];
6868
}
6969

7070
if (config.check("lightPose", "light pose for rendering in meters"))
@@ -73,17 +73,17 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
7373

7474
if (lightPose == nullptr || lightPose->size() != 3)
7575
{
76-
CD_ERROR("Parameter lightPose must be a list of 3 floats.\n");
76+
yError() << "Parameter lightPose must be a list of 3 floats";
7777
return nullptr;
7878
}
7979

8080
params->lightPose = cv::Vec3f(lightPose->get(0).asFloat32(), lightPose->get(1).asFloat32(), lightPose->get(2).asFloat32());
81-
CD_INFO("lightPose: (%s)\n", lightPose->toString().c_str());
81+
yInfo() << "lightPose =" << lightPose->toString();
8282
}
8383
else
8484
{
8585
const auto & cvLight = params->lightPose;
86-
CD_INFO("lightPose (DEFAULT): (%f %f %f)\n", cvLight[0], cvLight[1], cvLight[2]);
86+
yInfo() << "lightPose (DEFAULT) =" << cvLight[0] << cvLight[1] << cvLight[2];
8787
}
8888

8989
if (config.check("volumePoseTransl", "volume pose (translation vector) in meters"))
@@ -92,18 +92,18 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
9292

9393
if (volumePoseTransl == nullptr || volumePoseTransl->size() != 3)
9494
{
95-
CD_ERROR("Parameter volumePoseTransl must be a list of 3 floats.\n");
95+
yError() << "Parameter volumePoseTransl must be a list of 3 floats";
9696
return nullptr;
9797
}
9898

9999
auto transl = cv::Vec3f(volumePoseTransl->get(0).asFloat32(), volumePoseTransl->get(1).asFloat32(), volumePoseTransl->get(2).asFloat32());
100100
params->volumePose.translation(transl);
101-
CD_INFO("volumePoseTransl: (%s)\n", volumePoseTransl->toString().c_str());
101+
yInfo() << "volumePoseTransl =" << volumePoseTransl->toString();
102102
}
103103
else
104104
{
105105
const auto & transl = params->volumePose.translation();
106-
CD_INFO("volumePoseTransl (DEFAULT): (%f %f %f)\n", transl[0], transl[1], transl[2]);
106+
yInfo() << "volumePoseTransl (DEFAULT) =" << transl[0] << transl[1] << transl[2];
107107
}
108108

109109
if (config.check("volumePoseRot", "volume pose (rotation matrix) in radians"))
@@ -112,7 +112,7 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
112112

113113
if (volumePoseRot == nullptr || volumePoseRot->size() != 9)
114114
{
115-
CD_ERROR("Parameter volumePoseRot must be a list of 9 floats (3x3 matrix).\n");
115+
yError() << "Parameter volumePoseRot must be a list of 9 floats (3x3 matrix)";
116116
return nullptr;
117117
}
118118

@@ -121,12 +121,12 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
121121
volumePoseRot->get(6).asFloat32(), volumePoseRot->get(7).asFloat32(), volumePoseRot->get(8).asFloat32());
122122

123123
params->volumePose.rotation(rot);
124-
CD_INFO("volumePoseRot: (%s)\n", volumePoseRot->toString().c_str());
124+
yInfo() << "volumePoseRot =" << volumePoseRot->toString();
125125
}
126126
else
127127
{
128128
const auto & rot = params->volumePose.rotation();
129-
CD_INFO("volumePoseRot (DEFAULT): (%f %f %f %f %f %f %f %f %f)\n", rot(0,0), rot(0,1), rot(0,2), rot(1,0), rot(1,1), rot(1,2), rot(2,0), rot(2,1), rot(2,2));
129+
yInfo() << "volumePoseRot (DEFAULT) =" << rot(0,0) << rot(0,1) << rot(0,2) << rot(1,0) << rot(1,1) << rot(1,2) << rot(2,0) << rot(2,1) << rot(2,2);
130130
}
131131

132132
#if CV_VERSION_MINOR >= 2
@@ -140,17 +140,17 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
140140

141141
if (stringToCvVolume.find(volumeType) == stringToCvVolume.end())
142142
{
143-
CD_ERROR("Unsupported volume type: %s.\n", volumeType.c_str());
143+
yError() << "Unsupported volume type" << volumeType;
144144
return nullptr;
145145
}
146146

147147
params->volumeType = stringToCvVolume[volumeType];
148-
CD_INFO("volumeType: %s\n", volumeType.c_str());
148+
yInfo() << "volumeType =" << volumeType;
149149
}
150150
else
151151
{
152152
auto res = std::find_if(stringToCvVolume.begin(), stringToCvVolume.end(), [&params](const auto & el) { return el.second == params->volumeType; });
153-
CD_INFO("volumeType (DEFAULT): %s\n", res->first.c_str());
153+
yInfo() << "volumeType (DEFAULT) =" << res->first;
154154
}
155155
#endif
156156

@@ -168,7 +168,7 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
168168

169169
if (icpIterations == nullptr)
170170
{
171-
CD_ERROR("Parameter icpIterations must be a list.\n");
171+
yError() << "Parameter icpIterations must be a list";
172172
return nullptr;
173173
}
174174

@@ -179,11 +179,11 @@ std::unique_ptr<KinectFusion> makeKinFu(const yarp::os::Searchable & config, con
179179
params->icpIterations[i] = icpIterations->get(i).asInt32();
180180
}
181181

182-
CD_INFO("icpIterations: (%s)\n", icpIterations->toString().c_str());
182+
yInfo() << "icpIterations =" << icpIterations->toString();
183183
}
184184
else
185185
{
186-
CD_INFO("icpIterations (DEFAULT): (%s)\n", vectorToString(params->icpIterations).c_str());
186+
yInfo() << "icpIterations (DEFAULT) =" << params->icpIterations;
187187
}
188188

189189
updateParam(*params, &Params::tsdf_max_weight, config, "tsdfMaxWeight", "max number of frames per voxel");

programs/sceneReconstruction/KinectFusionImpl.hpp

+5-21
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55

66
#include "KinectFusion.hpp"
77

8-
#include <algorithm>
9-
#include <iterator>
10-
#include <sstream>
118
#include <type_traits>
129

10+
#include <yarp/os/LogStream.h>
1311
#include <yarp/cv/Cv.h>
1412

15-
#include <ColorDebug.h>
16-
1713
namespace roboticslab
1814
{
1915

@@ -112,31 +108,19 @@ template <typename TParams, typename TRet>
112108
void updateParam(TParams & params, TRet TParams::* param, const yarp::os::Searchable & config,
113109
const std::string & name, const std::string & description)
114110
{
115-
std::stringstream ss;
116-
ss << name;
111+
auto && log = yInfo();
112+
log << name;
117113

118114
if (config.check(name, description))
119115
{
120116
params.*param = getValue<TRet>(config.find(name));
121-
ss << ": ";
122117
}
123118
else
124119
{
125-
ss << " (DEFAULT): ";
120+
log << "(DEFAULT)";
126121
}
127122

128-
ss << params.*param << "\n";
129-
CD_INFO(ss.str().c_str());
130-
}
131-
132-
template <typename T>
133-
inline std::string vectorToString(const std::vector<T> & vec, const std::string & delimiter = " ")
134-
{
135-
// https://stackoverflow.com/a/8581865
136-
std::ostringstream oss;
137-
std::copy(vec.begin(), vec.end() - 1, std::ostream_iterator<T>(oss, delimiter.c_str()));
138-
oss << vec.back();
139-
return oss.str();
123+
log << "=" << params.*param;
140124
}
141125

142126
} // namespace roboticslab

0 commit comments

Comments
 (0)