-
Notifications
You must be signed in to change notification settings - Fork 51
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
Change aspect to AspectRatio() #635
Conversation
Signed-off-by: youhy <haoyuan2019@outlook.com>
Signed-off-by: youhy <haoyuan2019@outlook.com>
Signed-off-by: youhy <haoyuan2019@outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than linters this LGTM, will need @iche033 's stamp of approval
Ideally we also update the value of |
Signed-off-by: youhy <haoyuan2019@outlook.com>
Signed-off-by: youhy <haoyuan2019@outlook.com>
Codecov Report
@@ Coverage Diff @@
## ign-rendering6 #635 +/- ##
===================================================
- Coverage 80.00% 54.52% -25.48%
===================================================
Files 1 198 +197
Lines 15 20270 +20255
===================================================
+ Hits 12 11052 +11040
- Misses 3 9218 +9215
Continue to review full report at Codecov.
|
@iche033 Just to clarify, do you mean we should update |
yes I would expect the aspect ratio to change when user calls these 2 functions. I think the HFOV should not affect aspect ratio though but we should double check that. |
Signed-off-by: youhy <haoyuan2019@outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a Camera_TEST
you can check that after SetImageWidth
AspectRatio()
agrees.
e.g.,
double width = 100
camera.SetImageWidth(width)
double aspectRatio = width / camera.ImageHeight()
EXPECT_NEAR(aspectRatio, camera.AspectRatio(), 1e-6)
Similarly for SetImageHeight
Signed-off-by: youhy <haoyuan2019@outlook.com>
Signed-off-by: youhy <haoyuan2019@outlook.com>
Signed-off-by: youhy <haoyuan2019@outlook.com>
src/Camera_TEST.cc
Outdated
double width = 100 | ||
camera.SetImageWidth(width) | ||
double aspectRatio = width / camera.ImageHeight() | ||
EXPECT_NEAR(aspectRatio, camera.AspectRatio(), 1e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing ;
at the end of each line and camera
is a pointer. This test fails though, you will need to try to investigate why and how to correct this
Since you are using ogre
on your system, temporarily update ogre2
to ogre
here:
gz-rendering/test/test_config.h.in
Line 16 in a3dc1ae
static const std::vector<const char *> kRenderEngineTestValues{"ogre2", "optix"}; |
To compile the test, run colcon build --cmake-args -DBUILD_TESTING=ON --merge-install --packages-select ignition-rendering6
in the root of your workspace. To run the test you can do ./build/ignition-rendering6/bin/UNIT_Camera_Test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also add a similar test with SetImageHeight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 8d4e542
Signed-off-by: youhy <haoyuan2019@outlook.com>
Signed-off-by: youhy <haoyuan2019@outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Left some minor comments
@@ -286,6 +286,7 @@ namespace ignition | |||
void BaseCamera<T>::SetImageWidth(const unsigned int _width) | |||
{ | |||
this->RenderTarget()->SetWidth(_width); | |||
this->SetAspectRatio(1.0 * _width / this->ImageHeight()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you are multiplying by 1.0
to cast the result to a double
. It's better to use static_cast<double>
to be explicit with the cast making the purpose clear. Same for SetImageHeight
this->SetAspectRatio(1.0 * _width / this->ImageHeight()); | |
this->SetAspectRatio( | |
static_cast<double>(_width) / static_cast<double>(this->ImageHeight())); |
src/Camera_TEST.cc
Outdated
camera->SetImageHeight(80u); | ||
EXPECT_EQ(80u, camera->ImageHeight()); | ||
|
||
double height = 80; | ||
camera->SetImageHeight(height); | ||
double aspectRatio = camera->ImageWidth() / height; | ||
EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since your new tests are almost the same as the previous test, lets remove the new test and continue on the previous one. E.g.,
camera->SetImageHeight(80u); | |
EXPECT_EQ(80u, camera->ImageHeight()); | |
double height = 80; | |
camera->SetImageHeight(height); | |
double aspectRatio = camera->ImageWidth() / height; | |
EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); | |
unsigned int height = 80; | |
camera->SetImageHeight(height); | |
EXPECT_EQ(height, camera->ImageHeight()); | |
double aspectRatio = | |
static_cast<double>(camera->ImageWidth()) / static_cast<double>(height)); | |
EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); |
The same should be done for width.
Also, go ahead and update this expectation below to use the new variables:
gz-rendering/src/Camera_TEST.cc
Line 195 in 8d4e542
EXPECT_EQ(100u*80u*3u, camera->ImageMemorySize()); |
e.g., EXPECT_EQ(width*height*3u, ...)
Signed-off-by: youhy <haoyuan2019@outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @iche033 do you mind to take another look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me.
🦟 Bug fix
Fixes ignition crash bug introduced in gz-sim#1499
Summary
gz-sim#1499 adds a feature to change the FOV of the user camera at runtime. But if we scale the window after changing the FOV, Gazebo has a chance to crash. (Always crash on Ogre, sometimes crash on Ogre2)
Changing
aspect
toAspectRatio()
inOgreCamera::SetHFOV()
solves the bug.Also add comment to warn users not to use
aspect
inBaseCamera
but to useOrgeCamera::AspectRatio()
instead.Why this bug happened:
Resizing the window needs the correct aspect ratio value. There are 2 aspect ratio values available: one in Ogre library (
AspectRatio()
), and the other is inBaseCamera
(this->aspect
).When we change the FOV and resize the window, the aspect ratio and fov value in the Ogre library will both change but
aspect
in theBaseCamera
only update its fov value but not aspect ratio. However, inOgre2Camera::SetHFOV()
, it is still using the deprecated aspect ratio value from theBaseCamera
.If you check with gdb, the value read by
AspectRatio()
(directly from Ogre) andaspect
fromBaseCamera
no longer agree with each other after changing FOV and resizing the window. That is why there is a crash.Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.