PointCoordinates.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/PointCoordinates.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/QhullPoint.h"
13 
14 #include <iterator>
15 #include <iostream>
16 
17 using std::istream;
18 using std::string;
19 using std::ws;
20 
21 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
22 #pragma warning( disable : 4996) // function was declared deprecated(strcpy, localtime, etc.)
23 #endif
24 
25 namespace orgQhull {
26 
27 #
28 
29 #
30 
33 : QhullPoints()
34 , point_coordinates()
35 , describe_points()
36 {
37 }
38 
40 PointCoordinates(const std::string &aComment)
41 : QhullPoints()
43 , describe_points(aComment)
44 {
45 }
46 
48 PointCoordinates(int pointDimension, const std::string &aComment)
49 : QhullPoints()
51 , describe_points(aComment)
52 {
53  setDimension(pointDimension);
54 }
55 
59 : QhullPoints(q)
62 {
63 }
64 
66 PointCoordinates(const Qhull &q, const std::string &aComment)
67 : QhullPoints(q)
69 , describe_points(aComment)
70 {
71 }
72 
74 PointCoordinates(const Qhull &q, int pointDimension, const std::string &aComment)
75 : QhullPoints(q)
77 , describe_points(aComment)
78 {
79  setDimension(pointDimension);
80 }
81 
83 PointCoordinates(const Qhull &q, int pointDimension, const std::string &aComment, countT coordinatesCount, const coordT *c)
84 : QhullPoints(q)
86 , describe_points(aComment)
87 {
88  setDimension(pointDimension);
89  append(coordinatesCount, c);
90 }
91 
94 : QhullPoints(qqh)
97 {
98 }
99 
101 PointCoordinates(QhullQh *qqh, const std::string &aComment)
102 : QhullPoints(qqh)
104 , describe_points(aComment)
105 {
106 }
107 
109 PointCoordinates(QhullQh *qqh, int pointDimension, const std::string &aComment)
110 : QhullPoints(qqh)
112 , describe_points(aComment)
113 {
114  setDimension(pointDimension);
115 }
116 
118 PointCoordinates(QhullQh *qqh, int pointDimension, const std::string &aComment, countT coordinatesCount, const coordT *c)
119 : QhullPoints(qqh)
121 , describe_points(aComment)
122 {
123  setDimension(pointDimension);
124  append(coordinatesCount, c);
125 }
126 
129 : QhullPoints(other)
132 {
133  makeValid(); // Update point_first and point_end
134 }
135 
138 {
139  QhullPoints::operator=(other);
142  makeValid(); // Update point_first and point_end
143  return *this;
144 }//operator=
145 
148 { }
149 
150 #
151 
153 checkValid() const
154 {
155  if(getCoordinates().data()!=data()
157  throw QhullError(10060, "Qhull error: first point (%x) is not PointCoordinates.data() or count (%d) is not PointCoordinates.count (%d)", coordinateCount(), getCoordinates().count(), 0.0, data());
158  }
159 }//checkValid
160 
163 {
164  if(i<0){
165  throw QhullError(10062, "Qhull error: can not set PointCoordinates dimension to %d", i);
166  }
167  int currentDimension=QhullPoints::dimension();
168  if(currentDimension!=0 && i!=currentDimension){
169  throw QhullError(10063, "Qhull error: can not change PointCoordinates dimension (from %d to %d)", currentDimension, i);
170  }
172 }//setDimension
173 
174 #
175 
177 beginCoordinates(countT pointIndex) const
178 {
179  return point_coordinates.begin()+indexOffset(pointIndex);
180 }
181 
184 {
185  return point_coordinates.begin()+indexOffset(pointIndex);
186 }
187 
188 #
189 
191 append(countT coordinatesCount, const coordT *c)
192 {
193  if(coordinatesCount<=0){
194  return;
195  }
196  if(includesCoordinates(c)){
197  throw QhullError(10065, "Qhull error: can not append a subset of PointCoordinates to itself. The coordinates for point %d may move.", indexOf(c, QhullError::NOthrow));
198  }
199  reserveCoordinates(coordinatesCount);
200  std::copy(c, c+coordinatesCount, std::back_inserter(point_coordinates));
201  makeValid();
202 }//append coordT
203 
206 {
207  setDimension(other.dimension());
208  append(other.coordinateCount(), other.data());
209 }//append PointCoordinates
210 
213 {
214  setDimension(p.dimension());
215  append(p.dimension(), p.coordinates());
216 }//append QhullPoint
217 
219 appendComment(const std::string &s){
220  if(char c= s[0] && describe_points.empty()){
221  if(c=='-' || isdigit(c)){
222  throw QhullError(10028, "Qhull argument error: comments can not start with a number or minus, %s", 0, 0, 0.0, s.c_str());
223  }
224  }
225  describe_points += s;
226 }//appendComment
227 
231 appendPoints(istream &in)
232 {
233  int inDimension;
234  countT inCount;
235  in >> ws >> inDimension >> ws;
236  if(!in.good()){
237  in.clear();
238  string remainder;
239  getline(in, remainder);
240  throw QhullError(10005, "Qhull error: input did not start with dimension or count -- %s", 0, 0, 0, remainder.c_str());
241  }
242  char c= (char)in.peek();
243  if(c!='-' && !isdigit(c)){ // Comments start with a non-digit
244  getline(in, describe_points);
245  in >> ws;
246  }
247  in >> inCount >> ws;
248  if(!in.good()){
249  in.clear();
250  string remainder;
251  getline(in, remainder);
252  throw QhullError(10009, "Qhull error: input did not start with dimension and count -- %d %s", inDimension, 0, 0, remainder.c_str());
253  }
254  c= (char)in.peek();
255  if(c!='-' && !isdigit(c)){ // Comments start with a non-digit
256  getline(in, describe_points);
257  in >> ws;
258  }
259  if(inCount<inDimension){ // Count may precede dimension
260  std::swap(inCount, inDimension);
261  }
262  setDimension(inDimension);
263  reserveCoordinates(inCount*inDimension);
264  countT coordinatesCount= 0;
265  while(!in.eof()){
266  realT p;
267  in >> p >> ws;
268  if(in.fail()){
269  in.clear();
270  string remainder;
271  getline(in, remainder);
272  throw QhullError(10008, "Qhull error: failed to read coordinate %d of point %d\n %s", coordinatesCount % inDimension, coordinatesCount/inDimension, 0, remainder.c_str());
273  }else{
275  coordinatesCount++;
276  }
277  }
278  if(coordinatesCount != inCount*inDimension){
279  if(coordinatesCount%inDimension==0){
280  throw QhullError(10006, "Qhull error: expected %d %d-d PointCoordinates but read %i PointCoordinates", int(inCount), inDimension, 0.0, int(coordinatesCount/inDimension));
281  }else{
282  throw QhullError(10012, "Qhull error: expected %d %d-d PointCoordinates but read %i PointCoordinates plus %f extra coordinates", inCount, inDimension, float(coordinatesCount%inDimension), coordinatesCount/inDimension);
283  }
284  }
285  makeValid();
286 }//appendPoints istream
287 
289 operator+(const PointCoordinates &other) const
290 {
291  PointCoordinates pc= *this;
292  pc << other;
293  return pc;
294 }//operator+
295 
297 reserveCoordinates(countT newCoordinates)
298 {
299  // vector::reserve is not const
300  point_coordinates.reserve((countT)point_coordinates.size()+newCoordinates); // WARN64
301  makeValid();
302 }//reserveCoordinates
303 
304 #
305 
307 indexOffset(countT i) const {
308  countT n= i*dimension();
309  countT coordinatesCount= point_coordinates.count();
310  if(i<0 || n>coordinatesCount){
311  throw QhullError(10061, "Qhull error: point_coordinates is too short (%d) for point %d", coordinatesCount, i);
312  }
313  return n;
314 }
315 
316 }//namespace orgQhull
317 
318 #
319 
320 using std::endl;
321 using std::ostream;
322 
325 
326 ostream&
327 operator<<(ostream &os, const PointCoordinates &p)
328 {
329  p.checkValid();
330  countT count= p.count();
331  int dimension= p.dimension();
332  string comment= p.comment();
333  if(comment.empty()){
334  os << dimension << endl;
335  }else{
336  os << dimension << " " << comment << endl;
337  }
338  os << count << endl;
340  for(countT i=0; i<count; i++){
341  for(int j=0; j<dimension; j++){
342  os << *c++ << " ";
343  }
344  os << endl;
345  }
346  return os;
347 }//operator<<
348 
PointCoordinates & operator=(const PointCoordinates &other)
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
countT count() const
Definition: QhullPoints.h:86
Coordinates::ConstIterator beginCoordinates() const
See QhullPoints for begin, constBegin, end.
POD type equivalent to qhT. No virtual members.
Definition: QhullQh.h:58
void setDimension(int d)
Definition: QhullPoints.h:113
int dimension() const
Definition: QhullPoint.h:89
int dimension() const
Definition: QhullPoints.h:92
countT count() const
Definition: Coordinates.h:72
Java-style iterator.
Definition: QhullPoints.h:28
c
#define coordT
Definition: libqhull.h:80
void appendPoints(std::istream &in)
void reserveCoordinates(countT newCoordinates)
QhullPoints & operator=(const QhullPoints &other)
Definition: QhullPoints.h:59
void appendComment(const std::string &s)
Interface to Qhull from C++.
Definition: Qhull.h:43
countT indexOf(const coordT *pointCoordinates) const
PointCoordinates operator+(const PointCoordinates &other) const
void checkValid() const
See QhullPoints for coordinates, coordinateCount, dimension, empty, isEmpty, ==, !=.
void append(const std::vector< coordT > &otherCoordinates)
QhullPoints coordinates, constData, data, count, size.
countT coordinateCount() const
Definition: QhullPoints.h:85
const coordT * data() const
Definition: QhullPoints.h:87
size_t size() const
Definition: Coordinates.h:78
bool includesCoordinates(const coordT *c) const
Definition: QhullPoints.h:103
const_iterator ConstIterator
Definition: Coordinates.h:44
void push_back(const coordT &c)
Definition: Coordinates.h:123
void reserve(countT i)
Definition: Coordinates.h:130
PointCoordinates & operator<<(const PointCoordinates &other)
std::string comment() const
const Coordinates & getCoordinates() const
int countT
Definition: user_r.h:182
#define realT
Definition: user.h:154
const coordT * coordinates() const
0 if undefined
Definition: QhullPoint.h:84


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