1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (c) 2009-2012 C.B. Barber. All rights reserved.
|
---|
4 | ** $Id: //main/2011/qhull/src/libqhullcpp/QhullPointSet.h#6 $$Change: 1464 $
|
---|
5 | ** $DateTime: 2012/01/25 22:58:41 $$Author: bbarber $
|
---|
6 | **
|
---|
7 | ****************************************************************************/
|
---|
8 |
|
---|
9 | #ifndef QHULLPOINTSET_H
|
---|
10 | #define QHULLPOINTSET_H
|
---|
11 |
|
---|
12 | #include "QhullSet.h"
|
---|
13 | #include "QhullPoint.h"
|
---|
14 | extern "C" {
|
---|
15 | #include "libqhull/qhull_a.h"
|
---|
16 | }
|
---|
17 |
|
---|
18 | #include <ostream>
|
---|
19 |
|
---|
20 | namespace orgQhull {
|
---|
21 |
|
---|
22 | #//Types
|
---|
23 | //! QhullPointSet -- a set of coordinate pointers with dimension
|
---|
24 | // with const_iterator and iterator
|
---|
25 | class QhullPointSet;
|
---|
26 | //! Java-style iterator
|
---|
27 | class QhullPointsIterator;
|
---|
28 |
|
---|
29 | #//Classref
|
---|
30 | class QhullPoint;
|
---|
31 |
|
---|
32 | class QhullPointSet : public QhullSet<coordT *> {
|
---|
33 |
|
---|
34 | private:
|
---|
35 | #//Field
|
---|
36 | int point_dimension;
|
---|
37 |
|
---|
38 | public:
|
---|
39 | #//Subtypes and types
|
---|
40 | class const_iterator;
|
---|
41 | class iterator;
|
---|
42 | typedef QhullPointSet::const_iterator ConstIterator;
|
---|
43 | typedef QhullPointSet::iterator Iterator;
|
---|
44 |
|
---|
45 | typedef QhullPoint value_type;
|
---|
46 | typedef ptrdiff_t difference_type;
|
---|
47 | typedef int size_type;
|
---|
48 | //typedef const value_type *const_pointer; // FIXUP QH11019: QhullPointSet does not define pointer or reference due to point_dimension
|
---|
49 | //typedef const value_type &const_reference;
|
---|
50 | //typedef value_type *pointer;
|
---|
51 | //typedef value_type &reference;
|
---|
52 |
|
---|
53 | #//Construct
|
---|
54 | //Conversion from setT* is not type-safe. Implicit conversion for void* to T
|
---|
55 | QhullPointSet(int pointDimension, setT *s) : QhullSet<coordT *>(s), point_dimension(pointDimension) {}
|
---|
56 | //Copy constructor copies pointer but not contents. Needed for return by value and parameter passing.
|
---|
57 | QhullPointSet(const QhullPointSet &o) : QhullSet<coordT *>(o), point_dimension(o.point_dimension) {}
|
---|
58 | ~QhullPointSet() {}
|
---|
59 |
|
---|
60 | //Default constructor and copy assignment disabled since p= p2 is ambiguous (coord* vs coord)
|
---|
61 | private:
|
---|
62 | QhullPointSet();
|
---|
63 | QhullPointSet &operator=(const QhullPointSet &);
|
---|
64 | public:
|
---|
65 |
|
---|
66 | #//Conversions
|
---|
67 | // inherited -- constData, data
|
---|
68 | #ifndef QHULL_NO_STL
|
---|
69 | std::vector<QhullPoint> toStdVector() const;
|
---|
70 | #endif
|
---|
71 | #ifdef QHULL_USES_QT
|
---|
72 | QList<QhullPoint> toQList() const;
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | #//Read-only
|
---|
76 | //inherits count, empty, isEmpty, size
|
---|
77 | using QhullSetBase::count;
|
---|
78 | int dimension() const { return point_dimension; }
|
---|
79 | bool operator==(const QhullPointSet &o) const;
|
---|
80 | bool operator!=(const QhullPointSet &o) const { return !operator==(o); }
|
---|
81 |
|
---|
82 | #//Element access -- can not return references since QhullPoint must be generated
|
---|
83 | QhullPoint at(int idx) const { return operator[](idx); }
|
---|
84 | QhullPoint back() const { return last(); }
|
---|
85 | //! end element is NULL
|
---|
86 | QhullPoint first() const { QHULL_ASSERT(!isEmpty()); return *begin(); }
|
---|
87 | QhullPoint front() const { return first(); }
|
---|
88 | QhullPoint last() const { QHULL_ASSERT(!isEmpty()); return *(end()-1); }
|
---|
89 | // mid() not available. No setT constructor
|
---|
90 | QhullPoint operator[](int idx) const { return QhullPoint(dimension(), QhullSet<coordT *>::operator[](idx)); }
|
---|
91 | QhullPoint second() const { return operator[](1); }
|
---|
92 | QhullPoint value(int idx) const;
|
---|
93 | // Non-const since copy is an alias
|
---|
94 | QhullPoint value(int idx, QhullPoint &defaultValue) const;
|
---|
95 |
|
---|
96 | #//iterator
|
---|
97 | iterator begin() { return iterator(dimension(), reinterpret_cast<coordT **>(beginPointer())); }
|
---|
98 | const_iterator begin() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(beginPointer())); }
|
---|
99 | const_iterator constBegin() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(beginPointer())); }
|
---|
100 | const_iterator constEnd() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(endPointer())); }
|
---|
101 | iterator end() { return iterator(dimension(), reinterpret_cast<coordT **>(endPointer())); }
|
---|
102 | const_iterator end() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(endPointer())); }
|
---|
103 |
|
---|
104 | //Read-write -- Not available, no setT constructor
|
---|
105 |
|
---|
106 | #//Search
|
---|
107 | bool contains(const QhullPoint &t) const;
|
---|
108 | int count(const QhullPoint &t) const;
|
---|
109 | int indexOf(const QhullPoint &t) const;
|
---|
110 | int lastIndexOf(const QhullPoint &t) const;
|
---|
111 |
|
---|
112 | // before const_iterator for conversion with comparison operators
|
---|
113 | class iterator {
|
---|
114 | friend class const_iterator;
|
---|
115 |
|
---|
116 | private:
|
---|
117 | coordT **i;
|
---|
118 | int point_dimension;
|
---|
119 |
|
---|
120 | public:
|
---|
121 | typedef ptrdiff_t difference_type;
|
---|
122 | typedef std::bidirectional_iterator_tag iterator_category;
|
---|
123 | typedef QhullPoint *pointer;
|
---|
124 | typedef QhullPoint &reference;
|
---|
125 | typedef QhullPoint value_type;
|
---|
126 |
|
---|
127 | iterator() : i(0), point_dimension(0) {}
|
---|
128 | iterator(int dimension, coordT **c) : i(c), point_dimension(dimension) {}
|
---|
129 | iterator(const iterator &o) : i(o.i), point_dimension(o.point_dimension) {}
|
---|
130 | iterator &operator=(const iterator &o) { i= o.i; point_dimension= o.point_dimension; return *this; }
|
---|
131 |
|
---|
132 | QhullPoint operator*() const { return QhullPoint(point_dimension, *i); }
|
---|
133 | //operator->() n/a, value-type
|
---|
134 | QhullPoint operator[](int idx) { return QhullPoint(point_dimension, *(i+idx)); }
|
---|
135 | bool operator==(const iterator &o) const { return i == o.i && point_dimension == o.point_dimension; }
|
---|
136 | bool operator!=(const iterator &o) const { return !operator==(o); }
|
---|
137 | bool operator==(const const_iterator &o) const
|
---|
138 | { return i == reinterpret_cast<const iterator &>(o).i && point_dimension == reinterpret_cast<const iterator &>(o).point_dimension; }
|
---|
139 | bool operator!=(const const_iterator &o) const { return !operator==(o); }
|
---|
140 |
|
---|
141 | //! Assumes same point set
|
---|
142 | int operator-(const iterator &o) { return (int)(i-o.i); } //WARN64
|
---|
143 | bool operator>(const iterator &o) const { return i>o.i; }
|
---|
144 | bool operator<=(const iterator &o) const { return !operator>(o); }
|
---|
145 | bool operator<(const iterator &o) const { return i<o.i; }
|
---|
146 | bool operator>=(const iterator &o) const { return !operator<(o); }
|
---|
147 | bool operator>(const const_iterator &o) const
|
---|
148 | { return i > reinterpret_cast<const iterator &>(o).i; }
|
---|
149 | bool operator<=(const const_iterator &o) const { return !operator>(o); }
|
---|
150 | bool operator<(const const_iterator &o) const
|
---|
151 | { return i < reinterpret_cast<const iterator &>(o).i; }
|
---|
152 | bool operator>=(const const_iterator &o) const { return !operator<(o); }
|
---|
153 |
|
---|
154 | iterator &operator++() { ++i; return *this; }
|
---|
155 | iterator operator++(int) { iterator o= *this; ++i; return o; }
|
---|
156 | iterator &operator--() { --i; return *this; }
|
---|
157 | iterator operator--(int) { iterator o= *this; --i; return o; }
|
---|
158 | iterator operator+(int j) const { return iterator(point_dimension, i+j); }
|
---|
159 | iterator operator-(int j) const { return operator+(-j); }
|
---|
160 | iterator &operator+=(int j) { i += j; return *this; }
|
---|
161 | iterator &operator-=(int j) { i -= j; return *this; }
|
---|
162 | };//QhullPointSet::iterator
|
---|
163 |
|
---|
164 | class const_iterator {
|
---|
165 | private:
|
---|
166 | coordT **i;
|
---|
167 | int point_dimension;
|
---|
168 |
|
---|
169 | public:
|
---|
170 | typedef std::random_access_iterator_tag iterator_category;
|
---|
171 | typedef QhullPoint value_type;
|
---|
172 | typedef value_type *pointer;
|
---|
173 | typedef value_type &reference;
|
---|
174 | typedef ptrdiff_t difference_type;
|
---|
175 |
|
---|
176 | const_iterator() : i(0), point_dimension(0) {}
|
---|
177 | const_iterator(int dimension, coordT **c) : i(c), point_dimension(dimension) {}
|
---|
178 | const_iterator(const const_iterator &o) : i(o.i), point_dimension(o.point_dimension) {}
|
---|
179 | const_iterator(iterator o) : i(o.i), point_dimension(o.point_dimension) {}
|
---|
180 | const_iterator &operator=(const const_iterator &o) { i= o.i; point_dimension= o.point_dimension; return *this; }
|
---|
181 |
|
---|
182 | QhullPoint operator*() const { return QhullPoint(point_dimension, *i); }
|
---|
183 | QhullPoint operator[](int idx) { return QhullPoint(point_dimension, *(i+idx)); }
|
---|
184 | //operator->() n/a, value-type
|
---|
185 | bool operator==(const const_iterator &o) const { return i == o.i && point_dimension == o.point_dimension; }
|
---|
186 | bool operator!=(const const_iterator &o) const { return !operator==(o); }
|
---|
187 |
|
---|
188 | //! Assumes same point set
|
---|
189 | int operator-(const const_iterator &o) { return (int)(i-o.i); } //WARN64
|
---|
190 | bool operator>(const const_iterator &o) const { return i>o.i; }
|
---|
191 | bool operator<=(const const_iterator &o) const { return !operator>(o); }
|
---|
192 | bool operator<(const const_iterator &o) const { return i<o.i; }
|
---|
193 | bool operator>=(const const_iterator &o) const { return !operator<(o); }
|
---|
194 |
|
---|
195 | const_iterator &operator++() { ++i; return *this; }
|
---|
196 | const_iterator operator++(int) { const_iterator o= *this; ++i; return o; }
|
---|
197 | const_iterator &operator--() { --i; return *this; }
|
---|
198 | const_iterator operator--(int) { const_iterator o= *this; --i; return o; }
|
---|
199 | const_iterator operator+(int j) const { return const_iterator(point_dimension, i+j); }
|
---|
200 | const_iterator operator-(int j) const { return operator+(-j); }
|
---|
201 | const_iterator &operator+=(int j) { i += j; return *this; }
|
---|
202 | const_iterator &operator-=(int j) { i -= j; return *this; }
|
---|
203 | };//QhullPointSet::const_iterator
|
---|
204 |
|
---|
205 | #//IO
|
---|
206 | struct PrintIdentifiers{
|
---|
207 | const QhullPointSet *point_set;
|
---|
208 | const char *print_message;
|
---|
209 | int run_id;
|
---|
210 | PrintIdentifiers(const char *message, const QhullPointSet *s) : point_set(s), print_message(message) {}
|
---|
211 | };//PrintIdentifiers
|
---|
212 | PrintIdentifiers printIdentifiers(const char *message) const { return PrintIdentifiers(message, this); }
|
---|
213 |
|
---|
214 | struct PrintPointSet{
|
---|
215 | const QhullPointSet *point_set;
|
---|
216 | const char *print_message;
|
---|
217 | int run_id;
|
---|
218 | PrintPointSet(int qhRunId, const char *message, const QhullPointSet &s) : point_set(&s), print_message(message), run_id(qhRunId) {}
|
---|
219 | };//PrintPointSet
|
---|
220 | PrintPointSet print(int qhRunId) const { return PrintPointSet(qhRunId, 0, *this); }
|
---|
221 | PrintPointSet print(int qhRunId, const char *message) const { return PrintPointSet(qhRunId, message, *this); }
|
---|
222 |
|
---|
223 | };//QhullPointSet
|
---|
224 |
|
---|
225 | //derived from qiterator.h
|
---|
226 | class QhullPointSetIterator { // FIXUP QH11020 define QhullMutablePointSetIterator
|
---|
227 | typedef QhullPointSet::const_iterator const_iterator;
|
---|
228 | const QhullPointSet *c;
|
---|
229 | const_iterator i;
|
---|
230 |
|
---|
231 | public:
|
---|
232 | QhullPointSetIterator(const QhullPointSet &container) : c(&container), i(c->constBegin()) {}
|
---|
233 | QhullPointSetIterator &operator=(const QhullPointSet &container) { c= &container; i= c->constBegin(); return *this; }
|
---|
234 | bool findNext(const QhullPoint &p);
|
---|
235 | bool findPrevious(const QhullPoint &p);
|
---|
236 | bool hasNext() const { return i != c->constEnd(); }
|
---|
237 | bool hasPrevious() const { return i != c->constBegin(); }
|
---|
238 | QhullPoint next() { return *i++; }
|
---|
239 | QhullPoint peekNext() const { return *i; }
|
---|
240 | QhullPoint peekPrevious() const { const_iterator p= i; return *--p; }
|
---|
241 | QhullPoint previous() { return *--i; }
|
---|
242 | void toBack() { i= c->constEnd(); }
|
---|
243 | void toFront() { i= c->constBegin(); }
|
---|
244 | };//QhullPointSetIterator
|
---|
245 |
|
---|
246 | }//namespace orgQhull
|
---|
247 |
|
---|
248 | #//Global functions
|
---|
249 |
|
---|
250 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPointSet &fs); // Not inline to avoid using statement
|
---|
251 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPointSet::PrintIdentifiers &pr);
|
---|
252 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPointSet::PrintPointSet &pr);
|
---|
253 |
|
---|
254 | #endif // QHULLPOINTSET_H
|
---|