Skip to content

Commit 25bf58a

Browse files
committed
Merge pull request #476 from xlz/api-cleanup
API cleanup/refactoring
2 parents ded1d31 + 611dae4 commit 25bf58a

File tree

12 files changed

+174
-138
lines changed

12 files changed

+174
-138
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ SET(SOURCES
9393
include/internal/libfreenect2/logging.h
9494

9595
include/internal/libfreenect2/async_packet_processor.h
96-
include/libfreenect2/depth_packet_processor.h
96+
include/internal/libfreenect2/depth_packet_processor.h
9797
include/internal/libfreenect2/depth_packet_stream_parser.h
9898
include/internal/libfreenect2/double_buffer.h
9999
include/libfreenect2/frame_listener.hpp
100100
include/libfreenect2/frame_listener_impl.h
101101
include/libfreenect2/libfreenect2.hpp
102102
include/libfreenect2/packet_pipeline.h
103-
include/libfreenect2/packet_processor.h
103+
include/internal/libfreenect2/packet_processor.h
104104
include/libfreenect2/registration.h
105105
include/internal/libfreenect2/resource.h
106-
include/libfreenect2/rgb_packet_processor.h
106+
include/internal/libfreenect2/rgb_packet_processor.h
107107
include/internal/libfreenect2/rgb_packet_stream_parser.h
108108
include/internal/libfreenect2/threading.h
109109

freenect2.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ FIND_PATH(freenect2_INCLUDE_DIR @PROJECT_NAME@/libfreenect2.hpp
77
PATHS @CMAKE_INSTALL_PREFIX@/include
88
NO_DEFAULT_PATH
99
)
10+
SET(freenect2_INCLUDE_DIRS ${freenect2_INCLUDE_DIR})

include/libfreenect2/depth_packet_processor.h renamed to include/internal/libfreenect2/depth_packet_processor.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@
3333
#include <stdint.h>
3434

3535
#include <libfreenect2/config.h>
36+
#define LIBFREENECT2_SETCONFIGURATION_COMPAT_INTERNAL
37+
#include <libfreenect2/libfreenect2.hpp>
3638
#include <libfreenect2/frame_listener.hpp>
3739
#include <libfreenect2/packet_processor.h>
3840

3941
namespace libfreenect2
4042
{
4143

4244
/** Data packet with depth information. */
43-
struct LIBFREENECT2_API DepthPacket
45+
struct DepthPacket
4446
{
4547
uint32_t sequence;
4648
uint32_t timestamp;
@@ -51,23 +53,13 @@ struct LIBFREENECT2_API DepthPacket
5153
/** Class for processing depth information. */
5254
typedef PacketProcessor<DepthPacket> BaseDepthPacketProcessor;
5355

54-
class LIBFREENECT2_API DepthPacketProcessor : public BaseDepthPacketProcessor
56+
class DepthPacketProcessor : public ConfigPacketProcessor, public BaseDepthPacketProcessor
5557
{
5658
public:
57-
/** Configuration of depth processing. */
58-
struct LIBFREENECT2_API Config
59-
{
60-
float MinDepth;
61-
float MaxDepth;
62-
63-
bool EnableBilateralFilter; ///< Whether to run the bilateral filter.
64-
bool EnableEdgeAwareFilter; ///< Whether to run the edge aware filter.
65-
66-
Config();
67-
};
59+
typedef Freenect2Device::Config Config;
6860

6961
/** Parameters of depth processing. */
70-
struct LIBFREENECT2_API Parameters
62+
struct Parameters
7163
{
7264
float ab_multiplier;
7365
float ab_multiplier_per_frq[3];
@@ -125,7 +117,7 @@ class LIBFREENECT2_API DepthPacketProcessor : public BaseDepthPacketProcessor
125117
class OpenGLDepthPacketProcessorImpl;
126118

127119
/** Depth packet processor using OpenGL. */
128-
class LIBFREENECT2_API OpenGLDepthPacketProcessor : public DepthPacketProcessor
120+
class OpenGLDepthPacketProcessor : public DepthPacketProcessor
129121
{
130122
public:
131123
OpenGLDepthPacketProcessor(void *parent_opengl_context_ptr, bool debug);
@@ -147,7 +139,7 @@ class LIBFREENECT2_API OpenGLDepthPacketProcessor : public DepthPacketProcessor
147139
class CpuDepthPacketProcessorImpl;
148140

149141
/** Depth packet processor using the CPU. */
150-
class LIBFREENECT2_API CpuDepthPacketProcessor : public DepthPacketProcessor
142+
class CpuDepthPacketProcessor : public DepthPacketProcessor
151143
{
152144
public:
153145
CpuDepthPacketProcessor();
@@ -168,7 +160,7 @@ class LIBFREENECT2_API CpuDepthPacketProcessor : public DepthPacketProcessor
168160
class OpenCLDepthPacketProcessorImpl;
169161

170162
/** Depth packet processor using OpenCL. */
171-
class LIBFREENECT2_API OpenCLDepthPacketProcessor : public DepthPacketProcessor
163+
class OpenCLDepthPacketProcessor : public DepthPacketProcessor
172164
{
173165
public:
174166
OpenCLDepthPacketProcessor(const int deviceId = -1);
File renamed without changes.

include/libfreenect2/rgb_packet_processor.h renamed to include/internal/libfreenect2/rgb_packet_processor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace libfreenect2
4040
{
4141

4242
/** Packet with JPEG data. */
43-
struct LIBFREENECT2_API RgbPacket
43+
struct RgbPacket
4444
{
4545
uint32_t sequence;
4646

@@ -56,7 +56,7 @@ struct LIBFREENECT2_API RgbPacket
5656
typedef PacketProcessor<RgbPacket> BaseRgbPacketProcessor;
5757

5858
/** JPEG processor. */
59-
class LIBFREENECT2_API RgbPacketProcessor : public BaseRgbPacketProcessor
59+
class RgbPacketProcessor : public BaseRgbPacketProcessor
6060
{
6161
public:
6262
RgbPacketProcessor();
@@ -68,7 +68,7 @@ class LIBFREENECT2_API RgbPacketProcessor : public BaseRgbPacketProcessor
6868
};
6969

7070
/** Class for dumping the JPEG information, eg to file. */
71-
class LIBFREENECT2_API DumpRgbPacketProcessor : public RgbPacketProcessor
71+
class DumpRgbPacketProcessor : public RgbPacketProcessor
7272
{
7373
public:
7474
DumpRgbPacketProcessor();
@@ -80,7 +80,7 @@ class LIBFREENECT2_API DumpRgbPacketProcessor : public RgbPacketProcessor
8080
class TurboJpegRgbPacketProcessorImpl;
8181

8282
/** Processor to decode JPEG to image, using TurboJpeg. */
83-
class LIBFREENECT2_API TurboJpegRgbPacketProcessor : public RgbPacketProcessor
83+
class TurboJpegRgbPacketProcessor : public RgbPacketProcessor
8484
{
8585
public:
8686
TurboJpegRgbPacketProcessor();

include/libfreenect2/libfreenect2.hpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131

3232
#include <libfreenect2/config.h>
3333
#include <libfreenect2/frame_listener.hpp>
34+
#include <libfreenect2/packet_pipeline.h>
3435
#include <string>
3536

3637
namespace libfreenect2
3738
{
3839

39-
class PacketPipeline;
40-
4140
/** Device class. */
4241
class LIBFREENECT2_API Freenect2Device
4342
{
@@ -82,6 +81,18 @@ class LIBFREENECT2_API Freenect2Device
8281
float fx, fy, cx, cy, k1, k2, k3, p1, p2;
8382
};
8483

84+
/** Configuration of depth processing. */
85+
struct Config
86+
{
87+
float MinDepth;
88+
float MaxDepth;
89+
90+
bool EnableBilateralFilter; ///< Whether to run the bilateral filter.
91+
bool EnableEdgeAwareFilter; ///< Whether to run the edge aware filter.
92+
93+
Config();
94+
};
95+
8596
virtual ~Freenect2Device();
8697

8798
virtual std::string getSerialNumber() = 0;
@@ -91,6 +102,7 @@ class LIBFREENECT2_API Freenect2Device
91102
virtual Freenect2Device::IrCameraParams getIrCameraParams() = 0;
92103
virtual void setColorCameraParams(const Freenect2Device::ColorCameraParams &params) = 0;
93104
virtual void setIrCameraParams(const Freenect2Device::IrCameraParams &params) = 0;
105+
virtual void setConfiguration(const Config &config) = 0;
94106

95107
virtual void setColorFrameListener(libfreenect2::FrameListener* rgb_frame_listener) = 0;
96108
virtual void setIrAndDepthFrameListener(libfreenect2::FrameListener* ir_frame_listener) = 0;
@@ -100,6 +112,15 @@ class LIBFREENECT2_API Freenect2Device
100112
virtual void close() = 0;
101113
};
102114

115+
/** @deprecated Use Freenect2Device::setConfiguration() instead.
116+
*/
117+
class ConfigPacketProcessor
118+
{
119+
public:
120+
typedef Freenect2Device::Config Config;
121+
LIBFREENECT2_DEPRECATED virtual void setConfiguration(const Config &config) = 0;
122+
};
123+
103124
class Freenect2Impl;
104125

105126
/**
@@ -128,8 +149,6 @@ class LIBFREENECT2_API Freenect2
128149

129150
Freenect2Device *openDefaultDevice();
130151
Freenect2Device *openDefaultDevice(const PacketPipeline *factory);
131-
protected:
132-
Freenect2Device *openDevice(int idx, const PacketPipeline *factory, bool attempting_reset);
133152
private:
134153
Freenect2Impl *impl_;
135154
};

include/libfreenect2/packet_pipeline.h

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,73 +30,53 @@
3030
#define PACKET_PIPELINE_H_
3131

3232
#include <libfreenect2/config.h>
33-
#include <libfreenect2/depth_packet_processor.h>
34-
#include <libfreenect2/rgb_packet_processor.h>
3533

3634
namespace libfreenect2
3735
{
3836

3937
class DataCallback;
38+
class RgbPacketProcessor;
39+
class DepthPacketProcessor;
40+
class PacketPipelineComponents;
4041

41-
/** Packet pipeline for data processing of the device. */
42+
class ConfigPacketProcessor;
43+
#ifndef LIBFREENECT2_SETCONFIGURATION_COMPAT_INTERNAL
44+
#define DepthPacketProcessor ConfigPacketProcessor
45+
#endif
46+
47+
/** Front of the pipeline, RGB and Depth parsing and processing. */
4248
class LIBFREENECT2_API PacketPipeline
4349
{
4450
public:
4551
typedef DataCallback PacketParser;
46-
virtual ~PacketPipeline();
47-
48-
virtual PacketParser *getRgbPacketParser() const = 0;
49-
virtual PacketParser *getIrPacketParser() const = 0;
50-
51-
virtual RgbPacketProcessor *getRgbPacketProcessor() const = 0;
52-
virtual DepthPacketProcessor *getDepthPacketProcessor() const = 0;
53-
};
54-
55-
class RgbPacketStreamParser;
56-
class DepthPacketStreamParser;
57-
58-
/** Front of the pipeline, RGB and Depth parsing and processing. */
59-
class LIBFREENECT2_API BasePacketPipeline : public PacketPipeline
60-
{
61-
protected:
62-
RgbPacketStreamParser *rgb_parser_;
63-
DepthPacketStreamParser *depth_parser_;
64-
65-
RgbPacketProcessor *rgb_processor_;
66-
BaseRgbPacketProcessor *async_rgb_processor_;
67-
DepthPacketProcessor *depth_processor_;
68-
BaseDepthPacketProcessor *async_depth_processor_;
6952

70-
virtual void initialize();
71-
virtual DepthPacketProcessor *createDepthPacketProcessor() = 0;
72-
public:
73-
virtual ~BasePacketPipeline();
53+
PacketPipeline();
54+
virtual ~PacketPipeline();
7455

7556
virtual PacketParser *getRgbPacketParser() const;
7657
virtual PacketParser *getIrPacketParser() const;
7758

7859
virtual RgbPacketProcessor *getRgbPacketProcessor() const;
7960
virtual DepthPacketProcessor *getDepthPacketProcessor() const;
61+
protected:
62+
PacketPipelineComponents *comp_;
8063
};
8164

8265
/** Complete pipe line with depth processing by the CPU. */
83-
class LIBFREENECT2_API CpuPacketPipeline : public BasePacketPipeline
66+
class LIBFREENECT2_API CpuPacketPipeline : public PacketPipeline
8467
{
85-
protected:
86-
virtual DepthPacketProcessor *createDepthPacketProcessor();
8768
public:
8869
CpuPacketPipeline();
8970
virtual ~CpuPacketPipeline();
9071
};
9172

9273
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
9374
/** Complete pipe line with depth processing with OpenGL. */
94-
class LIBFREENECT2_API OpenGLPacketPipeline : public BasePacketPipeline
75+
class LIBFREENECT2_API OpenGLPacketPipeline : public PacketPipeline
9576
{
9677
protected:
9778
void *parent_opengl_context_;
9879
bool debug_;
99-
virtual DepthPacketProcessor *createDepthPacketProcessor();
10080
public:
10181
OpenGLPacketPipeline(void *parent_opengl_context = 0, bool debug = false);
10282
virtual ~OpenGLPacketPipeline();
@@ -105,11 +85,10 @@ class LIBFREENECT2_API OpenGLPacketPipeline : public BasePacketPipeline
10585

10686
#ifdef LIBFREENECT2_WITH_OPENCL_SUPPORT
10787
/** Complete pipe line with depth processing with OpenCL. */
108-
class LIBFREENECT2_API OpenCLPacketPipeline : public BasePacketPipeline
88+
class LIBFREENECT2_API OpenCLPacketPipeline : public PacketPipeline
10989
{
11090
protected:
11191
const int deviceId;
112-
virtual DepthPacketProcessor *createDepthPacketProcessor();
11392
public:
11493
OpenCLPacketPipeline(const int deviceId = -1);
11594
virtual ~OpenCLPacketPipeline();

include/libfreenect2/registration.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@
3737
namespace libfreenect2
3838
{
3939

40+
class RegistrationImpl;
41+
4042
/** Combine frames of depth and color camera. */
4143
class LIBFREENECT2_API Registration
4244
{
4345
public:
4446
Registration(Freenect2Device::IrCameraParams depth_p, Freenect2Device::ColorCameraParams rgb_p);
47+
~Registration();
4548

4649
// undistort/register a single depth data point
4750
void apply(int dx, int dy, float dz, float& cx, float &cy) const;
@@ -53,20 +56,7 @@ class LIBFREENECT2_API Registration
5356
void getPointXYZRGB (const Frame* undistorted, const Frame* registered, int r, int c, float& x, float& y, float& z, float& rgb) const;
5457

5558
private:
56-
void distort(int mx, int my, float& dx, float& dy) const;
57-
void depth_to_color(float mx, float my, float& rx, float& ry) const;
58-
59-
Freenect2Device::IrCameraParams depth; ///< Depth camera parameters.
60-
Freenect2Device::ColorCameraParams color; ///< Color camera parameters.
61-
62-
int distort_map[512 * 424];
63-
float depth_to_color_map_x[512 * 424];
64-
float depth_to_color_map_y[512 * 424];
65-
int depth_to_color_map_yi[512 * 424];
66-
67-
const int filter_width_half;
68-
const int filter_height_half;
69-
const float filter_tolerance;
59+
RegistrationImpl *impl_;
7060
};
7161

7262
} /* namespace libfreenect2 */

src/depth_packet_processor.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@
3232
namespace libfreenect2
3333
{
3434

35-
DepthPacketProcessor::Config::Config() :
36-
MinDepth(0.5f),
37-
MaxDepth(4.5f),
38-
EnableBilateralFilter(true),
39-
EnableEdgeAwareFilter(true)
40-
{
41-
42-
}
43-
4435
DepthPacketProcessor::Parameters::Parameters()
4536
{
4637
ab_multiplier = 0.6666667f;

0 commit comments

Comments
 (0)