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

BlendBrush for drawing on the blendmask Holds an internal pixel buffer. More...

#include <BlendBrush.h>

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

Public Member Functions

 BlendBrush ()
 Default constructor. More...
 
 BlendBrush (QVector2D const &_size, float _feather=1.0)
 Constructor with a size and feather value (1.0 by default) Updates internal pixel buffer. More...
 
QVector2D const & size () const
 Returns brush size. More...
 
void setSize (QVector2D const &_size)
 Sets size of the brush. Minimum size is 2 pixels, maximum size is 512 pixels. More...
 
void changeSize (QVector2D const &_delta)
 Increase/Decrease size of the brush with a certain delta value Minimum size is 2 pixels, maximum size is 512 pixels. More...
 
float feather () const
 Return feather value. More...
 
float opacity () const
 Return opacity value. More...
 
void setOpacity (float _opacity)
 Set opacity value Value must be between 0.0 and 1.0 and is clamped if necessary. A value 0.0 means a hard brush, a value of 1.0 means soft brush. More...
 
void setFeather (float _feather)
 Set feather value Value must be between 0.0 and 1.0 and is clamped if necessary. A value 0.0 means a hard brush, a value of 1.0 means soft brush. More...
 
bool invert () const
 Returns true if the brush is inverted (aka eraser mode) More...
 
void setInvert (bool _invert)
 Sets inverted flag of the brush. More...
 
void setBrush (QVector2D const &_size, float _feather, float _opacity, bool _invert)
 Set brush settings and generate pixel buffer. More...
 
void stamp (const QPointF &_pos, Buffer< uint8_t > &_buf) const
 Draws internal pixel buffer in given blend buffer. More...
 
float drawLine (const QPointF &_p0, const QPointF &_p1, Buffer< uint8_t > &_buf, float _leftOver=0.0)
 Draws a lot from point _p0 to _p1 on given pixel buffer. More...
 
Buffer< float > const & buffer () const
 
void toStream (QDataStream &) const
 Write blend brush to stream. More...
 
void fromStream (QDataStream &)
 Read blend brush from stream. More...
 

Private Member Functions

void generate ()
 Generate internal pixel buffer with given size and feather parameters. More...
 

Static Private Member Functions

static QVector2D clampBrushSize (QVector2D const &)
 Keep brush size within certain limits. More...
 

Private Attributes

Buffer< float > buffer_
 Internal pixel buffer. More...
 
float opacity_ = 1.0
 
QVector2D size_
 
float feather_ = 1.0
 
bool invert_ = false
 

Friends

bool operator== (BlendBrush const &, BlendBrush const &)
 Test for equality, buffer is ignored. More...
 

Detailed Description

BlendBrush for drawing on the blendmask Holds an internal pixel buffer.

Constructor & Destructor Documentation

omni::BlendBrush::BlendBrush ( )

Default constructor.

