46#ifndef UFO_VISION_CAMERA_ORTHOGONAL_HPP
47#define UFO_VISION_CAMERA_ORTHOGONAL_HPP
50#include <ufo/execution/algorithm.hpp>
51#include <ufo/execution/execution.hpp>
52#include <ufo/geometry/ray.hpp>
53#include <ufo/numeric/mat.hpp>
54#include <ufo/numeric/transform.hpp>
55#include <ufo/numeric/vec.hpp>
56#include <ufo/vision/camera/orthogonal_intrinsics.hpp>
57#include <ufo/vision/image.hpp>
111 [[nodiscard]]
Mat4f projection()
const
121 [[nodiscard]] Mat4f view()
const {
return Mat4f(
pose); }
123 [[nodiscard]] Image<Ray3f> rays()
const {
return rays(ufo::execution::seq); }
125 template <
class ExecutionPolicy>
126 [[nodiscard]] Image<Ray3f> rays(ExecutionPolicy&& policy)
const
128 auto const proj_inv =
inverse(projection());
129 auto const view_inv = view();
133 [&rays, &proj_inv, &view_inv](std::size_t y) {
134 float const vy = ((y + 0.5f) / rays.rows()) * 2.0f - 1.0f;
135 for (std::size_t x{}; rays.cols() > x; ++x) {
136 float const vx = ((x + 0.5f) / rays.cols()) * 2.0f - 1.0f;
137 Vec3f origin(ufo::convert<Vec3f>(view_inv * proj_inv *
138 Vec4f(vx, vy, 0.0f, 1.0f)));
140 ufo::convert<Vec3f>(view_inv * Vec4f(0.0f, 0.0f, 1.0f, 0.0f)));
141 rays[y, x] = {origin, direction};
147 [[nodiscard]]
friend bool operator==(OrthogonalCamera
const&,
148 OrthogonalCamera
const&)
noexcept =
default;
156 os <<
"Pose: " << camera.
pose <<
'\n'
158 <<
", Far clip: " << camera.
far_clip <<
'\n';
168struct std::formatter<
ufo::OrthogonalCamera> {
169 constexpr auto parse(std::format_parse_context& ctx)
const {
return ctx.begin(); }
173 return std::format_to(ctx.out(),
"Pose: {}\n{}\nNear clip: {}, Far clip: {}",
Mat< 4, 4, T > orthogonal(T left, T right, T bottom, T top)
Builds a right-handed 2-D orthographic projection matrix (no depth clipping).
All vision-related classes and functions.
constexpr UnaryFunc for_each(Index first, Index last, UnaryFunc f, Proj proj={})
Applies f to each integer index in [first, last) sequentially.
constexpr M inverse(M const &m) noexcept
Computes the inverse of a square floating-point matrix.
Mat< 4, 4, T > lookAt(Vec< 3, T > const &eye, Vec< 3, T > const &target, Vec< 3, T > const &up)
Builds a view matrix (OpenCV convention).
Orthogonal camera model for ray-generation and projection.
Transform3f pose
Camera-to-world pose transform.
void lookAt(Vec3f center, Vec3f const &target, Vec3f const &up)
Orients the camera so it looks from center toward target.
OrthogonalIntrinsics intrinsics
The intrinsic parameters of the camera.
float near_clip
Distance to the near clipping plane.
float far_clip
Distance to the far clipping plane.
Stores the intrinsic parameters of an orthogonal camera.
float height
Viewport height in world-space units (e.g., meters).
std::size_t rows
Image height in pixels.
float width
Viewport width in world-space units (e.g., meters).
std::size_t cols
Image width in pixels.