Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TangentSpace.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2015 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision$ *
38 * $LastChangedBy$ *
39 * $Date$ *
40 * *
41 \*===========================================================================*/
42 
43 #ifndef TANGENTSPACEPLUGIN_HH
44 #define TANGENTSPACEPLUGIN_HH
45 
49 
52 
53 
54 #include <QObject>
55 #include <QMenuBar>
56 #include <QLineEdit>
57 
58 #include <string>
59 
61 {
62  Q_OBJECT
63  Q_INTERFACES(BaseInterface)
64  Q_INTERFACES(ToolboxInterface)
65 
66 #if QT_VERSION >= 0x050000
67  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-TangentSpace")
68 #endif
69 
70  signals:
71 
72  void updatedObject(int, const UpdateType&);
73 
74  // ToolboxInterface
75  void addToolbox( QString _name , QWidget* _widget, QIcon* _icon);
76 
77  private slots:
78  void pluginsInitialized();
79 
80  public :
81 
82  TangentSpace();
83  ~TangentSpace();
84 
85  QString name() { return (QString("TangentSpace")); };
86  QString description( ) { return (QString("Compute tangent space properties")); };
87 
88  // decomposition method: extract rotational part from tangent space matrix
89  enum
90  {
91  DECOMP_GRAM_SCHMIDT = 0, // QR decomposition with gram-schmidt process: n is unchanged, b has no influence
92  DECOMP_HALF_ANGLE, // QR decomposition with half angle rotation: n is unchanged, t and b equally weighted
93  DECOMP_POLAR // polar decomposition, t,b,n all equally weighted / requires eigen math lib
94  };
95 
96  struct TangentBasis
97  {
98  ACG::Vec3f t,b,n;
99  float parity;
100 
101  void setZero();
102  void orthonormalize(int method = 0);
103 
104  void normalize();
105  void add(const TangentBasis& _r);
106 
107  void computeParity();
108  };
109 
110 
111  // compute unnormalized triangle tangent, bitangent and normal vector
112  // returns parity
113  float computeTriTBN(const ACG::Vec3f* _pos, const ACG::Vec2f* _texc, ACG::Vec3f* _outT, ACG::Vec3f* _outB, ACG::Vec3f* _outN, bool _divByDet = true);
114 
115  float computeTriTBN(TriMesh* mesh, TriMesh::FaceHandle _fh, ACG::Vec3f* _outT, ACG::Vec3f* _outB, ACG::Vec3f* _outN, bool _divByDet = true);
116  float computeFaceTBN(PolyMesh* mesh, PolyMesh::FaceHandle _fh, ACG::Vec3f* _outT, ACG::Vec3f* _outB, ACG::Vec3f* _outN, bool _divByDet = true);
117 
118 
119  // compute tangent matrix of triangle (optionally weighted by angle at incoming halfedge and/or area of triangle)
120  void computeWeightedTangentSpace(TriMesh* mesh, TriMesh::HalfedgeHandle _h, TangentBasis* _out);
121  void computeWeightedTangentSpace(PolyMesh* mesh, PolyMesh::HalfedgeHandle _h, TangentBasis* _out);
122 
123 
124  // parity of tangent space matrix = sign(det(TBN))
125  // returns +1: positive, -1: mirrored
126  float computeParity(const ACG::Vec3f& t, const ACG::Vec3f& b, const ACG::Vec3f& n);
127 
128  // get pos array of triangle
129  void getTriPos(TriMesh* _mesh, TriMesh::FaceHandle _h, ACG::Vec3f* _outPos);
130 
131  // area of triangle in texture space
132  float computeUVArea(TriMesh* _mesh, TriMesh::HalfedgeHandle _h);
133 
134  void computePerVertexTangents(TriMesh* _mesh);
135  void computePerHalfedgeTangents(TriMesh* _mesh);
136 
137  void getGUIConfig();
138 
139  private:
140 
141  // weighting of tangent space matrices within smoothing groups
142  bool weightByAngle_;
143  bool weightByArea_;
144  bool weightByUVArea_;
145  QCheckBox* weightByAngleGUI_; // qt checkbox widgets
146  QCheckBox* weightByAreaGUI_;
147  QCheckBox* weightByUVAreaGUI_;
148 
149  // overwrite vertex normals with resulting normals from tangent basis
150  bool overwriteVertexNormals_;
151  QCheckBox* overwriteNormalsGUI_;
152 
153  // detect and preserve sharp edges at texture seams
154  bool preserveTextureSeams_;
155  QCheckBox* preserveTextureSeamsGUI_;
156 
157  // extraction method to get rotational part of tangent space matrix
158  int decompMethod_;
159  QComboBox* decompMethodGUI_; // qt combobox
160 
161  // property name of tangent vectors
162  std::string propName_;
163  QLineEdit* propNameGUI_; // qt editbox
164 
165  public slots:
166 
167  void slotComputePerVertex();
168  void slotComputePerHalfedge();
169 
170  QString version() { return QString("1.0"); };
171 
172 };
173 
174 
175 
176 
177 
178 #endif //TANGENTSPACEPLUGIN_HH
Plugins can add its own toolbox to the main widget's toolbox area by using this interface.
QString description()
Return a description of what the plugin is doing.
Definition: TangentSpace.hh:86
Update type class.
Definition: UpdateType.hh:70
void pluginsInitialized()
Set the scripting slot descriptions.
QString name()
Return a name for the plugin.
Definition: TangentSpace.hh:85
Interface class from which all plugins have to be created.