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

Backport rendering test fixes from fortress to citadel #397

Merged
merged 2 commits into from
Oct 16, 2023
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
9 changes: 9 additions & 0 deletions src/RenderingSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ RenderingSensor::RenderingSensor() :
//////////////////////////////////////////////////
RenderingSensor::~RenderingSensor()
{
if (!this->dataPtr->scene || !this->dataPtr->scene->IsInitialized())
return;
for (auto &s : this->dataPtr->sensors)
{
auto sensor = s.lock();
if (sensor)
this->dataPtr->scene->DestroySensor(sensor);
}
this->dataPtr->sensors.clear();
}

/////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions test/integration/camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ void CameraSensorTest::ImagesWithBuiltinSDF(const std::string &_renderEngine)
EXPECT_DOUBLE_EQ(0.0, projection.p(11));
}

// test removing sensor
// first make sure the sensor objects do exist
auto sensorId = sensor->Id();
auto cameraId = sensor->RenderingCamera()->Id();
EXPECT_EQ(sensor, mgr.Sensor(sensorId));
EXPECT_EQ(sensor->RenderingCamera(), scene->SensorById(cameraId));
// remove and check sensor objects no longer exist in both sensors and
// rendering
EXPECT_TRUE(mgr.Remove(sensorId));
EXPECT_EQ(nullptr, mgr.Sensor(sensorId));
EXPECT_EQ(nullptr, scene->SensorById(cameraId));

// Clean up
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
Expand Down
12 changes: 6 additions & 6 deletions test/integration/depth_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
box->SetLocalRotation(0, 0, 0);
box->SetLocalScale(unitBoxSize, unitBoxSize, unitBoxSize);
box->SetMaterial(blue);
scene->DestroyMaterial(blue);
root->AddChild(box);

// do the test
Expand Down Expand Up @@ -333,11 +334,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
EXPECT_EQ(9, infoMsg.rectification_matrix().size());

// Check that for a box really close it returns -inf
root->RemoveChild(box);
gz::math::Vector3d boxPositionNear(
unitBoxSize * 0.5 + near_ * 0.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionNear);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -369,11 +368,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
g_mutex.unlock();

// Check that for a box really far it returns inf
root->RemoveChild(box);
gz::math::Vector3d boxPositionFar(
unitBoxSize * 0.5 + far_ * 1.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionFar);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -405,11 +402,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(


// Check that the depth values for a box do not warp.
root->RemoveChild(box);
gz::math::Vector3d boxPositionFillFrame(
unitBoxSize * 0.5 + 0.2, 0.0, 0.0);
box->SetLocalPosition(boxPositionFillFrame);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -494,7 +489,12 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
g_mutex.unlock();
g_pcMutex.unlock();

// clean up rendering ptrs
blue.reset();
box.reset();

// Clean up
mgr.Remove(depthSensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down
24 changes: 21 additions & 3 deletions test/integration/gpu_lidar_sensor_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ void GpuLidarSensorTest::CreateGpuLidar(const std::string &_renderEngine)

// Clean up
c.reset();
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -414,8 +415,11 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine)
EXPECT_TRUE(pointMsgs.back().is_dense());
EXPECT_EQ(32u * horzSamples * vertSamples, pointMsgs.back().data().size());

// Clean up rendering ptrs
visualBox1.reset();

// Clean up
//
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -567,7 +571,14 @@ void GpuLidarSensorTest::TestThreeBoxes(const std::string &_renderEngine)
for (unsigned int i = 0; i < sensor1->RayCount(); ++i)
EXPECT_DOUBLE_EQ(sensor2->Range(i), gz::math::INF_D);

// Clean up rendering ptrs
visualBox1.reset();
visualBox2.reset();
visualBox3.reset();

// Clean up
mgr.Remove(sensor1->Id());
mgr.Remove(sensor2->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -687,7 +698,11 @@ void GpuLidarSensorTest::VerticalLidar(const std::string &_renderEngine)
}
}

// Clean up rendering ptrs
visualBox1.reset();

// Clean up
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -809,8 +824,12 @@ void GpuLidarSensorTest::ManualUpdate(const std::string &_renderEngine)
EXPECT_DOUBLE_EQ(sensor2->Range(last), gz::math::INF_D);
#endif

// Clean up rendering ptrs
visualBox1.reset();

// Clean up
//
mgr.Remove(sensor1->Id());
mgr.Remove(sensor2->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -849,7 +868,6 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine)
// Create a GpuLidarSensor
gz::sensors::Manager mgr;


// Default topic
{
const std::string topic;
Expand Down
10 changes: 6 additions & 4 deletions test/integration/rgbd_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
box->SetLocalRotation(0, 0, 0);
box->SetLocalScale(unitBoxSize, unitBoxSize, unitBoxSize);
box->SetMaterial(blue);
scene->DestroyMaterial(blue);
root->AddChild(box);

// do the test
Expand Down Expand Up @@ -526,11 +527,9 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
g_imgMutex.unlock();

// Check that for a box really close it returns -inf
root->RemoveChild(box);
math::Vector3d boxPositionNear(
unitBoxSize * 0.5 + near_ * 0.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionNear);
root->AddChild(box);

mgr.RunOnce(common::Time::Zero, true);
for (int sleep = 0; sleep < 300 &&
Expand Down Expand Up @@ -632,11 +631,9 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
g_pcMutex.unlock();

// Check that for a box really far it returns inf
root->RemoveChild(box);
math::Vector3d boxPositionFar(
unitBoxSize * 0.5 + far_ * 1.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionFar);
root->AddChild(box);

mgr.RunOnce(common::Time::Zero, true);
for (int sleep = 0; sleep < 300 &&
Expand Down Expand Up @@ -737,7 +734,12 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
g_imgMutex.unlock();
g_pcMutex.unlock();

// Clean up rendering ptrs
box.reset();
blue.reset();

// Clean up
mgr.Remove(rgbdSensor->Id());
engine->DestroyScene(scene);
rendering::unloadEngine(engine->Name());
}
Expand Down
10 changes: 6 additions & 4 deletions test/integration/thermal_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,9 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
EXPECT_EQ(9, infoMsg.rectification_matrix().size());

// Check that for a box really close it returns box temperature
root->RemoveChild(box);
gz::math::Vector3d boxPositionNear(
unitBoxSize * 0.5 + near_ * 0.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionNear);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -296,11 +294,9 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
g_mutex.unlock();

// Check that for a box really far it returns ambient temperature
root->RemoveChild(box);
gz::math::Vector3d boxPositionFar(
unitBoxSize * 0.5 + far_ * 1.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionFar);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -329,8 +325,14 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
g_infoMutex.unlock();
g_mutex.unlock();

delete [] g_thermalBuffer;
g_thermalBuffer = nullptr;

// Clean up rendering ptrs
box.reset();

// Clean up
mgr.Remove(thermalSensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down
Loading