9 #include "QhullError.h"
10 #include "QhullPoint.h"
11 #include "PointCoordinates.h"
21 #pragma warning( disable : 4996)
39 PointCoordinates(
const std::string &aComment)
42 , describe_points(aComment)
47 PointCoordinates(
int pointDimension,
const std::string &aComment)
50 , describe_points(aComment)
52 setDimension(pointDimension);
57 PointCoordinates(
const Qhull &q)
65 PointCoordinates(
const Qhull &q,
const std::string &aComment)
68 , describe_points(aComment)
73 PointCoordinates(
const Qhull &q,
int pointDimension,
const std::string &aComment)
76 , describe_points(aComment)
78 setDimension(pointDimension);
82 PointCoordinates(
const Qhull &q,
int pointDimension,
const std::string &aComment, countT coordinatesCount,
const coordT *c)
85 , describe_points(aComment)
87 setDimension(pointDimension);
88 append(coordinatesCount, c);
92 PointCoordinates(QhullQh *qqh)
100 PointCoordinates(QhullQh *qqh,
const std::string &aComment)
102 , point_coordinates()
103 , describe_points(aComment)
108 PointCoordinates(QhullQh *qqh,
int pointDimension,
const std::string &aComment)
110 , point_coordinates()
111 , describe_points(aComment)
113 setDimension(pointDimension);
117 PointCoordinates(QhullQh *qqh,
int pointDimension,
const std::string &aComment, countT coordinatesCount,
const coordT *c)
119 , point_coordinates()
120 , describe_points(aComment)
122 setDimension(pointDimension);
123 append(coordinatesCount, c);
127 PointCoordinates(
const PointCoordinates &other)
129 , point_coordinates(other.point_coordinates)
130 , describe_points(other.describe_points)
135 PointCoordinates & PointCoordinates::
136 operator=(
const PointCoordinates &other)
138 QhullPoints::operator=(other);
139 point_coordinates= other.point_coordinates;
140 describe_points= other.describe_points;
151 void PointCoordinates::
154 if(getCoordinates().data()!=data()
155 || getCoordinates().
count()!=coordinateCount()){
156 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());
160 void PointCoordinates::
164 throw QhullError(10062,
"Qhull error: can not set PointCoordinates dimension to %d", i);
166 int currentDimension=QhullPoints::dimension();
167 if(currentDimension!=0 && i!=currentDimension){
168 throw QhullError(10063,
"Qhull error: can not change PointCoordinates dimension (from %d to %d)", currentDimension, i);
170 QhullPoints::setDimension(i);
175 Coordinates::ConstIterator PointCoordinates::
176 beginCoordinates(countT pointIndex)
const
178 return point_coordinates.begin()+indexOffset(pointIndex);
181 Coordinates::Iterator PointCoordinates::
182 beginCoordinates(countT pointIndex)
184 return point_coordinates.begin()+indexOffset(pointIndex);
189 void PointCoordinates::
190 append(countT coordinatesCount,
const coordT *c)
192 if(coordinatesCount<=0){
195 if(includesCoordinates(c)){
196 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 reserveCoordinates(coordinatesCount);
199 std::copy(c, c+coordinatesCount, std::back_inserter(point_coordinates));
203 void PointCoordinates::
204 append(
const PointCoordinates &other)
206 setDimension(other.dimension());
207 append(other.coordinateCount(), other.data());
210 void PointCoordinates::
211 append(
const QhullPoint &p)
213 setDimension(p.dimension());
214 append(p.dimension(), p.coordinates());
217 void PointCoordinates::
218 appendComment(
const std::string &
s){
219 if(
char c=
s[0] && describe_points.empty()){
220 if(c==
'-' || isdigit(c)){
221 throw QhullError(10028,
"Qhull argument error: comments can not start with a number or minus, %s", 0, 0, 0.0,
s.c_str());
224 describe_points +=
s;
229 void PointCoordinates::
230 appendPoints(istream &in)
234 in >> ws >> inDimension >> ws;
238 getline(in, remainder);
239 throw QhullError(10005,
"Qhull error: input did not start with dimension or count -- %s", 0, 0, 0, remainder.c_str());
241 char c= (char)in.peek();
242 if(c!=
'-' && !isdigit(c)){
243 getline(in, describe_points);
250 getline(in, remainder);
251 throw QhullError(10009,
"Qhull error: input did not start with dimension and count -- %d %s", inDimension, 0, 0, remainder.c_str());
254 if(c!=
'-' && !isdigit(c)){
255 getline(in, describe_points);
258 if(inCount<inDimension){
261 setDimension(inDimension);
262 reserveCoordinates(inCount*inDimension);
263 countT coordinatesCount= 0;
270 getline(in, remainder);
271 throw QhullError(10008,
"Qhull error: failed to read coordinate %d of point %d\n %s", coordinatesCount % inDimension, coordinatesCount/inDimension, 0, remainder.c_str());
273 point_coordinates.push_back(p);
277 if(coordinatesCount != inCount*inDimension){
278 if(coordinatesCount%inDimension==0){
279 throw QhullError(10006,
"Qhull error: expected %d %d-d PointCoordinates but read %i PointCoordinates",
int(inCount), inDimension, 0.0,
int(coordinatesCount/inDimension));
281 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);
288 operator+(
const PointCoordinates &other)
const
290 PointCoordinates pc= *
this;
295 void PointCoordinates::
296 reserveCoordinates(countT newCoordinates)
299 point_coordinates.reserve((countT)point_coordinates.size()+newCoordinates);
305 countT PointCoordinates::
306 indexOffset(countT i)
const {
307 countT n= i*dimension();
308 countT coordinatesCount= point_coordinates.count();
309 if(i<0 || n>coordinatesCount){
310 throw QhullError(10061,
"Qhull error: point_coordinates is too short (%d) for point %d", coordinatesCount, i);
322 using orgQhull::Coordinates;
323 using orgQhull::PointCoordinates;
326 operator<<(ostream &os,
const PointCoordinates &p)
329 countT
count= p.count();
330 int dimension= p.dimension();
331 string comment= p.comment();
333 os << dimension << endl;
335 os << dimension <<
" " << comment << endl;
338 Coordinates::ConstIterator c= p.beginCoordinates();
339 for(countT i=0; i<
count; i++){
340 for(
int j=0; j<dimension; j++){
std::set< std::string > & s
ostream & operator<<(ostream &os, const PointCoordinates &p)
Coordinate operator+(const Coordinate &LHS, const Coordinate &RHS)
void swap(ConfigDoF &A, ConfigDoF &B)
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.