mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
image_camera.h
Go to the documentation of this file.
1 #ifndef MF_IMAGE_CAMERA_H_
2 #define MF_IMAGE_CAMERA_H_
3 
4 #include <cstddef>
5 #include <array>
6 #include "camera.h"
7 #include "../common.h"
8 #include "../ndarray/ndspan.h"
9 
10 namespace mf {
11 
13 
16 class image_camera {
17 private:
18  ndsize<2> image_size_;
19  bool flipped_ = false;
20 
21 protected:
22  explicit image_camera(const ndsize<2>&);
23 
24 public:
27 
28  image_camera(const image_camera&) = default;
29 
30  real image_aspect_ratio() const;
31  const ndsize<2>& image_size() const { return image_size_; }
32  std::size_t image_number_of_pixels() const { return image_size_.product(); }
33 
34  bool pixel_coordinates_flipped() const { return flipped_; }
36 
37 
39  void set_image_width(std::size_t);
40 
42  void set_image_height(std::size_t);
43 
45  return ndspan<2>( make_ndptrdiff(0, 0), image_size_ );
46  }
47 
49  auto x = static_cast<real>(pix[0]) + 0.5;
50  auto y = static_cast<real>(pix[1]) + 0.5;
51  return flipped_ ? image_coordinates_type(y, x) : image_coordinates_type(x, y);
52  }
53 
55  auto x = static_cast<std::ptrdiff_t>(im[0] - 0.5);
56  auto y = static_cast<std::ptrdiff_t>(im[1] - 0.5);
57  return flipped_ ? pixel_coordinates_type{y, x} : pixel_coordinates_type{x, y};
58  }
59 };
60 
61 }
62 
63 #endif
Eigen_vec2 image_coordinates_type
2D image coordinates, range and scale defined by subclass.
Definition: camera.h:25
float real
Real number type.
Definition: common.h:48
image_camera(const ndsize< 2 > &)
Definition: image_camera.cc:5
const ndsize< 2 > & image_size() const
Definition: image_camera.h:31
ndspan< 2 > image_span() const
Definition: image_camera.h:44
Camera which handles mapping to image coordinates, base class.
Definition: image_camera.h:16
bool pixel_coordinates_flipped() const
Definition: image_camera.h:34
void set_image_width(std::size_t)
Set image width, and adjust height to keep same aspect ratio.
Definition: image_camera.cc:14
typename camera::image_coordinates_type image_coordinates_type
Definition: image_camera.h:26
Vector of n-dimensional coordinates.
Definition: ndcoord.h:18
image_coordinates_type to_image(pixel_coordinates_type pix) const
Definition: image_camera.h:48
Cuboid n-dimensional span delimited by two ndcoord vectors.
Definition: ndspan.h:15
real image_aspect_ratio() const
Definition: image_camera.cc:9
pixel_coordinates_type to_pixel(image_coordinates_type im) const
Definition: image_camera.h:54
auto make_ndptrdiff(Components...c)
Definition: ndcoord.h:192
void set_image_height(std::size_t)
Set image height, and adjust width to keep same aspect ratio.
Definition: image_camera.cc:20
std::size_t image_number_of_pixels() const
Definition: image_camera.h:32
void flip_pixel_coordinates()
Definition: image_camera.cc:26