Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
omni::WarpGrid Class Reference

A warp grid is a 2D bezier grid with MxN points Default size 6x6 points. Selected points are also stored: More...

#include <WarpGrid.h>

Collaboration diagram for omni::WarpGrid:
Collaboration graph
[legend]

Public Types

enum  Interpolation { Interpolation::BICUBIC, Interpolation::LINEAR }
 

Public Member Functions

 WarpGrid ()
 Default constructor. More...
 
void reset ()
 Resets all points to form a regular grid. More...
 
void resize (int _horz, int _vert)
 Resize grid with given horizontal and vertical resolution. More...
 
int vertical () const
 Return vertical resolution. More...
 
int horizontal () const
 Return horizontal resolution. More...
 
Interpolation interpolation () const
 Return interpolation type (BICUBIC is default) More...
 
void setInterpolation (Interpolation)
 Interpolation value. More...
 
bool isReset () const
 Returns true if all warp points are in regular position. More...
 
bool hasChanged () const
 Return true if warp grid has changed. More...
 
void selectAll ()
 Select all points. More...
 
WarpPointselectNearest (const QPointF &_p)
 Select nearest point, does not clear selection, returns pointer to. More...
 
void selectNone ()
 Clear selection. More...
 
std::set< WarpPoint * > getSelected ()
 Returns pointer set of selected points. More...
 
std::set< WarpPoint const * > getSelected () const
 Returns pointer set of selected points (const version) More...
 
WarpPointgetPoint (int x, int y)
 Get point with x and y index. More...
 
WarpPoint const * getPoint (int x, int y) const
 Get point with x and y index (const version) More...
 
QVector2D getWarpPointPos (int x, int y) const
 Return position of warp point. More...
 
QVector2D getWarpPointPos (int x, int y, float u, float v) const
 Return interpolated position of warp point x, y. More...
 
QVector2D getTexCoord (int _x, int _y) const
 Return texture coordinate on x,y index. More...
 
std::vector< WarpPoint > const & points () const
 Return const reference to warp points. More...
 

Private Types

typedef std::array< QVector2D, 4 > array4_type
 

Private Member Functions

size_t getNearest (const QPointF &_p) const
 Return index to nearest point. More...
 
QVector2D cubicInterpolate (const array4_type &_points, float t) const
 Interpolate four points. More...
 

Private Attributes

int horizontal_ = 4
 
int vertical_ = 4
 
bool hasChanged_ = true
 
Interpolation interpolation_ = Interpolation::BICUBIC
 
std::vector< WarpPointpoints_
 

Friends

