netgen/libsrc/csg/csgeom.hpp

390 lines
11 KiB
C++
Raw Permalink Normal View History

2009-01-13 04:40:13 +05:00
#ifndef FILE_CSGEOM
#define FILE_CSGEOM
/**************************************************************************/
/* File: csgeom.hh */
/* Author: Joachim Schoeberl */
/* Date: 27. Nov. 97 */
/**************************************************************************/
2009-09-07 17:50:13 +06:00
namespace netgen
{
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/**
Constructive Solid Geometry
*/
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
class TriangleApproximation;
class TATriangle;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/**
A top level object is an entity to be meshed.
I can be either a solid, or one surface patch of a solid.
*/
2015-10-19 13:08:30 +05:00
class DLL_HEADER TopLevelObject
2009-09-07 17:50:13 +06:00
{
Solid * solid;
Surface * surface;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
double red, blue, green;
bool visible, transp;
double maxh;
string material;
int layer;
int bc; // for surface patches, only
string bcname;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
public:
TopLevelObject (Solid * asolid,
Surface * asurface = NULL);
2018-12-06 21:53:44 +05:00
// default constructor for archive
TopLevelObject() {}
2009-01-13 04:40:13 +05:00
void DoArchive(Archive& archive)
{
archive & solid & surface & red & blue & green & visible & transp & maxh
& material & layer & bc & bcname;
}
2009-09-07 17:50:13 +06:00
const Solid * GetSolid() const { return solid; }
Solid * GetSolid() { return solid; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
const Surface * GetSurface () const { return surface; }
Surface * GetSurface () { return surface; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void GetData (ostream & ost);
void SetData (istream & ist);
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetMaxH (double amaxh) { maxh = amaxh; }
double GetMaxH () const { return maxh; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetRGB (double ared, double agreen, double ablue)
{
red = ared;
green = agreen;
blue = ablue;
}
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
double GetRed () const { return red; }
double GetGreen () const { return green; }
double GetBlue () const { return blue; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetTransparent (bool atransp)
{ transp = atransp; }
bool GetTransparent () const { return transp; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetVisible (bool avisible)
{ visible = avisible; }
bool GetVisible () const { return visible; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
const string GetMaterial () const { return material; }
void SetMaterial (const string & mat) { material = mat; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
int GetLayer () const { return layer; }
void SetLayer (int alayer) { layer = alayer; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetBCProp (int abc) { bc = abc; }
int GetBCProp () const { return bc; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetBCName (string abc) { bcname = abc; }
const string GetBCName () const { return bcname; }
};
2009-01-13 04:40:13 +05:00
2009-08-25 20:00:20 +06:00
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/**
CSGeometry has the whole geometric information
*/
2015-10-19 13:08:30 +05:00
class DLL_HEADER CSGeometry : public NetgenGeometry
2009-09-07 17:50:13 +06:00
{
private:
/// all surfaces
2019-01-02 22:21:52 +05:00
SymbolTable<Surface*> surfaces;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
public:
/// primitive of surface
2019-07-09 13:39:16 +05:00
NgArray<const Primitive*> surf2prim;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
private:
2019-07-09 13:39:16 +05:00
NgArray<Surface*> delete_them;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// all named solids
2019-01-02 22:21:52 +05:00
SymbolTable<Solid*> solids;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// all 2d splinecurves
2021-04-12 18:51:40 +05:00
SymbolTable<shared_ptr<SplineGeometry<2>>> splinecurves2d;
2009-09-07 17:50:13 +06:00
/// all 3d splinecurves
2021-04-12 18:51:40 +05:00
SymbolTable<shared_ptr<SplineGeometry<3>>> splinecurves3d;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// all top level objects: solids and surfaces
2019-07-09 13:39:16 +05:00
NgArray<TopLevelObject*> toplevelobjects;
2009-01-13 04:40:13 +05:00
2017-09-22 19:55:10 +05:00
public:
2009-09-07 17:50:13 +06:00
/// additional points specified by user
2017-09-22 19:55:10 +05:00
class UserPoint : public Point<3>
{
int index;
2020-01-15 15:56:23 +05:00
string name;
2017-09-22 19:55:10 +05:00
public:
UserPoint() = default;
UserPoint (Point<3> p, int _index) : Point<3>(p), index(_index) { ; }
2022-02-16 17:37:32 +05:00
UserPoint (Point<3> p, const string & _name) : Point<3>(p), index(-1), name(_name) { ; }
2017-09-22 19:55:10 +05:00
int GetIndex() const { return index; }
2020-01-15 15:56:23 +05:00
const string & GetName() const { return name; }
2018-11-29 22:35:30 +05:00
void DoArchive(Archive& archive)
{
2020-01-15 15:56:23 +05:00
archive & index & name;
2018-11-29 22:35:30 +05:00
Point<3>::DoArchive(archive);
}
2017-09-22 19:55:10 +05:00
};
private:
2019-07-09 13:39:16 +05:00
// NgArray<Point<3> > userpoints;
NgArray<UserPoint> userpoints;
NgArray<double> userpoints_ref_factor;
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
mutable NgArray<Point<3> > identpoints;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// triangular approximation of top level objects
2019-07-09 13:39:16 +05:00
NgArray<TriangleApproximation*> triapprox;
2009-09-07 17:50:13 +06:00
/// increment, if geometry is changed
static int changeval;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// bounding box of geometry
Box<3> boundingbox;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// bounding box, if not set by input file
static Box<3> default_boundingbox;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// identic surfaces are stored by pair of indizes, val = inverse
INDEX_2_HASHTABLE<int> identicsurfaces;
2019-07-09 13:39:16 +05:00
NgArray<int> isidenticto;
2009-09-07 17:50:13 +06:00
/// identification of boundaries (periodic, thin domains, ...)
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
double ideps;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// filename of inputfile
string filename;
2009-01-13 04:40:13 +05:00
/// store splinesurfaces, such that added ones do not get deleted before geometry does
2019-07-09 13:39:16 +05:00
NgArray<shared_ptr<SplineSurface>> spline_surfaces;
2019-07-09 03:23:09 +05:00
shared_ptr<BlockAllocator> solid_ball = Solid::ball;
2009-09-07 17:50:13 +06:00
public:
CSGeometry ();
CSGeometry (const string & afilename);
2010-03-23 17:52:07 +05:00
virtual ~CSGeometry ();
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void Clean ();
2009-01-13 04:40:13 +05:00
2022-02-17 20:52:07 +05:00
virtual void Save (const filesystem::path & filename) const override;
2011-01-11 01:18:01 +05:00
void Save (ostream & ost) const;
2009-09-07 17:50:13 +06:00
void Load (istream & ist);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void SaveSurfaces (ostream & out) const;
2009-09-07 17:50:13 +06:00
void LoadSurfaces (istream & in);
2009-01-13 04:40:13 +05:00
2018-12-14 16:01:58 +05:00
virtual void SaveToMeshFile (ostream & ost) const override;
2011-01-11 01:18:01 +05:00
PointGeomInfo ProjectPoint(INDEX surfind, Point<3> & p) const override;
bool ProjectPointGI (int surfind, Point<3> & p, PointGeomInfo & gi) const override;
void ProjectPointEdge(INDEX surfind, INDEX surfind2, Point<3> & p,
EdgePointGeomInfo* gi = nullptr) const override;
Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* gi = nullptr) const override;
void PointBetween(const Point<3> & p1, const Point<3> & p2,
double secpoint, int surfi,
const PointGeomInfo & gi1,
const PointGeomInfo & gi2,
Point<3> & newp, PointGeomInfo & newgi) const override;
void PointBetweenEdge(const Point<3> & p1, const Point<3> & p2, double secpoint,
int surfi1, int surfi2,
const EdgePointGeomInfo & ap1,
const EdgePointGeomInfo & ap2,
Point<3> & newp, EdgePointGeomInfo & newgi) const override;
Vec<3> GetTangent (const Point<3> & p, int surfi1, int surfi2,
const EdgePointGeomInfo & ap1) const override;
2009-09-07 17:50:13 +06:00
int GetChangeVal() { return changeval; }
void Change() { changeval++; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void AddSurface (Surface * surf);
void AddSurface (char * name, Surface * surf);
void AddSurfaces (Primitive * prim);
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
int GetNSurf () const { return surfaces.Size(); }
const Surface * GetSurface (const char * name) const;
const Surface * GetSurface (int i) const
{ return surfaces[i]; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetSolid (const char * name, Solid * sol);
const Solid * GetSolid (const char * name) const;
const Solid * GetSolid (const string & name) const;
int GetNSolids () const { return solids.Size(); }
const Solid * GetSolid (int i) const { return solids[i]; }
2019-01-02 22:21:52 +05:00
const SymbolTable<Solid*> & GetSolids () const { return solids; }
2009-01-13 04:40:13 +05:00
2021-04-12 18:51:40 +05:00
void SetSplineCurve (const char * name, shared_ptr<SplineGeometry<2>> spl);
void SetSplineCurve (const char * name, shared_ptr<SplineGeometry<3>> spl);
shared_ptr<SplineGeometry<2>> GetSplineCurve2d (const string & name) const;
shared_ptr<SplineGeometry<3>> GetSplineCurve3d (const string & name) const;
2018-11-29 22:35:30 +05:00
2018-12-14 16:01:58 +05:00
void DoArchive(Archive& archive) override;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetFlags (const char * solidname, const Flags & flags);
int GetNTopLevelObjects () const
{ return toplevelobjects.Size(); }
int SetTopLevelObject (Solid * sol, Surface * surf = NULL);
void GetTopLevelObject (int nr, Solid *& sol, Surface *& surf)
{
sol = toplevelobjects[nr]->GetSolid();
surf = toplevelobjects[nr]->GetSurface();
}
void GetTopLevelObject (int nr, const Solid *& sol, const Surface *& surf) const
{
sol = toplevelobjects[nr]->GetSolid();
surf = toplevelobjects[nr]->GetSurface();
}
TopLevelObject * GetTopLevelObject (const Solid * sol, const Surface * surf = NULL);
2011-01-11 01:18:01 +05:00
TopLevelObject * GetTopLevelObject (int nr) const
2009-09-07 17:50:13 +06:00
{ return toplevelobjects[nr]; }
2011-01-11 01:18:01 +05:00
// const TopLevelObject * GetTopLevelObject (int nr) const
// { return toplevelobjects[nr]; }
2009-09-07 17:50:13 +06:00
void RemoveTopLevelObject (Solid * sol, Surface * surf = NULL);
2017-09-22 19:55:10 +05:00
void AddUserPoint (const Point<3> & p, double ref_factor = 0)
2018-08-06 20:09:03 +05:00
{ userpoints.Append (UserPoint(p,userpoints.Size()+1)); userpoints_ref_factor.Append (ref_factor); }
2017-09-22 19:55:10 +05:00
void AddUserPoint (const UserPoint up, double ref_factor = 0)
{ userpoints.Append (up); userpoints_ref_factor.Append (ref_factor); }
2009-09-07 17:50:13 +06:00
int GetNUserPoints () const
{ return userpoints.Size(); }
2017-09-22 19:55:10 +05:00
const UserPoint & GetUserPoint (int nr) const
2009-09-07 17:50:13 +06:00
{ return userpoints[nr]; }
double GetUserPointRefFactor (int nr) const
{ return userpoints_ref_factor[nr]; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void AddIdentPoint (const Point<3> & p) const
{ identpoints.Append(p);}
int GetNIdentPoints (void) const
{ return identpoints.Size();}
const Point<3> & GetIdentPoint(int nr) const
{ return identpoints[nr]; }
void DeleteIdentPoints(void) const
{ identpoints.DeleteAll();}
// quick implementations:
2019-07-09 13:39:16 +05:00
NgArray<SingularFace*> singfaces;
NgArray<SingularEdge*> singedges;
NgArray<SingularPoint*> singpoints;
NgArray<Identification*> identifications;
2009-09-07 17:50:13 +06:00
int GetNIdentifications (void) const { return identifications.Size(); }
void AddIdentification (Identification * ident);
///
2011-01-11 01:18:01 +05:00
void CalcTriangleApproximation(double detail, double facets);
2009-09-07 17:50:13 +06:00
///
void FindIdenticSurfaces (double eps);
///
void GetSurfaceIndices (const Solid * sol,
const BoxSphere<3> & box,
2019-07-09 13:39:16 +05:00
NgArray<int> & locsurf) const;
2009-09-07 17:50:13 +06:00
///
void GetIndependentSurfaceIndices (const Solid * sol,
const BoxSphere<3> & box,
2019-07-09 13:39:16 +05:00
NgArray<int> & locsurf) const;
2009-09-07 17:50:13 +06:00
///
2012-11-05 17:28:36 +06:00
/*
2009-09-07 17:50:13 +06:00
void GetIndependentSurfaceIndices (const Solid * sol,
const Point<3> & p, Vec<3> & v,
2019-07-09 13:39:16 +05:00
NgArray<int> & locsurf) const;
2012-11-05 17:28:36 +06:00
*/
2009-09-07 17:50:13 +06:00
///
2019-07-09 13:39:16 +05:00
void GetIndependentSurfaceIndices (NgArray<int> & locsurf) const;
2009-09-07 17:50:13 +06:00
///
int GetSurfaceClassRepresentant (int si) const
2009-01-13 04:40:13 +05:00
{ return isidenticto[si]; }
2009-09-07 17:50:13 +06:00
///
const TriangleApproximation * GetTriApprox (int msnr)
{
if (msnr < triapprox.Size())
return triapprox[msnr];
return 0;
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void IterateAllSolids (SolidIterator & it, bool only_once = false) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void RefineTriangleApprox (Solid * locsol,
int surfind,
const BoxSphere<3> & box,
double detail,
const TATriangle & tria,
TriangleApproximation & tams,
IndexSet & iset,
int level);
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
const Box<3> & BoundingBox () const { return boundingbox; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetBoundingBox (const Box<3> & abox)
{
boundingbox = abox;
}
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
static void SetDefaultBoundingBox (const Box<3> & abox)
{
default_boundingbox = abox;
}
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
double MaxSize () const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetIdEps(double eps){ideps = eps;}
double GetIdEps(void) const {return ideps;}
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
class BCModification {
public:
int si;
int tlonr;
int bcnr;
string * bcname;
};
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<BCModification> bcmodifications;
2009-01-13 04:40:13 +05:00
2020-01-13 20:41:06 +05:00
map<tuple<Surface*,Surface*>, string> named_edges;
2018-12-14 16:01:58 +05:00
virtual int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam) override;
2009-08-25 20:00:20 +06:00
2017-02-27 15:32:42 +05:00
void AddSplineSurface (shared_ptr<SplineSurface> ss) { spline_surfaces.Append(ss); }
2009-09-07 17:50:13 +06:00
};
2009-08-25 20:00:20 +06:00
2011-01-11 01:18:01 +05:00
2009-09-07 17:50:13 +06:00
}
2009-08-25 20:00:20 +06:00
2009-01-13 04:40:13 +05:00
#endif