Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:55

0001 /****************************************************************************
0002 **
0003 ** Copyright (c) 2009-2020 C.B. Barber. All rights reserved.
0004 ** $Id: //main/2019/qhull/src/libqhullcpp/PointCoordinates.h#6 $$Change: 3001 $
0005 ** $DateTime: 2020/07/24 20:43:28 $$Author: bbarber $
0006 **
0007 ****************************************************************************/
0008 
0009 #ifndef QHPOINTCOORDINATES_H
0010 #define QHPOINTCOORDINATES_H
0011 
0012 #include "libqhull_r/qhull_ra.h"
0013 #include "libqhullcpp/QhullPoints.h"
0014 #include "libqhullcpp/Coordinates.h"
0015 
0016 #include <ostream>
0017 #include <string>
0018 
0019 #ifndef QHULL_NO_STL
0020 #include <vector>
0021 #endif
0022 
0023 namespace orgQhull {
0024 
0025 #//!\name Defined here
0026     //! QhullPoints with Coordinates and description
0027     //! Inherited by RboxPoints
0028     class PointCoordinates;
0029 
0030     //! Java-style iterators are not implemented for PointCoordinates.  Expensive copy constructor and copy assignment for Coordinates (std::vector).
0031     //! A pointer to PointCoordinates is vulnerable to mysterious overwrites (e.g., deleting a returned value and reusing its memory)
0032     //! 'foreach' likewise makes a copy of point_coordinates and should be avoided
0033 
0034 class PointCoordinates : public QhullPoints {
0035 
0036 private:
0037 #//!\name Fields
0038     Coordinates         point_coordinates;      //! std::vector of point coordinates
0039                                                 //! may have extraCoordinates()
0040     std::string         describe_points;        //! Comment describing PointCoordinates
0041 
0042 public:
0043 #//!\name Construct
0044     //! QhullPoint, PointCoordinates, and QhullPoints have similar constructors
0045     //! If Qhull/QhullQh is not initialized, then dimension()==0                        PointCoordinates();
0046                         PointCoordinates();
0047     explicit            PointCoordinates(const std::string &aComment);
0048                         PointCoordinates(int pointDimension, const std::string &aComment);
0049                         //! Qhull/QhullQh used for dimension() and QhullPoint equality
0050     explicit            PointCoordinates(const Qhull &q);
0051                         PointCoordinates(const Qhull &q, const std::string &aComment);
0052                         PointCoordinates(const Qhull &q, int pointDimension, const std::string &aComment);
0053                         PointCoordinates(const Qhull &q, int pointDimension, const std::string &aComment, countT coordinatesCount, const coordT *c); // may be invalid
0054                         //! Use append() and appendPoints() for Coordinates and vector<coordT>
0055     explicit            PointCoordinates(QhullQh *qqh);
0056                         PointCoordinates(QhullQh *qqh, const std::string &aComment);
0057                         PointCoordinates(QhullQh *qqh, int pointDimension, const std::string &aComment);
0058                         PointCoordinates(QhullQh *qqh, int pointDimension, const std::string &aComment, countT coordinatesCount, const coordT *c); // may be invalid
0059                         //! Use append() and appendPoints() for Coordinates and vector<coordT>
0060                         PointCoordinates(const PointCoordinates &other);
0061     PointCoordinates &  operator=(const PointCoordinates &other);
0062                         ~PointCoordinates();
0063 
0064 #//!\name Convert
0065     //! QhullPoints coordinates, constData, data, count, size
0066 #ifndef QHULL_NO_STL
0067     void                append(const std::vector<coordT> &otherCoordinates) { if(!otherCoordinates.empty()){ append(static_cast<int>(otherCoordinates.size()), &otherCoordinates[0]); } }
0068     std::vector<coordT> toStdVector() const { return point_coordinates.toStdVector(); }
0069 #endif //QHULL_NO_STL
0070 #ifdef QHULL_USES_QT
0071     void                append(const QList<coordT> &pointCoordinates) { if(!pointCoordinates.isEmpty()){ append(pointCoordinates.count(), &pointCoordinates[0]); } }
0072     QList<coordT>       toQList() const { return point_coordinates.toQList(); }
0073 #endif //QHULL_USES_QT
0074 
0075 #//!\name GetSet
0076     //! See QhullPoints for coordinates, coordinateCount, dimension, empty, isEmpty, ==, !=
0077     void                checkValid() const;
0078     std::string         comment() const { return describe_points; }
0079     void                makeValid() { defineAs(point_coordinates.count(), point_coordinates.data()); }
0080     const Coordinates & getCoordinates() const { return point_coordinates; }
0081     void                setComment(const std::string &s) { describe_points= s; }
0082     void                setDimension(int i);
0083 
0084 private:
0085     //! disable QhullPoints.defineAs()
0086     void                defineAs(countT coordinatesCount, coordT *c) { QhullPoints::defineAs(coordinatesCount, c); }
0087 public:
0088 
0089 #//!\name ElementAccess
0090     //! See QhullPoints for at, back, first, front, last, mid, [], value
0091 
0092 #//!\name Foreach
0093     //! See QhullPoints for begin, constBegin, end
0094     Coordinates::ConstIterator  beginCoordinates() const { return point_coordinates.begin(); }
0095     Coordinates::Iterator       beginCoordinates() { return point_coordinates.begin(); }
0096     Coordinates::ConstIterator  beginCoordinates(countT pointIndex) const;
0097     Coordinates::Iterator       beginCoordinates(countT pointIndex);
0098     Coordinates::ConstIterator  endCoordinates() const { return point_coordinates.end(); }
0099     Coordinates::Iterator       endCoordinates() { return point_coordinates.end(); }
0100 
0101 #//!\name Search
0102     //! See QhullPoints for contains, count, indexOf, lastIndexOf
0103 
0104 #//!\name GetSet
0105     PointCoordinates    operator+(const PointCoordinates &other) const;
0106 
0107 #//!\name Modify
0108     // QH11001 FIX: Add clear() and other modify operators from Coordinates.h.  Include QhullPoint::operator=()
0109     void                append(countT coordinatesCount, const coordT *c);  //! Dimension previously defined
0110     void                append(const coordT &c) { append(1, &c); } //! Dimension previously defined
0111     void                append(const QhullPoint &p);
0112     //! See convert for std::vector and QList
0113     void                append(const Coordinates &c) { append(c.count(), c.data()); }
0114     void                append(const PointCoordinates &other);
0115     void                appendComment(const std::string &s);
0116     void                appendPoints(std::istream &in);
0117     PointCoordinates &  operator+=(const PointCoordinates &other) { append(other); return *this; }
0118     PointCoordinates &  operator+=(const coordT &c) { append(c); return *this; }
0119     PointCoordinates &  operator+=(const QhullPoint &p) { append(p); return *this; }
0120     PointCoordinates &  operator<<(const PointCoordinates &other) { return *this += other; }
0121     PointCoordinates &  operator<<(const coordT &c) { return *this += c; }
0122     PointCoordinates &  operator<<(const QhullPoint &p) { return *this += p; }
0123     // reserve() is non-const
0124     void                reserveCoordinates(countT newCoordinates);
0125 
0126 #//!\name Helpers
0127 private:
0128     int                 indexOffset(int i) const;
0129 
0130 };//PointCoordinates
0131 
0132 }//namespace orgQhull
0133 
0134 #//!\name Global
0135 
0136 std::ostream &          operator<<(std::ostream &os, const orgQhull::PointCoordinates &p);
0137 
0138 #endif // QHPOINTCOORDINATES_H