Skip to content

Commit ef7fd4e

Browse files
committed
Use LOG_* macros in remaining classes
1 parent e30d4a2 commit ef7fd4e

File tree

8 files changed

+68
-82
lines changed

8 files changed

+68
-82
lines changed

examples/protonect/src/cpu_depth_packet_processor.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <libfreenect2/depth_packet_processor.h>
2828
#include <libfreenect2/resource.h>
2929
#include <libfreenect2/protocol/response.h>
30+
#include <libfreenect2/logging.h>
3031

31-
#include <iostream>
3232
#include <fstream>
3333

3434
#include <limits>
@@ -253,7 +253,7 @@ class CpuDepthPacketProcessorImpl
253253
if(timing_acc_n >= 100.0)
254254
{
255255
double avg = (timing_acc / timing_acc_n);
256-
std::cout << "[CpuDepthPacketProcessor] avg. time: " << (avg * 1000) << "ms -> ~" << (1.0/avg) << "Hz" << std::endl;
256+
LOG_INFO << "[CpuDepthPacketProcessor] avg. time: " << (avg * 1000) << "ms -> ~" << (1.0/avg) << "Hz";
257257
timing_acc = 0.0;
258258
timing_acc_n = 0.0;
259259
}
@@ -774,7 +774,7 @@ void CpuDepthPacketProcessor::loadP0TablesFromCommandResponse(unsigned char* buf
774774

775775
if(buffer_length < sizeof(libfreenect2::protocol::P0TablesResponse))
776776
{
777-
std::cerr << "[CpuDepthPacketProcessor::loadP0TablesFromCommandResponse] P0Table response too short!" << std::endl;
777+
LOG_ERROR << "P0Table response too short!";
778778
return;
779779
}
780780

@@ -801,19 +801,19 @@ void CpuDepthPacketProcessor::loadP0TablesFromFiles(const char* p0_filename, con
801801
Mat<uint16_t> p0_table0(424, 512);
802802
if(!loadBufferFromFile2(p0_filename, p0_table0.buffer(), p0_table0.sizeInBytes()))
803803
{
804-
std::cerr << "[CpuDepthPacketProcessor::loadP0TablesFromFiles] Loading p0table 0 from '" << p0_filename << "' failed!" << std::endl;
804+
LOG_ERROR << "Loading p0table 0 from '" << p0_filename << "' failed!";
805805
}
806806

807807
Mat<uint16_t> p0_table1(424, 512);
808808
if(!loadBufferFromFile2(p1_filename, p0_table1.buffer(), p0_table1.sizeInBytes()))
809809
{
810-
std::cerr << "[CpuDepthPacketProcessor::loadP0TablesFromFiles] Loading p0table 1 from '" << p1_filename << "' failed!" << std::endl;
810+
LOG_ERROR << "Loading p0table 1 from '" << p1_filename << "' failed!";
811811
}
812812

813813
Mat<uint16_t> p0_table2(424, 512);
814814
if(!loadBufferFromFile2(p2_filename, p0_table2.buffer(), p0_table2.sizeInBytes()))
815815
{
816-
std::cerr << "[CpuDepthPacketProcessor::loadP0TablesFromFiles] Loading p0table 2 from '" << p2_filename << "' failed!" << std::endl;
816+
LOG_ERROR << "Loading p0table 2 from '" << p2_filename << "' failed!";
817817
}
818818

819819
if(impl_->flip_ptables)
@@ -846,7 +846,7 @@ void CpuDepthPacketProcessor::loadXTableFromFile(const char* filename)
846846
}
847847
else
848848
{
849-
std::cerr << "[CpuDepthPacketProcessor::loadXTableFromFile] Loading xtable from resource 'xTable.bin' failed!" << std::endl;
849+
LOG_ERROR << "Loading xtable from resource 'xTable.bin' failed!";
850850
}
851851
}
852852

