netgen/libsrc/stlgeom/stlgeomchart.cpp

845 lines
24 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
//20.11.1999 third part of stlgeom.cc, functions with chart and atlas
#include <mystdlib.h>
#include <myadt.hpp>
#include <linalg.hpp>
#include <gprim.hpp>
#include <meshing.hpp>
#include "stlgeom.hpp"
namespace netgen
{
int chartdebug = 0;
void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, const STLParameters& stlparam)
2009-01-13 04:40:13 +05:00
{
2019-09-26 18:22:06 +05:00
static Timer t("makeatlas"); RegionTimer reg(t);
static Timer tinner("find innner chart");
static Timer touter("find outer chart");
2018-03-09 03:47:58 +05:00
// int timer1 = NgProfiler::CreateTimer ("makeatlas");
/*
2017-11-24 01:26:23 +05:00
int timerb = NgProfiler::CreateTimer ("makeatlas - begin");
int timere = NgProfiler::CreateTimer ("makeatlas - end");
int timere1 = NgProfiler::CreateTimer ("makeatlas - end1");
int timere2 = NgProfiler::CreateTimer ("makeatlas - end2");
2012-10-19 14:42:19 +06:00
int timer2 = NgProfiler::CreateTimer ("makeatlas - part 2");
int timer3 = NgProfiler::CreateTimer ("makeatlas - part 3");
2014-04-28 13:07:36 +06:00
int timer4 = NgProfiler::CreateTimer ("makeatlas - part 4");
2017-11-24 01:26:23 +05:00
int timer4a = NgProfiler::CreateTimer ("makeatlas - part 4a");
int timer4b = NgProfiler::CreateTimer ("makeatlas - part 4b");
int timer4c = NgProfiler::CreateTimer ("makeatlas - part 4c");
int timer4d = NgProfiler::CreateTimer ("makeatlas - part 4d");
int timer4e = NgProfiler::CreateTimer ("makeatlas - part 4e");
2014-04-28 13:07:36 +06:00
int timer5 = NgProfiler::CreateTimer ("makeatlas - part 5");
int timer5a = NgProfiler::CreateTimer ("makeatlas - part 5a");
int timer5b = NgProfiler::CreateTimer ("makeatlas - part 5b");
int timer5cs = NgProfiler::CreateTimer ("makeatlas - part 5cs");
int timer5cl = NgProfiler::CreateTimer ("makeatlas - part 5cl");
*/
2009-01-13 04:40:13 +05:00
PushStatusF("Make Atlas");
2012-10-19 14:42:19 +06:00
double h = mparam.maxh;
2009-01-13 04:40:13 +05:00
double atlasminh = 5e-3 * Dist (boundingbox.PMin(), boundingbox.PMax());
PrintMessage(5, "atlasminh = ", atlasminh);
//speedup for make atlas
if (GetNT() > 50000)
2012-10-22 19:13:57 +06:00
mesh.SetGlobalH(min2 (0.05*Dist (boundingbox.PMin(), boundingbox.PMax()),
mparam.maxh));
2009-01-13 04:40:13 +05:00
atlas.SetSize(0);
ClearSpiralPoints();
BuildSmoothEdges();
// NgProfiler::StartTimer (timer1);
2009-01-13 04:40:13 +05:00
double chartangle = stlparam.chartangle;
double outerchartangle = stlparam.outerchartangle;
chartangle = chartangle/180.*M_PI;
outerchartangle = outerchartangle/180.*M_PI;
double coschartangle = cos(chartangle);
double cosouterchartangle = cos(outerchartangle);
double cosouterchartanglehalf = cos(0.5*outerchartangle);
double sinchartangle = sin(chartangle);
double sinouterchartangle = sin(outerchartangle);
2019-09-21 04:06:49 +05:00
Array<ChartId,STLTrigId> outermark(GetNT()); //marks all trigs form actual outer region
Array<ChartId,STLTrigId> outertested(GetNT()); //marks tested trigs for outer region
Array<ChartId,STLPointId> pointstochart(GetNP()); //point in chart becomes chartnum
Array<ChartId,STLPointId> innerpointstochart(GetNP()); //point in chart becomes chartnum
Array<STLPointId> chartpoints; //point in chart becomes chartnum
Array<STLPointId> innerchartpoints;
Array<Point<3>> innerchartpts;
2019-07-09 13:39:16 +05:00
NgArray<int> dirtycharttrigs;
NgArray<int> chartdistacttrigs (GetNT()); //outercharttrigs
2012-10-19 14:42:19 +06:00
chartdistacttrigs = 0;
2009-01-13 04:40:13 +05:00
STLBoundary chartbound(this); //knows the actual chart boundary
//int chartboundarydivisions = 10;
markedsegs.SetSize(0); //for testing!!!
NgArray<ChartId> chartpointchecked(GetNP()); //for dirty-chart-trigs
2009-01-13 04:40:13 +05:00
chartmark.SetSize(GetNT());
innerpointstochart = ChartId::INVALID;
pointstochart = ChartId::INVALID;
chartpointchecked = ChartId::INVALID;
2009-01-13 04:40:13 +05:00
double eps = 1e-12 * Dist (boundingbox.PMin(), boundingbox.PMax());
int spiralcheckon = stldoctor.spiralcheck;
if (!spiralcheckon) {PrintWarning("++++++++++++\nspiral deactivated by user!!!!\n+++++++++++++++"); }
chartmark = ChartId::INVALID;
outermark = ChartId::INVALID;
outertested = ChartId::INVALID;
2009-01-13 04:40:13 +05:00
double atlasarea = Area();
double workedarea = 0;
double showinc = 100.*5000./(double)GetNT();
double nextshow = 0;
2019-09-21 04:06:49 +05:00
STLTrigId lastunmarked = 1;
2009-01-13 04:40:13 +05:00
PrintMessage(5,"one dot per 5000 triangles: ");
size_t markedtrigcnt = 0;
2012-10-19 14:42:19 +06:00
while (markedtrigcnt < GetNT())
2017-11-24 01:26:23 +05:00
{
2012-10-19 14:42:19 +06:00
if (multithread.terminate) { PopStatus(); return; }
2009-01-13 04:40:13 +05:00
// NgProfiler::StartTimer (timerb);
2009-01-13 04:40:13 +05:00
if (workedarea / atlasarea*100. >= nextshow)
{PrintDot(); nextshow+=showinc;}
SetThreadPercent(100.0 * workedarea / atlasarea);
atlas.Append (make_unique<STLChart> (this, stlparam));
STLChart & chart = *atlas.Last();
2009-01-13 04:40:13 +05:00
//find unmarked trig
2019-09-21 04:06:49 +05:00
STLTrigId prelastunmarked = lastunmarked;
2012-10-22 19:13:57 +06:00
2012-10-19 14:42:19 +06:00
bool found = false;
2019-09-21 04:06:49 +05:00
for (STLTrigId j = lastunmarked; j <= GetNT(); j++)
2012-10-19 14:42:19 +06:00
if (!GetMarker(j))
{
found = true;
lastunmarked = j;
break;
}
2009-01-13 04:40:13 +05:00
chartpoints.SetSize(0);
innerchartpoints.SetSize(0);
innerchartpts.SetSize(0);
2009-01-13 04:40:13 +05:00
chartbound.Clear();
chartbound.SetChart(&chart);
2017-11-13 15:58:03 +05:00
2019-09-21 04:06:49 +05:00
if (!found) throw Exception("Make Atlas, no starttrig found");
2009-01-13 04:40:13 +05:00
//find surrounding trigs
2012-10-19 14:42:19 +06:00
// int starttrig = j;
2019-09-21 04:06:49 +05:00
STLTrigId starttrig = lastunmarked;
2009-01-13 04:40:13 +05:00
Point<3> startp = GetPoint(GetTriangle(starttrig)[0]);
2009-01-13 04:40:13 +05:00
bool accepted;
ChartId chartnum = GetNOCharts();
2009-01-13 04:40:13 +05:00
Vec<3> sn = GetTriangle(starttrig).Normal();
chart.SetNormal (startp, sn);
2014-04-28 13:07:36 +06:00
// *testout << "first trig " << starttrig << ", n = " << sn << endl;
2009-01-13 04:40:13 +05:00
SetMarker(starttrig, chartnum);
markedtrigcnt++;
chart.AddChartTrig(starttrig);
2009-01-13 04:40:13 +05:00
chartbound.AddTriangle(GetTriangle(starttrig));
workedarea += GetTriangle(starttrig).Area(points);
2019-09-21 04:06:49 +05:00
for (int i = 0; i < 3; i++)
{
STLPointId pi = GetTriangle(starttrig)[i];
innerpointstochart[pi] = chartnum;
pointstochart[pi] = chartnum;
chartpoints.Append(pi);
innerchartpoints.Append(pi);
2009-01-13 04:40:13 +05:00
}
2012-10-19 14:42:19 +06:00
bool changed = true;
2009-01-13 04:40:13 +05:00
int oldstartic = 1;
int oldstartic2;
// NgProfiler::StopTimer (timerb);
// NgProfiler::StartTimer (timer2);
2012-10-19 14:42:19 +06:00
2019-09-26 18:22:06 +05:00
tinner.Start();
2009-01-13 04:40:13 +05:00
while (changed)
{
2012-10-19 14:42:19 +06:00
changed = false;
2009-01-13 04:40:13 +05:00
oldstartic2 = oldstartic;
oldstartic = chart.GetNT();
2009-01-13 04:40:13 +05:00
// for (ic = oldstartic2; ic <= chart->GetNT(); ic++)
2012-10-19 14:42:19 +06:00
for (int ic = oldstartic2; ic <= oldstartic; ic++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId i = chart.GetTrig1(ic);
2009-01-13 04:40:13 +05:00
if (GetMarker(i) == chartnum)
{
2012-10-19 14:42:19 +06:00
for (int j = 1; j <= NONeighbourTrigs(i); j++)
2009-01-13 04:40:13 +05:00
{
2019-09-26 18:22:06 +05:00
STLTrigId nt = NeighbourTrig(i,j);
2014-04-28 13:07:36 +06:00
// *testout << "check trig " << nt << endl;
2019-09-21 05:04:35 +05:00
STLPointId np1, np2;
2009-01-13 04:40:13 +05:00
GetTriangle(i).GetNeighbourPoints(GetTriangle(nt),np1,np2);
if (GetMarker(nt) == 0 && !IsEdge(np1,np2))
{
2012-10-19 14:42:19 +06:00
Vec<3> n2 = GetTriangle(nt).Normal();
2014-04-28 13:07:36 +06:00
// *testout << "acos = " << 180/M_PI*acos (n2*sn) << endl;
2009-01-13 04:40:13 +05:00
if ( (n2 * sn) >= coschartangle )
{
2014-04-28 13:07:36 +06:00
// *testout << "good angle " << endl;
accepted = true;
2009-01-13 04:40:13 +05:00
/*
//alter spiralentest, schnell, aber ungenau
for (k = 1; k <= 3; k++)
{
//find overlapping charts:
Point3d pt = GetPoint(GetTriangle(nt).PNum(k));
if (innerpointstochart.Get(GetTriangle(nt).PNum(k)) != chartnum)
{
for (l = 1; l <= chartpoints.Size(); l++)
{
Vec3d vptpl(GetPoint(chartpoints.Get(l)), pt);
double vlen = vptpl.Length();
if (vlen > 0)
{
vptpl /= vlen;
if ( fabs( vptpl * sn) > sinchartangle )
{
accepted = 0;
break;
}
}
}
}
}
*/
2012-10-19 14:42:19 +06:00
//find overlapping charts exacter (fast, too):
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
2012-10-19 14:42:19 +06:00
int nnt = NeighbourTrig(nt,k);
2009-01-13 04:40:13 +05:00
if (GetMarker(nnt) != chartnum)
{
2019-09-21 05:04:35 +05:00
STLPointId nnp1, nnp2;
2009-01-13 04:40:13 +05:00
GetTriangle(nt).GetNeighbourPoints(GetTriangle(nnt),nnp1,nnp2);
accepted = chartbound.TestSeg(GetPoint(nnp1),
GetPoint(nnp2),
sn,sinchartangle,1 /*chartboundarydivisions*/ ,points, eps);
2014-04-28 13:07:36 +06:00
// if (!accepted) *testout << "not acc due to testseg" << endl;
2009-01-13 04:40:13 +05:00
2012-10-19 14:42:19 +06:00
Vec<3> n3 = GetTriangle(nnt).Normal();
2009-01-13 04:40:13 +05:00
if ( (n3 * sn) >= coschartangle &&
IsSmoothEdge (nnp1, nnp2) )
accepted = true;
2009-01-13 04:40:13 +05:00
}
2014-04-28 13:07:36 +06:00
if (!accepted)
break;
2009-01-13 04:40:13 +05:00
}
2019-09-22 16:15:53 +05:00
/*
// new check 2019-09-22
if (accepted)
{
auto & trig = GetTriangle(nt);
Point<3> p0 = GetPoint(trig[0]);
Point<3> p1 = GetPoint(trig[1]);
Point<3> p2 = GetPoint(trig[2]);
Point<3> p01 = Center(p0,p1);
Point<3> p02 = Center(p0,p2);
Point<3> p12 = Center(p1,p2);
Point<3> p012 = Center(p0,p1,p2);
p01 += 1e-5 * (p012-p01);
p02 += 1e-5 * (p012-p02);
p12 += 1e-5 * (p012-p12);
bool test1 = chartbound.TestSegChartNV(p01,p012,sn);
bool test2 = chartbound.TestSegChartNV(p02,p012,sn);
bool test3 = chartbound.TestSegChartNV(p12,p012,sn);
if (!test1 || !test2 || !test3)
{
cout << "more stringent" << endl;
accepted = false;
}
}
*/
2014-04-28 13:07:36 +06:00
2009-01-13 04:40:13 +05:00
if (accepted)
{
2014-04-28 13:07:36 +06:00
// *testout << "trig accepted" << endl;
2009-01-13 04:40:13 +05:00
SetMarker(nt, chartnum);
2012-10-19 14:42:19 +06:00
changed = true;
2009-01-13 04:40:13 +05:00
markedtrigcnt++;
workedarea += GetTriangle(nt).Area(points);
chart.AddChartTrig(nt);
2009-01-13 04:40:13 +05:00
chartbound.AddTriangle(GetTriangle(nt));
2012-10-19 14:42:19 +06:00
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
2019-09-22 16:15:53 +05:00
STLPointId pi = GetTriangle(nt).PNum(k);
if (innerpointstochart[pi] != chartnum)
2009-01-13 04:40:13 +05:00
{
2019-09-22 16:15:53 +05:00
innerpointstochart[pi] = chartnum;
pointstochart[pi] = chartnum;
chartpoints.Append(pi);
innerchartpoints.Append(pi);
2009-01-13 04:40:13 +05:00
}
}
}
}
}
}
}
}
}
2019-09-26 18:22:06 +05:00
tinner.Stop();
innerchartpts.SetSize(innerchartpoints.Size());
for (size_t i = 0; i < innerchartpoints.Size(); i++)
innerchartpts[i] = GetPoint(innerchartpoints[i]);
// NgProfiler::StopTimer (timer2);
// NgProfiler::StartTimer (timer3);
2009-01-13 04:40:13 +05:00
//find outertrigs
// chartbound.Clear();
// warum, ic-bound auf edge macht Probleme js ???
2019-09-26 18:22:06 +05:00
touter.Start();
2019-09-21 04:06:49 +05:00
outermark[starttrig] = chartnum;
2009-01-13 04:40:13 +05:00
//chart->AddOuterTrig(starttrig);
2012-10-19 14:42:19 +06:00
changed = true;
2009-01-13 04:40:13 +05:00
oldstartic = 1;
while (changed)
{
2012-10-19 14:42:19 +06:00
changed = false;
2009-01-13 04:40:13 +05:00
oldstartic2 = oldstartic;
oldstartic = chart.GetNT();
2009-01-13 04:40:13 +05:00
2012-10-19 14:42:19 +06:00
for (int ic = oldstartic2; ic <= oldstartic; ic++)
{
2019-09-21 04:06:49 +05:00
STLTrigId i = chart.GetTrig1(ic);
if (outermark[i] != chartnum) continue;
2012-10-19 14:42:19 +06:00
for (int j = 1; j <= NONeighbourTrigs(i); j++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId nt = NeighbourTrig(i,j);
if (outermark[nt] == chartnum) continue;
2012-10-19 14:42:19 +06:00
const STLTriangle & ntrig = GetTriangle(nt);
2019-09-21 05:04:35 +05:00
STLPointId np1, np2;
2012-10-19 14:42:19 +06:00
GetTriangle(i).GetNeighbourPoints(GetTriangle(nt),np1,np2);
if (IsEdge (np1, np2)) continue;
/*
if (outertested.Get(nt) == chartnum)
continue;
*/
2019-09-21 04:06:49 +05:00
outertested[nt] = chartnum;
2012-10-19 14:42:19 +06:00
Vec<3> n2 = GetTriangle(nt).Normal();
2012-10-22 19:13:57 +06:00
2012-10-19 14:42:19 +06:00
//abfragen, ob noch im tolerierten Winkel
if ( (n2 * sn) >= cosouterchartangle )
2009-01-13 04:40:13 +05:00
{
accepted = true;
2012-10-19 14:42:19 +06:00
// NgProfiler::StartTimer (timer4);
2012-10-19 14:42:19 +06:00
bool isdirtytrig = false;
Vec<3> gn = GetTriangle(nt).GeomNormal(points);
double gnlen = gn.Length();
if (n2 * gn <= cosouterchartanglehalf * gnlen)
isdirtytrig = true;
//zurueckweisen, falls eine Spiralartige outerchart entsteht
//find overlapping charts exacter:
//do not check dirty trigs!
// NgProfiler::StartTimer (timer4a);
2017-11-24 01:26:23 +05:00
2012-10-19 14:42:19 +06:00
if (spiralcheckon && !isdirtytrig)
for (int k = 1; k <= 3; k++)
2017-11-24 01:26:23 +05:00
{
// NgProfiler::StartTimer (timer4b);
2019-09-21 04:06:49 +05:00
STLTrigId nnt = NeighbourTrig(nt,k);
2009-01-13 04:40:13 +05:00
2019-09-21 04:06:49 +05:00
if (outermark[nnt] != chartnum)
2012-10-19 14:42:19 +06:00
{
// NgProfiler::StartTimer (timer4c);
2019-09-21 05:04:35 +05:00
STLPointId nnp1, nnp2;
2012-10-19 14:42:19 +06:00
GetTriangle(nt).GetNeighbourPoints(GetTriangle(nnt),nnp1,nnp2);
// NgProfiler::StopTimer (timer4c);
2012-10-19 14:42:19 +06:00
// NgProfiler::StartTimer (timer4d);
2014-04-28 13:07:36 +06:00
2012-10-19 14:42:19 +06:00
accepted =
chartbound.TestSeg(GetPoint(nnp1),GetPoint(nnp2),
sn,sinouterchartangle, 0 /*chartboundarydivisions*/ ,points, eps);
// NgProfiler::StopTimer (timer4d);
2014-04-28 13:07:36 +06:00
// NgProfiler::StartTimer (timer4e);
2014-04-28 13:07:36 +06:00
2012-10-19 14:42:19 +06:00
Vec<3> n3 = GetTriangle(nnt).Normal();
if ( (n3 * sn) >= cosouterchartangle &&
IsSmoothEdge (nnp1, nnp2) )
accepted = true;
// NgProfiler::StopTimer (timer4e);
2012-10-19 14:42:19 +06:00
}
2017-11-24 01:26:23 +05:00
// NgProfiler::StopTimer (timer4b);
2012-10-19 14:42:19 +06:00
if (!accepted) break;
}
// NgProfiler::StopTimer (timer4a);
2012-10-19 14:42:19 +06:00
// NgProfiler::StopTimer (timer4);
2014-04-28 13:07:36 +06:00
// NgProfiler::RegionTimer reg5(timer5);
2014-04-28 13:07:36 +06:00
2012-10-19 14:42:19 +06:00
// outer chart is only small environment of
// inner chart:
if (accepted)
2009-01-13 04:40:13 +05:00
{
// NgProfiler::StartTimer (timer5a);
accepted = false;
2009-01-13 04:40:13 +05:00
2012-10-19 14:42:19 +06:00
for (int k = 1; k <= 3; k++)
2019-09-21 04:06:49 +05:00
if (innerpointstochart[ntrig.PNum(k)] == chartnum)
2012-10-19 14:42:19 +06:00
{
accepted = true;
2012-10-19 14:42:19 +06:00
break;
}
// NgProfiler::StopTimer (timer5a);
// int timer5csl = (innerchartpts.Size() < 100) ? timer5cs : timer5cl;
// NgProfiler::StartTimer (timer5csl);
2009-01-13 04:40:13 +05:00
2012-10-19 14:42:19 +06:00
if (!accepted)
for (int k = 1; k <= 3; k++)
{
Point<3> pt = GetPoint(ntrig.PNum(k));
double h2 = sqr(mesh.GetH(pt));
/*
for (int l = 1; l <= innerchartpoints.Size(); l++)
{
double tdist = Dist2(pt, GetPoint (innerchartpoints.Get(l)));
if (tdist < 4 * h2)
{
accepted = 1;
break;
}
}
*/
for (int l = 0; l < innerchartpts.Size(); l++)
2009-01-13 04:40:13 +05:00
{
double tdist = Dist2(pt, innerchartpts[l]);
2012-10-19 14:42:19 +06:00
if (tdist < 4 * h2)
{
accepted = true;
2012-10-19 14:42:19 +06:00
break;
}
2009-01-13 04:40:13 +05:00
}
2012-10-19 14:42:19 +06:00
if (accepted) break;
2009-01-13 04:40:13 +05:00
}
// NgProfiler::StopTimer (timer5csl);
2012-10-19 14:42:19 +06:00
}
// NgProfiler::StartTimer (timer5b);
2009-01-13 04:40:13 +05:00
2012-10-19 14:42:19 +06:00
if (accepted)
{
changed = true;
2019-09-21 04:06:49 +05:00
outermark[nt] = chartnum;
2012-10-19 14:42:19 +06:00
if (GetMarker(nt) != chartnum)
2009-01-13 04:40:13 +05:00
{
2012-10-19 14:42:19 +06:00
chartbound.AddTriangle(GetTriangle(nt));
chart.AddOuterTrig(nt);
2012-10-19 14:42:19 +06:00
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
if (pointstochart[GetTriangle(nt).PNum(k)]
2012-10-19 14:42:19 +06:00
!= chartnum)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
pointstochart[GetTriangle(nt).PNum(k)] = chartnum;
2012-10-19 14:42:19 +06:00
chartpoints.Append(GetTriangle(nt).PNum(k));
2009-01-13 04:40:13 +05:00
}
}
}
2012-10-19 14:42:19 +06:00
}
// NgProfiler::StopTimer (timer5b);
2012-10-19 14:42:19 +06:00
}
}
}
}
2019-09-26 18:22:06 +05:00
touter.Stop();
// NgProfiler::StopTimer (timer3);
// NgProfiler::StartTimer (timere);
// NgProfiler::StartTimer (timere1);
2009-01-13 04:40:13 +05:00
//end of while loop for outer chart
GetDirtyChartTrigs(chartnum, chart, outermark, chartpointchecked, dirtycharttrigs);
2009-01-13 04:40:13 +05:00
//dirtycharttrigs are local (chart) point numbers!!!!!!!!!!!!!!!!
if (dirtycharttrigs.Size() != 0 &&
(dirtycharttrigs.Size() != chart.GetNChartT() || dirtycharttrigs.Size() != 1))
2009-01-13 04:40:13 +05:00
{
if (dirtycharttrigs.Size() == chart.GetNChartT() && dirtycharttrigs.Size() != 1)
2009-01-13 04:40:13 +05:00
{
//if all trigs would be eliminated -> leave 1 trig!
dirtycharttrigs.SetSize(dirtycharttrigs.Size() - 1);
}
2012-10-19 14:42:19 +06:00
for (int k = 1; k <= dirtycharttrigs.Size(); k++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId tn = chart.GetChartTrig1(dirtycharttrigs.Get(k));
outermark[tn] = 0; //not necessary, for later use
2009-01-13 04:40:13 +05:00
SetMarker(tn, 0);
markedtrigcnt--;
workedarea -= GetTriangle(tn).Area(points);
}
chart.MoveToOuterChart(dirtycharttrigs);
2009-01-13 04:40:13 +05:00
lastunmarked = 1;
lastunmarked = prelastunmarked;
}
2017-11-13 15:58:03 +05:00
chartbound.DeleteSearchTree();
2017-11-24 01:26:23 +05:00
// NgProfiler::StopTimer (timere1);
// NgProfiler::StartTimer (timere2);
2017-11-24 01:26:23 +05:00
2017-11-13 15:58:03 +05:00
// cout << "key" << endl;
// char key;
// cin >> key;
2012-10-22 19:13:57 +06:00
//calculate an estimate meshsize, not to produce too large outercharts, with factor 2 larger!
RestrictHChartDistOneChart(chartnum, chartdistacttrigs, mesh, h, 0.5, atlasminh, stlparam);
2012-10-22 19:13:57 +06:00
// NgProfiler::Print(stdout);
// NgProfiler::StopTimer (timere2);
2017-11-24 01:26:23 +05:00
// NgProfiler::StopTimer (timere);
2017-11-24 01:26:23 +05:00
2009-01-13 04:40:13 +05:00
}
// NgProfiler::StopTimer (timer1);
2012-11-13 21:54:16 +06:00
// NgProfiler::Print(stdout);
2012-10-19 14:42:19 +06:00
2009-01-13 04:40:13 +05:00
PrintMessage(5,"");
PrintMessage(5,"NO charts=", atlas.Size());
int cnttrias = 0;
outerchartspertrig.SetSize(GetNT());
// for (int i = 1; i <= atlas.Size(); i++)
for (ChartId i : atlas.Range())
2009-01-13 04:40:13 +05:00
{
2012-10-19 14:42:19 +06:00
for (int j = 1; j <= GetChart(i).GetNT(); j++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId tn = GetChart(i).GetTrig1(j);
2009-01-13 04:40:13 +05:00
AddOCPT(tn,i);
}
cnttrias += GetChart(i).GetNT();
}
PrintMessage(5, "NO outer chart trias=", cnttrias);
//sort outerchartspertrig
2012-10-19 14:42:19 +06:00
for (int i = 1; i <= GetNT(); i++)
2009-01-13 04:40:13 +05:00
{
2012-10-19 14:42:19 +06:00
for (int k = 1; k < GetNOCPT(i); k++)
for (int j = 1; j < GetNOCPT(i); j++)
{
int swap = GetOCPT(i,j);
if (GetOCPT(i,j+1) < swap)
{
SetOCPT(i,j,GetOCPT(i,j+1));
SetOCPT(i,j+1,swap);
}
}
2009-01-13 04:40:13 +05:00
// check make atlas
if (GetChartNr(i) <= 0 || GetChartNr(i) > GetNOCharts())
2012-10-19 14:42:19 +06:00
PrintSysError("Make Atlas: chartnr(", i, ")=0!!");
2009-01-13 04:40:13 +05:00
}
mesh.SetGlobalH(mparam.maxh);
mesh.SetMinimalH(mparam.minh);
AddConeAndSpiralEdges(stlparam);
2009-01-13 04:40:13 +05:00
PrintMessage(5,"Make Atlas finished");
2019-09-30 21:14:46 +05:00
for (auto & chart : atlas)
chart->BuildInnerSearchTree();
2009-01-13 04:40:13 +05:00
PopStatus();
}
int STLGeometry::TrigIsInOC(int tn, int ocn) const
{
if (tn < 1 || tn > GetNT())
{
// assert (1);
abort ();
PrintSysError("STLGeometry::TrigIsInOC illegal tn: ", tn);
return 0;
}
/*
int firstval = 0;
int i;
for (i = 1; i <= GetNOCPT(tn); i++)
{
if (GetOCPT(tn, i) == ocn) {firstval = 1;}
}
*/
int found = 0;
int inc = 1;
while (inc <= GetNOCPT(tn)) {inc *= 2;}
inc /= 2;
int start = inc;
while (!found && inc > 0)
{
if (GetOCPT(tn,start) > ocn) {inc = inc/2; start -= inc;}
else if (GetOCPT(tn,start) < ocn) {inc = inc/2; if (start+inc <= GetNOCPT(tn)) {start += inc;}}
else {found = 1;}
}
return GetOCPT(tn, start) == ocn;
}
2019-09-21 04:06:49 +05:00
ChartId STLGeometry :: GetChartNr(STLTrigId i) const
2009-01-13 04:40:13 +05:00
{
if (i > chartmark.Size())
{
2019-09-21 04:06:49 +05:00
PrintSysError("GetChartNr(", int(i), ") not possible!!!");
2009-01-13 04:40:13 +05:00
i = 1;
}
2019-09-21 04:06:49 +05:00
return chartmark[i];
2009-01-13 04:40:13 +05:00
}
/*
int STLGeometry :: GetMarker(int i) const
{
return chartmark.Get(i);
}
*/
2019-09-21 04:06:49 +05:00
void STLGeometry :: SetMarker(STLTrigId nr, ChartId m)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
chartmark[nr] = m;
2009-01-13 04:40:13 +05:00
}
int STLGeometry :: AtlasMade() const
{
return chartmark.Size() != 0;
}
2012-10-22 19:13:57 +06:00
/*
2009-01-13 04:40:13 +05:00
//return 1 if not exists
2019-07-09 13:39:16 +05:00
int AddIfNotExists(NgArray<int>& list, int x)
2009-01-13 04:40:13 +05:00
{
int i;
for (i = 1; i <= list.Size(); i++)
{
if (list.Get(i) == x) {return 0;}
}
list.Append(x);
return 1;
}
2012-10-22 19:13:57 +06:00
*/
2009-01-13 04:40:13 +05:00
void STLGeometry :: GetInnerChartLimes(NgArray<twoint>& limes, ChartId chartnum)
2009-01-13 04:40:13 +05:00
{
2019-09-21 05:04:35 +05:00
STLPointId np1, np2;
2009-01-13 04:40:13 +05:00
limes.SetSize(0);
STLChart& chart = GetChart(chartnum);
2019-09-21 04:06:49 +05:00
for (int j = 1; j <= chart.GetNChartT(); j++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId t = chart.GetChartTrig1(j);
2009-01-13 04:40:13 +05:00
const STLTriangle& tt = GetTriangle(t);
2019-09-21 04:06:49 +05:00
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId nt = NeighbourTrig(t,k);
2009-01-13 04:40:13 +05:00
if (GetChartNr(nt) != chartnum)
{
tt.GetNeighbourPoints(GetTriangle(nt),np1,np2);
if (!IsEdge(np1,np2))
{
limes.Append(twoint(np1,np2));
/*
p3p1 = GetPoint(np1);
p3p2 = GetPoint(np2);
if (AddIfNotExists(limes,np1))
{
plimes1.Append(p3p1);
//plimes1trigs.Append(t);
//plimes1origin.Append(np1);
}
if (AddIfNotExists(limes1,np2))
{
plimes1.Append(p3p2);
//plimes1trigs.Append(t);
//plimes1origin.Append(np2);
}
//chart.AddILimit(twoint(np1,np2));
for (int di = 1; di <= divisions; di++)
{
double f1 = (double)di/(double)(divisions+1.);
double f2 = (divisions+1.-(double)di)/(double)(divisions+1.);
plimes1.Append(Point3d(p3p1.X()*f1+p3p2.X()*f2,
p3p1.Y()*f1+p3p2.Y()*f2,
p3p1.Z()*f1+p3p2.Z()*f2));
//plimes1trigs.Append(t);
//plimes1origin.Append(0);
}
*/
}
}
}
}
}
void STLGeometry :: GetDirtyChartTrigs(int chartnum, STLChart& chart,
2019-09-21 04:06:49 +05:00
const Array<ChartId,STLTrigId>& outercharttrigs,
NgArray<ChartId>& chartpointchecked,
2019-07-09 13:39:16 +05:00
NgArray<int>& dirtytrigs)
2009-01-13 04:40:13 +05:00
{
dirtytrigs.SetSize(0);
2019-09-21 04:06:49 +05:00
2009-01-13 04:40:13 +05:00
int cnt = 0;
2019-09-21 04:06:49 +05:00
for (int j = 1; j <= chart.GetNChartT(); j++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId t = chart.GetChartTrig1(j);
2009-01-13 04:40:13 +05:00
const STLTriangle& tt = GetTriangle(t);
2019-09-21 04:06:49 +05:00
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId nt = NeighbourTrig(t,k);
if (GetChartNr(nt) != chartnum && outercharttrigs[nt] != chartnum)
{
2019-09-21 05:04:35 +05:00
STLPointId np1, np2;
2009-01-13 04:40:13 +05:00
tt.GetNeighbourPoints(GetTriangle(nt),np1,np2);
if (!IsEdge(np1,np2))
{
dirtytrigs.Append(j); //local numbers!!!
cnt++;
break; //only once per trig!!!
}
}
}
}
cnt = 0;
2019-09-21 05:04:35 +05:00
STLPointId ap1, ap2, pn;
Array<STLTrigId> trigsaroundp;
2009-01-13 04:40:13 +05:00
2019-09-21 04:06:49 +05:00
for (int j = chart.GetNChartT(); j >= 1; j--)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
STLTrigId t = chart.GetChartTrig1(j);
2009-01-13 04:40:13 +05:00
const STLTriangle& tt = GetTriangle(t);
2019-09-21 04:06:49 +05:00
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
pn = tt.PNum(k);
//if (chartpointchecked.Get(pn) == chartnum)
//{continue;}
int checkpoint = 0;
2019-09-21 04:06:49 +05:00
for (int n = 1; n <= trigsperpoint.EntrySize(pn); n++)
2009-01-13 04:40:13 +05:00
{
if (trigsperpoint.Get(pn,n) != t && //ueberfluessig???
GetChartNr(trigsperpoint.Get(pn,n)) != chartnum &&
2019-09-21 04:06:49 +05:00
outercharttrigs[trigsperpoint.Get(pn,n)] != chartnum) {checkpoint = 1;};
2009-01-13 04:40:13 +05:00
}
if (checkpoint)
{
chartpointchecked.Elem(pn) = chartnum;
GetSortedTrianglesAroundPoint(pn,t,trigsaroundp);
trigsaroundp.Append(t); //ring
2019-09-21 05:04:35 +05:00
bool problem = false;
2009-01-13 04:40:13 +05:00
//forward:
2019-09-21 05:04:35 +05:00
for (int l = 2; l <= trigsaroundp.Size()-1; l++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 05:04:35 +05:00
STLTrigId tn1 = trigsaroundp[l-2];
STLTrigId tn2 = trigsaroundp[l-1];
2009-01-13 04:40:13 +05:00
const STLTriangle& t1 = GetTriangle(tn1);
const STLTriangle& t2 = GetTriangle(tn2);
t1.GetNeighbourPoints(t2, ap1, ap2);
if (IsEdge(ap1,ap2)) break;
2019-09-21 05:04:35 +05:00
if (GetChartNr(tn2) != chartnum && outercharttrigs[tn2] != chartnum) {problem = true;}
2009-01-13 04:40:13 +05:00
}
//backwards:
2019-09-21 05:04:35 +05:00
for (int l = trigsaroundp.Size()-1; l >= 2; l--)
2009-01-13 04:40:13 +05:00
{
2019-09-21 05:04:35 +05:00
STLTrigId tn1 = trigsaroundp[l];
STLTrigId tn2 = trigsaroundp[l-1];
2009-01-13 04:40:13 +05:00
const STLTriangle& t1 = GetTriangle(tn1);
const STLTriangle& t2 = GetTriangle(tn2);
t1.GetNeighbourPoints(t2, ap1, ap2);
if (IsEdge(ap1,ap2)) break;
2019-09-21 05:04:35 +05:00
if (GetChartNr(tn2) != chartnum && outercharttrigs[tn2] != chartnum) {problem = true;}
2009-01-13 04:40:13 +05:00
}
2018-07-29 15:03:56 +05:00
// if (problem && !IsInArray(j,dirtytrigs))
if (problem && !dirtytrigs.Contains(j))
2009-01-13 04:40:13 +05:00
{
dirtytrigs.Append(j);
cnt++;
break; //only once per triangle
}
}
}
}
}
}