QhullHyperplane.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2009-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/libqhullcpp/QhullHyperplane.cpp#3 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
10 
11 #include "libqhullcpp/Qhull.h"
12 #include "libqhullcpp/QhullPoint.h"
13 
14 #include <iostream>
15 
16 
17 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
18 #endif
19 
20 namespace orgQhull {
21 
22 #
23 
26 : hyperplane_coordinates(0)
27 , qh_qh(q.qh())
28 , hyperplane_offset(0.0)
29 , hyperplane_dimension(0)
30 {
31 }
32 
34 QhullHyperplane(const Qhull &q, int hyperplaneDimension, coordT *c, coordT hyperplaneOffset)
36 , qh_qh(q.qh())
37 , hyperplane_offset(hyperplaneOffset)
38 , hyperplane_dimension(hyperplaneDimension)
39 {
40 }
41 
42 #
43 
44 // See qt-qhull.cpp for QList conversions
45 
46 #ifndef QHULL_NO_STL
47 std::vector<coordT> QhullHyperplane::
48 toStdVector() const
49 {
50  QhullHyperplaneIterator i(*this);
51  std::vector<coordT> fs;
52  while(i.hasNext()){
53  fs.push_back(i.next());
54  }
55  fs.push_back(hyperplane_offset);
56  return fs;
57 }//toStdVector
58 #endif //QHULL_NO_STL
59 
60 #
61 
66 operator==(const QhullHyperplane &other) const
67 {
69  return false;
70  }
71  double d= fabs(hyperplane_offset-other.hyperplane_offset);
72  if(d > (qh_qh ? qh_qh->distanceEpsilon() : 0.0)){
73  return false;
74  }
75  double angle= hyperplaneAngle(other);
76 
77  double a= fabs(angle-1.0);
78  if(a > (qh_qh ? qh_qh->angleEpsilon() : 0.0)){
79  return false;
80  }
81  return true;
82 }//operator==
83 
84 #
85 
86 // qh_distplane [geom_r.c], QhullFacet::distance, and QhullHyperplane::distance are copies
89 // Does not support RANDOMdist or logging
90 double QhullHyperplane::
91 distance(const QhullPoint &p) const
92 {
93  const coordT *point= p.coordinates();
94  int dim= p.dimension();
95  QHULL_ASSERT(dim==dimension());
96  const coordT *normal= coordinates();
97  double dist;
98 
99  switch (dim){
100  case 2:
101  dist= offset() + point[0] * normal[0] + point[1] * normal[1];
102  break;
103  case 3:
104  dist= offset() + point[0] * normal[0] + point[1] * normal[1] + point[2] * normal[2];
105  break;
106  case 4:
107  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3];
108  break;
109  case 5:
110  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4];
111  break;
112  case 6:
113  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5];
114  break;
115  case 7:
116  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6];
117  break;
118  case 8:
119  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6]+point[7]*normal[7];
120  break;
121  default:
122  dist= offset();
123  for (int k=dim; k--; )
124  dist += *point++ * *normal++;
125  break;
126  }
127  return dist;
128 }//distance
129 
130 double QhullHyperplane::
131 hyperplaneAngle(const QhullHyperplane &other) const
132 {
133  volatile realT result= 0.0;
134  QH_TRY_(qh_qh){ // no object creation -- destructors skipped on longjmp()
136  }
137  qh_qh->NOerrexit= true;
138  qh_qh->maybeThrowQhullMessage(QH_TRY_status);
139  return result;
140 }//hyperplaneAngle
141 
142 double QhullHyperplane::
143 norm() const {
144  double d= 0.0;
145  const coordT *c= coordinates();
146  for (int k=dimension(); k--; ){
147  d += *c * *c;
148  ++c;
149  }
150  return sqrt(d);
151 }//norm
152 
153 }//namespace orgQhull
154 
155 #
156 
157 using std::ostream;
159 
160 #
161 
162 ostream &
163 operator<<(ostream &os, const QhullHyperplane &p)
164 {
165  os << p.print("");
166  return os;
167 }
168 
169 ostream &
170 operator<<(ostream &os, const QhullHyperplane::PrintHyperplane &pr)
171 {
172  os << pr.print_message;
173  QhullHyperplane p= *pr.hyperplane;
174  const realT *c= p.coordinates();
175  for(int k=p.dimension(); k--; ){
176  realT r= *c++;
177  if(pr.print_message){
178  os << " " << r; // FIXUP QH11010 %8.4g
179  }else{
180  os << " " << r; // FIXUP QH11010 qh_REAL_1
181  }
182  }
183  os << pr.hyperplane_offset_message << " " << p.offset();
184  os << std::endl;
185  return os;
186 }//PrintHyperplane
187 
coordT hyperplane_offset
Distance from hyperplane to origin.
double distanceEpsilon() const
Epsilon for distance to hyperplane.
Definition: QhullQh.h:106
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
void maybeThrowQhullMessage(int exitCode)
Definition: QhullQh.cpp:118
ostream & operator<<(ostream &os, const QhullHyperplane &p)
int dimension() const
Definition: QhullPoint.h:89
double angleEpsilon() const
Epsilon for hyperplane angle equality.
Definition: QhullQh.h:104
#define QH_TRY_(qh)
Definition: QhullQh.h:31
qhT qh_qh
Definition: global.c:26
PrintHyperplane print(const char *message) const
double distance(const QhullPoint &p) const
int dim
c
realT qh_getangle(pointT *vect1, pointT *vect2)
Definition: geom.c:644
#define coordT
Definition: libqhull.h:80
const coordT * coordinates() const
#define QHULL_ASSERT
Definition: QhullError.h:16
int hyperplane_dimension
Dimension of hyperplane.
#define qh
Definition: libqhull.h:457
Interface to Qhull from C++.
Definition: Qhull.h:43
boolT NOerrexit
Definition: libqhull.h:737
std::vector< coordT > toStdVector() const
double hyperplaneAngle(const QhullHyperplane &other) const
QhullQh * qh_qh
qhT for distanceEpsilon() in operator==
bool operator==(const QhullHyperplane &other) const
list a
coordT * hyperplane_coordinates
Normal to hyperplane. facetT.normal is normalized to 1.0.
#define realT
Definition: user.h:154
const coordT * coordinates() const
0 if undefined
Definition: QhullPoint.h:84


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:02