TextureControl.hh 16 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52 53 54 55 56 57 58 59 60 61




#ifndef TEXTURECONTROLPLUGIN_HH
#define TEXTURECONTROLPLUGIN_HH

#define OM_FORCE_STATIC_CAST

#include <QObject>
#include <QMenuBar>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
62
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
63 64 65
#include <OpenFlipper/BasePlugin/TextureInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
66
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
67
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
68 69
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
Jan Möbius's avatar
 
Jan Möbius committed
70

71
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
72 73
    #include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
74
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
75 76 77
    #include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif

78 79 80 81
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
    #include <ObjectTypes/BSplineSurface/BSplineSurface.hh>
#endif

Jan Möbius's avatar
 
Jan Möbius committed
82 83 84
#include <OpenFlipper/common/Types.hh>
#include "textureProperties.hh"

85
#include "TextureData.hh"
Jan Möbius's avatar
 
Jan Möbius committed
86

87
class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
88 89 90 91 92 93
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(TextureInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoggingInterface)
94
  Q_INTERFACES(LoadSaveInterface)
95
  Q_INTERFACES(ContextMenuInterface)
96
  Q_INTERFACES(BackupInterface)
Jan Möbius's avatar
 
Jan Möbius committed
97

Matthias Möller's avatar
Matthias Möller committed
98 99
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-TextureControl")

Jan Möbius's avatar
 
Jan Möbius committed
100 101 102
  public:

  signals:
103

Dirk Wilden's avatar
Dirk Wilden committed
104
    // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
105
    void updateView();
Jan Möbius's avatar
Jan Möbius committed
106
    void updatedObject(int _identifier, const UpdateType& _type);
107

Dirk Wilden's avatar
Dirk Wilden committed
108
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
109
    void updateTexture( QString , int);
110

Dirk Wilden's avatar
Dirk Wilden committed
111
    // LoggingInterface
Jan Möbius's avatar
 
Jan Möbius committed
112 113
    void log(Logtype _type, QString _message);
    void log(QString _message);
114

Dirk Wilden's avatar
Dirk Wilden committed
115
    // MenuInterface
116
    void addMenubarAction(QAction* _action, QString _type );
Jan Möbius's avatar
 
Jan Möbius committed
117

118 119
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type );
120

121

Jan Möbius's avatar
 
Jan Möbius committed
122
  private slots:
123

Dirk Wilden's avatar
Dirk Wilden committed
124 125
    // BaseInterface
    void pluginsInitialized();
Jan Möbius's avatar
Jan Möbius committed
126
    void slotObjectUpdated(int _identifier, const UpdateType& _type);
127
    void slotDrawModeChanged(int _viewerId );
128

Dirk Wilden's avatar
Dirk Wilden committed
129
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
130
    void slotUpdateAllTextures( );
131 132 133 134 135 136
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension , int _id ){slotTextureAdded( _textureName , _filename , QImage() , _dimension , _id );}
    void slotTextureAdded( QString _textureName , QImage _image , uint _dimension , int _id ){slotTextureAdded( _textureName , QString() , _image , _dimension , _id );}
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension ){slotTextureAdded( _textureName , _filename , QImage() , _dimension );}
    void slotTextureAdded( QString _textureName , QImage _image , uint _dimension ){slotTextureAdded( _textureName , QString() , _image , _dimension );}
    void slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ){slotMultiTextureAdded( _textureGroup , _name , _filename , QImage() , _id , _textureId );}
    void slotMultiTextureAdded( QString _textureGroup , QString _name , QImage _image , int _id , int& _textureId ){slotMultiTextureAdded( _textureGroup , _name , QString() , _image , _id , _textureId );}
Jan Möbius's avatar
 
Jan Möbius committed
137
    void slotTextureUpdated( QString _textureName , int _identifier );
Dirk Wilden's avatar
Dirk Wilden committed
138
    void slotSetTextureMode(QString _textureName ,QString _mode, int _id);
Jan Möbius's avatar
 
Jan Möbius committed
139
    void slotSetTextureMode(QString _textureName ,QString _mode);
Dirk Wilden's avatar
Dirk Wilden committed
140
    void slotSwitchTexture( QString _textureName, int _id );
Jan Möbius's avatar
 
Jan Möbius committed
141
    void slotSwitchTexture( QString _textureName );
142
    void slotUpdateTexture( QString _textureName , int _identifier);
143 144
    void slotTextureChangeImage( QString _textureName , QImage& _image , int _id );
    void slotTextureChangeImage( QString _textureName , QImage& _image );
145 146
    void slotTextureGetImage( QString _textureName, QImage& _image, int _id );
    void slotTextureGetImage( QString _textureName, QImage& _image );
