@@ -22,7 +22,7 @@ using namespace K_FLD;
2222using namespace K_SEARCH ;
2323
2424// =============================================================================
25- /* Déclarations et Fonctions */
25+ /* Local functions */
2626// =============================================================================
2727
2828inline bool isSamePoint (E_Float p1x, E_Float p1y, E_Float p1z, E_Float p2x, E_Float p2y, E_Float p2z)
@@ -32,21 +32,21 @@ inline bool isSamePoint(E_Float p1x, E_Float p1y, E_Float p1z, E_Float p2x, E_Fl
3232
3333// ============================================================================
3434/* Conservative smoothing (Kuprat)*/
35- // IN: array : maillage (structuré i-array ou non-structuré 1D dans le plan (x,y))
36- // IN: sweeps : nombre de passes de lissage
37- // IN: retour : 0 = lissage aller seulement , 1 = lissage aller + retour (default à 0, donne un lissage assymétrique )
38- // IN: pas : incrément de parcours (1, 2 ou 3) mis à 1 par default
39- // OUT: tableau lissé (même connectivité, coordonnées modifiées, type conservé )
35+ // IN: array: mesh (Structured i-array ou unstructured 1D in the (x,y) plane )
36+ // IN: sweeps: number of smoothing sweeps
37+ // IN: twoWays : 0 = one way smoothing , 1 = one way and back (default 0, may lead to assymetry )
38+ // IN: step: way step (1, 2 ou 3) default 1
39+ // OUT: smoothed mesh (same as input )
4040// ============================================================================
4141PyObject* K_TRANSFORM::consSmooth (PyObject* self, PyObject* args)
4242{
4343 PyObject* array;
4444
4545 E_Int sweeps = 1 ;
46- E_Int pas = 2 ;
47- E_Int retour = 1 ;
46+ E_Int step = 2 ;
47+ E_Int twoWays = 1 ;
4848
49- if (!PYPARSETUPLE_ (args, O_ III_, &array, &sweeps, &retour , &pas ))
49+ if (!PYPARSETUPLE_ (args, O_ III_, &array, &sweeps, &twoWays , &step ))
5050 {
5151 return NULL ;
5252 }
@@ -78,14 +78,14 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
7878 }
7979 posx++; posy++; posz++;
8080
81- if (retour != 0 && retour != 1 )
81+ if (twoWays != 0 && twoWays != 1 )
8282 {
8383 PyErr_SetString (PyExc_TypeError,
84- " consSmooth: int retour is invalid." );
84+ " consSmooth: int twoWays is invalid." );
8585 return NULL ;
8686 }
8787
88- if (pas < 1 && pas > 3 )
88+ if (step < 1 && step > 3 )
8989 {
9090 PyErr_SetString (PyExc_TypeError,
9191 " consSmooth: int step is invalid." );
@@ -97,7 +97,7 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
9797 FldArrayF* fo;
9898 FldArrayI* cno = NULL ;
9999
100- if (res == 1 ) // structure
100+ if (res == 1 ) // structured
101101 {
102102 tpl = K_ARRAY::buildArray3 (*f, varString, im, jm, km, f->getApi ());
103103 K_ARRAY::getFromArray3 (tpl, fo);
@@ -113,9 +113,9 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
113113 E_Int idx2;
114114 E_Int idx3;
115115
116- // Ouvert ou fermé ?
116+ // open or closed ?
117117 E_Float dx = x[1 ]-x[0 ], dy = y[1 ]-y[0 ], dz = z[1 ]-z[0 ];
118- E_Float refL = std::sqrt (dx*dx + dy*dy + dz*dz); // longueur du 1er segment
118+ E_Float refL = std::sqrt (dx*dx + dy*dy + dz*dz); // length of first segment
119119
120120 E_Float distBouts = std::sqrt ((x[0 ]-x[npts-1 ])*(x[0 ]-x[npts-1 ]) + (y[0 ]-y[npts-1 ])*(y[0 ]-y[npts-1 ]) + (z[0 ]-z[npts-1 ])*(z[0 ]-z[npts-1 ]));
121121
@@ -127,16 +127,16 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
127127 for (E_Int k = 0 ; k < sweeps; k++)
128128 {
129129
130- for (E_Int j = 0 ; j < retour + 1 ; j++)
130+ for (E_Int j = 0 ; j < twoWays + 1 ; j++)
131131 {
132132
133- for (E_Int i = start; i < end; i = i + pas )
133+ for (E_Int i = start; i < end; i = i + step )
134134 {
135135
136136 if (ouvert == 0 )
137137
138138 {
139- // Cyclique, toujours dans [0, nUnique-1]
139+ // Cycle, always in [0, nUnique-1]
140140 idx0 = (j == 0 ) ? i % nUnique : (nUnique - i % nUnique) % nUnique;
141141 idx1 = (j == 0 ) ? (i + 1 ) % nUnique : (nUnique - ((i + 1 ) % nUnique)) % nUnique;
142142 idx2 = (j == 0 ) ? (i + 2 ) % nUnique : (nUnique - ((i + 2 ) % nUnique)) % nUnique;
@@ -150,26 +150,26 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
150150 idx3 = (j == 0 ) ? (i + 3 ) : (nUnique-1 ) - (i + 3 ) ;
151151 }
152152
153- /* On récupère les coordonnées des points i, i+1, i+2, i+3 */
153+ /* Get points i, i+1, i+2, i+3 */
154154 E_Float xi = x[idx0]; E_Float yi = y[idx0]; E_Float zi = z[idx0];
155155 E_Float xip1 = x[idx1]; E_Float yip1 = y[idx1]; E_Float zip1 = z[idx1];
156156 E_Float xip2 = x[idx2]; E_Float yip2 = y[idx2]; E_Float zip2 = z[idx2];
157157 E_Float xip3 = x[idx3]; E_Float yip3 = y[idx3]; E_Float zip3 = z[idx3];
158158
159- /* On calcule les différences de points qui nous interessent (i+3 - i), (i+2 - i) et (i+1 - i) */
159+ /* Compute deltas (i+3 - i), (i+2 - i) et (i+1 - i) */
160160 E_Float dv1x = xip1 - xi; E_Float dv1y = yip1 - yi; E_Float dv1z = zip1 - zi; /* xi+1 - xi */
161161 E_Float dv2x = xip2 - xi; E_Float dv2y = yip2 - yi; E_Float dv2z = zip2 - zi; /* xi+2 - xi */
162162 E_Float dv3x = xip3 - xi; E_Float dv3y = yip3 - yi; E_Float dv3z = zip3 - zi; /* xi+3 - xi */
163163
164- /* On définit uNormal = unit normal to baseline (i+3;i) */
164+ /* Set uNormal = unit normal to baseline (i+3;i) */
165165 E_Float normeDv3 = (dv3x * dv3x) + (dv3y * dv3y) + (dv3z * dv3z); /* ||{xi+3-xi}**||² = ||xi+3-xi||² */
166166
167167 if (normeDv3 < 1e-12 ) continue ;
168168 E_Float divNorme = 1.0 / normeDv3 ;/* 1 / ||xi+3-xi||² */
169169
170170 E_Float uNormalx = divNorme * (-dv3y); E_Float uNormaly = divNorme * (dv3x); E_Float uNormalz = 0 ; /* {xi+3-xi}** / ||xi+3-xi||² */
171171
172- /* Calcul de l'aire signée */
172+ /* Compute signed area */
173173 E_Float aire = 0.5 * (dv3x * dv2y - dv3y * dv2x) + \
174174 0.5 * (dv2x * dv1y - dv2y * dv1x) ;
175175
@@ -190,12 +190,11 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
190190 z[nUnique] = z[0 ];
191191 }
192192
193- RELEASESHAREDS (tpl, fo); // Libération Structurée
193+ RELEASESHAREDS (tpl, fo); // free memory
194194
195195 }
196- else if (res == 2 ) // non structuré
197- {
198-
196+ else if (res == 2 ) // unstructured
197+ {
199198 tpl = K_ARRAY::buildArray3 (f->getNfld (), varString,
200199 f->getSize (), cn->getSize (),
201200 eltType, false , f->getApi ());
@@ -225,13 +224,13 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
225224 std::vector< std::vector<E_Int> > nodeAdj (npts);// vertex/elt adjacents
226225 K_CONNECT::connectEV2VE (*cn, nodeAdj);
227226
228- // Ouvert ou fermé ?? determine les noeuds frontières
227+ // Open or closed, find boundary nodes
229228 E_Int n1 = -1 ; E_Int n2 = -1 ;
230229 E_Int ouvert = 0 ;
231230
232- for (E_Int p = 0 ; p < npts; p++)
231+ for (E_Int p = 0 ; p < npts; p++)
233232 {
234- if ((E_Int)nodeAdj[p].size () == 1 )
233+ if ((E_Int)nodeAdj[p].size () == 1 )
235234 {
236235 if (n1 == -1 ) n1 = p;
237236 else n2 = p;
@@ -242,46 +241,46 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
242241 {
243242 if (isSamePoint (x[n1], y[n1], z[n1], x[n2], y[n2], z[n2]))
244243 {
245- // CAS 2 : Maillage topologiquement OUVERT, mais geometriquement FERME. On soude alors virtuellement
244+ // CASE 2: mesh is topologically OPEN, but geometrically CLOSED.
246245 ouvert = 0 ;
247- printf (" Géométrie fermé avec point doublons : %d et %d\n " , n1, n2);
246+ printf (" INFO: consmooth: closed geometry with double points : %d and %d. \n " , n1, n2);
248247 }
249- else // CAS 3 : Vraie courbe OUVERTE (Les extremites vont rester fixes )
248+ else // CASE 3: mesh is OPEN (extremities will stay fixed )
250249 {
251250 ouvert = 1 ;
252- printf (" Géométrie ouverte : frontières %d et %d\n " , n1, n2);
251+ printf (" INFO: consmooth: open geometry: fixed nodes %d and %d. \n " , n1, n2);
253252 }
254253 }
255254
256- // On crée une chaine ordonnée de noeuds
255+ // Create a chained of ordered nodes
257256 std::vector<E_Int> bar;
258257
259258 E_Int firstNode = (ouvert == 1 ) ? n1
260- : (n1 != -1 ) ? n1 // CAS 2 : fermé avec doublon, on part du premier doublon
261- : ((*cn)(0 , 1 ) - 1 ); // CAS 1 : fermé pur, on part de n'importe quel noeud
259+ : (n1 != -1 ) ? n1 // CASE 2: start from first double point
260+ : ((*cn)(0 , 1 ) - 1 ); // CASE 1: closed, start from any node
262261 E_Int cur = firstNode, prev = -1 ;
263262 bar.push_back (cur);
264263
265264 while (true )
266265 {
267266 E_Int next = -1 ;
268267
269- for (E_Int elt : nodeAdj[cur]) // elt = indice d'élément
268+ for (E_Int elt : nodeAdj[cur]) // elt = element index
270269 {
271270 E_Int nA = (*cn)(elt, 1 ) - 1 ;
272271 E_Int nB = (*cn)(elt, 2 ) - 1 ;
273- E_Int neighbor = (nA == cur) ? nB : nA; // le voisin = l'autre nœud du segment
272+ E_Int neighbor = (nA == cur) ? nB : nA; // neighbour is the other node of element
274273 if (neighbor != prev) { next = neighbor; break ; }
275274 }
276275
277- if (next == -1 ) break ; // CAS 3 : nœud avec 1 seul voisin atteint = fin d'une chaîne ouverte
278- if (ouvert == 0 && next == firstNode) break ; // CAS 1 : retour au départ
279- if (ouvert == 0 && n1 != -1 && next == n2) break ; // CAS 2 : on ne garde pas le doublon
276+ if (next == -1 ) break ; // CASE 3: node with only one node reached = end of open chain
277+ if (ouvert == 0 && next == firstNode) break ; // CASE 1: return to start
278+ if (ouvert == 0 && n1 != -1 && next == n2) break ; // CASE 2: we dont keep double point
280279
281280 bar.push_back (next);
282281 prev = cur;
283282 cur = next;
284- if (ouvert == 1 && cur == n2) break ; // on a atteint l'autre extrémité ouverte
283+ if (ouvert == 1 && cur == n2) break ; // we reach the end of opened curve
285284 }
286285
287286 E_Int nUnique = (E_Int)bar.size ();
@@ -291,29 +290,29 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
291290
292291 for (E_Int k = 0 ; k < sweeps; k++)
293292 {
294- for (E_Int j = 0 ; j < retour + 1 ; j++)
293+ for (E_Int j = 0 ; j < twoWays + 1 ; j++)
295294 {
296- for (E_Int i = start; i < end; i += pas )
295+ for (E_Int i = start; i < end; i += step )
297296 {
298- E_Int c0, c1, c2, c3; // indices dans le bar
297+ E_Int c0, c1, c2, c3; // indices in BAR
299298 if (ouvert == 0 )
300299 {
301- // CAS fermé
300+ // Closed case
302301 c0 = (j == 0 ) ? i % nUnique : (nUnique - i % nUnique) % nUnique;
303302 c1 = (j == 0 ) ? (i + 1 ) % nUnique : (nUnique - ((i + 1 ) % nUnique)) % nUnique;
304303 c2 = (j == 0 ) ? (i + 2 ) % nUnique : (nUnique - ((i + 2 ) % nUnique)) % nUnique;
305304 c3 = (j == 0 ) ? (i + 3 ) % nUnique : (nUnique - ((i + 3 ) % nUnique)) % nUnique;
306305 }
307306 else
308307 {
309- // CAS ouvert :
308+ // Open case
310309 c0 = (j == 0 ) ? i : (nUnique - 1 ) - i;
311310 c1 = (j == 0 ) ? (i + 1 ) : (nUnique - 1 ) - (i + 1 );
312311 c2 = (j == 0 ) ? (i + 2 ) : (nUnique - 1 ) - (i + 2 );
313312 c3 = (j == 0 ) ? (i + 3 ) : (nUnique - 1 ) - (i + 3 );
314313 }
315314
316- // indices réels des nœuds
315+ // Nodes indices
317316 E_Int idx0 = bar[c0];
318317 E_Int idx1 = bar[c1];
319318 E_Int idx2 = bar[c2];
@@ -324,20 +323,20 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
324323 E_Float xip2 = x[idx2]; E_Float yip2 = y[idx2]; E_Float zip2 = z[idx2];
325324 E_Float xip3 = x[idx3]; E_Float yip3 = y[idx3]; E_Float zip3 = z[idx3];
326325
327- /* On calcule les différences de points qui nous interessent (i+3 - i), (i+2 - i) et (i+1 - i) */
326+ /* Compute deltas (i+3 - i), (i+2 - i) et (i+1 - i) */
328327 E_Float dv1x = xip1 - xi; E_Float dv1y = yip1 - yi; E_Float dv1z = zip1 - zi; /* xi+1 - xi */
329328 E_Float dv2x = xip2 - xi; E_Float dv2y = yip2 - yi; E_Float dv2z = zip2 - zi; /* xi+2 - xi */
330329 E_Float dv3x = xip3 - xi; E_Float dv3y = yip3 - yi; E_Float dv3z = zip3 - zi; /* xi+3 - xi */
331330
332- /* On définit uNormal = unit normal to baseline (i+3;i) */
331+ /* Set uNormal = unit normal to baseline (i+3;i) */
333332 E_Float normeDv3 = (dv3x * dv3x) + (dv3y * dv3y) + (dv3z * dv3z); /* ||{xi+3-xi}**||² = ||xi+3-xi||² */
334333
335334 if (normeDv3 < 1e-12 ) continue ;
336335 E_Float divNorme = 1.0 / normeDv3 ;/* 1 / ||xi+3-xi||² */
337336
338337 E_Float uNormalx = divNorme * (-dv3y); E_Float uNormaly = divNorme * (dv3x); E_Float uNormalz = 0 ; /* {xi+3-xi}** / ||xi+3-xi||² */
339338
340- /* Calcul de l'aire signée */
339+ /* Compute signed area */
341340 E_Float aire = 0.5 * (dv3x * dv2y - dv3y * dv2x) + \
342341 0.5 * (dv2x * dv1y - dv2y * dv1x) ;
343342
@@ -346,8 +345,6 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
346345 x[idx1] = 2.0 /3.0 * xi + 1.0 /3.0 * xip3 + h * uNormalx; y[idx1] = 2.0 /3.0 * yi + 1.0 /3.0 * yip3 + h * uNormaly; z[idx1] = 2.0 /3.0 * zi + 1.0 /3.0 * zip3 + h * uNormalz;
347346 x[idx2] = 1.0 /3.0 * xi + 2.0 /3.0 * xip3 + h * uNormalx; y[idx2] = 1.0 /3.0 * yi + 2.0 /3.0 * yip3 + h * uNormaly; z[idx2] = 1.0 /3.0 * zi + 2.0 /3.0 * zip3 + h * uNormalz;
348347
349-
350-
351348 }
352349 }
353350 }
@@ -359,7 +356,7 @@ PyObject* K_TRANSFORM::consSmooth(PyObject* self, PyObject* args)
359356 z[n2] = z[n1];
360357 }
361358
362- RELEASESHAREDU (tpl, fo, cno); // Libération Non-Structurée
359+ RELEASESHAREDU (tpl, fo, cno); // free memory
363360 }
364361
365362 RELEASESHAREDB (res, array, f, cn);
0 commit comments