Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmg-primitive.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-generic.hh"
26 using namespace GMap3d;
27 //******************************************************************************
29 {
30  CDart * dart[6];
31 
32  for (int i=0; i<6; ++i)
33  dart[i] = addMapDart();
34 
35  linkAlpha0(dart[0], dart[1]); linkAlpha1(dart[1], dart[2]);
36  linkAlpha0(dart[2], dart[3]); linkAlpha1(dart[3], dart[4]);
37  linkAlpha0(dart[4], dart[5]); linkAlpha1(dart[5], dart[0]);
38 
39  return dart[0];
40 }
41 //******************************************************************************
43 {
44  CDart * dart[8];
45 
46  for (int i=0; i<8; ++i)
47  dart[i] = addMapDart();
48 
49  linkAlpha0(dart[0], dart[1]); linkAlpha1(dart[1], dart[2]);
50  linkAlpha0(dart[2], dart[3]); linkAlpha1(dart[3], dart[4]);
51  linkAlpha0(dart[4], dart[5]); linkAlpha1(dart[5], dart[6]);
52  linkAlpha0(dart[6], dart[7]); linkAlpha1(dart[7], dart[0]);
53 
54  return dart[0];
55 }
56 //******************************************************************************
58 {
59  assert(An>0);
60 
61  CDart * dart0, * current = NULL, * current0, * current01;
62 
63  linkAlpha0(dart0 = addMapDart(), current01 = addMapDart());
64 
65  for (int i=1; i<An; ++i)
66  {
67  current = addMapDart();
68  current0 = addMapDart();
69 
70  linkAlpha0(current , current0 );
71  linkAlpha1(current0, current01);
72 
73  current01 = current;
74  }
75 
76  linkAlpha1(current, dart0);
77 
78  return dart0;
79 }
80 //******************************************************************************
82 {
83  assert(An>0);
84 
85  CDart * dart0, * current = NULL, * current21;
86 
87  dart0 = current21 = createTopoTriangle();
88 
89  for (int i=1; i<An; ++i)
90  {
91  current = createTopoTriangle();
92  topoSew2(current, alpha1(current21));
93  current21 = current;
94  }
95 
96  /* On n'effectue pas la dernière couture, comme c'est fait dans la méthode
97  createTopoPole qui suit... */
98 
99  return dart0;
100 }
101 //******************************************************************************
103 {
104  assert(An>0);
105 
106  CDart * dart0, * current=NULL, * current21;
107 
108  dart0 = current21 = createTopoTriangle();
109 
110  for (int i=1; i<An; ++i)
111  {
112  current = createTopoTriangle();
113  topoSew2(current, alpha1(current21));
114  current21 = current;
115  }
116 
117  topoSew2(alpha1(current), dart0);
118 
119  return dart0;
120 }
121 //******************************************************************************
122 void CGMapGeneric::createTopoTube(int AMeridians, int AParallels,
123  CDart * * ABorder1, CDart * * ABorder2)
124 {
125  assert(AMeridians>0);
126  assert(AParallels>0);
127 
128  CDart * mesh2Corners[2][2];
129 
130  createTopoMesh2(AMeridians,AParallels, mesh2Corners);
131  border2TopoSew(alpha1(mesh2Corners[0][0]), alpha1(mesh2Corners[1][0]), AParallels);
132 
133  if (ABorder1!=NULL) * ABorder1 = mesh2Corners[0][0];
134  if (ABorder2!=NULL) * ABorder2 = mesh2Corners[0][1];
135 }
136 //******************************************************************************
137 CDart * CGMapGeneric::createTopoTube(int AMeridians, int AParallels)
138 {
139  assert(AMeridians>0);
140  assert(AParallels>0);
141 
142  CDart * border1;
143 
144  createTopoTube(AMeridians,AParallels, &border1,NULL);
145 
146  return border1;
147 }
148 //******************************************************************************
149 void CGMapGeneric::createTopoSphere(int AMeridians, int AParallels,
150  CDart * * ASouthPole, CDart * * ANorthPole)
151 {
152  assert(AMeridians>0);
153  assert(AParallels>0);
154 
155  CDart * southPole = createTopoPole(AMeridians);
156  CDart * northPole = createTopoPole(AMeridians);
157 
158  if (AParallels==1)
159  border2TopoSew(alpha01(southPole), alpha01(northPole), AMeridians);
160  else
161  {
162  CDart * top, * bottom;
163 
164  createTopoTube(AMeridians,AParallels-1, &bottom, &top);
165 
166  border2TopoSew(alpha01(southPole), bottom, AMeridians);
167  border2TopoSew(alpha01(northPole), top , AMeridians);
168  }
169 
170  if (ASouthPole!=NULL) * ASouthPole = southPole;
171  if (ANorthPole!=NULL) * ANorthPole = northPole;
172 }
173 //******************************************************************************
174 CDart * CGMapGeneric::createTopoSphere(int AMeridians, int AParallels)
175 {
176  assert(AMeridians>0);
177  assert(AParallels>0);
178 
179  CDart * southPole;
180 
181  createTopoSphere(AMeridians,AParallels, &southPole,NULL);
182 
183  return southPole;
184 }
185 //******************************************************************************
186 void CGMapGeneric::createTopoCylinder(int AMeridians, int AParallels,
187  CDart * * ABorder1, CDart * * ABorder2,
188  bool AClose1, bool AClose2)
189 {
190  assert(AMeridians>0);
191  assert(AParallels>0);
192 
193  CDart * border1;
194  CDart * border2;
195 
196  createTopoTube(AMeridians,AParallels, &border1,&border2);
197 
198  if (AClose1)
199  border2TopoSew(border1, createTopoPolygon(AMeridians), AMeridians);
200 
201  if (AClose2)
202  border2TopoSew(border2, createTopoPolygon(AMeridians), AMeridians);
203 
204  if (ABorder1!=NULL) * ABorder1 = border1;
205  if (ABorder2!=NULL) * ABorder2 = border2;
206 }
207 //******************************************************************************
208 CDart * CGMapGeneric::createTopoCylinder(int AMeridians, int AParallels,
209  bool AClose1, bool AClose2)
210 {
211  assert(AMeridians>0);
212  assert(AParallels>0);
213 
214  CDart * border1;
215 
216  createTopoCylinder(AMeridians,AParallels, &border1,NULL, AClose1,AClose2);
217 
218  return border1;
219 }
220 //******************************************************************************
221 void CGMapGeneric::createTopoPyramid(int AMeridians, int AParallels,
222  CDart * * ABaseDart, CDart * * APoleDart,
223  bool ACloseBase)
224 {
225  assert(AMeridians>0);
226  assert(AParallels>0);
227 
228  CDart * pole = createTopoPole(AMeridians);
229  CDart * base;
230 
231  if (AParallels==1)
232  base = alpha01(pole);
233  else
234  {
235  CDart * top;
236 
237  createTopoTube(AMeridians, AParallels-1, &base,&top);
238  border2TopoSew(top, alpha01(pole), AMeridians);
239  }
240 
241  if (ACloseBase)
242  border2TopoSew(base, createTopoPolygon(AMeridians), AMeridians);
243 
244  if (ABaseDart!=NULL) * ABaseDart = base;
245  if (APoleDart!=NULL) * APoleDart = pole;
246 }
247 //******************************************************************************
248 CDart * CGMapGeneric::createTopoPyramid(int AMeridians, int AParallels,
249  bool ACloseBase)
250 {
251  assert(AMeridians>0);
252  assert(AParallels>0);
253 
254  CDart * baseDart;
255 
256  createTopoPyramid(AMeridians,AParallels, &baseDart,NULL, ACloseBase);
257 
258  return baseDart;
259 }
260 //******************************************************************************
261 void CGMapGeneric::createTopoTorus(int AMeridians, int AParallels,
262  CDart * * AEquator)
263 {
264  assert(AMeridians>0);
265  assert(AParallels>0);
266 
267  CDart * border1;
268  CDart * border2;
269 
270  // Attention: Les méridiens d'un tore correspondent aux parallèles du tube à
271  // partie duquel on le construit.
272 
273  createTopoTube(AParallels, AMeridians, &border1, &border2);
274  border2TopoSew(border1, border2, AParallels);
275 
276  if (AEquator!=NULL) * AEquator = alpha1(border1);
277 }
278 //******************************************************************************
279 CDart * CGMapGeneric::createTopoTorus(int AMeridians, int AParallels)
280 {
281  assert(AMeridians>0);
282  assert(AParallels>0);
283 
284  CDart * equator;
285 
286  createTopoTorus(AMeridians,AParallels, &equator);
287 
288  return equator;
289 }
290 //******************************************************************************
292  int AMeshDimension,
293  CDart * ASquareCorners[2][2])
294 {
295  assert(ASx>0);
296  assert(ASy>0);
297  assert(AMeshDimension>=0 && AMeshDimension<=2);
298 
299  if (AMeshDimension==0)
300  ASx = ASy = 1;
301 
302  if (AMeshDimension==2)
303  createTopoMesh2(ASx, ASy, ASquareCorners);
304  else
305  {
306  CDart * corners[2];
307 
308  createTopoMesh1(ASx, corners);
309  ASquareCorners[0][0] = corners[0];
310  ASquareCorners[1][0] = corners[1];
311 
312  createTopoMesh1(ASx, corners);
313  ASquareCorners[0][1] = corners[0];
314  ASquareCorners[1][1] = corners[1];
315 
316  createTopoMesh1(ASy, corners);
317  linkAlpha1(corners[0], ASquareCorners[0][0]);
318  linkAlpha1(corners[1], ASquareCorners[0][1]);
319 
320  createTopoMesh1(ASy, corners);
321  linkAlpha1(corners[0], ASquareCorners[1][0]);
322  linkAlpha1(corners[1], ASquareCorners[1][1]);
323  }
324 }
325 //******************************************************************************
326 void CGMapGeneric::createTopoCubeIMeshed(int ASx, int ASy, int ASz,
327  int AMeshDimension,
328  bool ACreatedFaces[3][2],
329  CDart * AFacesCorners[3][2][2][2])
330 {
331  assert(ASx>0);
332  assert(ASy>0);
333  assert(ASz>0);
334  assert(AMeshDimension>=0 && AMeshDimension<=2);
335  assert(ACreatedFaces!=NULL);
336  assert(AFacesCorners!=NULL);
337 
338  if (AMeshDimension==0)
339  ASx = ASy = ASz = 1;
340 
341  int dim, dim1, dim2;
342  int s[3] = {ASx, ASy, ASz};
343 
344  // Créations:
345  for (dim=0; dim<3; ++dim)
346  {
347  dim1 = (dim+1) % 3;
348  dim2 = (dim+2) % 3;
349 
350  for (int side=0; side<2; ++side)
351  if (ACreatedFaces[dim][side])
352  createTopoSquareIMeshed(s[dim1], s[dim2],
353  AMeshDimension, AFacesCorners[dim][side]);
354  else
355  for (int n=0; n<4; ++n)
356  AFacesCorners[dim][side][n/2][n%2] = NULL;
357  }
358 
359  // Coutures:
360  for (dim=0; dim<3; ++dim)
361  {
362  dim1 = (dim+1) % 3;
363  dim2 = (dim+2) % 3;
364 
365  for (int dim1Side=0; dim1Side<2; ++dim1Side)
366  for (int dim2Side=0; dim2Side<2; ++dim2Side)
367  if (ACreatedFaces[dim1][dim1Side] && ACreatedFaces[dim2][dim2Side])
368  {
369  CDart * dartA = AFacesCorners[dim1][dim1Side][dim2Side][0];
370  CDart * dartB = AFacesCorners[dim2][dim2Side][0][dim1Side];
371 
372  border2TopoSew(alpha1(dartA), dartB, s[dim]);
373  }
374  }
375 }
376 //******************************************************************************