Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef QHULLPOINTSET_H
00010 #define QHULLPOINTSET_H
00011
00012 #include "QhullSet.h"
00013 #include "QhullPoint.h"
00014 extern "C" {
00015 #include "libqhull/qhull_a.h"
00016 }
00017
00018 #include <ostream>
00019
00020 namespace orgQhull {
00021
00022 #//Types
00023
00024
00025 class QhullPointSet;
00027 class QhullPointsIterator;
00028
00029 #//Classref
00030 class QhullPoint;
00031
00032 class QhullPointSet : public QhullSet<coordT *> {
00033
00034 private:
00035 #//Field
00036 int point_dimension;
00037
00038 public:
00039 #//Subtypes and types
00040 class const_iterator;
00041 class iterator;
00042 typedef QhullPointSet::const_iterator ConstIterator;
00043 typedef QhullPointSet::iterator Iterator;
00044
00045 typedef QhullPoint value_type;
00046 typedef ptrdiff_t difference_type;
00047 typedef int size_type;
00048
00049
00050
00051
00052
00053 #//Construct
00054
00055 QhullPointSet(int pointDimension, setT *s) : QhullSet<coordT *>(s), point_dimension(pointDimension) {}
00056
00057 QhullPointSet(const QhullPointSet &o) : QhullSet<coordT *>(o), point_dimension(o.point_dimension) {}
00058 ~QhullPointSet() {}
00059
00060
00061 private:
00062 QhullPointSet();
00063 QhullPointSet &operator=(const QhullPointSet &);
00064 public:
00065
00066 #//Conversions
00067
00068 #ifndef QHULL_NO_STL
00069 std::vector<QhullPoint> toStdVector() const;
00070 #endif
00071 #ifdef QHULL_USES_QT
00072 QList<QhullPoint> toQList() const;
00073 #endif
00074
00075 #//Read-only
00076
00077 using QhullSetBase::count;
00078 int dimension() const { return point_dimension; }
00079 bool operator==(const QhullPointSet &o) const;
00080 bool operator!=(const QhullPointSet &o) const { return !operator==(o); }
00081
00082 #//Element access -- can not return references since QhullPoint must be generated
00083 QhullPoint at(int idx) const { return operator[](idx); }
00084 QhullPoint back() const { return last(); }
00086 QhullPoint first() const { QHULL_ASSERT(!isEmpty()); return *begin(); }
00087 QhullPoint front() const { return first(); }
00088 QhullPoint last() const { QHULL_ASSERT(!isEmpty()); return *(end()-1); }
00089
00090 QhullPoint operator[](int idx) const { return QhullPoint(dimension(), QhullSet<coordT *>::operator[](idx)); }
00091 QhullPoint second() const { return operator[](1); }
00092 QhullPoint value(int idx) const;
00093
00094 QhullPoint value(int idx, QhullPoint &defaultValue) const;
00095
00096 #//iterator
00097 iterator begin() { return iterator(dimension(), reinterpret_cast<coordT **>(beginPointer())); }
00098 const_iterator begin() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(beginPointer())); }
00099 const_iterator constBegin() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(beginPointer())); }
00100 const_iterator constEnd() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(endPointer())); }
00101 iterator end() { return iterator(dimension(), reinterpret_cast<coordT **>(endPointer())); }
00102 const_iterator end() const { return const_iterator(dimension(), reinterpret_cast<coordT **>(endPointer())); }
00103
00104
00105
00106 #//Search
00107 bool contains(const QhullPoint &t) const;
00108 int count(const QhullPoint &t) const;
00109 int indexOf(const QhullPoint &t) const;
00110 int lastIndexOf(const QhullPoint &t) const;
00111
00112
00113 class iterator {
00114 friend class const_iterator;
00115
00116 private:
00117 coordT **i;
00118 int point_dimension;
00119
00120 public:
00121 typedef ptrdiff_t difference_type;
00122 typedef std::bidirectional_iterator_tag iterator_category;
00123 typedef QhullPoint *pointer;
00124 typedef QhullPoint &reference;
00125 typedef QhullPoint value_type;
00126
00127 iterator() : i(0), point_dimension(0) {}
00128 iterator(int dimension, coordT **c) : i(c), point_dimension(dimension) {}
00129 iterator(const iterator &o) : i(o.i), point_dimension(o.point_dimension) {}
00130 iterator &operator=(const iterator &o) { i= o.i; point_dimension= o.point_dimension; return *this; }
00131
00132 QhullPoint operator*() const { return QhullPoint(point_dimension, *i); }
00133
00134 QhullPoint operator[](int idx) { return QhullPoint(point_dimension, *(i+idx)); }
00135 bool operator==(const iterator &o) const { return i == o.i && point_dimension == o.point_dimension; }
00136 bool operator!=(const iterator &o) const { return !operator==(o); }
00137 bool operator==(const const_iterator &o) const
00138 { return i == reinterpret_cast<const iterator &>(o).i && point_dimension == reinterpret_cast<const iterator &>(o).point_dimension; }
00139 bool operator!=(const const_iterator &o) const { return !operator==(o); }
00140
00142 int operator-(const iterator &o) { return (int)(i-o.i); }
00143 bool operator>(const iterator &o) const { return i>o.i; }
00144 bool operator<=(const iterator &o) const { return !operator>(o); }
00145 bool operator<(const iterator &o) const { return i<o.i; }
00146 bool operator>=(const iterator &o) const { return !operator<(o); }
00147 bool operator>(const const_iterator &o) const
00148 { return i > reinterpret_cast<const iterator &>(o).i; }
00149 bool operator<=(const const_iterator &o) const { return !operator>(o); }
00150 bool operator<(const const_iterator &o) const
00151 { return i < reinterpret_cast<const iterator &>(o).i; }
00152 bool operator>=(const const_iterator &o) const { return !operator<(o); }
00153
00154 iterator &operator++() { ++i; return *this; }
00155 iterator operator++(int) { iterator o= *this; ++i; return o; }
00156 iterator &operator--() { --i; return *this; }
00157 iterator operator--(int) { iterator o= *this; --i; return o; }
00158 iterator operator+(int j) const { return iterator(point_dimension, i+j); }
00159 iterator operator-(int j) const { return operator+(-j); }
00160 iterator &operator+=(int j) { i += j; return *this; }
00161 iterator &operator-=(int j) { i -= j; return *this; }
00162 };
00163
00164 class const_iterator {
00165 private:
00166 coordT **i;
00167 int point_dimension;
00168
00169 public:
00170 typedef std::random_access_iterator_tag iterator_category;
00171 typedef QhullPoint value_type;
00172 typedef value_type *pointer;
00173 typedef value_type &reference;
00174 typedef ptrdiff_t difference_type;
00175
00176 const_iterator() : i(0), point_dimension(0) {}
00177 const_iterator(int dimension, coordT **c) : i(c), point_dimension(dimension) {}
00178 const_iterator(const const_iterator &o) : i(o.i), point_dimension(o.point_dimension) {}
00179 const_iterator(iterator o) : i(o.i), point_dimension(o.point_dimension) {}
00180 const_iterator &operator=(const const_iterator &o) { i= o.i; point_dimension= o.point_dimension; return *this; }
00181
00182 QhullPoint operator*() const { return QhullPoint(point_dimension, *i); }
00183 QhullPoint operator[](int idx) { return QhullPoint(point_dimension, *(i+idx)); }
00184
00185 bool operator==(const const_iterator &o) const { return i == o.i && point_dimension == o.point_dimension; }
00186 bool operator!=(const const_iterator &o) const { return !operator==(o); }
00187
00189 int operator-(const const_iterator &o) { return (int)(i-o.i); }
00190 bool operator>(const const_iterator &o) const { return i>o.i; }
00191 bool operator<=(const const_iterator &o) const { return !operator>(o); }
00192 bool operator<(const const_iterator &o) const { return i<o.i; }
00193 bool operator>=(const const_iterator &o) const { return !operator<(o); }
00194
00195 const_iterator &operator++() { ++i; return *this; }
00196 const_iterator operator++(int) { const_iterator o= *this; ++i; return o; }
00197 const_iterator &operator--() { --i; return *this; }
00198 const_iterator operator--(int) { const_iterator o= *this; --i; return o; }
00199 const_iterator operator+(int j) const { return const_iterator(point_dimension, i+j); }
00200 const_iterator operator-(int j) const { return operator+(-j); }
00201 const_iterator &operator+=(int j) { i += j; return *this; }
00202 const_iterator &operator-=(int j) { i -= j; return *this; }
00203 };
00204
00205 #//IO
00206 struct PrintIdentifiers{
00207 const QhullPointSet *point_set;
00208 const char *print_message;
00209 int run_id;
00210 PrintIdentifiers(const char *message, const QhullPointSet *s) : point_set(s), print_message(message) {}
00211 };
00212 PrintIdentifiers printIdentifiers(const char *message) const { return PrintIdentifiers(message, this); }
00213
00214 struct PrintPointSet{
00215 const QhullPointSet *point_set;
00216 const char *print_message;
00217 int run_id;
00218 PrintPointSet(int qhRunId, const char *message, const QhullPointSet &s) : point_set(&s), print_message(message), run_id(qhRunId) {}
00219 };
00220 PrintPointSet print(int qhRunId) const { return PrintPointSet(qhRunId, 0, *this); }
00221 PrintPointSet print(int qhRunId, const char *message) const { return PrintPointSet(qhRunId, message, *this); }
00222
00223 };
00224
00225
00226 class QhullPointSetIterator {
00227 typedef QhullPointSet::const_iterator const_iterator;
00228 const QhullPointSet *c;
00229 const_iterator i;
00230
00231 public:
00232 QhullPointSetIterator(const QhullPointSet &container) : c(&container), i(c->constBegin()) {}
00233 QhullPointSetIterator &operator=(const QhullPointSet &container) { c= &container; i= c->constBegin(); return *this; }
00234 bool findNext(const QhullPoint &p);
00235 bool findPrevious(const QhullPoint &p);
00236 bool hasNext() const { return i != c->constEnd(); }
00237 bool hasPrevious() const { return i != c->constBegin(); }
00238 QhullPoint next() { return *i++; }
00239 QhullPoint peekNext() const { return *i; }
00240 QhullPoint peekPrevious() const { const_iterator p= i; return *--p; }
00241 QhullPoint previous() { return *--i; }
00242 void toBack() { i= c->constEnd(); }
00243 void toFront() { i= c->constBegin(); }
00244 };
00245
00246 }
00247
00248 #//Global functions
00249
00250 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPointSet &fs);
00251 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPointSet::PrintIdentifiers &pr);
00252 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPointSet::PrintPointSet &pr);
00253
00254 #endif // QHULLPOINTSET_H