-
-
Notifications
You must be signed in to change notification settings - Fork 361
Add getters for camera parameters #1419 #2767
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
base: master
Are you sure you want to change the base?
Conversation
…ickly for further processing (cherry picked from commit 935740b)
(cherry picked from commit c589cd3)
…n to compute the distance from the camera position to the focal point (cherry picked from commit a54c71e)
(cherry picked from commit af3407a)
(cherry picked from commit 3f8671b)
…mproved getWorldAzimuth using SignedAngleBetweenVectors
|
You are modifying libf3d public API! |
|
I think this should be correct now, will work on better testing ASAP |
| // Elevation is angle above the horizontal plane | ||
| double dot = vtkMath::Dot(view.data(), up); | ||
| dot = std::clamp(dot, -1.0, 1.0); | ||
|
|
||
| return vtkMath::DegreesFromRadians(std::asin(dot)); |
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.
Would be nice to check if that can be done with AngleBetweenVectors to avoid the raw trig. Maybe something like 90° - angle_between(view, up)?
| static constexpr double EPS = 128 * std::numeric_limits<double>::epsilon(); | ||
| if (vtkMath::Norm(horizontal.data()) < EPS) | ||
| { | ||
| return 0.0; | ||
| } | ||
|
|
||
| vtkMath::Normalize(horizontal.data()); |
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.
Once you've got the tests you can double check if this is actually needed
|
please let us know when its ready for review @Dtsitos |
|
@mwestphal Hello there, I have implemented all the bindings and some basic testing for them. Full disclosure, I have never worked with bindings again and mostly deduced what to do based on the patterns from the existing implementations. Thank you for your patience |
Thats perfectly fine and it looks good to me :) |
|
\ci full |
|
Style Checks CI failed: diff --git a/library/src/camera_impl.cxx b/library/src/camera_impl.cxx
index fb8d8ee..5e35fb7 100644
--- a/library/src/camera_impl.cxx
+++ b/library/src/camera_impl.cxx
@@ -1,12 +1,11 @@
#include "camera_impl.h"
+#include <cmath>
#include <vtkCamera.h>
#include <vtkMatrix4x4.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkVersion.h>
-#include <cmath>
-
namespace f3d::detail
{
@@ -106,7 +105,7 @@ void camera_impl::getFocalPoint(point3_t& foc) const
}
//----------------------------------------------------------------------------
- void camera_impl::getPositionToFocalVector(vector3_t& vec) const
+void camera_impl::getPositionToFocalVector(vector3_t& vec) const
{
point3_t pos, focal;
this->getPosition(pos);
@@ -116,7 +115,7 @@ void camera_impl::getFocalPoint(point3_t& foc) const
}
//----------------------------------------------------------------------------
- double camera_impl::getWorldAzimuth() const
+double camera_impl::getWorldAzimuth() const
{
vector3_t view;
this->getPositionToFocalVector(view);
@@ -145,11 +144,10 @@ void camera_impl::getFocalPoint(point3_t& foc) const
double angleRad = vtkMath::SignedAngleBetweenVectors(right, horizontal.data(), up);
return vtkMath::DegreesFromRadians(angleRad);
-
}
//----------------------------------------------------------------------------
- double camera_impl::getWorldElevation() const
+double camera_impl::getWorldElevation() const
{
vector3_t view;
this->getPositionToFocalVector(view);
@@ -166,7 +164,7 @@ void camera_impl::getFocalPoint(point3_t& foc) const
}
//----------------------------------------------------------------------------
- double camera_impl::getDistance() const
+double camera_impl::getDistance() const
{
vector3_t v;
this->getPositionToFocalVector(v);
diff --git a/library/testing/TestSDKCamera.cxx b/library/testing/TestSDKCamera.cxx
index 74670fc..7bb46e0 100644
--- a/library/testing/TestSDKCamera.cxx
+++ b/library/testing/TestSDKCamera.cxx
@@ -243,7 +243,8 @@ int TestSDKCamera([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
if (!compareDouble(elevation, 0.0))
{
- std::cerr << "getWorldElevation (horizontal) is not behaving as expected: " << elevation << "\n";
+ std::cerr << "getWorldElevation (horizontal) is not behaving as expected: " << elevation
+ << "\n";
return EXIT_FAILURE;
}
@@ -258,13 +259,15 @@ int TestSDKCamera([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
if (!compareDouble(distance, std::sqrt(11.0 * 11.0 + 11.0 * 11.0)))
{
- std::cerr << "getDistance (positive elevation) is not behaving as expected: " << distance << "\n";
+ std::cerr << "getDistance (positive elevation) is not behaving as expected: " << distance
+ << "\n";
return EXIT_FAILURE;
}
if (!compareDouble(azimuth, 90.0))
{
- std::cerr << "getWorldAzimuth (positive elevation) is not behaving as expected: " << azimuth << "\n";
+ std::cerr << "getWorldAzimuth (positive elevation) is not behaving as expected: " << azimuth
+ << "\n";
return EXIT_FAILURE;
}
@@ -286,7 +289,8 @@ int TestSDKCamera([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
if (!compareDouble(distance, std::sqrt(11.0 * 11.0 + 11.0 * 11.0)))
{
- std::cerr << "getDistance (negative elevation) is not behaving as expected: " << distance << "\n";
+ std::cerr << "getDistance (negative elevation) is not behaving as expected: " << distance
+ << "\n";
return EXIT_FAILURE;
}
@@ -341,15 +345,14 @@ int TestSDKCamera([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
if (!compareDouble(azimuth, 0.0))
{
- std::cerr << "getWorldAzimuth with zero direction vector should return 0: "
- << azimuth << "\n";
+ std::cerr << "getWorldAzimuth with zero direction vector should return 0: " << azimuth << "\n";
return EXIT_FAILURE;
}
if (!compareDouble(elevation, 0.0))
{
- std::cerr << "getWorldElevation with zero direction vector should return 0: "
- << elevation << "\n";
+ std::cerr << "getWorldElevation with zero direction vector should return 0: " << elevation
+ << "\n";
return EXIT_FAILURE;
}
@@ -363,15 +366,14 @@ int TestSDKCamera([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
if (!compareDouble(azimuth, 0.0))
{
- std::cerr << "getWorldAzimuth with forward parallel to up should return 0: "
- << azimuth << "\n";
+ std::cerr << "getWorldAzimuth with forward parallel to up should return 0: " << azimuth << "\n";
return EXIT_FAILURE;
}
if (!compareDouble(elevation, 90.0))
{
- std::cerr << "getWorldElevation with forward parallel to up should be 90: "
- << elevation << "\n";
+ std::cerr << "getWorldElevation with forward parallel to up should be 90: " << elevation
+ << "\n";
return EXIT_FAILURE;
}
|
Describe your changes
This PR adds read-only getters to the camera API to retrieve derived world-space
camera parameters (azimuth, elevation, and distance).
The values are computed from the camera position and focal point and do not
modify camera state. This enables external applications and bindings to query
camera orientation consistently without duplicating math.
No existing behavior is changed.
Original PR: #2724
Issue ticket number and link if any
Fixes #1419
Checklist for finalizing the PR
.github/workflows/versions.json, I have updateddocker_timestampContinuous integration
Please write a comment to run CI, eg:
\ci fast.See here for more info.