Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WarpGrid.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_WARPGRID_H_
21 #define OMNI_WARPGRID_H_
22 
23 #include <array>
24 #include <set>
25 #include <QVector2D>
26 #include <omni/WarpPoint.h>
27 
28 namespace omni {
29  /**@brief A warp grid is a 2D bezier grid with MxN points
30  @detail Default size 6x6 points. Selected points are also stored:
31  **/
32  class WarpGrid {
33  public:
34  enum class Interpolation {
35  BICUBIC,
36  LINEAR
37  };
38 
39  /// Default constructor
40  WarpGrid();
41 
42  /// Resets all points to form a regular grid
43  void reset();
44 
45  /// Resize grid with given horizontal and vertical resolution
46  void resize(int _horz,
47  int _vert);
48 
49  /// Return vertical resolution
50  int vertical() const;
51 
52  /// Return horizontal resolution
53  int horizontal() const;
54 
55  /// Return interpolation type (BICUBIC is default)
57 
58  /// Interpolation value
60 
61  /// Returns true if all warp points are in regular position
62  bool isReset() const;
63 
64  /// Return true if warp grid has changed
65  bool hasChanged() const;
66 
67  /// Select all points
68  void selectAll();
69 
70  /// Select nearest point, does not clear selection, returns pointer to
71  // nearest
72  WarpPoint * selectNearest(const QPointF& _p);
73 
74  /// Clear selection
75  void selectNone();
76 
77  /// Returns pointer set of selected points
78  std::set<WarpPoint *> getSelected();
79 
80  /// Returns pointer set of selected points (const version)
81  std::set<WarpPoint const *>getSelected() const;
82 
83  /// Get point with x and y index
84  WarpPoint * getPoint(int x,
85  int y);
86 
87  /// Get point with x and y index (const version)
88  WarpPoint const* getPoint(int x,
89  int y) const;
90 
91  /// Return position of warp point
92  QVector2D getWarpPointPos(int x,
93  int y) const;
94 
95  /// Return interpolated position of warp point x, y
96  QVector2D getWarpPointPos(int x,
97  int y,
98  float u,
99  float v) const;
100 
101  /// Return texture coordinate on x,y index
102  QVector2D getTexCoord(int _x,
103  int _y) const;
104 
105  /// Return const reference to warp points
106  std::vector<WarpPoint>const& points() const;
107 
108  /// Test for equality (is equal if all warp points are equal
109  friend bool operator==(WarpGrid const&,
110  WarpGrid const&);
111 
112  private:
113  /// Return index to nearest point
114  size_t getNearest(const QPointF& _p) const;
115 
116  typedef std::array<QVector2D, 4>array4_type;
117 
118  /// Interpolate four points
119  QVector2D cubicInterpolate(const array4_type& _points,
120  float t) const;
121 
122  int horizontal_ = 4;
123  int vertical_ = 4;
124  bool hasChanged_ = true;
126  std::vector<WarpPoint> points_;
127  };
128 }
129 
130 /// Serialize omni::WarpGrid to stream
131 QDataStream& operator<<(QDataStream& _os,
132  const omni::WarpGrid& _p);
133 
134 /// Deserialize omni::WarpGrid from stream
135 QDataStream& operator>>(QDataStream& _is,
136  omni::WarpGrid& _p);
137 
138 #endif /* OMNI_WARPGRID_H_ */
Interpolation
Definition: WarpGrid.h:34
std::array< QVector2D, 4 > array4_type
Definition: WarpGrid.h:116
QVector2D cubicInterpolate(const array4_type &_points, float t) const
Interpolate four points.
Definition: WarpGrid.cpp:138
bool isReset() const
Returns true if all warp points are in regular position.
Definition: WarpGrid.cpp:238
void reset()
Resets all points to form a regular grid.
Definition: WarpGrid.cpp:41
bool hasChanged() const
Return true if warp grid has changed.
Definition: WarpGrid.cpp:251
QVector2D getTexCoord(int _x, int _y) const
Return texture coordinate on x,y index.
Definition: WarpGrid.cpp:35
QDataStream & operator>>(QDataStream &_is, omni::WarpGrid &_p)
Deserialize omni::WarpGrid from stream.
Definition: WarpGrid.cpp:282
int vertical_
Definition: WarpGrid.h:123
void resize(int _horz, int _vert)
Resize grid with given horizontal and vertical resolution.
Definition: WarpGrid.cpp:53
WarpPoint * getPoint(int x, int y)
Get point with x and y index.
Definition: WarpGrid.cpp:200
WarpGrid()
Default constructor.
Definition: WarpGrid.cpp:28
void selectAll()
Select all points.
Definition: WarpGrid.cpp:84
std::vector< WarpPoint > const & points() const
Return const reference to warp points.
Definition: WarpGrid.cpp:255
void selectNone()
Clear selection.
Definition: WarpGrid.cpp:99
bool hasChanged_
Definition: WarpGrid.h:124
A warp grid is a 2D bezier grid with MxN points Default size 6x6 points. Selected points are also st...
Definition: WarpGrid.h:32
Interpolation interpolation() const
Return interpolation type (BICUBIC is default)
Definition: WarpGrid.cpp:74
Interpolation interpolation_
Definition: WarpGrid.h:125
std::set< WarpPoint * > getSelected()
Returns pointer set of selected points.
Definition: WarpGrid.cpp:180
A Warp defines a bezier point with one position and two handles / * Also stores flag if it is selecte...
Definition: WarpPoint.h:30
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
QDataStream & operator<<(QDataStream &_os, const omni::WarpGrid &_p)
Serialize omni::WarpGrid to stream.
Definition: WarpGrid.cpp:269
friend bool operator==(WarpGrid const &, WarpGrid const &)
Test for equality (is equal if all warp points are equal.
Definition: WarpGrid.cpp:260
int horizontal_
Definition: WarpGrid.h:122
QVector2D getWarpPointPos(int x, int y) const
Return position of warp point.
Definition: WarpGrid.cpp:104
int horizontal() const
Return horizontal resolution.
Definition: WarpGrid.cpp:68
int vertical() const
Return vertical resolution.
Definition: WarpGrid.cpp:63
WarpPoint * selectNearest(const QPointF &_p)
Select nearest point, does not clear selection, returns pointer to.
Definition: WarpGrid.cpp:89
void setInterpolation(Interpolation)
Interpolation value.
Definition: WarpGrid.cpp:79
size_t getNearest(const QPointF &_p) const
Return index to nearest point.
Definition: WarpGrid.cpp:219