MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
GeometryIntersection< nDim_ >::CsgPlane Class Reference
Collaboration diagram for GeometryIntersection< nDim_ >::CsgPlane:
[legend]

Public Member Functions

 CsgPlane ()=default
 
 CsgPlane (CsgVector _normal, MFloat _w)
 
template<class T = CsgVector>
std::enable_if< nDim_==2, T >::type initPlane (CsgVector abc[nDim]) const
 
template<class T = CsgVector>
std::enable_if< nDim_==3, T >::type initPlane (CsgVector abc[nDim]) const
 
 CsgPlane (CsgVector abc[nDim])
 
 ~CsgPlane ()=default
 
CsgPlane clone ()
 
void flip ()
 
template<class T = void>
std::enable_if< nDim_==2, T >::type splitPolygon (CsgPolygon *polygon, std::vector< CsgPolygon > *coplanarFront, std::vector< CsgPolygon > *coplanarBack, std::vector< CsgPolygon > *front, std::vector< CsgPolygon > *back)
 
template<class T = void>
std::enable_if< nDim_==3, T >::type splitPolygon (CsgPolygon *polygon, std::vector< CsgPolygon > *coplanarFront, std::vector< CsgPolygon > *coplanarBack, std::vector< CsgPolygon > *front, std::vector< CsgPolygon > *back)
 
void insertCoplanarPolygon (CsgPolygon *polygon, std::vector< CsgPolygon > *coplanarFront, std::vector< CsgPolygon > *coplanarBack)
 

Public Attributes

CsgVector normal {}
 
MFloat w {}
 

Static Public Attributes

static constexpr MFloat eps = (nDim == 3) ? 10000 * MFloatEps : 1000 * MFloatEps
 

Detailed Description

template<MInt nDim_>
class GeometryIntersection< nDim_ >::CsgPlane

Definition at line 502 of file geometryintersection.h.

Constructor & Destructor Documentation

◆ CsgPlane() [1/3]

template<MInt nDim_>
GeometryIntersection< nDim_ >::CsgPlane::CsgPlane ( )
default

◆ CsgPlane() [2/3]

template<MInt nDim_>
GeometryIntersection< nDim_ >::CsgPlane::CsgPlane ( CsgVector  _normal,
MFloat  _w 
)
inline

Definition at line 510 of file geometryintersection.h.

◆ CsgPlane() [3/3]

template<MInt nDim_>
GeometryIntersection< nDim_ >::CsgPlane::CsgPlane ( CsgVector  abc[nDim])
inlineexplicit

Definition at line 523 of file geometryintersection.h.

523 {
524 CsgVector tmp = initPlane(abc);
525 IF_CONSTEXPR(nDim == 3) { normal = tmp; }
526 else IF_CONSTEXPR(nDim == 2) {
527 normal.xx[0] = -tmp.xx[1];
528 normal.xx[1] = tmp.xx[0];
529 }
530 w = normal.dot(abc[0]);
531 }
std::enable_if< nDim_==2, T >::type initPlane(CsgVector abc[nDim]) const
std::array< MFloat, nDim > xx
MFloat dot(const CsgVector &a) const
static constexpr MInt nDim

◆ ~CsgPlane()

template<MInt nDim_>
GeometryIntersection< nDim_ >::CsgPlane::~CsgPlane ( )
default

Member Function Documentation

◆ clone()

template<MInt nDim_>
CsgPlane GeometryIntersection< nDim_ >::CsgPlane::clone ( )
inline

Definition at line 533 of file geometryintersection.h.

533 {
534 CsgPlane tmp(this->normal, this->w);
535 return tmp;
536 }

◆ flip()

template<MInt nDim_>
void GeometryIntersection< nDim_ >::CsgPlane::flip ( )
inline

Definition at line 537 of file geometryintersection.h.

537 {
538 this->normal.negate();
539 this->w = -this->w;
540 }

◆ initPlane() [1/2]

template<MInt nDim_>
template<class T = CsgVector>
std::enable_if< nDim_==2, T >::type GeometryIntersection< nDim_ >::CsgPlane::initPlane ( CsgVector  abc[nDim]) const
inline

Definition at line 513 of file geometryintersection.h.

