Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002 **
0003 ** Copyright (c) 2008-2020 C.B. Barber. All rights reserved.
0004 ** $Id: //main/2019/qhull/src/libqhullcpp/QhullFacet.h#4 $$Change: 2963 $
0005 ** $DateTime: 2020/06/03 19:31:01 $$Author: bbarber $
0006 **
0007 ****************************************************************************/
0008 
0009 #ifndef QHULLFACET_H
0010 #define QHULLFACET_H
0011 
0012 #include "libqhull_r/qhull_ra.h"
0013 #include "libqhullcpp/QhullHyperplane.h"
0014 #include "libqhullcpp/QhullPoint.h"
0015 #include "libqhullcpp/QhullSet.h"
0016 #include "libqhullcpp/QhullPointSet.h"
0017 
0018 #include <ostream>
0019 
0020 namespace orgQhull {
0021 
0022 #//!\name Used here
0023     class Coordinates;
0024     class Qhull;
0025     class QhullFacetSet;
0026     class QhullRidge;
0027     class QhullVertex;
0028     class QhullVertexSet;
0029 
0030 #//!\name Defined here
0031     class QhullFacet;
0032     typedef QhullSet<QhullRidge>  QhullRidgeSet;
0033 
0034 //! A QhullFacet is the C++ equivalent to Qhull's facetT*
0035 class QhullFacet {
0036 
0037 #//!\name Defined here
0038 public:
0039     typedef facetT *   base_type;  // for QhullVertexSet
0040 
0041 private:
0042 #//!\name Fields -- no additions (QhullFacetSet of facetT*)
0043     facetT *            qh_facet;  //!< Corresponding facetT, may be 0 for corner cases (e.g., *facetSet.end()==0) and tricoplanarOwner()
0044     QhullQh *           qh_qh;     //!< QhullQh/qhT for facetT, may be 0
0045 
0046 #//!\name Class objects
0047     static facetT       s_empty_facet; // needed for shallow copy
0048 
0049 public:
0050 #//!\name Constructors
0051                         QhullFacet() : qh_facet(&s_empty_facet), qh_qh(0) {}
0052     explicit            QhullFacet(const Qhull &q);
0053                         QhullFacet(const Qhull &q, facetT *f);
0054     explicit            QhullFacet(QhullQh *qqh) : qh_facet(&s_empty_facet), qh_qh(qqh) {}
0055                         QhullFacet(QhullQh *qqh, facetT *f) : qh_facet(f ? f : &s_empty_facet), qh_qh(qqh) {}
0056                         // Creates an alias.  Does not copy QhullFacet.  Needed for return by value and parameter passing
0057                         QhullFacet(const QhullFacet &other) : qh_facet(other.qh_facet ? other.qh_facet : &s_empty_facet), qh_qh(other.qh_qh) {}
0058                         // Creates an alias.  Does not copy QhullFacet.  Needed for vector<QhullFacet>
0059     QhullFacet &        operator=(const QhullFacet &other) { qh_facet= other.qh_facet ? other.qh_facet : &s_empty_facet; qh_qh= other.qh_qh; return *this; }
0060                         ~QhullFacet() {}
0061 
0062 
0063 #//!\name GetSet
0064     int                 dimension() const { return (qh_qh ? qh_qh->hull_dim : 0); }
0065     QhullPoint          getCenter() { return getCenter(qh_PRINTpoints); }
0066     QhullPoint          getCenter(qh_PRINT printFormat);
0067     facetT *            getBaseT() const { return getFacetT(); } //!< For QhullSet<QhullFacet>
0068                         // Do not define facetT().  It conflicts with return type facetT*
0069     facetT *            getFacetT() const { return qh_facet; }
0070     bool                hasNext() const { return (qh_facet->next != NULL && qh_facet->next != qh_qh->facet_tail); }
0071     bool                hasPrevious() const { return (qh_facet->previous != NULL); }
0072     QhullHyperplane     hyperplane() const { return QhullHyperplane(qh_qh, dimension(), qh_facet->normal, qh_facet->offset); }
0073     countT              id() const { return (qh_facet ? qh_facet->id : static_cast<countT>(qh_IDunknown)); }
0074     QhullHyperplane     innerplane() const;
0075     bool                isValid() const { return qh_qh && qh_facet && qh_facet != &s_empty_facet; }
0076     bool                isGood() const { return qh_facet && qh_facet->good; }
0077     bool                isSimplicial() const { return qh_facet && qh_facet->simplicial; }
0078     bool                isTopOrient() const { return qh_facet && qh_facet->toporient; }
0079     bool                isTriCoplanar() const { return qh_facet && qh_facet->tricoplanar; }
0080     bool                isUpperDelaunay() const { return qh_facet && qh_facet->upperdelaunay; }
0081     QhullFacet          next() const { return QhullFacet(qh_qh, qh_facet->next); }
0082     QhullFacet          nextFacet2d(QhullVertex *nextVertex) const;
0083     bool                operator==(const QhullFacet &other) const { return qh_facet==other.qh_facet; }
0084     bool                operator!=(const QhullFacet &other) const { return !operator==(other); }
0085     QhullHyperplane     outerplane() const;
0086     QhullFacet          previous() const { return QhullFacet(qh_qh, qh_facet->previous); }
0087     QhullQh *           qh() const { return qh_qh; }
0088     void                setFacetT(QhullQh *qqh, facetT *facet) { qh_qh= qqh; qh_facet= facet; }
0089     QhullFacet          tricoplanarOwner() const;
0090     int                 visitId() const { return (qh_facet ? qh_facet->visitid : -1); }
0091     QhullPoint          voronoiVertex();
0092 
0093 #//!\name value
0094     //! Undefined if c.size() != dimension()
0095     double              distance(const Coordinates &c) const { return distance(c.data()); }
0096     double              distance(const pointT *p) const { return distance(QhullPoint(qh_qh, const_cast<coordT *>(p))); }
0097     double              distance(const QhullPoint &p) const { return hyperplane().distance(p); }
0098     double              facetArea();
0099 
0100 #//!\name foreach
0101     // Can not inline.  Otherwise circular reference
0102     QhullPointSet       coplanarPoints() const;
0103     QhullFacetSet       neighborFacets() const;
0104     QhullPointSet       outsidePoints() const;
0105     QhullRidgeSet       ridges() const;
0106     QhullVertexSet      vertices() const;
0107 
0108 #//!\name IO
0109     struct PrintCenter{
0110         QhullFacet *    facet;  // non-const due to facet.center()
0111         const char *    message;
0112         qh_PRINT        print_format;
0113                         PrintCenter(QhullFacet &f, qh_PRINT printFormat, const char * s) : facet(&f), message(s), print_format(printFormat){}
0114     };//PrintCenter
0115     PrintCenter         printCenter(qh_PRINT printFormat, const char *message) { return PrintCenter(*this, printFormat, message); }
0116 
0117     struct PrintFacet{
0118         QhullFacet *    facet;  // non-const due to f->center()
0119         const char *    message;
0120         explicit        PrintFacet(QhullFacet &f, const char * s) : facet(&f), message(s) {}
0121     };//PrintFacet
0122     PrintFacet          print(const char *message) { return PrintFacet(*this, message); }
0123 
0124     struct PrintFlags{
0125         const QhullFacet *facet;
0126         const char *    message;
0127                         PrintFlags(const QhullFacet &f, const char *s) : facet(&f), message(s) {}
0128     };//PrintFlags
0129     PrintFlags          printFlags(const char *message) const { return PrintFlags(*this, message); }
0130 
0131     struct PrintHeader{
0132         QhullFacet *    facet;  // non-const due to f->center()
0133                         PrintHeader(QhullFacet &f) : facet(&f) {}
0134     };//PrintHeader
0135     PrintHeader         printHeader() { return PrintHeader(*this); }
0136 
0137     struct PrintRidges{
0138         const QhullFacet *facet;
0139                         PrintRidges(QhullFacet &f) : facet(&f) {}
0140     };//PrintRidges
0141     PrintRidges         printRidges() { return PrintRidges(*this); }
0142 
0143 };//class QhullFacet
0144 
0145 }//namespace orgQhull
0146 
0147 #//!\name Global
0148 
0149 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintFacet &pr);
0150 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintCenter &pr);
0151 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintFlags &pr);
0152 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintHeader &pr);
0153 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintRidges &pr);
0154 std::ostream &operator<<(std::ostream &os, orgQhull::QhullFacet &f); // non-const due to qh_getcenter()
0155 
0156 #endif // QHULLFACET_H