Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mg-mesh.cc
Go to the documentation of this file.
1 /*
2  * lib-mesh : Opérations de maillage et lissage.
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-mesh
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 "mesh-generic.hh"
26 #include "g-map-generic.hh"
27 #include <cassert>
28 using namespace GMap3d;
29 //******************************************************************************
30 bool CMeshGeneric::canMesh1(CDart* ADart)
31 {
32  assert(ADart != NULL);
33  return isTopoEdge(ADart);
34 }
35 //------------------------------------------------------------------------------
36 void CMeshGeneric::mesh1(CDart* ADart, int ASx,
37  const CTransformationMatrix* /*AMeshMatrix*/,
38  bool AMeshWithMerges,
39  bool AMeshWithAdjacentSews,
40  bool AMeshAssociatedCells,
41  int /*ADirectInfoAlpha0*/, int ADirectInfoAssoc)
42 {
43  assert(ADart!=NULL);
44  assert(canMesh1(ADart));
45  assert(ASx>0);
46 
47  CDart* extremities[2];
48 
49  if (AMeshWithMerges)
50  {
51  FMap->createTopoMesh1(ASx, extremities, ADart);
52  mergeEdgeAndMesh1(ADart, extremities);
53  }
54  else
55  {
56  assert(ADirectInfoAssoc >= 0);
57 
58  if (AMeshWithAdjacentSews)
59  {
60  CDart* assoc = FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc);
61  FMap->createTopoMesh1(ASx, extremities, assoc);
62  mergeEdgeAndMesh1(assoc, extremities);
63  }
64  else
65  {
66  if (AMeshAssociatedCells)
67  {
68  CDart* assoc = FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc);
69 
70  FMap->createTopoMesh1(ASx, extremities, assoc);
71  mergeEdgeAndMesh1(assoc, extremities);
72  }
73  else
74  {
75  FMap->createTopoMesh1(ASx, extremities, NULL);
76  FMap->setDirectInfo( ADart , ADirectInfoAssoc, extremities[0]);
77  FMap->setDirectInfo(FMap->alpha0(ADart), ADirectInfoAssoc, extremities[1]);
78  }
79  }
80  }
81 }
82 //******************************************************************************
83 bool CMeshGeneric::canMesh2(CDart* ADart,
84  int ASx, int ASy, int AInitialMeshDim)
85 {
86  assert(ADart!=NULL);
87  assert(ASx>0);
88  assert(ASy>0);
89  assert(0<=AInitialMeshDim && AInitialMeshDim<=1);
90 
91  return isTopoSquareIMeshed(AInitialMeshDim, ADart, ASx,ASy,
92  true, ! FMap->isFree3(ADart));
93 }
94 //------------------------------------------------------------------------------
95 void CMeshGeneric::mesh2(CDart* ADart,
96  int ASx, int ASy,
97  const CTransformationMatrix * AMeshMatrix,
98  bool AMeshWithMerges,
99  bool AMeshWithAdjacentSews,
100  bool AMeshAssociatedCells,
101  bool /*AGetAssociatedEmbeddings*/,
102  int AInitialMeshDim, int AFinalMeshDim,
103  int ADirectInfoAlpha0, int ADirectInfoAssoc)
104 {
105  assert(ADart!=NULL);
106  assert(ASx>0);
107  assert(ASy>0);
108  assert(0<=AInitialMeshDim && AInitialMeshDim<=1);
109  assert(1<=AFinalMeshDim && AFinalMeshDim <=2);
110  assert(AInitialMeshDim < AFinalMeshDim);
111 
112  assert(canMesh2(AMeshAssociatedCells
113  ? FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc) : ADart,
114  ASx,ASy, AInitialMeshDim));
115 
116  bool isolated = !AMeshWithMerges && !AMeshWithAdjacentSews;
117 
118  // 1-maillage:
119  if (AInitialMeshDim==0 && (AFinalMeshDim==1 || !isolated))
120  {
121  CDart* dart1 = ADart;
122  CDart* dart2 = FMap->alpha0101(ADart);
123 
124  mesh1( dart1, ASx, AMeshMatrix, AMeshWithMerges, AMeshWithAdjacentSews,
125  AMeshAssociatedCells, ADirectInfoAlpha0, ADirectInfoAssoc);
126  mesh1( FMap->alpha1(dart1), ASy, AMeshMatrix, AMeshWithMerges, AMeshWithAdjacentSews,
127  AMeshAssociatedCells, ADirectInfoAlpha0, ADirectInfoAssoc);
128  mesh1( dart2, ASx, AMeshMatrix, AMeshWithMerges, AMeshWithAdjacentSews,
129  AMeshAssociatedCells, ADirectInfoAlpha0, ADirectInfoAssoc);
130  mesh1( FMap->alpha1(dart2), ASy, AMeshMatrix, AMeshWithMerges, AMeshWithAdjacentSews,
131  AMeshAssociatedCells, ADirectInfoAlpha0, ADirectInfoAssoc);
132  }
133 
134  // 2-maillage:
135  if (AFinalMeshDim==2)
136  {
137  CDart* first =
138  AMeshAssociatedCells
139  ? FMap->getDirectInfoAsDart(ADart, ADirectInfoAssoc)
140  : ADart;
141 
142  CDart* mesh = FMap->createTopoMesh2(ASx, ASy, !isolated &&
143  ! FMap->isFree3(first));
144 
145  mergeSquare1MeshedAndMesh2(first, mesh, ASx, ASy);
146  }
147 }
148 //******************************************************************************
149 bool CMeshGeneric::canMesh3(CDart* ADart,
150  int ASx, int ASy, int ASz, int AInitialMeshDim)
151 {
152  assert(ADart!=NULL);
153  assert(ASx>0);
154  assert(ASy>0);
155  assert(ASz>0);
156  assert(0<=AInitialMeshDim && AInitialMeshDim<=2);
157 
158  return isTopoCubeIMeshed(AInitialMeshDim, ADart, ASx,ASy,ASz);
159 }
160 //------------------------------------------------------------------------------
161 void CMeshGeneric::mesh3(CDart* ADart,
162  int ASx, int ASy, int ASz,
163  const CTransformationMatrix * AMeshMatrix,
164  bool AMeshWithMerges,
165  bool AMeshWithAdjacentSews,
166  bool AMeshAssociatedCells,
167  int AInitialMeshDim, int AFinalMeshDim,
168  int /*ADirectInfoAlpha0*/, int ADirectInfoAssoc)
169 {
170  assert(ADart!=NULL);
171  assert(ASx>0);
172  assert(ASy>0);
173  assert(ASz>0);
174  assert(0<=AInitialMeshDim && AInitialMeshDim<=2);
175  assert(1<=AFinalMeshDim && AFinalMeshDim <=3);
176  assert(AInitialMeshDim < AFinalMeshDim);
177  assert(canMesh3(ADart, ASx,ASy,ASz, AInitialMeshDim));
178 
179  // 1-maillage:
180  if (AInitialMeshDim==0)
181  {
182  CDart* dart1 = ADart;
183  CDart* dart2 = FMap->alpha21012(FMap->alpha0101(ADart));
184 
185  mesh1( FMap->alpha21 (dart1), ASz, AMeshMatrix, AMeshWithMerges,
186  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
187  mesh1( FMap->alpha21 (dart2), ASz, AMeshMatrix, AMeshWithMerges,
188  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
189  mesh1( FMap->alpha021(dart1), ASz, AMeshMatrix, AMeshWithMerges,
190  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
191  mesh1( FMap->alpha021(dart2), ASz, AMeshMatrix, AMeshWithMerges,
192  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
193  mesh1( FMap->alpha01 (dart1), ASy, AMeshMatrix, AMeshWithMerges,
194  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
195  mesh1( FMap->alpha01 (dart2), ASy, AMeshMatrix, AMeshWithMerges,
196  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
197  mesh1( FMap->alpha101(dart1), ASx, AMeshMatrix, AMeshWithMerges,
198  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
199  mesh1( FMap->alpha101(dart2), ASx, AMeshMatrix, AMeshWithMerges,
200  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
201  mesh1( FMap->alpha1 (dart1), ASy, AMeshMatrix, AMeshWithMerges,
202  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
203  mesh1( FMap->alpha1 (dart2), ASy, AMeshMatrix, AMeshWithMerges,
204  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
205  mesh1( dart1 , ASx, AMeshMatrix, AMeshWithMerges,
206  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
207  mesh1( dart2 , ASx, AMeshMatrix, AMeshWithMerges,
208  AMeshWithAdjacentSews, AMeshAssociatedCells, ADirectInfoAssoc);
209  }
210 
211  if (AFinalMeshDim>=2)
212  {
213  // 2-maillage:
214  if (AInitialMeshDim<2)
215  {
216  CDart* dart1 = ADart;
217  CDart* dart2 = ADart;
218 
219  for (int i=0; i<ASx; ++i)
220  dart2 = FMap->alpha01(dart2);
221 
222  for (int j=0; j<ASy; ++j)
223  dart2 = FMap->alpha01(dart2);
224 
225  dart2 = FMap->alpha21(dart2);
226 
227  for (int k=0; k<ASz; ++k)
228  dart2 = FMap->alpha01(dart2);
229 
230  mesh2( dart1 , ASx,ASy, AMeshMatrix, AMeshWithMerges,
231  AMeshWithAdjacentSews, AMeshAssociatedCells, false,
232  1,2, ADirectInfoAssoc);
233  mesh2( dart2 , ASx,ASy, AMeshMatrix, AMeshWithMerges,
234  AMeshWithAdjacentSews, AMeshAssociatedCells, false,
235  1,2, ADirectInfoAssoc);
236  mesh2(FMap->alpha2 (dart1), ASx,ASz, AMeshMatrix, AMeshWithMerges,
237  AMeshWithAdjacentSews, AMeshAssociatedCells, false,
238  1,2, ADirectInfoAssoc);
239  mesh2(FMap->alpha2 (dart2), ASx,ASz, AMeshMatrix, AMeshWithMerges,
240  AMeshWithAdjacentSews, AMeshAssociatedCells, false,
241  1,2, ADirectInfoAssoc);
242  mesh2(FMap->alpha12(dart1), ASy,ASz, AMeshMatrix, AMeshWithMerges,
243  AMeshWithAdjacentSews, AMeshAssociatedCells, false,
244  1,2, ADirectInfoAssoc);
245  mesh2(FMap->alpha12(dart2), ASy,ASz, AMeshMatrix, AMeshWithMerges,
246  AMeshWithAdjacentSews, AMeshAssociatedCells, false,
247  1,2, ADirectInfoAssoc);
248  }
249 
250  // 3-maillage:
251  if (AFinalMeshDim==3)
253  FMap->createTopoMesh3(ASx, ASy, ASz),
254  ASx, ASy, ASz);
255  }
256 }
257 //******************************************************************************