@@ -863,7 +863,7 @@ void CpuDepthPacketProcessor::loadZTableFromFile(const char* filename)
863863
}
864864
else
865865
{
866-
std::cerr << "[CpuDepthPacketProcessor::loadZTableFromFile] Loading ztable from resource 'zTable.bin' failed!" << std::endl;
866+
LOG_ERROR << "Loading ztable from resource 'zTable.bin' failed!";
867867
}
868868
}
869869

@@ -878,7 +878,7 @@ void CpuDepthPacketProcessor::load11To16LutFromFile(const char* filename)
878878
}
879879
else
880880
{
881-
std::cerr << "[CpuDepthPacketProcessor::load11To16LutFromFile] Loading 11to16 lut from resource '11to16.bin' failed!" << std::endl;
881+
LOG_ERROR << "Loading 11to16 lut from resource '11to16.bin' failed!";
882882
}
883883
}
884884

examples/protonect/src/libfreenect2.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* either License.
2525
*/
2626

27-
#include <iostream>
27+
#include <string>
2828
#include <vector>
2929
#include <algorithm>
3030
#include <libusb.h>
@@ -446,9 +446,8 @@ void Freenect2DeviceImpl::start()
446446
firmware_ = FirmwareVersionResponse(firmware_result.data, firmware_result.length).toString();
447447

448448
command_tx_.execute(ReadData0x14Command(nextCommandSeq()), result);
449-
LOG_DEBUG
450-
<< "ReadData0x14 response" << std::endl
451-
<< GenericResponse(result.data, result.length).toString();
449+
LOG_DEBUG << "ReadData0x14 response";
450+
LOG_DEBUG << GenericResponse(result.data, result.length).toString();
452451

453452
command_tx_.execute(ReadSerialNumberCommand(nextCommandSeq()), serial_result);
454453
std::string new_serial = SerialNumberResponse(serial_result.data, serial_result.length).toString();
@@ -509,18 +508,16 @@ void Freenect2DeviceImpl::start()
509508
rgb_camera_params_.my_x0y0 = rgb_p->my_x0y0; // 1
510509

511510
command_tx_.execute(ReadStatus0x090000Command(nextCommandSeq()), result);
512-
LOG_DEBUG
513-
<< "ReadStatus0x090000 response" << std::endl
514-
<< GenericResponse(result.data, result.length).toString();
511+
LOG_DEBUG << "ReadStatus0x090000 response";
512+
LOG_DEBUG << GenericResponse(result.data, result.length).toString();
515513

516514
command_tx_.execute(InitStreamsCommand(nextCommandSeq()), result);
517515

518516
usb_control_.setIrInterfaceState(UsbControl::Enabled);
519517

520518
command_tx_.execute(ReadStatus0x090000Command(nextCommandSeq()), result);
521-
LOG_DEBUG
522-
<< "ReadStatus0x090000 response" << std::endl
523-
<< GenericResponse(result.data, result.length).toString();
519+
LOG_DEBUG << "ReadStatus0x090000 response";
520+
LOG_DEBUG << GenericResponse(result.data, result.length).toString();
524521

525522
command_tx_.execute(SetStreamEnabledCommand(nextCommandSeq()), result);
526523

examples/protonect/src/opencl_depth_packet_processor.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
#include <libfreenect2/depth_packet_processor.h>
2828
#include <libfreenect2/resource.h>
2929
#include <libfreenect2/protocol/response.h>
30+
#include <libfreenect2/logging.h>
3031

31-
#include <iostream>
32-
#include <fstream>
3332
#include <sstream>
3433

3534
#define _USE_MATH_DEFINES
@@ -49,8 +48,6 @@
4948
#define REG_OPENCL_FILE ""
5049
#endif
5150

