Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmv-regression.cc
Go to the documentation of this file.
1 /*
2  * lib-gmapkernel : Un noyau de 3-G-cartes et des opérations.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-gmapkernel
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "g-map-vertex.hh"
26 using namespace GMap3d;
27 //******************************************************************************
29  CVertex * ABarycenter,
30  CVertex * ADirection)
31 {
32  assert(ABarycenter != NULL);
33  assert(ADirection != NULL);
34 
35  int N = 0;
36 
37  // Calcul du barycentre des sommets marqués:
38  CVertex b = barycenter(AMarkNumber);
39 
40  // Calcul de la variance en X et des covariances X/Y et X/Z:
41  TCoordinate vX = 0;
42  TCoordinate vXY = 0;
43  TCoordinate vXZ = 0;
44 
45  int treated = getNewMark();
46 
47  for (CDynamicCoverageAll it(this); it.cont(); ++it)
48  if (!isMarked(*it, treated))
49  {
50  if (isMarked(*it, AMarkNumber))
51  {
52  markOrbit(*it, ORBIT_VERTEX, treated);
53  CVertex & v = * findVertex(*it);
54 
55  ++N;
56  vX += sqr(v.getX() - b.getX());
57 
58  vXY += (v.getX() - b.getX()) * (v.getY() - b.getY());
59  vXZ += (v.getX() - b.getX()) * (v.getZ() - b.getZ());
60  }
61  else
62  setMark(*it, treated);
63  }
64 
65  negateMaskMark(treated);
66  freeMark(treated);
67 
68  if (N > 0)
69  {
70  vX /= N;
71  vXY /= N;
72  vXZ /= N;
73  }
74 
75  /* La droite de régression 3D alpha pour équation paramétrique:
76  *
77  * x = b.getX() + t * vX
78  * y = b.getY() + t * vXY
79  * z = b.getZ() + t * vXZ
80  */
81 
82  * ABarycenter = b;
83  * ADirection = CVertex(vX, vXY, vXZ);
84 }
85 //******************************************************************************
87  TCoordinate * AA, TCoordinate * AB,
88  TCoordinate * AC, TCoordinate * AD)
89 {
90  assert(AA != NULL);
91  assert(AB != NULL);
92  assert(AC != NULL);
93  assert(AD != NULL);
94 
95  int N = 0;
96 
97  // Calcul du barycentre des sommets marqués:
98  CVertex b = barycenter(AMarkNumber);
99 
100  // Calcul des variances en X et en Y et des covariances X/Z et Y/Z:
101  TCoordinate vX = 0;
102  TCoordinate vY = 0;
103  TCoordinate vXY = 0;
104  TCoordinate vXZ = 0;
105  TCoordinate vYZ = 0;
106 
107  int treated = getNewMark();
108 
109  for (CDynamicCoverageAll it(this); it.cont(); ++it)
110  if (!isMarked(*it, treated))
111  {
112  if (isMarked(*it, AMarkNumber))
113  {
114  markOrbit(*it, ORBIT_VERTEX, treated);
115  CVertex & v = * findVertex(*it);
116 
117  ++N;
118  vX += sqr(v.getX() - b.getX());
119  vY += sqr(v.getY() - b.getY());
120 
121  vXY += (v.getX() - b.getX()) * (v.getY() - b.getY());
122  vXZ += (v.getX() - b.getX()) * (v.getZ() - b.getZ());
123  vYZ += (v.getY() - b.getY()) * (v.getZ() - b.getZ());
124  }
125  else
126  setMark(*it, treated);
127  }
128 
129  negateMaskMark(treated);
130  freeMark(treated);
131 
132  if (N > 0)
133  {
134  vX /= N;
135  vY /= N;
136  vXY /= N;
137  vXZ /= N;
138  vYZ /= N;
139  }
140 
141  /* Le plan de régression 3D alpha pour équation cartésienne:
142  *
143  * z = alpha*x + b*y + c
144  *
145  * Avec: alpha * vX + b * vXY = vXZ
146  * alpha * vXY + b * vY = vYZ
147  *
148  *
149  *
150  * alpha = vY*vXZ
151  * b = vX*vYZ
152  * c = - vX*vY
153  * d = - b.getX()*vXZ - b.getY()*vYZ + b.getZ()*vX*vY
154  */
155 
156  for (float i=-1; i<=+1; i += 0.1)
157  for (float j=-1; j<=+1; j += 0.1)
158  {
159  TCoordinate x = b.getX() + i * vX ;
160  TCoordinate y = b.getY() + j * vXY;
161  TCoordinate z = b.getZ() + i * vXZ + j * vYZ;
162 
163  addMapDart(CVertex(x,y,z));
164  }
165 
166  * AA = vY*vXZ;
167  * AB = vX*vYZ;
168  * AC = - vX*vY;
169  * AD = - b.getX()* *AA - b.getY()* *AB - b.getZ()* *AC;
170 }
171 //******************************************************************************