Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
cenrad_3d.c
Go to the documentation of this 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
34#include "libmmg3d_private.h"
45int MMG5_cenrad_iso(MMG5_pMesh mesh,double *ct,double *c,double *rad) {
46 double dd,ux,uy,uz,n1[3],n2[3],n3[3],*c1,*c2,*c3,*c4,pl1,pl2,pl3;
47 double cc1,cc2,cc3;
48
49 c1 = &ct[0];
50 c2 = &ct[3];
51 c3 = &ct[6];
52 c4 = &ct[9];
53
54 ux = c4[0] - c1[0];
55 uy = c4[1] - c1[1];
56 uz = c4[2] - c1[2];
57
58 dd = ux*ux + uy*uy + uz*uz;
59 if ( dd < MMG5_EPSD2 ) return 0;
60
61 dd = 1.0 / sqrt(dd);
62
63 n1[0] = ux*dd;
64 n1[1] = uy*dd;
65 n1[2] = uz*dd;
66
67 /* plan: vecteur directeur passant par milieu(1,4) */
68 pl1 = n1[0]*(c4[0]+c1[0]) \
69 + n1[1]*(c4[1]+c1[1]) + n1[2]*(c4[2]+c1[2]);
70
71 ux = c4[0] - c2[0];
72 uy = c4[1] - c2[1];
73 uz = c4[2] - c2[2];
74
75 dd = ux*ux + uy*uy + uz*uz;
76 if ( dd < MMG5_EPSD2 ) return 0;
77
78 dd = 1.0 / sqrt(dd);
79
80 n2[0] = ux*dd;
81 n2[1] = uy*dd;
82 n2[2] = uz*dd;
83 pl2 = n2[0]*(c4[0]+c2[0]) \
84 + n2[1]*(c4[1]+c2[1]) + n2[2]*(c4[2]+c2[2]);
85
86 ux = c4[0] - c3[0];
87 uy = c4[1] - c3[1];
88 uz = c4[2] - c3[2];
89
90 dd = ux*ux + uy*uy + uz*uz;
91 if ( dd < MMG5_EPSD2 ) return 0;
92
93 dd = 1.0 / sqrt(dd);
94
95 n3[0] = ux*dd;
96 n3[1] = uy*dd;
97 n3[2] = uz*dd;
98 pl3 = n3[0]*(c4[0]+c3[0]) \
99 + n3[1]*(c4[1]+c3[1]) + n3[2]*(c4[2]+c3[2]);
100
101 /* center = intersection of 3 planes */
102 ux = n2[1]*n3[2] - n2[2]*n3[1];
103 uy = n1[2]*n3[1] - n1[1]*n3[2];
104 uz = n1[1]*n2[2] - n1[2]*n2[1];
105
106 dd = n1[0]*ux + n2[0]*uy + n3[0]*uz;
107 if(fabs((dd))<1e-12) return 0;
108 dd = 0.5 / dd;
109
110 cc1 = ux*pl1 + uy*pl2 + uz*pl3;
111 cc2 = pl1 * (n2[2]*n3[0] - n2[0]*n3[2]) \
112 + pl2 * (n1[0]*n3[2] - n3[0]*n1[2]) \
113 + pl3 * (n2[0]*n1[2] - n2[2]*n1[0]);
114 cc3 = pl1 * (n2[0]*n3[1] - n2[1]*n3[0]) \
115 + pl2 * (n3[0]*n1[1] - n3[1]*n1[0]) \
116 + pl3 * (n1[0]*n2[1] - n2[0]*n1[1]);
117
118 c[0] = dd * cc1;
119 c[1] = dd * cc2;
120 c[2] = dd * cc3;
121
122 /* radius (squared) */
123 *rad = (c[0] - c4[0]) * (c[0] - c4[0]) \
124 + (c[1] - c4[1]) * (c[1] - c4[1]) \
125 + (c[2] - c4[2]) * (c[2] - c4[2]);
126
127 return 1;
128}
129
142int MMG5_cenrad_ani(MMG5_pMesh mesh,double *ct,double *m,double *c,double *rad) {
143 double d1,d2,d3,det,dd,ux,uy,uz,vx,vy,vz,wx,wy,wz;
144 double ax,ay,az,bx,by,bz,cx,cy,cz;
145
146
147 dd = m[0]*ct[0]*ct[0] + m[3]*ct[1]*ct[1] + m[5]*ct[2]*ct[2] \
148 + 2.0*(m[1]*ct[0]*ct[1] + m[2]*ct[0]*ct[2] + m[4]*ct[1]*ct[2]);
149
150 /* MMG_lengths */
151 d1 = m[0]*ct[3]*ct[3] + m[3]*ct[4]*ct[4] + m[5]*ct[5]*ct[5] \
152 + 2.0*(m[1]*ct[3]*ct[4] + m[2]*ct[3]*ct[5] + m[4]*ct[4]*ct[5]) - dd;
153
154 d2 = m[0]*ct[6]*ct[6] + m[3]*ct[7]*ct[7] + m[5]*ct[8]*ct[8] \
155 + 2.0*(m[1]*ct[6]*ct[7] + m[2]*ct[6]*ct[8] + m[4]*ct[7]*ct[8]) - dd;
156
157 d3 = m[0]*ct[9]*ct[9] + m[3]*ct[10]*ct[10] + m[5]*ct[11]*ct[11] \
158 + 2.0*(m[1]*ct[9]*ct[10] + m[2]*ct[9]*ct[11] + m[4]*ct[10]*ct[11]) - dd;
159
160 ux = ct[3] - ct[0];
161 uy = ct[4] - ct[1];
162 uz = ct[5] - ct[2];
163
164 vx = ct[6] - ct[0];
165 vy = ct[7] - ct[1];
166 vz = ct[8] - ct[2];
167
168 wx = ct[9] - ct[0];
169 wy = ct[10] - ct[1];
170 wz = ct[11] - ct[2];
171
172 /* M.u */
173 ax = m[0]*ux + m[1]*uy + m[2]*uz;
174 ay = m[1]*ux + m[3]*uy + m[4]*uz;
175 az = m[2]*ux + m[4]*uy + m[5]*uz;
176
177 bx = m[0]*vx + m[1]*vy + m[2]*vz;
178 by = m[1]*vx + m[3]*vy + m[4]*vz;
179 bz = m[2]*vx + m[4]*vy + m[5]*vz;
180
181 cx = m[0]*wx + m[1]*wy + m[2]*wz;
182 cy = m[1]*wx + m[3]*wy + m[4]*wz;
183 cz = m[2]*wx + m[4]*wy + m[5]*wz;
184
185 /* center */
186 c[0] = d1 *(by*cz - bz*cy) - d2 * (ay*cz - az*cy) + d3 * (ay*bz - az*by);
187 c[1] = d1 *(bz*cx - bx*cz) - d2 * (az*cx - ax*cz) + d3 * (az*bx - ax*bz);
188 c[2] = d1 *(bx*cy - by*cx) - d2 * (ax*cy - ay*cx) + d3 * (ax*by - ay*bx);
189
190 det = ax * (by*cz - bz*cy) - ay * (bx*cz - bz*cx) + az * (bx*cy - cx*by);
191 det = 1.0 / (2.0*det);
192
193 c[0] *= det;
194 c[1] *= det;
195 c[2] *= det;
196
197 /* radius (squared) */
198 ux = ct[0] - c[0];
199 uy = ct[1] - c[1];
200 uz = ct[2] - c[2];
201 *rad = m[0]*ux*ux + m[3]*uy*uy + m[5]*uz*uz \
202 + 2.0*(m[1]*ux*uy + m[2]*ux*uz + m[4]*uy*uz);
203
204 return 1;
205}
MMG5_pMesh * mesh
int MMG5_cenrad_iso(MMG5_pMesh mesh, double *ct, double *c, double *rad)
Definition: cenrad_3d.c:45
int MMG5_cenrad_ani(MMG5_pMesh mesh, double *ct, double *m, double *c, double *rad)
Definition: cenrad_3d.c:142
#define MMG5_EPSD2
MMG mesh structure.
Definition: libmmgtypes.h:605