Azure-Kinect-Sensor-SDK icon indicating copy to clipboard operation
Azure-Kinect-Sensor-SDK copied to clipboard

is_valid(), operator bool(), handle() missing on C++ classes

Open diablodale opened this issue 4 years ago • 0 comments

I request boolean tests for validity for k4a::calibration and k4a::transformation. Those tests areoperator bool() and bool is_valid() This will align those classes with the already existing validity tests on device, capture, and image; and remove the need for project-specific boilerplate code for users of this SDK.

I also request handle() added to k4a::transformation. It is missing as compared to the others that manage handles.

Some discussion points:

  1. The validity test/condition for each class.
  2. Consider that k4a::calibration has no constructor like the others. Therefore, the in-memory state is different between k4a::calibration cali; and k4a::calibration cali{};. I lean towards defining a k4a::calibration() constructor that specifically sets member variables to a known invalid state (rather than leaving them random bits leftover in memory).

Below are pseudocode suggestions.

k4a::calibration

calibration() noexcept : depth_mode(K4A_DEPTH_MODE_OFF), color_resolution(K4A_COLOR_RESOLUTION_OFF) {}

bool is_valid() {
    return (depth_mode != K4A_DEPTH_MODE_OFF) || (color_resolution != K4A_COLOR_RESOLUTION_OFF);
}

explicit operator bool() const noexcept {
    return is_valid();
}

k4a::transformation

bool is_valid() {
    return m_handle != nullptr;
}

explicit operator bool() const noexcept {
    return is_valid();
}

k4a_transformation_t handle() const noexcept {
    return m_handle;
}

diablodale avatar Jul 01 '20 18:07 diablodale