OGLplus (0.52.0) a C++ wrapper for OpenGL

transformed.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_IMAGES_TRANSFORMED_1107121519_HPP
14 #define OGLPLUS_IMAGES_TRANSFORMED_1107121519_HPP
15 
17 #include <oglplus/math/matrix.hpp>
18 
19 namespace oglplus {
20 namespace images {
21 
23 
26 template <typename T, typename std::size_t N>
28  : public FilteredImage<T, N>
29 {
30 private:
31  struct _filter
32  {
33  Mat4d _matrix;
34 
35  _filter(const Mat4d& matrix)
36  : _matrix(matrix)
37  { }
38 
39  template <typename Extractor, typename Sampler>
40  Vector<T, N> operator()(
41  const Extractor& extractor,
42  const Sampler& sampler,
43  T one
44  ) const
45  {
47  extractor(sampler(0, 0, 0)),
48  1.0
49  ));
50  const Vector<double, N> res = _matrix*c*one;
51  return Vector<T, N>(res);
52  }
53  };
54 public:
56 
57  TransformComponents(const Image& input, const Mat4d& matrix)
58  : Filtered(
59  input,
60  _filter(matrix),
61  typename Filtered::DefaultSampler(),
62  typename Filtered::FromRGB()
63  )
64  {
65  this->_format = PixelDataFormat::RGB;
66  this->_internal = PixelDataInternalFormat::RGB;
67  }
68 };
69 
71 
74 template <typename T, std::size_t N>
76  : public FilteredImage<T, N>
77 {
78 private:
80 
81  static Matrix<double, 4, 4> _make_matrix(
82  int x_axis,
83  int y_axis,
84  int z_axis
85  )
86  {
87  typedef Vector<double, 3> V3d;
88  V3d x = (x_axis<0) ? -V3d::Unit(-x_axis) : V3d::Unit(x_axis);
89  V3d y = (y_axis<0) ? -V3d::Unit(-y_axis) : V3d::Unit(y_axis);
90  V3d z = (z_axis<0) ? -V3d::Unit(-z_axis) : V3d::Unit(z_axis);
91 
92  return Matrix<double, 4, 4>(
93  x.x(), x.y(), x.z(), 0,
94  y.x(), y.y(), y.z(), 0,
95  z.x(), z.y(), z.z(), 0,
96  0, 0, 0, 1
97  );
98  }
99 public:
100  FlipImageAxes(const Image& image, int x_axis, int y_axis, int z_axis)
101  : Filtered(
102  image,
103  typename Filtered::DefaultFilter(),
104  typename Filtered::template MatrixTransformSampler<
105  typename Filtered::RepeatSample
106  >(_make_matrix(x_axis, y_axis, z_axis)),
107  typename Filtered::template FirstNComponents<N>()
108  )
109  { }
110 };
111 
112 } // images
113 } // oglplus
114 
115 #endif // include guard
Object< SamplerOps > Sampler
An oglplus_object encapsulating the OpenGL sampler functionality.
Definition: sampler.hpp:877
Base class for image filters.
Base class for various image filters.
Definition: filtered.hpp:32
A filter flipping/reorienting image axes.
Definition: transformed.hpp:75
Wrapper for (texture) image data.
Definition: image.hpp:45
A filter transforming image RGB components by a 4x4 matrix.
Definition: transformed.hpp:27
Basic template for vector types.
Definition: fwd.hpp:43
A matrix class.

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).