TextureControl.hh 13.9 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
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
*                           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/>.                                       *
*                                                                            *
33 34 35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
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 67 68 69 70
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
    #include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
    #include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif

Jan Möbius's avatar
 
Jan Möbius committed
71 72 73
#include <OpenFlipper/common/Types.hh>
#include "textureProperties.hh"

74
#include "TextureData.hh"
Jan Möbius's avatar
 
Jan Möbius committed
75

76
class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
77 78 79 80 81 82
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(TextureInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoggingInterface)
83
  Q_INTERFACES(LoadSaveInterface)
84
  Q_INTERFACES(ContextMenuInterface)
85
  Q_INTERFACES(BackupInterface)
Jan Möbius's avatar
 
Jan Möbius committed
86

Matthias Möller's avatar
Matthias Möller committed
87 88 89 90
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-TextureControl")
#endif

Jan Möbius's avatar
 
Jan Möbius committed
91 92 93
  public:

  signals:
94

Dirk Wilden's avatar
Dirk Wilden committed
95
    // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
96
    void updateView();
Jan Möbius's avatar
Jan Möbius committed
97
    void updatedObject(int _identifier, const UpdateType& _type);
98

Dirk Wilden's avatar
Dirk Wilden committed
99
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
100
    void updateTexture( QString , int);
101

Dirk Wilden's avatar
Dirk Wilden committed
102
    // LoggingInterface
Jan Möbius's avatar
 
Jan Möbius committed
103 104
    void log(Logtype _type, QString _message);
    void log(QString _message);
105

Dirk Wilden's avatar
Dirk Wilden committed
106
    // MenuInterface
107
    void addMenubarAction(QAction* _action, QString _type );
Jan Möbius's avatar
 
Jan Möbius committed
108

109 110
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type );
111

112

Jan Möbius's avatar
 
Jan Möbius committed
113
  private slots:
114

Dirk Wilden's avatar
Dirk Wilden committed
115 116
    // BaseInterface
    void pluginsInitialized();
Jan Möbius's avatar
Jan Möbius committed
117
    void slotObjectUpdated(int _identifier, const UpdateType& _type);
118
    void slotDrawModeChanged(int _viewerId );
119

Dirk Wilden's avatar
Dirk Wilden committed
120
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
121
    void slotUpdateAllTextures( );
Dirk Wilden's avatar
Dirk Wilden committed
122
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension , int _id );
Jan Möbius's avatar
 
Jan Möbius committed
123
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension );
124
    void slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId );
Jan Möbius's avatar
 
Jan Möbius committed
125
    void slotTextureUpdated( QString _textureName , int _identifier );
Dirk Wilden's avatar
Dirk Wilden committed
126
    void slotSetTextureMode(QString _textureName ,QString _mode, int _id);
Jan Möbius's avatar
 
Jan Möbius committed
127
    void slotSetTextureMode(QString _textureName ,QString _mode);
Dirk Wilden's avatar
Dirk Wilden committed
128
    void slotSwitchTexture( QString _textureName, int _id );
Jan Möbius's avatar
 
Jan Möbius committed
129
    void slotSwitchTexture( QString _textureName );
130
    void slotUpdateTexture( QString _textureName , int _identifier);
131 132
    void slotTextureChangeImage( QString _textureName , QImage& _image , int _id );
    void slotTextureChangeImage( QString _textureName , QImage& _image );
133 134
    void slotTextureGetImage( QString _textureName, QImage& _image, int _id );
    void slotTextureGetImage( QString _textureName, QImage& _image );
135
    void slotTextureIndex( QString _textureName, int _id, int& _index);
136
    void slotTextureIndexPropertyName( int _id, QString& _propertyName);
137
    void slotTextureName( int _id, int _textureIndex, QString& _textureName);
138
    void slotTextureFilename( int _id, QString _textureName, QString& _textureFilename);
139 140 141
    void slotGetCurrentTexture( int _id, QString& _textureName );
    void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures );
    
142 143
    // LoadSaveInterface
    void fileOpened( int _id );
144
    void addedEmptyObject( int _id );
145 146
    
    //BackupInterface
Jan Möbius's avatar
Jan Möbius committed
147 148
    void slotAboutToRestore( int _objectid );
    void slotRestored( int _objectid);
Jan Möbius's avatar
Jan Möbius committed
149

Jan Möbius's avatar
 
Jan Möbius committed
150
  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
151 152 153

    void doSwitchTexture( QString _textureName, int _id );

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

