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

Feature: Add getters for camera parameters #1419 #1663

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9e490af
FIX: Add getters for camera parameters #1419
Schwarzemann Nov 8, 2024
d04552e
FIX: Add getters for camera parameters #1419
Schwarzemann Nov 8, 2024
bc36eb7
Merge branch 'f3d-app:master' into master
Schwarzemann Nov 28, 2024
e8d0274
Merge branch 'f3d-app:master' into master
Schwarzemann Dec 8, 2024
9096141
Merge branch 'f3d-app:master' into master
Schwarzemann Jan 5, 2025
9973927
Feature: Add getters for camera parameters #1419
Schwarzemann Jan 5, 2025
6e20870
Feature: Add getters for camera parameters #1419
Schwarzemann Jan 5, 2025
bb85a0d
Feature: Add getters for camera parameters #1419
Schwarzemann Jan 5, 2025
6ce7254
Feature: Add getters for camera parameters #1419
Schwarzemann Jan 5, 2025
9e175a4
Merge branch 'f3d-app:master' into master
Schwarzemann Mar 9, 2025
c76b117
Merge branch 'f3d-app:master' into master
Schwarzemann Mar 15, 2025
9839da3
Feature: Add getters for camera parameters #1419
Schwarzemann Mar 15, 2025
0ee83ca
Feature: Add getters for camera parameters #1419
Schwarzemann Mar 15, 2025
a2544ca
Feature: Add getters for camera parameters #1419
Schwarzemann Mar 16, 2025
e634a0f
Feature: Add getters for camera parameters #1419
Schwarzemann Mar 16, 2025
8cd2ea3
Feature: Add getters for camera parameters #1419
Schwarzemann Mar 16, 2025
c45409a
Feature: Add getters for camera parameters #1419
Schwarzemann Mar 16, 2025
06898e3
Merge branch 'f3d-app:master' into master
Schwarzemann Mar 18, 2025
fee585e
Merge branch 'f3d-app:master' into master
Schwarzemann Mar 27, 2025
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
2 changes: 1 addition & 1 deletion java/F3DJavaBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ extern "C"
{
GetEngine(env, self)->getWindow().getCamera().resetToBounds();
}
}
}
3 changes: 3 additions & 0 deletions library/private/camera_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class camera_impl : public camera
camera& setState(const camera_state_t& state) override;
camera_state_t getState() override;
void getState(camera_state_t& state) override;
angle_deg_t getAzimuth() override;
angle_deg_t getYaw() override;
angle_deg_t getElevation() override;

camera& dolly(double val) override;
camera& pan(double right, double up, double forward) override;
Expand Down
9 changes: 9 additions & 0 deletions library/public/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class F3D_EXPORT camera
virtual void getState(camera_state_t& state) = 0;
///@}

///@{ @name Orientation
/** Get the azimuth angle of the camera. */
virtual angle_deg_t getAzimuth() = 0;
/** Get the yaw angle of the camera. */
virtual angle_deg_t getYaw() = 0;
/** Get the elevation angle of the camera. */
virtual angle_deg_t getElevation() = 0;
///@}

///@{ @name Manipulation
/// Standard camera manipulation methods. Angles are in degrees.

Expand Down
49 changes: 49 additions & 0 deletions library/src/camera_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@ angle_deg_t camera_impl::getViewAngle()
return angle;
}

//----------------------------------------------------------------------------
angle_deg_t camera_impl::getAzimuth()
{
vtkCamera* cam = this->GetVTKCamera();
double pos[3], foc[3];
cam->GetPosition(pos);
cam->GetFocalPoint(foc);
double viewDir[3];
vtkMath::Subtract(foc, pos, viewDir);
double viewDirProj[2] = { viewDir[0], viewDir[1] };
if (vtkMath::Dot2D(viewDirProj, viewDirProj) < VTK_DBL_EPSILON)
{
return 0.0;
}
return vtkMath::DegreesFromRadians(atan2(viewDirProj[1], viewDirProj[0]));
}

//----------------------------------------------------------------------------
angle_deg_t camera_impl::getYaw()
{
vtkCamera* cam = this->GetVTKCamera();
double pos[3], foc[3];
cam->GetPosition(pos);
cam->GetFocalPoint(foc);
double viewDir[3];
vtkMath::Subtract(foc, pos, viewDir);
double viewDirProj[2] = { viewDir[0], viewDir[2] };
if (vtkMath::Dot2D(viewDirProj, viewDirProj) < VTK_DBL_EPSILON)
{
return 0.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in short you need to add a test where this conditionj is true and you enter this line

}
return vtkMath::DegreesFromRadians(atan2(viewDirProj[0], viewDirProj[1]));
}

