TextureControl.hh 15.6 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
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
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
42

43 44 45 46 47 48 49 50 51 52 53 54 55




#ifndef TEXTURECONTROLPLUGIN_HH
#define TEXTURECONTROLPLUGIN_HH

#define OM_FORCE_STATIC_CAST

#include <QObject>
#include <QMenuBar>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
56
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
57 58 59
#include <OpenFlipper/BasePlugin/TextureInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
60
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
61
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
62 63
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
64

65
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
66 67
    #include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
68
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
69 70 71
    #include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif

72 73 74 75
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
    #include <ObjectTypes/BSplineSurface/BSplineSurface.hh>
#endif

76
#include <OpenFlipper/common/Types.hh>
77
#include "Dialogs/textureProperties.hh"
78

79
#include "TextureData.hh"
80

81
class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
82 83 84 85 86 87
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(TextureInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoggingInterface)
88
  Q_INTERFACES(LoadSaveInterface)
89
  Q_INTERFACES(ContextMenuInterface)
90
  Q_INTERFACES(BackupInterface)
91

92 93
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-TextureControl")

94 95 96
  public:

  signals:
97

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

Dirk Wilden's avatar
Dirk Wilden committed
102
    // TextureInterface
103
    void updateTexture( QString , int);
104

Dirk Wilden's avatar
Dirk Wilden committed
105
    // LoggingInterface
106 107
    void log(Logtype _type, QString _message);
    void log(QString _message);
108

Dirk Wilden's avatar
Dirk Wilden committed
109
    // MenuInterface
110
    void addMenubarAction(QAction* _action, QString _type );
111

112 113
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type );
114

115

116
  private slots:
117

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

Dirk Wilden's avatar
Dirk Wilden committed
123
    // TextureInterface
124
    void slotUpdateAllTextures( );
125 126 127 128 129 130
    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 );}
131
    void slotTextureUpdated( QString _textureName , int _identifier );
Dirk Wilden's avatar
Dirk Wilden committed
132
    void slotSetTextureMode(QString _textureName ,QString _mode, int _id);
133
    void slotSetTextureMode(QString _textureName ,QString _mode);
Dirk Wilden's avatar
Dirk Wilden committed
134
    void slotSwitchTexture( QString _textureName, int _id );
135
    void slotSwitchTexture( QString _textureName );
136
    void slotUpdateTexture( QString _textureName , int _identifier);
137 138
    void slotTextureChangeImage( QString _textureName , QImage& _image , int _id );
    void slotTextureChangeImage( QString _textureName , QImage& _image );
139 140
    void slotTextureGetImage( QString _textureName, QImage& _image, int _id );
    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 146 147
    void slotGetCurrentTexture( int _id, QString& _textureName );
    void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures );
    
148 149
    // LoadSaveInterface
    void fileOpened( int _id );
150
    void addedEmptyObject( int _id );
151 152
    
    //BackupInterface
153 154
    void slotAboutToRestore( int _objectid );
    void slotRestored( int _objectid);
Jan Möbius's avatar
Jan Möbius committed
155

156
  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
157 158 159

    void doSwitchTexture( QString _textureName, int _id );

Dirk Wilden's avatar
Dirk Wilden committed
160
    /// Called when an action in the TextureMenu is triggered
161
    void slotTextureMenu(QAction* _action);
162

Dirk Wilden's avatar
Dirk Wilden committed
163 164
    /// Slot for showing the TextureProperties Dialog
    void slotSetTextureProperties();
165

166
  public :
Dirk Wilden's avatar
Dirk Wilden committed
167
    /// Constructor
Jan Möbius's avatar
Jan Möbius committed
168
    TextureControlPlugin();
Dirk Wilden's avatar
Dirk Wilden committed
169
    /// Destructor
170
    ~TextureControlPlugin() {delete(settingsDialog_);};
171

172
    QString name() { return (QString("TextureControl")); };
173 174
    QString description( ) { return (QString("Handles Textures which are written to mesh properties")); };

175
  private :
176

177 178 179 180
    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 );
    
181 182
    bool StringToBool(QString _value);

183
    /// Checks for a correct drawmode and changes if necessary
184
    void switchDrawMode( TextureType _type, int _id );
185

186
    TextureData globalTextures_;
187

188
    texturePropertiesWidget* settingsDialog_;
189

190 191
  private slots:
    void applyDialogSettings(TextureData* _texData, QString _textureName, int _id);
192

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

196
  private:
197

198 199
    /// Calls the correct \a copyTexture() function to copy the texture property into the displayed OM property
    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 204 205 206 207
    /// 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

208 209 210 211
    template< typename MeshT >
    void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
                              int _textureid, MeshT& _mesh,
                              OpenMesh::VPropHandleT< double > _texProp);
212

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

217
#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
218 219 220 221 222
    /// Handles data stored in new opened files ( e.g. Texture Information )
    template< typename VolumeMeshObjectT >
    void handleFileOpenTexturesOVM( VolumeMeshObjectT* _obj, int _id );
#endif

223 224 225 226 227 228
    /** \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 );

229 230 231 232 233
    //===========================================================================
    /** @name 1D Texture copy functions( copy 1D input textures to target texture coordinates and transform values )
      * @{ */
    //===========================================================================

234 235
    /// Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property
    template< typename MeshT >
236
    void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
237

238 239
    /// Copy the supplied 1D halfedge property to both coordinates of the 2D halfedge OM texture property
    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 244 245 246 247
    /// 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

248 249 250 251 252 253 254 255
    /** @} */

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


256 257
    /// Copy the supplied 2D vertex property to the 2D vertex OM property
    template< typename MeshT >
258
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
259 260
    /// Copy the supplied 2D halfedge property to the 2D halfedge OM property
    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 265 266 267 268
    /// 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

269 270
    /** @} */

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

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

    /** @} */
315
    
316 317
  public slots:
    QString version() { return QString("1.0"); };
318 319
 };

320 321 322
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_C)
#define TEXTURECONTROL_1D_TEXTURE_HANDLING_TEMPLATES
323
#include "TextureControl1DTextureHandlingT_impl.hh"
324 325 326 327
#endif

#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_C)
#define TEXTURECONTROL_2D_TEXTURE_HANDLING_TEMPLATES
328
#include "TextureControl2DTextureHandlingT_impl.hh"
329 330
#endif

331
#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
332 333
  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_C)
  #define TEXTURECONTROL_1D_TEXTURE_HANDLING_OVM_TEMPLATES
334
  #include "TextureControl1DTextureHandlingOVMT_impl.hh"
335 336 337 338
  #endif

  #if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_C)
  #define TEXTURECONTROL_2D_TEXTURE_HANDLING_OVM_TEMPLATES
339
  #include "TextureControl2DTextureHandlingOVMT_impl.hh"
340 341 342
  #endif
#endif

343 344
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
#define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
345
#include "TextureControlHistogramsT_impl.hh"
346 347
#endif

348

349
#endif //TEXTURECONTROLPLUGIN_HH