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 9 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"C_Cpp.errorSquiggles": "disabled",
"files.associations": {
"cmath": "cpp"
}
}
4 changes: 2 additions & 2 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class F3DStarter::F3DInternals
cam.resetToBounds(zoomFactor);
}

cam.azimuth(camConf.CameraAzimuthAngle)
.elevation(camConf.CameraElevationAngle)
cam.addAzimuth(camConf.CameraAzimuthAngle)
.addElevation(camConf.CameraElevationAngle)
.setCurrentAsDefault();
}

Expand Down
6 changes: 3 additions & 3 deletions java/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public Camera(long nativeAddress) {

public native void dolly(double val);
public native void roll(double angle);
public native void azimuth(double angle);
public native void yaw(double angle);
public native void elevation(double angle);
public native void addAzimuth(double angle);
public native void addYaw(double angle);
public native void addElevation(double angle);
public native void pitch(double angle);

public native double[] getFocalPoint();
Expand Down
14 changes: 7 additions & 7 deletions java/F3DJavaBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ extern "C"
GetEngine(env, self)->getWindow().getCamera().roll(angle);
}

JNIEXPORT void JAVA_BIND(Camera, azimuth)(JNIEnv* env, jobject self, jdouble angle)
JNIEXPORT void JNICALL JAVA_BIND(Camera, addAzimuth)(JNIEnv* env, jobject self, jdouble angle)
{
GetEngine(env, self)->getWindow().getCamera().azimuth(angle);
GetEngine(env, self)->getWindow().getCamera().addAzimuth(angle);
}

JNIEXPORT void JAVA_BIND(Camera, yaw)(JNIEnv* env, jobject self, jdouble angle)
JNIEXPORT void JNICALL JAVA_BIND(Camera, addYaw)(JNIEnv* env, jobject self, jdouble angle)
{
GetEngine(env, self)->getWindow().getCamera().yaw(angle);
GetEngine(env, self)->getWindow().getCamera().addYaw(angle);
}

JNIEXPORT void JAVA_BIND(Camera, elevation)(JNIEnv* env, jobject self, jdouble angle)
JNIEXPORT void JNICALL JAVA_BIND(Camera, addElevation)(JNIEnv* env, jobject self, jdouble angle)
{
GetEngine(env, self)->getWindow().getCamera().elevation(angle);
GetEngine(env, self)->getWindow().getCamera().addElevation(angle);
}

JNIEXPORT void JAVA_BIND(Camera, pitch)(JNIEnv* env, jobject self, jdouble angle)
{
GetEngine(env, self)->getWindow().getCamera().pitch(angle);
Expand Down
9 changes: 6 additions & 3 deletions library/private/camera_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ 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;
camera& zoom(double factor) override;
camera& roll(angle_deg_t angle) override;
camera& azimuth(angle_deg_t angle) override;
camera& yaw(angle_deg_t angle) override;
camera& elevation(angle_deg_t angle) override;
camera& addAzimuth(angle_deg_t angle) override;
camera& addYaw(angle_deg_t angle) override;
camera& addElevation(angle_deg_t angle) override;
camera& pitch(angle_deg_t angle) override;

camera& setCurrentAsDefault() override;
Expand Down
15 changes: 12 additions & 3 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 All @@ -63,11 +72,11 @@ class F3D_EXPORT camera
/** Rotate the camera about its forward axis. */
virtual camera& roll(angle_deg_t angle) = 0;
/** Rotate the camera about its vertical axis, centered at the focal point. */
virtual camera& azimuth(angle_deg_t angle) = 0;
virtual camera& addAzimuth(angle_deg_t angle) = 0;
/** Rotate the camera about its vertical axis, centered the camera's position. */
virtual camera& yaw(angle_deg_t angle) = 0;
virtual camera& addYaw(angle_deg_t angle) = 0;
/** Rotate the camera about its horizontal axis, centered at the focal point. */
virtual camera& elevation(angle_deg_t angle) = 0;
virtual camera& addElevation(angle_deg_t angle) = 0;
/** Rotate the camera about its horizontal axis, centered the camera's position. */
virtual camera& pitch(angle_deg_t angle) = 0;

Expand Down
55 changes: 52 additions & 3 deletions library/src/camera_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@
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;

Check warning on line 132 in library/src/camera_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/camera_impl.cxx#L132

Added line #L132 was not covered by tests
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

}
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;