513 {
514 CsgVector tmp = abc[1].minus(abc[0]).unit();
515 return tmp;
516 }

◆ initPlane() [2/2]

template<MInt nDim_>
template<class T = CsgVector>
std::enable_if< nDim_==3, T >::type GeometryIntersection< nDim_ >::CsgPlane::initPlane ( CsgVector  abc[nDim]) const
inline

Definition at line 519 of file geometryintersection.h.

519 {
520 CsgVector tmp = abc[1].minus(abc[0]).cross(abc[2].minus(abc[0])).unit();
521 return tmp;
522 }

◆ insertCoplanarPolygon()

template<MInt nDim_>
void GeometryIntersection< nDim_ >::CsgPlane::insertCoplanarPolygon ( CsgPolygon polygon,
std::vector< CsgPolygon > *  coplanarFront,
std::vector< CsgPolygon > *  coplanarBack 
)
inline

Definition at line 675 of file geometryintersection.h.

677 {
678 ASSERT(!(std::isnan(polygon->plane.normal.xx[0])), "");
679 (this->normal.dot((polygon->plane.normal)) > F0 ? coplanarFront : coplanarBack)->push_back(*polygon);
680 }

◆ splitPolygon() [1/2]

template<MInt nDim_>
template<class T = void>
std::enable_if< nDim_==2, T >::type GeometryIntersection< nDim_ >::CsgPlane::splitPolygon ( CsgPolygon polygon,
std::vector< CsgPolygon > *  coplanarFront,
std::vector< CsgPolygon > *  coplanarBack,
std::vector< CsgPolygon > *  front,
std::vector< CsgPolygon > *  back 
)
inline

Definition at line 543 of file geometryintersection.h.

547 {
548 const MInt COPLANAR = 0;
549 const MInt FRONT = 1;
550 const MInt BACK = 2;
551 const MInt SPANNING = 3;
552
553 MInt polygonType = 0;
554 std::vector<MInt> types;
555
556 for(MInt i = 0; (unsigned)i < polygon->vertices.size(); i++) {
557 MFloat t = this->normal.dot((polygon->vertices[i].pos)) - this->w;
558 MInt type = (t < -eps) ? BACK : (t > eps) ? FRONT : COPLANAR;
559 polygonType |= type;
560 types.push_back(type);
561 }
562
563 switch(polygonType) {
564 case COPLANAR:
565 (this->normal.dot((polygon->plane.normal)) > F0 ? coplanarFront : coplanarBack)->push_back(*polygon);
566 break;
567 case FRONT:
568 front->push_back(*polygon);
569 break;
570 case BACK:
571 back->push_back(*polygon);
572 break;
573 case SPANNING: {
574 std::vector<CsgVertex> f;
575 std::vector<CsgVertex> b;
576 MInt i = 0;
577 MInt j = 1;
578 MInt ti = types[i], tj = types[j];
579 CsgVertex vi = polygon->vertices[i];
580 CsgVertex vj = polygon->vertices[j];
581 if(ti != BACK) f.push_back(vi);
582 if(ti != FRONT) b.push_back(ti != BACK ? vi.clone() : vi);
583 if((ti | tj) == SPANNING) {
584 MFloat t = (this->w - this->normal.dot((vi.pos))) / this->normal.dot(vj.pos.minus((vi.pos)));
585 CsgVertex v = vi.interpolate(&vj, t);
586 f.push_back(v);
587 b.push_back(v.clone());
588 }
589 if(tj != BACK) f.push_back(vj);
590 if(tj != FRONT) b.push_back(tj != BACK ? vj.clone() : vj);
591 if(f.size() >= 2)
592 front->push_back(
593 CsgPolygon(f, polygon->setIndex, polygon->faceId, polygon->faceType, polygon->bodyId, polygon->plane));
594 if(b.size() >= 2)
595 back->push_back(
596 CsgPolygon(b, polygon->setIndex, polygon->faceId, polygon->faceType, polygon->bodyId, polygon->plane));
597 } break;
598 default:
599 break;
600 }
601 }
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52

◆ splitPolygon() [2/2]

