 |
ATLAS Offline Software
|
Go to the documentation of this file.
113 #define sqr(t) (t)*(t)
122 typedef std::map<unsigned int, Linebase*>
LineMap;
123 typedef std::priority_queue<Pointbase>
PQueue;
129 typedef std::map<unsigned int, std::set<unsigned int> >
AdjEdgeMap;
273 #define Absolute(a) ((a) >= 0.0 ? (a) : -(a))
289 #define Fast_Two_Sum_Tail(a, b, x, y) \
293 #define Fast_Two_Sum(a, b, x, y) \
294 x = (REAL) (a + b); \
295 Fast_Two_Sum_Tail(a, b, x, y)
297 #define Two_Sum_Tail(a, b, x, y) \
298 bvirt = (REAL) (x - a); \
300 bround = b - bvirt; \
301 around = a - avirt; \
304 #define Two_Sum(a, b, x, y) \
305 x = (REAL) (a + b); \
306 Two_Sum_Tail(a, b, x, y)
308 #define Two_Diff_Tail(a, b, x, y) \
309 bvirt = (REAL) (a - x); \
311 bround = bvirt - b; \
312 around = a - avirt; \
315 #define Two_Diff(a, b, x, y) \
316 x = (REAL) (a - b); \
317 Two_Diff_Tail(a, b, x, y)
322 #define Split(a, ahi, alo) \
323 c = (REAL) (1.0 * a); \
324 abig = (REAL) (c - a); \
328 #define Two_Product_Tail(a, b, x, y) \
329 Split(a, ahi, alo); \
330 Split(b, bhi, blo); \
331 err1 = x - (ahi * bhi); \
332 err2 = err1 - (alo * bhi); \
333 err3 = err2 - (ahi * blo); \
334 y = (alo * blo) - err3
336 #define Two_Product(a, b, x, y) \
337 x = (REAL) (a * b); \
338 Two_Product_Tail(a, b, x, y)
343 #define Two_One_Diff(a1, a0, b, x2, x1, x0) \
344 Two_Diff(a0, b , x_i, x0); \
345 Two_Sum( a1, x_i, x2, x1)
347 #define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \
348 Two_One_Diff(a1, a0, b0, x_j, x_0, x0); \
349 Two_One_Diff(x_j, x_0, b1, x3, x2, x1)
382 REAL avirt, bround, around;
383 int eindex, findex, hindex;
389 if ((fnow > enow) == (fnow > -enow)) {
397 if ((eindex < elen) && (findex < flen)) {
398 if ((fnow > enow) == (fnow > -enow)) {
409 while ((eindex < elen) && (findex < flen)) {
410 if ((fnow > enow) == (fnow > -enow)) {
423 while (eindex < elen) {
431 while (findex < flen) {
439 if ((Q != 0.0) || (hindex == 0)) {
460 for (eindex = 1; eindex < elen; ++eindex) {
495 REAL acxtail, acytail, bcxtail, bcytail;
497 REAL detlefttail, detrighttail;
499 REAL B[4], C1[8], C2[12], D[16];
501 int C1length, C2length, Dlength;
508 REAL avirt, bround, around;
511 REAL ahi, alo, bhi, blo;
512 REAL err1, err2, err3;
516 acx = (
REAL) (pa[0] -
pc[0]);
518 acy = (
REAL) (pa[1] -
pc[1]);
524 Two_Two_Diff(detleft, detlefttail, detright, detrighttail,
525 B3,
B[2],
B[1],
B[0]);
531 if ((
det >= errbound) || (-
det >= errbound)) {
540 if ((acxtail == 0.0) && (acytail == 0.0)
541 && (bcxtail == 0.0) && (bcytail == 0.0)) {
547 det += (acx * bcytail + bcy * acxtail)
548 - (acy * bcxtail + bcx * acytail);
549 if ((
det >= errbound) || (-
det >= errbound)) {
571 return(D[Dlength - 1]);
577 REAL detsum, errbound;
579 detleft = (pa[0] -
pc[0]) * (
pb[1] -
pc[1]);
580 detright = (pa[1] -
pc[1]) * (
pb[0] -
pc[0]);
581 det = detleft - detright;
584 if (detright <= 0.0) {
587 detsum = detleft + detright;
589 }
else if (detleft < 0.0) {
590 if (detright >= 0.0) {
593 detsum = -detleft - detright;
601 if ((
det >= errbound) || (-
det >= errbound)) {
634 template <
class T,
class KeyType>
637 template <
class T,
class KeyType>
662 template <
class T,
class KeyType>
731 template <
class T,
class KeyType>
740 template <
class T,
class KeyType>
749 template <
class T,
class KeyType>
759 m_root = newNode; ++m_size;
763 KeyType
keys=
x->keyValue();
764 splay(
keys, m_root );
765 KeyType rootk=m_root->keyValue();
774 else if(
keys > rootk )
788 x->increaseKeyValue(1.0
e-10);
798 template <
class T,
class KeyType>
803 splay(
keys, m_root );
804 if( m_root->keyValue() !=
keys ) {
res=NULL;
return; }
808 if( m_root->m_left == NULL )
816 newTree->m_right = m_root->m_right;
826 template <
class T,
class KeyType>
831 splay(
keys, m_root );
832 KeyType rootk=m_root->keyValue();
833 if( rootk !=
keys ) {
return; }
835 if( m_root->m_left == NULL )
newTree = m_root->m_right;
842 newTree->m_right = m_root->m_right;
855 template <
class T,
class KeyType>
858 if( IsEmpty( ) ) {
min=NULL;
return; }
861 splay(
keys, m_root );
866 if( m_root->m_left == NULL )
newTree = m_root->m_right;
871 newTree->m_right = m_root->m_right;
882 template <
class T,
class KeyType>
885 if( IsEmpty( ) ) {
max=NULL;
return; }
888 splay(
keys, m_root );
893 if( m_root->m_left == NULL )
newTree = m_root->m_right;
898 newTree->m_right = m_root->m_right;
908 template <
class T,
class KeyType>
911 if( IsEmpty( ) ) {
min=NULL;
return; }
914 while(
ptr->m_left != NULL )
ptr =
ptr->m_left;
915 splay(
ptr->keyValue(), m_root );
922 template <
class T,
class KeyType>
925 if( IsEmpty( ) ) {
max=NULL;
return; }
928 while(
ptr->m_right != NULL )
ptr =
ptr->m_right;
929 splay(
ptr->keyValue(), m_root );
937 template <
class T,
class KeyType>
940 if( IsEmpty( ) ) {
res=NULL;
return; }
941 splay(
keys, m_root );
942 if( m_root->keyValue() !=
keys ) {
res=NULL;
return; }
951 template <
class T,
class KeyType>
954 if( IsEmpty( ) ) {
res=NULL;
return; }
955 splay(
keys, m_root );
957 if( m_root->data()->keyValue() <
keys)
res=m_root;
958 else if(m_root->m_left)
972 template <
class T,
class KeyType>
986 template <
class T,
class KeyType>
989 return m_root == NULL;
995 template <
class T,
class KeyType>
1013 template <
class T,
class KeyType>
1021 leftTreeMax = rightTreeMin = &
header;
1025 KeyType rkey=
t->keyValue();
1028 if(
t->m_left == NULL)
break;
1029 if( keys < t->m_left->keyValue() ) rotateWithLeftChild(
t );
1030 if(
t->m_left == NULL )
break;
1037 else if(
keys > rkey )
1039 if(
t->m_right == NULL )
break;
1040 if(
keys >
t->m_right->keyValue() ) rotateWithRightChild(
t );
1041 if(
t->m_right == NULL )
break;
1052 rightTreeMin->
m_left =
t->m_right;
1061 template <
class T,
class KeyType>
1073 template <
class T,
class KeyType>
1086 template <
class T,
class KeyType>
1089 if(
t !=
t->m_left )
1091 reclaimMemory(
t->m_left );
1092 reclaimMemory(
t->m_right );
1101 template <
class T,
class KeyType>
1104 if(
t ==
t->m_left )
1113 template<
class T,
class KeyType>
1119 PreOrder(Visit,
t->m_left);
1120 PreOrder(Visit,
t->m_right);
1128 template<
class T,
class KeyType>
1133 InOrder(Visit,
t->m_left);
1135 InOrder(Visit,
t->m_right);
1143 template<
class T,
class KeyType>
1149 InOrder(Visit,
t->m_left,
y);
1151 InOrder(Visit,
t->m_right,
y);
1160 template<
class T,
class KeyType>
1165 PostOrder(Visit,
t->m_left);
1166 PostOrder(Visit,
t->m_right);
1174 template<
class T,
class KeyType>
1177 if(subtree==NULL)
return 0;
1179 int rh=Height(subtree->
m_right);
1181 return (
lh>rh)?(++
lh):(++rh);
1327 node->data()->setKeyValue(
y);
1347 return (pa.
x==
pb.x && pa.
y==
pb.y);
1353 return( (pa.
y >
pb.y) || ( (pa.
y==
pb.y) && (pa.
x <
pb.x)) );
1359 return( (pa.
y <
pb.y) || ( (pa.
y==
pb.y) && (pa.
x >
pb.x)) );
1365 return !(pa.
x==
pb.x && pa.
y==
pb.y);
1425 Polygon(
const std::vector<double>&
x,
const std::vector<double>&
y);
1443 void set_contour (
const std::vector<double>&
x,
const std::vector<double>&
y);
1447 unsigned int prev(
const unsigned int&
i);
1448 unsigned int next(
const unsigned int&
i);
1459 void addDiagonal(
const unsigned int&
i,
const unsigned int& j);
1526 assert(
x.size()==
y.size());
1528 m_nVertices.push_back(
x.size() );
1529 unsigned int i = m_points.size()+1;
1532 for (
unsigned int j = 0; j < m_nVertices[m_ncontours]; ++j, ++
i)
1538 if(
xx > m_xmax ) m_xmax=
xx;
1539 if(
xx < m_xmin ) m_xmin=
xx;
1540 if(
yy > m_ymax ) m_ymax=
yy;
1541 if(
yy < m_ymin ) m_ymin=
yy;
1560 m_xmin = m_ymin = std::numeric_limits<double>::infinity();
1561 m_xmax = m_ymax = - std::numeric_limits<double>::infinity();
1565 init_vertices_and_lines();
1576 for(;
itp!=m_points.end(); ++
itp)
1582 for(; itl!=m_edges.end(); ++itl)
1594 unsigned int j(0),prevLoop(0),currentLoop(0);
1596 while (
i > m_nVertices[currentLoop] )
1598 prevLoop=currentLoop;
1602 if(
i==1 || (
i==m_nVertices[prevLoop]+1) ) j=m_nVertices[currentLoop];
1603 else if(
i <= m_nVertices[currentLoop] ) j=
i-1;
1613 unsigned int j(0),prevLoop(0),currentLoop(0);
1615 while (
i > m_nVertices[currentLoop] )
1617 prevLoop=currentLoop;
1621 if(
i < m_nVertices[currentLoop] ) j=
i+1;
1622 else if (
i==m_nVertices[currentLoop] )
1624 if( currentLoop==0) j=1;
1625 else j=m_nVertices[prevLoop]+1;
1641 for(;
it!=m_points.end(); ++
it)
1648 if(
p > pnext && pprev >
p )
1650 else if (
p > pprev && pnext >
p)
1654 double pa[2],
pb[2],
pc[2];
1656 pa[0]=m_points[idp]->x;
1657 pa[1]=m_points[idp]->y;
1659 pb[0]=m_points[
id]->x;
1660 pb[1]=m_points[
id]->y;
1662 pc[0]=m_points[idn]->x;
1663 pc[1]=m_points[idn]->y;
1672 m_qpoints.push(*(
it->second));
1674 m_startAdjEdgeMap[
id].insert(
id);
1686 m_edges[diag->
id()]=diag;
1688 m_startAdjEdgeMap[
i].insert(diag->
id());
1689 m_startAdjEdgeMap[j].insert(diag->
id());
1691 m_diagonals[diag->
id()]=diag;
1700 double y=m_points[
i]->y;
1703 m_edges[
i]->setHelper(
i);
1704 m_edges[
i]->setKeyValue(
y);
1705 m_edgebst.Insert(m_edges[
i]);
1714 double y=m_points[
i]->y;
1717 unsigned int previ=prev(
i);
1719 unsigned int helper=m_edges[previ]->helper();
1723 m_edgebst.Delete(edge->
keyValue());
1732 double x=m_points[
i]->x,
y=m_points[
i]->y;
1736 m_edgebst.FindMaxSmallerThan(
x, leftnode);
1743 m_edges[
i]->setHelper(
i);
1744 m_edges[
i]->setKeyValue(
y);
1745 m_edgebst.Insert(m_edges[
i]);
1753 double x=m_points[
i]->x,
y=m_points[
i]->y;
1756 unsigned int previ=prev(
i);
1757 unsigned int helper=m_edges[previ]->helper();
1759 m_edgebst.Delete(m_edges[previ]->
keyValue());
1762 m_edgebst.FindMaxSmallerThan(
x, leftnode);
1776 double y=m_points[
i]->y;
1779 unsigned int previ=prev(
i);
1780 unsigned int helper=m_edges[previ]->helper();
1783 m_edgebst.Delete(m_edges[previ]->
keyValue());
1784 m_edges[
i]->setHelper(
i);
1785 m_edges[
i]->setKeyValue(
y);
1786 m_edgebst.Insert(m_edges[
i]);
1795 double x=m_points[
i]->x,
y=m_points[
i]->y;
1799 m_edgebst.FindMaxSmallerThan(
x, leftnode);
1817 std::cout<<
"Please check your input polygon:\n1)orientations?\n2)duplicated points?\n";
1821 while(!m_qpoints.empty())
1825 unsigned int id=
vertex.id;
1836 std::cout<<
"No duplicated points please!\n";
1852 double dxab = pa[0] -
pb[0];
1853 double dyab = pa[1] -
pb[1];
1855 double dxcb =
pc[0] -
pb[0];
1856 double dycb =
pc[1] -
pb[1];
1858 double dxab2 = dxab * dxab;
1859 double dyab2 = dyab * dyab;
1860 double dxcb2 = dxcb * dxcb;
1861 double dycb2 = dycb * dycb;
1862 double ab = dxab2 + dyab2;
1863 double cb = dxcb2 + dycb2;
1865 double cosb = dxab * dxcb + dyab * dycb;
1866 double denom = sqrt( ab * cb);
1881 std::set<unsigned int> edges=m_startAdjEdgeMap[eid];
1882 assert(!edges.empty());
1884 unsigned int nexte=0;
1885 if( edges.size() == 1 ) nexte=*(edges.begin());
1886 else if( edges.size() > 1 )
1888 unsigned int nexte_ccw(0), nexte_cw(0);
1893 for(;
it!=edges.end(); ++
it)
1895 if(*
it==edge->
id())
continue;
1896 double A[2],
B[2],
C[2];
1900 if(edge->
endPoint(1)!=m_edges[*
it]->endPoint(0)) m_edges[*
it]->reverse();
1901 C[0]=m_edges[*
it]->endPoint(1)->x;
C[1]=m_edges[*
it]->endPoint(1)->y;
1904 double cosb=angleCosb(
A,
B,
C);
1906 if(
area > 0 &&
max < cosb ) { nexte_ccw=*
it;
max=cosb; }
1907 else if(
min > cosb ) { nexte_cw=*
it;
min=cosb; }
1910 nexte = (nexte_ccw!=0) ? nexte_ccw : nexte_cw;
1923 while( edges.size() > m_diagonals.size() )
1931 poly.push_back(startp->
id);
1935 endp=
next->endPoint(1);
1938 edges.erase(
next->id());
1939 m_startAdjEdgeMap[
next->endPoint(0)->id].erase(
next->id());
1941 if(endp==startp)
break;
1942 poly.push_back(endp->
id);
1944 unsigned int nexte=selectNextEdge(
next);
1948 std::cout<<
"Please check your input polygon:\n";
1949 std::cout<<
"1)orientations?\n2)with duplicated points?\n3)is a simple one?\n";
1954 if(
next->endPoint(0) !=endp )
next->reverse();
1957 m_mpolys.push_back(std::move(
poly));
1969 for(; itnext=
it,
it!=mpoly.end(); ++
it)
1972 if(itnext==mpoly.end()) itnext=mpoly.begin();
1974 point.
left=(point > pointnext)?
true:
false;
1975 qvertex.push(point);
1978 std::stack<internal_poltrig::Pointbase> spoint;
1979 for(
int i=0;
i<2; ++
i) { spoint.push(qvertex.top()); qvertex.pop(); }
1981 while ( qvertex.size() > 1 )
1986 if(topQueuePoint.
left!=topStackPoint.
left)
1988 while ( spoint.size() > 1 )
1994 v[0]=topQueuePoint.
id;
1997 sort(
v.begin(),
v.end());
1998 m_triangles.push_back(std::move(
v));
2002 spoint.push(topStackPoint);
2003 spoint.push(topQueuePoint);
2007 while( spoint.size() > 1 )
2012 spoint.push(stack1Point);
2013 double pa[2],
pb[2],
pc[2];
2014 pa[0]=topQueuePoint.
x; pa[1]=topQueuePoint.
y;
2015 pb[0]=stack2Point.
x;
pb[1]=stack2Point.
y;
2016 pc[0]=stack1Point.
x;
pc[1]=stack1Point.
y;
2019 bool left=stack1Point.
left;
2020 if( (
area > 0 && left) || (
area < 0 && !left ) )
2023 v[0]=topQueuePoint.
id;
2024 v[1]=stack2Point.
id;
2025 v[2]=stack1Point.
id;
2026 sort(
v.begin(),
v.end());
2027 m_triangles.push_back(std::move(
v));
2032 spoint.push(topQueuePoint);
2041 while( spoint.size() !=1 )
2048 v[0]=lastQueuePoint.
id;
2051 sort(
v.begin(),
v.end());
2052 m_triangles.push_back(std::move(
v));
2061 partition2Monotone();
2064 for(;
it!=m_mpolys.end(); ++
it)
2065 triangulateMonotone(*
it);
2076 const std::vector<double>& polygon_ycoords)
JetConstituentVector::iterator iterator
void Find(const KeyType &keys, BTreeNode< T, KeyType > *&res)
void InOrder(void(*Visit)(BTreeNode< T, KeyType > *u, double y), double y)
const Triangles * triangles()
std::map< unsigned int, Linebase * > LineMap
#define Two_Product(a, b, x, y)
void PostOrder(void(*Visit)(BTreeNode< T, KeyType > *u))
unsigned int next(const unsigned int &i)
std::list< Monopoly > Monopolys
std::map< unsigned int, Pointbase * > PointbaseMap
BTreeNode< T, KeyType > * clone(BTreeNode< T, KeyType > *t) const
void DeleteMin(BTreeNode< T, KeyType > *&min)
std::list< Triangle > Triangles
std::vector< unsigned int > Triangle
void Delete(const KeyType &keys)
Pointbase(const double &xx, const double &yy)
internal_poltrig::PQueue m_qpoints
const Triangles * triangles() const
std::vector< ALFA_RawData_p1 > t0
internal_poltrig::EdgeBST m_edgebst
std::vector< ALFA_RawDataCollection_p1 > t1
void handleMergeVertex(const unsigned int &)
void set_contour(const std::vector< double > &x, const std::vector< double > &y)
BTreeNode< T, KeyType > * Right(BTreeNode< T, KeyType > *node)
std::list< Triangle > Triangles
internal_poltrig::LineMap m_edges
std::map< unsigned int, std::set< unsigned int > > AdjEdgeMap
std::priority_queue< Pointbase > PQueue
void handleStartVertex(const unsigned int &)
double dist_sqr(const Pointbase &sp, const Pointbase &ep)
BTreeNode(const T &data, BTreeNode *lt, BTreeNode *rt)
REAL orient2d(REAL *pa, REAL *pb, REAL *pc)
void triangulateMonotone(internal_poltrig::Monopoly &mpoly)
bool operator!=(const Pointbase &pa, const Pointbase &pb)
internal_poltrig::AdjEdgeMap m_startAdjEdgeMap
Pointbase * endPoint(const int &i) const
void handleEndVertex(const unsigned int &)
#define Two_Sum(a, b, x, y)
BTreeNode< T, KeyType > * Left(BTreeNode< T, KeyType > *node)
@ u
Enums for curvilinear frames.
void PreOrder(void(*Visit)(BTreeNode< T, KeyType > *u))
void InOrder(void(*Visit)(BTreeNode< T, KeyType > *u))
friend bool operator==(const Pointbase &, const Pointbase &)
void init_vertices_and_lines()
PolygonTriangulator(const std::vector< double > &polygon_xcoords, const std::vector< double > &polygon_ycoords)
constexpr double poly(const double x)
Evaluates the n-th Legendre polynomial at x.
void FindMaxSmallerThan(const KeyType &keys, BTreeNode< T, KeyType > *&res)
internal_poltrig::Monopolys m_mpolys
void partition2Monotone()
double angleCosb(double *A, double *B, double *C)
void setKeyValue(const double &y)
internal_poltrig::PointbaseMap m_points
bool operator>(const Pointbase &pa, const Pointbase &pb)
Pointbase(const int &idd, const double &xx, const double &yy)
void UpdateKey(BTreeNode< Linebase *, double > *node, double y)
BTreeNode< T, KeyType > * Root()
unsigned int selectNextEdge(internal_poltrig::Linebase *edge)
std::pair< std::vector< unsigned int >, bool > res
void handleSplitVertex(const unsigned int &)
void increaseKeyValue(const double &diff)
void SetVisited(const bool &visited)
REAL estimate(const int &elen, REAL *e)
BTreeNode< T, KeyType > * m_root
internal_poltrig::PointbaseMap & points()
void rotateWithRightChild(BTreeNode< T, KeyType > *&k1) const
unsigned int prev(const unsigned int &i)
void FindMax(BTreeNode< T, KeyType > *&max)
bool operator==(const Pointbase &pa, const Pointbase &pb)
const SplayTree & operator=(const SplayTree &rhs)
#define Fast_Two_Sum(a, b, x, y)
internal_poltrig::LineMap & edges()
void addDiagonal(const unsigned int &i, const unsigned int &j)
REAL orient2dadapt(REAL *pa, REAL *pb, REAL *pc, const REAL &detsum)
Pointbase(const double &xx, const double &yy, const Type &ttype)
#define Two_Diff_Tail(a, b, x, y)
Pointbase(const int &idd, const double &xx, const double &yy, const Type &ttype)
std::list< unsigned int > Monopoly
void InOrder(void(*Visit)(BTreeNode< T, KeyType > *, double y), BTreeNode< T, KeyType > *t, double y)
int fast_expansion_sum_zeroelim(const int &elen, REAL *e, const int &flen, REAL *f, REAL *h)
#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0)
void newTree(MVAUtils::ForestTMVA *forest, const TMVA::DecisionTreeNode *node, float weight, bool isRegression, bool useYesNoLeaf)
void DeleteMax(BTreeNode< T, KeyType > *&max)
friend bool operator!=(const Pointbase &, const Pointbase &)
Linebase & operator=(const Linebase &)=delete
SplayTree< Linebase *, double > EdgeBST
Polygon(const std::vector< double > &x, const std::vector< double > &y)
Pointbase & operator=(const Pointbase &)=default
friend bool operator>(const Pointbase &, const Pointbase &)
bool operator<(const Pointbase &pa, const Pointbase &pb)
void rotateWithLeftChild(BTreeNode< T, KeyType > *&k2) const
void reclaimMemory(BTreeNode< T, KeyType > *t) const
std::vector< unsigned int > m_nVertices
internal_poltrig::LineMap m_diagonals
void setHelper(const unsigned int &i)
std::vector< unsigned > Triangle
void splay(const KeyType &keys, BTreeNode< T, KeyType > *&t) const
void handleRegularVertexDown(const unsigned int &)
void FindMin(BTreeNode< T, KeyType > *&min)
void handleRegularVertexUp(const unsigned int &)
friend bool operator<(const Pointbase &, const Pointbase &)