File indexing completed on 2024-11-15 09:44:15
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef QHPOINT_H
0010 #define QHPOINT_H
0011
0012 #include "libqhull_r/qhull_ra.h"
0013 #include "libqhullcpp/QhullError.h"
0014 #include "libqhullcpp/QhullIterator.h"
0015 #include "libqhullcpp/QhullQh.h"
0016 #include "libqhullcpp/Coordinates.h"
0017
0018 #include <ostream>
0019
0020 namespace orgQhull {
0021
0022 #
0023 class QhullPoint;
0024 class QhullPointIterator;
0025
0026 #
0027 class Qhull;
0028
0029
0030
0031 class QhullPoint {
0032
0033 #
0034 public:
0035 typedef coordT * base_type;
0036 typedef const coordT * iterator;
0037 typedef const coordT * const_iterator;
0038 typedef QhullPoint::iterator Iterator;
0039 typedef QhullPoint::const_iterator ConstIterator;
0040
0041 #
0042 protected:
0043 coordT * point_coordinates;
0044 QhullQh * qh_qh;
0045
0046
0047 int point_dimension;
0048 public:
0049
0050 #
0051
0052
0053
0054 QhullPoint() : point_coordinates(0), qh_qh(0), point_dimension(0) {}
0055 QhullPoint(int pointDimension, coordT *c) : point_coordinates(c), qh_qh(0), point_dimension(pointDimension) { QHULL_ASSERT(pointDimension>0); }
0056 explicit QhullPoint(const Qhull &q);
0057 QhullPoint(const Qhull &q, coordT *c);
0058 QhullPoint(const Qhull &q, Coordinates &c);
0059 QhullPoint(const Qhull &q, int pointDimension, coordT *c);
0060 explicit QhullPoint(QhullQh *qqh) : point_coordinates(0), qh_qh(qqh), point_dimension(qqh->hull_dim) {}
0061 QhullPoint(QhullQh *qqh, coordT *c) : point_coordinates(c), qh_qh(qqh), point_dimension(qqh->hull_dim) { QHULL_ASSERT(qqh->hull_dim>0); }
0062 QhullPoint(QhullQh *qqh, Coordinates &c) : point_coordinates(c.data()), qh_qh(qqh), point_dimension(c.count()) {}
0063 QhullPoint(QhullQh *qqh, int pointDimension, coordT *c) : point_coordinates(c), qh_qh(qqh), point_dimension(pointDimension) {}
0064
0065 QhullPoint(const QhullPoint &other) : point_coordinates(other.point_coordinates), qh_qh(other.qh_qh), point_dimension(other.point_dimension) {}
0066
0067 QhullPoint & operator=(const QhullPoint &other) { point_coordinates= other.point_coordinates; qh_qh= other.qh_qh; point_dimension= other.point_dimension; return *this; }
0068 ~QhullPoint() {}
0069
0070
0071 #
0072
0073 #ifndef QHULL_NO_STL
0074 std::vector<coordT> toStdVector() const;
0075 #endif
0076 #ifdef QHULL_USES_QT
0077 QList<coordT> toQList() const;
0078 #endif
0079
0080 #
0081 public:
0082 const coordT * coordinates() const { return point_coordinates; }
0083 coordT * coordinates() { return point_coordinates; }
0084 void defineAs(coordT *c) { QHULL_ASSERT(point_dimension>0); point_coordinates= c; }
0085 void defineAs(int pointDimension, coordT *c) { QHULL_ASSERT(pointDimension>=0); point_coordinates= c; point_dimension= pointDimension; }
0086 void defineAs(QhullPoint &other) { point_coordinates= other.point_coordinates; qh_qh= other.qh_qh; point_dimension= other.point_dimension; }
0087 int dimension() const { return point_dimension; }
0088 coordT * getBaseT() const { return point_coordinates; }
0089 countT id() const { return qh_pointid(qh_qh, point_coordinates); }
0090 bool isValid() const { return (point_coordinates!=0 && point_dimension>0); }
0091 bool operator==(const QhullPoint &other) const;
0092 bool operator!=(const QhullPoint &other) const { return ! operator==(other); }
0093 const coordT & operator[](int idx) const { QHULL_ASSERT(point_coordinates!=0 && idx>=0 && idx<point_dimension); return *(point_coordinates+idx); }
0094 coordT & operator[](int idx) { QHULL_ASSERT(point_coordinates!=0 && idx>=0 && idx<point_dimension); return *(point_coordinates+idx); }
0095 QhullQh * qh() { return qh_qh; }
0096 void setCoordinates(coordT *c) { point_coordinates= c; }
0097 void setDimension(int pointDimension) { point_dimension= pointDimension; }
0098
0099 #
0100 iterator begin() { return point_coordinates; }
0101 const_iterator begin() const { return point_coordinates; }
0102 const_iterator constBegin() const { return point_coordinates; }
0103 const_iterator constEnd() const { return (point_coordinates ? point_coordinates+point_dimension : 0); }
0104 int count() { return (point_coordinates ? point_dimension : 0); }
0105 iterator end() { return (point_coordinates ? point_coordinates+point_dimension : 0); }
0106 const_iterator end() const { return (point_coordinates ? point_coordinates+point_dimension : 0); }
0107 size_t size() { return static_cast<size_t>(point_coordinates ? point_dimension : 0); }
0108
0109 #
0110 void advancePoint(countT idx) { if(point_coordinates) { point_coordinates += idx*point_dimension; } }
0111 double distance(const QhullPoint &p) const;
0112
0113 #
0114
0115 struct PrintPoint{
0116 const QhullPoint *point;
0117 const char * point_message;
0118 bool with_identifier;
0119 PrintPoint(const char *message, bool withIdentifier, const QhullPoint &p) : point(&p), point_message(message), with_identifier(withIdentifier) {}
0120 };
0121 PrintPoint print(const char *message) const { return PrintPoint(message, false, *this); }
0122 PrintPoint printWithIdentifier(const char *message) const { return PrintPoint(message, true, *this); }
0123
0124 };
0125
0126
0127
0128 QHULL_DECLARE_SEQUENTIAL_ITERATOR(QhullPoint, coordT)
0129
0130 }
0131
0132 #
0133
0134 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPoint::PrintPoint &pr);
0135 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPoint &p);
0136
0137 #endif
0138