1 /****************************************************************************
2 **
3 ** Copyright (c) 2008-2020 C.B. Barber. All rights reserved.
4 ** $Id: //main/2019/qhull/src/libqhullcpp/QhullFacetSet.cpp#2 $$Change: 2953 $
5 ** $DateTime: 2020/05/21 22:05:32 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #//! QhullFacetSet -- Qhull's linked facets, as a C++ class
10 
11 #include "libqhullcpp/QhullFacetSet.h"
12 
13 #include "libqhullcpp/QhullFacet.h"
14 #include "libqhullcpp/QhullPoint.h"
15 #include "libqhullcpp/QhullRidge.h"
16 #include "libqhullcpp/QhullVertex.h"
17 
18 #ifndef QHULL_NO_STL
19 using std::vector;
20 #endif
21 
22 #ifdef _MSC_VER  // Microsoft Visual C++ -- warning level 4
23 #pragma warning( disable : 4611)  // interaction between '_setjmp' and C++ object destruction is non-portable
24 #pragma warning( disable : 4996)  // function was declared deprecated(strcpy, localtime, etc.)
25 #endif
26 
27 namespace orgQhull {
28 
29 #//!\name Conversions
30 
31 // See qt-qhull.cpp for QList conversions
32 
33 #ifndef QHULL_NO_STL
34 std::vector<QhullFacet> QhullFacetSet::
toStdVector() const35 toStdVector() const
36 {
37     QhullSetIterator<QhullFacet> i(*this);
38     std::vector<QhullFacet> vs;
39     while(i.hasNext()){
40         QhullFacet f= i.next();
41         if(isSelectAll() || f.isGood()){
42             vs.push_back(f);
43         }
44     }
45     return vs;
46 }//toStdVector
47 #endif //QHULL_NO_STL
48 
49 #//!\name GetSet
50 
51 bool QhullFacetSet::
contains(const QhullFacet & facet) const52 contains(const QhullFacet &facet) const
53 {
54     if(isSelectAll()){
55         return QhullSet<QhullFacet>::contains(facet);
56     }
57     for(QhullFacetSet::const_iterator i=begin(); i != end(); ++i){
58         QhullFacet f= *i;
59         if(f==facet && f.isGood()){
60             return true;
61         }
62     }
63     return false;
64 }//contains
65 
66 int QhullFacetSet::
count() const67 count() const
68 {
69     if(isSelectAll()){
70         return QhullSet<QhullFacet>::count();
71     }
72     int counter= 0;
73     for(QhullFacetSet::const_iterator i=begin(); i != end(); ++i){
74         QhullFacet f= *i;
75         if(f.isGood()){
76             counter++;
77         }
78     }
79     return counter;
80 }//count
81 
82 int QhullFacetSet::
count(const QhullFacet & facet) const83 count(const QhullFacet &facet) const
84 {
85     if(isSelectAll()){
86         return QhullSet<QhullFacet>::count(facet);
87     }
88     int counter= 0;
89     for(QhullFacetSet::const_iterator i=begin(); i != end(); ++i){
90         QhullFacet f= *i;
91         if(f==facet && f.isGood()){
92             counter++;
93         }
94     }
95     return counter;
96 }//count
97 
98 }//namespace orgQhull
99 
100 #//!\name Global functions
101 
102 using std::endl;
103 using std::ostream;
104 using orgQhull::QhullFacet;
105 using orgQhull::QhullFacetSet;
106 
107 ostream &
operator <<(ostream & os,const QhullFacetSet & fs)108 operator<<(ostream &os, const QhullFacetSet &fs)
109 {
110     os << fs.print("");
111     return os;
112 }//<<QhullFacetSet
113 
114 ostream &
115 
operator <<(ostream & os,const QhullFacetSet::PrintFacetSet & pr)116 operator<<(ostream &os, const QhullFacetSet::PrintFacetSet &pr)
117 {
118     os << pr.print_message;
119     QhullFacetSet fs= *pr.facet_set;
120     for(QhullFacetSet::iterator i=fs.begin(); i != fs.end(); ++i){
121         QhullFacet f= *i;
122         if(fs.isSelectAll() || f.isGood()){
123             os << f;
124         }
125     }
126     return os;
127 }//<< QhullFacetSet::PrintFacetSet
128 
129 //! Print facet identifiers to stream.  Space prefix.  From qh_printfacetheader [io_r.c]
130 ostream &
operator <<(ostream & os,const QhullFacetSet::PrintIdentifiers & p)131 operator<<(ostream &os, const QhullFacetSet::PrintIdentifiers &p)
132 {
133     os << p.print_message;
134     for(QhullFacetSet::const_iterator i=p.facet_set->begin(); i!=p.facet_set->end(); ++i){
135         const QhullFacet f= *i;
136         if(f.getFacetT()==qh_MERGEridge){
137             os << " MERGE";
138         }else if(f.getFacetT()==qh_DUPLICATEridge){
139             os << " DUP";
140         }else if(p.facet_set->isSelectAll() || f.isGood()){
141             os << " f" << f.id();
142         }
143     }
144     os << endl;
145     return os;
146 }//<<QhullFacetSet::PrintIdentifiers
147 
148