Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Interface.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_MAPPING_INTERFACE_H_
21 #define OMNI_MAPPING_INTERFACE_H_
22 
23 #include <map>
24 #include <memory>
25 #include <omni/PluginInfo.h>
28 #include <omni/visual/Interface.h>
29 
30 class QOpenGLShaderProgram;
31 
32 namespace omni {
33  namespace input {
34  class Interface;
35  class List;
36  }
37  namespace visual {
38  class Scene;
39  }
40 
41  namespace mapping {
42  enum class OutputMode
43  {
44  MAPPED_INPUT, // Draws actual input texture on mapping
45  TEXCOORDS, // Draw texture coordinates of mapping
46  UVW, // Draws uvw coordinates of mapping
47  LIGHTING_ONLY, // Draw plain canvas with lighting
48  LIGHTING_TEX // Draw canvas with
49  };
50 
51  /**@brief Mapping interface with one or several inputs and shader
52  * @detail Holds inputs and shader
53  */
54  class Interface :
55  public TypeIdInterface,
56  public PropertyMapSerializer,
57  public visual::Interface {
58  public:
59  Interface();
60 
61  virtual ~Interface();
62 
63  /// Initialized OpenGL shader
64  void initialize();
65 
66  /// Bind shaders and set uniforms
67  virtual void bind();
68  void bind(input::Interface const*, OutputMode, bool _grayscale);
69  void bind(input::Interface const*, float _transparency);
70 
71  /// Release shader
72  void release();
73 
74  /// Flip horizontally
75  bool flipHorizontal() const;
76 
77  /// Flip horizontally
78  void setFlipHorizontal(bool);
79 
80  /// Flip vertically
81  bool flipVertical() const;
82 
83  /// Flip vertically
84  void setFlipVertical(bool);
85 
86  /**@brief Flag which tells if this mapping uses UVW texture coordinates
87  (true by default)
88  @detail
89  **/
90  inline virtual bool isUVW() const
91  {
92  return true;
93  }
94 
95  /// Static function to retrieve all registered mappings that support UVW
96  // coords
97  static IdSet getUVWMappings();
98 
99  /// Static function to retrieve all registered mappings that dont
100  // support UVW coords
101  static IdSet getPlanarMappings();
102 
103  /// Return pointer to parameter widget
104  virtual QWidget* widget() = 0;
105 
106  inline void draw() const {
107  draw(1.0);
108  }
109 
110  /// Draw mapping with opacity
111  inline virtual void draw(float _opacity) const {}
112 
113  /// Update mapping visualizer
114  inline virtual void update() {}
115 
116  /// Return const ref to affine transform
117  AffineTransform const& transform() const;
118 
119  /// Return ref to affine transform
120  AffineTransform & transform();
121 
122  /// Set new affine transform
123  void setTransform(AffineTransform const& _transform);
124 
125  /// Return matrix of transform
126  virtual QMatrix4x4 matrix() const;
127 
128  /**@brief If true, mapping transform is attached to canvas transform
129  @detail Is true by default
130  **/
131  bool isBoundToCanvas() const;
132 
133  /// Set whether mapping transform is attached to canvas transform
134  void setBoundToCanvas(bool);
135 
136  /// Write mapping to stream
137  virtual void toPropertyMap(PropertyMap&) const;
138 
139  /// Read mapping from stream
140  virtual void fromPropertyMap(PropertyMap const&);
141 
142  /// The scene this canvas belongs to
143  visual::Scene const* scene() const;
144 
145  /**@brief Set the scene this canvas belongs to.
146  @detail Is set automatically when a canvas is added to a session
147  **/
148  void setScene(visual::Scene const*);
149 
150  protected:
151  std::unique_ptr<QOpenGLShaderProgram> shader_;
152 
153  private:
154  /**@brief Returns vertex shader source code
155  * @detail Is taken from file :/shaders/mapping/common.vert by default)
156  **/
157  virtual QString vertexShaderSourceCode() const;
158 
159  /**@brief Returns fragment shader source code
160  * @detail Is taken from file :/shaders/mapping/$MAPPING_TYPEID by
161  *default)
162  **/
163  virtual QString fragmentShaderSourceCode() const;
164 
165  AffineTransform transform_;
166  bool boundToCanvas_ = true;
167  bool flipHorizontal_ = false;
168  bool flipVertical_ = false;
169 
170  visual::Scene const* scene_ = nullptr;
171  };
172 
173  /// Abstract mapping factory
175  }
176 
179 }
180 
182 
183 #define OMNI_MAPPING_INTERFACE_IID "org.omnidome.mapping.Interface"
184 
186 
187 #define OMNI_MAPPING_PLUGIN_DECL \
188  Q_OBJECT \
189  Q_PLUGIN_METADATA(IID OMNI_MAPPING_INTERFACE_IID) \
190  Q_INTERFACES(omni::mapping::Interface) \
191  OMNI_PLUGIN_TYPE("Mapping")
192 
193 
194 #endif /* OMNI_MAPPING_INTERFACE_H_ */
void initialize()
Initialized OpenGL shader.
Definition: Interface.cpp:40
visual::Scene const * scene_
Definition: Interface.h:170
#define OMNI_MAPPING_INTERFACE_IID
Definition: Interface.h:183
#define OMNI_DECL_ENUM_STREAM_OPERATORS(ENUM)
Definition: Interface.h:65
AffineTransform const & transform() const
Return const ref to affine transform.
Definition: Interface.cpp:160
bool flipVertical_
Definition: Interface.h:168
visual::Scene const * scene() const
The scene this canvas belongs to.
Definition: Interface.cpp:69
std::unique_ptr< QOpenGLShaderProgram > shader_
Definition: Interface.h:151
virtual void toPropertyMap(PropertyMap &) const
Write mapping to stream.
Definition: Interface.cpp:205
virtual QWidget * widget()=0
Return pointer to parameter widget.
bool boundToCanvas_
Definition: Interface.h:166
bool flipHorizontal_
Definition: Interface.h:167
void setFlipHorizontal(bool)
Flip horizontally.
Definition: Interface.cpp:116
virtual ~Interface()
Definition: Interface.cpp:37
std::set< Id > IdSet
Id set typedef.
Definition: Id.h:83
Basic visual interface.
Definition: Interface.h:28
mapping::Interface Mapping
Definition: Interface.h:177
void setScene(visual::Scene const *)
Set the scene this canvas belongs to. Is set automatically when a canvas is added to a session...
void setTransform(AffineTransform const &_transform)
Set new affine transform.
Definition: Interface.cpp:170
virtual QString fragmentShaderSourceCode() const
Returns fragment shader source code Is taken from file :/shaders/mapping/$MAPPING_TYPEID by default)...
Definition: Interface.cpp:195
virtual QMatrix4x4 matrix() const
Return matrix of transform.
Definition: Interface.cpp:186
OutputMode
Definition: Interface.h:42
AbstractFactory< Interface > Factory
Abstract mapping factory.
Definition: Interface.h:174
virtual void update()
Update mapping visualizer.
Definition: Interface.h:114
A class that holds settings and elements for session 3d visualization Belongs to a session...
Definition: Scene.h:63
mapping::Factory MappingFactory
Definition: Interface.h:178
Generic input interface.
Definition: Interface.h:53
virtual void fromPropertyMap(PropertyMap const &)
Read mapping from stream.
Definition: Interface.cpp:213
bool isBoundToCanvas() const
If true, mapping transform is attached to canvas transform Is true by default.
Definition: Interface.cpp:177
virtual void draw(float _opacity) const
Draw mapping with opacity.
Definition: Interface.h:111
static IdSet getUVWMappings()
Static function to retrieve all registered mappings that support UVW.
Definition: Interface.cpp:131
void draw() const
Abstract method for visualing.
Definition: Interface.h:106
void release()
Release shader.
Definition: Interface.cpp:106
Interface()
Definition: Interface.cpp:30
AffineTransform transform_
Definition: Interface.h:165
Abstract Interface with a single virtual member function which returns.
Definition: TypeIdInterface.h:28
static IdSet getPlanarMappings()
Static function to retrieve all registered mappings that dont.
Definition: Interface.cpp:145
virtual void bind()
Bind shaders and set uniforms.
Definition: Interface.cpp:51
void setFlipVertical(bool)
Flip vertically.
Definition: Interface.cpp:126
bool flipVertical() const
Flip vertically.
Definition: Interface.cpp:121
Mapping interface with one or several inputs and shader Holds inputs and shader. ...
Definition: Interface.h:54
The central factory class.
Definition: factory.hpp:38
virtual bool isUVW() const
Flag which tells if this mapping uses UVW texture coordinates (true by default) . ...
Definition: Interface.h:90
virtual QString vertexShaderSourceCode() const
Returns vertex shader source code Is taken from file :/shaders/mapping/common.vert by default) ...
Definition: Interface.cpp:190
void setBoundToCanvas(bool)
Set whether mapping transform is attached to canvas transform.
Definition: Interface.cpp:182
bool flipHorizontal() const
Flip horizontally.
Definition: Interface.cpp:111