TextureInterface.hh 21.8 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


Jan Möbius's avatar
 
Jan Möbius committed
44 45
#ifndef TEXTUREINTERFACE_HH
#define TEXTUREINTERFACE_HH
Jan Möbius's avatar
 
Jan Möbius committed
46 47 48 49

 #include <QtGui>
 #include <QMenuBar>
 #include <OpenFlipper/common/Types.hh>
Jan Möbius's avatar
 
Jan Möbius committed
50

Jan Möbius's avatar
 
Jan Möbius committed
51
 /**
Mike Kremer's avatar
Mike Kremer committed
52 53
  * \brief Provide texture support for a plugin.
  *
Jan Möbius's avatar
 
Jan Möbius committed
54 55
  * This Interface should be used by plugins which will provide a texture. The texture coordinates have
  * to be written into a mesh property. You do not need to write texture information into the texture
Jan Möbius's avatar
 
Jan Möbius committed
56
  * coordinates of the mesh. As other plugins may provide textures to, the visualization of the
Jan Möbius's avatar
 
Jan Möbius committed
57 58 59 60
  * textures is handled by the main application (or a texture control plugin).
 */
class TextureInterface {
   signals :
Jan Möbius's avatar
 
Jan Möbius committed
61

Jan Möbius's avatar
 
Jan Möbius committed
62
      /** \brief Emit this Signal if a texture has been added (Property Name,filename,Dimension)
Dirk Wilden's avatar
Dirk Wilden committed
63 64 65 66
       *
       *  Emit this signal if a texture for a specific object has been added
       *
       *  @param  _name Name of the property which contains the tex coords (double or vec2d)
67
       *  @param _filename Filename of the texture (either local in OpenFlippers texture dir or global ( "./Textures/<name>")
Dirk Wilden's avatar
Dirk Wilden committed
68 69 70
       *  @param _dimension 1D texture ( currenty only supports 1 )
       *  @param _id id of an object
       */
71
      virtual void addTexture( QString _name , QString _filename , uint _dimension , int _id ) {};
Dirk Wilden's avatar
Dirk Wilden committed
72 73 74 75

      /** \brief Emit this Signal if a texture has been added (Property Name,filename,Dimension)
       *
       *  Emit this signal if a global texture has been added
Jan Möbius's avatar
 
Jan Möbius committed
76
       *
Jan Möbius's avatar
 
Jan Möbius committed
77
       *  @param  _name Name of the property which contains the tex coords (double or vec2d)
78
       *  @param _filename Filename of the texture (either local in OpenFlippers texture dir or global ( "./Textures/<name>")
Jan Möbius's avatar
 
Jan Möbius committed
79 80
       *  @param _dimension 1D texture ( currenty only supports 1 )
       */
81
      virtual void addTexture( QString _name , QString _filename , uint _dimension ) {};
Jan Möbius's avatar
 
Jan Möbius committed
82

83 84 85
      /** \brief Emit this Signal if you want to add a texture for a multitexturing mode
       *
       *  Emit this signal if a texture should be added to a multitexturing mode.
Jan Möbius's avatar
Jan Möbius committed
86
       *
87
       *  The first parameter defines a texturegroup which collects all textures
Jan Möbius's avatar
Jan Möbius committed
88 89 90 91
       *  that should be painted in the multitexturing mode. This group does not
       *  have to exist on the first call but will be created automatically.
       *
       *  The second parameter defines the single textures name used in the gui.
92 93 94 95 96
       *
       *  @param _textureGroup Multitexturing group using this texture
       *  @param _name         Name of the property which contains the tex coords (double or vec2d)
       *  @param _filename     Filename of the texture (either local in OpenFlippers texture dir or global ( "./Textures/<name>")
       *  @param _id           Id of the object which should use that texture
Jan Möbius's avatar
Jan Möbius committed
97
       *  @param _textureId    The new internal id of the texture( This id is object related!!). Use this id in your mesh as the texture index (Use mesh->set_texture_index on the face using this texture).
98
       */
99
      virtual void addMultiTexture( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ) {};
100

Jan Möbius's avatar
 
Jan Möbius committed
101 102
      /** \brief Tell Plugins to update the given texture for the given identifier
       */
103
      virtual void updateTexture( QString _textureName  , int _identifier) {};
Jan Möbius's avatar
 
Jan Möbius committed
104

Jan Möbius's avatar
 
Jan Möbius committed
105 106 107
      /** \brief Tell Plugins to update all textures
       */
      virtual void updateAllTextures( ) {};
Jan Möbius's avatar
 
Jan Möbius committed
108 109 110 111

