QhullPoints.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/QhullPoints.cpp#3 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
10 
11 #include "libqhullcpp/Qhull.h"
12 
13 #include <iostream>
14 
15 #ifndef QHULL_NO_STL
16 #include <vector>
17 #endif
18 
19 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
20 #endif
21 
22 namespace orgQhull {
23 
24 #
25 
27 QhullPoints(const Qhull &q)
28 : point_first(0)
29 , point_end(0)
30 , qh_qh(q.qh())
31 , point_dimension(q.hullDimension())
32 {
33 }//QhullPoints Qhull
34 
36 QhullPoints(const Qhull &q, countT coordinateCount2, coordT *c)
37 : point_first(c)
38 , point_end(c+coordinateCount2)
39 , qh_qh(q.qh())
40 , point_dimension(q.hullDimension())
41 {
43  QHULL_ASSERT(coordinateCount2>=0);
44 }//QhullPoints Qhull dim
45 
47 QhullPoints(const Qhull &q, int pointDimension, countT coordinateCount2, coordT *c)
48 : point_first(c)
49 , point_end(c+coordinateCount2)
50 , qh_qh(q.qh())
51 , point_dimension(pointDimension)
52 {
53  QHULL_ASSERT(pointDimension>=0);
54  QHULL_ASSERT(coordinateCount2>=0);
55 }//QhullPoints Qhull dim coordT
56 
58 QhullPoints(QhullQh *qqh, int pointDimension, countT coordinateCount2, coordT *c)
59 : point_first(c)
60 , point_end(c+coordinateCount2)
61 , qh_qh(qqh)
62 , point_dimension(pointDimension)
63 {
64  QHULL_ASSERT(pointDimension>=0);
65  QHULL_ASSERT(coordinateCount2>=0);
66 }//QhullPoints QhullQh dim coordT
67 
68 #
69 // See qt-qhull.cpp for QList conversion
70 
71 #ifndef QHULL_NO_STL
72 std::vector<QhullPoint> QhullPoints::
73 toStdVector() const
74 {
75  QhullPointsIterator i(*this);
76  std::vector<QhullPoint> vs;
77  while(i.hasNext()){
78  vs.push_back(i.next());
79  }
80  return vs;
81 }//toStdVector
82 #endif //QHULL_NO_STL
83 
84 #
85 
88 {
89  if(point_dimension>0){
90  return (countT)((point_end-point_first)%(size_t)point_dimension);
91  }
92  return 0;
93 }//extraCoordinatesCount
94 
97 bool QhullPoints::
98 operator==(const QhullPoints &other) const
99 {
100  if((point_end-point_first) != (other.point_end-other.point_first)){
101  return false;
102  }
103  if(point_dimension!=other.point_dimension){
104  return false;
105  }
106  if(point_first==other.point_first){
107  return true;
108  }
109  if(!qh_qh || qh_qh->hull_dim==0){
110  const coordT *c= point_first;
111  const coordT *c2= other.point_first;
112  while(c<point_end){
113  if(*c++!=*c2++){
114  return false;
115  }
116  }
117  }else{
118  const_iterator i= begin();
119  const_iterator i2= other.begin();
120  while(i<end()){
121  if(*i++!=*i2++){
122  return false;
123  }
124  }
125  }
126  return true;
127 }//operator==
128 
131 void QhullPoints::
133 {
134  qh_qh= qqh;
135  point_dimension= (qqh ? qqh->hull_dim : 0);
136  point_first= 0;
137  point_end= 0;
138 }//resetQhullQh
139 
141 value(countT idx) const
142 {
143  QhullPoint p(qh_qh);
144  if(idx>=0 && idx<count()){
146  }
147  return p;
148 }//value
149 
151 value(countT idx, QhullPoint &defaultValue) const
152 {
153  QhullPoint p(qh_qh);
154  if(idx>=0 && idx<count()){
156  }else{
157  p.defineAs(defaultValue);
158  }
159  return p;
160 }//value
161 
162 #
163 
164 bool QhullPoints::
165 contains(const QhullPoint &t) const
166 {
167  const_iterator i= begin();
168  while(i != end()){
169  if(*i==t){
170  return true;
171  }
172  i++;
173  }
174  return false;
175 }//contains
176 
178 count(const QhullPoint &t) const
179 {
180  countT n= 0;
181  const_iterator i= begin();
182  while(i != end()){
183  if(*i==t){
184  ++n;
185  }
186  i++;
187  }
188  return n;
189 }//count
190 
192 indexOf(const coordT *pointCoordinates) const
193 {
194  if(!includesCoordinates(pointCoordinates) || point_dimension==0){
195  return -1;
196  }
197  size_t offset= pointCoordinates-point_first;
198  countT idx= (countT)(offset/(size_t)point_dimension);
199  countT extra= (countT)(offset%(size_t)point_dimension);
200  if(extra!=0){
201  throw QhullError(10066, "Qhull error: coordinates %x are not at point boundary (extra %d at index %d)", extra, idx, 0.0, pointCoordinates);
202  }
203  return idx;
204 }//indexOf coordT
205 
207 indexOf(const coordT *pointCoordinates, int noThrow) const
208 {
209  size_t extra= 0;
210  if(noThrow){
211  if(!includesCoordinates(pointCoordinates) || point_dimension==0){
212  return -1;
213  }
214  extra= (pointCoordinates-point_first)%(size_t)point_dimension;
215  }
216  return indexOf(pointCoordinates-extra);
217 }//indexOf coordT noThrow
218 
220 indexOf(const QhullPoint &t) const
221 {
222  countT j=0;
223  const_iterator i= begin();
224  while(i!=end()){
225  if(*i==t){
226  return j;
227  }
228  ++i;
229  ++j;
230  }
231  return -1;
232 }//indexOf
233 
235 lastIndexOf(const QhullPoint &t) const
236 {
237  countT j= count();
238  const_iterator i= end();
239  while(i != begin()){
240  --i;
241  --j;
242  if(*i==t){
243  return j;
244  }
245  }
246  return -1;
247 }//lastIndexOf
248 
250 mid(countT idx, countT length) const
251 {
252  countT n= count();
253  if(idx<0 || idx>=n){
254  n= 0;
255  }else if(length<0 || idx+length>=n){
256  n -= idx;
257  }else{
258  n -= idx+length;
259  }
260  return QhullPoints(qh_qh, point_dimension, n*point_dimension, point_first+idx*point_dimension);
261 }//mid
262 
263 #
264 
267 {
268  while(i!=ps->constEnd()){
269  if(*i++ == p){
270  return true;
271  }
272  }
273  return false;
274 }//findNext
275 
278 {
279  while(i!=ps->constBegin()){
280  if(*--i == p){
281  return true;
282  }
283  }
284  return false;
285 }//findPrevious
286 
287 }//namespace orgQhull
288 
289 #
290 
291 using std::ostream;
295 
296 ostream &
297 operator<<(ostream &os, const QhullPoints &p)
298 {
299  QhullPointsIterator i(p);
300  while(i.hasNext()){
301  os << i.next();
302  }
303  return os;
304 }//operator<<QhullPoints
305 
306 ostream &
307 operator<<(ostream &os, const QhullPoints::PrintPoints &pr)
308 {
309  os << pr.point_message;
310  QhullPoints ps= *pr.points;
311  for(QhullPoints::iterator i=ps.begin(); i!=ps.end(); ++i){
312  QhullPoint p= *i;
313  if(pr.with_identifier){
314  os << p.printWithIdentifier("");
315  }else{
316  os << p.print("");
317  }
318  }
319  return os;
320 }//<<PrintPoints
int hull_dim
Definition: libqhull.h:591
PrintPoint printWithIdentifier(const char *message) const
Definition: QhullPoint.h:124
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
countT count() const
Definition: QhullPoints.h:86
POD type equivalent to qhT. No virtual members.
Definition: QhullQh.h:58
QhullQh * qh() const
Definition: QhullPoints.h:111
void resetQhullQh(QhullQh *qqh)
qhT qh_qh
Definition: global.c:26
bool findPrevious(const QhullPoint &t)
Java-style iterator.
Definition: QhullPoints.h:28
c
int point_dimension
Dimension, >=0.
Definition: QhullPoints.h:36
coordT * point_first
First coordinate of an array of points of point_dimension.
Definition: QhullPoints.h:32
void defineAs(coordT *c)
Definition: QhullPoint.h:86
#define coordT
Definition: libqhull.h:80
countT lastIndexOf(const QhullPoint &t) const
#define QHULL_ASSERT
Definition: QhullError.h:16
ConstIterator end() const
Definition: QhullPoints.h:93
#define qh
Definition: libqhull.h:457
bool findNext(const QhullPoint &t)
Interface to Qhull from C++.
Definition: Qhull.h:43
countT indexOf(const coordT *pointCoordinates) const
countT extraCoordinatesCount() const
Definition: QhullPoints.cpp:87
int hullDimension() const
Dimension of the computed hull.
Definition: Qhull.h:74
bool includesCoordinates(const coordT *c) const
Definition: QhullPoints.h:103
QhullPoints mid(countT idx, countT length=-1) const
Returns a subset of the points, not a copy.
PrintPoint print(const char *message) const
Definition: QhullPoint.h:123
QhullPoint value(countT idx) const
c2
coordT * point_end
End of point coordinates (end>=first). Trailing coordinates ignored.
Definition: QhullPoints.h:33
bool contains(const QhullPoint &t) const
ConstIterator begin() const
Definition: QhullPoints.h:79
int countT
Definition: user_r.h:182
std::vector< QhullPoint > toStdVector() const
Definition: QhullPoints.cpp:73
bool operator==(const QhullPoints &other) const
Definition: QhullPoints.cpp:98
ostream & operator<<(ostream &os, const QhullPoints &p)


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