TextureControl.hh 7.59 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
Jan Möbius's avatar
 
Jan Möbius committed
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16 17 18 19
//  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.
Jan Möbius's avatar
 
Jan Möbius committed
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




#ifndef TEXTURECONTROLPLUGIN_HH
#define TEXTURECONTROLPLUGIN_HH

#define OM_FORCE_STATIC_CAST

#include <QObject>
#include <QMenuBar>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/TextureInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
47 48
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52 53 54 55 56

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

struct Texture {
  QString name;
  QString filename;
  uint dimension;
Jan Möbius's avatar
 
Jan Möbius committed
57

Jan Möbius's avatar
 
Jan Möbius committed
58 59
  double clamp_min;
  double clamp_max;
Jan Möbius's avatar
 
Jan Möbius committed
60

Jan Möbius's avatar
 
Jan Möbius committed
61 62
  bool clamp;
  bool repeat;
Jan Möbius's avatar
 
Jan Möbius committed
63

Jan Möbius's avatar
 
Jan Möbius committed
64
  double max_val;
Jan Möbius's avatar
 
Jan Möbius committed
65

Jan Möbius's avatar
 
Jan Möbius committed
66
  bool center;
Jan Möbius's avatar
 
Jan Möbius committed
67

Jan Möbius's avatar
 
Jan Möbius committed
68
  bool abs;
Jan Möbius's avatar
 
Jan Möbius committed
69

Jan Möbius's avatar
 
Jan Möbius committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  bool scale;

  uint type;
};

class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(TextureInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoggingInterface)

  public:
    enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};

  signals:
Dirk Wilden's avatar
Dirk Wilden committed
87
    // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
88
    void updateView();
Dirk Wilden's avatar
Dirk Wilden committed
89
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
90
    void updateTexture( QString , int);
Dirk Wilden's avatar
Dirk Wilden committed
91
    // LoggingInterface
Jan Möbius's avatar
 
Jan Möbius committed
92 93
    void log(Logtype _type, QString _message);
    void log(QString _message);
Dirk Wilden's avatar
Dirk Wilden committed
94
    // MenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
95
    void addMenubarAction(QAction* _action, MenuActionType _type );
Jan Möbius's avatar
 
Jan Möbius committed
96 97

  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
98 99
    // BaseInterface
    void pluginsInitialized();
Jan Möbius's avatar
 
Jan Möbius committed
100
    void slotObjectUpdated(int _identifier);
Dirk Wilden's avatar
Dirk Wilden committed
101
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
102
    void slotUpdateAllTextures( );
Jan Möbius's avatar
 
Jan Möbius committed
103
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension );
Jan Möbius's avatar
 
Jan Möbius committed
104 105
    void slotTextureUpdated( QString _textureName , int _identifier );
    void slotSetTextureMode(QString _textureName ,QString _mode);
Jan Möbius's avatar
 
Jan Möbius committed
106 107
    void slotSwitchTexture( QString _textureName );

Jan Möbius's avatar
 
Jan Möbius committed
108
  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
109
    /// Called when an action in the TextureMenu is triggered
Jan Möbius's avatar
 
Jan Möbius committed
110
    void slotTextureMenu(QAction* _action);
Jan Möbius's avatar
 
Jan Möbius committed
111

Dirk Wilden's avatar
Dirk Wilden committed
112 113 114
    /// Slot for showing the TextureProperties Dialog
    void slotSetTextureProperties();
    /// Called when Ok was clicked in the dialog
Jan Möbius's avatar
 
Jan Möbius committed
115
    void slotTexturePropertiesOk();
Dirk Wilden's avatar
Dirk Wilden committed
116
    /// Called when Cancel was clicked in the dialog
Jan Möbius's avatar
 
Jan Möbius committed
117
    void slotTexturePropertiesCancel();
Dirk Wilden's avatar
Dirk Wilden committed
118
    /// Called when Apply was clicked in the dialog
Jan Möbius's avatar
 
Jan Möbius committed
119
    void slotTexturePropertiesApply();
Jan Möbius's avatar
 
Jan Möbius committed
120