      /** \brief emit this signal if you updated a texture
       *
       *  Give the name of the texture and the id of the object or -1 if all objects were update
Jan Möbius's avatar
 
Jan Möbius committed
112 113
      */
      virtual void updatedTextures( QString , int ) {};
Jan Möbius's avatar
 
Jan Möbius committed
114

Dirk Wilden's avatar
Dirk Wilden committed
115 116
      /** \brief emit this signal if you want to switch the texture of a specific object
       */
117
      virtual void switchTexture( QString _textureName , int _id  ) {};
Dirk Wilden's avatar
Dirk Wilden committed
118 119 120

      /** \brief emit this signal if you want to switch the global texture
       */
121
      virtual void switchTexture( QString _textureName ) {};
Jan Möbius's avatar
 
Jan Möbius committed
122

Jan Möbius's avatar
 
Jan Möbius committed
123
      /** \brief emit this signal if you want to set a special mode for this texture (Clamping,...)
Jan Möbius's avatar
 
Jan Möbius committed
124
       *
Jan Möbius's avatar
 
Jan Möbius committed
125
       *  emit this signal if you want to set a special mode for this texture
Jan Möbius's avatar
 
Jan Möbius committed
126
       *
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
       * The values are modified in the following way:\n
       *
       * First the absolute value of the property is taken if requested:\n
       * abs=true/false \n
       *
       * Then this value is clamped against the given values:\n
       * clamp=true/false \n
       * clamp_min=value \n
       * clamp_max=value \n
       *
       * If the texture should be repeated, the values are translated such that the minimum is at min_val(0.0 by default)
       * and than scaled such that the maximum is at max_val. This data is than passed to the rendering: \n
       * repeat=true/false \n
       * min_val=value \n
       * max_val=value \n
       *
       * If the texture should not be repeated you could choose to center the data around 0.5. The negative values are than mapped to 0..0.5
       * and the positive values to 0.5..1:\n
       * center=true/false\n
       *
       * Otherwise, the values are mapped directly to 0..1. You can also disable that final scaling with:\n
       * scale=true/false\n
       *
       * Examples:\n
       * Pass texture without modification: abs=false,clamp=false,repeat=false,center=false,scale=false\n
Jan Möbius's avatar
 
Jan Möbius committed
152
       *  @param _textureName Name of your Texture
Jan Möbius's avatar
 
Jan Möbius committed
153
       *  @param _mode colon separated String describing your settings (e.g. clamp,abs )
Jan Möbius's avatar
 
Jan Möbius committed
154
      */
155
      virtual void setTextureMode(QString _textureName ,QString _mode) {};
Jan Möbius's avatar
 
Jan Möbius committed
156

Dirk Wilden's avatar
Dirk Wilden committed
157 158 159 160 161
      /** \brief emit this signal if you want to set a special mode for this texture (Clamping,...)
       *
       * for info about the _mode parameter see setTextureMode(QString,QString)
       *
       *  @param _textureName Name of your Texture
Jan Möbius's avatar
 
Jan Möbius committed
162
       *  @param _mode colon separated String describing your settings (e.g. clamp,abs )
Dirk Wilden's avatar
Dirk Wilden committed
163 164
       *  @param _id id of an object
       */
165
      virtual void setTextureMode(QString _textureName ,QString _mode, int _id ) {};
Dirk Wilden's avatar
Dirk Wilden committed
166

167 168 169 170 171 172
      /** \brief Change the texture image of a given texture
       *
       *  @param _textureName The name of the texture which should be changed
       *  @param _image The new image for the texture
       *  @param _id Id of the object where the texture should be changed
       */
173
      virtual void textureChangeImage( QString _textureName , QImage& _image , int _id ) {};
174 175 176 177 178 179

