GCC Code Coverage Report


Directory: ./
File: lib/geogram/points/principal_axes.cpp
Date: 2026-09-07 02:36:43
Exec Total Coverage
Lines: 55 63 87.3%
Functions: 4 4 100.0%
Branches: 11 16 68.8%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39 #include <geogram/points/principal_axes.h>
40
41 namespace GEO {
42
43
2/2
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 8 times.
32 PrincipalAxes3d::PrincipalAxes3d() {
44 8 }
45
46 158810 void PrincipalAxes3d::begin() {
47 158810 nb_points_ = 0;
48 158810 sum_weights_ = 0;
49 158810 center_[0] = 0.0;
50 158810 center_[1] = 0.0;
51 158810 center_[2] = 0.0;
52 158810 M_[0] = M_[1] = M_[2] = M_[3] = M_[4] = M_[5] = 0.0;
53 158810 }
54
55 158810 void PrincipalAxes3d::end() {
56 158810 center_[0] /= sum_weights_ ;
57 158810 center_[1] /= sum_weights_ ;
58 158810 center_[2] /= sum_weights_ ;
59
60 // If the system is under-determined,
61 // return the trivial basis.
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 158810 times.
158810 if(nb_points_ < 4) {
63 axis_[0] = vec3(1,0,0) ;
64 axis_[1] = vec3(0,1,0) ;
65 axis_[2] = vec3(0,0,1) ;
66 eigen_value_[0] = 1.0 ;
67 eigen_value_[1] = 1.0 ;
68 eigen_value_[2] = 1.0 ;
69 } else {
70 158810 double x = center_[0] ;
71 158810 double y = center_[1] ;
72 158810 double z = center_[2] ;
73
74 158810 M_[0] = M_[0]/sum_weights_ - x*x ;
75 158810 M_[1] = M_[1]/sum_weights_ - x*y ;
76 158810 M_[2] = M_[2]/sum_weights_ - y*y ;
77 158810 M_[3] = M_[3]/sum_weights_ - x*z ;
78 158810 M_[4] = M_[4]/sum_weights_ - y*z ;
79 158810 M_[5] = M_[5]/sum_weights_ - z*z ;
80
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 158810 times.
158810 if( M_[0] <= 0 ) {
82 M_[0] = 1.e-30 ;
83 }
84
2/2
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 158729 times.
158810 if( M_[2] <= 0 ) {
85 81 M_[2] = 1.e-30 ;
86 }
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 158810 times.
158810 if( M_[5] <= 0 ) {
88 M_[5] = 1.e-30 ;
89 }
90
91 double eigen_vectors[9] ;
92 158810 MatrixUtil::semi_definite_symmetric_eigen(
93
1/2
✓ Branch 1 taken 158810 times.
✗ Branch 2 not taken.
158810 M_, 3, eigen_vectors, eigen_value_
94 ) ;
95
96 158810 axis_[0] = vec3(
97 eigen_vectors[0], eigen_vectors[1], eigen_vectors[2]
98 158810 );
99
100 158810 axis_[1] = vec3(
101 eigen_vectors[3], eigen_vectors[4], eigen_vectors[5]
102 158810 );
103
104 158810 axis_[2] = vec3(
105 eigen_vectors[6], eigen_vectors[7], eigen_vectors[8]
106 158810 );
107
108 // Normalize the eigen vectors
109
110
2/2
✓ Branch 0 taken 476430 times.
✓ Branch 1 taken 158810 times.
635240 for(int i=0; i<3; i++) {
111
1/2
✓ Branch 1 taken 476430 times.
✗ Branch 2 not taken.
476430 axis_[i] = normalize(axis_[i]) ;
112 }
113 }
114 158810 }
115
116 4764300 void PrincipalAxes3d::add_point(const vec3& p, double weight) {
117 4764300 center_[0] += p.x * weight ;
118 4764300 center_[1] += p.y * weight ;
119 4764300 center_[2] += p.z * weight ;
120
121 4764300 double x = p.x ;
122 4764300 double y = p.y ;
123 4764300 double z = p.z ;
124
125 4764300 M_[0] += weight * x*x ;
126 4764300 M_[1] += weight * x*y ;
127 4764300 M_[2] += weight * y*y ;
128 4764300 M_[3] += weight * x*z ;
129 4764300 M_[4] += weight * y*z ;
130 4764300 M_[5] += weight * z*z ;
131
132 4764300 nb_points_++ ;
133 4764300 sum_weights_ += weight ;
134 4764300 }
135
136
137 }
138