From 9e490af92b311d5ac3de8d76182807f157919934 Mon Sep 17 00:00:00 2001 From: Schwarzemann Date: Fri, 8 Nov 2024 20:47:43 +0300 Subject: [PATCH 1/6] FIX: Add getters for camera parameters #1419 --- .vscode/settings.json | 3 ++ application/F3DStarter.cxx | 4 +-- java/Camera.java | 6 ++-- java/F3DJavaBindings.cxx | 14 ++++---- library/private/camera_impl.h | 9 +++-- library/public/camera.h | 15 +++++++-- library/src/camera_impl.cxx | 55 +++++++++++++++++++++++++++++-- library/testing/TestSDKCamera.cxx | 42 +++++++++++++++++++++-- python/F3DPythonBindings.cxx | 9 +++-- python/testing/test_camera.py | 6 ++-- 10 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..70e34ecb3d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/application/F3DStarter.cxx b/application/F3DStarter.cxx index a6a9c5a4bd..66b4b150a6 100644 --- a/application/F3DStarter.cxx +++ b/application/F3DStarter.cxx @@ -138,8 +138,8 @@ class F3DStarter::F3DInternals cam.resetToBounds(zoomFactor); } - cam.azimuth(camConf.CameraAzimuthAngle) - .elevation(camConf.CameraElevationAngle) + cam.addAzimuth(camConf.CameraAzimuthAngle) + .addElevation(camConf.CameraElevationAngle) .setCurrentAsDefault(); } diff --git a/java/Camera.java b/java/Camera.java index bf2f5aa31c..871e8324e5 100644 --- a/java/Camera.java +++ b/java/Camera.java @@ -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(); diff --git a/java/F3DJavaBindings.cxx b/java/F3DJavaBindings.cxx index 9f9391949b..4416d98108 100644 --- a/java/F3DJavaBindings.cxx +++ b/java/F3DJavaBindings.cxx @@ -134,21 +134,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); diff --git a/library/private/camera_impl.h b/library/private/camera_impl.h index 17173d74ca..b34bf9f05d 100644 --- a/library/private/camera_impl.h +++ b/library/private/camera_impl.h @@ -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; diff --git a/library/public/camera.h b/library/public/camera.h index dcdf8d8230..cfd6a839db 100644 --- a/library/public/camera.h +++ b/library/public/camera.h @@ -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. @@ -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; diff --git a/library/src/camera_impl.cxx b/library/src/camera_impl.cxx index af5e2f26ac..965a8c629d 100644 --- a/library/src/camera_impl.cxx +++ b/library/src/camera_impl.cxx @@ -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; + } + 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) { @@ -215,7 +264,7 @@ camera& camera_impl::roll(angle_deg_t angle) } //---------------------------------------------------------------------------- -camera& camera_impl::azimuth(angle_deg_t angle) +camera& camera_impl::addAzimuth(angle_deg_t angle) { vtkCamera* cam = this->GetVTKCamera(); cam->Azimuth(angle); @@ -225,7 +274,7 @@ camera& camera_impl::azimuth(angle_deg_t angle) } //---------------------------------------------------------------------------- -camera& camera_impl::yaw(angle_deg_t angle) +camera& camera_impl::addYaw(angle_deg_t angle) { vtkCamera* cam = this->GetVTKCamera(); cam->Yaw(angle); @@ -235,7 +284,7 @@ camera& camera_impl::yaw(angle_deg_t angle) } //---------------------------------------------------------------------------- -camera& camera_impl::elevation(angle_deg_t angle) +camera& camera_impl::addElevation(angle_deg_t angle) { vtkCamera* cam = this->GetVTKCamera(); cam->Elevation(angle); diff --git a/library/testing/TestSDKCamera.cxx b/library/testing/TestSDKCamera.cxx index 3210f4f210..2821cc5206 100644 --- a/library/testing/TestSDKCamera.cxx +++ b/library/testing/TestSDKCamera.cxx @@ -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. }; @@ -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 << " != 0.0" << std::endl; + return EXIT_FAILURE; + } + double viewDirProj[2] = { 0.0, 0.0 }; + double dotProduct = viewDirProj[0] * viewDirProj[0] + viewDirProj[1] * viewDirProj[1]; + const double epsilon = std::numeric_limits::epsilon(); + if (dotProduct < epsilon) + { + std::cerr << "Dot product is lesser than epsilon, returning 0.0 as expected." << std::endl; + return 0.0; + } + // Test roll cam.roll(90); expectedUp = { 0., 0., -1. }; @@ -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(); @@ -179,8 +196,23 @@ 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; + } + dotProduct = viewDirProj[0] * viewDirProj[0] + viewDirProj[1] * viewDirProj[1]; + if (dotProduct < epsilon) + { + std::cerr << "Dot product is lesser than epsilon, returning 0.0 as expected." << std::endl; + return 0.0; + } + // Test elevation - cam.elevation(90); + cam.addElevation(90); expectedPos = { 11., -11., -12. }; expectedUp = { 1., 0., 0. }; pos = cam.getPosition(); @@ -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. }; diff --git a/python/F3DPythonBindings.cxx b/python/F3DPythonBindings.cxx index c61cca1e2a..02ecbc39b3 100644 --- a/python/F3DPythonBindings.cxx +++ b/python/F3DPythonBindings.cxx @@ -277,9 +277,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) diff --git a/python/testing/test_camera.py b/python/testing/test_camera.py index c875a3ead2..dc2b6eb3ec 100644 --- a/python/testing/test_camera.py +++ b/python/testing/test_camera.py @@ -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) From d04552e699e1c19bc089694130b383cc9220388d Mon Sep 17 00:00:00 2001 From: Schwarzemann Date: Fri, 8 Nov 2024 21:08:29 +0300 Subject: [PATCH 2/6] FIX: Add getters for camera parameters #1419 --- library/testing/TestSDKCamera.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/testing/TestSDKCamera.cxx b/library/testing/TestSDKCamera.cxx index 2821cc5206..7221d16d28 100644 --- a/library/testing/TestSDKCamera.cxx +++ b/library/testing/TestSDKCamera.cxx @@ -154,8 +154,8 @@ int TestSDKCamera(int argc, char* argv[]) const double epsilon = std::numeric_limits::epsilon(); if (dotProduct < epsilon) { - std::cerr << "Dot product is lesser than epsilon, returning 0.0 as expected." << std::endl; - return 0.0; + std::cerr << "Dot product is lesser than epsilon, returning epsilon." << std::endl; + return epsilon; } // Test roll @@ -207,8 +207,8 @@ int TestSDKCamera(int argc, char* argv[]) dotProduct = viewDirProj[0] * viewDirProj[0] + viewDirProj[1] * viewDirProj[1]; if (dotProduct < epsilon) { - std::cerr << "Dot product is lesser than epsilon, returning 0.0 as expected." << std::endl; - return 0.0; + std::cerr << "Dot product is lesser than epsilon, returning epsilon." << std::endl; + return epsilon; } // Test elevation From 997392752297c270280bc2eb2286dfd69f57879e Mon Sep 17 00:00:00 2001 From: Schwarzemann Date: Sun, 5 Jan 2025 17:27:19 +0300 Subject: [PATCH 3/6] Feature: Add getters for camera parameters #1419 --- library/testing/TestSDKCamera.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/testing/TestSDKCamera.cxx b/library/testing/TestSDKCamera.cxx index 7221d16d28..cdf8017b95 100644 --- a/library/testing/TestSDKCamera.cxx +++ b/library/testing/TestSDKCamera.cxx @@ -155,7 +155,7 @@ int TestSDKCamera(int argc, char* argv[]) if (dotProduct < epsilon) { std::cerr << "Dot product is lesser than epsilon, returning epsilon." << std::endl; - return epsilon; + return EXIT_FAILURE; } // Test roll @@ -208,7 +208,7 @@ int TestSDKCamera(int argc, char* argv[]) if (dotProduct < epsilon) { std::cerr << "Dot product is lesser than epsilon, returning epsilon." << std::endl; - return epsilon; + return EXIT_FAILURE; } // Test elevation From 6e20870344b49ee9bfd7c56b602e1bb838904714 Mon Sep 17 00:00:00 2001 From: Schwarzemann Date: Sun, 5 Jan 2025 17:55:05 +0300 Subject: [PATCH 4/6] Feature: Add getters for camera parameters #1419 --- .vscode/settings.json | 5 ++++- library/testing/TestSDKCamera.cxx | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 70e34ecb3d..63c5d37b51 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,6 @@ { - "C_Cpp.errorSquiggles": "disabled" + "C_Cpp.errorSquiggles": "disabled", + "files.associations": { + "cmath": "cpp" + } } \ No newline at end of file diff --git a/library/testing/TestSDKCamera.cxx b/library/testing/TestSDKCamera.cxx index cdf8017b95..5c6485f6cd 100644 --- a/library/testing/TestSDKCamera.cxx +++ b/library/testing/TestSDKCamera.cxx @@ -141,20 +141,19 @@ 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 << " != 0.0" << std::endl; + std::cerr << std::setprecision(12) << "azimuth: " << azimuth << " != 90.0" << std::endl; return EXIT_FAILURE; } - double viewDirProj[2] = { 0.0, 0.0 }; + double viewDirProj[2] = { 1.0, 1.0 }; double dotProduct = viewDirProj[0] * viewDirProj[0] + viewDirProj[1] * viewDirProj[1]; const double epsilon = std::numeric_limits::epsilon(); if (dotProduct < epsilon) { - std::cerr << "Dot product is lesser than epsilon, returning epsilon." << std::endl; + std::cerr << "Dot product is lesser than epsilon, returning failure." << std::endl; return EXIT_FAILURE; } @@ -208,7 +207,7 @@ int TestSDKCamera(int argc, char* argv[]) if (dotProduct < epsilon) { std::cerr << "Dot product is lesser than epsilon, returning epsilon." << std::endl; - return EXIT_FAILURE; + return epsilon; } // Test elevation From bb85a0d461c22a65d660180928771610a1f0a263 Mon Sep 17 00:00:00 2001 From: Schwarzemann Date: Sun, 5 Jan 2025 17:56:03 +0300 Subject: [PATCH 5/6] Feature: Add getters for camera parameters #1419 --- library/testing/TestSDKCamera.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/library/testing/TestSDKCamera.cxx b/library/testing/TestSDKCamera.cxx index 5c6485f6cd..bcd8224f5d 100644 --- a/library/testing/TestSDKCamera.cxx +++ b/library/testing/TestSDKCamera.cxx @@ -141,6 +141,7 @@ int TestSDKCamera(int argc, char* argv[]) return EXIT_FAILURE; } + // Test getAzimuth f3d::angle_deg_t azimuth = cam.getAzimuth(); if (!compareDouble(azimuth, 90.0)) { From 6ce7254708fcbc2115cc0df9a77af0a32d6bda61 Mon Sep 17 00:00:00 2001 From: Schwarzemann Date: Sun, 5 Jan 2025 17:57:48 +0300 Subject: [PATCH 6/6] Feature: Add getters for camera parameters #1419 --- library/testing/TestSDKCamera.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/testing/TestSDKCamera.cxx b/library/testing/TestSDKCamera.cxx index bcd8224f5d..4525f4d987 100644 --- a/library/testing/TestSDKCamera.cxx +++ b/library/testing/TestSDKCamera.cxx @@ -204,11 +204,10 @@ int TestSDKCamera(int argc, char* argv[]) std::cerr << std::setprecision(12) << "yaw: " << yaw << " != 0.0" << std::endl; return EXIT_FAILURE; } - dotProduct = viewDirProj[0] * viewDirProj[0] + viewDirProj[1] * viewDirProj[1]; if (dotProduct < epsilon) { - std::cerr << "Dot product is lesser than epsilon, returning epsilon." << std::endl; - return epsilon; + std::cerr << "Dot product is lesser than epsilon, returning failure." << std::endl; + return EXIT_FAILURE; } // Test elevation