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 18 commits into
base: master
Choose a base branch
from
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
@@ -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
@@ -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;
9 changes: 9 additions & 0 deletions library/public/camera.h
Original file line number Diff line number Diff line change
@@ -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.

49 changes: 49 additions & 0 deletions library/src/camera_impl.cxx
Original file line number Diff line number Diff line change
@@ -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
Contributor

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
Contributor

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)
{
3 changes: 2 additions & 1 deletion library/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
36 changes: 36 additions & 0 deletions library/testing/TestSDKCamera.cxx
Original file line number Diff line number Diff line change
@@ -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
@@ -141,6 +142,23 @@ int TestSDKCamera(int argc, char* argv[])
return EXIT_FAILURE;
}

// Test getAzimuth
f3d::angle_deg_t azimuth = cam.getAzimuth();
if (!compareDouble(azimuth, 90.0))
{
std::cerr << "getAzimuth is not behaving as expected:" << std::endl;
std::cerr << std::setprecision(12) << "azimuth: " << azimuth << " != 90.0" << std::endl;
return EXIT_FAILURE;
}
const double viewDirProj[2] = { 1.0, 1.0 };
double dotProduct = vtkMath::Dot(viewDirProj, viewDirProj);
const double epsilon = std::numeric_limits<double>::epsilon();
if (dotProduct < epsilon)
{
std::cerr << "Dot product is lesser than epsilon, returning failure." << std::endl;
return 0.0;
}

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

// Test getYaw
f3d::angle_deg_t yaw = cam.getYaw();
if (!compareDouble(yaw, 90.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;
}
if (dotProduct < epsilon)
{
std::cerr << "Dot product is lesser than epsilon, returning failure." << std::endl;
return 0.0;
}

// Test elevation
cam.elevation(90);
expectedPos = { 11., -11., -12. };
@@ -199,6 +231,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. };
2 changes: 1 addition & 1 deletion python/F3DPythonBindings.cxx
Original file line number Diff line number Diff line change
@@ -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); });
}
}
1 change: 1 addition & 0 deletions python/testing/test_camera.py
Original file line number Diff line number Diff line change
@@ -107,3 +107,4 @@ def test_resets():
camera.set_current_as_default()
camera.reset_to_bounds()
camera.reset_to_default()

Copy link
Contributor

Choose a reason for hiding this comment

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

still incorrect ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I delete the line?

Copy link
Contributor

Choose a reason for hiding this comment

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

not exactly, you should fix the "missing end of line" issue. See this:
https://stackoverflow.com/questions/5813311/whats-the-significance-of-the-no-newline-at-end-of-file-log

Loading
Oops, something went wrong.