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