[10207] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (c) 2008-2012 C.B. Barber. All rights reserved.
|
---|
| 4 | ** $Id: //main/2011/qhull/src/libqhullcpp/QhullFacet.h#7 $$Change: 1464 $
|
---|
| 5 | ** $DateTime: 2012/01/25 22:58:41 $$Author: bbarber $
|
---|
| 6 | **
|
---|
| 7 | ****************************************************************************/
|
---|
| 8 |
|
---|
| 9 | #ifndef QHULLFACET_H
|
---|
| 10 | #define QHULLFACET_H
|
---|
| 11 |
|
---|
| 12 | #include "Coordinates.h"
|
---|
| 13 | #include "QhullHyperplane.h"
|
---|
| 14 | #include "QhullPoint.h"
|
---|
| 15 | #include "QhullSet.h"
|
---|
| 16 | #include "QhullPointSet.h"
|
---|
| 17 | extern "C" {
|
---|
| 18 | #include "libqhull/qhull_a.h"
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | #include <string>
|
---|
| 22 | #include <vector>
|
---|
| 23 | #include <ostream>
|
---|
| 24 |
|
---|
| 25 | namespace orgQhull {
|
---|
| 26 |
|
---|
| 27 | #//ClassRef
|
---|
| 28 | class QhullFacetSet;
|
---|
| 29 | class QhullRidge;
|
---|
| 30 | typedef QhullSet<QhullRidge> QhullRidgeSet;
|
---|
| 31 | class QhullVertex;
|
---|
| 32 | class QhullVertexSet;
|
---|
| 33 |
|
---|
| 34 | #//Types
|
---|
| 35 | //! QhullFacet -- Qhull's facet structure, facetT [libqhull.h], as a C++ class
|
---|
| 36 | class QhullFacet;
|
---|
| 37 |
|
---|
| 38 | //! A QhullFacet is the C++ equivalent to Qhull's facetT*
|
---|
| 39 | class QhullFacet {
|
---|
| 40 |
|
---|
| 41 | private:
|
---|
| 42 | #//Fields -- no additions (QhullFacetSet of facetT*)
|
---|
| 43 | facetT *qh_facet; //! May be 0 (!isDefined) for corner cases (e.g., *facetSet.end()==0) and tricoplanarOwner()
|
---|
| 44 |
|
---|
| 45 | #//Class objects
|
---|
| 46 | static facetT s_empty_facet; // needed for shallow copy
|
---|
| 47 |
|
---|
| 48 | public:
|
---|
| 49 | #//Constants
|
---|
| 50 |
|
---|
| 51 | #//Constructors
|
---|
| 52 | QhullFacet() : qh_facet(&s_empty_facet) {}
|
---|
| 53 | // Creates an alias. Does not copy QhullFacet. Needed for return by value and parameter passing
|
---|
| 54 | QhullFacet(const QhullFacet &o) : qh_facet(o.qh_facet ? o.qh_facet : &s_empty_facet) {}
|
---|
| 55 | // Creates an alias. Does not copy QhullFacet. Needed for vector<QhullFacet>
|
---|
| 56 | QhullFacet &operator=(const QhullFacet &o) { qh_facet= o.qh_facet ? o.qh_facet : &s_empty_facet; return *this; }
|
---|
| 57 | ~QhullFacet() {}
|
---|
| 58 |
|
---|
| 59 | #//Conversion
|
---|
| 60 | //Implicit conversion from facetT
|
---|
| 61 | QhullFacet(facetT *f) : qh_facet(f ? f : &s_empty_facet) {}
|
---|
| 62 | // Do not define facetT(). It conflicts with return type facetT*
|
---|
| 63 | facetT *getFacetT() const { return qh_facet; }
|
---|
| 64 |
|
---|
| 65 | #//QhullSet<QhullFacet>
|
---|
| 66 | facetT *getBaseT() const { return getFacetT(); }
|
---|
| 67 |
|
---|
| 68 | #//getSet
|
---|
| 69 | int dimension() const;
|
---|
| 70 | QhullPoint getCenter(int qhRunId) { return getCenter(qhRunId, qh_PRINTpoints); }
|
---|
| 71 | QhullPoint getCenter(int qhRunId, qh_PRINT printFormat);
|
---|
| 72 | QhullHyperplane hyperplane() const { return QhullHyperplane(dimension(), qh_facet->normal, qh_facet->offset); }
|
---|
| 73 | int id() const { return qh_facet ? qh_facet->id : -1; }
|
---|
| 74 | QhullHyperplane innerplane(int qhRunId) const;
|
---|
| 75 | bool isDefined() const { return qh_facet && qh_facet != &s_empty_facet; }
|
---|
| 76 | bool isGood() const { return qh_facet && qh_facet->good; }
|
---|
| 77 | bool isSimplicial() const { return qh_facet->simplicial; }
|
---|
| 78 | bool isTopOrient() const { return qh_facet->toporient; }
|
---|
| 79 | bool isTriCoplanar() const { return qh_facet->tricoplanar; }
|
---|
| 80 | bool isUpperDelaunay() const { return qh_facet->upperdelaunay; }
|
---|
| 81 | QhullFacet next() const { return qh_facet->next; }
|
---|
| 82 | bool operator==(const QhullFacet &o) const { return qh_facet==o.qh_facet; }
|
---|
| 83 | bool operator!=(const QhullFacet &o) const { return !operator==(o); }
|
---|
| 84 | QhullHyperplane outerplane(int qhRunId) const;
|
---|
| 85 | QhullFacet previous() const { return qh_facet->previous; }
|
---|
| 86 | QhullFacet tricoplanarOwner() const;
|
---|
| 87 | QhullPoint voronoiVertex(int qhRunId);
|
---|
| 88 |
|
---|
| 89 | #//value
|
---|
| 90 | //! Undefined if c.size() != dimension()
|
---|
| 91 | double distance(const Coordinates &c) const { return distance(c.data()); }
|
---|
| 92 | double distance(const pointT *p) const { return distance(QhullPoint(dimension(), const_cast<coordT *>(p))); }
|
---|
| 93 | double distance(const QhullPoint &p) const { return hyperplane().distance(p); }
|
---|
| 94 | double facetArea(int qhRunId);
|
---|
| 95 |
|
---|
| 96 | #//foreach
|
---|
| 97 | // Can not inline. Otherwise circular reference
|
---|
| 98 | QhullPointSet coplanarPoints() const;
|
---|
| 99 | QhullFacetSet neighborFacets() const;
|
---|
| 100 | QhullPointSet outsidePoints() const;
|
---|
| 101 | QhullRidgeSet ridges() const;
|
---|
| 102 | QhullVertexSet vertices() const;
|
---|
| 103 |
|
---|
| 104 | #//IO
|
---|
| 105 | struct PrintCenter{
|
---|
| 106 | QhullFacet *facet; // non-const due to facet.center()
|
---|
| 107 | const char *message;
|
---|
| 108 | int run_id;
|
---|
| 109 | qh_PRINT print_format;
|
---|
| 110 | PrintCenter(int qhRunId, QhullFacet &f, qh_PRINT printFormat, const char * s) : facet(&f), message(s), run_id(qhRunId), print_format(printFormat){}
|
---|
| 111 | };//PrintCenter
|
---|
| 112 | PrintCenter printCenter(int qhRunId, qh_PRINT printFormat, const char *message) { return PrintCenter(qhRunId, *this, printFormat, message); }
|
---|
| 113 |
|
---|
| 114 | struct PrintFacet{
|
---|
| 115 | QhullFacet *facet; // non-const due to f->center()
|
---|
| 116 | int run_id;
|
---|
| 117 | PrintFacet(int qhRunId, QhullFacet &f) : facet(&f), run_id(qhRunId) {}
|
---|
| 118 | };//PrintFacet
|
---|
| 119 | PrintFacet print(int qhRunId) { return PrintFacet(qhRunId, *this); }
|
---|
| 120 |
|
---|
| 121 | struct PrintFlags{
|
---|
| 122 | const QhullFacet *facet;
|
---|
| 123 | const char *message;
|
---|
| 124 | PrintFlags(const QhullFacet &f, const char *s) : facet(&f), message(s) {}
|
---|
| 125 | };//PrintFlags
|
---|
| 126 | PrintFlags printFlags(const char *message) const { return PrintFlags(*this, message); }
|
---|
| 127 |
|
---|
| 128 | struct PrintHeader{
|
---|
| 129 | QhullFacet *facet; // non-const due to f->center()
|
---|
| 130 | int run_id;
|
---|
| 131 | PrintHeader(int qhRunId, QhullFacet &f) : facet(&f), run_id(qhRunId) {}
|
---|
| 132 | };//PrintHeader
|
---|
| 133 | PrintHeader printHeader(int qhRunId) { return PrintHeader(qhRunId, *this); }
|
---|
| 134 |
|
---|
| 135 | struct PrintRidges{
|
---|
| 136 | const QhullFacet *facet;
|
---|
| 137 | int run_id;
|
---|
| 138 | PrintRidges(int qhRunId, QhullFacet &f) : facet(&f), run_id(qhRunId) {}
|
---|
| 139 | };//PrintRidges
|
---|
| 140 | PrintRidges printRidges(int qhRunId) { return PrintRidges(qhRunId, *this); }
|
---|
| 141 |
|
---|
| 142 | };//class QhullFacet
|
---|
| 143 |
|
---|
| 144 | }//namespace orgQhull
|
---|
| 145 |
|
---|
| 146 | #//Global functions
|
---|
| 147 |
|
---|
| 148 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintCenter &pr);
|
---|
| 149 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintFlags &pr);
|
---|
| 150 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintHeader &pr);
|
---|
| 151 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintRidges &pr);
|
---|
| 152 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullFacet::PrintFacet &pr);
|
---|
| 153 | std::ostream &operator<<(std::ostream &os, orgQhull::QhullFacet &f); // non-const due to qh_getcenter()
|
---|
| 154 |
|
---|
| 155 | #endif // QHULLFACET_H
|
---|