TextureControl.hh 12.7 KB
Newer Older
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54




#ifndef TEXTURECONTROLPLUGIN_HH
#define TEXTURECONTROLPLUGIN_HH

#define OM_FORCE_STATIC_CAST

#include <QObject>
#include <QMenuBar>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
55
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
56
57
58
#include <OpenFlipper/BasePlugin/TextureInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
59
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
60
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
Jan Möbius's avatar
   
Jan Möbius committed
61
62
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
Jan Möbius's avatar
 
Jan Möbius committed
63
64
65
66

#include <OpenFlipper/common/Types.hh>
#include "textureProperties.hh"

67
#include "TextureData.hh"
Jan Möbius's avatar
 
Jan Möbius committed
68

69
class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
70
71
72
73
74
75
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(TextureInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoggingInterface)
76
  Q_INTERFACES(LoadSaveInterface)
77
  Q_INTERFACES(ContextMenuInterface)
78
  Q_INTERFACES(BackupInterface)
Jan Möbius's avatar
 
Jan Möbius committed
79
80
81
82

  public:

  signals:
83

Dirk Wilden's avatar
Dirk Wilden committed
84
    // BaseInterface
Jan Möbius's avatar
   
Jan Möbius committed
85
    void updateView();
86

Dirk Wilden's avatar
Dirk Wilden committed
87
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
88
    void updateTexture( QString , int);
89

Dirk Wilden's avatar
Dirk Wilden committed
90
    // LoggingInterface
Jan Möbius's avatar
 
Jan Möbius committed
91
92
    void log(Logtype _type, QString _message);
    void log(QString _message);
93

Dirk Wilden's avatar
Dirk Wilden committed
94
    // MenuInterface
95
    void addMenubarAction(QAction* _action, QString _type );
Jan Möbius's avatar
 
Jan Möbius committed
96

97
98
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type );
99

100

Jan Möbius's avatar
 
Jan Möbius committed
101
  private slots:
102

Dirk Wilden's avatar
Dirk Wilden committed
103
104
    // BaseInterface
    void pluginsInitialized();
Jan Möbius's avatar
Jan Möbius committed
105
    void slotObjectUpdated(int _identifier, const UpdateType _type);
106

Dirk Wilden's avatar
Dirk Wilden committed
107
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
108
    void slotUpdateAllTextures( );
Dirk Wilden's avatar
Dirk Wilden committed
109
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension , int _id );
Jan Möbius's avatar
   
Jan Möbius committed
110
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension );
111
    void slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId );
Jan Möbius's avatar
 
Jan Möbius committed
112
    void slotTextureUpdated( QString _textureName , int _identifier );
Dirk Wilden's avatar
Dirk Wilden committed
113
    void slotSetTextureMode(QString _textureName ,QString _mode, int _id);
Jan Möbius's avatar
 
Jan Möbius committed
114
    void slotSetTextureMode(QString _textureName ,QString _mode);
Dirk Wilden's avatar
Dirk Wilden committed
115
    void slotSwitchTexture( QString _textureName, int _id );
Jan Möbius's avatar
   
Jan Möbius committed
116
    void slotSwitchTexture( QString _textureName );
117
    void slotUpdateTexture( QString _textureName , int _identifier);
118
119
    void slotTextureChangeImage( QString _textureName , QImage& _image , int _id );
    void slotTextureChangeImage( QString _textureName , QImage& _image );
120
121
    void slotTextureGetImage( QString _textureName, QImage& _image, int _id );
    void slotTextureGetImage( QString _textureName, QImage& _image );
122
123
    void slotTextureIndex( QString _textureName, int _id, int& _index);
    void slotTextureName( int _id, int _textureIndex, QString& _textureName);
124
    void slotTextureFilename( int _id, QString _textureName, QString& _textureFilename);
125
126
127
    void slotGetCurrentTexture( int _id, QString& _textureName );
    void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures );
    