147
    void slotTextureIndex( QString _textureName, int _id, int& _index);
148
    void slotTextureIndexPropertyName( int _id, QString& _propertyName);
149
    void slotTextureName( int _id, int _textureIndex, QString& _textureName);
150
    void slotTextureFilename( int _id, QString _textureName, QString& _textureFilename);
151 152 153
    void slotGetCurrentTexture( int _id, QString& _textureName );
    void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures );
    
154 155
    // LoadSaveInterface
    void fileOpened( int _id );
156
    void addedEmptyObject( int _id );
157 158
    
    //BackupInterface
Jan Möbius's avatar
Jan Möbius committed
159 160
    void slotAboutToRestore( int _objectid );
    void slotRestored( int _objectid);
Jan Möbius's avatar
Jan Möbius committed
161

Jan Möbius's avatar
 
Jan Möbius committed
162
  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
163 164 165

    void doSwitchTexture( QString _textureName, int _id );

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

Dirk Wilden's avatar
Dirk Wilden committed
169 170
    /// Slot for showing the TextureProperties Dialog
    void slotSetTextureProperties();
Jan Möbius's avatar
 
Jan Möbius committed
171

Jan Möbius's avatar
 
Jan Möbius committed
172
  public :
Dirk Wilden's avatar
Dirk Wilden committed
173
    /// Constructor
Jan Möbius's avatar
Jan Möbius committed
174
    TextureControlPlugin();
Dirk Wilden's avatar
Dirk Wilden committed
175
    /// Destructor
Jan Möbius's avatar
 
Jan Möbius committed
176
    ~TextureControlPlugin() {delete(settingsDialog_);};
Jan Möbius's avatar
 
Jan Möbius committed
177

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

Jan Möbius's avatar
 
Jan Möbius committed
181
  private :
Jan Möbius's avatar
 
Jan Möbius committed
182

183 184 185 186
    void slotTextureAdded( QString _textureName , QString _fileName , QImage _image , uint _dimension , int _id );
    void slotTextureAdded( QString _textureName , QString _fileName , QImage _image , uint _dimension );
    void slotMultiTextureAdded( QString _textureGroup , QString _name , QString _fileName , QImage _image , int _id , int& _textureId );
    
Dirk Wilden's avatar
Dirk Wilden committed
187 188
    bool StringToBool(QString _value);

189
    /// Checks for a correct drawmode and changes if necessary
190
    void switchDrawMode( TextureType _type, int _id );
191

192
    TextureData globalTextures_;
Jan Möbius's avatar
 
Jan Möbius committed
193

Jan Möbius's avatar
 
Jan Möbius committed
194
    texturePropertiesWidget* settingsDialog_;
Jan Möbius's avatar
 
Jan Möbius committed
195

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

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

202
  private:
Jan Möbius's avatar
 
Jan Möbius committed
203

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

208
#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
209 210 211 212 213
    /// 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

214 215 216 217
    template< typename MeshT >
    void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
                              int _textureid, MeshT& _mesh,
                              OpenMesh::VPropHandleT< double > _texProp);
218

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

223
#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
224 225 226 227 228
    /// Handles data stored in new opened files ( e.g. Texture Information )
    template< typename VolumeMeshObjectT >
    void handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj, int _id );
#endif

229 230 231 232 233 234
    /** \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 );

235 236 237 238 239
    //===========================================================================
    /** @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
240 241
    /// Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property
    template< typename MeshT >
242
    void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
243

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

248
#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
249 250 251 252 253
    /// 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

254 255 256 257 258 259 260 261
    /** @} */

    //===========================================================================
    /** @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
262 263
    /// Copy the supplied 2D vertex property to the 2D vertex OM property
    template< typename MeshT >
264
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
265 266
    /// Copy the supplied 2D halfedge property to the 2D halfedge OM property
    template< typename MeshT >
267
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::HPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
268

269
#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
270 271 272 273 274
    /// 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

275 276
    /** @} */

277
    //===========================================================================
Jan Möbius's avatar
Jan Möbius committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
    /** @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
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
      * @{ */
    //===========================================================================

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

    /** @} */
321
    
Jan Möbius's avatar
 
Jan Möbius committed
322 323
  public slots:
    QString version() { return QString("1.0"); };
Jan Möbius's avatar
 
Jan Möbius committed
324 325
 };

326 327 328 329 330 331 332 333 334 335 336
//=============================================================================
#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

337
#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
338 339 340 341 342 343 344 345 346 347 348
  #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

349 350 351 352 353
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
#define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
#include "TextureControlHistogramsT.cc"
#endif

354

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