Developer Documentation
TextureControl.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 #ifndef TEXTURECONTROLPLUGIN_HH
48 #define TEXTURECONTROLPLUGIN_HH
49 
50 #define OM_FORCE_STATIC_CAST
51 
52 #include <QObject>
53 #include <QMenuBar>
54 
57 #include <OpenFlipper/BasePlugin/TextureInterface.hh>
64 
65 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT
67 #endif
68 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
70 #endif
71 
72 #ifdef ENABLE_BSPLINESURFACE_SUPPORT
74 #endif
75 
77 #include "Dialogs/textureProperties.hh"
78 
79 #include "TextureData.hh"
80 
82 {
83  Q_OBJECT
84  Q_INTERFACES(BaseInterface)
85  Q_INTERFACES(TextureInterface)
86  Q_INTERFACES(MenuInterface)
87  Q_INTERFACES(LoggingInterface)
88  Q_INTERFACES(LoadSaveInterface)
89  Q_INTERFACES(ContextMenuInterface)
90  Q_INTERFACES(BackupInterface)
91 
92  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-TextureControl")
93 
94  public:
95 
96  signals:
97 
98  // BaseInterface
99  void updateView();
100  void updatedObject(int _identifier, const UpdateType& _type);
101 
102  // TextureInterface
103  void updateTexture( QString , int);
104 
105  // LoggingInterface
106  void log(Logtype _type, QString _message);
107  void log(QString _message);
108 
109  // MenuInterface
110  void addMenubarAction(QAction* _action, QString _type );
111 
112  // ContextMenuInterface
113  void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type );
114 
115 
116  private slots:
117 
118  // BaseInterface
119  void pluginsInitialized();
120  void slotObjectUpdated(int _identifier, const UpdateType& _type);
121  void slotDrawModeChanged(int _viewerId );
122 
123  // TextureInterface
124  void slotUpdateAllTextures( );
125  void slotTextureAdded( QString _textureName , QString _filename , uint _dimension , int _id ){slotTextureAdded( _textureName , _filename , QImage() , _dimension , _id );}
126  void slotTextureAdded( QString _textureName , QImage _image , uint _dimension , int _id ){slotTextureAdded( _textureName , QString() , _image , _dimension , _id );}
127  void slotTextureAdded( QString _textureName , QString _filename , uint _dimension ){slotTextureAdded( _textureName , _filename , QImage() , _dimension );}
128  void slotTextureAdded( QString _textureName , QImage _image , uint _dimension ){slotTextureAdded( _textureName , QString() , _image , _dimension );}
129  void slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ){slotMultiTextureAdded( _textureGroup , _name , _filename , QImage() , _id , _textureId );}
130  void slotMultiTextureAdded( QString _textureGroup , QString _name , QImage _image , int _id , int& _textureId ){slotMultiTextureAdded( _textureGroup , _name , QString() , _image , _id , _textureId );}
131  void slotTextureUpdated( QString _textureName , int _identifier );
132  void slotSetTextureMode(QString _textureName ,QString _mode, int _id);
133  void slotSetTextureMode(QString _textureName ,QString _mode);
134  void slotSwitchTexture( QString _textureName, int _id );
135  void slotSwitchTexture( QString _textureName );
136  void slotUpdateTexture( QString _textureName , int _identifier);
137  void slotTextureChangeImage( QString _textureName , QImage& _image , int _id );
138  void slotTextureChangeImage( QString _textureName , QImage& _image );
139  void slotTextureGetImage( QString _textureName, QImage& _image, int _id );
140  void slotTextureGetImage( QString _textureName, QImage& _image );
141  void slotTextureIndex( QString _textureName, int _id, int& _index);
142  void slotTextureIndexPropertyName( int _id, QString& _propertyName);
143  void slotTextureName( int _id, int _textureIndex, QString& _textureName);
144  void slotTextureFilename( int _id, QString _textureName, QString& _textureFilename);
145  void slotGetCurrentTexture( int _id, QString& _textureName );
146  void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures );
147 
148  // LoadSaveInterface
149  void fileOpened( int _id );
150  void addedEmptyObject( int _id );
151 
152  //BackupInterface
153  void slotAboutToRestore( int _objectid );
154  void slotRestored( int _objectid);
155 
156  private slots:
157 
158  void doSwitchTexture( QString _textureName, int _id );
159 
161  void slotTextureMenu(QAction* _action);
162 
165 
167  void slotPrintImagePoolInfo();
168 
169  public :
173  ~TextureControlPlugin() {delete(settingsDialog_);};
174 
175  QString name() { return (QString("TextureControl")); };
176  QString description( ) { return (QString("Handles Textures which are written to mesh properties")); };
177 
178  private :
179 
180  void slotTextureAdded( QString _textureName , QString _fileName , QImage _image , uint _dimension , int _id );
181  void slotTextureAdded( QString _textureName , QString _fileName , QImage _image , uint _dimension );
182  void slotMultiTextureAdded( QString _textureGroup , QString _name , QString _fileName , QImage _image , int _id , int& _textureId );
183 
184  bool StringToBool(QString _value);
185 
187  void switchDrawMode( TextureType _type, int _id );
188 
189  TextureData globalTextures_;
190 
191  texturePropertiesWidget* settingsDialog_;
192 
193  private slots:
194  void applyDialogSettings(TextureData* _texData, QString _textureName, int _id);
195 
196  //compute histogram for the given texture property
197  void getCoordinates1D(QString _textureName, int _id, std::vector< double >& _x );
198 
199  private:
200 
202  template< typename MeshT >
203  void doUpdateTexture ( Texture& _texture , MeshT& _mesh);
204 
205 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
206  template< typename VolumeMeshT, typename VolumeMeshObjectT >
208  void doUpdateTextureOVM ( Texture& _texture , VolumeMeshT& _mesh, VolumeMeshObjectT& meshObj);
209 #endif
210 
211  template< typename MeshT >
212  void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
213  int _textureid, MeshT& _mesh,
215 
217  template< typename MeshT >
218  void handleFileOpenTextures( MeshT*& _mesh , int _objectId );
219 
220 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
221  template< typename VolumeMeshObjectT >
223  void handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj, int _id );
224 #endif
225 
230  bool parseMode( QString _mode, Texture& _texture );
231 
232  //===========================================================================
235  //===========================================================================
236 
238  template< typename MeshT >
239  void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
240 
242  template< typename MeshT >
243  void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp );
244 
245 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
246  template< typename VolumeMeshT, typename VolumeMeshObjectT >
248  void copyTexture(Texture& _texture , VolumeMeshT& _mesh, VolumeMeshObjectT& _obj, OpenVolumeMesh::VertexPropertyT< double > _texProp );
249 #endif
250 
253  //===========================================================================
256  //===========================================================================
257 
258 
260  template< typename MeshT >
261  void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
263  template< typename MeshT >
264  void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::HPropHandleT< ACG::Vec2d > _texProp );
265 
266 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
267  template< typename VolumeMeshT, typename VolumeMeshObjectT >
269  void copyTexture(Texture& _texture, VolumeMeshT& _mesh, VolumeMeshObjectT& _obj, OpenVolumeMesh::VertexPropertyT< ACG::Vec2d > _texProp );
270 #endif
271 
274  //===========================================================================
277  //===========================================================================
278 
279  private:
280  // Global Texture menu
281  QMenu *textureMenu_;
282 
283  // Action group for global texture menu
284  QActionGroup* actionGroup_;
285 
286  // All actions in the global texture menu
287  std::vector<QAction*> textureActions_;
288 
291  //===========================================================================
294  //===========================================================================
295 
296  private slots:
297 
303  void slotUpdateContextMenu( int _objectId );
304 
305 
311  void slotTextureContextMenu( QAction * _action );
312 
313  private:
315  QMenu* contextMenu_;
316 
319  public slots:
320  QString version() { return QString("1.0"); };
321  };
322 
323 //=============================================================================
324 #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_C)
325 #define TEXTURECONTROL_1D_TEXTURE_HANDLING_TEMPLATES
326 #include "TextureControl1DTextureHandlingT_impl.hh"
327 #endif
328 
329 #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_C)
330 #define TEXTURECONTROL_2D_TEXTURE_HANDLING_TEMPLATES
331 #include "TextureControl2DTextureHandlingT_impl.hh"
332 #endif
333 
334 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
335  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_C)
336  #define TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_TEMPLATES
337  #include "TextureControl1DTextureHandlingOVMT_impl.hh"
338  #endif
339 
340  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_C)
341  #define TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_TEMPLATES
342  #include "TextureControl2DTextureHandlingOVMT_impl.hh"
343  #endif
344 #endif
345 
346 #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
347 #define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
348 #include "TextureControlHistogramsT_impl.hh"
349 #endif
350 
351 
352 #endif //TEXTURECONTROLPLUGIN_HH
bool parseMode(QString _mode, Texture &_texture)
parse texture mode settings Parses the string _mode and changes the settings in _texture according to...
Interface for all plugins which provide entries to the main menubar.
void slotUpdateContextMenu(int _objectId)
Slot from the context menu interface.
Logtype
Log types for Message Window.
Predefined datatypes.
Definition: DataTypes.hh:83
Interface for all Plugins which do logging to the logging window of the framework.
void copyTexture(Texture &_texture, MeshT &_mesh, OpenMesh::VPropHandleT< double > _texProp)
Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property...
void doUpdateTexture(Texture &_texture, MeshT &_mesh)
Calls the correct copyTexture() function to copy the texture property into the displayed OM property...
QMenu * contextMenu_
Stores the per object context menu.
Update type class.
Definition: UpdateType.hh:59
void slotPrintImagePoolInfo()
Print Pool Info.
void slotSetTextureProperties()
Slot for showing the TextureProperties Dialog.
TextureControlPlugin()
Constructor.
void switchDrawMode(TextureType _type, int _id)
Checks for a correct drawmode and changes if necessary.
void handleFileOpenTextures(MeshT *&_mesh, int _objectId)
Handles data stored in new opened files ( e.g. Texture Information )
void slotTextureMenu(QAction *_action)
Called when an action in the TextureMenu is triggered.
QString name()
Return a name for the plugin.
void slotTextureContextMenu(QAction *_action)
Called when the context menu has been triggered.
QString description()
Return a description of what the plugin is doing.
Interface class for creating custom context menus.
Provide texture support for a plugin.
Interface class from which all plugins have to be created.
Interface class for backup handling.
Interface for all plugins which want to Load or Save files and create Objects.
~TextureControlPlugin()
Destructor.