Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BlendMask.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_BLENDMASK_H_
21 #define OMNI_BLENDMASK_H_
22 
23 #include <vector>
24 #include <QRectF>
25 #include <omni/BlendBrush.h>
26 
27 namespace omni {
28  namespace proj {
29  class Tuning;
30  }
31 
32  /**@brief A blend mask consists of an edge mask and stroke mask with a brush
33  * @detail Edge mask and stroke mask are stored in different buffers
34  */
35  class BlendMask {
36  public:
37  /// Resolution of blend mask
38  inline static constexpr int resolution() {
39  return 1024;
40  }
41 
43 
44  BlendMask(proj::Tuning const& _tuning);
45 
46  /// Clears stroke buffer
47  void clear();
48 
49  /**@brief Sets rect of blends
50  *@detail Clamps rect to borders 0,0,1,1 if its overlapping
51  **/
52  void setRect(QRectF const&);
53 
54  /// Returns rectangle
55  QRectF rect() const;
56 
57  /// Returns distance to top edge
58  float topWidth() const;
59 
60  /// Returns distance to bottom edge
61  float bottomWidth() const;
62 
63  /// Returns distance to left edge
64  float leftWidth() const;
65 
66  /// Returns distance to right edge
67  float rightWidth() const;
68 
69  /// Sets gamma value for edge mask
70  void setGamma(float _gamma);
71 
72  /// Return gamma value
73  float gamma() const;
74 
75  /// Set blend brush settings
76  void setBrush(
77  float _size,
78  float _feather, float _opacity, bool _invert);
79 
80  /// Brush size for tuning
81  float brushSize() const;
82 
83  /// Invert brush
84  void invertBrush(bool);
85 
86  /// Change brush size by +- amount of pixel
87  void changeBrushSize(float _delta);
88 
89  /// Return reference blend brush (const version)
90  BlendBrush const& brush() const;
91 
92  /// Stamp on stroke buffer with current brush at position x y
93  void stamp(const QPointF& _pos);
94 
95  /**@brief Draws a line on stroke buffer
96  * @returns new left over value
97  */
98  float drawLine(QPointF const& _p0,
99  QPointF const& _p1,
100  float _leftOver = 0.0);
101 
102  /// Returns stroke buffer (read only)
103  buffer_type const& strokeBuffer() const;
104 
105  void resize(int width,
106  int height);
107 
108  /// Return void* pointer to strokebuffer data, used for OpenGL Texture
109  void * strokeBufferData() const;
110 
111  /// Write blend mask to stream
112  void toStream(QDataStream&) const;
113 
114  /// Read blend mask from stream
115  void fromStream(QDataStream&);
116 
117  /// Test for equality, buffers are ignored
118  friend bool operator==(BlendMask const&,
119  BlendMask const&);
120 
121  private:
122  /// Transform point from tuning coordinates to stroke buffer coordinates
123  QPointF transformedPoint(QPointF const&) const;
124 
125  /// Returns blend value for mask buffer at position x y
126  float borderValue(float _x,
127  float _y) const;
128 
130  QRectF rect_;
131  float gamma_;
134  };
135 }
136 
138 
139 #endif /* OMNI_BLEND_MASK_H_ */
void toStream(QDataStream &) const
Write blend mask to stream.
Definition: BlendMask.cpp:147
void setRect(QRectF const &)
Sets rect of blends Clamps rect to borders 0,0,1,1 if its overlapping.
Definition: BlendMask.cpp:41
QRectF rect() const
Returns rectangle.
Definition: BlendMask.cpp:46
BlendBrush for drawing on the blendmask Holds an internal pixel buffer.
Definition: BlendBrush.h:33
float borderValue(float _x, float _y) const
Returns blend value for mask buffer at position x y.
proj::Tuning const & tuning_
Definition: BlendMask.h:129
float gamma_
Definition: BlendMask.h:131
float leftWidth() const
Returns distance to left edge.
Definition: BlendMask.cpp:61
A projector tuning holds adjustment and distorsion data for a single projector and screen A tuning c...
Definition: Tuning.h:52
Buffer< uint8_t > buffer_type
Definition: BlendMask.h:42
buffer_type strokeBuffer_
Definition: BlendMask.h:133
QRectF rect_
Definition: BlendMask.h:130
void clear()
Clears stroke buffer.
Definition: BlendMask.cpp:36
BlendMask(proj::Tuning const &_tuning)
Definition: BlendMask.cpp:27
friend bool operator==(BlendMask const &, BlendMask const &)
Test for equality, buffers are ignored.
Definition: BlendMask.cpp:167
void setBrush(float _size, float _feather, float _opacity, bool _invert)
Set blend brush settings.
Definition: BlendMask.cpp:83
float bottomWidth() const
Returns distance to bottom edge.
Definition: BlendMask.cpp:56
void stamp(const QPointF &_pos)
Stamp on stroke buffer with current brush at position x y.
Definition: BlendMask.cpp:113
#define OMNI_DECL_STREAM_OPERATORS(CLASS)
Definition: Interface.h:53
float rightWidth() const
Returns distance to right edge.
Definition: BlendMask.cpp:66
void fromStream(QDataStream &)
Read blend mask from stream.
Definition: BlendMask.cpp:157
void invertBrush(bool)
Invert brush.
Definition: BlendMask.cpp:93
BlendBrush const & brush() const
Return reference blend brush (const version)
Definition: BlendMask.cpp:104
float topWidth() const
Returns distance to top edge.
Definition: BlendMask.cpp:51
float gamma() const
Return gamma value.
Definition: BlendMask.cpp:78
void changeBrushSize(float _delta)
Change brush size by +- amount of pixel.
Definition: BlendMask.cpp:98
QPointF transformedPoint(QPointF const &) const
Transform point from tuning coordinates to stroke buffer coordinates.
Definition: BlendMask.cpp:142
void resize(int width, int height)
Definition: BlendMask.cpp:132
A blend mask consists of an edge mask and stroke mask with a brush Edge mask and stroke mask are sto...
Definition: BlendMask.h:35
float drawLine(QPointF const &_p0, QPointF const &_p1, float _leftOver=0.0)
Draws a line on stroke buffer.
Definition: BlendMask.cpp:118
void * strokeBufferData() const
Return void* pointer to strokebuffer data, used for OpenGL Texture.
Definition: BlendMask.cpp:137
buffer_type const & strokeBuffer() const
Returns stroke buffer (read only)
Definition: BlendMask.cpp:127
void setGamma(float _gamma)
Sets gamma value for edge mask.
Definition: BlendMask.cpp:71
float brushSize() const
Brush size for tuning.
Definition: BlendMask.cpp:109
static constexpr int resolution()
Resolution of blend mask.
Definition: BlendMask.h:38
BlendBrush brush_
Definition: BlendMask.h:132