//----------------------------------------------------------------------------
angle_deg_t camera_impl::getElevation()
{
vtkCamera* cam = this->GetVTKCamera();
double pos[3], foc[3];
cam->GetPosition(pos);
cam->GetFocalPoint(foc);

double viewDir[3];
vtkMath::Subtract(foc, pos, viewDir);
vtkMath::Normalize(viewDir);

return vtkMath::DegreesFromRadians(asin(viewDir[2]));
}

//----------------------------------------------------------------------------
void camera_impl::getViewAngle(angle_deg_t& angle)
{
Expand Down
3 changes: 2 additions & 1 deletion library/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ option(F3D_TESTING_ENABLE_EXTERNAL_QT "Test external QT" OFF)

set(libf3dSDKTests_link_libs "")

find_package(VTK REQUIRED COMPONENTS CommonCore)
if(F3D_TESTING_ENABLE_EXTERNAL_GLFW)
find_package(glfw3 REQUIRED)
list(APPEND libf3dSDKTests_list TestSDKExternalWindowGLFW.cxx)
Expand Down Expand Up @@ -177,7 +178,7 @@ if(F3D_MODULE_UI AND NOT F3D_TESTING_ENABLE_LONG_TIMEOUT_TESTS)
set_tests_properties(libf3d::TestSDKInteractorCallBack PROPERTIES DISABLED ON)
endif()

target_link_libraries(libf3dSDKTests libf3d ${libf3dSDKTests_link_libs})
target_link_libraries(libf3dSDKTests libf3d ${libf3dSDKTests_link_libs} VTK::CommonCore)

# make sure the libf3d API is compatible with the right C++ standard
set_target_properties(libf3dSDKTests PROPERTIES CXX_STANDARD 17)
31 changes: 31 additions & 0 deletions library/testing/TestSDKCamera.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <iostream>
#include <limits>
#include <sstream>
#include <vtkMath.h>

// TODO these methods should be put in types.h at some point.
// https://github.com/f3d-app/f3d/issues/361
Expand Down Expand Up @@ -141,6 +142,19 @@ int TestSDKCamera(int argc, char* argv[])
return EXIT_FAILURE;
}

// Test getAzimuth
f3d::point3_t tempPos = { 0.0, 0.0, 0.0 };
f3d::point3_t tempFoc = { 0.0, 0.0, 1.0 };
cam.setPosition(tempPos);
cam.setFocalPoint(tempFoc);
f3d::angle_deg_t azimuth = cam.getAzimuth();
if (!compareDouble(azimuth, 0.0))
{
std::cerr << "getAzimuth is not behaving as expected:" << std::endl;
std::cerr << std::setprecision(12) << "azimuth: " << azimuth << " != 0.0" << std::endl;
return EXIT_FAILURE;
}

// Test roll
cam.roll(90);
expectedUp = { 0., 0., -1. };
Expand Down Expand Up @@ -179,6 +193,19 @@ int TestSDKCamera(int argc, char* argv[])
return EXIT_FAILURE;
}

// Test getYaw
// f3d::point3_t testPos = { 0.0, 0.0, 0.0 };
f3d::point3_t termFoc = { 0.0, 0.0, 1.0 };
// cam.setPosition(testPos);
cam.setFocalPoint(termFoc);
f3d::angle_deg_t yaw = cam.getYaw();
if (!compareDouble(yaw, 0.0))
{
std::cerr << "getYaw is not behaving as expected:" << std::endl;
std::cerr << std::setprecision(12) << "yaw: " << yaw << " != 0.0" << std::endl;
return EXIT_FAILURE;
}

// Test elevation
cam.elevation(90);
expectedPos = { 11., -11., -12. };
Expand All @@ -199,6 +226,10 @@ int TestSDKCamera(int argc, char* argv[])
return EXIT_FAILURE;
}

// Test getElevation
double elevation = cam.getElevation();
checkDouble(elevation, 90.0, "getElevation");

// Test pitch
cam.pitch(90);
expectedFoc = { 22., -11., -12. };
Expand Down
2 changes: 1 addition & 1 deletion python/F3DPythonBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,4 @@ PYBIND11_MODULE(pyf3d, module)
.def_static("set_use_coloring", &f3d::log::setUseColoring)
.def_static("print", [](f3d::log::VerboseLevel& level, const std::string& message)
{ f3d::log::print(level, message); });
}
}
Loading