netgen/libsrc/meshing/basegeom.hpp

362 lines
12 KiB
C++
Raw Permalink Normal View History

2009-08-24 06:03:40 +06:00
#ifndef FILE_BASEGEOM
#define FILE_BASEGEOM
/**************************************************************************/
/* File: basegeom.hpp */
/* Author: Joachim Schoeberl */
/* Date: 23. Aug. 09 */
/**************************************************************************/
#include <gprim/geomobjects.hpp>
#include <gprim/transform3d.hpp>
#include "meshtype.hpp"
#include "meshclass.hpp"
2011-03-03 01:50:39 +05:00
struct Tcl_Interp;
2011-01-11 01:18:01 +05:00
namespace netgen
{
class Refinement;
2021-11-28 20:14:41 +05:00
struct ShapeProperties
{
optional<string> name;
optional<Vec<4>> col;
double maxh = 1e99;
double hpref = 0; // number of hp refinement levels (will be multiplied by factor later)
int layer = 1;
2022-02-25 14:50:51 +05:00
optional<bool> quad_dominated;
optional<Array<double>> partition;
2021-11-28 20:14:41 +05:00
void Merge(const ShapeProperties & prop2)
{
if (!name && prop2.name) name = prop2.name;
if (!col && prop2.col) col = prop2.col;
if (!partition && prop2.partition) partition = prop2.partition;
2021-11-28 20:14:41 +05:00
maxh = min2(maxh, prop2.maxh);
hpref = max2(hpref, prop2.hpref);
2022-02-25 14:50:51 +05:00
if(!quad_dominated.has_value()) quad_dominated = prop2.quad_dominated;
layer = max(layer, prop2.layer);
2021-11-28 20:14:41 +05:00
}
string GetName() const { return name ? *name : "default"; }
Vec<4> GetColor() { return col ? *col : Vec<4>{0., 1., 0., 1.}; }
void DoArchive(Archive& ar)
{
ar & name & col & maxh & hpref & layer;
2021-11-28 20:14:41 +05:00
}
};
class GeometryShape;
struct ShapeIdentification
{
GeometryShape * from;
GeometryShape * to;
Transformation<3> trafo;
Identifications::ID_TYPE type;
string name = "";
};
class DLL_HEADER GeometryShape
2019-10-28 21:14:55 +05:00
{
public:
2021-11-28 20:14:41 +05:00
int nr = -1;
int layer = 1;
2021-11-28 20:14:41 +05:00
ShapeProperties properties;
Array<ShapeIdentification> identifications;
GeometryShape * primary;
Transformation<3> primary_to_me;
virtual ~GeometryShape() {}
virtual bool IsMappedShape( const GeometryShape & other, const Transformation<3> & trafo, double tolerance ) const;
};
class DLL_HEADER GeometryVertex : public GeometryShape
{
public:
virtual Point<3> GetPoint() const = 0;
virtual bool IsMappedShape( const GeometryShape & other, const Transformation<3> & trafo, double tolerance ) const override;
2019-10-28 21:14:55 +05:00
};
2021-11-28 20:14:41 +05:00
class DLL_HEADER GeometryEdge : public GeometryShape
2019-10-28 18:41:31 +05:00
{
protected:
GeometryVertex *start, *end;
2019-10-28 18:41:31 +05:00
public:
int domin=-1, domout=-1;
GeometryEdge( GeometryVertex &start_, GeometryVertex &end_ )
: start(&start_), end(&end_)
{}
virtual const GeometryVertex& GetStartVertex() const { return *start; }
virtual const GeometryVertex& GetEndVertex() const { return *end; }
virtual GeometryVertex& GetStartVertex() { return *start; }
virtual GeometryVertex& GetEndVertex() { return *end; }
2019-10-28 21:14:55 +05:00
virtual double GetLength() const = 0;
2021-11-28 20:14:41 +05:00
virtual Point<3> GetCenter() const = 0;
2019-10-28 21:14:55 +05:00
virtual Point<3> GetPoint(double t) const = 0;
// Calculate parameter step respecting edges sag value
virtual double CalcStep(double t, double sag) const = 0;
virtual bool IsDegenerated(double tol = 1e-10) const {
return GetLength() < tol;
}
virtual void ProjectPoint(Point<3>& p, EdgePointGeomInfo* gi) const = 0;
virtual void PointBetween(const Point<3>& p1,
const Point<3>& p2,
double secpoint,
const EdgePointGeomInfo& gi1,
const EdgePointGeomInfo& gi2,
Point<3>& newp,
EdgePointGeomInfo& newgi) const
{
newp = p1 + secpoint * (p2-p1);
newgi = gi1;
ProjectPoint(newp, &newgi);
}
virtual Vec<3> GetTangent(double t) const = 0;
2021-11-28 20:14:41 +05:00
virtual bool IsMappedShape( const GeometryShape & other, const Transformation<3> & trafo, double tolerance ) const override;
2023-02-13 19:57:53 +05:00
virtual void Divide(const MeshingParameters & mparam, const Mesh & mesh, Array<Point<3>> & points, Array<double> & params);
2019-10-28 18:41:31 +05:00
};
2021-11-28 20:14:41 +05:00
class DLL_HEADER GeometryFace : public GeometryShape
2019-10-28 18:41:31 +05:00
{
public:
Array<GeometryEdge*> edges;
2021-11-28 20:14:41 +05:00
int domin=-1, domout=-1;
virtual Point<3> GetCenter() const = 0;
2019-10-28 18:41:31 +05:00
virtual size_t GetNBoundaries() const = 0;
2021-11-28 20:14:41 +05:00
virtual Array<Segment> GetBoundary(const Mesh& mesh) const = 0;
virtual PointGeomInfo Project(Point<3>& p) const = 0;
2019-10-28 18:41:31 +05:00
// Project point using geo info. Fast if point is close to
// parametrization in geo info.
virtual bool ProjectPointGI(Point<3>& p, PointGeomInfo& gi) const =0;
virtual bool CalcPointGeomInfo(const Point<3>& p, PointGeomInfo& gi) const
{
auto pnew = p;
gi = Project(pnew);
return (p-pnew).Length() < 1e-10 * GetBoundingBox().Diam() ;
}
virtual Point<3> GetPoint(const PointGeomInfo& gi) const = 0;
2019-10-28 21:14:55 +05:00
virtual void CalcEdgePointGI(const GeometryEdge& edge,
double t,
EdgePointGeomInfo& egi) const = 0;
2019-10-28 18:41:31 +05:00
virtual Box<3> GetBoundingBox() const = 0;
// Get curvature in point from local coordinates in PointGeomInfo
virtual double GetCurvature(const PointGeomInfo& gi) const = 0;
virtual void RestrictH(Mesh& mesh, const MeshingParameters& mparam) const = 0;
virtual Vec<3> GetNormal(const Point<3>& p, const PointGeomInfo* gi = nullptr) const = 0;
virtual void PointBetween(const Point<3>& p1,
const Point<3>& p2,
double secpoint,
const PointGeomInfo& gi1,
const PointGeomInfo& gi2,
Point<3>& newp,
PointGeomInfo& newgi) const
{
newp = p1 + secpoint * (p2-p1);
newgi.trignum = gi1.trignum;
/*
newgi.u = 0.5 * (gi1.u + gi1.u);
newgi.v = 0.5 * (gi1.v + gi2.v);
*/
newgi.u = gi1.u + secpoint*(gi2.u - gi1.u);
newgi.v = gi1.v + secpoint*(gi2.v - gi1.v);
if(!ProjectPointGI(newp, newgi))
newgi = Project(newp);
}
virtual bool IsMappedShape( const GeometryShape & other, const Transformation<3> & trafo, double tolerance ) const override;
virtual bool IsConnectingCloseSurfaces() const;
protected:
void RestrictHTrig(Mesh& mesh,
const PointGeomInfo& gi0,
const PointGeomInfo& gi1,
const PointGeomInfo& gi2,
const MeshingParameters& mparam,
int depth = 0, double h = 0.) const;
2019-10-28 18:41:31 +05:00
};
2009-08-24 06:03:40 +06:00
2021-11-28 20:14:41 +05:00
class DLL_HEADER GeometrySolid : public GeometryShape
{ };
class DLL_HEADER NetgenGeometry
2011-03-03 01:50:39 +05:00
{
2019-10-03 16:52:59 +05:00
unique_ptr<Refinement> ref;
2019-10-24 16:17:00 +05:00
protected:
2019-10-28 21:14:55 +05:00
Array<unique_ptr<GeometryVertex>> vertices;
Array<unique_ptr<GeometryEdge>> edges;
2019-10-28 18:41:31 +05:00
Array<unique_ptr<GeometryFace>> faces;
2021-11-28 20:14:41 +05:00
Array<unique_ptr<GeometrySolid>> solids;
2021-09-09 01:12:45 +05:00
Array<std::pair<Point<3>, double>> restricted_h;
2019-10-24 16:17:00 +05:00
Box<3> bounding_box;
2021-11-28 20:14:41 +05:00
int dimension = 3;
2011-03-03 01:50:39 +05:00
public:
2021-11-28 20:14:41 +05:00
2019-10-03 16:52:59 +05:00
NetgenGeometry()
{
ref = make_unique<Refinement>(*this);
}
2011-03-03 01:50:39 +05:00
virtual ~NetgenGeometry () { ; }
2009-08-25 20:00:20 +06:00
2021-11-28 20:14:41 +05:00
size_t GetNVertices() const { return vertices.Size(); }
size_t GetNEdges() const { return edges.Size(); }
size_t GetNFaces() const { return faces.Size(); }
const GeometryFace & GetFace(int i) const { return *faces[i]; }
const GeometryEdge & GetEdge(int i) const { return *edges[i]; }
const GeometryVertex & GetVertex(int i) const { return *vertices[i]; }
2021-11-28 20:14:41 +05:00
virtual Array<const GeometryVertex*> GetFaceVertices(const GeometryFace& face) const { return Array<const GeometryVertex*>{}; }
void Clear();
2021-11-28 20:14:41 +05:00
virtual int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam);
2009-08-25 20:00:20 +06:00
2021-09-09 01:12:45 +05:00
void RestrictH(const Point<3>& pnt, double maxh)
{
restricted_h.Append({pnt, maxh});
}
2019-10-03 16:52:59 +05:00
virtual const Refinement & GetRefinement () const
{
return *ref;
}
2011-01-11 01:18:01 +05:00
2019-10-02 20:20:13 +05:00
virtual void DoArchive(Archive&)
2018-12-14 16:01:58 +05:00
{ throw NgException("DoArchive not implemented for " + Demangle(typeid(*this).name())); }
2019-10-02 20:20:13 +05:00
virtual Mesh::GEOM_TYPE GetGeomType() const { return Mesh::NO_GEOM; }
2021-11-28 20:14:41 +05:00
virtual void ProcessIdentifications();
2019-10-02 20:20:13 +05:00
virtual void Analyse(Mesh& mesh,
2019-10-28 18:41:31 +05:00
const MeshingParameters& mparam) const;
virtual void FindEdges(Mesh& mesh, const MeshingParameters& mparam) const;
virtual void MeshSurface(Mesh& mesh, const MeshingParameters& mparam) const;
2021-11-28 20:14:41 +05:00
virtual bool MeshFace(Mesh& mesh, const MeshingParameters& mparam,
int nr, FlatArray<int, PointIndex> glob2loc) const;
2024-03-06 15:20:20 +05:00
virtual void MapSurfaceMesh( Mesh & mesh, const GeometryFace & dst, std::map<tuple<PointIndex, int>, PointIndex> & mapto) const;
2019-10-28 18:41:31 +05:00
virtual void OptimizeSurface(Mesh& mesh, const MeshingParameters& mparam) const;
2021-11-28 20:14:41 +05:00
virtual void FinalizeMesh(Mesh& mesh) const;
virtual PointGeomInfo ProjectPoint (int surfind, Point<3> & p) const
{
2022-02-25 22:17:49 +05:00
if(surfind <= faces.Size() && surfind > 0)
return faces[surfind-1]->Project(p);
return PointGeomInfo();
}
virtual void ProjectPointEdge (int surfind, int surfind2, Point<3> & p, EdgePointGeomInfo* gi = nullptr) const
{
2022-02-25 22:17:49 +05:00
if(gi && gi->edgenr < edges.Size())
edges[gi->edgenr]->ProjectPoint(p, gi);
}
virtual bool CalcPointGeomInfo(int surfind, PointGeomInfo& gi, const Point<3> & p3) const
{
return faces[surfind-1]->CalcPointGeomInfo(p3, gi);
}
virtual bool ProjectPointGI (int surfind, Point<3> & p, PointGeomInfo & gi) const
{
2022-02-25 22:17:49 +05:00
if(surfind > 0 && surfind <= faces.Size())
return faces[surfind-1]->ProjectPointGI(p, gi);
2022-03-08 01:08:04 +05:00
return false;
}
virtual Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* gi = nullptr) const
2022-02-25 22:17:49 +05:00
{
if(surfind > 0 && surfind <= faces.Size())
return faces[surfind-1]->GetNormal(p, gi);
else
return {0., 0., 0.};
}
virtual 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
{
2022-02-25 22:17:49 +05:00
if(faces.Size() >= surfi && surfi > 0)
{
faces[surfi-1]->PointBetween(p1, p2, secpoint, gi1, gi2, newp, newgi);
return;
}
newp = p1 + secpoint * (p2-p1);
}
virtual 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
{
2022-02-25 22:17:49 +05:00
if(ap1.edgenr < edges.Size() && ap1.edgenr >= 0)
{
edges[ap1.edgenr]->PointBetween(p1, p2, secpoint,
ap1, ap2, newp, newgi);
return;
}
newp = p1+secpoint*(p2-p1);
}
virtual Vec<3> GetTangent(const Point<3> & p, int surfi1,
int surfi2,
const EdgePointGeomInfo & egi) const
{
throw Exception("Base geometry get tangent called");
}
2019-10-28 21:14:55 +05:00
2022-02-17 20:52:07 +05:00
virtual void Save (const filesystem::path & filename) const;
2011-08-29 16:09:11 +06:00
virtual void SaveToMeshFile (ostream & /* ost */) const { ; }
2011-03-03 01:50:39 +05:00
};
2009-08-24 06:03:40 +06:00
2010-03-23 17:52:07 +05:00
class DLL_HEADER GeometryRegister
2011-03-03 01:50:39 +05:00
{
public:
virtual ~GeometryRegister();
2022-02-17 20:52:07 +05:00
virtual NetgenGeometry * Load (const filesystem::path & filename) const = 0;
virtual NetgenGeometry * LoadFromMeshFile (istream & /* ist */, string) const { return NULL; }
2011-08-29 16:09:11 +06:00
virtual class VisualScene * GetVisualScene (const NetgenGeometry * /* geom */) const
2011-03-03 01:50:39 +05:00
{ return NULL; }
2011-08-29 16:09:11 +06:00
virtual void SetParameters (Tcl_Interp * /* interp */) { ; }
2011-03-03 01:50:39 +05:00
};
2019-07-09 13:39:16 +05:00
class DLL_HEADER GeometryRegisterArray : public NgArray<GeometryRegister*>
2013-02-06 18:55:20 +06:00
{
public:
virtual ~GeometryRegisterArray()
{
for (int i = 0; i < Size(); i++)
delete (*this)[i];
}
virtual shared_ptr<NetgenGeometry> LoadFromMeshFile (istream & ist) const;
2013-02-06 18:55:20 +06:00
};
2019-07-09 13:39:16 +05:00
// extern DLL_HEADER NgArray<GeometryRegister*> geometryregister;
2013-02-06 18:55:20 +06:00
extern DLL_HEADER GeometryRegisterArray geometryregister;
2011-01-11 01:18:01 +05:00
}
2010-03-23 17:52:07 +05:00
2009-08-24 06:03:40 +06:00
#endif