From 1a0115a21a5c27af8505bda124d40665223f15aa Mon Sep 17 00:00:00 2001 From: Dan Turner Date: Thu, 22 Jul 2021 15:27:14 -0600 Subject: [PATCH] rework how integer locations are detected in image_to_sensor --- src/core/DICe_Camera.cpp | 14 ++++++++++++-- src/core/DICe_Camera.h | 4 +--- tests/component/DICe_TestCamera.cpp | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/core/DICe_Camera.cpp b/src/core/DICe_Camera.cpp index b09f78c0..410a91f8 100644 --- a/src/core/DICe_Camera.cpp +++ b/src/core/DICe_Camera.cpp @@ -576,8 +576,7 @@ Camera::image_to_sensor( const std::vector & image_x, const std::vector & image_y, std::vector & sen_x, - std::vector & sen_y, - const bool integer_locs) { + std::vector & sen_y) { camera_info_.check_valid(); prep_lens_distortion(); @@ -586,6 +585,17 @@ Camera::image_to_sensor( TEUCHOS_TEST_FOR_EXCEPTION(sen_x.size()!=vec_size,std::runtime_error,""); TEUCHOS_TEST_FOR_EXCEPTION(sen_y.size()!=vec_size,std::runtime_error,""); + // check for integer locations + scalar_t intpart; + bool integer_locs = true; + for (size_t i = 0; i < vec_size; i++) { + if(std::modf(image_x[i], &intpart) != 0.0 || std::modf(image_y[i], &intpart) != 0.0){ // see if there is a fractional part to the input coordinates + integer_locs = false; + break; + } + } + DEBUG_MSG("Camera::image_to_sensor(): integer locations is " << integer_locs); + //transformation from distorted image locations to undistorted sensor locations int_t index; int_t index00; diff --git a/src/core/DICe_Camera.h b/src/core/DICe_Camera.h index fb7c0595..b7c5648c 100644 --- a/src/core/DICe_Camera.h +++ b/src/core/DICe_Camera.h @@ -431,13 +431,11 @@ Camera { /// \param image_y y location after applied lens distortion /// \param sen_x projected x sensor location /// \param sen_y projected y sensor location - /// \param integer_locs if all image points are integers setting this flag avoids interpolation overhead void image_to_sensor( const std::vector & image_x, const std::vector & image_y, std::vector & sen_x, - std::vector & sen_y, - const bool integer_locs = true); + std::vector & sen_y); /// helper function to convert image coordinates to world coordinates /// \param image_x x location after applied lens distortion diff --git a/tests/component/DICe_TestCamera.cpp b/tests/component/DICe_TestCamera.cpp index add07086..2621557d 100644 --- a/tests/component/DICe_TestCamera.cpp +++ b/tests/component/DICe_TestCamera.cpp @@ -543,7 +543,7 @@ int main(int argc, char *argv[]) { img_y[i] = rand() % (image_height * 100); img_y[i] = img_y[i] / 100.0; } - test_cam.image_to_sensor(img_x, img_y, sen_x, sen_y, false); + test_cam.image_to_sensor(img_x, img_y, sen_x, sen_y); test_cam.sensor_to_image(sen_x, sen_y, ret_x, ret_y); for (int_t i = 0; i < num_points; i++) { if (max_deviation < abs(ret_x[i] - img_x[i])) max_deviation = abs(ret_x[i] - img_x[i]);