Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:44:15

0001 /****************************************************************************
0002 **
0003 ** Copyright (c) 2009-2020 C.B. Barber. All rights reserved.
0004 ** $Id: //main/2019/qhull/src/libqhullcpp/QhullPoint.h#5 $$Change: 3008 $
0005 ** $DateTime: 2020/07/30 13:54:27 $$Author: bbarber $
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 #//!\name Defined here
0023     class QhullPoint;           //!< QhullPoint is a pointer to coordinates and dimension
0024     class QhullPointIterator;   //!< Java-style iterator for QhullPoint coordinates
0025 
0026 #//!\name Used here
0027     class Qhull;
0028 
0029 //! A QhullPoint is a dimension and an array of coordinates.
0030 //! With Qhull/QhullQh, a QhullPoint has an identifier.  Point equality is relative to qh.distanceEpsilon
0031 class QhullPoint {
0032 
0033 #//!\name Iterators
0034 public:
0035     typedef coordT *                    base_type;  // for QhullPointSet
0036     typedef const coordT *              iterator;
0037     typedef const coordT *              const_iterator;
0038     typedef QhullPoint::iterator        Iterator;
0039     typedef QhullPoint::const_iterator  ConstIterator;
0040 
0041 #//!\name Fields
0042 protected: // For QhullPoints::iterator, QhullPoints::const_iterator
0043     coordT *            point_coordinates;  //!< Pointer to first coordinate,   0 if undefined
0044     QhullQh *           qh_qh;              //!< qhT for this instance of Qhull.  0 if undefined.
0045                                             //!< operator==() returns true if points within sqrt(qh_qh->distanceEpsilon())
0046                                             //!< If !qh_qh, id() is -3, and operator==() requires equal coordinates
0047     int                 point_dimension;    //!< Default dimension is qh_qh->hull_dim
0048 public:
0049 
0050 #//!\name Constructors
0051     //! QhullPoint, PointCoordinates, and QhullPoints have similar constructors
0052     //! If Qhull/QhullQh is not initialized, then QhullPoint.dimension() is zero unless explicitly set
0053     //! Cannot define QhullPoints(int pointDimension) since it is ambiguous with QhullPoints(QhullQh *qqh)
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                         //! Creates an alias.  Does not make a deep copy of the point.  Needed for return by value and parameter passing.
0065                         QhullPoint(const QhullPoint &other) : point_coordinates(other.point_coordinates), qh_qh(other.qh_qh), point_dimension(other.point_dimension) {}
0066                         //! Creates an alias.  Does not make a deep copy of the point.  Needed for vector<QhullPoint>
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 #//!\name Conversions
0072 
0073 #ifndef QHULL_NO_STL
0074     std::vector<coordT> toStdVector() const;
0075 #endif //QHULL_NO_STL
0076 #ifdef QHULL_USES_QT
0077     QList<coordT>       toQList() const;
0078 #endif //QHULL_USES_QT
0079 
0080 #//!\name GetSet
0081 public:
0082     const coordT *      coordinates() const { return point_coordinates; }  //!< 0 if undefined
0083     coordT *            coordinates() { return point_coordinates; }        //!< 0 if undefined
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; } // for QhullPointSet
0089     countT              id() const { return qh_pointid(qh_qh, point_coordinates); } // NOerrors
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); } //!< 0 to hull_dim-1
0094     coordT &            operator[](int idx) { QHULL_ASSERT(point_coordinates!=0 && idx>=0 && idx<point_dimension); return *(point_coordinates+idx); } //!< 0 to hull_dim-1
0095     QhullQh *           qh() { return qh_qh; }
0096     void                setCoordinates(coordT *c) { point_coordinates= c; }
0097     void                setDimension(int pointDimension) { point_dimension= pointDimension; }
0098 
0099 #//!\name foreach
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 #//!\name Methods
0110     void                advancePoint(countT idx) { if(point_coordinates) { point_coordinates += idx*point_dimension; } }
0111     double              distance(const QhullPoint &p) const;
0112 
0113 #//!\name IO
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     };//PrintPoint
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 };//QhullPoint
0125 
0126 //! QhullPointIterator is a Java-style iterator for QhullPoint coordinates
0127 //! QhullPointIterator may be used on temporary results.  It copies the coordinates pointer in QhullPoint
0128 QHULL_DECLARE_SEQUENTIAL_ITERATOR(QhullPoint, coordT)
0129 
0130 }//namespace orgQhull
0131 
0132 #//!\name Global
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 // QHPOINT_H
0138