Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
inter-smooth-diver.icc
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 "vertex.hh"
26 #include "transformation-matrix.hh"
27 #include <cassert>
28 //******************************************************************************
29 INLINE
31  const CVertex& AVertex0,
32  const CVertex& AVertex1)
33  : CMesh1Diver(ASx)
34 {
35  FVertex0 = AVertex0;
36  FVertex1 = AVertex1;
37 }
38 //------------------------------------------------------------------------------
39 INLINE
41 {}
42 //------------------------------------------------------------------------------
43 INLINE
45  const CVertex** ABottomEdge,
46  const CVertex** ATopEdge,
47  const CVertex** ALeftEdge,
48  const CVertex** ARightEdge)
49  : CMesh2Diver(ASx, ASy)
50 {
51  assert(ABottomEdge[ 0 ]==ALeftEdge [ 0 ]);
52  assert(ABottomEdge[FSx]==ARightEdge[ 0 ]);
53  assert(ATopEdge [ 0 ]==ALeftEdge [FSy]);
54  assert(ATopEdge [FSx]==ARightEdge[FSy]);
55 
56  // Allocations:
57  FBottomEdge = new const CVertex* [FSx+1];
58  FTopEdge = new const CVertex* [FSx+1];
59  FLeftEdge = new const CVertex* [FSy+1];
60  FRightEdge = new const CVertex* [FSy+1];
61 
62  // Affectations:
63  for (int i=0; i<=FSx; ++i)
64  {
65  FBottomEdge[i] = ABottomEdge[i];
66  FTopEdge [i] = ATopEdge [i];
67  }
68 
69  for (int j=0; j<=FSy; ++j)
70  {
71  FLeftEdge [j] = ALeftEdge [j];
72  FRightEdge [j] = ARightEdge [j];
73  }
74 }
75 //------------------------------------------------------------------------------
76 INLINE
78 {
79  // Libérations:
80  delete [] FBottomEdge;
81  delete [] FTopEdge ;
82  delete [] FLeftEdge ;
83  delete [] FRightEdge ;
84 }
85 //------------------------------------------------------------------------------
86 INLINE
88  const CVertex*** ALeftFace ,
89  const CVertex*** ARightFace ,
90  const CVertex*** AFrontFace ,
91  const CVertex*** ABackFace ,
92  const CVertex*** ABottomFace,
93  const CVertex*** ATopFace )
94  : CMesh3Diver(ASx, ASy, ASz)
95 {
96  int i,j,k;
97 
98 #ifndef NDEBUG
99  for (i=0; i<FSx; ++i)
100  {
101  assert( ABottomFace[ i ][ 0 ] == AFrontFace[ 0 ][ i ] );
102  assert( ABottomFace[ i ][FSy] == ABackFace [ 0 ][ i ] );
103  assert( ATopFace [ i ][ 0 ] == AFrontFace[FSz][ i ] );
104  assert( ATopFace [ i ][FSy] == ABackFace [FSz][ i ] );
105  }
106 
107  for (j=0; j<FSy; ++j)
108  {
109  assert( ABottomFace[ 0 ][ j ] == ALeftFace [ j ][ 0 ] );
110  assert( ABottomFace[FSx][ j ] == ARightFace[ j ][ 0 ] );
111  assert( ATopFace [ 0 ][ j ] == ALeftFace [ j ][FSz] );
112  assert( ATopFace [FSx][ j ] == ARightFace[ j ][FSz] );
113  }
114 
115  for (k=0; k<FSz; ++k)
116  {
117  assert( AFrontFace [ k ][ 0 ] == ALeftFace [ 0 ][ k ] );
118  assert( AFrontFace [ k ][FSx] == ARightFace[ 0 ][ k ] );
119  assert( ABackFace [ k ][ 0 ] == ALeftFace [FSy][ k ] );
120  assert( ABackFace [ k ][FSx] == ARightFace[FSy][ k ] );
121  }
122 #endif
123 
124  // Allocations:
125  FLeftFace = new const CVertex** [FSy+1];
126  FRightFace = new const CVertex** [FSy+1];
127  FFrontFace = new const CVertex** [FSz+1];
128  FBackFace = new const CVertex** [FSz+1];
129  FBottomFace = new const CVertex** [FSx+1];
130  FTopFace = new const CVertex** [FSx+1];
131 
132  for (j=0; j<=FSy; ++j)
133  {
134  FLeftFace [j] = new const CVertex* [FSz+1];
135  FRightFace [j] = new const CVertex* [FSz+1];
136  }
137 
138  for (k=0; k<=FSz; ++k)
139  {
140  FFrontFace [k] = new const CVertex* [FSx+1];
141  FBackFace [k] = new const CVertex* [FSx+1];
142  }
143 
144  for (i=0; i<=FSx; ++i)
145  {
146  FBottomFace[i] = new const CVertex* [FSy+1];
147  FTopFace [i] = new const CVertex* [FSy+1];
148  }
149 
150  // Affectations:
151  for (j=0; j<=FSy; ++j)
152  for (k=0; k<=FSz; ++k)
153  {
154  FLeftFace [j][k] = ALeftFace [j][k];
155  FRightFace [j][k] = ARightFace [j][k];
156  }
157 
158  for (k=0; k<=FSz; ++k)
159  for (i=0; i<=FSx; ++i)
160  {
161  FFrontFace [k][i] = AFrontFace [k][i];
162  FBackFace [k][i] = ABackFace [k][i];
163  }
164 
165  for (i=0; i<=FSx; ++i)
166  for (j=0; j<=FSy; ++j)
167  {
168  FBottomFace[i][j] = ABottomFace[i][j];
169  FTopFace [i][j] = ATopFace [i][j];
170  }
171 }
172 //------------------------------------------------------------------------------
173 INLINE
175 {
176  // Libérations:
177  for (int j=0; j<=FSy; ++j)
178  {
179  delete [] FLeftFace [j];
180  delete [] FRightFace [j];
181  }
182 
183  for (int k=0; k<=FSz; ++k)
184  {
185  delete [] FFrontFace [k];
186  delete [] FBackFace [k];
187  }
188 
189  for (int i=0; i<=FSx; ++i)
190  {
191  delete [] FBottomFace[i];
192  delete [] FTopFace [i];
193  }
194 
195  delete [] FLeftFace ;
196  delete [] FRightFace ;
197  delete [] FFrontFace ;
198  delete [] FBackFace ;
199  delete [] FBottomFace;
200  delete [] FTopFace ;
201 }
202 //******************************************************************************
203 INLINE
205  const CVertex& AVertex0,
206  const CVertex& AVertex1)
207  : CMesh1InterpolationDiver(ASx, AVertex0, AVertex1)
208 {
209 }
210 //------------------------------------------------------------------------------
211 INLINE
213 {}
214 //------------------------------------------------------------------------------
215 INLINE
217  const CVertex** ABottomEdge,
218  const CVertex** ATopEdge,
219  const CVertex** ALeftEdge,
220  const CVertex** ARightEdge)
221  : CMesh2InterpolationDiver(ASx, ASy,
222  ABottomEdge, ATopEdge,
223  ALeftEdge, ARightEdge)
224 {
225  FP00 = FBottomEdge[ 0 ];
226  FP10 = FRightEdge [ 0 ];
227  FP11 = FTopEdge [FSx];
228  FP01 = FLeftEdge [FSy];
229 }
230 //------------------------------------------------------------------------------
231 INLINE
233 {}
234 //------------------------------------------------------------------------------
235 INLINE
236 CMesh3LinearDiver::CMesh3LinearDiver(int ASx, int ASy, int ASz,
237  const CVertex** ALeftFace[],
238  const CVertex** ARightFace[],
239  const CVertex** AFrontFace[],
240  const CVertex** ABackFace[],
241  const CVertex** ABottomFace[],
242  const CVertex** ATopFace[])
243  : CMesh3InterpolationDiver(ASx, ASy, ASz,
244  ALeftFace, ARightFace,
245  AFrontFace, ABackFace,
246  ABottomFace,
247  ATopFace)
248 {
249  FP000 = FBottomFace[ 0 ][ 0 ];
250  FP010 = FBottomFace[ 0 ][ASy];
251  FP100 = FBottomFace[ASx][ 0 ];
252  FP110 = FBottomFace[ASx][ASy];
253 
254  FP001 = ATopFace [ 0 ][ 0 ];
255  FP011 = ATopFace [ 0 ][ASy];
256  FP101 = ATopFace [ASx][ 0 ];
257  FP111 = ATopFace [ASx][ASy];
258 }
259 //------------------------------------------------------------------------------
260 INLINE
262 {}
263 //******************************************************************************
264 INLINE
266  const CTransformationMatrix& AMethod,
267  const CVertex* AControlPoints)
268  : CMesh1Diver(ASx)
269 {
270  assert(AControlPoints!=NULL);
271 
272  for (int dim=0; dim<3; ++dim)
273  {
274  // Récupération du vecteur de 4 coordonnées:
275  CVector controlPoints;
276 
277  for (int i=0; i<4; ++i)
278  controlPoints[i] = AControlPoints[i].getCoord(dim);
279 
280  // Calcul du vecteur de contrôle:
281  FControl[dim] = controlPoints* AMethod;
282  }
283 }
284 //------------------------------------------------------------------------------
285 INLINE
287 {}
288 //------------------------------------------------------------------------------
289 INLINE
291  const CTransformationMatrix& AMethod,
292  const CVertex** AControlPoints)
293  : CMesh2Diver(ASx, ASy)
294 {
295  assert(AControlPoints!=NULL);
296 
297  FMethod = & AMethod;
298 
299  for (int i=0; i<4; ++i)
300  FCurbsY[i] = new CMesh1SmoothingDiver(ASy, * FMethod,
301  AControlPoints[i]);
302 
303  FCurbX = NULL;
304 }
305 //------------------------------------------------------------------------------
306 INLINE
308 {
309  for (int i=0; i<4; ++i)
310  delete FCurbsY[i];
311 
312  if (FCurbX!=NULL)
313  delete FCurbX;
314 }
315 //------------------------------------------------------------------------------
316 INLINE
318  const CTransformationMatrix& AMethod,
319  const CVertex*** AControlPoints)
320  : CMesh3Diver(ASx, ASy, ASz)
321 {
322  assert(AControlPoints!=NULL);
323 
324  FMethod = & AMethod;
325 
326  for (int i=0; i<4; ++i)
327  FSurfacesYZ[i] = new CMesh2SmoothingDiver(ASy, ASz, * FMethod,
328  AControlPoints[i]);
329 
330  FCurbX = NULL;
331 }
332 //------------------------------------------------------------------------------
333 INLINE
335 {
336  for (int i=0; i<4; ++i)
337  delete FSurfacesYZ[i];
338 
339  if (FCurbX!=NULL)
340  delete FCurbX;
341 }
342 //******************************************************************************
343 INLINE
345 {
346  TCoordinate
347  x = FKx0*FVertex0.getX() + FKx1*FVertex1.getX(),
348  y = FKx0*FVertex0.getY() + FKx1*FVertex1.getY(),
349  z = FKx0*FVertex0.getZ() + FKx1*FVertex1.getZ();
350 
351  return CVertex(x,y,z);
352 }
353 //------------------------------------------------------------------------------
354 INLINE
356 {
357  CMesh2InterpolationDiver::setIx(AIx);
358 
359  FPi0 = FBottomEdge[FIx];
360  FPi1 = FTopEdge [FIx];
361 }
362 //------------------------------------------------------------------------------
363 INLINE
365 {
366  CMesh2InterpolationDiver::setIy(AIy);
367 
368  FP0j = FLeftEdge [FIy];
369  FP1j = FRightEdge [FIy];
370 }
371 //------------------------------------------------------------------------------
372 INLINE
374 {
375  TCoordinate
376  x =
377  (
378  FKx0 * FP0j->getX() + FKx1 * FP1j->getX() +
379  FKy0 * FPi0->getX() + FKy1 * FPi1->getX() )
380  -
381  ( FKx0 * FKy0 * FP00->getX() + FKx1 * FKy0 * FP10->getX() +
382  FKx0 * FKy1 * FP01->getX() + FKx1 * FKy1 * FP11->getX() ),
383 
384  y =
385  (
386  FKx0 * FP0j->getY() + FKx1 * FP1j->getY() +
387  FKy0 * FPi0->getY() + FKy1 * FPi1->getY() )
388  -
389  ( FKx0 * FKy0 * FP00->getY() + FKx1 * FKy0 * FP10->getY() +
390  FKx0 * FKy1 * FP01->getY() + FKx1 * FKy1 * FP11->getY() ),
391 
392  z =
393  (
394  FKx0 * FP0j->getZ() + FKx1 * FP1j->getZ() +
395  FKy0 * FPi0->getZ() + FKy1 * FPi1->getZ() )
396  -
397  ( FKx0 * FKy0 * FP00->getZ() + FKx1 * FKy0 * FP10->getZ() +
398  FKx0 * FKy1 * FP01->getZ() + FKx1 * FKy1 * FP11->getZ() );
399 
400  return CVertex(x,y,z);
401 }
402 //------------------------------------------------------------------------------
403 INLINE
405 {
406  CMesh3InterpolationDiver::setIx(AIx);
407 
408  FPi00 = FBottomFace[FIx][ 0 ];
409  FPi01 = FTopFace [FIx][ 0 ];
410  FPi10 = FBottomFace[FIx][FSy];
411  FPi11 = FTopFace [FIx][FSy];
412 
413  FPi0k = FFrontFace [FIz][FIx];
414  FPi1k = FBackFace [FIz][FIx];
415 
416  FPij0 = FBottomFace[FIx][FIy];
417  FPij1 = FTopFace [FIx][FIy];
418 }
419 //------------------------------------------------------------------------------
420 INLINE
422 {
423  CMesh3InterpolationDiver::setIy(AIy);
424 
425  FP0j0 = FLeftFace [FIy][ 0 ];
426  FP1j0 = FRightFace [FIy][ 0 ];
427  FP0j1 = FLeftFace [FIy][FSz];
428  FP1j1 = FRightFace [FIy][FSz];
429 
430  FP0jk = FLeftFace [FIy][FIz];
431  FP1jk = FRightFace [FIy][FIz];
432 
433  FPij0 = FBottomFace[FIx][FIy];
434  FPij1 = FTopFace [FIx][FIy];
435 }
436 //------------------------------------------------------------------------------
437 INLINE
439 {
440  CMesh3InterpolationDiver::setIz(AIz);
441 
442  FP00k = FFrontFace [FIz][ 0 ];
443  FP01k = FBackFace [FIz][ 0 ];
444  FP10k = FFrontFace [FIz][FSx];
445  FP11k = FBackFace [FIz][FSx];
446 
447  FP0jk = FLeftFace [FIy][FIz];
448  FP1jk = FRightFace [FIy][FIz];
449 
450  FPi0k = FFrontFace [FIz][FIx];
451  FPi1k = FBackFace [FIz][FIx];
452 }
453 //------------------------------------------------------------------------------
454 INLINE
456 {
457  TCoordinate
458  x =
459  // Faces:
460  (
461  FKx0 * FP0jk->getX() + FKx1 * FP1jk->getX() +
462  FKy0 * FPi0k->getX() + FKy1 * FPi1k->getX() +
463  FKz0 * FPij0->getX() + FKz1 * FPij1->getX() )
464  // Arêtes:
465  -
466  (
467  FKx0 * FKy0 * FP00k->getX() + FKx1 * FKy0 * FP10k->getX() +
468  FKx0 * FKy1 * FP01k->getX() + FKx1 * FKy1 * FP11k->getX() +
469 
470  FKx0 * FKz0 * FP0j0->getX() + FKx1 * FKz0 * FP1j0->getX() +
471  FKx0 * FKz1 * FP0j1->getX() + FKx1 * FKz1 * FP1j1->getX() +
472 
473  FKy0 * FKz0 * FPi00->getX() + FKy1 * FKz0 * FPi10->getX() +
474  FKy0 * FKz1 * FPi01->getX() + FKy1 * FKz1 * FPi11->getX() )
475  // Sommets:
476  +
477  (
478  FKx0 * FKy0 * FKz0 * FP000->getX() +
479  FKx1 * FKy1 * FKz1 * FP111->getX() +
480  FKx1 * FKy0 * FKz0 * FP100->getX() +
481  FKx0 * FKy1 * FKz0 * FP010->getX() +
482  FKx0 * FKy0 * FKz1 * FP001->getX() +
483  FKx0 * FKy1 * FKz1 * FP011->getX() +
484  FKx1 * FKy0 * FKz1 * FP101->getX() +
485  FKx1 * FKy1 * FKz0 * FP110->getX() ),
486 
487  y =
488  // Faces:
489  (
490  FKx0 * FP0jk->getY() + FKx1 * FP1jk->getY() +
491  FKy0 * FPi0k->getY() + FKy1 * FPi1k->getY() +
492  FKz0 * FPij0->getY() + FKz1 * FPij1->getY() )
493  // Arêtes:
494  -
495  (
496  FKx0 * FKy0 * FP00k->getY() + FKx1 * FKy0 * FP10k->getY() +
497  FKx0 * FKy1 * FP01k->getY() + FKx1 * FKy1 * FP11k->getY() +
498 
499  FKx0 * FKz0 * FP0j0->getY() + FKx1 * FKz0 * FP1j0->getY() +
500  FKx0 * FKz1 * FP0j1->getY() + FKx1 * FKz1 * FP1j1->getY() +
501 
502  FKy0 * FKz0 * FPi00->getY() + FKy1 * FKz0 * FPi10->getY() +
503  FKy0 * FKz1 * FPi01->getY() + FKy1 * FKz1 * FPi11->getY() )
504  // Sommets:
505  +
506  (
507  FKx0 * FKy0 * FKz0 * FP000->getY() +
508  FKx1 * FKy1 * FKz1 * FP111->getY() +
509  FKx1 * FKy0 * FKz0 * FP100->getY() +
510  FKx0 * FKy1 * FKz0 * FP010->getY() +
511  FKx0 * FKy0 * FKz1 * FP001->getY() +
512  FKx0 * FKy1 * FKz1 * FP011->getY() +
513  FKx1 * FKy0 * FKz1 * FP101->getY() +
514  FKx1 * FKy1 * FKz0 * FP110->getY() ),
515 
516  z =
517  // Faces:
518  (
519  FKx0 * FP0jk->getZ() + FKx1 * FP1jk->getZ() +
520  FKy0 * FPi0k->getZ() + FKy1 * FPi1k->getZ() +
521  FKz0 * FPij0->getZ() + FKz1 * FPij1->getZ() )
522  // Arêtes:
523  -
524  (
525  FKx0 * FKy0 * FP00k->getZ() + FKx1 * FKy0 * FP10k->getZ() +
526  FKx0 * FKy1 * FP01k->getZ() + FKx1 * FKy1 * FP11k->getZ() +
527 
528  FKx0 * FKz0 * FP0j0->getZ() + FKx1 * FKz0 * FP1j0->getZ() +
529  FKx0 * FKz1 * FP0j1->getZ() + FKx1 * FKz1 * FP1j1->getZ() +
530 
531  FKy0 * FKz0 * FPi00->getZ() + FKy1 * FKz0 * FPi10->getZ() +
532  FKy0 * FKz1 * FPi01->getZ() + FKy1 * FKz1 * FPi11->getZ() )
533  // Sommets:
534  +
535  (
536  FKx0 * FKy0 * FKz0 * FP000->getZ() +
537  FKx1 * FKy1 * FKz1 * FP111->getZ() +
538  FKx1 * FKy0 * FKz0 * FP100->getZ() +
539  FKx0 * FKy1 * FKz0 * FP010->getZ() +
540  FKx0 * FKy0 * FKz1 * FP001->getZ() +
541  FKx0 * FKy1 * FKz1 * FP011->getZ() +
542  FKx1 * FKy0 * FKz1 * FP101->getZ() +
543  FKx1 * FKy1 * FKz0 * FP110->getZ() );
544 
545  return CVertex(x,y,z);
546 }
547 //******************************************************************************
548 INLINE
550 {
551  CMesh1Diver::setIx(AIx);
552 
553  TCoordinate t = 1;
554 
555  for (int i=3; i>=0; --i)
556  {
557  FTX[i] = t;
558  t *= FKx1;
559  }
560 }
561 //------------------------------------------------------------------------------
562 INLINE
564 {
565  TCoordinate coord[3];
566 
567  for (int i=0; i<3; ++i)
568  coord[i] = FTX * FControl[i];
569 
570  return CVertex(coord[0], coord[1], coord[2]);
571 }
572 //------------------------------------------------------------------------------
573 INLINE
575 {
576  assert(FCurbX!=NULL);
577 
578  CMesh2Diver::setIx(AIx);
579 
580  FCurbX->setIx(AIx);
581 }
582 //------------------------------------------------------------------------------
583 INLINE
585 {
586  CMesh2Diver::setIy(AIy);
587 
588  CVertex controlPoints[4];
589 
590  for (int i=0; i<4; ++i)
591  {
592  FCurbsY[i]->setIx(AIy);
593  controlPoints[i] = FCurbsY[i]->computeCurrentVertex();
594  }
595 
596  if (FCurbX!=NULL)
597  delete FCurbX;
598 
599  FCurbX = new CMesh1SmoothingDiver(FSx, * FMethod,
600  controlPoints);
601 }
602 //------------------------------------------------------------------------------
603 INLINE
605 {
606  assert(FCurbX!=NULL);
607 
608  return FCurbX->computeCurrentVertex();
609 }
610 //------------------------------------------------------------------------------
611 INLINE
613 {
614  assert(FCurbX!=NULL);
615 
616  FCurbX->setIx(AIx);
617 }
618 //------------------------------------------------------------------------------
619 INLINE
621 {
622  CMesh3Diver::setIy(AIy);
623 
624  CVertex controlPoints[4];
625 
626  for (int i=0; i<4; ++i)
627  {
628  FSurfacesYZ[i]->setIx(AIy);
629  controlPoints[i] = FSurfacesYZ[i]->computeCurrentVertex();
630  }
631 
632  if (FCurbX!=NULL)
633  delete FCurbX;
634 
635  FCurbX = new CMesh1SmoothingDiver(FSx, * FMethod,
636  controlPoints);
637 }
638 //------------------------------------------------------------------------------
639 INLINE
641 {
642  CMesh3Diver::setIz(AIz);
643 
644  for (int i=0; i<4; ++i)
645  FSurfacesYZ[i]->setIy(AIz);
646 }
647 //------------------------------------------------------------------------------
648 INLINE
650 {
651  assert(FCurbX!=NULL);
652 
653  return FCurbX->computeCurrentVertex();
654 }
655 //******************************************************************************