128
129
    // LoadSaveInterface
    void fileOpened( int _id );
130
    void addedEmptyObject( int _id );
131
132
133
134
135
    
    //BackupInterface
    void slotAboutToRestore( int _objectid , int _internalId);      
    void slotRestore( int _objectid, int _internalId);
    void slotRestored( int _objectid, int _internalId);
Jan Möbius's avatar
Jan Möbius committed
136

Jan Möbius's avatar
 
Jan Möbius committed
137
  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
138
139
140

    void doSwitchTexture( QString _textureName, int _id );

Dirk Wilden's avatar
Dirk Wilden committed
141
    /// Called when an action in the TextureMenu is triggered
Jan Möbius's avatar
 
Jan Möbius committed
142
    void slotTextureMenu(QAction* _action);
Jan Möbius's avatar
   
Jan Möbius committed
143

Dirk Wilden's avatar
Dirk Wilden committed
144
145
    /// Slot for showing the TextureProperties Dialog
    void slotSetTextureProperties();
Jan Möbius's avatar
   
Jan Möbius committed
146

Jan Möbius's avatar
 
Jan Möbius committed
147
  public :
Dirk Wilden's avatar
Dirk Wilden committed
148
149
150
    /// Constructor
    TextureControlPlugin() {};
    /// Destructor
Jan Möbius's avatar
 
Jan Möbius committed
151
    ~TextureControlPlugin() {delete(settingsDialog_);};
Jan Möbius's avatar
   
Jan Möbius committed
152

Jan Möbius's avatar
 
Jan Möbius committed
153
    QString name() { return (QString("TextureControl")); };
Jan Möbius's avatar
   
Jan Möbius committed
154
155
    QString description( ) { return (QString("Handles Textures which are written to mesh properties")); };

Jan Möbius's avatar
 
Jan Möbius committed
156
  private :
Jan Möbius's avatar
   
Jan Möbius committed
157

Dirk Wilden's avatar
Dirk Wilden committed
158
159
    bool StringToBool(QString _value);

160
    /// Load an Image from disk ( if filename contains leading "/ " its consedered global otherwise in texturedir)
Dirk Wilden's avatar
   
Dirk Wilden committed
161
    bool getImage( QString _fileName, QImage& _image );
162
163

    /// Checks for a correct drawmode and changes if necessary
164
    void switchDrawMode( TextureType _type );
165

166
    TextureData globalTextures_;
Jan Möbius's avatar
   
Jan Möbius committed
167

Jan Möbius's avatar
 
Jan Möbius committed
168
    texturePropertiesWidget* settingsDialog_;
Jan Möbius's avatar
   
Jan Möbius committed
169

170
171
  private slots:
    void applyDialogSettings(TextureData* _texData, QString _textureName, int _id);
Jan Möbius's avatar
   
Jan Möbius committed
172

173
174
175
    //compute histogram for the given texture property
    void getCoordinates1D(QString _textureName, int _id, std::vector< double >& _x );

176
  private:
Jan Möbius's avatar
   
Jan Möbius committed
177

Jan Möbius's avatar
 
Jan Möbius committed
178
179
    /// Take a scalar value and return a clamped,... depending on texture settings
    inline
180
    void computeValue(Texture& _texture, double _min, double _max, double& _value);
Jan Möbius's avatar
 
Jan Möbius committed
181
182
183

    /// Calls the correct \a copyTexture() function to copy the texture property into the displayed OM property
    template< typename MeshT >
184
    void doUpdateTexture ( Texture& _texture , MeshT& _mesh);
Jan Möbius's avatar
 
Jan Möbius committed
185

186
187
188
189
    template< typename MeshT >
    void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
                              int _textureid, MeshT& _mesh,
                              OpenMesh::VPropHandleT< double > _texProp);
190

191
192
    /// Handles data stored in new opened files ( e.g. Texture Information )
    template< typename MeshT >
