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()
42 , point_coordinates()
43 , describe_points(aComment)
44 {
45 }
46 
48 PointCoordinates(int pointDimension, const std::string &aComment)
49 : QhullPoints()
50 , point_coordinates()
51 , describe_points(aComment)
52 {
53  setDimension(pointDimension);
54 }
55 
59 : QhullPoints(q)
60 , point_coordinates()
61 , describe_points()
62 {
63 }
64 
66 PointCoordinates(const Qhull &q, const std::string &aComment)
67 : QhullPoints(q)
68 , point_coordinates()
69 , describe_points(aComment)
70 {
71 }
72 
74 PointCoordinates(const Qhull &q, int pointDimension, const std::string &aComment)
75 : QhullPoints(q)
76 , point_coordinates()
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)
85 , point_coordinates()
86 , describe_points(aComment)
87 {
88  setDimension(pointDimension);
89  append(coordinatesCount, c);
90 }
91 
94 : QhullPoints(qqh)
95 , point_coordinates()
96 , describe_points()
97 {
98 }
99 
101 PointCoordinates(QhullQh *qqh, const std::string &aComment)
102 : QhullPoints(qqh)
103 , point_coordinates()
104 , describe_points(aComment)
105 {
106 }
107 
109 PointCoordinates(QhullQh *qqh, int pointDimension, const std::string &aComment)
110 : QhullPoints(qqh)
111 , point_coordinates()
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)
120 , point_coordinates()
121 , describe_points(aComment)
122 {
123  setDimension(pointDimension);
124  append(coordinatesCount, c);
125 }
126 
129 : QhullPoints(other)
130 , point_coordinates(other.point_coordinates)
131 , describe_points(other.describe_points)
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;
339  Coordinates::ConstIterator c= p.beginCoordinates();
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 
orgQhull::PointCoordinates::checkValid
void checkValid() const
See QhullPoints for coordinates, coordinateCount, dimension, empty, isEmpty, ==, !...
Definition: PointCoordinates.cpp:153
orgQhull::PointCoordinates::reserveCoordinates
void reserveCoordinates(countT newCoordinates)
Definition: PointCoordinates.cpp:297
coordT
#define coordT
Definition: libqhull.h:80
countT
int countT
Definition: user_r.h:182
orgQhull::PointCoordinates::describe_points
std::string describe_points
Definition: PointCoordinates.h:44
orgQhull::QhullPoints::coordinateCount
countT coordinateCount() const
Definition: QhullPoints.h:91
orgQhull::Coordinates::count
countT count() const
Definition: Coordinates.h:78
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::PointCoordinates
Definition: PointCoordinates.h:38
orgQhull::QhullPoints
Java-style iterator.
Definition: QhullPoints.h:34
orgQhull::QhullPoint
Definition: QhullPoint.h:39
orgQhull::QhullError::NOthrow
@ NOthrow
Definition: QhullError.h:33
orgQhull::PointCoordinates::operator+
PointCoordinates operator+(const PointCoordinates &other) const
Definition: PointCoordinates.cpp:289
orgQhull::PointCoordinates::indexOffset
int indexOffset(int i) const
Definition: PointCoordinates.cpp:307
realT
#define realT
Definition: user.h:154
orgQhull::PointCoordinates::setDimension
void setDimension(int i)
Definition: PointCoordinates.cpp:162
orgQhull::PointCoordinates::point_coordinates
Coordinates point_coordinates
Definition: PointCoordinates.h:42
orgQhull::PointCoordinates::getCoordinates
const Coordinates & getCoordinates() const
Definition: PointCoordinates.h:84
orgQhull::PointCoordinates::append
void append(const std::vector< coordT > &otherCoordinates)
QhullPoints coordinates, constData, data, count, size.
Definition: PointCoordinates.h:71
orgQhull::PointCoordinates::comment
std::string comment() const
Definition: PointCoordinates.h:82
orgQhull::Coordinates::size
size_t size() const
Definition: Coordinates.h:84
orgQhull::Coordinates::iterator
Definition: Coordinates.h:152
orgQhull::QhullPoints::setDimension
void setDimension(int d)
Definition: QhullPoints.h:119
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::PointCoordinates::operator=
PointCoordinates & operator=(const PointCoordinates &other)
Definition: PointCoordinates.cpp:137
orgQhull::Coordinates::push_back
void push_back(const coordT &c)
Definition: Coordinates.h:129
orgQhull::Coordinates::reserve
void reserve(countT i)
Definition: Coordinates.h:136
operator<<
ostream & operator<<(ostream &os, const PointCoordinates &p)
Definition: PointCoordinates.cpp:327
c
c
orgQhull::QhullPoints::data
const coordT * data() const
Definition: QhullPoints.h:93
orgQhull::QhullQh
POD type equivalent to qhT. No virtual members.
Definition: QhullQh.h:58
orgQhull::PointCoordinates::beginCoordinates
Coordinates::ConstIterator beginCoordinates() const
See QhullPoints for begin, constBegin, end.
Definition: PointCoordinates.h:98
q
q
orgQhull::QhullPoints::includesCoordinates
bool includesCoordinates(const coordT *c) const
Definition: QhullPoints.h:109
orgQhull::QhullPoint::dimension
int dimension() const
Definition: QhullPoint.h:95
orgQhull::QhullPoints::count
countT count() const
Definition: QhullPoints.h:92
orgQhull::PointCoordinates::~PointCoordinates
~PointCoordinates()
Definition: PointCoordinates.cpp:147
QhullPoint.h
orgQhull::Coordinates::const_iterator
Definition: Coordinates.h:200
orgQhull::QhullPoints::dimension
int dimension() const
Definition: QhullPoints.h:98
orgQhull::Coordinates
Definition: Coordinates.h:38
orgQhull::PointCoordinates::PointCoordinates
PointCoordinates()
Definition: PointCoordinates.cpp:32
PointCoordinates.h
orgQhull::QhullError
Definition: QhullError.h:26
orgQhull::Coordinates::begin
iterator begin()
Definition: Coordinates.h:103
orgQhull::PointCoordinates::makeValid
void makeValid()
Definition: PointCoordinates.h:83
orgQhull::QhullPoints::operator=
QhullPoints & operator=(const QhullPoints &other)
Definition: QhullPoints.h:65
orgQhull::PointCoordinates::appendPoints
void appendPoints(std::istream &in)
Definition: PointCoordinates.cpp:231
QhullError.h
orgQhull::QhullPoints::indexOf
countT indexOf(const coordT *pointCoordinates) const
Definition: QhullPoints.cpp:198
orgQhull::PointCoordinates::appendComment
void appendComment(const std::string &s)
Definition: PointCoordinates.cpp:219


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:14