netgen/libsrc/stlgeom/stltool.hpp

332 lines
9.2 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#ifndef FILE_STLTOOL
#define FILE_STLTOOL
//#include "gprim/gprim.hh"
/**************************************************************************/
/* File: stlgeom.hh */
/* Author: Joachim Schoeberl */
/* Author2: Johannes Gerstmayr */
/* Date: 20. Nov. 99 */
/**************************************************************************/
namespace netgen {
2009-01-13 04:40:13 +05:00
// use one normal vector for whole chart
extern int usechartnormal;
extern int chartdebug;
extern int geomsearchtreeon;
2019-07-09 13:39:16 +05:00
extern int AddPointIfNotExists(NgArray<Point3d>& ap, const Point3d& p, double eps = 1e-8);
2009-01-13 04:40:13 +05:00
//get distance from line lp1-lp2 to point p
extern double GetDistFromLine(const Point<3>& lp1, const Point<3>& lp2, Point<3>& p);
extern double GetDistFromInfiniteLine(const Point<3>& lp1, const Point<3>& lp2, const Point<3>& p);
extern void FIOReadInt(istream& ios, int& i);
extern void FIOWriteInt(ostream& ios, const int& i);
extern void FIOReadDouble(istream& ios, double& i);
extern void FIOWriteDouble(ostream& ios, const double& i);
extern void FIOReadFloat(istream& ios, float& i);
extern void FIOWriteFloat(ostream& ios, const float& i);
extern void FIOReadString(istream& ios, char* str, int len);
extern void FIOReadStringE(istream& ios, char* str, int len);
extern void FIOWriteString(ostream& ios, char* str, int len);
2019-07-09 13:39:16 +05:00
typedef NgArray <int> * ArrayINTPTR;
2009-01-13 04:40:13 +05:00
class STLGeometry;
class STLParameters;
2009-01-13 04:40:13 +05:00
// typedef int ChartId
class ChartId
{
int i;
public:
class t_invalid { public: constexpr t_invalid() = default; };
static constexpr t_invalid INVALID{};
ChartId() { }
constexpr ChartId(t_invalid inv) : i(0) { ; }
constexpr ChartId(int ai) : i(ai) { }
operator int() const { return i; }
ChartId operator++ (int) { ChartId hi(*this); i++; return hi; }
ChartId & operator++ () { i++; return *this; }
};
}
namespace ngcore
{
template<>
constexpr netgen::ChartId IndexBASE<netgen::ChartId> () { return netgen::ChartId(1); }
}
namespace netgen {
2009-01-13 04:40:13 +05:00
class STLChart
{
private:
STLGeometry * geometry;
2019-09-21 04:06:49 +05:00
Array<STLTrigId> charttrigs; // trigs which only belong to this chart
Array<STLTrigId> outertrigs; // trigs which belong to other charts
BoxTree<3,STLTrigId> * searchtree; // ADT containing outer trigs
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<twoint> olimit; //outer limit of outer chart
NgArray<twoint> ilimit; //outer limit of inner chart
const STLParameters& stlparam;
2009-01-13 04:40:13 +05:00
public:
STLChart(STLGeometry * ageometry, const STLParameters& astlparam);
2018-07-29 15:03:56 +05:00
~STLChart();
2019-09-21 04:06:49 +05:00
void AddChartTrig(STLTrigId i);
void AddOuterTrig(STLTrigId i);
2009-01-13 04:40:13 +05:00
bool IsInWholeChart(int nr) const;
2009-01-13 04:40:13 +05:00
2019-09-21 04:06:49 +05:00
STLTrigId GetChartTrig1(int i) const {return charttrigs[i-1];}
STLTrigId GetOuterTrig1(int i) const {return outertrigs[i-1];}
2009-01-13 04:40:13 +05:00
//get all trigs:
2019-09-21 04:06:49 +05:00
STLTrigId GetTrig1(int i) const
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
if (i <= charttrigs.Size()) {return charttrigs[i-1];}
else {return outertrigs[i-charttrigs.Size()-1];}
2009-01-13 04:40:13 +05:00
}
2019-09-21 04:06:49 +05:00
size_t GetNChartT() const {return charttrigs.Size();}
size_t GetNOuterT() const {return outertrigs.Size();}
size_t GetNT() const {return charttrigs.Size()+outertrigs.Size(); }
2009-01-13 04:40:13 +05:00
void GetTrianglesInBox (const Point3d & pmin,
const Point3d & pmax,
2019-09-21 04:06:49 +05:00
NgArray<STLTrigId> & trias) const;
2018-07-29 15:03:56 +05:00
void AddOLimit(twoint l) {olimit.Append(l);}
void AddILimit(twoint l) {ilimit.Append(l);}
2009-01-13 04:40:13 +05:00
2018-07-29 15:03:56 +05:00
void ClearOLimit() {olimit.SetSize(0);}
void ClearILimit() {ilimit.SetSize(0);}
2009-01-13 04:40:13 +05:00
2019-09-21 04:06:49 +05:00
size_t GetNOLimit() const {return olimit.Size();}
size_t GetNILimit() const {return ilimit.Size();}
2009-01-13 04:40:13 +05:00
2018-07-29 15:03:56 +05:00
twoint GetOLimit(int i) const {return olimit.Get(i);}
twoint GetILimit(int i) const {return ilimit.Get(i);}
2009-01-13 04:40:13 +05:00
//move triangles trigs (local chart-trig numbers) to outer chart
2019-07-09 13:39:16 +05:00
void MoveToOuterChart(const NgArray<int>& trigs);
void DelChartTrigs(const NgArray<int>& trigs);
2009-01-13 04:40:13 +05:00
// define local coordinate system, JS:
private:
Vec<3> normal;
Point<3> pref;
Vec<3> t1, t2;
unique_ptr<BoxTree<2,STLTrigId>> inner_searchtree;
2009-01-13 04:40:13 +05:00
public:
void SetNormal (const Point<3> & apref, const Vec<3> & anormal);
const Vec<3> & GetNormal () const { return normal; }
2014-04-28 13:14:34 +06:00
Point<2> Project2d (const Point<3> & p3d) const
{
Vec<3> v = p3d-pref;
return Point<2> (t1 * v, t2 * v);
}
2019-09-30 21:14:46 +05:00
void BuildInnerSearchTree();
STLTrigId ProjectNormal (Point<3> & p) const;
2009-01-13 04:40:13 +05:00
};
class STLBoundarySeg
{
Point<3> p1, p2, center;
Point<2> p2d1, p2d2;
Box<2> boundingbox;
double rad;
STLPointId i1, i2;
2019-09-24 13:14:52 +05:00
bool smoothedge;
2009-01-13 04:40:13 +05:00
public:
STLBoundarySeg () { ; }
STLBoundarySeg (STLPointId ai1, STLPointId ai2, const Array<Point<3>,STLPointId> & points,
2014-04-28 13:14:34 +06:00
const STLChart * chart)
: p1(points[ai1]), p2(points[ai2]),
2014-04-28 13:14:34 +06:00
i1(ai1), i2(ai2)
{
center = ::netgen::Center (p1, p2);
rad = Dist (p1, center);
p2d1 = chart->Project2d (p1);
p2d2 = chart->Project2d (p2);
boundingbox.Set (p2d1);
boundingbox.Add (p2d2);
}
2009-01-13 04:40:13 +05:00
int operator== (const STLBoundarySeg & s2) const
{ return i1 == s2.i1 && i2 == s2.i2; }
void Swap ();
2019-09-22 16:15:53 +05:00
STLPointId I1() const { return i1; }
STLPointId I2() const { return i2; }
2009-01-13 04:40:13 +05:00
const Point<3> & P1() const { return p1; }
const Point<3> & P2() const { return p2; }
const Point<2> & P2D1() const { return p2d1; }
const Point<2> & P2D2() const { return p2d2; }
const Point<2> & P2DMin() const { return boundingbox.PMin(); }
const Point<2> & P2DMax() const { return boundingbox.PMax(); }
const Point<3> & Center() const { return center; }
const Box<2> & BoundingBox() const { return boundingbox; }
double Radius () const { return rad; }
2019-09-24 13:14:52 +05:00
void SetSmoothEdge (bool se) { smoothedge = se; }
bool IsSmoothEdge () const { return smoothedge; }
2009-01-13 04:40:13 +05:00
friend class STLBoundary;
};
class STLBoundary
{
private:
STLGeometry * geometry;
const STLChart * chart;
// NgArray<STLBoundarySeg> boundary;
2017-11-13 15:58:03 +05:00
ClosedHashTable<INDEX_2, STLBoundarySeg> boundary_ht;
2019-10-01 14:23:22 +05:00
unique_ptr<BoxTree<2,INDEX_2>> searchtree;
2009-01-13 04:40:13 +05:00
public:
STLBoundary(STLGeometry * ageometry);
2019-10-01 14:23:22 +05:00
~STLBoundary() {}
2009-01-13 04:40:13 +05:00
void Clear() { /* boundary.SetSize(0); */ boundary_ht = ClosedHashTable<INDEX_2,STLBoundarySeg>(); }
2009-01-13 04:40:13 +05:00
void SetChart (const STLChart * achart) { chart = achart; }
//don't check, if already exists!
// void AddNewSegment(const STLBoundarySeg & seg) {boundary.Append(seg);};
2009-01-13 04:40:13 +05:00
//check if segment exists
// void AddOrDelSegment(const STLBoundarySeg & seg);
2009-01-13 04:40:13 +05:00
//addordelsegment for all 3 triangle segments!
void AddTriangle(const STLTriangle & t);
int NOSegments() {return boundary_ht.UsedElements();};
// const STLBoundarySeg & GetSegment(int i) {return boundary.Get(i);}
2009-01-13 04:40:13 +05:00
void BuildSearchTree();
void DeleteSearchTree();
bool TestSeg(const Point<3> & p1, const Point<3> & p2, const Vec<3> & sn,
double sinchartangle, int divisions, Array<Point<3>,STLPointId>& points,
double eps);
bool TestSegChartNV(const Point3d& p1, const Point3d& p2, const Vec3d& sn);
2009-01-13 04:40:13 +05:00
};
class STLDoctorParams
{
public:
int drawmeshededges;
double geom_tol_fact;
double longlinefact;
int showexcluded;
int selectmode; //0==trig, 1==edge, 2==point, 3==multiedge, 4==line cluster
int edgeselectmode;
int useexternaledges;
int showfaces;
int showedgecornerpoints;
int showtouchedtrigchart;
int conecheck;
int spiralcheck;
int selecttrig;
int nodeofseltrig;
int selectwithmouse;
int showmarkedtrigs;
double dirtytrigfact;
double smoothangle;
double smoothnormalsweight;
int showvicinity;
int vicinity;
///
STLDoctorParams();
///
void Print (ostream & ost) const;
};
2015-10-19 13:08:30 +05:00
DLL_HEADER extern STLDoctorParams stldoctor;
2009-01-13 04:40:13 +05:00
// TODO change enable flag to optional parameters
2019-08-06 23:03:17 +05:00
class DLL_HEADER STLParameters
2009-01-13 04:40:13 +05:00
{
public:
/// angle for edge detection
double yangle = 30.;
double contyangle = 20.; //edges continued with contyangle
2009-01-13 04:40:13 +05:00
/// angle of geometry edge at which the mesher should set a point
double edgecornerangle = 60.;
2009-01-13 04:40:13 +05:00
/// angle inside on chart
double chartangle = 15.;
2009-01-13 04:40:13 +05:00
/// angle for overlapping parts of char
double outerchartangle = 70.;
2009-01-13 04:40:13 +05:00
/// 0 .. no, 1 .. local, (2 .. global)
int usesearchtree = 0;
2009-01-13 04:40:13 +05:00
///
double resthatlasfac = 2.;
bool resthatlasenable = true;
double atlasminh = 0.1;
2009-01-13 04:40:13 +05:00
double resthsurfcurvfac = 2.;
bool resthsurfcurvenable = false;
2009-01-13 04:40:13 +05:00
double resthchartdistfac = 1.2;
bool resthchartdistenable = true;
2009-01-13 04:40:13 +05:00
double resthcloseedgefac = 1.;
bool resthcloseedgeenable = true;
2009-01-13 04:40:13 +05:00
double resthedgeanglefac = 1.;
bool resthedgeangleenable = false;
2009-01-13 04:40:13 +05:00
double resthsurfmeshcurvfac = 1.;
bool resthsurfmeshcurvenable = false;
2009-01-13 04:40:13 +05:00
double resthlinelengthfac = 0.5;
bool resthlinelengthenable = true;
2009-01-13 04:40:13 +05:00
///
bool recalc_h_opt = true;
2009-01-13 04:40:13 +05:00
///
STLParameters();
///
void Print (ostream & ost) const;
};
inline ostream & operator<< (ostream & ost, const STLParameters & stlparam)
{
stlparam.Print (ost);
return ost;
}
2009-01-13 04:40:13 +05:00
void STLMeshing (STLGeometry & geom,
Mesh & mesh,
const MeshingParameters& mparam,
const STLParameters& stlpar);
2009-01-13 04:40:13 +05:00
int STLSurfaceMeshing (STLGeometry & geom,
Mesh & mesh,
const MeshingParameters& mparam,
const STLParameters& stlpar);
2009-01-13 04:40:13 +05:00
void STLSurfaceOptimization (STLGeometry & geom,
Mesh & mesh,
const MeshingParameters & mparam);
2009-01-13 04:40:13 +05:00
} // namespace netgen
2009-01-13 04:40:13 +05:00
#endif