bool operator== (WarpGrid const &, WarpGrid const &)
 Test for equality (is equal if all warp points are equal. More...
 

Detailed Description

A warp grid is a 2D bezier grid with MxN points Default size 6x6 points. Selected points are also stored:

Member Typedef Documentation

typedef std::array<QVector2D, 4> omni::WarpGrid::array4_type
private

Member Enumeration Documentation

Enumerator
BICUBIC 
LINEAR 
34  {
35  BICUBIC,
36  LINEAR
37  };

Constructor & Destructor Documentation

omni::WarpGrid::WarpGrid ( )

Default constructor.

28  :
29  horizontal_(4),
30  vertical_(4)
31  {
32  reset();
33  }
void reset()
Resets all points to form a regular grid.
Definition: WarpGrid.cpp:41
int vertical_
Definition: WarpGrid.h:123
int horizontal_
Definition: WarpGrid.h:122

Member Function Documentation

QVector2D omni::WarpGrid::cubicInterpolate ( const array4_type _points,
float  t 
) const
private

Interpolate four points.

141  {
142  return knots[1] + 0.5f * t * (knots[2] - knots[0] +
143  t * (2.0f * knots[0] - 5.0f * knots[1] +
144  4.0f * knots[2] - knots[3] +
145  t * (3.0f * (knots[1] - knots[2]) +
146  knots[3] - knots[0])));
147  }
size_t omni::WarpGrid::getNearest ( const QPointF &  _p) const
private

Return index to nearest point.

220  {
221  float _nearestDist = std::numeric_limits<float>::max();
222  size_t _nearestIdx = -1;
223 
224  for (size_t i = 0; i < points_.size(); ++i)
225  {
226  auto& _point = points_[i];
227  auto _dist = QVector2D(_p - _point.pos()).lengthSquared();
228 
229  if (_dist < _nearestDist)
230  {
231  _nearestIdx = i;
232  _nearestDist = _dist;
233  }
234  }
235  return _nearestIdx;
236  }
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
WarpPoint * omni::WarpGrid::getPoint ( int  x,
int  y 
)

Get point with x and y index.

201  {
202  if ((x < 0) || (y < 0)) return nullptr;
203 
204  if ((x >= horizontal_) || (y >= vertical_)) return nullptr;
205  hasChanged_ = true;
206 
207  return &points_[y * horizontal_ + x];
208  }
int vertical_
Definition: WarpGrid.h:123
bool hasChanged_
Definition: WarpGrid.h:124
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
int horizontal_
Definition: WarpGrid.h:122
WarpPoint const * omni::WarpGrid::getPoint ( int  x,
int  y 
) const

Get point with x and y index (const version)

211  {
212  if ((x < 0) || (y < 0)) return nullptr;
213 
214  if ((x >= horizontal_) || (y >= vertical_)) return nullptr;
215 
216  return &points_[y * horizontal_ + x];
217  }
int vertical_
Definition: WarpGrid.h:123
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
int horizontal_
Definition: WarpGrid.h:122
std::set< WarpPoint * > omni::WarpGrid::getSelected ( )

Returns pointer set of selected points.

181  {
182  std::set<WarpPoint *> _selection;
183 
184  hasChanged_ = true;
185 
186  for (auto& _point : points_)
187  if (_point.selected()) _selection.insert(&_point);
188  return _selection;
189  }
bool hasChanged_
Definition: WarpGrid.h:124
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
std::set< WarpPoint const * > omni::WarpGrid::getSelected ( ) const

Returns pointer set of selected points (const version)

192  {
193  std::set<WarpPoint const *> _selection;
194 
195  for (auto& _point : points_)
196  if (_point.selected()) _selection.insert(&_point);
197  return _selection;
198  }
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
QVector2D omni::WarpGrid::getTexCoord ( int  _x,
int  _y 
) const

Return texture coordinate on x,y index.

36  {
37  return QVector2D(float(_x) / (horizontal() - 1),
38  float(_y) / (vertical() - 1));
39  }
int horizontal() const
Return horizontal resolution.
Definition: WarpGrid.cpp:68
int vertical() const
Return vertical resolution.
Definition: WarpGrid.cpp:63
QVector2D omni::WarpGrid::getWarpPointPos ( int  x,
int  y 
) const

Return position of warp point.

105  {
106  int maxX = horizontal() - 1;
107  int maxY = vertical() - 1;
108 
109  // here's the magic: extrapolate points beyond the edges
110  if (x < 0) {
111  return QVector2D(
112  2.0f * getWarpPointPos(0, y) - getWarpPointPos(0 - x, y));
113  }
114 
115  if (y < 0) {
116  return QVector2D(
117  2.0f * getWarpPointPos(x, 0) - getWarpPointPos(x, 0 - y));
118  }
119 
120  if (x > maxX) {
121  return QVector2D(2.0f * getWarpPointPos(maxX, y) - getWarpPointPos(
122  2 * maxX - x,
123  y));
124  }
125 
126  if (y > maxY) {
127  return QVector2D(
128  2.0f * getWarpPointPos(x, maxY)
129  - getWarpPointPos(x, 2 * maxY - y));
130  }
131 
132 
133  return QVector2D(getPoint(x, y)->pos());
134  }
WarpPoint * getPoint(int x, int y)
Get point with x and y index.
Definition: WarpGrid.cpp:200
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
QVector2D omni::WarpGrid::getWarpPointPos ( int  x,
int  y,
float  u,
float  v 
) const

Return interpolated position of warp point x, y.

149  {
150  switch (interpolation_) {
151  default:
152 
153  // perform linear interpolation
155  {
156  auto _p00 = getWarpPointPos(x + 0, y + 0);
157  auto _p10 = getWarpPointPos(x + 1, y + 0);
158  auto _p01 = getWarpPointPos(x + 0, y + 1);
159  auto _p11 = getWarpPointPos(x + 1, y + 1);
160  QVector2D p1((1.0f - u) * _p00 + u * _p10);
161  QVector2D p2((1.0f - u) * _p01 + u * _p11);
162  return QVector2D((1.0f - v) * p1 + v * p2);
163  }
164  // perform bicubic interpolation
166  {
167  array4_type _rows, _cols;
168  for (int i = -1; i < 3; ++i) {
169  for (int j = -1; j < 3; ++j) {
170  _cols[j + 1] = getWarpPointPos(x + i, y + j);
171  }
172  _rows[i + 1] = cubicInterpolate(_cols, v);
173  }
174  return cubicInterpolate(_rows, u);
175  }
176  }
177  return QVector2D(0.0, 0.0);
178  }
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
Interpolation interpolation_
Definition: WarpGrid.h:125
QVector2D getWarpPointPos(int x, int y) const
Return position of warp point.
Definition: WarpGrid.cpp:104
bool omni::WarpGrid::hasChanged ( ) const

Return true if warp grid has changed.

251  {
252  return hasChanged_;
253  }
bool hasChanged_
Definition: WarpGrid.h:124
int omni::WarpGrid::horizontal ( ) const

Return horizontal resolution.

69  {
70  return horizontal_;
71  }
int horizontal_
Definition: WarpGrid.h:122
WarpGrid::Interpolation omni::WarpGrid::interpolation ( ) const

Return interpolation type (BICUBIC is default)

74  {
75  return interpolation_;
76  }
Interpolation interpolation_
Definition: WarpGrid.h:125
bool omni::WarpGrid::isReset ( ) const

Returns true if all warp points are in regular position.

239  {
240  for (size_t y = 0; y < vertical(); ++y)
241  for (size_t x = 0; x < horizontal(); ++x)
242  {
243  if (QVector2D(getPoint(x,
244  y)->pos()) !=
245  (getTexCoord(x, y) - QVector2D(0.5, 0.5))) return false;
246  }
247 
248  return true;
249  }
QVector2D getTexCoord(int _x, int _y) const
Return texture coordinate on x,y index.
Definition: WarpGrid.cpp:35
WarpPoint * getPoint(int x, int y)
Get point with x and y index.
Definition: WarpGrid.cpp:200
int horizontal() const
Return horizontal resolution.
Definition: WarpGrid.cpp:68
int vertical() const
Return vertical resolution.
Definition: WarpGrid.cpp:63
std::vector< WarpPoint > const & omni::WarpGrid::points ( ) const

Return const reference to warp points.

256  {
257  return points_;
258  }
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
void omni::WarpGrid::reset ( )

Resets all points to form a regular grid.

42  {
43  points_.clear();
44  points_.reserve(vertical() * horizontal());
45 
46  for (size_t y = 0; y < vertical(); ++y)
47  for (size_t x = 0; x < horizontal();
48  ++x) points_.emplace_back((getTexCoord(x, y) - QVector2D(0.5,
49  0.5)).toPointF());
50  hasChanged_ = true;
51  }
QVector2D getTexCoord(int _x, int _y) const
Return texture coordinate on x,y index.
Definition: WarpGrid.cpp:35
bool hasChanged_
Definition: WarpGrid.h:124
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
int horizontal() const
Return horizontal resolution.
Definition: WarpGrid.cpp:68
int vertical() const
Return vertical resolution.
Definition: WarpGrid.cpp:63
void omni::WarpGrid::resize ( int  _horz,
int  _vert 
)

Resize grid with given horizontal and vertical resolution.

54  {
55  if ((_horz < 2) || (_vert < 2) ||
56  ((_horz == horizontal_) && (_vert == vertical_))) return;
57 
58  horizontal_ = _horz;
59  vertical_ = _vert;
60  reset();
61  }
void reset()
Resets all points to form a regular grid.
Definition: WarpGrid.cpp:41
int vertical_
Definition: WarpGrid.h:123
int horizontal_
Definition: WarpGrid.h:122
void omni::WarpGrid::selectAll ( )

Select all points.

85  {
86  for (auto& _point : points_) _point.setSelected(true);
87  }
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
WarpPoint * omni::WarpGrid::selectNearest ( const QPointF &  _p)

Select nearest point, does not clear selection, returns pointer to.

90  {
91  size_t _nearestIdx = getNearest(_p);
92  auto _nearest =
93  (_nearestIdx == -1) ? nullptr : &points_[_nearestIdx];
94  hasChanged_ = true;
95 
96  return _nearest;
97  }
bool hasChanged_
Definition: WarpGrid.h:124
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
size_t getNearest(const QPointF &_p) const
Return index to nearest point.
Definition: WarpGrid.cpp:219
void omni::WarpGrid::selectNone ( )

Clear selection.

100  {
101  for (auto& _point : points_) _point.setSelected(false);
102  }
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
void omni::WarpGrid::setInterpolation ( Interpolation  _interpolation)

Interpolation value.

79  {
80  interpolation_ = _interpolation;
81  hasChanged_ = true;
82  }
bool hasChanged_
Definition: WarpGrid.h:124
Interpolation interpolation_
Definition: WarpGrid.h:125
int omni::WarpGrid::vertical ( ) const

Return vertical resolution.

64  {
65  return vertical_;
66  }
int vertical_
Definition: WarpGrid.h:123

Friends And Related Function Documentation

bool operator== ( WarpGrid const &  _lhs,
WarpGrid const &  _rhs 
)
friend

Test for equality (is equal if all warp points are equal.

261  {
262  return
266  }
int vertical_
Definition: WarpGrid.h:123
#define OMNI_TEST_MEMBER_EQUAL(member)
Definition: util.h:125
std::vector< WarpPoint > points_
Definition: WarpGrid.h:126
int horizontal_
Definition: WarpGrid.h:122

Field Documentation

bool omni::WarpGrid::hasChanged_ = true
private
int omni::WarpGrid::horizontal_ = 4
private
Interpolation omni::WarpGrid::interpolation_ = Interpolation::BICUBIC
private
std::vector<WarpPoint> omni::WarpGrid::points_
private
int omni::WarpGrid::vertical_ = 4
private

The documentation for this class was generated from the following files: