Skip to content

Commit a11bef3

Browse files
Fix the rectilinear camera projection so it doesn't mirror points behind the camera.
This shouldn't be an issue normally as the visual mesh cuts off points that are outside of the camera's view
1 parent 67d72b7 commit a11bef3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

cpp/visualmesh/engine/opencl/kernels/project_rectilinear.cl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
*/
1717

18+
#ifndef M_PI_2
19+
#define M_PI_2 1.57079632679489661923132169163975144
20+
#endif
21+
1822
/**
1923
* Projects visual mesh points to a rectilinear camera
2024
*
@@ -52,7 +56,7 @@ kernel void project_rectilinear(global const Scalar4* points,
5256
// Calculate some intermediates
5357
const Scalar theta = acos(ray.x);
5458
const Scalar rsin_theta = rsqrt((Scalar)(1.0) - ray.x * ray.x);
55-
const Scalar r_u = f * tan(theta);
59+
const Scalar r_u = f * tan(clamp(theta, 0.0, M_PI_2));
5660
const Scalar r_d = r_u
5761
* (1.0 //
5862
+ k.x * (r_u * r_u) //

cpp/visualmesh/utility/projection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace equisolid {
5050
namespace rectilinear {
5151
template <typename Scalar>
5252
inline Scalar r(const Scalar& theta, const Scalar& f) {
53-
return f * std::tan(theta);
53+
return f * std::tan(std::min(std::max(theta, Scalar(0.0)), Scalar(M_PI_2)));
5454
}
5555

5656
template <typename Scalar>

training/projection/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import math
2+
13
import tensorflow as tf
24

35

@@ -26,7 +28,7 @@ def _equidistant_r(theta, f):
2628

2729

2830
def _rectilinear_r(theta, f):
29-
return f * tf.math.tan(theta)
31+
return f * tf.math.tan(tf.clip_by_value(theta, 0.0, math.pi * 0.5))
3032

3133

3234
def _equisolid_r(theta, f):

0 commit comments

Comments
 (0)