DGtal 1.4.0
Loading...
Searching...
No Matches
NormalCycleComputer.ih
1/**
2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 **/
16
17/**
18 * @file NormalCycleComputer.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
21 *
22 * @date 2020/02/18
23 *
24 * Implementation of inline methods defined in NormalCycleComputer.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
40
41//-----------------------------------------------------------------------------
42template <typename TRealPoint, typename TRealVector>
43DGtal::NormalCycleComputer<TRealPoint, TRealVector>::
44NormalCycleComputer( ConstAlias< SurfaceMesh > aMesh )
45 : myMesh( aMesh )
46{}
47
48
49//-----------------------------------------------------------------------------
50template <typename TRealPoint, typename TRealVector>
51typename DGtal::NormalCycleComputer<TRealPoint, TRealVector>::ScalarMeasure
52DGtal::NormalCycleComputer<TRealPoint, TRealVector>::
53computeMu0() const
54{
55 ScalarMeasure mu0( &myMesh, 0.0 );
56 auto& face_mu0 = mu0.kMeasures( 2 );
57 face_mu0.resize( myMesh.nbFaces() );
58 Index idx_f = 0;
59 for ( const auto& f : myMesh.allIncidentVertices() )
60 {
61 RealPoints p( f.size() );
62 for ( Index idx_v = 0; idx_v < f.size(); ++idx_v )
63 p[ idx_v ] = myMesh.positions() [ f[ idx_v ] ];
64 face_mu0[ idx_f++ ] = Formula::area( p );
65 }
66 return mu0;
67}
68
69//-----------------------------------------------------------------------------
70template <typename TRealPoint, typename TRealVector>
71typename DGtal::NormalCycleComputer<TRealPoint, TRealVector>::ScalarMeasure
72DGtal::NormalCycleComputer<TRealPoint, TRealVector>::
73computeMu1() const
74{
75 ScalarMeasure mu1( &myMesh, 0.0 );
76 auto& edge_mu1 = mu1.kMeasures( 1 );
77 edge_mu1.resize( myMesh.nbEdges() );
78 Index idx_e = 0;
79 for ( const auto& e : myMesh.allEdgeVertices() )
80 {
81 const auto & right_faces = myMesh.allEdgeRightFaces()[ idx_e ];
82 const auto & left_faces = myMesh.allEdgeLeftFaces ()[ idx_e ];
83 if ( right_faces.size() != 1 || left_faces.size() != 1 )
84 {
85 edge_mu1[ idx_e ] = 0.0;
86 }
87 else
88 {
89 const RealPoint a = myMesh.positions()[ e.first ];
90 const RealPoint b = myMesh.positions()[ e.second ];
91 const RealPoint right = myMesh.faceCentroid( right_faces[ 0 ] );
92 const RealPoint left = myMesh.faceCentroid( left_faces [ 0 ] );
93 const RealVector right_n = Formula::normal( a, right, b );
94 const RealVector left_n = Formula::normal( a, b, left );
95 edge_mu1[ idx_e ] = Formula::twiceMeanCurvature( a, b, right_n, left_n );
96 }
97 idx_e++;
98 }
99 return mu1;
100}
101
102//-----------------------------------------------------------------------------
103template <typename TRealPoint, typename TRealVector>
104typename DGtal::NormalCycleComputer<TRealPoint, TRealVector>::ScalarMeasure
105DGtal::NormalCycleComputer<TRealPoint, TRealVector>::
106computeMu2() const
107{
108 ScalarMeasure mu2( &myMesh, 0.0 );
109 auto& vertex_mu2 = mu2.kMeasures( 0 );
110 vertex_mu2.resize( myMesh.nbVertices() );
111 Index idx_v = 0;
112 for ( const auto& faces_v : myMesh.allIncidentFaces() )
113 {
114 const RealPoint a = myMesh.positions()[ idx_v ];
115 RealPoints pairs;
116 for ( auto f : faces_v )
117 {
118 const auto & vtcs = myMesh.allIncidentVertices()[ f ];
119 Index j = std::find( vtcs.cbegin(), vtcs.cend(), idx_v ) - vtcs.cbegin();
120 if ( j != vtcs.size() )
121 {
122 const Index prev = ( j + vtcs.size() - 1 ) % vtcs.size();
123 const Index next = ( j + vtcs.size() + 1 ) % vtcs.size();
124 pairs.push_back( myMesh.positions()[ vtcs[ next ] ] );
125 pairs.push_back( myMesh.positions()[ vtcs[ prev ] ] );
126 }
127 }
128 vertex_mu2[ idx_v++ ] = Formula::gaussianCurvatureWithPairs( a, pairs );
129 }
130 return mu2;
131}
132
133//-----------------------------------------------------------------------------
134template <typename TRealPoint, typename TRealVector>
135typename DGtal::NormalCycleComputer<TRealPoint, TRealVector>::TensorMeasure
136DGtal::NormalCycleComputer<TRealPoint, TRealVector>::
137computeMuXY() const
138{
139 const RealTensor zeroT { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
140 TensorMeasure muXY( &myMesh, zeroT );
141 auto& edge_muXY = muXY.kMeasures( 1 );
142 edge_muXY.resize( myMesh.nbEdges() );
143 Index idx_e = 0;
144 for ( auto e : myMesh.allEdgeVertices() )
145 {
146 const auto & right_faces = myMesh.allEdgeRightFaces()[ idx_e ];
147 const auto & left_faces = myMesh.allEdgeLeftFaces ()[ idx_e ];
148 if ( right_faces.size() != 1 || left_faces.size() != 1 )
149 edge_muXY[ idx_e ] = zeroT;
150 else
151 {
152 const RealPoint a = myMesh.positions()[ e.first ];
153 const RealPoint b = myMesh.positions()[ e.second ];
154 const RealPoint right = myMesh.faceCentroid( right_faces[ 0 ] );
155 const RealPoint left = myMesh.faceCentroid( left_faces [ 0 ] );
156 const RealVector right_n = Formula::normal( a, right, b );
157 const RealVector left_n = Formula::normal( a, b, left );
158 edge_muXY[ idx_e ] =
159 Formula::anisotropicCurvatureH1( a, b, right_n, left_n );
160 }
161 idx_e++;
162 }
163 return muXY;
164}
165
166//-----------------------------------------------------------------------------
167template <typename TRealPoint, typename TRealVector>
168typename DGtal::NormalCycleComputer<TRealPoint, TRealVector>::TensorMeasure
169DGtal::NormalCycleComputer<TRealPoint, TRealVector>::
170computeMuXYs() const
171{
172 const RealTensor zeroT { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
173 TensorMeasure muXYs( &myMesh, zeroT );
174 auto& edge_muXYs = muXYs.kMeasures( 1 );
175 edge_muXYs.resize( myMesh.nbEdges() );
176 Index idx_e = 0;
177 for ( auto e : myMesh.allEdgeVertices() )
178 {
179 const auto & right_faces = myMesh.allEdgeRightFaces()[ idx_e ];
180 const auto & left_faces = myMesh.allEdgeLeftFaces ()[ idx_e ];
181 if ( right_faces.size() != 1 || left_faces.size() != 1 )
182 edge_muXYs[ idx_e ] = zeroT;
183 else
184 {
185 const RealPoint a = myMesh.positions()[ e.first ];
186 const RealPoint b = myMesh.positions()[ e.second ];
187 const RealPoint right = myMesh.faceCentroid( right_faces[ 0 ] );
188 const RealPoint left = myMesh.faceCentroid( left_faces [ 0 ] );
189 const RealVector right_n = Formula::normal( a, right, b );
190 const RealVector left_n = Formula::normal( a, b, left );
191 edge_muXYs[ idx_e ] =
192 Formula::anisotropicCurvatureH2( a, b, right_n, left_n );
193 }
194 idx_e++;
195 }
196 return muXYs;
197}
198
199
200///////////////////////////////////////////////////////////////////////////////
201///////////////////////////////////////////////////////////////////////////////