Jan Möbius's avatar
 
Jan Möbius committed
121
  public :
Dirk Wilden's avatar
Dirk Wilden committed
122 123 124
    /// Constructor
    TextureControlPlugin() {};
    /// Destructor
Jan Möbius's avatar
 
Jan Möbius committed
125
    ~TextureControlPlugin() {delete(settingsDialog_);};
Jan Möbius's avatar
 
Jan Möbius committed
126

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

Jan Möbius's avatar
 
Jan Möbius committed
130 131
  private :
    QMenu *textureMenu_;
Jan Möbius's avatar
 
Jan Möbius committed
132

Jan Möbius's avatar
 
Jan Möbius committed
133
    QActionGroup* actionGroup_;
Jan Möbius's avatar
 
Jan Möbius committed
134

Jan Möbius's avatar
 
Jan Möbius committed
135
    QAction* AC_Texture_Settings;
Jan Möbius's avatar
 
Jan Möbius committed
136

Jan Möbius's avatar
 
Jan Möbius committed
137
    QString activeTexture_;
Jan Möbius's avatar
 
Jan Möbius committed
138

Jan Möbius's avatar
 
Jan Möbius committed
139
    std::vector< Texture > textures_;
Jan Möbius's avatar
 
Jan Möbius committed
140

Jan Möbius's avatar
 
Jan Möbius committed
141
    std::vector<QAction*> textureActions_;
Jan Möbius's avatar
 
Jan Möbius committed
142

Jan Möbius's avatar
 
Jan Möbius committed
143
    texturePropertiesWidget* settingsDialog_;
Jan Möbius's avatar
 
Jan Möbius committed
144

Jan Möbius's avatar
 
Jan Möbius committed
145
    /// Set the active texture values to the values in the dialog box.
Jan Möbius's avatar
 
Jan Möbius committed
146 147
    void applyDialogSettings();

Jan Möbius's avatar
 
Jan Möbius committed
148 149
    /// Update the values in the Dialog box to the current ones
    void updateDialog();
Jan Möbius's avatar
 
Jan Möbius committed
150

151

Jan Möbius's avatar
 
Jan Möbius committed
152 153 154 155 156 157 158 159
    /// Take a scalar value and return a clamped,... depending on texture settings
    inline
    void computeValue(int _textureid, double _min, double _max, double& _value);

    /// Calls the correct \a copyTexture() function to copy the texture property into the displayed OM property
    template< typename MeshT >
    void doUpdateTexture ( int _textureid, MeshT& _mesh);

160 161 162 163
    template< typename MeshT >
    void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
                              int _textureid, MeshT& _mesh,
                              OpenMesh::VPropHandleT< double > _texProp);
164 165 166 167 168 169

    //===========================================================================
    /** @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
170 171 172
    /// Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property
    template< typename MeshT >
    void copyTexture(int _textureid, MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
173

Jan Möbius's avatar
 
Jan Möbius committed
174 175 176
    /// Copy the supplied 1D halfedge property to both coordinates of the 2D halfedge OM texture property
    template< typename MeshT >
    void copyTexture(int _textureid, MeshT& _mesh, OpenMesh::HPropHandleT< double > _texProp );
177

178 179 180 181 182 183 184 185 186 187 188

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

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

189 190 191 192 193 194 195 196
    /** @} */

    //===========================================================================
    /** @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
197 198 199 200 201 202 203
    /// Copy the supplied 2D vertex property to the 2D vertex OM property
    template< typename MeshT >
    void copyTexture(int _textureid, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
    /// Copy the supplied 2D halfedge property to the 2D halfedge OM property
    template< typename MeshT >
    void copyTexture(int _textureid, MeshT& _mesh, OpenMesh::HPropHandleT< ACG::Vec2d > _texProp );

204 205
    /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
206 207
  public slots:
    QString version() { return QString("1.0"); };
Jan Möbius's avatar
 
Jan Möbius committed
208 209
 };

210 211 212 213 214 215 216 217 218 219 220
//=============================================================================
#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

221 222 223 224 225
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
#define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
#include "TextureControlHistogramsT.cc"
#endif

226

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