      /** \brief Change the texture image of a given global texture
       *
       *  @param _textureName The name of the texture which should be changed
       *  @param _image The new image for the texture
       */
180
      virtual void textureChangeImage( QString _textureName , QImage& _image ) {};
181

182 183 184 185 186 187
      /** \brief get the texture image of a given texture
       *
       *  @param _textureName The name of the texture which should be addressed
       *  @param _image reference to the image for the texture
       *  @param _id Id of the object where the texture should be fetched from
       */
188
      virtual void textureGetImage( QString _textureName , QImage& _image , int _id ) {};
189 190 191 192 193 194

      /** \brief Get the texture image of a given global texture
       *
       *  @param _textureName The name of the texture which should be addressed
       *  @param _image reference to the image for the texture
       */
195
      virtual void textureGetImage( QString _textureName , QImage& _image ) {};
196 197 198 199 200 201 202

      /** \brief Get the texture index of a given texture
       *
       *  @param _textureName The name of the texture which should be addressed
       *  @param _id Id of the object where the texture is defined on
       *  @param _index the index of the texture (used for multiTexturing)
       */
203
      virtual void textureIndex( QString _textureName, int _id, int& _index) {};
204
      
205 206 207 208 209 210 211
      /** \brief Get the name of the texture index property
       *
       *  Get the name of the property that holds the texture index (face property).
       *
       *  @param _id The id of the mesh object
       *  @param _propertyName The name of the property that holds the texture indices
       */
212
      virtual void textureIndexPropertyName( int _id, QString& _propertyName) {};
213
      
214 215
       /** \brief get the name of the texture with given texture index
       *
216
       *  When using multiTexturing you can retrieve the texture index of a face with 'mesh.texture_index(Handle)'
217
       *  This function maps the texture index to the name of the actual texture that is used to texture
218 219
       *  the face. Note that some plugins may change the mesh's internal property name for the texture
       *  index such that mesh.texture_index(Handle) won't return a valid texture index.
220 221 222 223 224
       *
       *  @param _id Id of the object where the texture should be fetched from
       *  @param _textureIndex texture index of the wanted texture
       *  @param _textureName this returns the name of the texture
       */
225
      virtual void textureName( int _id, int _textureIndex, QString& _textureName ) {};
226 227 228 229 230 231 232 233 234 235
      
      /** \brief get the filename of the texture with given texture index
       *
       *  Get the filename of a given texture with name _textureName. Retrieve the texture's
       *  name via signal textureName(int,int,QString&) first.
       *
       *  @param _id Id of the object where the texture should be fetched from
       *  @param _textureName The name of the texture whose filename will be fetched
       *  @param _textureFilename this returns the name of the texture
       */
236
      virtual void textureFilename( int _id, QString _textureName, QString& _textureFilename ) {};
237

238 239 240 241 242
       /** \brief get the name of the texture which is currently enabled
       *
       *  @param _id Id of the object where the current texture should be fetched from
       *  @param _textureName this returns the name of the texture
       */
243
      virtual void getCurrentTexture( int _id, QString& _textureName ) {};
244 245 246 247 248 249 250
      
       /** \brief get the names of all sub-textures under the given multiTexture
       *
       *  @param _id Id of the object where the current texture should be fetched from
       *  @param _multiTextureName name of a multi texture
       *  @param _textureName this returns the names of all sub textures that are combined under the given multi texture
       */
251
      virtual void getSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures ) {};
252

Jan Möbius's avatar
 
Jan Möbius committed
253 254
   private slots :
      /** \brief update the texture with the given Name ( if this plugin provides this texture ) for all meshes
255 256 257 258
       *
       * This function is called if the texture of the object is about to be shown and the object has changed
       * since the last rendering of the texture.
       *
Jan Möbius's avatar
 
Jan Möbius committed
259 260 261
       * @param _textureName Name of the Texture to be updated
       * @param _identifier The id of the object to update
      */
262
      virtual void slotUpdateTexture( QString _textureName , int _identifier) {};
Jan Möbius's avatar
 
Jan Möbius committed
263

Jan Möbius's avatar
 
Jan Möbius committed
264 265 266
      /** \brief update all textures provided by this plugin
       */
      virtual void slotUpdateAllTextures( ) {};
Jan Möbius's avatar
 
Jan Möbius committed
267

268 269 270 271 272 273
      /** \brief A texture has been updated
       *
       *  A plugin has updated a Texture
       *  @param _textureName The name of the updated texture
       *  @param _identifier -1 if all objects updated, otherwise the identifier of the object
       */
274
      virtual void slotTextureUpdated( QString _textureName , int _identifier ) {};
275 276 277 278 279 280

      /** \brief This slot is called when a plugin requests to switch an objects texture
       *
       * @param _textureName Name of the Texture
       * @param _id id of an object
       */
281
      virtual void slotSwitchTexture( QString _textureName, int _id ) {};
282 283 284 285 286

      /** \brief This slot is called when a plugin requests to switch to a different texture mode
       *
       * @param _textureName Name of the Texture
      */
287
      virtual void slotSwitchTexture( QString _textureName ) {};
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303

   public :

      /// Destructor
      virtual ~TextureInterface() {};

   //===========================================================================
    /** @name Functions handled by textureControlPlugin
     *
     * Normally you dont have to do anything when these functions are called.
     * Texturecontrol handles visualization and updates of textures.
    * @{ */
   //===========================================================================

  private slots :

Jan Möbius's avatar
 
Jan Möbius committed
304 305
      /** \brief A texture has been added by a plugin.
       *
Dirk Wilden's avatar
Dirk Wilden committed
306 307 308 309 310 311 312
       * This slot is called when a texture for a specific object has been added by a plugin.
       *
       * @param _textureName Name of the Added texture (has to be equal to the property name)
       * @param _filename Filename of the Texture Image to be used
       * @param _dimension Dimension of the Texture (currently only 1D and 2D Textures are supported
       * @param _id id of an object
       */
313
      virtual void slotTextureAdded( QString _textureName , QString _filename , uint _dimension, int _id ) {};
Dirk Wilden's avatar
Dirk Wilden committed
314 315 316 317 318

      /** \brief A texture has been added by a plugin.
       *
       * This slot is called when a global texture has been added by a plugin.
       *
Jan Möbius's avatar
 
Jan Möbius committed
319 320
       * @param _textureName Name of the Added texture (has to be equal to the property name)
       * @param _filename Filename of the Texture Image to be used
321
       * @param _dimension Dimension of the Texture (currently only 1D and 2D Textures are supported
Jan Möbius's avatar
 
Jan Möbius committed
322
       */
323
      virtual void slotTextureAdded( QString _textureName , QString _filename , uint _dimension ) {};
Jan Möbius's avatar
 
Jan Möbius committed
324

325 326 327 328 329 330 331 332 333
      /** \brief A multiTexture has been added by a plugin.
       *
       * This slot is called when a Multi Texture has been added by a plugin.
       *
       * @param _name Name of the Added texture (has to be equal to the property name)
       * @param _filename Filename of the Texture Image to be used
       * @param _id Id of the object which should use the texture
       * @param _textureId    The new id of the texture( This id is object related!!)
       */
334 335
      virtual void slotMultiTextureAdded( QString _textureGroup , QString _name ,
                                          QString _filename , int _id , int& _textureId ) {};
336

Dirk Wilden's avatar
Dirk Wilden committed
337 338 339 340 341 342 343
      /** \brief Texturemode for texture should be changed
       *
       *  A plugin has updated the Texture settings for a texture
       *  @param _textureName The name of the updated texture
       *  @param _mode New mode flags for the given texture
       *  @param _id id of an object
       */
344
      virtual void slotSetTextureMode(QString _textureName ,QString _mode, int _id ) {};
Dirk Wilden's avatar
Dirk Wilden committed
345

346 347 348 349 350 351
      /** \brief Changes the texture image of a given texture
       *
       *  @param _textureName The name of the texture which should be changed
       *  @param _image The new image for the texture
       *  @param _id Id of the object where the texture should be changed
       */
352
      virtual void slotTextureChangeImage( QString _textureName , QImage& _image , int _id ) {};
353 354 355 356 357 358

      /** \brief Changes the texture image of a given global texture
       *
       *  @param _textureName The name of the texture which should be changed
       *  @param _image The new image for the texture
       */
