Path: blob/devel/ElmerGUI/netgen/libsrc/csg/surface.hpp
3206 views
#ifndef FILE_SURFACE1#define FILE_SURFACE23/**************************************************************************/4/* File: surface.hh */5/* Author: Joachim Schoeberl */6/* Date: 1. Dez. 95 */7/**************************************************************************/89101112// class DenseMatrix;13// class Box3dSphere;14class TriangleApproximation;1516/**17Basis class for implicit surface geometry.18This class is used for generation of surface meshes19in NETGEN as well as for mesh refinement in FEPP.20*/2122232425class Surface26{27protected:28/// invert normal vector29bool inverse;30/// maximal h in surface31double maxh;32/// name of surface33char * name;34/// boundary condition nr35int bcprop;36///37string bcname;3839public:40Surface ();41/** @name Tangential plane.42The tangential plane is used for surface mesh generation.43*/4445virtual ~Surface();4647protected:48/** @name Points in the surface defining tangential plane.49Tangential plane is taken in p1, the local x-axis50is directed to p2.51*/52//@{53///54Point<3> p1;55///56Point<3> p2;57//@}58/** @name Base-vectos for local coordinate system. */59//@{60/// in plane, directed p1->p261Vec<3> ex;62/// in plane63Vec<3> ey;64/// outer normal direction65Vec<3> ez;66//@}67public:6869void SetName (const char * aname);70const char * Name () const { return name; }7172//@{73/**74Defines tangential plane in ap1.75The local x-coordinate axis point to the direction of ap2 */76virtual void DefineTangentialPlane (const Point<3> & ap1,77const Point<3> & ap2);7879/// Transforms 3d point p3d to local coordinates pplane80virtual void ToPlane (const Point<3> & p3d, Point<2> & pplane,81double h, int & zone) const;8283/// Transforms point pplane in local coordinates to 3d point84virtual void FromPlane (const Point<2> & pplane,85Point<3> & p3d, double h) const;86//@}878889/// Move Point p to closes point in surface90virtual void Project (Point<3> & p) const;9192///93virtual void SkewProject(Point<3> & p, const Vec<3> & direction) const;9495virtual int IsIdentic (const Surface & /* s2 */, int & /* inv */,96double /* eps */) const97{ return 0; }9899///100virtual int PointOnSurface (const Point<3> & p,101double eps = 1e-6) const;102103104/** @name Implicit function.105Calculate function value and derivatives.106*/107//@{108/// Calculate implicit function value in point point109virtual double CalcFunctionValue (const Point<3> & point) const = 0;110111/**112Calc gradient of implicit function.113gradient should be O(1) at surface114*/115virtual void CalcGradient (const Point<3> & point, Vec<3> & grad) const = 0;116117/**118Calculate second derivatives of implicit function.119*/120virtual void CalcHesse (const Point<3> & point, Mat<3> & hesse) const;121122/**123Returns outer normal vector.124*/125// virtual void GetNormalVector (const Point<3> & p, Vec<3> & n) const;126virtual Vec<3> GetNormalVector (const Point<3> & p) const;127128/**129Upper bound for spectral norm of Hesse-matrix130*/131virtual double HesseNorm () const = 0;132133/**134Upper bound for spectral norm of Hesse-matrix in the135rad - environment of point c.136*/137virtual double HesseNormLoc (const Point<3> & /* c */,138double /* rad */) const139{ return HesseNorm (); }140//@}141142143///144virtual double MaxCurvature () const;145///146virtual double MaxCurvatureLoc (const Point<3> & /* c */ ,147double /* rad */) const;148149/** Returns any point in the surface.150Needed to start surface mesh generation e.g. on sphere */151virtual Point<3> GetSurfacePoint () const = 0;152153///154bool Inverse () const { return inverse; }155///156void SetInverse (bool ainverse) { inverse = ainverse; }157///158virtual void Print (ostream & str) const = 0;159160///161virtual void Reduce (const BoxSphere<3> & /* box */) { };162///163virtual void UnReduce () { };164165/// set max h in surface166void SetMaxH (double amaxh) { maxh = amaxh; }167///168double GetMaxH () const { return maxh; }169///170int GetBCProperty () const { return bcprop; }171///172void SetBCProperty (int abc) { bcprop = abc; }173174/** Determine local mesh-size.175Find176\[ h \leq hmax, \]177such that178\[ h \times \kappa (x) \leq c \qquad \mbox{in} B(x, h), \]179where kappa(x) is the curvature in x. */180virtual double LocH (const Point<3> & p, double x,181double c, double hmax) const;182183/**184Gets Approximation by triangles,185where qual is about the number of triangles per radius186*/187virtual void GetTriangleApproximation (TriangleApproximation & /* tas */,188const Box<3> & /* boundingbox */,189double /* facets */ ) const { };190191#ifdef MYGRAPH192///193virtual void Plot (const class ROT3D & /* rot */) const { };194#endif195196string GetBCName() const { return bcname; }197198void SetBCName( string abc ) { bcname = abc; }199};200201202inline ostream & operator<< (ostream & ost, const Surface & surf)203{204surf.Print(ost);205return ost;206}207208209210typedef enum { IS_OUTSIDE = 0, IS_INSIDE = 1, DOES_INTERSECT = 2}211INSOLID_TYPE;212213214215216class Primitive217{218219public:220221Primitive ();222223virtual ~Primitive();224225226/*227Check, whether box intersects solid defined by surface.228229return values:2300 .. box outside solid \\2311 .. box in solid \\2322 .. can't decide (allowed, iff box is close to solid)233*/234virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const = 0;235virtual INSOLID_TYPE PointInSolid (const Point<3> & p,236double eps) const = 0;237238virtual void GetTangentialSurfaceIndices (const Point<3> & p,239ARRAY<int> & surfind, double eps) const;240241virtual INSOLID_TYPE VecInSolid (const Point<3> & p,242const Vec<3> & v,243double eps) const = 0;244245// checks if lim s->0 lim t->0 p + t(v1 + s v2) in solid246virtual INSOLID_TYPE VecInSolid2 (const Point<3> & p,247const Vec<3> & v1,248const Vec<3> & v2,249double eps) const;250251// checks if p + s v1 + s*s/2 v2 is inside252virtual INSOLID_TYPE VecInSolid3 (const Point<3> & p,253const Vec<3> & v1,254const Vec<3> & v2,255double eps) const;256257// like VecInSolid2, but second order approximation258virtual INSOLID_TYPE VecInSolid4 (const Point<3> & p,259const Vec<3> & v,260const Vec<3> & v2,261const Vec<3> & m,262double eps) const;263264virtual void GetTangentialVecSurfaceIndices (const Point<3> & p, const Vec<3> & v,265ARRAY<int> & surfind, double eps) const;266267virtual void GetTangentialVecSurfaceIndices2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,268ARRAY<int> & surfind, double eps) const;269270271virtual void CalcSpecialPoints (ARRAY<Point<3> > & pts) const { ; }272virtual void AnalyzeSpecialPoint (const Point<3> & pt,273ARRAY<Point<3> > & specpts) const { ; }274virtual Vec<3> SpecialPointTangentialVector (const Point<3> & p, int s1, int s2) const { return Vec<3> (0,0,0); }275276277virtual int GetNSurfaces() const = 0;278virtual Surface & GetSurface (int i = 0) = 0;279virtual const Surface & GetSurface (int i = 0) const = 0;280281ARRAY<int> surfaceids;282ARRAY<int> surfaceactive;283284int GetSurfaceId (int i = 0) const;285void SetSurfaceId (int i, int id);286int SurfaceActive (int i) const { return surfaceactive[i]; }287virtual int SurfaceInverted (int i = 0) const { return 0; }288289virtual void GetPrimitiveData (const char *& classname,290ARRAY<double> & coeffs) const;291virtual void SetPrimitiveData (ARRAY<double> & coeffs);292static Primitive * CreatePrimitive (const char * classname);293294295virtual void Reduce (const BoxSphere<3> & /* box */) { };296virtual void UnReduce () { };297298virtual Primitive * Copy () const;299virtual void Transform (Transformation<3> & trans);300};301302303304305class OneSurfacePrimitive : public Surface, public Primitive306{307public:308OneSurfacePrimitive();309~OneSurfacePrimitive();310311virtual INSOLID_TYPE PointInSolid (const Point<3> & p,312double eps) const;313virtual INSOLID_TYPE VecInSolid (const Point<3> & p,314const Vec<3> & v,315double eps) const;316virtual INSOLID_TYPE VecInSolid2 (const Point<3> & p,317const Vec<3> & v1,318const Vec<3> & v2,319double eps) const;320321virtual INSOLID_TYPE VecInSolid3 (const Point<3> & p,322const Vec<3> & v1,323const Vec<3> & v2,324double eps) const;325326virtual INSOLID_TYPE VecInSolid4 (const Point<3> & p,327const Vec<3> & v,328const Vec<3> & v2,329const Vec<3> & m,330double eps) const;331332virtual int GetNSurfaces() const;333virtual Surface & GetSurface (int i = 0);334virtual const Surface & GetSurface (int i = 0) const;335};336337338339340341342/**343Projects point to edge.344The point hp is projected to the edge descibed by f1 and f2.345It is assumed that the edge is non-degenerated, and the346(generalized) Newton method converges.347*/348extern void ProjectToEdge (const Surface * f1,349const Surface * f2,350Point<3> & hp);351352353354#endif355356357