template<MInt nDim_>
template<class T = void>
std::enable_if< nDim_==3, T >::type GeometryIntersection< nDim_ >::CsgPlane::splitPolygon ( CsgPolygon polygon,
std::vector< CsgPolygon > *  coplanarFront,
std::vector< CsgPolygon > *  coplanarBack,
std::vector< CsgPolygon > *  front,
std::vector< CsgPolygon > *  back 
)
inline

Definition at line 604 of file geometryintersection.h.

608 {
609 const MInt COPLANAR = 0;
610 const MInt FRONT = 1;
611 const MInt BACK = 2;
612 const MInt SPANNING = 3;
613
614 MInt polygonType = 0;
615 std::vector<MInt> types;
616
617 // test normals for equivalence
618 MBool normalsEqual = false;
619 if(std::abs(std::abs(this->normal.xx[0]) - std::abs(polygon->plane.normal.xx[0])) < MFloatEps
620 && std::abs(std::abs(this->normal.xx[1]) - std::abs(polygon->plane.normal.xx[1])) < MFloatEps
621 && std::abs(std::abs(this->normal.xx[2]) - std::abs(polygon->plane.normal.xx[2])) < MFloatEps)
622 normalsEqual = true;
623
624 MBool coplanarVertex = false;
625 for(MInt i = 0; (unsigned)i < polygon->vertices.size(); i++) {
626 MFloat t = this->normal.dot((polygon->vertices[i].pos)) - this->w;
627 MInt type = (t < -eps) ? BACK : (t > eps) ? FRONT : COPLANAR;
628 polygonType |= type;
629 types.push_back(type);
630 if(type == 0) coplanarVertex = true;
631 }
632 ASSERT(!(std::isnan(polygon->plane.normal.xx[0])), "");
633
634 if(normalsEqual && coplanarVertex) polygonType = COPLANAR;
635
636 switch(polygonType) {
637 case COPLANAR:
638 (this->normal.dot((polygon->plane.normal)) > F0 ? coplanarFront : coplanarBack)->push_back(*polygon);
639 break;
640 case FRONT:
641 front->push_back(*polygon);
642 break;
643 case BACK:
644 back->push_back(*polygon);
645 break;
646 case SPANNING: {
647 std::vector<CsgVertex> f;
648 std::vector<CsgVertex> b;
649 for(MInt i = 0; (unsigned)i < polygon->vertices.size(); i++) {
650 MInt j = (i + 1) % polygon->vertices.size();
651 MInt ti = types[i], tj = types[j];
652 CsgVertex vi = polygon->vertices[i];
653 CsgVertex vj = polygon->vertices[j];
654 if(ti != BACK) f.push_back(vi);
655 if(ti != FRONT) b.push_back(ti != BACK ? vi.clone() : vi);
656 if((ti | tj) == SPANNING) {
657 MFloat t = (this->w - this->normal.dot((vi.pos))) / this->normal.dot(vj.pos.minus((vi.pos)));
658 CsgVertex v = vi.interpolate(&vj, t);
659 f.push_back(v);
660 b.push_back(v.clone());
661 }
662 }
663 if(f.size() >= 3)
664 front->push_back(
665 CsgPolygon(f, polygon->setIndex, polygon->faceId, polygon->faceType, polygon->bodyId, polygon->plane));
666 if(b.size() >= 3)
667 back->push_back(
668 CsgPolygon(b, polygon->setIndex, polygon->faceId, polygon->faceType, polygon->bodyId, polygon->plane));
669 } break;
670 default:
671 break;
672 }
673 }
bool MBool
Definition: maiatypes.h:58

Member Data Documentation

◆ eps

template<MInt nDim_>
constexpr MFloat GeometryIntersection< nDim_ >::CsgPlane::eps = (nDim == 3) ? 10000 * MFloatEps : 1000 * MFloatEps
staticconstexpr

Definition at line 504 of file geometryintersection.h.

◆ normal

template<MInt nDim_>
CsgVector GeometryIntersection< nDim_ >::CsgPlane::normal {}

Definition at line 506 of file geometryintersection.h.

◆ w

template<MInt nDim_>
MFloat GeometryIntersection< nDim_ >::CsgPlane::w {}

Definition at line 507 of file geometryintersection.h.


The documentation for this class was generated from the following file: