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)
35 : point_coordinates(c)
36 , qh_qh(q.qh())
37 , point_dimension(q.hullDimension())
38 {
39  QHULL_ASSERT(q.hullDimension()>0);
40 }//QhullPoint dim, coordT
41 
43 QhullPoint(const Qhull &q, int pointDimension, coordT *c)
44 : point_coordinates(c)
45 , qh_qh(q.qh())
46 , point_dimension(pointDimension)
47 {
48 }//QhullPoint dim, coordT
49 
52 QhullPoint(const Qhull &q, Coordinates &c)
53 : point_coordinates(c.data())
54 , qh_qh(q.qh())
55 , point_dimension(c.count())
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<<
coordT
#define coordT
Definition: libqhull.h:80
orgQhull::QhullPoint::id
countT id() const
Definition: QhullPoint.h:97
countT
int countT
Definition: user_r.h:182
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
qhT::hull_dim
int hull_dim
Definition: libqhull.h:591
qh_IDnone
@ qh_IDnone
Definition: libqhull.h:99
orgQhull::QhullPoint
Definition: QhullPoint.h:39
realT
#define realT
Definition: user.h:154
data
data
Qhull.h
orgQhull::QhullPoint::toStdVector
std::vector< coordT > toStdVector() const
Definition: QhullPoint.cpp:71
qh_IDunknown
@ qh_IDunknown
Definition: libqhull.h:99
octree.r
r
Definition: octree.py:9
operator<<
ostream & operator<<(ostream &os, const QhullPoint::PrintPoint &pr)
Same as qh_printpointid [io.c].
Definition: QhullPoint.cpp:173
orgQhull::QhullPoint::QhullPoint
QhullPoint()
Definition: QhullPoint.h:62
orgQhull::QhullPoint::print
PrintPoint print(const char *message) const
Definition: QhullPoint.h:129
orgQhull::QhullPoint::distance
double distance(const QhullPoint &p) const
Return distance between two points.
Definition: QhullPoint.cpp:123
qh_qh
qhT qh_qh
Definition: global.c:26
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
c
c
qh
#define qh
Definition: libqhull.h:457
q
q
orgQhull::QhullPoint::dimension
int dimension() const
Definition: QhullPoint.h:95
QhullPoint.h
orgQhull::QhullPoint::point_dimension
int point_dimension
Default dimension is qh_qh->hull_dim.
Definition: QhullPoint.h:55
orgQhull::QhullPoint::operator==
bool operator==(const QhullPoint &other) const
Definition: QhullPoint.cpp:89
orgQhull::Coordinates
Definition: Coordinates.h:38
orgQhull::QhullError
Definition: QhullError.h:26
orgQhull::QhullPoint::point_coordinates
coordT * point_coordinates
Pointer to first coordinate, 0 if undefined.
Definition: QhullPoint.h:51
QHULL_ASSERT
#define QHULL_ASSERT
Definition: QhullError.h:16
dim
int dim
c2
c2
QhullError.h
orgQhull::QhullPoint::qh_qh
QhullQh * qh_qh
Definition: QhullPoint.h:52


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58