32
29
#include <algorithm>
44
44
void vector_triangle(BDS_Point *p1, BDS_Point *p2, BDS_Point *p3, double c[3]);
45
45
void normal_triangle(BDS_Point *p1, BDS_Point *p2, BDS_Point *p3, double c[3]);
46
46
double surface_triangle(BDS_Point *p1, BDS_Point *p2, BDS_Point *p3);
47
double surface_triangle_param(BDS_Point *p1, BDS_Point *p2, BDS_Point *p3);
47
48
double quality_triangle(BDS_Point *p1, BDS_Point *p2, BDS_Point *p3);
52
const double target,_min,_max,treshold, beta;
53
const double nb_elements_per_radius_of_curvature;
54
BDS_Metric(double _target , double _mmin, double _mmax, double _b, double cc, double _tres = 0.7)
55
: target(_target),_min(_mmin),_max(_mmax),treshold(_tres),beta(_b),nb_elements_per_radius_of_curvature(cc)
57
inline double update_target_length(double _target, double old_target_length) const
59
if(_target <= _min) return _min;
60
if(_target >= _max && old_target_length > _max) return _max;
61
if(old_target_length > _target)return _target ;
62
return old_target_length;
64
inline double target_length(double x, double y, double z) const
73
virtual ~BDS_Surface(){}
74
virtual double signedDistanceTo(double x, double y, double z) const = 0;
75
virtual void projection(double xa, double ya, double za,
76
double &x, double &y, double &z) const =0;
77
virtual std::string nameOf() const = 0;
78
virtual BDS_Vector Gradient(double x, double y, double z) const = 0;
79
virtual double normalCurv(double x, double y, double z) const = 0;
83
50
class BDS_GeomEntity
88
55
int classif_degree;
91
ANNpointArray dataPts; // data points
92
ANNpoint queryPt; // query point
93
ANNidxArray nnIdx; // near neighbor indices
94
ANNdistArray dists; // near neighbor distances
95
ANNkd_tree* kdTree; // search structure
96
std::vector<BDS_Edge *> sE;
97
std::vector<double> sR;
99
std::list<BDS_Triangle *> t;
100
std::list<BDS_Edge *> e;
103
void getClosestTriangles(double x, double y, double z,
104
std::list<BDS_Triangle*> &l ,
106
double &X, double &Y, double &Z);
107
inline bool operator < (const BDS_GeomEntity & other) const
56
inline bool operator < (const BDS_GeomEntity & other) const
109
58
if(classif_degree < other.classif_degree)return true;
110
59
if(classif_degree > other.classif_degree)return false;
256
double min_edge_length();
257
void getTriangles(std::list<BDS_Triangle *> &t) const;
258
void compute_curvature();
191
void getTriangles(std::list<BDS_Face *> &t) const;
259
192
BDS_Point(int id, double x=0, double y=0, double z=0)
260
: BDS_Pos(x,y,z),iD(id),radius_of_curvature(1.e22),g(0)
193
: _lc(1.e22),X(x),Y(y),Z(z),u(0),v(0),config_modified(true),iD(id),g(0)
267
std::vector <BDS_Triangle *> _faces;
201
std::vector <BDS_Face *> _faces;
272
double target_length;
273
204
BDS_Point *p1,*p2;
274
205
BDS_GeomEntity *g;
275
inline BDS_Triangle* faces(int i) const
206
inline BDS_Face* faces(int i) const
277
208
return _faces [i];
279
210
inline double length() const
281
return sqrt((p1->X-p2->X)*(p1->X-p2->X)+(p1->Y-p2->Y)*(p1->Y-p2->Y)+(p1->Z-p2->Z)*(p1->Z-p2->Z));
283
214
inline int numfaces() const
285
216
return _faces.size();
218
int numTriangles() const ;
287
219
inline BDS_Point * commonvertex(const BDS_Edge *other) const
289
221
if(p1 == other->p1 || p1 == other->p2) return p1;
336
273
p1->edges.push_back(this);
337
274
p2->edges.push_back(this);
348
BDS_Edge *e1,*e2,*e3;
351
inline BDS_Vector N() const {return NORMAL;}
352
inline double S() const {return surface;}
284
BDS_Edge *e1,*e2,*e3,*e4;
353
285
BDS_GeomEntity *g;
355
inline double inscribed_radius() const
357
double l1 = e1->length();
358
double l2 = e2->length();
359
double l3 = e3->length();
360
return (2 * S() / (l1+l2+l3));
363
inline BDS_Tet * opposite_tet(BDS_Tet *t)
365
if(t == t1)return t2;
366
if(t == t2)return t1;
370
inline int numtets() const
372
return ((t1!=0) + (t2 !=0));
375
inline BDS_Vector cog() const
379
return BDS_Vector((n[0]->X+n[1]->X+n[2]->X)/3.,
380
(n[0]->Y+n[1]->Y+n[2]->Y)/3.,
381
(n[0]->Z+n[1]->Z+n[2]->Z)/3.);
384
inline void _update()
389
vector_triangle(pts[0],pts[1],pts[2],c);
390
surface = 0.5 * sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);
391
NORMAL.x = 2*c[0]/surface;
392
NORMAL.y = 2*c[1]/surface;
393
NORMAL.z = 2*c[2]/surface;
396
inline void getNodes(BDS_Point *n[3]) const
398
n[0] = e1->commonvertex(e3);
399
n[1] = e1->commonvertex(e2);
400
n[2] = e2->commonvertex(e3);
403
inline BDS_Vector N_on_the_fly() const
408
normal_triangle(pp[0], pp[1], pp[2],nn);
409
return BDS_Vector(nn[0],nn[1],nn[2]);
412
inline void addtet(BDS_Tet *t)
419
inline void del(BDS_Tet *t)
286
inline int numEdges () const {return e4?4:3;}
287
inline void getNodes(BDS_Point *n[4]) const
291
n[0] = e1->commonvertex(e3);
292
n[1] = e1->commonvertex(e2);
293
n[2] = e2->commonvertex(e3);
298
n[0] = e1->commonvertex(e4);
299
n[1] = e1->commonvertex(e2);
300
n[2] = e2->commonvertex(e3);
301
n[3] = e3->commonvertex(e4);
432
BDS_Triangle(BDS_Edge *A, BDS_Edge *B, BDS_Edge *C)
433
: deleted(false) , status(0), partition(0),t1(0),t2(0),e1(A),e2(B),e3(C),g(0)
305
BDS_Face(BDS_Edge *A, BDS_Edge *B, BDS_Edge *C,BDS_Edge *D = 0)
306
: deleted(false) ,e1(A),e2(B),e3(C),e4(D),g(0)
435
308
e1->addface(this);
436
309
e2->addface(this);
437
310
e3->addface(this);
448
BDS_Triangle *f1,*f2,*f3,*f4;
450
inline double V() const {return volume;}
453
inline BDS_Vector cog() const
457
return BDS_Vector((n[0]->X+n[1]->X+n[2]->X+n[3]->X)/4.,
458
(n[0]->Y+n[1]->Y+n[2]->Y+n[3]->Y)/4.,
459
(n[0]->Z+n[1]->Z+n[2]->Z+n[3]->Z)/4.);
462
inline void _update()
466
inline void getNodes(BDS_Point *n[4]) const
471
n[3] = 0; //for stupid gcc warning
472
if(o[0] != n[0] && o[0] != n[1] &&o[0] != n[2])n[3] = o[0];
473
if(o[1] != n[0] && o[1] != n[1] &&o[1] != n[2])n[3] = o[1];
474
if(o[2] != n[0] && o[2] != n[1] &&o[2] != n[2])n[3] = o[2];
477
BDS_Tet(BDS_Triangle *A, BDS_Triangle *B, BDS_Triangle *C, BDS_Triangle *D)
478
: deleted(false) , status(0), partition(0),f1(A),f2(B),f3(C),f4(D),g(0)
489
class BDS_Plane : public BDS_Surface
493
BDS_Plane(const double &A, const double &B, const double &C)
497
virtual double signedDistanceTo(double x, double y, double z) const {return a*x + b*y + c*z + 1;}
498
virtual void projection(double xa, double ya, double za,
499
double &x, double &y, double &z) const
501
double k = - (a * xa + b * ya + c * za + 1) / (a * a + b * b + c * c);
506
virtual std::string nameOf() const {return std::string("Plane");}
507
virtual BDS_Vector Gradient(double x, double y, double z) const
509
return BDS_Vector(a , b , c);
511
virtual double normalCurv(double x, double y, double z) const
517
class BDS_Quadric : public BDS_Surface
520
double a,b,c,d,e,f,g,h,i;
521
BDS_Quadric(double A,double B,double C, double D, double E, double F, double G, double H, double I)
522
: a(A),b(B),c(C),d(D),e(E),f(F),g(G),h(H),i(I)
526
virtual BDS_Vector Gradient(double x, double y, double z) const
528
return BDS_Vector(2 * (a * x + d * y + e * z) + g ,
529
2 * (d * x + b * y + f * z) + h ,
530
2 * (e * x + f * y + c * z) + i);
533
virtual double normalCurv(double x, double y, double z) const;
535
virtual double signedDistanceTo(double x, double y, double z) const {
548
virtual void projection(double xa, double ya, double za,
549
double &x, double &y, double &z) const ;
550
virtual std::string nameOf() const {return std::string("Quadric");}
311
if(e4)e4->addface(this);
553
316
class GeomLessThan
359
class BDS_SwapEdgeTest
362
virtual bool operator() (BDS_Point *p1,BDS_Point *p2,
363
BDS_Point *q1,BDS_Point *q2) const = 0;
364
virtual ~BDS_SwapEdgeTest(){}
367
class BDS_SwapEdgeTestParametric : public BDS_SwapEdgeTest
370
virtual bool operator() (BDS_Point *p1,BDS_Point *p2,
371
BDS_Point *q1,BDS_Point *q2) const ;
372
virtual ~BDS_SwapEdgeTestParametric(){}
597
378
int MAXPOINTNUMBER,SNAP_SUCCESS,SNAP_FAILURE;
600
379
double Min[3],Max[3],LC;
602
void projection(double &x, double &y, double &z);
604
BDS_Mesh(int _MAXX = 0) : MAXPOINTNUMBER(_MAXX){}
380
double scalingU, scalingV;
381
BDS_Mesh(int _MAXX = 0) : MAXPOINTNUMBER(_MAXX),scalingU(1),scalingV(1){}
382
void load(GVertex *gv); // load in BDS all the meshes of the vertex
383
void load(GEdge *ge); // load in BDS all the meshes of the edge
384
void load(GFace *gf); // load in BDS all the meshes of the surface
605
385
virtual ~BDS_Mesh();
606
386
BDS_Mesh(const BDS_Mesh &other);
607
387
std::set<BDS_GeomEntity*,GeomLessThan> geom;
608
388
std::set<BDS_Point*,PointLessThan> points;
609
389
std::list<BDS_Edge*> edges;
610
std::list<BDS_Triangle*> triangles;
611
std::list<BDS_Tet*> tets;
390
std::list<BDS_Face*> triangles;
612
392
BDS_Point * add_point(int num , double x, double y,double z);
393
BDS_Point * add_point(int num , double u, double v , GFace *gf);
394
void del_point(BDS_Point *p);
395
BDS_Point *find_point(int num);
613
397
BDS_Edge * add_edge(int p1, int p2);
614
void del_point(BDS_Point *p);
615
398
void del_edge(BDS_Edge *e);
616
BDS_Triangle *add_triangle(int p1, int p2, int p3);
617
BDS_Triangle *add_triangle(BDS_Edge *e1,BDS_Edge *e2,BDS_Edge *e3);
618
BDS_Tet *add_tet(int p1, int p2, int p3,int p4);
619
void del_triangle(BDS_Triangle *t);
399
BDS_Edge *find_edge(int p1, int p2);
400
BDS_Edge *find_edge(BDS_Point *p1, BDS_Point *p2, BDS_Face *t)const;
401
// Triangles & Quadrangles
402
BDS_Face *add_triangle(int p1, int p2, int p3);
403
BDS_Face *add_quadrangle(int p1, int p2, int p3,int p4);
404
BDS_Face *add_triangle(BDS_Edge *e1,BDS_Edge *e2,BDS_Edge *e3);
405
BDS_Face *add_quadrangle(BDS_Edge *e1,BDS_Edge *e2,BDS_Edge *e3,BDS_Edge *e4);
406
void del_face(BDS_Face *t);
407
BDS_Face *find_triangle(BDS_Edge *e1,BDS_Edge *e2,BDS_Edge *e3);
408
BDS_Face *find_quadrangle(BDS_Edge *e1,BDS_Edge *e2,BDS_Edge *e3,BDS_Edge *e4);
620
410
void add_geom(int degree, int tag);
621
BDS_Point *find_point(int num);
622
BDS_Edge *find_edge(int p1, int p2);
623
BDS_Triangle *find_triangle(BDS_Edge *e1,BDS_Edge *e2,BDS_Edge *e3);
624
BDS_Edge *find_edge(BDS_Point *p1, BDS_Point *p2, BDS_Triangle *t)const;
625
411
BDS_GeomEntity *get_geom(int p1, int p2);
626
bool swap_edge(BDS_Edge *);
627
bool collapse_edge(BDS_Edge *, BDS_Point*, const double eps);
413
BDS_Edge *recover_edge(int p1, int p2);
414
bool swap_edge(BDS_Edge *, const BDS_SwapEdgeTest &theTest);
415
bool collapse_edge_parametric(BDS_Edge *, BDS_Point*);
628
416
void snap_point(BDS_Point* , BDS_Mesh *geom = 0);
629
417
bool smooth_point(BDS_Point* , BDS_Mesh *geom = 0);
630
bool smooth_point_b(BDS_Point*);
418
bool smooth_point_parametric(BDS_Point * p, GFace *gf);
631
419
bool move_point(BDS_Point *p , double X, double Y, double Z);
632
bool split_edge(BDS_Edge *, double coord, BDS_Mesh *geom = 0);
633
void classify(double angle, int nb = -1);
634
void color_plane_surf(double eps , int nb);
635
void reverseEngineerCAD() ;
636
void createSearchStructures() ;
637
int adapt_mesh(const BDS_Metric & ,bool smooth = false,BDS_Mesh *geom = 0);
638
void compute_metric_edge_lengths(const BDS_Metric & metric);
420
void split_edge(BDS_Edge *, BDS_Point *);
421
bool edge_constraint ( BDS_Point *p1, BDS_Point *p2 );
422
bool recombine_edge ( BDS_Edge *e );
640
bool extractVolumes();
425
void recombineIntoQuads (const double angle, GFace *gf);
643
bool read_stl(const char *filename, const double tolerance);
645
bool read_mesh(const char *filename);
646
bool read_vrml(const char *filename);
647
void save_gmsh_format(const char *filename);
648
427
bool import_view(Post_View *view, const double tolerance);
649
void applyOptimizationPatterns();
652
bool project_point_on_a_list_of_triangles(BDS_Point *p , const std::list<BDS_Triangle*> &t,
653
double &X, double &Y, double &Z);
430
void outputScalarField(std::list < BDS_Face * >t, const char *fn, int param);
431
void recur_tag(BDS_Face * t, BDS_GeomEntity * g);