QhullPoint.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/QhullPoint.cpp#3 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
10 
11 #include "libqhullcpp/QhullError.h"
12 #include "libqhullcpp/Qhull.h"
13 
14 #include <iostream>
15 #include <algorithm>
16 
17 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
18 #endif
19 
20 namespace orgQhull {
21 
22 #
23 
24 
26 QhullPoint(const Qhull &q)
27 : point_coordinates(0)
28 , qh_qh(q.qh())
29 , point_dimension(q.hullDimension())
30 {
31 }//QhullPoint
32 
34 QhullPoint(const Qhull &q, coordT *c)
36 , qh_qh(q.qh())
37 , point_dimension(q.hullDimension())
38 {
40 }//QhullPoint dim, coordT
41 
43 QhullPoint(const Qhull &q, int pointDimension, coordT *c)
45 , qh_qh(q.qh())
46 , point_dimension(pointDimension)
47 {
48 }//QhullPoint dim, coordT
49 
54 , qh_qh(q.qh())
56 {
57 }//QhullPoint Coordinates
58 
59 #
60 
61 // See qt-qhull.cpp for QList conversion
62 
63 #ifndef QHULL_NO_STL
64 std::vector<coordT> QhullPoint::
65 toStdVector() const
66 {
67  QhullPointIterator i(*this);
68  std::vector<coordT> vs;
69  while(i.hasNext()){
70  vs.push_back(i.next());
71  }
72  return vs;
73 }//toStdVector
74 #endif //QHULL_NO_STL
75 
76 #
77 
78 bool QhullPoint::
83 operator==(const QhullPoint &other) const
84 {
86  return false;
87  }
88  const coordT *c= point_coordinates;
89  const coordT *c2= other.point_coordinates;
90  if(c==c2){
91  return true;
92  }
93  if(!c || !c2){
94  return false;
95  }
96  if(!qh_qh || qh_qh->hull_dim==0){
97  for(int k= point_dimension; k--; ){
98  if(*c++ != *c2++){
99  return false;
100  }
101  }
102  return true;
103  }
104  double dist2= 0.0;
105  for(int k= point_dimension; k--; ){
106  double diff= *c++ - *c2++;
107  dist2 += diff*diff;
108  }
109  dist2= sqrt(dist2);
110  return (dist2 < qh_qh->distanceEpsilon());
111 }//operator==
112 
113 #
114 
115 double QhullPoint::
117 distance(const QhullPoint &p) const
118 {
119  const coordT *c= point_coordinates;
120  const coordT *c2= p.point_coordinates;
121  int dim= point_dimension;
122  if(dim!=p.point_dimension){
123  throw QhullError(10075, "QhullPoint error: Expecting dimension %d for distance(). Got %d", dim, p.point_dimension);
124  }
125  if(!c || !c2){
126  throw QhullError(10076, "QhullPoint error: Cannot compute distance() for undefined point");
127  }
128  double dist;
129 
130  switch(dim){
131  case 2:
132  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]);
133  break;
134  case 3:
135  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]);
136  break;
137  case 4:
138  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]);
139  break;
140  case 5:
141  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]);
142  break;
143  case 6:
144  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]);
145  break;
146  case 7:
147  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]) + (c[6]-c2[6])*(c[6]-c2[6]);
148  break;
149  case 8:
150  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]) + (c[6]-c2[6])*(c[6]-c2[6]) + (c[7]-c2[7])*(c[7]-c2[7]);
151  break;
152  default:
153  dist= 0.0;
154  for(int k=dim; k--; ){
155  dist += (*c - *c2) * (*c - *c2);
156  ++c;
157  ++c2;
158  }
159  break;
160  }
161  return sqrt(dist);
162 }//distance
163 
164 }//namespace orgQhull
165 
166 #
167 
168 using std::ostream;
170 
172 ostream &
173 operator<<(ostream &os, const QhullPoint::PrintPoint &pr)
174 {
175  QhullPoint p= *pr.point;
176  countT i= p.id();
177  if(pr.point_message){
178  if(*pr.point_message){
179  os << pr.point_message << " ";
180  }
181  if(pr.with_identifier && (i!=qh_IDunknown) && (i!=qh_IDnone)){
182  os << "p" << i << ": ";
183  }
184  }
185  const realT *c= p.coordinates();
186  for(int k=p.dimension(); k--; ){
187  realT r= *c++;
188  if(pr.point_message){
189  os << " " << r; // FIXUP QH11010 %8.4g
190  }else{
191  os << " " << r; // FIXUP QH11010 qh_REAL_1
192  }
193  }
194  os << std::endl;
195  return os;
196 }//printPoint
197 
198 ostream &
199 operator<<(ostream &os, const QhullPoint &p)
200 {
201  os << p.print("");
202  return os;
203 }//operator<<
int hull_dim
Definition: libqhull.h:591
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
QhullQh * qh()
Definition: QhullPoint.h:97
ostream & operator<<(ostream &os, const QhullPoint::PrintPoint &pr)
Same as qh_printpointid [io.c].
Definition: QhullPoint.cpp:173
int dimension() const
Definition: QhullPoint.h:89
qhT qh_qh
Definition: global.c:26
bool operator==(const QhullPoint &other) const
Definition: QhullPoint.cpp:83
int point_dimension
Default dimension is qh_qh->hull_dim.
Definition: QhullPoint.h:49
int dim
c
data
coordT * point_coordinates
Pointer to first coordinate, 0 if undefined.
Definition: QhullPoint.h:45
#define coordT
Definition: libqhull.h:80
#define QHULL_ASSERT
Definition: QhullError.h:16
#define qh
Definition: libqhull.h:457
countT id() const
Definition: QhullPoint.h:91
Interface to Qhull from C++.
Definition: Qhull.h:43
int hullDimension() const
Dimension of the computed hull.
Definition: Qhull.h:74
std::vector< coordT > toStdVector() const
Definition: QhullPoint.cpp:65
PrintPoint print(const char *message) const
Definition: QhullPoint.h:123
c2
int countT
Definition: user_r.h:182
#define realT
Definition: user.h:154
const coordT * coordinates() const
0 if undefined
Definition: QhullPoint.h:84
double distance(const QhullPoint &p) const
Return distance between two points.
Definition: QhullPoint.cpp:117


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