netgen/libsrc/csg/csgeom.hpp

330 lines
8.8 KiB
C++
Raw 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.
*/
class TopLevelObject
{
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);
2009-01-13 04:40:13 +05:00
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
*/
class CSGeometry : public NetgenGeometry
{
private:
/// all surfaces
SYMBOLTABLE<Surface*> surfaces;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
public:
/// primitive of surface
Array<const Primitive*> surf2prim;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
private:
Array<Surface*> delete_them;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// all named solids
SYMBOLTABLE<Solid*> solids;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// all 2d splinecurves
SYMBOLTABLE< SplineGeometry<2>* > splinecurves2d;
/// all 3d splinecurves
SYMBOLTABLE< 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
Array<TopLevelObject*> toplevelobjects;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// additional points specified by user
Array<Point<3> > userpoints;
Array<double> userpoints_ref_factor;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
mutable Array<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
Array<TriangleApproximation*> triapprox;
/// 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;
Array<int> isidenticto;
/// 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
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
2011-01-11 01:18:01 +05:00
virtual void Save (string filename) const;
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
2011-01-11 01:18:01 +05:00
virtual void SaveToMeshFile (ostream & ost) const;
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]; }
const SYMBOLTABLE<Solid*> & GetSolids () const { return solids; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetSplineCurve (const char * name, SplineGeometry<2> * spl);
void SetSplineCurve (const char * name, SplineGeometry<3> * spl);
const SplineGeometry<2> * GetSplineCurve2d (const string & name) const;
const SplineGeometry<3> * GetSplineCurve3d (const string & name) const;
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);
void AddUserPoint (const Point<3> & p, double ref_factor = 0)
{ userpoints.Append (p); userpoints_ref_factor.Append (ref_factor); }
int GetNUserPoints () const
{ return userpoints.Size(); }
const Point<3> & GetUserPoint (int nr) const
{ 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:
Array<SingularFace*> singfaces;
Array<SingularEdge*> singedges;
Array<SingularPoint*> singpoints;
Array<Identification*> identifications;
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,
Array<int> & locsurf) const;
///
void GetIndependentSurfaceIndices (const Solid * sol,
const BoxSphere<3> & box,
Array<int> & locsurf) const;
///
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,
Array<int> & locsurf) const;
2012-11-05 17:28:36 +06:00
*/
2009-09-07 17:50:13 +06:00
///
void GetIndependentSurfaceIndices (Array<int> & locsurf) const;
///
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
2009-09-07 17:50:13 +06:00
Array<BCModification> bcmodifications;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
int perfstepsstart, int perfstepsend);
2009-08-25 20:00:20 +06:00
2009-09-07 17:50:13 +06:00
virtual const Refinement & GetRefinement () const;
};
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