Path: blob/devel/ElmerGUI/netgen/libsrc/csg/csgeom.hpp
3206 views
#ifndef FILE_CSGEOM1#define FILE_CSGEOM23/**************************************************************************/4/* File: csgeom.hh */5/* Author: Joachim Schoeberl */6/* Date: 27. Nov. 97 */7/**************************************************************************/89/**10Constructive Solid Geometry11*/121314class TriangleApproximation;15class TATriangle;161718/**19A top level object is an entity to be meshed.20I can be either a solid, or one surface patch of a solid.21*/22class TopLevelObject23{24Solid * solid;25Surface * surface;2627double red, blue, green;28bool visible, transp;29double maxh;30string material;31int layer;32int bc; // for surface patches, only33string bcname;3435public:36TopLevelObject (Solid * asolid,37Surface * asurface = NULL);3839const Solid * GetSolid() const { return solid; }40Solid * GetSolid() { return solid; }4142const Surface * GetSurface () const { return surface; }43Surface * GetSurface () { return surface; }4445void GetData (ostream & ost);46void SetData (istream & ist);4748void SetMaxH (double amaxh) { maxh = amaxh; }49double GetMaxH () const { return maxh; }5051void SetRGB (double ared, double agreen, double ablue)52{53red = ared;54green = agreen;55blue = ablue;56}5758double GetRed () const { return red; }59double GetGreen () const { return green; }60double GetBlue () const { return blue; }6162void SetTransparent (bool atransp)63{ transp = atransp; }64bool GetTransparent () const { return transp; }6566void SetVisible (bool avisible)67{ visible = avisible; }68bool GetVisible () const { return visible; }6970const string GetMaterial () const { return material; }71void SetMaterial (const string & mat) { material = mat; }7273int GetLayer () const { return layer; }74void SetLayer (int alayer) { layer = alayer; }7576void SetBCProp (int abc) { bc = abc; }77int GetBCProp () const { return bc; }7879void SetBCName (string abc) { bcname = abc; }80const string GetBCName () const { return bcname; }81};828384/**85CSGeometry has the whole geometric information86*/87class CSGeometry88{89private:90/// all surfaces91SYMBOLTABLE<Surface*> surfaces;9293public:94/// primitive of surface95ARRAY<const Primitive*> surf2prim;9697private:98ARRAY<Surface*> delete_them;99100/// all named solids101SYMBOLTABLE<Solid*> solids;102103/// all 2d splinecurves104SYMBOLTABLE< SplineGeometry<2>* > splinecurves2d;105/// all 3d splinecurves106SYMBOLTABLE< SplineGeometry<3>* > splinecurves3d;107108/// all top level objects: solids and surfaces109ARRAY<TopLevelObject*> toplevelobjects;110111/// additional points specified by user112ARRAY<Point<3> > userpoints;113ARRAY<double> userpoints_ref_factor;114115mutable ARRAY<Point<3> > identpoints;116117/// triangular approximation of top level objects118ARRAY<TriangleApproximation*> triapprox;119120/// increment, if geometry is changed121static int changeval;122123/// bounding box of geometry124Box<3> boundingbox;125126/// bounding box, if not set by input file127static Box<3> default_boundingbox;128129/// identic surfaces are stored by pair of indizes, val = inverse130INDEX_2_HASHTABLE<int> identicsurfaces;131ARRAY<int> isidenticto;132/// identification of boundaries (periodic, thin domains, ...)133134double ideps;135136137/// filename of inputfile138string filename;139140141public:142CSGeometry ();143CSGeometry (const string & afilename);144~CSGeometry ();145146void Clean ();147148void Save (ostream & ost);149void Load (istream & ist);150151void SaveSurfaces (ostream & out);152void LoadSurfaces (istream & in);153154int GetChangeVal() { return changeval; }155void Change() { changeval++; }156157void AddSurface (Surface * surf);158void AddSurface (char * name, Surface * surf);159void AddSurfaces (Primitive * prim);160161int GetNSurf () const { return surfaces.Size(); }162const Surface * GetSurface (const char * name) const;163const Surface * GetSurface (int i) const164{ return surfaces[i]; }165166void SetSolid (const char * name, Solid * sol);167const Solid * GetSolid (const char * name) const;168const Solid * GetSolid (const string & name) const;169int GetNSolids () const { return solids.Size(); }170const Solid * GetSolid (int i) const { return solids[i]; }171const SYMBOLTABLE<Solid*> & GetSolids () const { return solids; }172173174void SetSplineCurve (const char * name, SplineGeometry<2> * spl);175void SetSplineCurve (const char * name, SplineGeometry<3> * spl);176const SplineGeometry<2> * GetSplineCurve2d (const string & name) const;177const SplineGeometry<3> * GetSplineCurve3d (const string & name) const;178179180void SetFlags (const char * solidname, const Flags & flags);181182183int GetNTopLevelObjects () const184{ return toplevelobjects.Size(); }185int SetTopLevelObject (Solid * sol, Surface * surf = NULL);186void GetTopLevelObject (int nr, Solid *& sol, Surface *& surf)187{188sol = toplevelobjects[nr]->GetSolid();189surf = toplevelobjects[nr]->GetSurface();190}191void GetTopLevelObject (int nr, const Solid *& sol, const Surface *& surf) const192{193sol = toplevelobjects[nr]->GetSolid();194surf = toplevelobjects[nr]->GetSurface();195}196197TopLevelObject * GetTopLevelObject (const Solid * sol, const Surface * surf = NULL);198TopLevelObject * GetTopLevelObject (int nr)199{ return toplevelobjects[nr]; }200const TopLevelObject * GetTopLevelObject (int nr) const201{ return toplevelobjects[nr]; }202void RemoveTopLevelObject (Solid * sol, Surface * surf = NULL);203204205void AddUserPoint (const Point<3> & p, double ref_factor = 0)206{ userpoints.Append (p); userpoints_ref_factor.Append (ref_factor); }207int GetNUserPoints () const208{ return userpoints.Size(); }209const Point<3> & GetUserPoint (int nr) const210{ return userpoints[nr]; }211double GetUserPointRefFactor (int nr) const212{ return userpoints_ref_factor[nr]; }213214void AddIdentPoint (const Point<3> & p) const215{ identpoints.Append(p);}216int GetNIdentPoints (void) const217{ return identpoints.Size();}218const Point<3> & GetIdentPoint(int nr) const219{ return identpoints[nr]; }220void DeleteIdentPoints(void) const221{ identpoints.DeleteAll();}222223224// quick implementations:225ARRAY<SingularFace*> singfaces;226ARRAY<SingularEdge*> singedges;227ARRAY<SingularPoint*> singpoints;228ARRAY<Identification*> identifications;229230int GetNIdentifications (void) const { return identifications.Size(); }231void AddIdentification (Identification * ident);232233234///235void CalcTriangleApproximation(const Box<3> & boundingbox,236double detail, double facets);237238///239void FindIdenticSurfaces (double eps);240///241void GetSurfaceIndices (const Solid * sol,242const BoxSphere<3> & box,243ARRAY<int> & locsurf) const;244///245void GetIndependentSurfaceIndices (const Solid * sol,246const BoxSphere<3> & box,247ARRAY<int> & locsurf) const;248///249void GetIndependentSurfaceIndices (const Solid * sol,250const Point<3> & p, Vec<3> & v,251ARRAY<int> & locsurf) const;252///253void GetIndependentSurfaceIndices (ARRAY<int> & locsurf) const;254255///256int GetSurfaceClassRepresentant (int si) const257{ return isidenticto[si]; }258259///260const TriangleApproximation * GetTriApprox (int msnr)261{262if (msnr < triapprox.Size())263return triapprox[msnr];264return 0;265}266267268void IterateAllSolids (SolidIterator & it, bool only_once = false);269270void RefineTriangleApprox (Solid * locsol,271int surfind,272const BoxSphere<3> & box,273double detail,274const TATriangle & tria,275TriangleApproximation & tams,276IndexSet & iset);277278const Box<3> & BoundingBox () const { return boundingbox; }279280void SetBoundingBox (const Box<3> & abox)281{282boundingbox = abox;283}284285286static void SetDefaultBoundingBox (const Box<3> & abox)287{288default_boundingbox = abox;289}290291double MaxSize () const;292293void SetIdEps(double eps){ideps = eps;}294double GetIdEps(void) const {return ideps;}295296class BCModification {297public:298int si;299int tlonr;300int bcnr;301string * bcname;302};303304ARRAY<BCModification> bcmodifications;305306};307#endif308309310311