Skip to content

Commit 5c1eb71

Browse files
committed
Use constexpr where appropriate
Fixes #470 Signed-off-by: Benn Snyder <[email protected]>
1 parent afcc53d commit 5c1eb71

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

OpenNI2-FreenectDriver/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# OpenNI2-FreenectDriver
33
######################################################################################
44

5+
cmake_minimum_required(VERSION 3.1.0)
6+
57
file(GLOB HEADERS src/*.hpp src/*.h)
68
file(GLOB SOURCES src/*.cpp)
79
add_library(FreenectDriver SHARED ${HEADERS} ${SOURCES})
@@ -20,6 +22,8 @@ include_directories(extern/OpenNI-Linux-x64-2.2.0.33/Include)
2022
include_directories(${PROJECT_SOURCE_DIR}/src)
2123
include_directories(${PROJECT_SOURCE_DIR}/wrappers/cpp)
2224

25+
target_compile_features(FreenectDriver PUBLIC cxx_constexpr)
26+
2327
target_link_libraries(FreenectDriver freenectstatic ${MATH_LIB})
2428

2529
install (TARGETS FreenectDriver

OpenNI2-FreenectDriver/src/ColorStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ OniStatus ColorStream::setVideoMode(OniVideoMode requested_mode)
5050

5151
void ColorStream::populateFrame(void* data, OniFrame* frame) const
5252
{
53-
frame->sensorType = sensor_type;
53+
frame->sensorType = SENSOR_TYPE;
5454
frame->stride = video_mode.resolutionX * 3;
5555
frame->cropOriginX = 0;
5656
frame->cropOriginY = 0;

OpenNI2-FreenectDriver/src/ColorStream.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace FreenectDriver
1212
class ColorStream : public VideoStream
1313
{
1414
public:
15+
static constexpr OniSensorType SENSOR_TYPE = ONI_SENSOR_COLOR;
1516
// from NUI library & converted to radians
16-
static const float DIAGONAL_FOV = 73.9 * (M_PI / 180);
17-
static const float HORIZONTAL_FOV = 62 * (M_PI / 180);
18-
static const float VERTICAL_FOV = 48.6 * (M_PI / 180);
17+
static constexpr float DIAGONAL_FOV = 73.9 * (M_PI / 180);
18+
static constexpr float HORIZONTAL_FOV = 62 * (M_PI / 180);
19+
static constexpr float VERTICAL_FOV = 48.6 * (M_PI / 180);
1920

2021
private:
2122
typedef std::map< OniVideoMode, std::pair<freenect_video_format, freenect_resolution> > FreenectVideoModeMap;
22-
static const OniSensorType sensor_type = ONI_SENSOR_COLOR;
2323

2424
static FreenectVideoModeMap getSupportedVideoModes();
2525
OniStatus setVideoMode(OniVideoMode requested_mode);
@@ -37,7 +37,7 @@ namespace FreenectDriver
3737
FreenectVideoModeMap supported_modes = getSupportedVideoModes();
3838
OniVideoMode* modes = new OniVideoMode[supported_modes.size()];
3939
std::transform(supported_modes.begin(), supported_modes.end(), modes, ExtractKey());
40-
OniSensorInfo sensors = { sensor_type, static_cast<int>(supported_modes.size()), modes };
40+
OniSensorInfo sensors = { SENSOR_TYPE, static_cast<int>(supported_modes.size()), modes };
4141
return sensors;
4242
}
4343

OpenNI2-FreenectDriver/src/DepthStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ OniStatus DepthStream::setVideoMode(OniVideoMode requested_mode)
5555

5656
void DepthStream::populateFrame(void* data, OniFrame* frame) const
5757
{
58-
frame->sensorType = sensor_type;
58+
frame->sensorType = SENSOR_TYPE;
5959
frame->stride = video_mode.resolutionX * sizeof(uint16_t);
6060

6161
if (cropping.enabled)

OpenNI2-FreenectDriver/src/DepthStream.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ namespace FreenectDriver
1616
class DepthStream : public VideoStream
1717
{
1818
public:
19+
static constexpr OniSensorType SENSOR_TYPE = ONI_SENSOR_DEPTH;
1920
// from NUI library and converted to radians
20-
static const float DIAGONAL_FOV = 70 * (M_PI / 180);
21-
static const float HORIZONTAL_FOV = 58.5 * (M_PI / 180);
22-
static const float VERTICAL_FOV = 45.6 * (M_PI / 180);
21+
static constexpr float DIAGONAL_FOV = 70 * (M_PI / 180);
22+
static constexpr float HORIZONTAL_FOV = 58.5 * (M_PI / 180);
23+
static constexpr float VERTICAL_FOV = 45.6 * (M_PI / 180);
2324
// from DepthKinectStream.cpp
24-
static const int MAX_VALUE = 10000;
25-
static const unsigned long long GAIN_VAL = 42;
26-
static const unsigned long long CONST_SHIFT_VAL = 200;
27-
static const unsigned long long MAX_SHIFT_VAL = 2047;
28-
static const unsigned long long PARAM_COEFF_VAL = 4;
29-
static const unsigned long long SHIFT_SCALE_VAL = 10;
30-
static const unsigned long long ZERO_PLANE_DISTANCE_VAL = 120;
31-
static const double ZERO_PLANE_PIXEL_SIZE_VAL = 0.10520000010728836;
32-
static const double EMITTER_DCMOS_DISTANCE_VAL = 7.5;
25+
static constexpr int MAX_VALUE = 10000;
26+
static constexpr unsigned long long GAIN_VAL = 42;
27+
static constexpr unsigned long long CONST_SHIFT_VAL = 200;
28+
static constexpr unsigned long long MAX_SHIFT_VAL = 2047;
29+
static constexpr unsigned long long PARAM_COEFF_VAL = 4;
30+
static constexpr unsigned long long SHIFT_SCALE_VAL = 10;
31+
static constexpr unsigned long long ZERO_PLANE_DISTANCE_VAL = 120;
32+
static constexpr double ZERO_PLANE_PIXEL_SIZE_VAL = 0.10520000010728836;
33+
static constexpr double EMITTER_DCMOS_DISTANCE_VAL = 7.5;
3334

3435
private:
3536
typedef std::map< OniVideoMode, std::pair<freenect_depth_format, freenect_resolution> > FreenectDepthModeMap;
36-
static const OniSensorType sensor_type = ONI_SENSOR_DEPTH;
3737
OniImageRegistrationMode image_registration_mode;
3838

3939
static FreenectDepthModeMap getSupportedVideoModes();
@@ -49,7 +49,7 @@ namespace FreenectDriver
4949
FreenectDepthModeMap supported_modes = getSupportedVideoModes();
5050
OniVideoMode* modes = new OniVideoMode[supported_modes.size()];
5151
std::transform(supported_modes.begin(), supported_modes.end(), modes, ExtractKey());
52-
OniSensorInfo sensors = { sensor_type, static_cast<int>(supported_modes.size()), modes };
52+
OniSensorInfo sensors = { SENSOR_TYPE, static_cast<int>(supported_modes.size()), modes };
5353
return sensors;
5454
}
5555

OpenNI2-FreenectDriver/src/DeviceDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ namespace FreenectDriver
218218
return "freenect://" + to_string(id);
219219
}
220220

221-
static int uri_to_devid(const std::string uri) {
221+
static int uri_to_devid(const std::string& uri) {
222222
int id;
223223
std::istringstream is(uri);
224224
is.seekg(strlen("freenect://"));

OpenNI2-FreenectDriver/src/VideoStream.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace FreenectDriver
1717
virtual void populateFrame(void* data, OniFrame* frame) const = 0;
1818

1919
protected:
20-
static const OniSensorType sensor_type;
2120
Freenect::FreenectDevice* device;
2221
bool running; // buildFrame() does something iff true
2322
OniVideoMode video_mode;

0 commit comments

Comments
 (0)