TextureControl.hh 8.15 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>
47
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
48
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
49 50
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
Jan Möbius's avatar
 
Jan Möbius committed
51 52 53 54

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

55 56
#include "TextureData.hh"
/*
Jan Möbius's avatar
 
Jan Möbius committed
57 58 59 60
struct Texture {
  QString name;
  QString filename;
  uint dimension;
Jan Möbius's avatar
 
Jan Möbius committed
61

Jan Möbius's avatar
 
Jan Möbius committed
62 63
  double clamp_min;
  double clamp_max;
Jan Möbius's avatar
 
Jan Möbius committed
64

Jan Möbius's avatar
 
Jan Möbius committed
65 66
  bool clamp;
  bool repeat;
Jan Möbius's avatar
 
Jan Möbius committed
67

Jan Möbius's avatar
 
Jan Möbius committed
68
  double max_val;
Jan Möbius's avatar
 
Jan Möbius committed
69

Jan Möbius's avatar
 
Jan Möbius committed
70
  bool center;
Jan Möbius's avatar
 
Jan Möbius committed
71

Jan Möbius's avatar
 
Jan Möbius committed
72
  bool abs;
Jan Möbius's avatar
 
Jan Möbius committed
73

Jan Möbius's avatar
 
Jan Möbius committed
74 75 76
  bool scale;

  uint type;
77
};*/
Jan Möbius's avatar
 
Jan Möbius committed
78

79
class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
80 81 82 83 84 85
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(TextureInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoggingInterface)
86
  Q_INTERFACES(LoadSaveInterface)
87
  Q_INTERFACES(ContextMenuInterface)
Jan Möbius's avatar
 
Jan Möbius committed
88 89 90 91 92

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

  signals:
93

Dirk Wilden's avatar
Dirk Wilden committed
94
    // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
95
    void updateView();
96

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

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

Dirk Wilden's avatar
Dirk Wilden committed
104
    // MenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
105
    void addMenubarAction(QAction* _action, MenuActionType _type );
Jan Möbius's avatar
 
Jan Möbius committed
106

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

Jan Möbius's avatar
 
Jan Möbius committed
110
  private slots:
111

Dirk Wilden's avatar
Dirk Wilden committed
112 113
    // BaseInterface
    void pluginsInitialized();
Jan Möbius's avatar
 
Jan Möbius committed
114
    void slotObjectUpdated(int _identifier);
115

Dirk Wilden's avatar
Dirk Wilden committed
116
    // TextureInterface
Jan Möbius's avatar
 
Jan Möbius committed
117
    void slotUpdateAllTextures( );
Jan Möbius's avatar
 
Jan Möbius committed
118
    void slotTextureAdded( QString _textureName , QString _filename , uint _dimension );
Jan Möbius's avatar
 
Jan Möbius committed
119 120
    void slotTextureUpdated( QString _textureName , int _identifier );
    void slotSetTextureMode(QString _textureName ,QString _mode);
Jan Möbius's avatar
 
Jan Möbius committed
121 122
    void slotSwitchTexture( QString _textureName );

123 124 125
    // LoadSaveInterface
    void fileOpened( int _id );

126 127 128
    // ContextMenuInterface
    void slotUpdateContextMenu( int _objectId );

Jan Möbius's avatar
 
Jan Möbius committed
129
  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
130
    /// Called when an action in the TextureMenu is triggered
Jan Möbius's avatar
 
Jan Möbius committed
131
    void slotTextureMenu(QAction* _action);
Jan Möbius's avatar
 
Jan Möbius committed
132

Dirk Wilden's avatar
Dirk Wilden committed
133 134 135
    /// 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
136
    void slotTexturePropertiesOk();
Dirk Wilden's avatar
Dirk Wilden committed
137
    /// Called when Cancel was clicked in the dialog
Jan Möbius's avatar
 
Jan Möbius committed
138
    void slotTexturePropertiesCancel();