359
      virtual void slotTextureChangeImage( QString _textureName , QImage& _image ) {};
360

Jan Möbius's avatar
 
Jan Möbius committed
361
      /** \brief Texturemode for texture should be changed
Jan Möbius's avatar
 
Jan Möbius committed
362
       *
Jan Möbius's avatar
 
Jan Möbius committed
363 364 365 366
       *  A plugin has updated the Texture settings for a texture
       *  @param _textureName The name of the updated texture
       *  @param _mode New mode flags for the given texture
       */
367
      virtual void slotSetTextureMode(QString _textureName ,QString _mode) {};
368 369 370 371 372 373 374
      
      /** \brief fetches the texture image of a given texture
       *
       *  @param _textureName The name of the texture which should be addressed
       *  @param _image reference to the image for the texture
       *  @param _id Id of the object where the texture should be fetched from
       */
375
      virtual void slotTextureGetImage( QString _textureName , QImage& _image , int _id ) {};
376 377 378 379 380 381

      /** \brief fetches the texture image of a given global texture
       *
       *  @param _textureName The name of the texture which should be addressed
       *  @param _image reference to the image for the texture
       */
382
      virtual void slotTextureGetImage( QString _textureName , QImage& _image ) {};
383
      
384 385 386 387 388 389
      /** \brief Get the texture index of a given texture
       *
       *  @param _textureName The name of the texture which should be addressed
       *  @param _id Id of the object where the texture is defined on
       *  @param _index the index of the texture (used for multiTexturing)
       */
390
      virtual void slotTextureIndex( QString _textureName, int _id, int& _index) {};
391
      
392 393 394 395 396 397 398
      /** \brief Get the name of the texture index property
       *
       *  Get the name of the property that holds the texture index (face property).
       *
       *  @param _id The id of the mesh object
       *  @param _propertyName The name of the property that holds the texture indices
       */
399
      virtual void slotTextureIndexPropertyName( int _id, QString& _propertyName) {};
400
      
401 402 403 404 405 406
       /** \brief get the name of the texture with given texture index
       *
       *  @param _id Id of the object where the texture should be fetched from
       *  @param _textureIndex texture index of the wanted texture
       *  @param _textureName this returns the name of the texture
       */
407
      virtual void slotTextureName( int _id, int _textureIndex, QString& _textureName ) {};
408 409 410 411 412 413 414 415 416 417 418
      
      /** \brief get the filename of the texture with given texture name
       *
       *  Get the filename to texture with name _textureName. Retrieve texture names
       *  via signal textureName(int,int,QString&) using the object's id and
       *  the texture index.
       *
       *  @param _id Id of the object where the texture should be fetched from
       *  @param _textureName texture name of the wanted texture
       *  @param _textureFilename this returns the filename of the texture
       */
419
      virtual void slotTextureFilename( int _id, QString _textureName, QString& _textureFilename ) {};
420 421 422 423 424 425
      
      /** \brief get the number of textures per object
       *
       *  @param _id Id of the object
       *  @param _numTextures returns the number of textures
       */
426
      virtual void slotNumberOfTextures( int _id, int& _numTextures ) {};
427

428 429 430 431 432
       /** \brief fetches the name of the texture which is currently enabled
       *
       *  @param _id Id of the object where the current texture should be fetched from
       *  @param _textureName this returns the name of the texture
       */
433
      virtual void slotGetCurrentTexture( int _id, QString& _textureName ) {};
434 435 436 437 438 439 440
      
       /** \brief fetches the names of all sub-textures under the given multiTexture
       *
       *  @param _id Id of the object where the current texture should be fetched from
       *  @param _multiTextureName name of a multi texture
       *  @param _textureName this returns the names of all sub textures that are combined under the given multi texture
       */
441
      virtual void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures ) {};
Jan Möbius's avatar
 
Jan Möbius committed
442

443
   /** @} */
Jan Möbius's avatar
 
Jan Möbius committed
444 445 446
};

Q_DECLARE_INTERFACE(TextureInterface,"OpenFlipper.TextureInterface/1.0")
Jan Möbius's avatar
 
Jan Möbius committed
447

Jan Möbius's avatar
 
Jan Möbius committed
448
#endif // TEXTUREINTERFACE_HH