52-
#define OUT_NAME(FUNCTION) "[OpenCLDepthPacketProcessor::" FUNCTION "] "
53-
5451
namespace libfreenect2
5552
{
5653

@@ -61,7 +58,7 @@ std::string loadCLSource(const std::string &filename)
6158

6259
if(!loadResource(filename, &data, &length))
6360
{
64-
std::cerr << OUT_NAME("loadCLSource") "failed to load cl source!" << std::endl;
61+
LOG_ERROR << "failed to load cl source!";
6562
return "";
6663
}
6764

@@ -226,7 +223,7 @@ class OpenCLDepthPacketProcessorImpl
226223

227224
void listDevice(std::vector<cl::Device> &devices)
228225
{
229-
std::cout << OUT_NAME("listDevice") " devices:" << std::endl;
226+
LOG_INFO << " devices:";
230227
for(size_t i = 0; i < devices.size(); ++i)
231228
{
232229
cl::Device &dev = devices[i];
@@ -254,7 +251,7 @@ class OpenCLDepthPacketProcessorImpl
254251
devType = "UNKNOWN";
255252
}
256253

257-
std::cout << " " << i << ": " << devName << " (" << devType << ")[" << devVendor << ']' << std::endl;
254+
LOG_INFO << " " << i << ": " << devName << " (" << devType << ")[" << devVendor << ']';
258255
}
259256
}
260257

@@ -298,12 +295,12 @@ class OpenCLDepthPacketProcessorImpl
298295
std::vector<cl::Platform> platforms;
299296
if(cl::Platform::get(&platforms) != CL_SUCCESS)
300297
{
301-
std::cerr << OUT_NAME("init") "error while getting opencl platforms." << std::endl;
298+
LOG_ERROR << "error while getting opencl platforms.";
302299
return false;
303300
}
304301
if(platforms.empty())
305302
{
306-
std::cerr << OUT_NAME("init") "no opencl platforms found." << std::endl;
303+
LOG_ERROR << "no opencl platforms found.";
307304
return false;
308305
}
309306

@@ -335,19 +332,19 @@ class OpenCLDepthPacketProcessorImpl
335332
default:
336333
devType = "UNKNOWN";
337334
}
338-
std::cout << OUT_NAME("init") " selected device: " << devName << " (" << devType << ")[" << devVendor << ']' << std::endl;
335+
LOG_INFO << "selected device: " << devName << " (" << devType << ")[" << devVendor << ']';
339336
}
340337
else
341338
{
342-
std::cerr << OUT_NAME("init") "could not find any suitable device" << std::endl;
339+
LOG_ERROR << "could not find any suitable device";
343340
return false;
344341
}
345342

346343
context = cl::Context(device);
347344
}
348345
catch(const cl::Error &err)
349346
{
350-
std::cerr << OUT_NAME("init") "ERROR: " << err.what() << "(" << err.err() << ")" << std::endl;
347+
LOG_ERROR << err.what() << "(" << err.err() << ")";
351348
throw;
352349
}
353350

@@ -451,7 +448,7 @@ class OpenCLDepthPacketProcessorImpl
451448
}
452449
catch(const cl::Error &err)
453450
{
454-
std::cerr << OUT_NAME("init") "ERROR: " << err.what() << "(" << err.err() << ")" << std::endl;
451+
LOG_ERROR << err.what() << "(" << err.err() << ")";
455452
throw;
456453
}
457454
programInitialized = true;
@@ -496,7 +493,7 @@ class OpenCLDepthPacketProcessorImpl
496493
}
497494
catch(const cl::Error &err)
498495
{
499-
std::cerr << OUT_NAME("run") "ERROR: " << err.what() << " (" << err.err() << ")" << std::endl;
496+
LOG_ERROR << err.what() << " (" << err.err() << ")";
500497
throw;
501498
}
502499
}
@@ -511,25 +508,25 @@ class OpenCLDepthPacketProcessorImpl
511508
{
512509
try
513510
{
514-
std::cout<< OUT_NAME("buildProgram") "building OpenCL program..." <<std::endl;
511+
LOG_INFO << "building OpenCL program...";
515512

516513
std::string options;
517514
generateOptions(options);
518515

519516
cl::Program::Sources source(1, std::make_pair(sources.c_str(), sources.length()));
520517
program = cl::Program(context, source);
521518
program.build(options.c_str());
522-
std::cout<< OUT_NAME("buildProgram") "OpenCL program built successfully" <<std::endl;
519+
LOG_INFO << "OpenCL program built successfully";
523520
}
524521
catch(const cl::Error &err)
525522
{
526-
std::cerr << OUT_NAME("buildProgram") "ERROR: " << err.what() << "(" << err.err() << ")" << std::endl;
523+
LOG_ERROR << err.what() << "(" << err.err() << ")";
527524

528525
if(err.err() == CL_BUILD_PROGRAM_FAILURE)
529526
{
530-
std::cout << OUT_NAME("buildProgram") "Build Status: " << program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(device) << std::endl;
531-
std::cout << OUT_NAME("buildProgram") "Build Options:\t" << program.getBuildInfo<CL_PROGRAM_BUILD_OPTIONS>(device) << std::endl;
532-
std::cout << OUT_NAME("buildProgram") "Build Log:\t " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device) << std::endl;
527+
LOG_ERROR << "Build Status: " << program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(device);
528+
LOG_ERROR << "Build Options:\t" << program.getBuildInfo<CL_PROGRAM_BUILD_OPTIONS>(device);
529+
LOG_ERROR << "Build Log:\t " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device);
533530
}
534531

