irafhy
Interval arithmetic based Reachability Analysis Framework for Hybrid Automaton
extQhull.hpp
Go to the documentation of this file.
1 #ifndef UTILITY_EXTENSION_EXT_QHULL_H
2 #define UTILITY_EXTENSION_EXT_QHULL_H
3 
6 #include <libqhullcpp/QhullHyperplane.h>
7 #include <libqhullcpp/QhullFacet.h>
8 #include <libqhullcpp/QhullVertexSet.h>
9 #include <libqhullcpp/QhullFacetSet.h>
10 #include <libqhullcpp/QhullFacetList.h>
11 #include <libqhullcpp/Qhull.h>
12 #include <vector>
13 
14 namespace orgQhull
15 {
21  static Eigen::VectorXd getNormal(const QhullHyperplane& qhullHyperplane)
22  {
23  int dimension = qhullHyperplane.dimension();
24  Eigen::VectorXd retNorm = Eigen::VectorXd::Zero(dimension);
25  const realT* c = qhullHyperplane.coordinates();
26  for (int dimIdx = 0; dimIdx < dimension; ++dimIdx)
27  retNorm(dimIdx) = double(*c++);
28  return retNorm;
29  }
35  static double getOffset(const QhullHyperplane& qhullHyperplane) { return qhullHyperplane.offset(); }
41  static std::vector<int> getVerticesIdx(const QhullFacet& qhullFacet)
42  {
43  std::vector<int> retIndices;
44  retIndices.reserve(qhullFacet.vertices().size());
45  for (const QhullVertex& qhullVertex : qhullFacet.vertices())
46  retIndices.emplace_back(qhullVertex.point().id());
47  return retIndices;
48  }
54  static std::vector<irafhy::Point> getVertices(const Qhull& qhull)
55  {
56  std::vector<irafhy::Point> retVertices;
57  retVertices.reserve(qhull.vertexCount());
58  for (const QhullVertex& qhullVertex : qhull.vertexList())
59  retVertices.emplace_back(irafhy::Point(qhullVertex.point().toStdVector()));
60  return retVertices;
61  }
67  static std::vector<irafhy::Point> getVertices(const QhullFacet& qhullFacet)
68  {
69  std::vector<irafhy::Point> retVertices;
70  retVertices.reserve(qhullFacet.vertices().size());
71  for (const QhullVertex& qhullVertex : qhullFacet.vertices())
72  retVertices.emplace_back(irafhy::Point(qhullVertex.point().toStdVector()));
73  return retVertices;
74  }
80  static std::vector<irafhy::HalfSpace> getHalfSpaces(const Qhull& qhull)
81  {
82  std::vector<irafhy::HalfSpace> retHalfSpaces;
83  retHalfSpaces.reserve(qhull.facetCount());
84  for (const QhullFacet& qhullFacet : qhull.facetList())
85  retHalfSpaces.emplace_back(
86  irafhy::HalfSpace(getNormal(qhullFacet.hyperplane()), getOffset(qhullFacet.hyperplane())));
87  return retHalfSpaces;
88  }
94  static std::vector<irafhy::HalfSpace> getHalfSpaces(const QhullFacetSet& qhullFacetSet)
95  {
96  std::vector<irafhy::HalfSpace> retHalfSpaces;
97  retHalfSpaces.reserve(qhullFacetSet.size());
98  for (const QhullFacet& qhullFacet : qhullFacetSet)
99  retHalfSpaces.emplace_back(
100  irafhy::HalfSpace(getNormal(qhullFacet.hyperplane()), getOffset(qhullFacet.hyperplane())));
101  return retHalfSpaces;
102  }
109  static bool contains(const irafhy::Point& point, const Qhull& qhull)
110  {
111  for (const QhullFacet& qhullFacet : qhull.facetList())
112  {
113  Eigen::VectorXd normal = getNormal(qhullFacet.hyperplane());
114  double offset = getOffset(qhullFacet.hyperplane());
115  if (normal.dot(point.coordinate()) + offset > 0)
116  return false;
117  }
118  return true;
119  }
120 } // namespace orgQhull
121 #endif //UTILITY_EXTENSION_EXT_QHULL_H
Definition: extQhull.hpp:14
Eigen::VectorXd coordinate() const
get the coordinate of the point
Definition: point.cpp:38
Definition: point.h:10
Definition: halfSpace.h:8