1 /****************************************************************************
2 **
3 ** Copyright (c) 2008-2012 C.B. Barber. All rights reserved.
4 ** $Id: //main/2011/qhull/src/libqhullcpp/QhullRidge.h#6 $$Change: 1464 $
5 ** $DateTime: 2012/01/25 22:58:41 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #ifndef QHULLRIDGE_H
10 #define QHULLRIDGE_H
11 
12 #include "QhullSet.h"
13 #include "QhullVertex.h"
14 #include "QhullVertexSet.h"
15 #include "QhullFacet.h"
16 extern "C" {
17     #include "libqhull/qhull_a.h"
18 }
19 
20 #include <ostream>
21 
22 namespace orgQhull {
23 
24 #//ClassRef
25     class QhullVertex;
26     class QhullVertexSet;
27     class QhullFacet;
28 
29 #//Types
30     //! QhullRidge -- Qhull's ridge structure, ridgeT [libqhull.h], as a C++ class
31     class QhullRidge;
32     typedef QhullSet<QhullRidge>  QhullRidgeSet;
33     typedef QhullSetIterator<QhullRidge>  QhullRidgeSetIterator;
34 
35     // see QhullSets.h for QhullRidgeSet and QhullRidgeSetIterator -- avoids circular references
36 
37 /************************
38 a ridge is hull_dim-1 simplex between two neighboring facets.  If the
39 facets are non-simplicial, there may be more than one ridge between
40 two facets.  E.G. a 4-d hypercube has two triangles between each pair
41 of neighboring facets.
42 
43 topological information:
44     vertices            a set of vertices
45     top,bottom          neighboring facets with orientation
46 
47 geometric information:
48     tested              True if ridge is clearly convex
49     nonconvex           True if ridge is non-convex
50 */
51 
52 class QhullRidge {
53 
54 #//Fields
55     ridgeT             *qh_ridge;
56 
57 #//Class objects
58     static ridgeT       s_empty_ridge;
59 
60 public:
61 #//Constants
62 
63 #//Constructors
QhullRidge()64                         QhullRidge() : qh_ridge(&s_empty_ridge) {}
65                         // Creates an alias.  Does not copy QhullRidge.  Needed for return by value and parameter passing
QhullRidge(const QhullRidge & o)66                         QhullRidge(const QhullRidge &o) : qh_ridge(o.qh_ridge) {}
67                         // Creates an alias.  Does not copy QhullRidge.  Needed for vector<QhullRidge>
68     QhullRidge         &operator=(const QhullRidge &o) { qh_ridge= o.qh_ridge; return *this; }
~QhullRidge()69                        ~QhullRidge() {}
70 
71 #//Conversion
72                         //Implicit conversion from ridgeT
QhullRidge(ridgeT * r)73                         QhullRidge(ridgeT *r) : qh_ridge(r ? r : &s_empty_ridge) {}
getRidgeT()74     ridgeT             *getRidgeT() const { return qh_ridge; }
75 
76 #//QhullSet<QhullRidge>
getBaseT()77     ridgeT             *getBaseT() const { return getRidgeT(); }
78 
79 #//getSet
bottomFacet()80     QhullFacet          bottomFacet() const { return QhullFacet(qh_ridge->bottom); }
dimension()81     int                 dimension() const { return QhullSetBase::count(qh_ridge->vertices); }
id()82     int                 id() const { return qh_ridge->id; }
isDefined()83     bool                isDefined() const { return qh_ridge != &s_empty_ridge; }
84     bool                operator==(const QhullRidge &o) const { return qh_ridge==o.qh_ridge; }
85     bool                operator!=(const QhullRidge &o) const { return !operator==(o); }
otherFacet(QhullFacet f)86     QhullFacet          otherFacet(QhullFacet f) const { return QhullFacet(qh_ridge->top==f.getFacetT() ? qh_ridge->bottom : qh_ridge->top); }
topFacet()87     QhullFacet          topFacet() const { return QhullFacet(qh_ridge->top); }
88 
89 #//forEach
90     bool                hasNextRidge3d(const QhullFacet f) const;
nextRidge3d(const QhullFacet f)91     QhullRidge          nextRidge3d(const QhullFacet f) const { return nextRidge3d(f, 0); }
92     QhullRidge          nextRidge3d(const QhullFacet f, QhullVertex *nextVertex) const;
vertices()93     QhullVertexSet      vertices() const { return QhullVertexSet(qh_ridge->vertices); }
94 
95 #//IO
96 
97     struct PrintRidge{
98         const QhullRidge *ridge;
99         int             run_id;
PrintRidgePrintRidge100                         PrintRidge(int qhRunId, const QhullRidge &r) : ridge(&r), run_id(qhRunId) {}
101     };//PrintRidge
print(int qhRunId)102     PrintRidge          print(int qhRunId) const { return PrintRidge(qhRunId, *this); }
103 };//class QhullRidge
104 
105 }//namespace orgQhull
106 
107 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullRidge &r);
108 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullRidge::PrintRidge &pr);
109 
110 #endif // QHULLRIDGE_H
111