Path: blob/devel/ElmerGUI/netgen/libsrc/stlgeom/stlgeom.hpp
3206 views
#ifndef FILE_STLGEOM1#define FILE_STLGEOM23/**************************************************************************/4/* File: stlgeom.hpp */5/* Author: Joachim Schoeberl */6/* Author2: Johannes Gerstmayr */7/* Date: 26. Jul. 99 */8/**************************************************************************/910/**11STL Geometry121314Terminology:1516Point ... coordinates of STL triangles17Triangle (short Trig) STL triangle18TopEdge .... edge in topology, boundary of STL triangles (many)19Edge .... Edges which will occur in the mesh (confirmed edges, less)20*/212223#include <gprim.hpp>24#include <meshing.hpp>25262728namespace netgen29{30extern int IsInArray(int n, const ARRAY<int>& ia);31extern int AddIfNotExists(ARRAY<int>& list, int x);323334#include "stltopology.hpp"35#include "stltool.hpp"36#include "stlline.hpp"3738394041424344class STLEdgeDataList45{46ARRAY<int> storedstatus;47STLTopology & geom;48public:4950STLEdgeDataList(STLTopology & ageom);51~STLEdgeDataList();5253void Store ();54void Restore ();5556void SetSize(int /* size */) { };57void Clear() { };58int Size() const { return geom.GetNTE(); }59const STLTopEdge & Get(int i) const { return geom.GetTopEdge(i); }60STLTopEdge & Elem(int i) { return geom.GetTopEdge(i); }6162int GetNEPP(int pn) const {return geom.NTopEdgesPerPoint(pn); }63int GetEdgePP(int pn, int vi) const {return geom.TopEdgePerPoint(pn, vi);};6465//void AddEdgePP(int pn, int vn) { } ;6667void ResetAll();68void ChangeStatus(int status1, int status2);6970int GetEdgeNum(int np1, int np2) const71{ return geom.GetTopEdgeNum (np1, np2); }7273int GetNConfEdges() const;7475void Write(ofstream& of) const;76void Read(ifstream& ifs);7778void BuildLineWithEdge(int ep1, int ep2, ARRAY<twoint>& line);79void BuildClusterWithEdge(int ep1, int ep2, ARRAY<twoint>& line);8081int GetNEPPStat(int p, int status) const;82int GetNConfCandEPP(int p) const;83};84858687888990class STLGeometry : public STLTopology91{92// edges to be meshed:93ARRAY<STLEdge> edges;94//edges per point95TABLE<int> edgesperpoint;9697// line: a connection of edges98ARRAY<STLLine*> lines;99ARRAY<int> lineendpoints; //per geometrypoint, 1 = is endpoint; 0 = no endpoint,100101ARRAY<Vec3d> normals; //normals belong to points!102103ARRAY<twoint> externaledges;104105int undoexternaledges;106ARRAY<twoint> storedexternaledges;107108STLEdgeDataList * edgedata;109// STLEdgeDataList edgedata_store;110int calcedgedataanglesnew;111112int edgedatastored;113114115116int facecnt;117//meshpoint is only set, if an edge is at this point!!!118119ARRAY<int> vicinity; //is one, if a triangle belongs to vicinity (eg. of selecttrig)120ARRAY<int> markedtrigs; //is one, if a triangle belongs to marked triangles (calcdirtystrigs)121ARRAY<Point3d> markedsegs; //every pointpair is a segment!!!122ARRAY<twoint> selectedmultiedge;123124125//spiralpoints:126ARRAY<int> spiralpoints;127//128ARRAY<STLChart*> atlas;129//marks all already charted trigs with chartnumber130ARRAY<int> chartmark;131//outerchartspertrig, ascending sorted132TABLE<int> outerchartspertrig;133134135//for meshing and project:136ARRAY<int> meshcharttrigs; //per trig: 1=belong to chart, 0 not137int meshchart;138139ARRAY<int> ha_points; // help array, np long, filled with 0140141142// sharp geometric edges not declared as edges143// (not considered for spiral check)144INDEX_2_HASHTABLE<int> * smoothedges;145146147//transformation:148Vec<3> meshtrignv;149Vec<3> ex, ey, ez;150Point<3> p1;151152public:153int edgesfound;154int surfacemeshed;155int surfaceoptimized;156int volumemeshed;157158int trigsconverted; //when STLTriangles exist -> 1159160//for selecting nodes161//int selecttrig, nodeofseltrig;162163//only for testing;164ARRAY<STLLine*> meshlines;165ARRAY<Point3d> meshpoints;166167public:168STLGeometry();169virtual ~STLGeometry();170171172void Clear();173174175176void STLInfo(double* data);177//stldoctor:178void SmoothNormals();179void MarkNonSmoothNormals();180181void CalcEdgeData();182void CalcEdgeDataAngles();183184const STLEdgeDataList& EdgeDataList() const {return *edgedata;}185186void UndoEdgeChange();187void StoreEdgeData();188void RestoreEdgeData();189190//void ClearSelectedMultiEdge() {selectedmultiedge.SetSize(0);}191//void AddSelectedMultiEdge(twoint ep) {selectedmultiedge.Append(ep);}192//int SelectedMultiEdgeSize() {return selectedmultiedge.Size();}193const ARRAY<twoint>& SelectedMultiEdge() {return selectedmultiedge;}194twoint GetNearestSelectedDefinedEdge();195void BuildSelectedMultiEdge(twoint ep);196void BuildSelectedEdge(twoint ep);197void BuildSelectedCluster(twoint ep);198199void ImportEdges();200void AddEdges(const ARRAY<Point<3> >& eps);201void ExportEdges();202void LoadEdgeData(const char* file);203void SaveEdgeData(const char* file);204// void SetEdgeAtSelected(int mode);205206207void STLDoctorConfirmEdge();208void STLDoctorCandidateEdge();209void STLDoctorExcludeEdge();210void STLDoctorUndefinedEdge();211212void STLDoctorSetAllUndefinedEdges();213void STLDoctorEraseCandidateEdges();214void STLDoctorConfirmCandidateEdges();215void STLDoctorConfirmedToCandidateEdges();216217void STLDoctorDirtyEdgesToCandidates();218void STLDoctorLongLinesToCandidates();219220void UndoExternalEdges();221void StoreExternalEdges();222void RestoreExternalEdges();223224void ImportExternalEdges(const char * filename); // Flame edges, JS225// void LoadExternalEdges();226227void BuildExternalEdgesFromEdges();228void SaveExternalEdges();229void AddExternalEdgeAtSelected();230void AddClosedLinesToExternalEdges();231void AddLongLinesToExternalEdges();232void AddAllNotSingleLinesToExternalEdges();233void STLDoctorBuildEdges();234void AddExternalEdgesFromGeomLine();235void DeleteDirtyExternalEdges();236void DeleteExternalEdgeAtSelected();237void DeleteExternalEdgeInVicinity();238void AddExternalEdge(int p1, int p2);239void DeleteExternalEdge(int p1, int p2);240int IsExternalEdge(int p1, int p2);241int NOExternalEdges() const {return externaledges.Size();}242twoint GetExternalEdge(int i) const {return externaledges.Get(i);}243244void DestroyDirtyTrigs();245void CalcNormalsFromGeometry();246void MoveSelectedPointToMiddle();247void NeighbourAnglesOfSelectedTrig();248void PrintSelectInfo();249void ShowSelectedTrigChartnum();250void ShowSelectedTrigCoords();251void SmoothGeometry ();252253254void LoadMarkedTrigs();255void SaveMarkedTrigs();256void ClearMarkedSegs() {markedsegs.SetSize(0);}257void AddMarkedSeg(const Point<3> & ap1, const Point<3> & ap2)258{259markedsegs.Append(ap1);markedsegs.Append(ap2);260}261262void GetMarkedSeg(int i, Point<3> & ap1, Point<3> & ap2)263{264ap1=markedsegs.Get(i*2-1);265ap2=markedsegs.Get(i*2);266}267int GetNMarkedSegs() {return markedsegs.Size()/2;}268void CalcVicinity(int starttrig);269void GetVicinity(int starttrig, int size, ARRAY<int>& vic);270271int Vicinity(int trig) const;272273void InitMarkedTrigs();274void MarkDirtyTrigs();275void SmoothDirtyTrigs();276void GeomSmoothRevertedTrigs();277void MarkRevertedTrigs();278double CalcTrigBadness(int i);279int IsMarkedTrig(int trig) const;280void SetMarkedTrig(int trig, int num);281void MarkTopErrorTrigs ();282283//Selected triangle284void SetSelectTrig(int trig);285int GetSelectTrig() const;286void SetNodeOfSelTrig(int n);287int GetNodeOfSelTrig() const;288289290int AddNormal(const Vec3d& n) {return normals.Append(n);}291const Vec3d & GetNormal(int nr) const {return normals.Get(nr);}292void SetNormal(int nr, const Vec3d& n) {normals.Elem(nr) = n;}293294int AddEdge(const STLEdge& v) {return edges.Append(v);}295int AddEdge(int p1, int p2);296297STLEdge GetEdge(int nr) {return edges.Get(nr);}298int GetNE() {return edges.Size();}299300double Area();301302double GetAngle(int t1, int t2);303double GetGeomAngle(int t1, int t2);304//if triangles t1 and t2 touch, return 1 and in p1, p2 the touching points305//int TrigsTouch(int t1, int t2, int& p1, int& p2);306307308309///310311///ReadTriangle->STLTriangle, initialise some important variables, always after load!!!312virtual void InitSTLGeometry (const ARRAY<STLReadTriangle> & readtrigs);313virtual void TopologyChanged(); //do some things, if topology changed!314int CheckGeometryOverlapping();315316//get NO edges per point317int GetEPPSize() const {return edgesperpoint.Size();};318int GetNEPP(int pn)319{320if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();}321return edgesperpoint.EntrySize(pn);322};323int GetEdgePP(int pn, int vi)324{325if (edgesperpoint.Size() == 0) {BuildEdgesPerPoint();}326return edgesperpoint.Get(pn,vi);327};328void AddEdgePP(int pn, int vn) {edgesperpoint.Add1(pn,vn);};329//von 2 punkten ermitteln, ob sie eine Kante sind330int IsEdge(int p1, int p2);331int IsEdgeNum(int p1, int p2);332333///Build EdgeSegments334void ClearEdges();335void BuildEdges();336void BuildEdgesPerPoint();337void UseExternalEdges();338339340void FindEdgesFromAngles();341void CalcFaceNums();342int GetNOBodys();343int GetNOFaces() {return facecnt;}344void LinkEdges();345346void AddConeAndSpiralEdges();347void AddFaceEdges(); //each face should have at least one starting edge (outherwise it won't be meshed)348349void GetDirtyChartTrigs(int chartnum, STLChart& chart, const ARRAY<int>& outercharttrigs,350ARRAY<int>& chartpointchecked, ARRAY<int>& dirtytrigs);351352void ClearSpiralPoints();353void SetSpiralPoint(int pn) {spiralpoints.Elem(pn) = 1;};354int GetSpiralPoint(int pn) const {return spiralpoints.Get(pn);};355356void GetSortedTrianglesAroundPoint(int p, int starttrig, ARRAY<int>& trigs);357358// smooth edges: sharp geometric edges not declared as edges359void BuildSmoothEdges ();360int IsSmoothEdge (int pi1, int pi2) const;361362363//make charts with regions of a max. angle364void MakeAtlas(class Mesh & mesh);365366//outerchartspertrig, sorted!367int GetOCPTSize() const {return outerchartspertrig.Size();};368int GetNOCPT(int tn) const {return outerchartspertrig.EntrySize(tn);};369int GetOCPT(int tn, int vi) const {return outerchartspertrig.Get(tn,vi);};370void SetOCPT(int tn, int vi, int ocn) {outerchartspertrig.Set(tn,vi,ocn);};371void AddOCPT(int tn, int ocn) {outerchartspertrig.Add1(tn, ocn);};372int TrigIsInOC(int tn, int ocn) const;373374//get chart number of a trig or 0 if unmarked375int GetChartNr(int i) const;376int GetMarker(int i) const377{ return chartmark.Get(i); }378void SetMarker(int nr, int m);379int GetNOCharts() const;380//get a chart from atlas381const STLChart& GetChart(int nr) const;382STLChart& GetChart(int nr) {return *(atlas.Get(nr));};383int AtlasMade() const;384385void GetInnerChartLimes(ARRAY<twoint>& limes, int chartnum);386387//FOR MESHING388int GetMeshChartNr () { return meshchart; }389void GetMeshChartBoundary (ARRAY<Point2d > & points,390ARRAY<Point3d > & points3d,391ARRAY<INDEX_2> & lines, double h);392393394Point<3> PointBetween(const Point<3> & p1, int t1, const Point<3> & p2, int t2);395396//select triangles in meshcharttrigs of actual (defined by trig) whole chart397void PrepareSurfaceMeshing();398//399void DefineTangentialPlane(const Point<3> & ap1, const Point<3> & ap2, int trig);400//401void SelectChartOfTriangle (int trignum);402//403void SelectChartOfPoint (const Point<3> & p);404//405const Vec<3> & GetChartNormalVector () const { return meshtrignv; }406407// list of trigs408void ToPlane (const Point<3> & locpoint, int * trigs, Point<2> & plainpoint,409double h, int& zone, int checkchart);410//return 0, wenn alles OK, 1 sonst411int FromPlane (const Point<2> & plainpoint, Point<3> & locpoint, double h);412413//get nearest point in actual chart and return any triangle where it lies on414int ProjectNearest(Point<3> & p3d) const;415//project point with normal nv from last define tangential plane416417int LastTrig() const;418int Project(Point<3> & p3d) const;419int ProjectOnWholeSurface (Point<3> & p3d) const;420421int GetNLines() const {return lines.Size();}422int AddLine(STLLine* line) {return lines.Append(line);}423STLLine* GetLine(int nr) const {return lines.Get(nr);}424int GetLineP(int lnr, int pnr) const {return lines.Get(lnr)->PNum(pnr);}425int GetLineNP(int nr) const {return lines.Get(nr)->NP();}426427void SetLineEndPoint(int pn);428int IsLineEndPoint(int pn);429int LineEndPointsSet() const {return lineendpoints.Size() == GetNP();}430void ClearLineEndPoints();431432void RestrictLocalH(class Mesh & mesh, double gh);433void RestrictLocalHCurv(class Mesh & mesh, double gh);434void RestrictHChartDistOneChart(int chartnum, ARRAY<int>& acttrigs, class Mesh & mesh,435double gh, double fact, double minh);436437friend class MeshingSTLSurface;438};439440441#include "meshstlsurface.hpp"442443444extern int STLMeshingDummy (STLGeometry* stlgeometry, Mesh*& mesh,445int perfstepsstart, int perfstepsend, char* optstring);446447448}449#endif450451452