Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mv-control-points.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 "g-map-vertex.hh"
26 #include "mesh-vertex.hh"
27 #include <cassert>
28 using namespace GMap3d;
29 //******************************************************************************
30 #define A0(DART) (ADirectInfoAlpha0<0 \
31  ? FMap->alpha0(DART) \
32  : FMap->getDirectInfoAsDart((DART), ADirectInfoAlpha0))
33 
34 #define A1(DART) (FMap->alpha1(DART))
35 //------------------------------------------------------------------------------
36 #define SUCC(DART) ((((CGMapGeneric*) FMap)->*succ)(DART))
37 //------------------------------------------------------------------------------
38 void CMeshVertex::get4ControlPoints(CDart* ADart, CVertex* AVertexArray,
39  int ADirectInfoAlpha0)
40 {
41  assert(ADart!=NULL);
42  assert(AVertexArray!=NULL);
43 
44  CDart* dart0 = A0(ADart);
45 
46  AVertexArray[1] = * FMap->findVertex(ADart);
47  AVertexArray[2] = * FMap->findVertex(dart0);
48 
49  if (FMap->isFree2(ADart) &&
50  FMap->isFree2(A1(ADart)) &&
51  FMap->isFree2(A1(dart0)))
52  {
53  // meshDim = 1
54  if (FMap->isFree1(ADart))
55  AVertexArray[0] = AVertexArray[1];
56  else
57  AVertexArray[0] = * FMap->findVertex(A0(A1(ADart)));
58 
59  if (FMap->isFree1(dart0))
60  AVertexArray[3] = AVertexArray[2];
61  else
62  AVertexArray[3] = * FMap->findVertex(A0(A1(dart0)));
63  }
64  else if (FMap->isFree3(ADart) &&
65  FMap->isFree3(FMap->alpha12(ADart)) &&
66  FMap->isFree3(FMap->alpha12(dart0)))
67  {
68  // meshDim = 2
69  if (FMap->isFree2(A1(ADart)))
70  AVertexArray[0] = AVertexArray[1];
71  else
72  AVertexArray[0] = * FMap->findVertex(A0(FMap->alpha121(ADart)));
73 
74  if (FMap->isFree2(A1(dart0)))
75  AVertexArray[3] = AVertexArray[2];
76  else
77  AVertexArray[3] = * FMap->findVertex(A0(FMap->alpha121(dart0)));
78  }
79  else
80  {
81  // meshDim = 3;
82  if (FMap->isFree3(FMap->alpha12(ADart)))
83  AVertexArray[0] = AVertexArray[1];
84  else
85  AVertexArray[0] = * FMap->findVertex(A0(FMap->alpha12321(ADart)));
86 
87  if (FMap->isFree3(FMap->alpha12(dart0)))
88  AVertexArray[3] = AVertexArray[1];
89  else
90  AVertexArray[3] = * FMap->findVertex(A0(FMap->alpha12321(dart0)));
91  }
92 }
93 //------------------------------------------------------------------------------
94 void CMeshVertex::get16ControlPoints(CDart* ADart, CVertex** AVertexArray,
95  int ADirectInfoAlpha0)
96 {
97  assert(ADart!=NULL);
98  assert(AVertexArray!=NULL);
99 
100  CDart* dart0 = A1(A0(ADart));
101 
102  ADart = A1(ADart);
103 
104  if (FMap->isFree3(FMap->alpha12(ADart)) &&
105  FMap->isFree3(FMap->alpha12(dart0)))
106  {
107  // meshDim = 2
108 
109 // static int x[4][2][2] =
110 // {
111 // { { 0 , 0 } , { 1 , 1 } },
112 // { { 0 , 1 } , { 0 , 1 } },
113 // { { 3 , 3 } , { 2 , 2 } },
114 // { { 3 , 2 } , { 3 , 2 } }
115 // };
116 // static int y[4][2][2] =
117 // {
118 // { { 0 , 1 } , { 0 , 1 } },
119 // { { 3 , 3 } , { 2 , 2 } },
120 // { { 3 , 2 } , { 3 , 2 } },
121 // { { 0 , 0 } , { 1 , 1 } }
122 // };
123 
124 // #define V(I,J) (AVertexArray[x[time][I][J]][y[time][I][J]])
125 
126 // for (int time=0; time<4; ++time)
127 // {
128 // // Sommets faciles à retrouver:
129 // V(1,1) = * findVertex(ADart);
130 
131 // V(0,1) = isFree2( ADart ) ? V(1,1) : * findVertex(alpha210( ADart ));
132 // V(1,0) = isFree2(alpha1(ADart)) ? V(1,1) : * findVertex(alpha210(alpha1(ADart)));
133 
134 // // Quatrième sommet:
135 // int deg = degree(ADart, 0, 3);
136 // int mid = deg / 2;
137 // CDart* d = ADart;
138 
139 // for (int i=0; i<mid; ++i)
140 // d = alpha21(d);
141 
142 // V(0,0) = * findVertex((deg % 2) ? alpha0(d) : alpha010(d));
143 
144 // // Passage au sommet central suivant:
145 // ADart = alpha01(ADart);
146 // }
147 
148  get4ControlPoints(A1(A0(FMap->alpha21(ADart))), AVertexArray[0], ADirectInfoAlpha0);
149  get4ControlPoints( ADart , AVertexArray[1], ADirectInfoAlpha0);
150  get4ControlPoints( dart0 , AVertexArray[2], ADirectInfoAlpha0);
151  get4ControlPoints(A1(A0(FMap->alpha21(dart0))), AVertexArray[3], ADirectInfoAlpha0);
152 // #undef V
153 
154  return;
155  }
156 
157  // meshDim = 3
158  get4ControlPoints(A1(A0(FMap->alpha2321(ADart))), AVertexArray[0], ADirectInfoAlpha0);
159  get4ControlPoints( ADart , AVertexArray[1], ADirectInfoAlpha0);
160  get4ControlPoints( dart0 , AVertexArray[2], ADirectInfoAlpha0);
161  get4ControlPoints(A1(A0(FMap->alpha2321(dart0))), AVertexArray[3], ADirectInfoAlpha0);
162 }
163 //------------------------------------------------------------------------------
164 void CMeshVertex::get64ControlPoints(CDart* ADart, CVertex*** AVertexArray,
165  int ADirectInfoAlpha0)
166 {
167  assert(ADart!=NULL);
168  assert(AVertexArray!=NULL);
169 
170  CDart* currentX =
171  A0(FMap->alpha12321(FMap->alpha1(A0(FMap->alpha2321(FMap->alpha12(A0(FMap->alpha321(ADart))))))));
172 
173  for (int i=0; i<4; ++i)
174  {
175  CDart* currentY = FMap->alpha1(currentX);
176 
177  for (int j=0; j<4; ++j)
178  {
179  CDart* currentZ = FMap->alpha21(currentY);
180 
181  for (int k=0; k<4; ++k)
182  {
183  AVertexArray[i][j][k] = * FMap->findVertex(currentZ);
184 
185  currentZ = k<3 ? FMap->alpha12321(A0(currentZ)) : A0(currentZ);
186  }
187 
188  currentY = j<3 ? FMap->alpha12321(A0(currentY)) : A0(currentY);
189  }
190 
191  currentX = i<3 ? FMap->alpha12321(A0(currentX)) : A0(currentX);
192  }
193 }
194 //------------------------------------------------------------------------------
195 #undef A0
196 #undef A1
197 //******************************************************************************
198 CDart* CMeshVertex::getMesh1Dive(CDart* ADart, int ASx,
199  const CVertex** AVertexTable,
200  bool AAlready2MeshedSquare)
201 {
202  assert(ADart!=NULL);
203  assert(AVertexTable!=NULL);
204  assert(ASx>0);
205 
206  CDart* currentX = ADart;
207 
208  CDart* (CGMapGeneric::* succ) (CDart*) const
209  = AAlready2MeshedSquare ?
210  & CGMapGeneric::alpha0121 : & CGMapGeneric::alpha01;
211 
212  for (int i=0; i<=ASx; ++i)
213  {
214  assert(FMap->findVertex(currentX) != NULL);
215 
216  AVertexTable[i] = FMap->findVertex(currentX);
217 
218  if (i<=ASx-2)
219  currentX = SUCC(currentX);
220  else
221  if (i==ASx-1)
222  currentX = FMap->alpha0(currentX);
223  }
224 
225  return currentX;
226 }
227 //------------------------------------------------------------------------------
228 CDart* CMeshVertex::getMesh2Dive(CDart* ADart, int ASx, int ASy,
229  const CVertex*** AVertexTable,
230  bool AAlready3MeshedCube,
231  int AReturnedDart)
232 {
233  assert(ADart!=NULL);
234  assert(AVertexTable!=NULL);
235  assert(ASx>0);
236  assert(ASy>0);
237  assert(1<=AReturnedDart && AReturnedDart<=3);
238 
239  CDart* currentX, * currentY=NULL, * returned;
240 
241  CDart* (CGMapGeneric::* succ) (CDart*) const
242  = AAlready3MeshedCube ?
243  & CGMapGeneric::alpha012321 : & CGMapGeneric::alpha0121;
244 
245  currentX = ADart;
246 
247  for (int i=0; i<=ASx; ++i)
248  {
249  if (i==ASx && AReturnedDart==1)
250  returned = currentX;
251 
252  currentY = FMap->alpha1(currentX);
253 
254  for (int j=0; j<=ASy; ++j)
255  {
256  assert(FMap->findVertex(currentY) != NULL);
257 
258  AVertexTable[i][j] = FMap->findVertex(currentY);
259 
260  if (j<=ASy-2)
261  currentY = SUCC(currentY);
262  else
263  if (j==ASy-1)
264  currentY = FMap->alpha0(currentY);
265  }
266 
267  if (i==0 && AReturnedDart==2)
268  returned = FMap->alpha1(currentY);
269 
270  if (i<=ASx-2)
271  currentX = SUCC(currentX);
272  else
273  if (i==ASx-1)
274  currentX = FMap->alpha0(currentX);
275  }
276 
277  if (AReturnedDart==1)
278  returned = currentX;
279  else
280  returned = FMap->alpha1(currentY);
281 
282  return returned;
283 }
284 //------------------------------------------------------------------------------
285 #undef SUCC
286 //******************************************************************************