Check warning on line 149 in library/src/camera_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/camera_impl.cxx#L149

Added line #L149 was not covered by tests
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

}
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 Expand Up @@ -215,7 +264,7 @@
}

//----------------------------------------------------------------------------
camera& camera_impl::azimuth(angle_deg_t angle)
camera& camera_impl::addAzimuth(angle_deg_t angle)
{
vtkCamera* cam = this->GetVTKCamera();
cam->Azimuth(angle);
Expand All @@ -225,7 +274,7 @@
}

//----------------------------------------------------------------------------
camera& camera_impl::yaw(angle_deg_t angle)
camera& camera_impl::addYaw(angle_deg_t angle)
{
vtkCamera* cam = this->GetVTKCamera();
cam->Yaw(angle);
Expand All @@ -235,7 +284,7 @@
}

//----------------------------------------------------------------------------
camera& camera_impl::elevation(angle_deg_t angle)
camera& camera_impl::addElevation(angle_deg_t angle)
{
vtkCamera* cam = this->GetVTKCamera();
cam->Elevation(angle);
Expand Down
41 changes: 38 additions & 3 deletions library/testing/TestSDKCamera.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int TestSDKCamera(int argc, char* argv[])
}

// Test azimuth
cam.azimuth(90);
cam.addAzimuth(90);
f3d::point3_t expectedPos = { 0., -11., -1. };
f3d::point3_t expectedFoc = { 0., 0., -1. };
f3d::vector3_t expectedUp = { 1., 0., 0. };
Expand All @@ -141,6 +141,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;
}
double viewDirProj[2] = { 1.0, 1.0 };
double dotProduct = viewDirProj[0] * viewDirProj[0] + viewDirProj[1] * viewDirProj[1];
const double epsilon = std::numeric_limits<double>::epsilon();
if (dotProduct < epsilon)
{
std::cerr << "Dot product is lesser than epsilon, returning failure." << std::endl;
return EXIT_FAILURE;
}

// Test roll
cam.roll(90);
expectedUp = { 0., 0., -1. };
Expand All @@ -161,7 +178,7 @@ int TestSDKCamera(int argc, char* argv[])
}

// Test yaw
cam.yaw(90);
cam.addYaw(90);
expectedFoc = { 11., -11., -1. };
pos = cam.getPosition();
foc = cam.getFocalPoint();
Expand All @@ -179,8 +196,22 @@ int TestSDKCamera(int argc, char* argv[])
return EXIT_FAILURE;
}

// Test getYaw
mwestphal marked this conversation as resolved.
Show resolved Hide resolved
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 EXIT_FAILURE;
}

// Test elevation
cam.elevation(90);
cam.addElevation(90);
expectedPos = { 11., -11., -12. };
expectedUp = { 1., 0., 0. };
pos = cam.getPosition();
Expand All @@ -199,6 +230,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
9 changes: 6 additions & 3 deletions python/F3DPythonBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,12 @@ PYBIND11_MODULE(pyf3d, module)
.def("pan", &f3d::camera::pan, py::arg("right"), py::arg("up"), py::arg("forward") = 0.0)
.def("zoom", &f3d::camera::zoom)
.def("roll", &f3d::camera::roll)
.def("azimuth", &f3d::camera::azimuth)
.def("yaw", &f3d::camera::yaw)
.def("elevation", &f3d::camera::elevation)
.def("add_azimuth", &f3d::camera::addAzimuth)
.def("add_yaw", &f3d::camera::addYaw)
.def("add_elevation", &f3d::camera::addElevation)
.def_property_readonly("azimuth", &f3d::camera::getAzimuth)
.def_property_readonly("yaw", &f3d::camera::getYaw)
.def_property_readonly("elevation", &f3d::camera::getElevation)
.def("pitch", &f3d::camera::pitch)
.def("set_current_as_default", &f3d::camera::setCurrentAsDefault)
.def("reset_to_default", &f3d::camera::resetToDefault)
Expand Down
6 changes: 3 additions & 3 deletions python/testing/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def test_moves():
camera.dolly(10)
angle = 30
camera.roll(angle)
camera.azimuth(angle)
camera.yaw(angle)
camera.elevation(angle)
camera.add_azimuth(angle)
camera.add_yaw(angle)
camera.add_elevation(angle)
camera.pitch(angle)


Expand Down
Loading