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 
166  public :
170  ~TextureControlPlugin() {delete(settingsDialog_);};
171 
172  QString name() { return (QString("TextureControl")); };
173  QString description( ) { return (QString("Handles Textures which are written to mesh properties")); };
174 
175  private :
176 
177  void slotTextureAdded( QString _textureName , QString _fileName , QImage _image , uint _dimension , int _id );
178  void slotTextureAdded( QString _textureName , QString _fileName , QImage _image , uint _dimension );
179  void slotMultiTextureAdded( QString _textureGroup , QString _name , QString _fileName , QImage _image , int _id , int& _textureId );
180 
181  bool StringToBool(QString _value);
182 
184  void switchDrawMode( TextureType _type, int _id );
185 
186  TextureData globalTextures_;
187 
188  texturePropertiesWidget* settingsDialog_;
189 
190  private slots:
191  void applyDialogSettings(TextureData* _texData, QString _textureName, int _id);
192 
193  //compute histogram for the given texture property
194  void getCoordinates1D(QString _textureName, int _id, std::vector< double >& _x );
195 
196  private:
197 
199  template< typename MeshT >
200  void doUpdateTexture ( Texture& _texture , MeshT& _mesh);
201 
202 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
203  template< typename VolumeMeshT, typename VolumeMeshObjectT >
205  void doUpdateTextureOVM ( Texture& _texture , VolumeMeshT& _mesh, VolumeMeshObjectT& meshObj);
206 #endif
207 
208  template< typename MeshT >
209  void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
210  int _textureid, MeshT& _mesh,
212 
214  template< typename MeshT >
215  void handleFileOpenTextures( MeshT*& _mesh , int _objectId );
216 
217 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
218  template< typename VolumeMeshObjectT >
220  void handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj, int _id );
221 #endif
222 
227  bool parseMode( QString _mode, Texture& _texture );
228 
229  //===========================================================================
232  //===========================================================================
233 
235  template< typename MeshT >
236  void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
237 
239  template< typename MeshT >
240  void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp );
241 
242 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
243  template< typename VolumeMeshT, typename VolumeMeshObjectT >
245  void copyTexture(Texture& _texture , VolumeMeshT& _mesh, VolumeMeshObjectT& _obj, OpenVolumeMesh::VertexPropertyT< double > _texProp );
246 #endif
247 
250  //===========================================================================
253  //===========================================================================
254 
255 
257  template< typename MeshT >
258  void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
260  template< typename MeshT >
261  void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::HPropHandleT< ACG::Vec2d > _texProp );
262 
263 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
264  template< typename VolumeMeshT, typename VolumeMeshObjectT >
266  void copyTexture(Texture& _texture, VolumeMeshT& _mesh, VolumeMeshObjectT& _obj, OpenVolumeMesh::VertexPropertyT< ACG::Vec2d > _texProp );
267 #endif
268 
271  //===========================================================================
274  //===========================================================================
275 
276  private:
277  // Global Texture menu
278  QMenu *textureMenu_;
279 
280  // Action group for global texture menu
281  QActionGroup* actionGroup_;
282 
283  // All actions in the global texture menu
284  std::vector<QAction*> textureActions_;
285 
288  //===========================================================================
291  //===========================================================================
292 
293  private slots:
294 
300  void slotUpdateContextMenu( int _objectId );
301 
302 
308  void slotTextureContextMenu( QAction * _action );
309 
310  private:
312  QMenu* contextMenu_;
313 
316  public slots:
317  QString version() { return QString("1.0"); };
318  };
319 
320 //=============================================================================
321 #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_C)
322 #define TEXTURECONTROL_1D_TEXTURE_HANDLING_TEMPLATES
323 #include "TextureControl1DTextureHandlingT_impl.hh"
324 #endif
325 
326 #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_C)
327 #define TEXTURECONTROL_2D_TEXTURE_HANDLING_TEMPLATES
328 #include "TextureControl2DTextureHandlingT_impl.hh"
329 #endif
330 
331 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
332  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_C)
333  #define TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_TEMPLATES
334  #include "TextureControl1DTextureHandlingOVMT_impl.hh"
335  #endif
336 
337  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_C)
338  #define TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_TEMPLATES
339  #include "TextureControl2DTextureHandlingOVMT_impl.hh"
340  #endif
341 #endif
342 
343 #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
344 #define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
345 #include "TextureControlHistogramsT_impl.hh"
346 #endif
347 
348 
349 #endif //TEXTURECONTROLPLUGIN_HH
Interface class for creating custom context menus.
Update type class.
Definition: UpdateType.hh:60
Logtype
Log types for Message Window.
QString description()
Return a description of what the plugin is doing.
void slotUpdateContextMenu(int _objectId)
Slot from the context menu interface.
Interface for all plugins which want to Load or Save files and create Objects.
Provide texture support for a plugin.
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 do logging to the logging window of the framework.
void doUpdateTexture(Texture &_texture, MeshT &_mesh)
Calls the correct copyTexture() function to copy the texture property into the displayed OM property...
void handleFileOpenTextures(MeshT *&_mesh, int _objectId)
Handles data stored in new opened files ( e.g. Texture Information )
~TextureControlPlugin()
Destructor.
Interface class from which all plugins have to be created.
QMenu * contextMenu_
Stores the per object context menu.
Predefined datatypes.
Definition: DataTypes.hh:83
void slotSetTextureProperties()
Slot for showing the TextureProperties Dialog.
Interface for all plugins which provide entries to the main menubar.
QString name()
Return a name for the plugin.
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 switchDrawMode(TextureType _type, int _id)
Checks for a correct drawmode and changes if necessary.
void slotTextureMenu(QAction *_action)
Called when an action in the TextureMenu is triggered.
Interface class for backup handling.
TextureControlPlugin()
Constructor.
void slotTextureContextMenu(QAction *_action)
Called when the context menu has been triggered.