535532
programBuilt = false;
@@ -552,7 +549,7 @@ class OpenCLDepthPacketProcessorImpl
552549
if(timing_acc_n >= 100.0)
553550
{
554551
double avg = (timing_acc / timing_acc_n);
555-
std::cout << "[OpenCLDepthPacketProcessor] avg. time: " << (avg * 1000) << "ms -> ~" << (1.0 / avg) << "Hz" << std::endl;
552+
LOG_INFO << "[OpenCLDepthPacketProcessor] avg. time: " << (avg * 1000) << "ms -> ~" << (1.0 / avg) << "Hz";
556553
timing_acc = 0.0;
557554
timing_acc_n = 0.0;
558555
}
@@ -626,7 +623,7 @@ void OpenCLDepthPacketProcessor::loadP0TablesFromCommandResponse(unsigned char *
626623

627624
if(buffer_length < sizeof(libfreenect2::protocol::P0TablesResponse))
628625
{
629-
std::cerr << OUT_NAME("loadP0TablesFromCommandResponse") "P0Table response too short!" << std::endl;
626+
LOG_ERROR << "P0Table response too short!";
630627
return;
631628
}
632629

@@ -637,23 +634,23 @@ void OpenCLDepthPacketProcessor::loadXTableFromFile(const char *filename)
637634
{
638635
if(!loadBufferFromResources(filename, (unsigned char *)impl_->x_table, impl_->image_size * sizeof(float)))
639636
{
640-
std::cerr << OUT_NAME("loadXTableFromFile") "could not load x table from: " << filename << std::endl;
637+
LOG_ERROR << "could not load x table from: " << filename;
641638
}
642639
}
643640

644641
void OpenCLDepthPacketProcessor::loadZTableFromFile(const char *filename)
645642
{
646643
if(!loadBufferFromResources(filename, (unsigned char *)impl_->z_table, impl_->image_size * sizeof(float)))
647644
{
648-
std::cerr << OUT_NAME("loadZTableFromFile") "could not load z table from: " << filename << std::endl;
645+
LOG_ERROR << "could not load z table from: " << filename;
649646
}
650647
}
651648

652649
void OpenCLDepthPacketProcessor::load11To16LutFromFile(const char *filename)
653650
{
654651
if(!loadBufferFromResources(filename, (unsigned char *)impl_->lut11to16, 2048 * sizeof(cl_ushort)))
655652
{
656-
std::cerr << OUT_NAME("load11To16LutFromFile") "could not load lut table from: " << filename << std::endl;
653+
LOG_ERROR << "could not load lut table from: " << filename;
657654
}
658655
}
659656

@@ -663,7 +660,7 @@ void OpenCLDepthPacketProcessor::process(const DepthPacket &packet)
663660

664661
if(!impl_->programInitialized && !impl_->initProgram())
665662
{
666-
std::cerr << OUT_NAME("process") "could not initialize OpenCLDepthPacketProcessor" << std::endl;
663+
LOG_ERROR << "could not initialize OpenCLDepthPacketProcessor";
667664
return;
668665
}
669666

0 commit comments

Comments
 (0)