localFrame.h 6.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* This library 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 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.u-strasbg.fr/                                         *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef LOCALFRAME_H_
#define LOCALFRAME_H_

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
28
29
#include <cmath>

30
31
32
33
34
35
36
namespace CGoGN {

namespace Utils {

/**
 * Class for representing a direct local frame composed of 3 orthonormal vectors T (tangent), B (bitangent) and N (normal).
 * This class can compress/decompress a local frame, switching from its explicit representation (3 vectors) to its compressed representation (1 vector).
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
37
 * Two different compressions coexist : one which is not correct on the extreme values (VEC3 getCompressed()) and one which is totally correct (VEC4 getCompressedSecure()).
38
39
 * Usage :
 *  VEC3 T,B,N ;							// current set of orthonormal vectors composing the direct frame.
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
40
 *  LocalFrame<PFP> lf(T,B,N) ; 				// Constructor from explicit expression.
41
 *  if (lf.isOrthoNormalDirect())			// test if the frame is Orthogonal, Normalized and Direct
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
42
43
 *   VEC4 compressed = lf.getCompressedSecure() ;	// Extract compressed frame
 *  LocalFrame<PFP> decompressed(compressed) ;	// Constructor from implicit (compressed) expression.
44
45
46
47
48
49
50
 *
 * All formulae were provided by "Représentation compacte d'un repère local", june 14th, 2011 by K. Vanhoey
 */
template <typename PFP>
class LocalFrame
{
	typedef typename PFP::REAL REAL ;
51
	typedef typename Geom::Vector<2,REAL> VEC2 ;
52
	typedef typename PFP::VEC3 VEC3 ;
53
	typedef typename Geom::Vector<4,REAL> VEC4 ;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

private: // fields
	/**
	 * The three explicit vectors
	 */
	VEC3 m_T,m_B,m_N ;

public: // methods
	/**
	 * Constructor from explicit data
	 * @param T the tangent vector
	 * @param B the bitangent vector
	 * @param N the normal vector
	 */
	LocalFrame(const VEC3& T, const VEC3& B, const VEC3& N) ;
69

70
71
72
73
74
	/**
	 * Constructor from implicit (compressed representation)
	 * @param compressedFrame an implicit (compressed) version of the local frame
	 */
	LocalFrame(const VEC3& compressedFrame) ;
75
76
77
78
79
80
81

	/**
	 * Constructor from implicit (compressed representation)
	 * @param secureCompressedFrame an implicit (compressed) version of the local frame
	 */
	LocalFrame(const VEC4& secureCompressedFrame) ;

82
83
84
85
	~LocalFrame() {} ;

	/**
	 * Returns a compressed version of the current local frame
86
	 * A VEC3 is not sufficient to completely define a local frame (if phiN=0, the decompression is not unique).
87
	 */
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
88
	VEC3 getCompressed() const ;
89
90
91
92
93

	/**
	 * Returns a compressed version of the current local frame (fully defined, no ambiguities)
	 */
	VEC4 getCompressedSecure() const ;
94

95
96
97
98
99
100
	/**
	 * Tests if the frames are identical
	 * @param lf the frame to compare to the current frame
	 * @param epsilon the authorized deviation
	 * @return true if frames are identical (or deviate less than epsilon)
	 */
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
101
	bool equals(const LocalFrame<PFP>& lf, REAL epsilon = 1e-3) const ;
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

	/**
	 * Equality of frames
	 * Identical to calling equals with default epsilon
	 * @return true if frames are identical
	 */
	bool operator==(const LocalFrame<PFP>& lf) const ;

	/**
	 * Inequality of frames
	 * Identical to calling !equals with default epsilon
	 * @return false if frames are identical
	 */
	bool operator!=(const LocalFrame<PFP>& lf) const ;

117
118
119
120
	/**
	 * Tests if the frame is direct
	 * @return true if the frame is direct
	 */
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
121
	bool isDirect(REAL epsilon = 1e-5) const ;
122
123
124
125
126

	/**
	 * Tests if the frame is orthogonal
	 * @return true if the frame is orthogonal
	 */
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
127
	bool isOrthogonal(REAL epsilon = 1e-5) const ;
128
129
130
131
132

	/**
	 * Tests if the frame is normalized
	 * @return true if the frame is normalized
	 */
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
133
	bool isNormalized(REAL epsilon = 1e-5) const ;
134
135
136
137
138

	/**
	 * Tests if the frame is direct, normalized and orthogonal
	 * @return true if the frame is direct, normalized and orthogonal
	 */
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
139
	bool isOrthoNormalDirect(REAL epsilon = 1e-5) const ;
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

	/**
	 * @return current tangent vector
	 */
	VEC3& getT() { return m_T ; }
	const VEC3& getT() const { return m_T ; }

	/**
	 * @return current bitangent vector
	 */
	VEC3& getB() { return m_B ; }
	const VEC3& getB() const { return m_B ; }

	/**
	 * @return current normal vector
	 */
	VEC3& getN() { return m_N ; }
	const VEC3& getN() const { return m_N ; }

	friend std::ostream& operator<< (std::ostream &out, const LocalFrame& lf) {
		out << "T : " << lf.m_T << std::endl ;
		out << "B : " << lf.m_B << std::endl ;
		out << "N : " << lf.m_N << std::endl ;
		return out ;
	} ;

private : // methods
	VEC2 carthToSpherical(const VEC3& carth) const ;
	VEC3 sphericalToCarth(const VEC2& sph) const ;
} ;

} // Utils

} // CGoGN

#include "localFrame.hpp"

#endif /* LOCALFRAME_H_ */