Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002 **
0003 ** Copyright (c) 2009-2020 C.B. Barber. All rights reserved.
0004 ** $Id: //main/2019/qhull/src/libqhullcpp/QhullHyperplane.h#4 $$Change: 3008 $
0005 ** $DateTime: 2020/07/30 13:54:27 $$Author: bbarber $
0006 **
0007 ****************************************************************************/
0008 
0009 #ifndef QHHYPERPLANE_H
0010 #define QHHYPERPLANE_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 
0017 #include <ostream>
0018 
0019 namespace orgQhull {
0020 
0021 #//!\name Used here
0022     class Qhull;
0023     class QhullPoint;
0024 
0025 #//!\name Defined here
0026     class QhullHyperplane;          //!< QhullHyperplane is a pointer to the normal vector, an offset from the origin, and dimension
0027     class QhullHyperplaneIterator;  //!< Java-style iterator for QhullHyperplane coordinates    
0028 
0029 class QhullHyperplane { // Similar to QhullPoint
0030 public:
0031 #//!\name Subtypes
0032     typedef const coordT *                  iterator;
0033     typedef const coordT *                  const_iterator;
0034     typedef QhullHyperplane::iterator       Iterator;
0035     typedef QhullHyperplane::const_iterator ConstIterator;
0036 
0037 private:
0038 #//!\name Fields
0039     coordT *            hyperplane_coordinates;  //!< Normal to hyperplane.   facetT.normal is normalized to 1.0
0040     QhullQh *           qh_qh;                  //!< qhT for distanceEpsilon() in operator==
0041     coordT              hyperplane_offset;      //!< Distance from hyperplane to origin
0042     int                 hyperplane_dimension;   //!< Dimension of hyperplane
0043 
0044 #//!\name Construct
0045 public:
0046                         QhullHyperplane() : hyperplane_coordinates(0), qh_qh(0), hyperplane_offset(0.0), hyperplane_dimension(0) {}
0047     explicit            QhullHyperplane(const Qhull &q);
0048                         QhullHyperplane(const Qhull &q, int hyperplaneDimension, coordT *c, coordT hyperplaneOffset);
0049     explicit            QhullHyperplane(QhullQh *qqh) : hyperplane_coordinates(0), qh_qh(qqh), hyperplane_offset(0.0), hyperplane_dimension(0) {}
0050                         QhullHyperplane(QhullQh *qqh, int hyperplaneDimension, coordT *c, coordT hyperplaneOffset) : hyperplane_coordinates(c), qh_qh(qqh), hyperplane_offset(hyperplaneOffset), hyperplane_dimension(hyperplaneDimension) {}
0051                         // Creates an alias.  Does not copy the hyperplane's coordinates.  Needed for return by value and parameter passing.
0052                         QhullHyperplane(const QhullHyperplane &other)  : hyperplane_coordinates(other.hyperplane_coordinates), qh_qh(other.qh_qh), hyperplane_offset(other.hyperplane_offset), hyperplane_dimension(other.hyperplane_dimension) {}
0053                         // Creates an alias.  Does not copy the hyperplane's coordinates.  Needed for vector<QhullHyperplane>
0054     QhullHyperplane &   operator=(const QhullHyperplane &other) { hyperplane_coordinates= other.hyperplane_coordinates; qh_qh= other.qh_qh; hyperplane_offset= other.hyperplane_offset; hyperplane_dimension= other.hyperplane_dimension; return *this; }
0055                         ~QhullHyperplane() {}
0056 
0057 #//!\name Conversions --
0058 //! Includes offset at end
0059 #ifndef QHULL_NO_STL
0060     std::vector<coordT> toStdVector() const;
0061 #endif //QHULL_NO_STL
0062 #ifdef QHULL_USES_QT
0063     QList<coordT>       toQList() const;
0064 #endif //QHULL_USES_QT
0065 
0066 #//!\name GetSet
0067 public:
0068     const coordT *      coordinates() const { return hyperplane_coordinates; }
0069     coordT *            coordinates() { return hyperplane_coordinates; }
0070     void                defineAs(int hyperplaneDimension, coordT *c, coordT hyperplaneOffset) { QHULL_ASSERT(hyperplaneDimension>=0); hyperplane_coordinates= c; hyperplane_dimension= hyperplaneDimension; hyperplane_offset= hyperplaneOffset; }
0071     //! Creates an alias to other using the same qh_qh
0072     void                defineAs(QhullHyperplane &other) { hyperplane_coordinates= other.coordinates(); hyperplane_dimension= other.dimension();  hyperplane_offset= other.offset(); }
0073     int                 dimension() const { return hyperplane_dimension; }
0074     bool                isValid() const { return hyperplane_coordinates!=0 && hyperplane_dimension>0; }
0075     coordT              offset() const { return hyperplane_offset; }
0076     bool                operator==(const QhullHyperplane &other) const;
0077     bool                operator!=(const QhullHyperplane &other) const { return !operator==(other); }
0078     const coordT &      operator[](int idx) const { QHULL_ASSERT(idx>=0 && idx<hyperplane_dimension); return *(hyperplane_coordinates+idx); }
0079     coordT &            operator[](int idx) { QHULL_ASSERT(idx>=0 && idx<hyperplane_dimension); return *(hyperplane_coordinates+idx); }
0080     void                setCoordinates(coordT *c) { hyperplane_coordinates= c; }
0081     void                setDimension(int hyperplaneDimension) { hyperplane_dimension= hyperplaneDimension; }
0082     void                setOffset(coordT hyperplaneOffset) { hyperplane_offset= hyperplaneOffset; }
0083 
0084 #//!\name iterator
0085     iterator            begin() { return hyperplane_coordinates; }
0086     const_iterator      begin() const { return hyperplane_coordinates; }
0087     const_iterator      constBegin() const { return hyperplane_coordinates; }
0088     const_iterator      constEnd() const { return hyperplane_coordinates+hyperplane_dimension; }
0089     int                 count() { return hyperplane_dimension; }
0090     iterator            end() { return hyperplane_coordinates+hyperplane_dimension; }
0091     const_iterator      end() const { return hyperplane_coordinates+hyperplane_dimension; }
0092     size_t              size() { return static_cast<size_t>(hyperplane_dimension); }
0093 
0094 #//!\name Methods
0095     double              distance(const QhullPoint &p) const;
0096     double              hyperplaneAngle(const QhullHyperplane &other) const;
0097     double              norm() const;
0098 
0099 #//!\name IO
0100     struct PrintHyperplane{
0101         const QhullHyperplane  *hyperplane;
0102         const char *    print_message;      //!< non-null message
0103         const char *    hyperplane_offset_message;  //!< non-null message
0104                         PrintHyperplane(const char *message, const char *offsetMessage, const QhullHyperplane &p) : hyperplane(&p), print_message(message), hyperplane_offset_message(offsetMessage) {}
0105     };//PrintHyperplane
0106     PrintHyperplane          print(const char *message) const { return PrintHyperplane(message, "", *this); }
0107     PrintHyperplane          print(const char *message, const char *offsetMessage) const { return PrintHyperplane(message, offsetMessage, *this); }
0108 
0109 };//QhullHyperplane
0110 
0111 //! QhullHyperplaneIterator is a Java-style iterator for QhullHyperplane coordinates
0112 QHULL_DECLARE_SEQUENTIAL_ITERATOR(QhullHyperplane, coordT)
0113 
0114 }//namespace orgQhull
0115 
0116 #//!\name Global
0117 
0118 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullHyperplane::PrintHyperplane &pr);
0119 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullHyperplane &p);
0120 
0121 #endif // QHHYPERPLANE_H
0122