1 /**************************************************************************** 2 ** 3 ** Copyright (c) 2008-2020 C.B. Barber. All rights reserved. 4 ** $Id: //main/2019/qhull/src/libqhullcpp/Qhull.h#5 $$Change: 2956 $ 5 ** $DateTime: 2020/05/23 21:08:29 $$Author: bbarber $ 6 ** 7 ****************************************************************************/ 8 9 #ifndef QHULLCPP_H 10 #define QHULLCPP_H 11 12 #include "libqhullcpp/QhullPoint.h" 13 #include "libqhullcpp/QhullVertex.h" 14 #include "libqhullcpp/QhullFacet.h" 15 16 namespace orgQhull { 17 18 /*** 19 Compile qhullcpp and libqhull with the same compiler. setjmp() and longjmp() must be the same. 20 21 #define QHULL_NO_STL 22 Do not supply conversions to STL 23 Coordinates.h requires <vector>. It could be rewritten for another vector class such as QList 24 #define QHULL_USES_QT 25 Supply conversions to QT 26 qhulltest requires QT. It is defined in RoadTest.h 27 28 #define QHULL_ASSERT 29 Defined by QhullError.h 30 It invokes assert() 31 */ 32 33 #//!\name Used here 34 class QhullFacetList; 35 class QhullPoints; 36 class QhullQh; 37 class RboxPoints; 38 39 #//!\name Defined here 40 class Qhull; 41 42 //! Interface to Qhull from C++ 43 class Qhull { 44 45 private: 46 #//!\name Members and friends 47 QhullQh * qh_qh; //! qhT for this instance 48 Coordinates origin_point; //! origin for qh_qh->hull_dim. Set by runQhull() 49 bool run_called; //! True at start of runQhull. Errors if call again. 50 Coordinates feasible_point; //! feasible point for half-space intersection (alternative to qh.feasible_string for qh.feasible_point) 51 52 public: 53 #//!\name Constructors 54 Qhull(); //!< call runQhull() next 55 Qhull(const RboxPoints &rboxPoints, const char *qhullCommand2); 56 Qhull(const char *inputComment2, int pointDimension, int pointCount, const realT *pointCoordinates, const char *qhullCommand2); 57 ~Qhull() throw(); 58 private: //! Disable copy constructor and assignment. Qhull owns QhullQh. 59 Qhull(const Qhull &); 60 Qhull & operator=(const Qhull &); 61 62 private: 63 void allocateQhullQh(); 64 65 public: 66 67 #//!\name GetSet 68 void checkIfQhullInitialized(); dimension()69 int dimension() const { return qh_qh->input_dim; } //!< Dimension of input and result disableOutputStream()70 void disableOutputStream() { qh_qh->disableOutputStream(); } enableOutputStream()71 void enableOutputStream() { qh_qh->enableOutputStream(); } facetCount()72 countT facetCount() const { return qh_qh->num_facets; } 73 Coordinates feasiblePoint() const; hullDimension()74 int hullDimension() const { return qh_qh->hull_dim; } //!< Dimension of the computed hull hasOutputStream()75 bool hasOutputStream() const { return qh_qh->hasOutputStream(); } initialized()76 bool initialized() const { return (qh_qh->hull_dim>0); } inputComment()77 const char * inputComment() const { return qh_qh->rbox_command; } 78 QhullPoint inputOrigin(); isDelaunay()79 bool isDelaunay() const { return qh_qh->DELAUNAY; } 80 //! non-const due to QhullPoint origin()81 QhullPoint origin() { QHULL_ASSERT(initialized()); return QhullPoint(qh_qh, origin_point.data()); } qh()82 QhullQh * qh() const { return qh_qh; } qhullCommand()83 const char * qhullCommand() const { return qh_qh->qhull_command; } rboxCommand()84 const char * rboxCommand() const { return qh_qh->rbox_command; } rotateRandom()85 int rotateRandom() const { return qh_qh->ROTATErandom; } //!< Return QRn for repeating QR0 runs setFeasiblePoint(const Coordinates & c)86 void setFeasiblePoint(const Coordinates &c) { feasible_point= c; } //!< Sets qh.feasible_point via initializeFeasiblePoint vertexCount()87 countT vertexCount() const { return qh_qh->num_vertices; } 88 89 #//!\name Delegated to QhullQh angleEpsilon()90 double angleEpsilon() const { return qh_qh->angleEpsilon(); } //!< Epsilon for hyperplane angle equality appendQhullMessage(const std::string & s)91 void appendQhullMessage(const std::string &s) { qh_qh->appendQhullMessage(s); } clearQhullMessage()92 void clearQhullMessage() { qh_qh->clearQhullMessage(); } distanceEpsilon()93 double distanceEpsilon() const { return qh_qh->distanceEpsilon(); } //!< Epsilon for distance to hyperplane factorEpsilon()94 double factorEpsilon() const { return qh_qh->factorEpsilon(); } //!< Factor for angleEpsilon and distanceEpsilon qhullMessage()95 std::string qhullMessage() const { return qh_qh->qhullMessage(); } hasQhullMessage()96 bool hasQhullMessage() const { return qh_qh->hasQhullMessage(); } qhullStatus()97 int qhullStatus() const { return qh_qh->qhullStatus(); } setErrorStream(std::ostream * os)98 void setErrorStream(std::ostream *os) { qh_qh->setErrorStream(os); } setFactorEpsilon(double a)99 void setFactorEpsilon(double a) { qh_qh->setFactorEpsilon(a); } setOutputStream(std::ostream * os)100 void setOutputStream(std::ostream *os) { qh_qh->setOutputStream(os); } 101 102 #//!\name ForEach beginFacet()103 QhullFacet beginFacet() const { return QhullFacet(qh_qh, qh_qh->facet_list); } beginVertex()104 QhullVertex beginVertex() const { return QhullVertex(qh_qh, qh_qh->vertex_list); } 105 void defineVertexNeighborFacets(); //!< Automatically called if merging facets or Voronoi diagram endFacet()106 QhullFacet endFacet() const { return QhullFacet(qh_qh, qh_qh->facet_tail); } endVertex()107 QhullVertex endVertex() const { return QhullVertex(qh_qh, qh_qh->vertex_tail); } 108 QhullFacetList facetList() const; firstFacet()109 QhullFacet firstFacet() const { return beginFacet(); } firstVertex()110 QhullVertex firstVertex() const { return beginVertex(); } 111 QhullPoints points() const; 112 QhullPointSet otherPoints() const; 113 //! Same as points().coordinates() pointCoordinateBegin()114 coordT * pointCoordinateBegin() const { return qh_qh->first_point; } pointCoordinateEnd()115 coordT * pointCoordinateEnd() const { return qh_qh->first_point + qh_qh->num_points*qh_qh->hull_dim; } 116 QhullVertexList vertexList() const; 117 118 #//!\name Methods 119 double area(); 120 void outputQhull(); 121 void outputQhull(const char * outputflags); 122 void prepareVoronoi(bool *isLower, int *voronoiVertexCount); 123 void runQhull(const RboxPoints &rboxPoints, const char *qhullCommand2); 124 void runQhull(const char *inputComment2, int pointDimension, int pointCount, const realT *pointCoordinates, const char *qhullCommand2); 125 double volume(); 126 127 #//!\name Helpers 128 private: 129 void initializeFeasiblePoint(int hulldim); 130 };//Qhull 131 132 }//namespace orgQhull 133 134 #endif // QHULLCPP_H 135