Developer Documentation

PrincipalAxisNodeT_impl.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2016, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 //=============================================================================
44 //
45 // CLASS PrincipalAxisNode - IMPLEMENTATION
46 //
47 //=============================================================================
48
49 #define ACG_PRINCIPAL_AXIS_NODE_C
50
51 //== INCLUDES =================================================================
52
53 #include "PrincipalAxisNode.hh"
54 #include <ACG/GL/gl.hh>
55
56
57 //== NAMESPACES ===============================================================
58
59 namespace ACG {
60 namespace SceneGraph {
61
62
63 //== IMPLEMENTATION ==========================================================
64
65
66 template<class VectorT>
67 void
68 PrincipalAxisNode::
69 set_vector( unsigned int _i, const Vec3d _p, const VectorT& _v)
70 {
71 Matrix4x4T<double> m;
72
73 m(0,0) = _v[0];
74 m(1,1) = _v[1];
75 m(2,2) = _v[2];
76 m(0,1) = m(1,0) = _v[3];
77 m(1,2) = m(2,1) = _v[4];
78 m(0,2) = m(2,0) = _v[5];
79
80 set_matrix(_i, _p, m);
81 }
82
83
84 //----------------------------------------------------------------------------
85
86
87 template<class MatrixT>
88 void
89 PrincipalAxisNode::
90 set_matrix( unsigned int _i, const Vec3d _p, const MatrixT& _m)
91 {
92 // create matrix
93 double s[3][3];
94
95 // copy values
96 for(unsigned int i=0; i<3; ++i)
97 for(unsigned int j=0; j<3; ++j)
98 s[i][j] = _m(i,j);
99
100 // compute eigenvalues and eigenvectors
101 double Q[3][3];
102 double D[3][3];
103
104 diagonalize(s, Q, D);
105
106 std::vector<double> eigval;
107 for (int i = 0; i < 3; ++i)
108 eigval.push_back(D[i][i]);
109
110
111 unsigned int pstress_idx[3];
112 if( fabs(eigval[0]) >= fabs(eigval[1]) && fabs(eigval[0]) >= fabs(eigval[2])) pstress_idx[0] = 0;
113 if( fabs(eigval[1]) >= fabs(eigval[0]) && fabs(eigval[1]) >= fabs(eigval[2])) pstress_idx[0] = 1;
114 if( fabs(eigval[2]) >= fabs(eigval[0]) && fabs(eigval[2]) >= fabs(eigval[1])) pstress_idx[0] = 2;
115
116 unsigned int i0 = (pstress_idx[0] + 1)%3;
117 unsigned int i1 = (pstress_idx[0] + 2)%3;
118 if( fabs(eigval[i0]) > fabs(eigval[i1]) )
119 {
120 pstress_idx[1] = i0;
121 pstress_idx[2] = i1;
122 }
123 else
124 {
125 pstress_idx[1] = i1;
126 pstress_idx[2] = i0;
127 }
128
129 Vec3d a[3];
130 bool sign[3];
131
132 for(unsigned int j=0; j<3; ++j)
133 {
134 // set sign
135 if( eigval[ pstress_idx[j]] < 0 )
136 sign[j] = false;
137 else
138 sign[j] = true;
139
140 for(unsigned int k=0; k<3; ++k)
141 a[j][k] = eigval[ pstress_idx[j]]*Q[k][pstress_idx[j]];
142 }
143
144 set(_i,
145 PrincipalComponent(_p,
146 a[0],
147 a[1],
148 a[2],
149 sign[0],
150 sign[1],
151 sign[2] ) );
152
153 }
154
155
156 //----------------------------------------------------------------------------
157
158
159 //=============================================================================
160 } // namespace SceneGraph
161 } // namespace ACG
162 //=============================================================================
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
VectorT
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121