SensorData's isValid() method checks whether camera models are valid (#1769)

* SensorData's isValid() method checks whether camera models are valid

* Added tests and doc

---------

Co-authored-by: matlabbe <[email protected]>
This commit is contained in:
Borong Yuan
2026-09-28 09:22:24 -07:00
committed by GitHub
co-authored by matlabbe
parent 1088df9a7f
commit b03344842e
2 changed files with 51 additions and 7 deletions
+17 -6
View File
@@ -470,21 +470,33 @@ public:
* @brief Checks if the sensor data is valid
*
* Returns true if the sensor data contains at least one of:
* - Valid ID (> 0) or non-zero stamp
* - Valid ID (> 0)
* - Images (raw or compressed)
* - Depth/right images (raw or compressed)
* - Depth confidence (raw or compressed)
* - Laser scan (raw or compressed)
* - Camera models (mono or stereo)
* - Camera models (mono or stereo), at least one valid for projection
* (see CameraModel::isValidForProjection() and StereoCameraModel::isValidForProjection())
* - User data (raw or compressed)
* - Keypoints and descriptors
* - Occupancy grid cells (ground, obstacles or empty)
* - IMU data
*
*
* @note The stamp is not considered: a SensorData with only a stamp set is not valid
* (e.g., an empty message converted from ROS still has its header stamp
* and a camera model created from an empty camera info).
*
* @return True if the sensor data contains any valid information, false otherwise
*/
bool isValid() const {
bool hasCameraModel = false;
for (size_t i=0; i < _cameraModels.size() && !hasCameraModel; ++i)
hasCameraModel = _cameraModels[i].isValidForProjection();
if (!hasCameraModel)
for (size_t i=0; i < _stereoCameraModels.size() && !hasCameraModel; ++i)
hasCameraModel = _stereoCameraModels[i].isValidForProjection();
return !(_id == 0 &&
_stamp == 0.0 &&
_imageRaw.empty() &&
_imageCompressed.empty() &&
_depthOrRightRaw.empty() &&
@@ -493,8 +505,7 @@ public:
_depthConfidenceCompressed.empty() &&
_laserScanRaw.isEmpty() &&
_laserScanCompressed.isEmpty() &&
_cameraModels.empty() &&
_stereoCameraModels.empty() &&
!hasCameraModel &&
_userDataRaw.empty() &&
_userDataCompressed.empty() &&
_keypoints.size() == 0 &&