Dirk Wilden's avatar
Dirk Wilden committed
139
    /// Called when Apply was clicked in the dialog
Jan Möbius's avatar
 
Jan Möbius committed
140
    void slotTexturePropertiesApply();
Jan Möbius's avatar
 
Jan Möbius committed
141

Jan Möbius's avatar
 
Jan Möbius committed
142
  public :
Dirk Wilden's avatar
Dirk Wilden committed
143 144 145
    /// Constructor
    TextureControlPlugin() {};
    /// Destructor
Jan Möbius's avatar
 
Jan Möbius committed
146
    ~TextureControlPlugin() {delete(settingsDialog_);};
Jan Möbius's avatar
 
Jan Möbius committed
147

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

Jan Möbius's avatar
 
Jan Möbius committed
151 152
  private :
    QMenu *textureMenu_;
Jan Möbius's avatar
 
Jan Möbius committed
153

Jan Möbius's avatar
 
Jan Möbius committed
154
    QActionGroup* actionGroup_;
Jan Möbius's avatar
 
Jan Möbius committed
155

Jan Möbius's avatar
 
Jan Möbius committed
156
    QAction* AC_Texture_Settings;
Jan Möbius's avatar
 
Jan Möbius committed
157

Jan Möbius's avatar
 
Jan Möbius committed
158
    QString activeTexture_;
Jan Möbius's avatar
 
Jan Möbius committed
159

160
    TextureData globalTextures_;
Jan Möbius's avatar
 
Jan Möbius committed
161

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

Jan Möbius's avatar
 
Jan Möbius committed
164
    texturePropertiesWidget* settingsDialog_;
Jan Möbius's avatar
 
Jan Möbius committed
165

166 167
    QMenu* contextMenu_;

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

Jan Möbius's avatar
 
Jan Möbius committed
171 172
    /// Update the values in the Dialog box to the current ones
    void updateDialog();
Jan Möbius's avatar
 
Jan Möbius committed
173

174

Jan Möbius's avatar
 
Jan Möbius committed
175 176
    /// Take a scalar value and return a clamped,... depending on texture settings
    inline
177
    void computeValue(Texture& _texture, double _min, double _max, double& _value);
Jan Möbius's avatar
 
Jan Möbius committed
178 179 180

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

183 184 185 186
    template< typename MeshT >
    void getOriginalHistogram(std::vector< double>& _x, std::vector< double>& _y,
                              int _textureid, MeshT& _mesh,
                              OpenMesh::VPropHandleT< double > _texProp);
187 188 189 190 191 192

    //===========================================================================
    /** @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
193 194
    /// Copy the supplied 1D vertex property to both coordinates of the 2D vertex OM texture property
    template< typename MeshT >
195
    void copyTexture(Texture& _texture , MeshT& _mesh, OpenMesh::VPropHandleT< double > _texProp );
196

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

201 202 203 204

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

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

212 213 214 215 216 217 218 219
    /** @} */

    //===========================================================================
    /** @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
220 221
    /// Copy the supplied 2D vertex property to the 2D vertex OM property
    template< typename MeshT >
222
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::VPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
223 224
    /// Copy the supplied 2D halfedge property to the 2D halfedge OM property
    template< typename MeshT >
225
    void copyTexture(Texture& _texture, MeshT& _mesh, OpenMesh::HPropHandleT< ACG::Vec2d > _texProp );
Jan Möbius's avatar
 
Jan Möbius committed
226

227 228
    /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
229 230
  public slots:
    QString version() { return QString("1.0"); };
Jan Möbius's avatar
 
Jan Möbius committed
231 232
 };

233 234 235 236 237 238 239 240 241 242 243
//=============================================================================
#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

244 245 246 247 248
#if defined(INCLUDE_TEMPLATES) && !defined(TEXTURECONTROL_HISTOGRAMS_C)
#define TEXTURECONTROL_HISTOGRAMS_TEMPLATES
#include "TextureControlHistogramsT.cc"
#endif

249

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