Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check camera sensors have non-zero width or height (backport #480) #482

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/BoundingBoxCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ bool BoundingBoxCameraSensor::CreateCamera()
auto width = sdfCamera->ImageWidth();
auto height = sdfCamera->ImageHeight();

if (width == 0u || height == 0u)
{
gzerr << "Unable to create a bounding box camera sensor with 0 width or "
<< "height. " << std::endl;
return false;
}

// Set Camera Properties
this->dataPtr->rgbCamera->SetImageFormat(rendering::PF_R8G8B8);
this->dataPtr->rgbCamera->SetImageWidth(width);
Expand Down
7 changes: 7 additions & 0 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ bool CameraSensor::CreateCamera()
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
gzerr << "Unable to create a camera sensor with 0 width or height."
<< std::endl;
return false;
}

this->dataPtr->camera = this->Scene()->CreateCamera(this->Name());
this->dataPtr->camera->SetImageWidth(width);
this->dataPtr->camera->SetImageHeight(height);
Expand Down
11 changes: 9 additions & 2 deletions src/DepthCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,15 @@ bool DepthCameraSensor::CreateCamera()
return false;
}

int width = cameraSdf->ImageWidth();
int height = cameraSdf->ImageHeight();
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
gzerr << "Unable to create a depth camera sensor with 0 width or height."
<< std::endl;
return false;
}

double far = cameraSdf->FarClip();
double near = cameraSdf->NearClip();
Expand Down
11 changes: 9 additions & 2 deletions src/RgbdCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,15 @@ bool RgbdCameraSensor::CreateCameras()

this->PopulateInfo(cameraSdf);

int width = cameraSdf->ImageWidth();
int height = cameraSdf->ImageHeight();
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
gzerr << "Unable to create an RGBD camera sensor with 0 width or height."
<< std::endl;
return false;
}

this->dataPtr->depthCamera =
this->Scene()->CreateDepthCamera(this->Name());
Expand Down
7 changes: 7 additions & 0 deletions src/SegmentationCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ bool SegmentationCameraSensor::CreateCamera()
auto width = sdfCamera->ImageWidth();
auto height = sdfCamera->ImageHeight();

if (width == 0u || height == 0u)
{
gzerr << "Unable to create a segmentation camera sensor with 0 width or "
<< "height." << std::endl;
return false;
}

math::Angle angle = sdfCamera->HorizontalFov();
if (angle < 0.01 || angle > GZ_PI*2)
{
Expand Down
11 changes: 9 additions & 2 deletions src/ThermalCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,15 @@ bool ThermalCameraSensor::CreateCamera()
return false;
}

int width = cameraSdf->ImageWidth();
int height = cameraSdf->ImageHeight();
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
gzerr << "Unable to create a thermal camera sensor with 0 width or height."
<< std::endl;
return false;
}

sdf::PixelFormatType pixelFormat = cameraSdf->PixelFormat();

Expand Down
7 changes: 7 additions & 0 deletions src/WideAngleCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ bool WideAngleCameraSensor::CreateCamera()
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
gzerr << "Unable to create a wide angle camera sensor with 0 width or "
<< "height." << std::endl;
return false;
}

this->dataPtr->camera = this->Scene()->CreateWideAngleCamera(this->Name());

if (!this->dataPtr->camera)
Expand Down