Jan Möbius's avatar
Jan Möbius committed
193
    void handleFileOpenTextures( MeshT*& _mesh  , int _objectId );
194

195
196
197
198
199
200
    /** \brief parse texture mode settings
     * Parses the string _mode and changes the settings in _texture according to the string.
     * If the setting changes, it will return true.
     */
    bool parseMode( QString _mode, Texture& _texture );

201
202
203
204
205
    //===========================================================================
    /** @name 1D Texture copy functions( copy 1D input textures to target texture coordinates and transform values )
      * @{ */
    //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
206
207
    /// Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property
    template< typename MeshT >
208
    void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
209

Jan Möbius's avatar
 
Jan Möbius committed
210
211
    /// Copy the supplied 1D halfedge property to both coordinates of the 2D halfedge OM texture property
    template< typename MeshT >
212
    void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp );
213

214
215
216
217

    /// For a given mesh compute the minimum and maximum values depending on texture settings (vertex based)
    template< typename MeshT >
    inline
218
    void computeMinMaxScalar(Texture& _textureData , MeshT& _mesh ,OpenMesh::VPropHandleT< double > _texture,double& _min , double& _max);
219
220
221
222

    /// For a given mesh compute the minimum and maximum values depending on texture settings (halfedge based)
    template< typename MeshT >
    inline
223
    void computeMinMaxScalar(Texture& _textureData , MeshT& _mesh,OpenMesh::HPropHandleT< double > _texture,double& _min , double& _max);
224

225
226
227
228
229
230
231
232
    /** @} */

    //===========================================================================
    /** @name 2D Texture copy functions( copy 2D input textures to target texture coordinates and transform values )
      * @{ */
    //===========================================================================


Jan Möbius's avatar
 
Jan Möbius committed
233
234
    /// Copy the supplied 2D vertex property to the 2D vertex OM property
    template< typename MeshT >
235
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
236
237
    /// Copy the supplied 2D halfedge property to the 2D halfedge OM property
    template< typename MeshT >
238
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::HPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
239

240
241
    /** @} */

242
    //===========================================================================
Jan Möbius's avatar
Jan Möbius committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    /** @name Global texture menu
      * @{ */
    //===========================================================================

  private:
    // Global Texture menu
    QMenu *textureMenu_;

    // Action group for global texture menu
    QActionGroup* actionGroup_;

    // All actions in the global texture menu
    std::vector<QAction*> textureActions_;

    /** @} */

    //===========================================================================
    /** @name Context Menu
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
      * @{ */
    //===========================================================================

  private slots:

    /** \brief Slot from the context menu interface.
     *
     * This slot is called, when the core requests a context menu and creates and updates
     * the context menu.
     */
    void slotUpdateContextMenu( int _objectId );


    /** \brief Called when the context menu has been triggered
     *
     *  This slot is called when the per object context menu is triggered.
     *  It will switch to the requested texture and mode.
     */
    void slotTextureContextMenu( QAction * _action );

  private:
    /// Stores the per object context menu
    QMenu* contextMenu_;

    /** @} */
286
    
Jan Möbius's avatar
   
Jan Möbius committed
287
288
  public slots:
    QString version() { return QString("1.0"); };
Jan Möbius's avatar
 
Jan Möbius committed
289
290
 };

291
292
293
294
295
296
297
298
299
300
301
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_C)
#define TEXTURECONTROL_1D_TEXTURE_HANDLING_TEMPLATES
#include "TextureControl1DTextureHandlingT.cc"
#endif

#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_C)
#define TEXTURECONTROL_2D_TEXTURE_HANDLING_TEMPLATES
#include "TextureControl2DTextureHandlingT.cc"
#endif

302
303
304
305
306
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
#define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
#include "TextureControlHistogramsT.cc"
#endif

307

Jan Möbius's avatar
 
Jan Möbius committed
308
#endif //TEXTURECONTROLPLUGIN_HH