29  : size_(100.0,100.0)
30  {
31  generate();
32  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
QVector2D size_
Definition: BlendBrush.h:129
omni::BlendBrush::BlendBrush ( QVector2D const &  _size,
float  _feather = 1.0 
)

Constructor with a size and feather value (1.0 by default) Updates internal pixel buffer.

34  :
35  size_(_size),
36  feather_(_feather)
37  {
38  generate();
39  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
QVector2D size_
Definition: BlendBrush.h:129
float feather_
Definition: BlendBrush.h:130

Member Function Documentation

Buffer< float > const & omni::BlendBrush::buffer ( ) const
206  {
207  return buffer_;
208  }
Buffer< float > buffer_
Internal pixel buffer.
Definition: BlendBrush.h:126
void omni::BlendBrush::changeSize ( QVector2D const &  _delta)

Increase/Decrease size of the brush with a certain delta value Minimum size is 2 pixels, maximum size is 512 pixels.

53  {
54  setSize(size_ + _delta);
55  }
void setSize(QVector2D const &_size)
Sets size of the brush. Minimum size is 2 pixels, maximum size is 512 pixels.
Definition: BlendBrush.cpp:46
QVector2D size_
Definition: BlendBrush.h:129
QVector2D omni::BlendBrush::clampBrushSize ( QVector2D const &  _size)
staticprivate

Keep brush size within certain limits.

237  {
238  float _aspect = _size.x() / _size.y();
239  return QVector2D(
240  qBound(30.0f,_size.x(), 400.0f),
241  qBound(30.0f / _aspect,_size.y(), 400.0f / _aspect));
242  }
float omni::BlendBrush::drawLine ( const QPointF &  _p0,
const QPointF &  _p1,
Buffer< uint8_t > &  _buf,
float  _leftOver = 0.0 
)

Draws a lot from point _p0 to _p1 on given pixel buffer.

Parameters
_p0Start point
_p1End point
_bufBuffer to be drawn
_leftOverLeft over value to compensate positioning errors from previous moves
Returns
New left over value
162  {
163  float _spacing = size_.length() / 10.0;
164  if (_spacing < 0.5) _spacing = 0.5;
165 
166  QVector2D _step(0.0, 0.0);
167 
168  // Calculate vector and distance
169  QVector2D _delta(_p1 - _p0);
170  float _dist = _delta.length();
171 
172  float _invDist = 0.0;
173 
174  if (_dist > 0.0)
175  {
176  _invDist = 1.0 / _dist;
177  _step += _delta * _invDist;
178  }
179 
180  // Draw line
181  QVector2D _offset(0.0, 0.0);
182  float _totalDistance = _leftOver + _dist;
183 
184  while (_totalDistance >= _spacing)
185  {
186  if (_leftOver > 0)
187  {
188  _offset += _step * (_spacing - _leftOver);
189  _leftOver -= _spacing;
190  }
191  else
192  {
193  _offset += _step * _spacing;
194  }
195 
196  // Draw stamp
197  stamp(_p0 + _offset.toPointF(), _buf);
198 
199  _totalDistance -= _spacing;
200  }
201 
202  return _totalDistance;
203  }
void stamp(const QPointF &_pos, Buffer< uint8_t > &_buf) const
Draws internal pixel buffer in given blend buffer.
Definition: BlendBrush.cpp:124
QVector2D size_
Definition: BlendBrush.h:129
float omni::BlendBrush::feather ( ) const

Return feather value.

75  {
76  return feather_;
77  }
float feather_
Definition: BlendBrush.h:130
void omni::BlendBrush::fromStream ( QDataStream &  _is)

Read blend brush from stream.

256  {
257  PropertyMap _map;
258  _is >> _map;
259  _map.get("size", size_);
260  _map.get("feather", feather_);
261  _map.get("opacity", opacity_);
262  _map.get("invert", invert_);
263  generate();
264  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
bool invert_
Definition: BlendBrush.h:131
QVector2D size_
Definition: BlendBrush.h:129
float feather_
Definition: BlendBrush.h:130
float opacity_
Definition: BlendBrush.h:128
void omni::BlendBrush::generate ( )
private

Generate internal pixel buffer with given size and feather parameters.

211  {
212  int _sizeX = std::max(int(size().x() + 1), 2);
213  int _sizeY = std::max(int(size().y() + 1), 2);
214  buffer_.resize(_sizeX, _sizeY);
215 
216  float _r = 0.49;
217  float _innerRadius = _r - _r * feather();
218 
219 
220  // For each pixel
221  for (int y = 0; y < _sizeY; ++y)
222  for (int x = 0; x < _sizeX; ++x)
223  {
224  QVector2D _pos(float(x) / _sizeX - 0.5, float(y) / _sizeY - 0.5);
225 
226  float _distance = _pos.length();
227 
228  // Pixel value
229  float _v = ((_distance - _innerRadius) / (_r - _innerRadius)) *
230  opacity_ + 1.0 - opacity_;
231 
232  // Clamp and set pixel value
233  buffer_(x, y) = qBound(0.0f, _v, 1.0f);
234  }
235  }
QVector2D const & size() const
Returns brush size.
Definition: BlendBrush.cpp:41
float feather() const
Return feather value.
Definition: BlendBrush.cpp:74
void resize(int _width, int _height)
Resize buffer to given width and height.
Definition: Buffer.h:172
float opacity_
Definition: BlendBrush.h:128
Buffer< float > buffer_
Internal pixel buffer.
Definition: BlendBrush.h:126
bool omni::BlendBrush::invert ( ) const

Returns true if the brush is inverted (aka eraser mode)

90  {
91  return invert_;
92  }
bool invert_
Definition: BlendBrush.h:131
float omni::BlendBrush::opacity ( ) const

Return opacity value.

57  {
58  return opacity_;
59  }
float opacity_
Definition: BlendBrush.h:128
void omni::BlendBrush::setBrush ( QVector2D const &  _size,
float  _feather,
float  _opacity,
bool  _invert 
)

Set brush settings and generate pixel buffer.

104  {
105  size_ = clampBrushSize(_size);
106 
107  feather_ = _feather;
108 
109  if (feather_ < 0.0) feather_ = 0.0;
110  if (feather_ > 10.0) feather_ = 10.0;
111  invert_ = _invert;
112 
113  if (opacity_ < 0.0) {
114  opacity_ = 0.0;
115  }
116 
117  if (opacity_ > 1.0) {
118  opacity_ = 1.0;
119  }
120  opacity_ = _opacity;
121  generate();
122  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
bool invert_
Definition: BlendBrush.h:131
static QVector2D clampBrushSize(QVector2D const &)
Keep brush size within certain limits.
Definition: BlendBrush.cpp:237
QVector2D size_
Definition: BlendBrush.h:129
float feather_
Definition: BlendBrush.h:130
float opacity_
Definition: BlendBrush.h:128
void omni::BlendBrush::setFeather ( float  _feather)

Set feather value Value must be between 0.0 and 1.0 and is clamped if necessary. A value 0.0 means a hard brush, a value of 1.0 means soft brush.

80  {
81  feather_ = _feather;
82 
83  if (feather_ < 0.0) feather_ = 0.0;
84 
85  if (feather_ > 10.0) feather_ = 10.0;
86  generate();
87  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
float feather_
Definition: BlendBrush.h:130
void omni::BlendBrush::setInvert ( bool  _invert)

Sets inverted flag of the brush.

95  {
96  invert_ = _invert;
97  generate();
98  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
bool invert_
Definition: BlendBrush.h:131
void omni::BlendBrush::setOpacity ( float  _opacity)

Set opacity value Value must be between 0.0 and 1.0 and is clamped if necessary. A value 0.0 means a hard brush, a value of 1.0 means soft brush.

61  {
62  opacity_ = _opacity;
63 
64  if (opacity_ < 0.0) {
65  opacity_ = 0.0;
66  }
67 
68  if (opacity_ > 1.0) {
69  opacity_ = 1.0;
70  }
71  generate();
72  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
float opacity_
Definition: BlendBrush.h:128
void omni::BlendBrush::setSize ( QVector2D const &  _size)

Sets size of the brush. Minimum size is 2 pixels, maximum size is 512 pixels.

47  {
48  size_ = clampBrushSize(_size);
49  generate();
50  }
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
static QVector2D clampBrushSize(QVector2D const &)
Keep brush size within certain limits.
Definition: BlendBrush.cpp:237
QVector2D size_
Definition: BlendBrush.h:129
QVector2D const & omni::BlendBrush::size ( ) const

Returns brush size.

42  {
43  return size_;
44  }
QVector2D size_
Definition: BlendBrush.h:129
void omni::BlendBrush::stamp ( const QPointF &  _pos,
Buffer< uint8_t > &  _buf 
) const

Draws internal pixel buffer in given blend buffer.

125  {
126  int _sizeX = size().x();
127  int _sizeY = size().y();
128  QVector2D r = size() * 0.5;
129 
130  int dx = _p.x() - r.x();
131  int dy = _p.y() - r.y();
132 
133  for (int i = 0; i < _sizeX; ++i)
134  {
135  int _posx = int(i + dx);
136 
137  if ((_posx < 0) || (_posx >= _buf.width())) continue;
138 
139  for (int j = 0; j < _sizeY; ++j)
140  {
141  int _posy = int(j + dy);
142 
143  if ((_posy < 0) || (_posy >= _buf.height())) continue;
144 
145  auto _v = buffer_(i, j);
146  auto& _pix = _buf(_posx, _posy);
147 
148  if (invert())
149  {
150  _pix = _pix * _v;
151  }
152  else
153  {
154  _pix = (255 - (255 - _buf(_posx, _posy)) * _v);
155  }
156  }
157  }
158  }
QVector2D const & size() const
Returns brush size.
Definition: BlendBrush.cpp:41
int height() const
Return height of the buffer.
Definition: Buffer.h:137
bool invert() const
Returns true if the brush is inverted (aka eraser mode)
Definition: BlendBrush.cpp:89
int width() const
Return width of the buffer.
Definition: Buffer.h:131
Buffer< float > buffer_
Internal pixel buffer.
Definition: BlendBrush.h:126
void omni::BlendBrush::toStream ( QDataStream &  _os) const

Write blend brush to stream.

245  {
246  PropertyMap _map;
247 
248  _map("size", size_)
249  ("feather", feather_)
250  ("opacity", opacity_)
251  ("invert", invert_);
252  _os << _map;
253  }
bool invert_
Definition: BlendBrush.h:131
QVector2D size_
Definition: BlendBrush.h:129
float feather_
Definition: BlendBrush.h:130
float opacity_
Definition: BlendBrush.h:128

Friends And Related Function Documentation

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

Test for equality, buffer is ignored.

267  {
268  return
273  }
#define OMNI_TEST_MEMBER_EQUAL(member)
Definition: util.h:125
bool invert_
Definition: BlendBrush.h:131
QVector2D size_
Definition: BlendBrush.h:129
float feather_
Definition: BlendBrush.h:130
float opacity_
Definition: BlendBrush.h:128

Field Documentation

Buffer<float> omni::BlendBrush::buffer_
private

Internal pixel buffer.

float omni::BlendBrush::feather_ = 1.0
private
bool omni::BlendBrush::invert_ = false
private
float omni::BlendBrush::opacity_ = 1.0
private
QVector2D omni::BlendBrush::size_
private

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