Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmv-primitive-mesh.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 #include "geometry.hh"
27 using namespace GMap3d;
28 //******************************************************************************
29 #define SUCC(DART) ((((CGMapGeneric*) this)->*succ)(DART))
30 //------------------------------------------------------------------------------
31 void CGMapVertex::diveMesh1(CDart * AFirstDart, CMesh1Diver & ADiver,
32  TEmbedMethod ADiveBorders, int AMeshDimension)
33 {
34  assert(1 <= AMeshDimension && AMeshDimension <= 3);
35 
36  CDart * (CGMapGeneric::* succ) (CDart *) const = NULL;
37 
38  switch (AMeshDimension)
39  {
40  case 1: succ = & CGMapGeneric::alpha01 ; break;
41  case 2: succ = & CGMapGeneric::alpha0121 ; break;
42  case 3: succ = & CGMapGeneric::alpha012321; break;
43  }
44 
45  CDart * currentX =
46  ADiveBorders==GMV_NO ? SUCC(AFirstDart) : AFirstDart;
47 
48  int iMin = ADiveBorders==GMV_NO ? 1 : 0;
49  int iMax = ADiveBorders==GMV_NO ? ADiver.getSx() - 1 : ADiver.getSx();
50 
51  for (int i=iMin; i<=iMax; ++i, currentX = SUCC(currentX))
52  {
53  ADiver.setIx(i);
54 
55  if (ADiveBorders==GMV_CHECK && (i==0 || i==ADiver.getSx()))
56  updateVertex(currentX, ADiver.computeCurrentVertex());
57  else
58  setVertex(currentX, ADiver.computeCurrentVertex());
59  }
60 }
61 //******************************************************************************
62 void CGMapVertex::diveMesh2(CDart * AFirstDart, CMesh2Diver & ADiver,
63  TEmbedMethod ADiveBorders, int AMeshDimension)
64 {
65  assert(2 <= AMeshDimension && AMeshDimension <= 3);
66 
67  CDart * (CGMapGeneric::* succ) (CDart *) const = NULL;
68 
69  switch (AMeshDimension)
70  {
71  case 2: succ = & CGMapGeneric::alpha0121 ; break;
72  case 3: succ = & CGMapGeneric::alpha012321; break;
73  }
74 
75  CDart * currentY =
76  ADiveBorders==GMV_NO ? SUCC(alpha1(SUCC(AFirstDart))) : alpha1(AFirstDart);
77 
78  int iMin = ADiveBorders==GMV_NO ? 1 : 0;
79  int iMax = ADiveBorders==GMV_NO ? ADiver.getSx() - 1 : ADiver.getSx();
80 
81  int jMin = ADiveBorders==GMV_NO ? 1 : 0;
82  int jMax = ADiveBorders==GMV_NO ? ADiver.getSy() - 1 : ADiver.getSy();
83 
84  for (int j=jMin; j<=jMax;
85  ++j, currentY = j==jMax ? alpha0(currentY) : SUCC(currentY))
86  {
87  ADiver.setIy(j);
88 
89  bool borderY = j==0 || j==ADiver.getSy();
90 
91  CDart * currentX = alpha1(currentY);
92 
93  for (int i=iMin; i<=iMax; ++i, currentX = SUCC(currentX))
94  {
95  ADiver.setIx(i);
96 
97  bool borderX = i==0 || i==ADiver.getSx();
98 
99  if (ADiveBorders==GMV_CHECK && (borderX || borderY))
100  updateVertex(currentX, ADiver.computeCurrentVertex());
101  else
102  setVertex(currentX, ADiver.computeCurrentVertex());
103  }
104  }
105 }
106 //******************************************************************************
107 void CGMapVertex::diveMesh3(CDart * AFirstDart, CMesh3Diver & ADiver,
108  TEmbedMethod ADiveBorders)
109 {
110  CDart * currentZ =
111  ADiveBorders==GMV_NO
112  ? alpha210123(alpha101232(alpha012321(AFirstDart)))
113  : AFirstDart;
114 
115  currentZ = alpha21(currentZ);
116 
117  int iMin = ADiveBorders==GMV_NO ? 1 : 0;
118  int iMax = ADiveBorders==GMV_NO ? ADiver.getSx() - 1 : ADiver.getSx();
119 
120  int jMin = ADiveBorders==GMV_NO ? 1 : 0;
121  int jMax = ADiveBorders==GMV_NO ? ADiver.getSy() - 1 : ADiver.getSy();
122 
123  int kMin = ADiveBorders==GMV_NO ? 1 : 0;
124  int kMax = ADiveBorders==GMV_NO ? ADiver.getSz() - 1 : ADiver.getSz();
125 
126  for (int k=kMin; k<=kMax;
127  ++k, currentZ = k==kMax ? alpha0(currentZ) : alpha012321(currentZ))
128  {
129  ADiver.setIz(k);
130 
131  bool borderZ = k==0 || k==ADiver.getSz();
132 
133  CDart * currentY = alpha21(currentZ);
134 
135  for (int j=jMin; j<=jMax;
136  ++j, currentY = j==jMax ? alpha0(currentY) : alpha012321(currentY))
137  {
138  ADiver.setIy(j);
139 
140  bool borderY = j==0 || j==ADiver.getSy();
141 
142  CDart * currentX = alpha21(currentY);
143 
144  for (int i=iMin; i<=iMax;
145  ++i, currentX = i==iMax ? alpha0(currentX) : alpha012321(currentX))
146  {
147  ADiver.setIx(i);
148 
149  bool borderX = i==0 || i==ADiver.getSx();
150 
151  if (ADiveBorders==GMV_CHECK && (borderX || borderY || borderZ))
152  updateVertex(currentX, ADiver.computeCurrentVertex());
153  else
154  setVertex(currentX, ADiver.computeCurrentVertex());
155  }
156  }
157  }
158 }
159 //******************************************************************************
160 void CGMapVertex::createMesh1(int ASx, CDart * AMesh1Corners[2],
161  CMesh1Diver & ADiver)
162 {
163  assert(ASx == ADiver.getSx());
164  assert(AMesh1Corners!=NULL);
165 
166  createTopoMesh1(ASx, AMesh1Corners);
167  diveMesh1(AMesh1Corners[0], ADiver);
168 }
169 //******************************************************************************
171 {
172  CDart * mesh1Corners[2];
173 
174  createMesh1(ASx, mesh1Corners, ADiver);
175 
176  return mesh1Corners[0];
177 }
178 //******************************************************************************
180 {
181  CMesh1BasicDiver diver(ASx, -OX/2,OX);
182  return createMesh1(ASx, diver);
183 }
184 //******************************************************************************
185 void CGMapVertex::createMesh2(int ASx, int ASy,
186  CDart * AMesh2Corners[2][2],
187  CMesh2Diver & ADiver)
188 {
189  assert(ASx == ADiver.getSx());
190  assert(ASy == ADiver.getSy());
191  assert(AMesh2Corners!=NULL);
192 
193  createTopoMesh2(ASx,ASy, AMesh2Corners);
194  diveMesh2(AMesh2Corners[0][0], ADiver);
195 }
196 //******************************************************************************
197 CDart * CGMapVertex::createMesh2(int ASx, int ASy, CMesh2Diver & ADiver)
198 {
199  CDart * mesh2Corners[2][2];
200 
201  createMesh2(ASx,ASy, mesh2Corners, ADiver);
202 
203  return mesh2Corners[0][0];
204 }
205 //******************************************************************************
206 CDart * CGMapVertex::createMesh2(int ASx, int ASy)
207 {
208  CMesh2BasicDiver diver(ASx,ASy, -(OX+OY)/2, OX,OY);
209  return createMesh2(ASx,ASy, diver);
210 }
211 //******************************************************************************
212 void CGMapVertex::createMesh3(int ASx, int ASy, int ASz,
213  CDart * AMesh3Corners[2][2][2],
214  CMesh3Diver & ADiver)
215 {
216  assert(ASx == ADiver.getSx());
217  assert(ASy == ADiver.getSy());
218  assert(ASz == ADiver.getSz());
219  assert(AMesh3Corners!=NULL);
220 
221  createTopoMesh3(ASx,ASy,ASz, AMesh3Corners);
222  diveMesh3(AMesh3Corners[0][0][0], ADiver);
223 }
224 //******************************************************************************
225 CDart * CGMapVertex::createMesh3(int ASx, int ASy, int ASz, CMesh3Diver & ADiver)
226 {
227  CDart * mesh3Corners[2][2][2];
228 
229  createMesh3(ASx,ASy,ASz, mesh3Corners, ADiver);
230 
231  return mesh3Corners[0][0][0];
232 }
233 //******************************************************************************
234 CDart * CGMapVertex::createMesh3(int ASx, int ASy, int ASz)
235 {
236  CMesh3BasicDiver diver(ASx,ASy,ASz, -(OX+OY+OZ)/2, OX,OY,OZ);
237  return createMesh3(ASx,ASy,ASz, diver);
238 }
239 //------------------------------------------------------------------------------
240 #undef SUCC
241 //******************************************************************************