Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002 **
0003 ** Copyright (c) 2008-2020 C.B. Barber. All rights reserved.
0004 ** $Id: //main/2019/qhull/src/libqhullcpp/QhullRidge.h#4 $$Change: 3001 $
0005 ** $DateTime: 2020/07/24 20:43:28 $$Author: bbarber $
0006 **
0007 ****************************************************************************/
0008 
0009 #ifndef QHULLRIDGE_H
0010 #define QHULLRIDGE_H
0011 
0012 #include "libqhull_r/qhull_ra.h"
0013 #include "libqhullcpp/QhullSet.h"
0014 #include "libqhullcpp/QhullVertex.h"
0015 #include "libqhullcpp/QhullVertexSet.h"
0016 #include "libqhullcpp/QhullFacet.h"
0017 
0018 #include <ostream>
0019 
0020 namespace orgQhull {
0021 
0022 #//!\name Used here
0023     class Qhull;
0024     class QhullVertex;
0025     class QhullVertexSet;
0026     class QhullFacet;
0027 
0028 #//!\name Defined here
0029     //! QhullRidge -- Qhull's ridge structure, ridgeT [libqhull.h], as a C++ class
0030     class QhullRidge;
0031 
0032     typedef QhullSet<QhullRidge>  QhullRidgeSet;
0033 
0034     //! QhullRidgeSetIterator is a Java-style iterator for QhullRidge in a QhullRidgeSet
0035     //! QhullRidgeSetIterator may be used on temporary results.  It copies the pointers in QhullRidgeSet
0036     //! Use QhullSets.h to avoid circular references to QhullRidgeSet and QhullRidgeSetIterator
0037     typedef QhullSetIterator<QhullRidge>  QhullRidgeSetIterator;
0038 
0039 /************************
0040 a ridge is hull_dim-1 simplex between two neighboring facets.  If the
0041 facets are non-simplicial, there may be more than one ridge between
0042 two facets.  E.G. a 4-d hypercube has two triangles between each pair
0043 of neighboring facets.
0044 
0045 topological information:
0046     vertices            a set of vertices
0047     top,bottom          neighboring facets with orientation
0048 
0049 geometric information:
0050     tested              True if ridge is clearly convex
0051     nonconvex           True if ridge is non-convex
0052 */
0053 
0054 class QhullRidge {
0055 
0056 #//!\name Defined here
0057 public:
0058     typedef ridgeT *   base_type;  // for QhullRidgeSet
0059 
0060 #//!\name Fields
0061 private:
0062     ridgeT *            qh_ridge;  //!< Corresponding ridgeT, never 0
0063     QhullQh *           qh_qh;     //!< QhullQh/qhT for ridgeT, may be 0
0064 
0065 #//!\name Class objects
0066     static ridgeT       s_empty_ridge;
0067 
0068 public:
0069 #//!\name Constants
0070 
0071 #//!\name Constructors
0072                         QhullRidge() : qh_ridge(&s_empty_ridge), qh_qh(0) {}
0073     explicit            QhullRidge(const Qhull &q);
0074                         QhullRidge(const Qhull &q, ridgeT *r);
0075     explicit            QhullRidge(QhullQh *qqh) : qh_ridge(&s_empty_ridge), qh_qh(qqh) {}
0076                         QhullRidge(QhullQh *qqh, ridgeT *r) : qh_ridge(r ? r : &s_empty_ridge), qh_qh(qqh) {}
0077                         // Creates an alias.  Does not copy QhullRidge.  Needed for return by value and parameter passing
0078                         QhullRidge(const QhullRidge &other) : qh_ridge(other.qh_ridge), qh_qh(other.qh_qh) {}
0079                         // Creates an alias.  Does not copy QhullRidge.  Needed for vector<QhullRidge>
0080     QhullRidge &        operator=(const QhullRidge &other) { qh_ridge= other.qh_ridge; qh_qh= other.qh_qh; return *this; }
0081                         ~QhullRidge() {}
0082 
0083 #//!\name GetSet
0084     QhullFacet          bottomFacet() const { return QhullFacet(qh_qh, qh_ridge->bottom); }
0085     int                 dimension() const { return ((qh_qh && qh_qh->hull_dim) ? qh_qh->hull_dim-1 : 0); }
0086     ridgeT *            getBaseT() const { return getRidgeT(); } //!< For QhullSet<QhullRidge>
0087     ridgeT *            getRidgeT() const { return qh_ridge; }
0088     countT              id() const { return qh_ridge->id; }
0089     bool                isValid() const { return (qh_qh && qh_ridge != &s_empty_ridge); }
0090     bool                operator==(const QhullRidge &other) const { return qh_ridge==other.qh_ridge; }
0091     bool                operator!=(const QhullRidge &other) const { return !operator==(other); }
0092     QhullFacet          otherFacet(const QhullFacet &f) const { return QhullFacet(qh_qh, (qh_ridge->top==f.getFacetT() ? qh_ridge->bottom : qh_ridge->top)); }
0093     QhullQh *           qh() const { return qh_qh; }
0094     void                setRidgeT(QhullQh *qqh, ridgeT *ridge) { qh_qh= qqh; qh_ridge= ridge; }
0095     QhullFacet          topFacet() const { return QhullFacet(qh_qh, qh_ridge->top); }
0096 
0097 #//!\name foreach
0098     bool                hasNextRidge3d(const QhullFacet &f) const;
0099     QhullRidge          nextRidge3d(const QhullFacet &f) const { return nextRidge3d(f, 0); }
0100     QhullRidge          nextRidge3d(const QhullFacet &f, QhullVertex *nextVertex) const;
0101     QhullVertexSet      vertices() const { return QhullVertexSet(qh_qh, qh_ridge->vertices); }
0102 
0103 #//!\name IO
0104 
0105     struct PrintRidge{
0106         const QhullRidge *ridge;
0107         const char *    print_message;    //!< non-null message
0108                         PrintRidge(const char *message, const QhullRidge &r) : ridge(&r), print_message(message) {}
0109     };//PrintRidge
0110     PrintRidge          print(const char* message) const { return PrintRidge(message, *this); }
0111 };//class QhullRidge
0112 
0113 }//namespace orgQhull
0114 
0115 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullRidge &r);
0116 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullRidge::PrintRidge &pr);
0117 
0118 #endif // QHULLRIDGE_H