/src/mmgs/gentools_s.c

https://github.com/MmgTools/mmg · C · 177 lines · 96 code · 24 blank · 57 comment · 20 complexity · 1c61e24420415b1df881d1441f338ddd MD5 · raw file

  1. /* =============================================================================
  2. ** This file is part of the mmg software package for the tetrahedral
  3. ** mesh modification.
  4. ** Copyright (c) Bx INP/CNRS/Inria/UBordeaux/UPMC, 2004-
  5. **
  6. ** mmg is free software: you can redistribute it and/or modify it
  7. ** under the terms of the GNU Lesser General Public License as published
  8. ** by the Free Software Foundation, either version 3 of the License, or
  9. ** (at your option) any later version.
  10. **
  11. ** mmg is distributed in the hope that it will be useful, but WITHOUT
  12. ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  14. ** License for more details.
  15. **
  16. ** You should have received a copy of the GNU Lesser General Public
  17. ** License and of the GNU General Public License along with mmg (in
  18. ** files COPYING.LESSER and COPYING). If not, see
  19. ** <http://www.gnu.org/licenses/>. Please read their terms carefully and
  20. ** use this copy of the mmg distribution only if you accept them.
  21. ** =============================================================================
  22. */
  23. /**
  24. * \file mmgs/gentools_s.c
  25. * \brief Generic algebraic and algorithmic tools.
  26. * \author Charles Dapogny (UPMC)
  27. * \author Cécile Dobrzynski (Bx INP/Inria/UBordeaux)
  28. * \author Pascal Frey (UPMC)
  29. * \author Algiane Froehly (Inria/UBordeaux)
  30. * \version 5
  31. * \copyright GNU Lesser General Public License.
  32. */
  33. #include "mmgs.h"
  34. /* Delete all triangle references in mesh */
  35. int delref(MMG5_pMesh mesh) {
  36. MMG5_pTria pt;
  37. int k;
  38. for(k=1; k<=mesh->nt; k++) {
  39. pt = &mesh->tria[k];
  40. pt->ref = 0;
  41. }
  42. return 1;
  43. }
  44. /**
  45. * \param mesh pointer toward the mesh
  46. * \param start index of the tetra from which we start
  47. * \param ref reference to set
  48. * \param putreq 1 if boundary edges must be set to required
  49. *
  50. * \return 1 if success, 0 if fail
  51. *
  52. * Start from triangle start, and pile up triangles by adjacency, till a GEO or
  53. * REF curve is met ; pass all references of travelled faces to ref ; putreq = 1
  54. * if boundary edges met must be set to MG_REQ, 0 otherwise.
  55. *
  56. */
  57. int setref(MMG5_pMesh mesh,int start,int ref,int putreq) {
  58. MMG5_pTria pt,pt1;
  59. int *list,*adja,cur,base,k,iel,jel,ilist;
  60. int8_t j,voy;
  61. ilist = cur = 0;
  62. MMG5_SAFE_CALLOC(list,mesh->nt+1,int,return 0);
  63. base = ++mesh->base;
  64. /* Pile up triangles from start, till a GEO boundary is met */
  65. pt = &mesh->tria[start];
  66. list[ilist] = start;
  67. ilist++;
  68. assert( ilist <= mesh->nt );
  69. pt->flag = base;
  70. do {
  71. iel = list[cur];
  72. pt = &mesh->tria[iel];
  73. adja = &mesh->adja[3*(iel-1)+1];
  74. for(j=0; j<3; j++) {
  75. if( MG_EDG(pt->tag[j]) ) {
  76. if( putreq ) {
  77. pt->tag[j] |= MG_REQ;
  78. jel = adja[j] / 3;
  79. voy = adja[j] % 3;
  80. if( !jel ) continue;
  81. pt1 = &mesh->tria[jel];
  82. pt1->tag[voy] |= MG_REQ;
  83. }
  84. continue;
  85. }
  86. jel = adja[j] / 3;
  87. assert(jel);
  88. pt1 = &mesh->tria[jel];
  89. if ( pt1->flag == base ) continue;
  90. list[ilist] = jel;
  91. ilist++;
  92. assert( ilist <= mesh->nt );
  93. pt1->flag = base;
  94. }
  95. cur++;
  96. }
  97. while( cur < ilist );
  98. /* Set all references of triangles of list to ref */
  99. for (k=0; k<ilist; k++) {
  100. iel = list[k];
  101. pt = &mesh->tria[iel];
  102. pt->ref = ref;
  103. }
  104. MMG5_SAFE_FREE(list);
  105. return 1;
  106. }
  107. /** find the element number in packed numerotation */
  108. int MMGS_indElt(MMG5_pMesh mesh, int kel) {
  109. MMG5_pTria pt;
  110. int ne, k;
  111. ne = 0;
  112. for (k=1; k<=mesh->nt; k++) {
  113. pt = &mesh->tria[k];
  114. if ( MG_EOK(pt) ) {
  115. ne++;
  116. if ( k == kel ) return ne;
  117. }
  118. }
  119. return 0;
  120. }
  121. /** find the point number in packed numerotation */
  122. int MMGS_indPt(MMG5_pMesh mesh, int kp) {
  123. MMG5_pPoint ppt;
  124. int np, k;
  125. np = 0;
  126. for (k=1; k<=mesh->np; k++) {
  127. ppt = &mesh->point[k];
  128. if ( MG_VOK(ppt) ) {
  129. np++;
  130. if ( k == kp ) return np;
  131. }
  132. }
  133. return 0;
  134. }
  135. /**
  136. * \param mesh pointer toward the mesh structure.
  137. * \param nsd index of subdomain to keep.
  138. *
  139. * Keep only subdomain of index \a nsd and remove other subdomains.
  140. *
  141. */
  142. void MMGS_keep_only1Subdomain ( MMG5_pMesh mesh,int nsd ) {
  143. if ( !nsd ) {
  144. return;
  145. }
  146. if ( mesh->info.imprim > 4 || mesh->info.ddebug ) {
  147. fprintf(stdout,"\n -- ONLY KEEP DOMAIN OF REF %d\n",nsd );
  148. }
  149. MMG5_mark_verticesAsUnused ( mesh );
  150. MMG5_keep_subdomainElts ( mesh, nsd, MMGS_delElt );
  151. MMG5_mark_usedVertices ( mesh,MMGS_delPt );
  152. return;
  153. }