netgen/libsrc/csg/solid.hpp

265 lines
7.6 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#ifndef FILE_SOLID
#define FILE_SOLID
/**************************************************************************/
/* File: solid.hh */
/* Author: Joachim Schoeberl */
/* Date: 1. Dez. 95 */
/**************************************************************************/
2015-01-23 15:12:54 +05:00
#include <functional>
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
/*
2009-01-13 04:40:13 +05:00
Constructive Solid Model (csg)
2009-09-07 17:50:13 +06:00
*/
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
class Solid;
class SolidIterator
{
public:
SolidIterator () { ; }
virtual ~SolidIterator () { ; }
virtual void Do (Solid * sol) = 0;
};
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
class Solid
{
public:
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
typedef enum optyp1 { TERM, TERM_REF, SECTION, UNION, SUB, ROOT /*, DUMMY */ } optyp;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
private:
char * name;
Primitive * prim;
Solid * s1, * s2;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
optyp op;
bool visited;
double maxh;
int num_surfs;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
// static int cntnames;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
public:
Solid (Primitive * aprim);
Solid (optyp aop, Solid * as1, Solid * as2 = NULL);
2018-12-06 21:53:44 +05:00
// default constructor for archive
Solid () {}
2009-09-07 17:50:13 +06:00
~Solid ();
2009-01-13 04:40:13 +05:00
void DoArchive(Archive& archive)
{
archive & name & prim & s1 & s2 & visited & maxh & num_surfs;
if(archive.Output())
archive << int(op);
else
{
int iop;
archive & iop;
op = optyp(iop);
}
}
2009-09-07 17:50:13 +06:00
const char * Name () const { return name; }
void SetName (const char * aname);
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
Solid * Copy (class CSGeometry & geom) const;
void Transform (Transformation<3> & trans);
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void IterateSolid (SolidIterator & it, bool only_once = 0);
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
void Boundaries (const Point<3> & p, NgArray<int> & bounds) const;
2009-09-07 17:50:13 +06:00
int NumPrimitives () const;
2019-07-09 13:39:16 +05:00
void GetSurfaceIndices (NgArray<int> & surfind) const;
2009-09-07 17:50:13 +06:00
void GetSurfaceIndices (IndexSet & iset) const;
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
void GetTangentialSurfaceIndices (const Point<3> & p, NgArray<int> & surfids, double eps) const;
void GetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, NgArray<int> & surfids, double eps) const;
void GetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, NgArray<int> & surfids, double eps) const;
2009-01-13 04:40:13 +05:00
void ForEachSurface (const std::function<void(Surface*,bool)> & lambda, bool inv = false) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
Primitive * GetPrimitive ()
2009-01-13 04:40:13 +05:00
{ return (op == TERM || op == TERM_REF) ? prim : NULL; }
2009-09-07 17:50:13 +06:00
const Primitive * GetPrimitive () const
2009-01-13 04:40:13 +05:00
{ return (op == TERM || op == TERM_REF) ? prim : NULL; }
2009-09-07 17:50:13 +06:00
Solid * S1() { return s1; }
Solid * S2() { return s2; }
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
// geometric tests
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
bool IsIn (const Point<3> & p, double eps = 1e-6) const;
bool IsStrictIn (const Point<3> & p, double eps = 1e-6) const;
bool VectorIn (const Point<3> & p, const Vec<3> & v, double eps = 1e-6) const;
bool VectorStrictIn (const Point<3> & p, const Vec<3> & v, double eps = 1e-6) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
bool VectorIn2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,
double eps) const;
bool VectorIn2Rec (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,
double eps) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// compute localization in point p
2019-07-09 13:39:16 +05:00
void TangentialSolid (const Point<3> & p, Solid *& tansol, NgArray<int> & surfids, double eps) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/// compute localization in point p tangential to vector t
void TangentialSolid2 (const Point<3> & p, const Vec<3> & t,
2019-07-09 13:39:16 +05:00
Solid *& tansol, NgArray<int> & surfids, double eps) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/** compute localization in point p, with second order approximation to edge
p + s t + s*s/2 t2 **/
void TangentialSolid3 (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
2019-07-09 13:39:16 +05:00
Solid *& tansol, NgArray<int> & surfids, double eps) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
/** tangential solid, which follows the edge
p + s t + s*s/2 t2
with second order, and the neighbouring face
p + s t + s*s/2 t2 + r m
with first order
**/
void TangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
const Vec<3> & m,
2019-07-09 13:39:16 +05:00
Solid *& tansol, NgArray<int> & surfids, double eps) const;
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
void CalcOnePrimitiveSpecialPoints (const Box<3> & box, NgArray<Point<3> > & pts) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
///
int Edge (const Point<3> & p, const Vec<3> & v, double eps) const;
///
int OnFace (const Point<3> & p, const Vec<3> & v, double eps) const;
///
void Print (ostream & str) const;
///
void CalcSurfaceInverse ();
///
Solid * GetReducedSolid (const BoxSphere<3> & box) const;
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
void SetMaxH (double amaxh)
2009-01-13 04:40:13 +05:00
{ maxh = amaxh; }
2009-09-07 17:50:13 +06:00
double GetMaxH () const
2009-01-13 04:40:13 +05:00
{ return maxh; }
2009-09-07 17:50:13 +06:00
void GetSolidData (ostream & ost, int first = 1) const;
2019-01-02 22:21:52 +05:00
static Solid * CreateSolid (istream & ist, const SymbolTable<Solid*> & solids);
2009-09-07 17:50:13 +06:00
2019-07-09 03:23:09 +05:00
static shared_ptr<BlockAllocator> ball;
2009-09-07 17:50:13 +06:00
void * operator new(size_t /* s */)
{
2019-07-09 03:23:09 +05:00
return ball->Alloc();
2009-09-07 17:50:13 +06:00
}
void operator delete (void * p)
{
2019-07-09 03:23:09 +05:00
ball->Free (p);
2009-09-07 17:50:13 +06:00
}
protected:
///
2019-07-09 13:39:16 +05:00
void RecBoundaries (const Point<3> & p, NgArray<int> & bounds,
2009-09-07 17:50:13 +06:00
int & in, int & strin) const;
///
2019-07-09 13:39:16 +05:00
void RecTangentialSolid (const Point<3> & p, Solid *& tansol, NgArray<int> & surfids,
2009-09-07 17:50:13 +06:00
int & in, int & strin, double eps) const;
void RecTangentialSolid2 (const Point<3> & p, const Vec<3> & vec,
2019-07-09 13:39:16 +05:00
Solid *& tansol, NgArray<int> & surfids,
2009-09-07 17:50:13 +06:00
int & in, int & strin, double eps) const;
///
void RecTangentialSolid3 (const Point<3> & p, const Vec<3> & vec,const Vec<3> & vec2,
2019-07-09 13:39:16 +05:00
Solid *& tansol, NgArray<int> & surfids,
2009-09-07 17:50:13 +06:00
int & in, int & strin, double eps) const;
///
void RecTangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
const Vec<3> & m,
2019-07-09 13:39:16 +05:00
Solid *& tansol, NgArray<int> & surfids,
2009-09-07 17:50:13 +06:00
int & in, int & strin, double eps) const;
///
void RecEdge (const Point<3> & p, const Vec<3> & v,
int & in, int & strin, int & faces, double eps) const;
///
void CalcSurfaceInverseRec (int inv);
///
Solid * RecGetReducedSolid (const BoxSphere<3> & box, INSOLID_TYPE & in) const;
///
2019-07-09 13:39:16 +05:00
void RecGetSurfaceIndices (NgArray<int> & surfind) const;
void RecGetTangentialSurfaceIndices (const Point<3> & p, NgArray<int> & surfids, double eps) const;
void RecGetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, NgArray<int> & surfids, double eps) const;
2009-09-07 17:50:13 +06:00
void RecGetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2,
2019-07-09 13:39:16 +05:00
NgArray<int> & surfids, double eps) const;
2009-09-07 17:50:13 +06:00
void RecGetTangentialEdgeSurfaceIndices (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, const Vec<3> & m,
2019-07-09 13:39:16 +05:00
NgArray<int> & surfids, double eps) const;
2009-09-07 17:50:13 +06:00
void RecGetSurfaceIndices (IndexSet & iset) const;
2019-07-09 13:39:16 +05:00
void RecCalcOnePrimitiveSpecialPoints (NgArray<Point<3> > & pts) const;
2009-09-07 17:50:13 +06:00
friend class SolidIterator;
friend class ClearVisitedIt;
friend class RemoveDummyIterator;
friend class CSGeometry;
};
inline ostream & operator<< (ostream & ost, const Solid & sol)
2009-01-13 04:40:13 +05:00
{
2009-09-07 17:50:13 +06:00
sol.Print (ost);
return ost;
2009-01-13 04:40:13 +05:00
}
2009-09-07 17:50:13 +06:00
class ReducePrimitiveIterator : public SolidIterator
2009-01-13 04:40:13 +05:00
{
2019-03-31 10:42:15 +05:00
BoxSphere<3> box;
2009-09-07 17:50:13 +06:00
public:
ReducePrimitiveIterator (const BoxSphere<3> & abox)
: SolidIterator(), box(abox) { ; }
virtual ~ReducePrimitiveIterator () { ; }
virtual void Do (Solid * sol)
{
if (sol -> GetPrimitive())
sol -> GetPrimitive() -> Reduce (box);
}
};
class UnReducePrimitiveIterator : public SolidIterator
2009-01-13 04:40:13 +05:00
{
2009-09-07 17:50:13 +06:00
public:
UnReducePrimitiveIterator () { ; }
virtual ~UnReducePrimitiveIterator () { ; }
virtual void Do (Solid * sol)
{
if (sol -> GetPrimitive())
sol -> GetPrimitive() -> UnReduce ();
}
};
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
}
2009-01-13 04:40:13 +05:00
#endif