1 /****************************************************************************
2 **
3 ** Copyright (c) 2008-2020 C.B. Barber. All rights reserved.
4 ** $Id: //main/2019/qhull/src/libqhullcpp/QhullFacetList.h#3 $$Change: 3001 $
5 ** $DateTime: 2020/07/24 20:43:28 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #ifndef QHULLFACETLIST_H
10 #define QHULLFACETLIST_H
11 
12 #include "libqhullcpp/QhullLinkedList.h"
13 #include "libqhullcpp/QhullFacet.h"
14 
15 #include <ostream>
16 
17 #ifndef QHULL_NO_STL
18 #include <vector>
19 #endif
20 
21 namespace orgQhull {
22 
23 #//!\name Used here
24     class Qhull;
25     class QhullFacet;
26     class QhullQh;
27 
28 #//!\name Defined here
29     //! QhullFacetList -- List of QhullFacet/facetT, as a C++ class.
30     //!\see QhullFacetSet.h
31     class QhullFacetList;
32     //! QhullFacetListIterator is a Java-style iterator for QhullFacetList. -- if(f.isGood()){ ... }
33     typedef QhullLinkedListIterator<QhullFacet> QhullFacetListIterator;
34 
35 class QhullFacetList : public QhullLinkedList<QhullFacet> {
36 
37 #//!\name  Fields
38 private:
39     bool                select_all;   //! True if include bad facets.  Default is false.
40 
41 #//!\name Constructors
42 public:
43                         QhullFacetList(const Qhull &q, facetT *b, facetT *e);
44                         QhullFacetList(QhullQh *qqh, facetT *b, facetT *e);
QhullFacetList(QhullFacet b,QhullFacet e)45                         QhullFacetList(QhullFacet b, QhullFacet e) : QhullLinkedList<QhullFacet>(b, e), select_all(false) {}
46                         //Copy constructor copies pointer but not contents.  Needed for return by value and parameter passing.
QhullFacetList(const QhullFacetList & other)47                         QhullFacetList(const QhullFacetList &other) : QhullLinkedList<QhullFacet>(*other.begin(), *other.end()), select_all(other.select_all) {}
48     QhullFacetList &    operator=(const QhullFacetList &other) { QhullLinkedList<QhullFacet>::operator =(other); select_all= other.select_all; return *this; }
~QhullFacetList()49                         ~QhullFacetList() {}
50 
51 private:                //!Disable default constructor.  See QhullLinkedList
52                         QhullFacetList();
53 public:
54 
55 #//!\name Conversion
56 #ifndef QHULL_NO_STL
57     std::vector<QhullFacet> toStdVector() const;
58     std::vector<QhullVertex> vertices_toStdVector() const;
59 #endif //QHULL_NO_STL
60 #ifdef QHULL_USES_QT
61     QList<QhullFacet>   toQList() const;
62     QList<QhullVertex>  vertices_toQList() const;
63 #endif //QHULL_USES_QT
64 
65 #//!\name GetSet
66                         //! Filtered by facet.isGood().  May be 0 when !isEmpty().
67     countT              count() const;
68     bool                contains(const QhullFacet &f) const;
69     countT              count(const QhullFacet &f) const;
isSelectAll()70     bool                isSelectAll() const { return select_all; }
qh()71     QhullQh *           qh() const { return first().qh(); }
selectAll()72     void                selectAll() { select_all= true; }
selectGood()73     void                selectGood() { select_all= false; }
74                         //!< operator==() does not depend on isGood()
75 
76 #//!\name IO
77     struct PrintFacetList{
78         const QhullFacetList *facet_list;
79         const char *    print_message;   //!< non-null message
PrintFacetListPrintFacetList80                         PrintFacetList(const QhullFacetList &fl, const char *message) : facet_list(&fl), print_message(message) {}
81     };//PrintFacetList
print(const char * message)82     PrintFacetList      print(const char *message) const  { return PrintFacetList(*this, message); }
83 
84     struct PrintFacets{
85         const QhullFacetList *facet_list;
PrintFacetsPrintFacets86                         PrintFacets(const QhullFacetList &fl) : facet_list(&fl) {}
87     };//PrintFacets
printFacets()88     PrintFacets         printFacets() const { return PrintFacets(*this); }
89 
90     struct PrintVertices{
91         const QhullFacetList *facet_list;
PrintVerticesPrintVertices92                         PrintVertices(const QhullFacetList &fl) : facet_list(&fl) {}
93     };//PrintVertices
printVertices()94     PrintVertices       printVertices() const { return PrintVertices(*this); }
95 };//class QhullFacetList
96 
97 }//namespace orgQhull
98 
99 #//!\name == Global namespace =========================================
100 
101 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacetList::PrintFacetList &p);
102 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacetList::PrintFacets &p);
103 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacetList::PrintVertices &p);
104 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacetList &fs);
105 
106 #endif // QHULLFACETLIST_H
107