epaississement.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*************************************/
  2. /* Auteur : Rémi Synave */
  3. /* Date de création : 24/02/09 */
  4. /* Date de modification : 15/03/15 */
  5. /* Version : 0.4 */
  6. /*************************************/
  7. /***************************************************************************/
  8. /* This file is part of a2ri. */
  9. /* */
  10. /* a2ri is free software: you can redistribute it and/or modify it */
  11. /* under the terms of the GNU Lesser General Public License as published */
  12. /* by the Free Software Foundation, either version 3 of the License, or */
  13. /* (at your option) any later version. */
  14. /* */
  15. /* a2ri 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 */
  21. /* License along with a2ri. */
  22. /* If not, see <http://www.gnu.org/licenses/>. */
  23. /***************************************************************************/
  24. #include "epaississement.h"
  25. /********** INTERMEDIATE TYPES AND FUNCTIONS **********/
  26. /* Les fonctions intermédiaires sont préfixées de IF */
  27. /* et les types intermédiaires de IT */
  28. void
  29. IFcomble_bord (
  30. int key,
  31. vf_edge * value,
  32. void *user_data)
  33. {
  34. if (value->nbsharedfaces != 1)
  35. return;
  36. vf_model *m = user_data;
  37. int ve1 = value->ve1;
  38. int ve2 = value->ve2;
  39. int numface = value->sharedfaces[0];
  40. int nbancienvertex = m->nbvertex / 2;
  41. if (((m->fa[numface].ve1 == ve1 && m->fa[numface].ve2 == ve2) ||
  42. (m->fa[numface].ve2 == ve1 && m->fa[numface].ve3 == ve2) ||
  43. (m->fa[numface].ve3 == ve1 && m->fa[numface].ve1 == ve2)))
  44. {
  45. ve1 = value->ve2;
  46. ve2 = value->ve1;
  47. }
  48. a2ri_vf_add_face (m, ve1, ve2, ve1 + nbancienvertex);
  49. a2ri_vf_add_face (m, ve2, ve2 + nbancienvertex, ve1 + nbancienvertex);
  50. }
  51. /********** MAIN FUNCTIONS **********/
  52. /**
  53. Epaississement de la surface d'un maillage triangulaire
  54. @param m le modèle à épaissir
  55. @return aucun
  56. **/
  57. void
  58. a2ri_vf_epaissi_surface (
  59. vf_model * m,
  60. double epaisseur)
  61. {
  62. int nbvertex = m->nbvertex;
  63. hashtable *edge = a2ri_vf_construction_edge_table (m, NULL, 0);
  64. for (int i = 0; i < nbvertex; i++)
  65. {
  66. point3d p;
  67. vector3d n;
  68. int *listface = NULL,
  69. sizelist = 0;
  70. vector3d_init (&n, 0, 0, 0);
  71. point3d_init (&p, m->ve[i].x, m->ve[i].y, m->ve[i].z);
  72. for (int j = 0; j < m->ve[i].nbincidentvertices; j++)
  73. {
  74. vf_edge *temp =
  75. hashtable_look_for (edge, i, m->ve[i].incidentvertices[j]);
  76. for (int k = 0; k < temp->nbsharedfaces; k++)
  77. list_int_add (&listface, &sizelist, temp->sharedfaces[k],
  78. WITHOUT_REDUNDANCE);
  79. }
  80. for (int j = 0; j < sizelist; j++)
  81. {
  82. point3d A,
  83. B,
  84. C;
  85. vector3d AB,
  86. AC,
  87. ntemp;
  88. int ve1,
  89. ve2,
  90. ve3;
  91. ve1 = m->fa[listface[j]].ve1;
  92. ve2 = m->fa[listface[j]].ve2;
  93. ve3 = m->fa[listface[j]].ve3;
  94. point3d_init (&A, m->ve[ve1].x, m->ve[ve1].y, m->ve[ve1].z);
  95. point3d_init (&B, m->ve[ve2].x, m->ve[ve2].y, m->ve[ve2].z);
  96. point3d_init (&C, m->ve[ve3].x, m->ve[ve3].y, m->ve[ve3].z);
  97. vector3d_init (&AB, B.x - A.x, B.y - A.y, B.z - A.z);
  98. vector3d_init (&AC, C.x - A.x, C.y - A.y, C.z - A.z);
  99. ntemp = vector3d_vectorialproduct (&AB, &AC);
  100. vector3d_normalize (&ntemp);
  101. vector3d_reverse (&ntemp);
  102. n.dx += ntemp.dx;
  103. n.dy += ntemp.dy;
  104. n.dz += ntemp.dz;
  105. }
  106. n.dx /= sizelist;
  107. n.dy /= sizelist;
  108. n.dz /= sizelist;
  109. vector3d_normalize (&n);
  110. n.dx *= epaisseur;
  111. n.dy *= epaisseur;
  112. n.dz *= epaisseur;
  113. p.x += n.dx;
  114. p.y += n.dy;
  115. p.z += n.dz;
  116. a2ri_vf_add_vertex (m, p.x, p.y, p.z);
  117. free (listface);
  118. }
  119. int nbface = m->nbface;
  120. for (int i = 0; i < nbface; i++)
  121. a2ri_vf_add_face (m, m->fa[i].ve1 + nbvertex, m->fa[i].ve3 + nbvertex,
  122. m->fa[i].ve2 + nbvertex);
  123. hashtable_foreach (edge, IFcomble_bord, m);
  124. hashtable_free (edge);
  125. }