Dirk Wilden's avatar
Dirk Wilden committed
157 158
    /// Slot for showing the TextureProperties Dialog
    void slotSetTextureProperties();
Jan Möbius's avatar
 
Jan Möbius committed
159

Jan Möbius's avatar
 
Jan Möbius committed
160
  public :
Dirk Wilden's avatar
Dirk Wilden committed
161
    /// Constructor
Jan Möbius's avatar
Jan Möbius committed
162
    TextureControlPlugin();
Dirk Wilden's avatar
Dirk Wilden committed
163
    /// Destructor
Jan Möbius's avatar
 
Jan Möbius committed
164
    ~TextureControlPlugin() {delete(settingsDialog_);};
Jan Möbius's avatar
 
Jan Möbius committed
165

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

Jan Möbius's avatar
 
Jan Möbius committed
169
  private :
Jan Möbius's avatar
 
Jan Möbius committed
170

Dirk Wilden's avatar
Dirk Wilden committed
171 172
    bool StringToBool(QString _value);

173
    /// Checks for a correct drawmode and changes if necessary
174
    void switchDrawMode( TextureType _type );
175

176
    TextureData globalTextures_;
Jan Möbius's avatar
 
Jan Möbius committed
177

Jan Möbius's avatar
 
Jan Möbius committed
178
    texturePropertiesWidget* settingsDialog_;
Jan Möbius's avatar
 
Jan Möbius committed
179

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

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

186
  private:
Jan Möbius's avatar
 
Jan Möbius committed
187

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

192 193 194 195 196 197
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
    /// Calls the correct \a copyTexture() function to copy the texture property into the displayed OVM property
    template< typename VolumeMeshT, typename VolumeMeshObjectT >
    void doUpdateTextureOVM ( Texture& _texture , VolumeMeshT& _mesh, VolumeMeshObjectT& meshObj);
#endif

198 199 200 201
    template< typename MeshT >
    void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
                              int _textureid, MeshT& _mesh,
                              OpenMesh::VPropHandleT< double > _texProp);
202

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

207 208 209 210 211 212
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
    /// Handles data stored in new opened files ( e.g. Texture Information )
    template< typename VolumeMeshObjectT >
    void handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj, int _id );
#endif

213 214 215 216 217 218
    /** \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 );

219 220 221 222 223
    //===========================================================================
    /** @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
224 225
    /// Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property
    template< typename MeshT >
226
    void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
227

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

232 233 234 235 236 237
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
    /// Copy the supplied 1D vertex property to both coordinates of the 2D vertex OVM texture property
    template< typename VolumeMeshT, typename VolumeMeshObjectT >
    void copyTexture(Texture& _texture , VolumeMeshT& _mesh, VolumeMeshObjectT& _obj, OpenVolumeMesh::VertexPropertyT< double > _texProp );
#endif

238 239 240 241 242 243 244 245
    /** @} */

    //===========================================================================
    /** @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
246 247
    /// Copy the supplied 2D vertex property to the 2D vertex OM property
    template< typename MeshT >
248
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
249 250
    /// Copy the supplied 2D halfedge property to the 2D halfedge OM property
    template< typename MeshT >
251
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::HPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
252

253 254 255 256 257 258
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
    /// Copy the supplied 2D vertex property to the 2D vertex OVM property
    template< typename VolumeMeshT, typename VolumeMeshObjectT >
    void copyTexture(Texture& _texture, VolumeMeshT& _mesh, VolumeMeshObjectT& _obj, OpenVolumeMesh::VertexPropertyT< ACG::Vec2d > _texProp );
#endif

259 260
    /** @} */

261
    //===========================================================================
Jan Möbius's avatar
Jan Möbius committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    /** @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
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
      * @{ */
    //===========================================================================

  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_;

    /** @} */
305
    
Jan Möbius's avatar
 
Jan Möbius committed
306 307
  public slots:
    QString version() { return QString("1.0"); };
Jan Möbius's avatar
 
Jan Möbius committed
308 309
 };

310 311 312 313 314 315 316 317 318 319 320
//=============================================================================
#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

321 322 323 324 325 326 327 328 329 330 331 332
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_C)
  #define TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_TEMPLATES
  #include "TextureControl1DTextureHandlingOVMT.cc"
  #endif

  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_C)
  #define TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_TEMPLATES
  #include "TextureControl2DTextureHandlingOVMT.cc"
  #endif
#endif

333 334 335 336 337
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
#define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
#include "TextureControlHistogramsT.cc"
#endif

338

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