Path: blob/devel/ElmerGUI/netgen/libsrc/stlgeom/stltool.hpp
3206 views
#ifndef FILE_STLTOOL1#define FILE_STLTOOL234//#include "gprim/gprim.hh"56/**************************************************************************/7/* File: stlgeom.hh */8/* Author: Joachim Schoeberl */9/* Author2: Johannes Gerstmayr */10/* Date: 20. Nov. 99 */11/**************************************************************************/12131415// use one normal vector for whole chart16extern int usechartnormal;17extern int chartdebug;1819extern int geomsearchtreeon;20extern int AddPointIfNotExists(ARRAY<Point3d>& ap, const Point3d& p, double eps = 1e-8);21//get distance from line lp1-lp2 to point p22extern double GetDistFromLine(const Point<3>& lp1, const Point<3>& lp2, Point<3>& p);23extern double GetDistFromInfiniteLine(const Point<3>& lp1, const Point<3>& lp2, const Point<3>& p);242526extern void FIOReadInt(istream& ios, int& i);27extern void FIOWriteInt(ostream& ios, const int& i);28extern void FIOReadDouble(istream& ios, double& i);29extern void FIOWriteDouble(ostream& ios, const double& i);30extern void FIOReadFloat(istream& ios, float& i);31extern void FIOWriteFloat(ostream& ios, const float& i);32extern void FIOReadString(istream& ios, char* str, int len);33extern void FIOReadStringE(istream& ios, char* str, int len);34extern void FIOWriteString(ostream& ios, char* str, int len);353637typedef ARRAY <int> * ARRAYINTPTR;3839class STLGeometry;4041class STLChart42{43private:44STLGeometry * geometry;45ARRAY<int>* charttrigs; // trigs which only belong to this chart46ARRAY<int>* outertrigs; // trigs which belong to other charts47Box3dTree * searchtree; // ADT containing outer trigs4849ARRAY<twoint>* olimit; //outer limit of outer chart50ARRAY<twoint>* ilimit; //outer limit of inner chart515253public:5455STLChart(STLGeometry * ageometry);56void AddChartTrig(int i);57void AddOuterTrig(int i);5859int IsInWholeChart(int nr) const;6061int GetChartTrig(int i) const {return charttrigs->Get(i);}62int GetOuterTrig(int i) const {return outertrigs->Get(i);}63//get all trigs:64int GetTrig(int i) const65{66if (i <= charttrigs->Size()) {return charttrigs->Get(i);}67else {return outertrigs->Get(i-charttrigs->Size());}68}6970int GetNChartT() const {return charttrigs->Size();}71int GetNOuterT() const {return outertrigs->Size();}72int GetNT() const {return charttrigs->Size()+outertrigs->Size(); }7374void GetTrianglesInBox (const Point3d & pmin,75const Point3d & pmax,76ARRAY<int> & trias) const;77void AddOLimit(twoint l) {olimit->Append(l);}78void AddILimit(twoint l) {ilimit->Append(l);}7980void ClearOLimit() {olimit->SetSize(0);}81void ClearILimit() {ilimit->SetSize(0);}8283int GetNOLimit() const {return olimit->Size();}84int GetNILimit() const {return ilimit->Size();}8586twoint GetOLimit(int i) const {return olimit->Get(i);}87twoint GetILimit(int i) const {return ilimit->Get(i);}8889//move triangles trigs (local chart-trig numbers) to outer chart90void MoveToOuterChart(const ARRAY<int>& trigs);91void DelChartTrigs(const ARRAY<int>& trigs);929394// define local coordinate system, JS:95private:96Vec<3> normal;97Point<3> pref;98Vec<3> t1, t2;99public:100void SetNormal (const Point<3> & apref, const Vec<3> & anormal);101const Vec<3> & GetNormal () const { return normal; }102Point<2> Project2d (const Point<3> & p3d) const;103};104105class STLBoundarySeg106{107Point<3> p1, p2, center;108Point<2> p2d1, p2d2;109Box<2> boundingbox;110// Point<2> p2dmin, p2dmax;111112double rad;113int i1, i2;114int smoothedge;115public:116STLBoundarySeg () { ; }117STLBoundarySeg (int ai1, int ai2, const ARRAY<Point<3> > & points,118const STLChart * achart);119120int operator== (const STLBoundarySeg & s2) const121{ return i1 == s2.i1 && i2 == s2.i2; }122void Swap ();123int I1() const { return i1; }124int I2() const { return i2; }125const Point<3> & P1() const { return p1; }126const Point<3> & P2() const { return p2; }127const Point<2> & P2D1() const { return p2d1; }128const Point<2> & P2D2() const { return p2d2; }129const Point<2> & P2DMin() const { return boundingbox.PMin(); }130const Point<2> & P2DMax() const { return boundingbox.PMax(); }131const Point<3> & Center() const { return center; }132const Box<2> & BoundingBox() const { return boundingbox; }133double Radius () const { return rad; }134135void SetSmoothEdge (int se) { smoothedge = se; }136int IsSmoothEdge () const { return smoothedge; }137friend class STLBoundary;138};139140class STLBoundary141{142private:143STLGeometry * geometry;144const STLChart * chart;145ARRAY<STLBoundarySeg> boundary;146public:147STLBoundary(STLGeometry * ageometry);148// : boundary() {};149150void Clear() {boundary.SetSize(0);};151void SetChart (const STLChart * achart) { chart = achart; }152//don't check, if already exists!153void AddNewSegment(const STLBoundarySeg & seg) {boundary.Append(seg);};154//check if segment exists155void AddOrDelSegment(const STLBoundarySeg & seg);156//addordelsegment for all 3 triangle segments!157void AddTriangle(const STLTriangle & t);158int NOSegments() {return boundary.Size();};159const STLBoundarySeg & GetSegment(int i) {return boundary.Get(i);}160161int TestSeg(const Point<3> & p1, const Point<3> & p2, const Vec<3> & sn,162double sinchartangle, int divisions, ARRAY<Point<3> >& points,163double eps);164165int TestSegChartNV(const Point3d& p1, const Point3d& p2, const Vec3d& sn);166};167168169class STLDoctorParams170{171public:172int drawmeshededges;173double geom_tol_fact;174175double longlinefact;176int showexcluded;177178int selectmode; //0==trig, 1==edge, 2==point, 3==multiedge, 4==line cluster179int edgeselectmode;180181int useexternaledges;182int showfaces;183int showedgecornerpoints;184int showtouchedtrigchart;185int conecheck;186int spiralcheck;187int selecttrig;188int nodeofseltrig;189int selectwithmouse;190int showmarkedtrigs;191double dirtytrigfact;192double smoothangle;193194double smoothnormalsweight;195196int showvicinity;197int vicinity;198///199STLDoctorParams();200///201void Print (ostream & ost) const;202};203204extern STLDoctorParams stldoctor;205206207208class STLParameters209{210public:211/// angle for edge detection212double yangle;213double contyangle; //edges continued with contyangle214/// angle of geometry edge at which the mesher should set a point215double edgecornerangle;216/// angle inside on chart217double chartangle;218/// angle for overlapping parts of char219double outerchartangle;220/// 0 .. no, 1 .. local, (2 .. global)221int usesearchtree;222///223double resthatlasfac;224int resthatlasenable;225double atlasminh;226227double resthsurfcurvfac;228int resthsurfcurvenable;229230double resthchartdistfac;231int resthchartdistenable;232233double resthcloseedgefac;234int resthcloseedgeenable;235236double resthedgeanglefac;237int resthedgeangleenable;238239double resthsurfmeshcurvfac;240int resthsurfmeshcurvenable;241242double resthlinelengthfac;243int resthlinelengthenable;244245///246int recalc_h_opt;247///248STLParameters();249///250void Print (ostream & ost) const;251};252253extern STLParameters stlparam;254255256void STLMeshing (STLGeometry & geom,257class Mesh & mesh);258259260int STLSurfaceMeshing (STLGeometry & geom,261class Mesh & mesh);262263void STLSurfaceOptimization (STLGeometry & geom,264class Mesh & mesh,265class MeshingParameters & mparam);266267268269270#endif271272273