Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmv-plating.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 //******************************************************************************
28 bool CGMapVertex::canPlate(CDart * ADart1, CDart * ADart2)
29 {
30  assert(ADart1!=NULL && ADart2!=NULL);
31  return !isSameOrbit(ADart1,ADart2, ORBIT_CC);
32 }
33 //******************************************************************************
35 {
36  assert(ADart1!=NULL && ADart2!=NULL);
37 
38  if (!canPlate(ADart1,ADart2))
39  return -1;
40 
41  if (isFree1(ADart1) && isFree1(ADart2)) return 0;
42  if (isFree2(ADart1) && isFree2(ADart2)) return 1;
43  if (isFree3(ADart1) && isFree3(ADart2)) return 2;
44 
45  return -1;
46 }
47 //******************************************************************************
48 void CGMapVertex::plate(CDart * ADart1, CDart * ADart2, int ADim,
49  bool ARotateCells,
50  bool AScaleCells,
51  bool ATranslateCells)
52 {
53  assert(ADart1!=NULL && ADart2!=NULL);
54  assert(ADim>=0 && ADim<3);
55  assert(canPlate(ADart1,ADart2));
56 
57  CVertex origin1, origin2;
58  CVertex U1,V1, U2,V2;
59  TCoordinate kHomothety;
60 
61  // Calcul des origines:
62  origin1= barycenter(ADart1, ORBIT_INF[ADim]);
63 
64  if (ATranslateCells)
65  origin2= barycenter(ADart2, ORBIT_INF[ADim]);
66  else
67  origin2= origin1;
68 
69  // Calcul des vecteurs de chaque repère:
70  if (ADim==0 || !ARotateCells)
71  {
72  U1= U2= OZ;
73  V1= V2= OX;
74  }
75  else
76  {
77  U1= faceNormalVector(ADart1); if (U1.isNull()) U1= OZ;
78  U2= faceNormalVector(ADart2); if (U2.isNull()) U2= OZ;
79 
80  V1= barycenter(ADart1, ORBIT_EDGE) - barycenter(ADart1, ORBIT_FACE);
81  if (V1.isNull()) V1= OX;
82  V2= barycenter(ADart2, ORBIT_EDGE) - barycenter(ADart2, ORBIT_FACE);
83  if (V2.isNull()) V2= OX;
84 
85  if ((U1*V1).isNull() || (U2*V2).isNull())
86  { U1= U2= OZ; V1= V2= OX; }
87  else
88  if (ADim==1)
89  { U2= -U2; V2= -V2; }
90  }
91 
92  // Calcul du coefficient d'homothétie:
93  if (ADim==0 || !AScaleCells)
94  kHomothety = 1;
95  else
96  {
97  TCoordinate length1=
98  ADim==1 ? edgeLength(ADart1) : facePerimeter(ADart1);
99 
100  TCoordinate length2=
101  ADim==1 ? edgeLength(ADart2) : facePerimeter(ADart2);
102 
103  kHomothety = isZero(length1) ? 1 : length2/length1;
104  }
105 
106  {
107  // Initialisation de la matrice de placage:
109 
110  platingMatrix.transform(origin1, U1, V1,
111  origin2, U2, V2,
112  CVertex(kHomothety, kHomothety, kHomothety));
113 
114  // Application de la transformation globale sur l'objet:
115  applyMatrix(platingMatrix, ADart1,ORBIT_CC);
116  }
117 }
118 //******************************************************************************
119 bool CGMapVertex::intuitivePlate(CDart * ADart1, CDart * ADart2,
120  bool ARotateCells, bool AScaleCells,
121  bool ATranslateCells)
122 {
123  assert(ADart1!=NULL && ADart2!=NULL);
124 
125  int dim= getPlateDimension(ADart1,ADart2);
126 
127  if (dim>0)
128  plate(ADart1,ADart2, dim, ARotateCells, AScaleCells, ATranslateCells);
129 
130  return dim>0;
131 }
132 //******************************************************************************
133 void CGMapVertex::borderPlate(CDart * ADart1, CDart * ADart2, int ADim,
134  bool ARotateCells, bool AScaleCells,
135  bool ATranslateCells)
136 {
137  assert(ADart1!=NULL && ADart2!=NULL);
138  assert(ADim>=0 && ADim<3);
139 
140  assert(canPlate(ADart1,ADart2));
141 
142  CVertex origin1, origin2;
143  CVertex U1,V1, U2,V2;
144  TCoordinate kHomothety;
145 
146  // Calcul des origines:
147  origin1= barycenter(ADart1, ORBIT_BORDER[ADim]);
148 
149  if (ATranslateCells)
150  origin2= barycenter(ADart2, ORBIT_BORDER[ADim]);
151  else
152  origin2= origin1;
153 
154  // Calcul des vecteurs de chaque repère:
155  if (ADim==0 || !ARotateCells)
156  {
157  U1= U2= OZ;
158  V1= V2= OX;
159  }
160  else
161  {
162  if (ADim==1)
163  {
164  U1= faceNormalVector(ADart1);
165  U2= faceNormalVector(ADart2);
166  V1= barycenter(ADart1, ORBIT_BORDER_1)
167  - barycenter(ADart1, ORBIT_FACE);
168  V2= barycenter(ADart2, ORBIT_BORDER_1)
169  - barycenter(ADart2, ORBIT_FACE);
170  }
171  else
172  {
173  U1= border2NormalVector(ADart1);
174  U2= border2NormalVector(ADart2);
175  V1= barycenter(ADart1, ORBIT_EDGE)
176  - barycenter(ADart1, ORBIT_BORDER[ADim]);
177  V2= barycenter(ADart2, ORBIT_EDGE)
178  - barycenter(ADart2, ORBIT_BORDER[ADim]);
179  }
180 
181  if (U1.isNull()) U1= OZ;
182  if (U2.isNull()) U2= OZ;
183 
184  if (V1.isNull()) V1= OX;
185  if (V2.isNull()) V2= OX;
186 
187  if ((U1*V1).isNull() || (U2*V2).isNull())
188  { U1= U2= OZ; V1= V2= OX; }
189  else
190  if (ADim==1)
191  { U2= -U2; V2= -V2; }
192  }
193 
194  // Calcul du coefficient d'homothétie:
195  if (ADim==0 || !AScaleCells)
196  kHomothety = 1;
197  else
198  {
199  TCoordinate length1= orbitLength(ADart1, ORBIT_BORDER[ADim]);
200  TCoordinate length2= orbitLength(ADart2, ORBIT_BORDER[ADim]);
201 
202  kHomothety = isZero(length1) ? 1 : length2/length1;
203  }
204 
205  {
206  // Initialisation de la matrice de placage:
208 
209  platingMatrix.transform(origin1, U1, V1,
210  origin2, U2, V2,
211  CVertex(kHomothety, kHomothety, kHomothety));
212 
213  // Application de la transformation globale sur l'objet:
214  applyMatrix(platingMatrix, ADart1,ORBIT_CC);
215  }
216 }
217 //******************************************************************************