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 {
42  QHULL_ASSERT(q.hullDimension());
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::
132 resetQhullQh(QhullQh *qqh)
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  }
261 }//mid
262 
263 #
264 
266 findNext(const QhullPoint &p)
267 {
268  while(i!=ps->constEnd()){
269  if(*i++ == p){
270  return true;
271  }
272  }
273  return false;
274 }//findNext
275 
277 findPrevious(const QhullPoint &p)
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
coordT
#define coordT
Definition: libqhull.h:80
countT
int countT
Definition: user_r.h:182
orgQhull::QhullPointsIterator::next
QhullPoint next()
Definition: QhullPoints.h:259
QhullPoints.h
orgQhull::QhullPoints::point_first
coordT * point_first
First coordinate of an array of points of point_dimension.
Definition: QhullPoints.h:38
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
orgQhull::QhullPoints::constBegin
ConstIterator constBegin() const
Definition: QhullPoints.h:87
orgQhull::QhullPoints
Java-style iterator.
Definition: QhullPoints.h:34
orgQhull::QhullPoint
Definition: QhullPoint.h:39
orgQhull::QhullPointsIterator
Definition: QhullPoints.h:242
orgQhull::QhullPoints::point_end
coordT * point_end
End of point coordinates (end>=first). Trailing coordinates ignored.
Definition: QhullPoints.h:39
orgQhull::QhullPoints::qh_qh
QhullQh * qh_qh
Definition: QhullPoints.h:40
Qhull.h
orgQhull::QhullPoints::QhullPoints
QhullPoints()
Definition: QhullPoints.h:55
orgQhull::QhullPointsIterator::ps
const QhullPoints * ps
Definition: QhullPoints.h:248
orgQhull::QhullPointsIterator::findNext
bool findNext(const QhullPoint &t)
Definition: QhullPoints.cpp:272
orgQhull::QhullPoint::print
PrintPoint print(const char *message) const
Definition: QhullPoint.h:129
qh_qh
qhT qh_qh
Definition: global.c:26
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::QhullPointsIterator::hasNext
bool hasNext() const
Definition: QhullPoints.h:257
orgQhull::QhullPoints::value
QhullPoint value(countT idx) const
Definition: QhullPoints.cpp:147
c
c
qh
#define qh
Definition: libqhull.h:457
operator<<
ostream & operator<<(ostream &os, const QhullPoints &p)
Definition: QhullPoints.cpp:297
orgQhull::QhullPoints::extraCoordinatesCount
countT extraCoordinatesCount() const
Definition: QhullPoints.cpp:93
orgQhull::QhullQh
POD type equivalent to qhT. No virtual members.
Definition: QhullQh.h:58
orgQhull::QhullPoints::operator==
bool operator==(const QhullPoints &other) const
Definition: QhullPoints.cpp:104
orgQhull::QhullPointsIterator::i
const_iterator i
Definition: QhullPoints.h:249
orgQhull::QhullPoint::printWithIdentifier
PrintPoint printWithIdentifier(const char *message) const
Definition: QhullPoint.h:130
q
q
orgQhull::QhullPoints::includesCoordinates
bool includesCoordinates(const coordT *c) const
Definition: QhullPoints.h:109
orgQhull::QhullPointsIterator::findPrevious
bool findPrevious(const QhullPoint &t)
Definition: QhullPoints.cpp:283
orgQhull::QhullPoints::count
countT count() const
Definition: QhullPoints.h:92
orgQhull::QhullPoints::toStdVector
std::vector< QhullPoint > toStdVector() const
Definition: QhullPoints.cpp:79
orgQhull::QhullPoints::begin
ConstIterator begin() const
Definition: QhullPoints.h:85
orgQhull::QhullError
Definition: QhullError.h:26
orgQhull::QhullPoints::mid
QhullPoints mid(countT idx, countT length=-1) const
Returns a subset of the points, not a copy.
Definition: QhullPoints.cpp:256
QHULL_ASSERT
#define QHULL_ASSERT
Definition: QhullError.h:16
orgQhull::QhullPoint::defineAs
void defineAs(coordT *c)
Definition: QhullPoint.h:92
orgQhull::QhullPoints::end
ConstIterator end() const
Definition: QhullPoints.h:99
orgQhull::QhullPoints::point_dimension
int point_dimension
Dimension, >=0.
Definition: QhullPoints.h:42
c2
c2
orgQhull::QhullPoints::lastIndexOf
countT lastIndexOf(const QhullPoint &t) const
Definition: QhullPoints.cpp:241
t
dictionary t
orgQhull::QhullPoints::indexOf
countT indexOf(const coordT *pointCoordinates) const
Definition: QhullPoints.cpp:198
orgQhull::QhullPoints::contains
bool contains(const QhullPoint &t) const
Definition: QhullPoints.cpp:171
orgQhull::QhullPoints::resetQhullQh
void resetQhullQh(QhullQh *qqh)
Definition: QhullPoints.cpp:138
orgQhull::QhullPoints::constEnd
ConstIterator constEnd() const
Definition: QhullPoints.h:89


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