84 double GetX(
void)
const {
return mX; };
85 double GetY(
void)
const {
return mY; };
87 void Set(
double x,
double y)
103 static bool InsideTriangle(
double Ax,
double Ay,
double Bx,
double By,
double Cx,
double Cy,
double Px,
double Py);
104 static bool Snip(
const Vec2dVector &contour,
int u,
int v,
int w,
int n,
int *V);
110 int n = contour.size();
112 for(
int p=n-1,q=0; q<n; p=q++)
114 A+= contour[p].GetX()*contour[q].GetY() - contour[q].GetX()*contour[p].GetY();
122 bool InsideTriangle(
double Ax,
double Ay,
double Bx,
double By,
double Cx,
double Cy,
double Px,
double Py)
124 double ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
125 double cCROSSap, bCROSScp, aCROSSbp; ax = Cx - Bx; ay = Cy - By;
126 bx = Ax - Cx; by = Ay - Cy;
127 cx = Bx - Ax; cy = By - Ay;
128 apx= Px - Ax; apy= Py - Ay;
129 bpx= Px - Bx; bpy= Py - By;
130 cpx= Px - Cx; cpy= Py - Cy; aCROSSbp = ax*bpy - ay*bpx;
131 cCROSSap = cx*apy - cy*apx;
132 bCROSScp = bx*cpy - by*cpx;
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
138 double Ax, Ay, Bx, By, Cx, Cy, Px, Py;
139 Ax = contour[V[u]].GetX();
140 Ay = contour[V[u]].GetY();
141 Bx = contour[V[v]].GetX();
142 By = contour[V[v]].GetY();
143 Cx = contour[V[w]].GetX();
144 Cy = contour[V[w]].GetY();
145 if (
EPSILON > (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) )
return false;
for (p=0;p<n;p++)
147 if( (p == u) || (p == v) || (p == w) )
continue;
148 Px = contour[V[p]].GetX();
149 Py = contour[V[p]].GetY();
157 int n = contour.size();
158 if ( n < 3 )
return false;
int *V =
new int[n];
if ( 0.0f <
Area(contour) )
159 for (
int v=0; v<n; v++) V[v] = v;
161 for(
int v=0; v<n; v++) V[v] = (n-1)-v;
int nv = n;
165 for(
int m=0, v=nv-1; nv>2; )
176 v = u+1;
if (nv <= v) v = 0;
180 if (
Snip(contour,u,v,w,nv,V) )
188 result.push_back( contour[a] );
189 result.push_back( contour[b] );
190 result.push_back( contour[c] );
193 for(s=v,t=v+1;t<nv;s++,t++) V[s] = V[t]; nv--;
204 const double *vertices,
210 unsigned int ret = 0;
212 FILE *fph = fopen(
"debug.obj",
"wb");
215 fprintf(fph,
"v 10 10 0\r\n");
216 for (
unsigned int i=0; i<pcount; i++)
218 fprintf(fph,
"v %f %f %f\r\n", vertices[i*3+0], vertices[i*3+1], vertices[i*3+2]);
220 for (
unsigned int i=0; i<pcount; i++)
222 unsigned int next = i+1;
223 if ( next == pcount ) next = 0;
224 fprintf(fph,
"f %d %d %d\r\n", i+2, 1, next+2 );
233 normal[0] =
plane[0];
234 normal[1] =
plane[1];
235 normal[2] =
plane[2];
241 unsigned int axis = 0;
245 double dx = fabs(normal[0]);
246 double dy = fabs(normal[1]);
247 double dz = fabs(normal[2]);
249 if ( dx > dy && dx > dz )
256 else if ( dy > dx && dy > dz )
263 else if ( dz > dx && dz > dy )
271 double *ptemp =
new double[pcount*2];
272 double *ptri =
new double[maxTri*2*3];
273 const double *source = vertices;
274 double *dest = ptemp;
276 for (
unsigned int i=0; i<pcount; i++)
279 dest[0] = source[i0];
280 dest[1] = source[i1];
291 const double *source = ptri;
292 double *dest = triangles;
294 double inverseZ = -1.0f / normal[i2];
296 for (
unsigned int i=0; i<ret*3; i++)
299 dest[i0] = source[0];
300 dest[i1] = source[1];
302 dest[i2] = (normal[i0]*source[0] + normal[i1]*source[1] + D ) * inverseZ;
311 FILE *fph = fopen(
"test.obj",
"wb");
312 const double *source = triangles;
313 for (
unsigned int i=0; i<ret*3; i++)
315 fprintf(fph,
"v %f %f %f\r\n", source[0], source[1], source[2] );
319 for (
unsigned int i=0; i<ret; i++)
321 fprintf(fph,
"f %d %d %d\r\n", index, index+1, index+2 );
337 const unsigned int *indices,
338 const double *vertices,
343 unsigned int ret = 0;
348 double *ptemp =
new double[pcount*3];
349 double *dest = ptemp;
351 for (
unsigned int i=0; i<pcount; i++)
353 unsigned int index = indices[i];
354 const double *source = &vertices[index*3];
369 const double *vertices,
373 unsigned int ret = 0;
375 const double *source = vertices;
378 for (
unsigned int i=0; i<pcount; i++)
387 bool ok =
Process(vlist,result);
390 ret = result.size()/3;
393 double *dest = triangles;
394 for (
unsigned int i=0; i<ret*3; i++)
396 dest[0] = result[i].GetX();
397 dest[1] = result[i].GetY();