2009-01-13 04:40:13 +05:00
|
|
|
#include <mystdlib.h>
|
|
|
|
#include "meshing.hpp"
|
|
|
|
|
|
|
|
namespace netgen
|
|
|
|
{
|
|
|
|
|
|
|
|
netrule :: netrule ()
|
|
|
|
{
|
2021-06-21 18:13:08 +05:00
|
|
|
// name = new char[1];
|
|
|
|
// name[0] = char(0);
|
2009-01-13 04:40:13 +05:00
|
|
|
quality = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
netrule :: ~netrule()
|
|
|
|
{
|
2021-06-21 11:36:14 +05:00
|
|
|
// delete [] name;
|
|
|
|
/*
|
2010-07-21 02:04:16 +06:00
|
|
|
for(int i = 0; i < oldutofreearea_i.Size(); i++)
|
2009-01-13 04:40:13 +05:00
|
|
|
delete oldutofreearea_i[i];
|
2010-07-21 02:04:16 +06:00
|
|
|
for(int i = 0; i < freezone_i.Size(); i++)
|
|
|
|
delete freezone_i[i];
|
2021-06-21 11:36:14 +05:00
|
|
|
*/
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void netrule :: SetFreeZoneTransformation (const Vector & devp, int tolclass)
|
|
|
|
{
|
|
|
|
double lam1 = 1.0/tolclass;
|
|
|
|
double lam2 = 1.-lam1;
|
|
|
|
|
|
|
|
double mem1[100], mem2[100], mem3[100];
|
|
|
|
|
|
|
|
int vs = oldutofreearea.Height();
|
|
|
|
FlatVector devfree(vs, mem1);
|
2010-07-21 02:04:16 +06:00
|
|
|
|
|
|
|
int fzs = freezone.Size();
|
|
|
|
transfreezone.SetSize (fzs);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
if (tolclass <= oldutofreearea_i.Size())
|
|
|
|
{
|
2021-06-21 11:36:14 +05:00
|
|
|
oldutofreearea_i[tolclass-1].Mult (devp, devfree);
|
2010-07-21 02:04:16 +06:00
|
|
|
|
2021-06-21 11:36:14 +05:00
|
|
|
auto& fzi = freezone_i[tolclass-1];
|
2010-07-21 02:04:16 +06:00
|
|
|
for (int i = 0; i < fzs; i++)
|
|
|
|
{
|
2019-09-29 19:22:00 +05:00
|
|
|
transfreezone[i][0] = fzi[i][0] + devfree[2*i];
|
|
|
|
transfreezone[i][1] = fzi[i][1] + devfree[2*i+1];
|
2010-07-21 02:04:16 +06:00
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-21 02:04:16 +06:00
|
|
|
FlatVector devfree1(vs, mem2);
|
|
|
|
FlatVector devfree2(vs, mem3);
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
oldutofreearea.Mult (devp, devfree1);
|
|
|
|
oldutofreearealimit.Mult (devp, devfree2);
|
|
|
|
devfree.Set2 (lam1, devfree1, lam2, devfree2);
|
2010-07-21 02:04:16 +06:00
|
|
|
|
|
|
|
for (int i = 0; i < fzs; i++)
|
|
|
|
{
|
2019-09-29 19:22:00 +05:00
|
|
|
transfreezone[i][0] = lam1 * freezone[i][0] + lam2 * freezonelimit[i][0] + devfree[2*i];
|
|
|
|
transfreezone[i][1] = lam1 * freezone[i][1] + lam2 * freezonelimit[i][1] + devfree[2*i+1];
|
2010-07-21 02:04:16 +06:00
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fzs > 0)
|
|
|
|
{
|
2019-09-29 19:22:00 +05:00
|
|
|
fzmaxx = fzminx = transfreezone[0][0];
|
|
|
|
fzmaxy = fzminy = transfreezone[0][1];
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i < fzs; i++)
|
|
|
|
{
|
2019-09-29 19:22:00 +05:00
|
|
|
if (transfreezone[i][0] > fzmaxx) fzmaxx = transfreezone[i][0];
|
|
|
|
if (transfreezone[i][0] < fzminx) fzminx = transfreezone[i][0];
|
|
|
|
if (transfreezone[i][1] > fzmaxy) fzmaxy = transfreezone[i][1];
|
|
|
|
if (transfreezone[i][1] < fzminy) fzminy = transfreezone[i][1];
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < fzs; i++)
|
|
|
|
{
|
2019-09-30 13:19:35 +05:00
|
|
|
const auto& p1 = transfreezone[i];
|
|
|
|
const auto& p2 = transfreezone[(i+1) % fzs];
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-09-30 13:19:35 +05:00
|
|
|
Vec<2> vn = { p2[1] - p1[1], p1[0] - p2[0] };
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
double len2 = vn.Length2();
|
|
|
|
|
|
|
|
if (len2 < 1e-10)
|
|
|
|
{
|
|
|
|
freesetinequ(i, 0) = 0;
|
|
|
|
freesetinequ(i, 1) = 0;
|
|
|
|
freesetinequ(i, 2) = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-19 18:00:52 +06:00
|
|
|
vn /= sqrt (len2); // scaling necessary ?
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-09-30 13:19:35 +05:00
|
|
|
freesetinequ(i,0) = vn[0];
|
|
|
|
freesetinequ(i,1) = vn[1];
|
|
|
|
freesetinequ(i,2) = -(p1[0] * vn[0] + p1[1] * vn[1]);
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
int netrule :: IsInFreeZone2 (const Point2d & p) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < transfreezone.Size(); i++)
|
|
|
|
{
|
|
|
|
if (freesetinequ(i, 0) * p.X() +
|
2019-09-30 13:19:35 +05:00
|
|
|
freesetinequ(i, 1) * p[1] +
|
2009-01-13 04:40:13 +05:00
|
|
|
freesetinequ(i, 2) > 0) return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-09-30 13:19:35 +05:00
|
|
|
int netrule :: IsLineInFreeZone2 (const Point<2> & p1, const Point<2> & p2) const
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
2019-09-30 13:19:35 +05:00
|
|
|
if ( (p1[0] > fzmaxx && p2[0] > fzmaxx) ||
|
|
|
|
(p1[0] < fzminx && p2[0] < fzminx) ||
|
|
|
|
(p1[1] > fzmaxy && p2[1] > fzmaxy) ||
|
|
|
|
(p1[1] < fzminy && p2[1] < fzminy) ) return 0;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
for (int i = 1; i <= transfreezone.Size(); i++)
|
|
|
|
{
|
2019-09-30 13:19:35 +05:00
|
|
|
if (freesetinequ.Get(i, 1) * p1[0] + freesetinequ.Get(i, 2) * p1[1] +
|
2009-01-13 04:40:13 +05:00
|
|
|
freesetinequ.Get(i, 3) > -1e-8 && // -1e-6
|
2019-09-30 13:19:35 +05:00
|
|
|
freesetinequ.Get(i, 1) * p2[0] + freesetinequ.Get(i, 2) * p2[1] +
|
2009-01-13 04:40:13 +05:00
|
|
|
freesetinequ.Get(i, 3) > -1e-8 // -1e-6
|
|
|
|
) return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-30 13:19:35 +05:00
|
|
|
double nx = (p2[1] - p1[1]);
|
|
|
|
double ny = -(p2[0] - p1[0]);
|
2009-01-13 04:40:13 +05:00
|
|
|
double nl = sqrt (nx * nx + ny * ny);
|
|
|
|
if (nl > 1e-8)
|
|
|
|
{
|
|
|
|
nx /= nl;
|
|
|
|
ny /= nl;
|
2019-09-30 13:19:35 +05:00
|
|
|
double c = - (p1[0] * nx + p1[1] * ny);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2016-01-31 01:56:12 +05:00
|
|
|
bool allleft = true;
|
|
|
|
bool allright = true;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
for (int i = 1; i <= transfreezone.Size(); i++)
|
|
|
|
{
|
2019-09-29 19:22:00 +05:00
|
|
|
bool left = transfreezone.Get(i)[0] * nx + transfreezone.Get(i)[1] * ny + c < 1e-7;
|
|
|
|
bool right = transfreezone.Get(i)[0] * nx + transfreezone.Get(i)[1] * ny + c > -1e-7;
|
2016-01-31 01:56:12 +05:00
|
|
|
if (!left) allleft = false;
|
|
|
|
if (!right) allright = false;
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
2016-01-31 01:56:12 +05:00
|
|
|
if (allleft || allright) return false;
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
2016-01-31 01:56:12 +05:00
|
|
|
return true;
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
int netrule :: ConvexFreeZone () const
|
|
|
|
{
|
|
|
|
int n = transfreezone.Size();
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
{
|
|
|
|
const bool counterclockwise = CCW (transfreezone.Get(i),
|
|
|
|
transfreezone.Get(i % n + 1),
|
|
|
|
transfreezone.Get( (i+1) % n + 1 ),
|
|
|
|
1e-7);
|
|
|
|
//(*testout) << "ccw " << counterclockwise << endl << " p1 " << transfreezone.Get(i) << " p2 " << transfreezone.Get(i % n + 1)
|
|
|
|
// << " p3 " << transfreezone.Get( (i+1) % n + 1 ) << endl;
|
|
|
|
if (!counterclockwise )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
float netrule :: CalcPointDist (int pi, const Point2d & p) const
|
|
|
|
{
|
|
|
|
float dx = p.X() - points.Get(pi).X();
|
|
|
|
float dy = p.Y() - points.Get(pi).Y();
|
|
|
|
const threefloat * tf = &tolerances.Get(pi);
|
|
|
|
|
|
|
|
return tf->f1 * dx * dx + tf->f2 * dx * dy + tf->f3 * dy * dy;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-09-29 19:22:00 +05:00
|
|
|
float netrule :: CalcLineError (int li, const Vec<2> & v) const
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
2019-09-29 19:22:00 +05:00
|
|
|
float dx = v[0] - linevecs.Get(li)[0];
|
|
|
|
float dy = v[1] - linevecs.Get(li)[1];
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
const threefloat * ltf = &linetolerances.Get(li);
|
|
|
|
return ltf->f1 * dx * dx + ltf->f2 * dx * dy + ltf->f3 * dy * dy;
|
|
|
|
}
|
2019-09-29 19:22:00 +05:00
|
|
|
} // namespace netgen
|