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 
25 QhullHyperplane(const Qhull &q)
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)
35 : hyperplane_coordinates(c)
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 
QhullHyperplane.h
coordT
#define coordT
Definition: libqhull.h:80
qh_getangle
realT qh_getangle(pointT *vect1, pointT *vect2)
Definition: geom.c:644
QH_TRY_
#define QH_TRY_(qh)
Definition: QhullQh.h:31
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::QhullHyperplane::QhullHyperplane
QhullHyperplane()
Definition: QhullHyperplane.h:56
realT
#define realT
Definition: user.h:154
Qhull.h
octree.r
r
Definition: octree.py:9
orgQhull::QhullHyperplane::coordinates
const coordT * coordinates() const
Definition: QhullHyperplane.h:78
orgQhull::QhullHyperplane::qh_qh
QhullQh * qh_qh
qhT for distanceEpsilon() in operator==
Definition: QhullHyperplane.h:50
a
list a
orgQhull::QhullHyperplane::distance
double distance(const QhullPoint &p) const
Definition: QhullHyperplane.cpp:97
qh_qh
qhT qh_qh
Definition: global.c:26
orgQhull::QhullHyperplane::operator==
bool operator==(const QhullHyperplane &other) const
Definition: QhullHyperplane.cpp:72
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::QhullHyperplane::hyperplane_coordinates
coordT * hyperplane_coordinates
Normal to hyperplane. facetT.normal is normalized to 1.0.
Definition: QhullHyperplane.h:49
dim
int dim
c
c
qh
#define qh
Definition: libqhull.h:457
orgQhull::QhullHyperplane::hyperplane_dimension
int hyperplane_dimension
Dimension of hyperplane.
Definition: QhullHyperplane.h:52
qhT::NOerrexit
boolT NOerrexit
Definition: libqhull.h:737
orgQhull::QhullHyperplane::offset
coordT offset() const
Definition: QhullHyperplane.h:85
orgQhull::QhullHyperplane::dimension
int dimension() const
Definition: QhullHyperplane.h:83
orgQhull::QhullHyperplane
Definition: QhullHyperplane.h:39
q
q
orgQhull::QhullHyperplane::toStdVector
std::vector< coordT > toStdVector() const
Definition: QhullHyperplane.cpp:54
QhullPoint.h
orgQhull::QhullHyperplane::norm
double norm() const
Definition: QhullHyperplane.cpp:149
orgQhull::QhullHyperplane::print
PrintHyperplane print(const char *message) const
Definition: QhullHyperplane.h:116
orgQhull::QhullHyperplane::hyperplaneAngle
double hyperplaneAngle(const QhullHyperplane &other) const
Definition: QhullHyperplane.cpp:137
QHULL_ASSERT
#define QHULL_ASSERT
Definition: QhullError.h:16
operator<<
ostream & operator<<(ostream &os, const QhullHyperplane &p)
Definition: QhullHyperplane.cpp:163
orgQhull::QhullQh::maybeThrowQhullMessage
void maybeThrowQhullMessage(int exitCode)
Definition: QhullQh.cpp:118
orgQhull::QhullHyperplane::hyperplane_offset
coordT hyperplane_offset
Distance from hyperplane to origin.
Definition: QhullHyperplane.h:51


hpp-fcl
Author(s):
autogenerated on Fri Jan 26 2024 03:46:14