QhullHyperplane_test.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/qhulltest/QhullHyperplane_test.cpp#4 $$Change: 2064 $
5 ** $DateTime: 2016/01/18 12:36:08 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled headers
10 #include <iostream>
11 #include "qhulltest/RoadTest.h" // QT_VERSION
12 
14 #include "libqhullcpp/QhullError.h"
15 #include "libqhullcpp/RboxPoints.h"
16 #include "libqhullcpp/QhullFacet.h"
19 #include "libqhullcpp/Qhull.h"
20 
21 #include <numeric>
22 #include <vector>
23 
24 using std::cout;
25 using std::endl;
26 using std::ostringstream;
27 using std::ostream;
28 using std::string;
29 
30 namespace orgQhull {
31 
33 {
34  Q_OBJECT
35 
36 #
37 private slots:
38  void cleanup();
39  void t_construct();
40  void t_construct_qh();
41  void t_convert();
42  void t_readonly();
43  void t_define();
44  void t_value();
45  void t_operator();
46  void t_iterator();
47  void t_const_iterator();
49  void t_io();
50 };//QhullHyperplane_test
51 
52 void
54 {
55  new QhullHyperplane_test(); // RoadTest::s_testcases
56 }
57 
58 //Executed after each testcase
61 {
63 }
64 
67 {
68  QhullHyperplane h4;
69  QVERIFY(!h4.isValid());
70  QCOMPARE(h4.dimension(), 0);
71  // Qhull.runQhull() constructs QhullFacets as facetT
72  RboxPoints rcube("c");
73  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
74  QhullHyperplane h(q);
75  QVERIFY(!h.isValid());
76  QCOMPARE(h.dimension(), 0);
77  QCOMPARE(h.coordinates(),static_cast<double *>(0));
78  QhullFacet f= q.firstFacet();
80  QVERIFY(h2.isValid());
81  QCOMPARE(h2.dimension(), 3);
82  h= h2;
83  QCOMPARE(h, h2);
84  QhullHyperplane h3(q, h2.dimension(), h2.coordinates(), h2.offset());
85  QCOMPARE(h2, h3);
86  QhullHyperplane h5= h2; // copy constructor
87  QVERIFY(h5==h2);
88 }//t_construct
89 
92 {
93  // Qhull.runQhull() constructs QhullFacets as facetT
94  RboxPoints rcube("c");
95  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
96  QhullFacet f= q.firstFacet();
98  QVERIFY(h2.isValid());
99  QCOMPARE(h2.dimension(), 3);
100  // h= h2; // copy assignment disabled, ambiguous
101  QhullHyperplane h3(q.qh(), h2.dimension(), h2.coordinates(), h2.offset());
102  QCOMPARE(h2, h3);
103  QhullHyperplane h5= h2; // copy constructor
104  QVERIFY(h5==h2);
105 }//t_construct_qh
106 
109 {
110  RboxPoints rcube("c");
111  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
112  QhullHyperplane h= q.firstFacet().hyperplane();
113  std::vector<double> fs= h.toStdVector();
114  QCOMPARE(fs.size(), 4u);
115  double offset= fs.back();
116  fs.pop_back();
117  QCOMPARE(offset, -0.5);
118 
119  double squareNorm= inner_product(fs.begin(), fs.end(), fs.begin(), 0.0);
120  QCOMPARE(squareNorm, 1.0);
121  QList<double> qs= h.toQList();
122  QCOMPARE(qs.size(), 4);
123  double offset2= qs.takeLast();
124  QCOMPARE(offset2, -0.5);
125  double squareNorm2= std::inner_product(qs.begin(), qs.end(), qs.begin(), 0.0);
126  QCOMPARE(squareNorm2, 1.0);
127 }//t_convert
128 
131 {
132  RboxPoints rcube("c");
133  {
134  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
135  QhullFacetList fs= q.facetList();
137  while(i.hasNext()){
138  QhullFacet f= i.next();
140  int id= f.id();
141  cout << "h" << id << endl;
142  QVERIFY(h.isValid());
143  QCOMPARE(h.dimension(),3);
144  const coordT *c= h.coordinates();
145  coordT *c2= h.coordinates();
146  QCOMPARE(c, c2);
147  const coordT *c3= h.begin();
148  QCOMPARE(c, c3);
149  QCOMPARE(h.offset(), -0.5);
150  int j= h.end()-h.begin();
151  QCOMPARE(j, 3);
152  double squareNorm= std::inner_product(h.begin(), h.end(), h.begin(), 0.0);
153  QCOMPARE(squareNorm, 1.0);
154  }
155  QhullHyperplane h2= fs.first().hyperplane();
156  QhullHyperplane h3= fs.last().hyperplane();
157  QVERIFY(h2!=h3);
158  QVERIFY(h3.coordinates()!=h2.coordinates());
159  }
160 }//t_readonly
161 
164 {
165  RboxPoints rcube("c");
166  {
167  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
168  QhullFacetList fs= q.facetList();
169  QhullHyperplane h= fs.first().hyperplane();
170  QhullHyperplane h2= h;
171  QVERIFY(h==h2);
172  QhullHyperplane h3= fs.last().hyperplane();
173  QVERIFY(h2!=h3);
174 
175  QhullHyperplane h4= h3;
176  h4.defineAs(h2);
177  QVERIFY(h2==h4);
178  QhullHyperplane p5= h3;
179  p5.defineAs(h2.dimension(), h2.coordinates(), h2.offset());
180  QVERIFY(h2==p5);
181  QhullHyperplane h6= h3;
182  h6.setCoordinates(h2.coordinates());
183  QCOMPARE(h2.coordinates(), h6.coordinates());
184  h6.setOffset(h2.offset());
185  QCOMPARE(h2.offset(), h6.offset());
186  QVERIFY(h2==h6);
187  h6.setDimension(2);
188  QCOMPARE(h6.dimension(), 2);
189  QVERIFY(h2!=h6);
190  }
191 }//t_define
192 
195 {
196  RboxPoints rcube("c G1");
197  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
198  QhullFacet f= q.firstFacet();
199  QhullFacet f2= f.neighborFacets().at(0);
200  const QhullHyperplane h= f.hyperplane();
201  const QhullHyperplane h2= f2.hyperplane(); // At right angles
202  double dist= h.distance(q.origin());
203  QCOMPARE(dist, -1.0);
204  double norm= h.norm();
205  QCOMPARE(norm, 1.0);
206  double angle= h.hyperplaneAngle(h2);
207  cout << "angle " << angle << endl;
208  QCOMPARE(angle+1.0, 1.0); // qFuzzyCompare does not work for 0.0
209  QVERIFY(h==h);
210  QVERIFY(h!=h2);
211 }//t_value
212 
215 {
216  RboxPoints rcube("c");
217  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
218  const QhullHyperplane h= q.firstFacet().hyperplane();
219  //operator== and operator!= tested elsewhere
220  const coordT *c= h.coordinates();
221  for(int k=h.dimension(); k--; ){
222  QCOMPARE(c[k], h[k]);
223  }
224  //h[0]= 10.0; // compiler error, const
225  QhullHyperplane h2= q.firstFacet().hyperplane();
226  h2[0]= 10.0; // Overwrites Hyperplane coordinate!
227  QCOMPARE(h2[0], 10.0);
228 }//t_operator
229 
232 {
233  RboxPoints rcube("c");
234  {
235  Qhull q(rcube,"QR0"); // rotated unit cube
236  QhullHyperplane h= q.firstFacet().hyperplane();
237  QCOMPARE(h.count(), 3);
238  QCOMPARE(h.size(), 3u);
241  QVERIFY(i==i2);
242  QVERIFY(i>=i2);
243  QVERIFY(i<=i2);
244  i= h.begin();
245  QVERIFY(i==i2);
246  i2= h.end();
247  QVERIFY(i!=i2);
248  double d3= *i;
249  i2--;
250  double d2= *i2;
251  QCOMPARE(d3, h[0]);
252  QCOMPARE(d2, h[2]);
254  QCOMPARE(*i2, *i3);
255 
256  (i3= i)++;
257  QCOMPARE((*i3), h[1]);
258  QVERIFY(i==i);
259  QVERIFY(i!=i2);
260  QVERIFY(i<i2);
261  QVERIFY(i<=i2);
262  QVERIFY(i2>i);
263  QVERIFY(i2>=i);
264 
266  QVERIFY(i==i4); // iterator COMP const_iterator
267  QVERIFY(i<=i4);
268  QVERIFY(i>=i4);
269  QVERIFY(i4==i); // const_iterator COMP iterator
270  QVERIFY(i4<=i);
271  QVERIFY(i4>=i);
272  QVERIFY(i>=i4);
273  QVERIFY(i4<=i);
274  QVERIFY(i2!=i4);
275  QVERIFY(i2>i4);
276  QVERIFY(i2>=i4);
277  QVERIFY(i4!=i2);
278  QVERIFY(i4<i2);
279  QVERIFY(i4<=i2);
280  ++i4;
281  QVERIFY(i<i4);
282  QVERIFY(i<=i4);
283  QVERIFY(i4>i);
284  QVERIFY(i4>=i);
285 
286  i= h.begin();
287  i2= h.begin();
288  QCOMPARE(i, i2++);
289  QCOMPARE(*i2, h[1]);
290  QCOMPARE(++i, i2);
291  QCOMPARE(i, i2--);
292  QCOMPARE(i2, h.begin());
293  QCOMPARE(--i, i2);
294  QCOMPARE(i2 += 3, h.end());
295  QCOMPARE(i2 -= 3, h.begin());
296  QCOMPARE(i2+0, h.begin());
297  QCOMPARE(i2+3, h.end());
298  i2 += 3;
299  i= i2-0;
300  QCOMPARE(i, i2);
301  i= i2-3;
302  QCOMPARE(i, h.begin());
303  QCOMPARE(i2-i, 3);
304 
305  //h.begin end tested above
306 
307  // QhullHyperplane is const-only
308  }
309 }//t_iterator
310 
313 {
314  RboxPoints rcube("c");
315  {
316  Qhull q(rcube,"QR0"); // rotated unit cube
317  QhullHyperplane h= q.firstFacet().hyperplane();
320  QVERIFY(i==i2);
321  QVERIFY(i>=i2);
322  QVERIFY(i<=i2);
323  i= h.begin();
324  QVERIFY(i==i2);
325  i2= h.end();
326  QVERIFY(i!=i2);
327  double d3= *i;
328  i2--;
329  double d2= *i2;
330  QCOMPARE(d3, h[0]);
331  QCOMPARE(d2, h[2]);
333  QCOMPARE(*i2, *i3);
334 
335  (i3= i)++;
336  QCOMPARE((*i3), h[1]);
337  QVERIFY(i==i);
338  QVERIFY(i!=i2);
339  QVERIFY(i<i2);
340  QVERIFY(i<=i2);
341  QVERIFY(i2>i);
342  QVERIFY(i2>=i);
343 
344  // See t_iterator for const_iterator COMP iterator
345 
346  i= h.begin();
347  i2= h.constBegin();
348  QCOMPARE(i, i2++);
349  QCOMPARE(*i2, h[1]);
350  QCOMPARE(++i, i2);
351  QCOMPARE(i, i2--);
352  QCOMPARE(i2, h.constBegin());
353  QCOMPARE(--i, i2);
354  QCOMPARE(i2+=3, h.constEnd());
355  QCOMPARE(i2-=3, h.constBegin());
356  QCOMPARE(i2+0, h.constBegin());
357  QCOMPARE(i2+3, h.constEnd());
358  i2 += 3;
359  i= i2-0;
360  QCOMPARE(i, i2);
361  i= i2-3;
362  QCOMPARE(i, h.constBegin());
363  QCOMPARE(i2-i, 3);
364 
365  // QhullHyperplane is const-only
366  }
367 }//t_const_iterator
368 
371 {
372  RboxPoints rcube("c");
373  Qhull q(rcube,"QR0"); // rotated unit cube
374  QhullHyperplane h = q.firstFacet().hyperplane();
375  QhullHyperplaneIterator i2(h);
376  QCOMPARE(h.dimension(), 3);
377  QhullHyperplaneIterator i= h;
378  QVERIFY(i2.hasNext());
379  QVERIFY(!i2.hasPrevious());
380  QVERIFY(i.hasNext());
381  QVERIFY(!i.hasPrevious());
382  i2.toBack();
383  i.toFront();
384  QVERIFY(!i2.hasNext());
385  QVERIFY(i2.hasPrevious());
386  QVERIFY(i.hasNext());
387  QVERIFY(!i.hasPrevious());
388 
389  // i at front, i2 at end/back, 3 coordinates
390  QCOMPARE(i.peekNext(), h[0]);
391  QCOMPARE(i2.peekPrevious(), h[2]);
392  QCOMPARE(i2.previous(), h[2]);
393  QCOMPARE(i2.previous(), h[1]);
394  QCOMPARE(i2.previous(), h[0]);
395  QVERIFY(!i2.hasPrevious());
396  QCOMPARE(i.peekNext(), h[0]);
397  // i.peekNext()= 1.0; // compiler error, i is const
398  QCOMPARE(i.next(), h[0]);
399  QCOMPARE(i.peekNext(), h[1]);
400  QCOMPARE(i.next(), h[1]);
401  QCOMPARE(i.next(), h[2]);
402  QVERIFY(!i.hasNext());
403  i.toFront();
404  QCOMPARE(i.next(), h[0]);
405 }//t_qhullHyperplane_iterator
406 
409 {
410  RboxPoints rcube("c");
411  {
412  Qhull q(rcube, "");
413  QhullHyperplane h= q.firstFacet().hyperplane();
414  ostringstream os;
415  os << "Hyperplane:\n";
416  os << h;
417  os << h.print("message");
418  os << h.print(" and a message ", " offset ");
419  cout << os.str();
420  QString s= QString::fromStdString(os.str());
421  QCOMPARE(s.count("1"), 3);
422  // QCOMPARE(s.count(QRegExp("f\\d")), 3*7 + 13*3*2);
423  }
424 }//t_io
425 
426 
427 }//orgQhull
428 
429 #include "moc/QhullHyperplane_test.moc"
QhullHyperplane.h
QhullFacet.h
coordT
#define coordT
Definition: libqhull.h:80
orgQhull::QhullHyperplane::Iterator
QhullHyperplane::iterator Iterator
Definition: QhullHyperplane.h:44
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::QhullHyperplane_test::t_convert
void t_convert()
Definition: QhullHyperplane_test.cpp:108
QhullFacetSet.h
orgQhull::QhullHyperplane::isValid
bool isValid() const
Definition: QhullHyperplane.h:84
Qhull.h
orgQhull::QhullHyperplane_test::t_readonly
void t_readonly()
Definition: QhullHyperplane_test.cpp:130
orgQhull::QhullHyperplane_test::cleanup
void cleanup()
Definition: QhullHyperplane_test.cpp:60
orgQhull::QhullHyperplane_test::t_iterator
void t_iterator()
Definition: QhullHyperplane_test.cpp:231
QhullFacetList.h
orgQhull::QhullFacet::hyperplane
QhullHyperplane hyperplane() const
Definition: QhullFacet.h:78
orgQhull::QhullHyperplane::const_iterator
const typedef coordT * const_iterator
Definition: QhullHyperplane.h:43
orgQhull::QhullLinkedListIterator::hasNext
bool hasNext() const
Definition: QhullLinkedList.h:211
orgQhull::QhullHyperplane::coordinates
const coordT * coordinates() const
Definition: QhullHyperplane.h:78
orgQhull::QhullHyperplane::size
size_t size()
Definition: QhullHyperplane.h:102
orgQhull::QhullFacetList
Definition: QhullFacetList.h:41
orgQhull::QhullHyperplane::constBegin
const_iterator constBegin() const
Definition: QhullHyperplane.h:97
orgQhull::QhullHyperplane::distance
double distance(const QhullPoint &p) const
Definition: QhullHyperplane.cpp:97
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::QhullHyperplane_test::t_const_iterator
void t_const_iterator()
Definition: QhullHyperplane_test.cpp:312
c
c
orgQhull::QhullHyperplane::defineAs
void defineAs(int hyperplaneDimension, coordT *c, coordT hyperplaneOffset)
Definition: QhullHyperplane.h:80
orgQhull::QhullHyperplane::setDimension
void setDimension(int hyperplaneDimension)
Definition: QhullHyperplane.h:91
orgQhull::QhullHyperplane::begin
iterator begin()
Definition: QhullHyperplane.h:95
orgQhull::QhullHyperplane_test::t_construct
void t_construct()
Definition: QhullHyperplane_test.cpp:66
orgQhull::QhullHyperplane::offset
coordT offset() const
Definition: QhullHyperplane.h:85
orgQhull::QhullHyperplane::dimension
int dimension() const
Definition: QhullHyperplane.h:83
orgQhull::QhullHyperplane_test
Definition: QhullHyperplane_test.cpp:32
orgQhull::QhullHyperplane
Definition: QhullHyperplane.h:39
orgQhull::QhullLinkedListIterator::next
T next()
Definition: QhullLinkedList.h:213
orgQhull::QhullHyperplane::setCoordinates
void setCoordinates(coordT *c)
Definition: QhullHyperplane.h:90
orgQhull::QhullFacet::id
countT id() const
Definition: QhullFacet.h:79
q
q
orgQhull::QhullHyperplane_test::t_qhullHyperplane_iterator
void t_qhullHyperplane_iterator()
Definition: QhullHyperplane_test.cpp:370
orgQhull::RoadTest
Definition: RoadTest.h:54
orgQhull::QhullHyperplane::toStdVector
std::vector< coordT > toStdVector() const
Definition: QhullHyperplane.cpp:54
orgQhull::QhullHyperplane::ConstIterator
QhullHyperplane::const_iterator ConstIterator
Definition: QhullHyperplane.h:45
orgQhull::QhullFacet
A QhullFacet is the C++ equivalent to Qhull's facetT*.
Definition: QhullFacet.h:43
orgQhull::RboxPoints
Definition: RboxPoints.h:37
orgQhull::QhullSet::at
const T at(countT idx) const
Definition: QhullSet.h:152
orgQhull::QhullLinkedList::first
const T & first() const
Definition: QhullLinkedList.h:106
orgQhull::add_QhullHyperplane_test
void add_QhullHyperplane_test()
Definition: QhullHyperplane_test.cpp:53
orgQhull::QhullHyperplane_test::t_construct_qh
void t_construct_qh()
Definition: QhullHyperplane_test.cpp:91
orgQhull::QhullHyperplane::norm
double norm() const
Definition: QhullHyperplane.cpp:149
orgQhull::QhullLinkedListIterator
Definition: QhullLinkedList.h:200
RoadTest.h
orgQhull::QhullHyperplane::print
PrintHyperplane print(const char *message) const
Definition: QhullHyperplane.h:116
orgQhull::QhullHyperplane_test::t_value
void t_value()
Definition: QhullHyperplane_test.cpp:194
orgQhull::QhullHyperplane::hyperplaneAngle
double hyperplaneAngle(const QhullHyperplane &other) const
Definition: QhullHyperplane.cpp:137
orgQhull::QhullHyperplane_test::t_define
void t_define()
Definition: QhullHyperplane_test.cpp:163
orgQhull::QhullHyperplane_test::t_io
void t_io()
Definition: QhullHyperplane_test.cpp:408
orgQhull::QhullHyperplane::count
int count()
Definition: QhullHyperplane.h:99
orgQhull::QhullHyperplane::end
iterator end()
Definition: QhullHyperplane.h:100
c2
c2
orgQhull::QhullHyperplane_test::t_operator
void t_operator()
Definition: QhullHyperplane_test.cpp:214
RboxPoints.h
QhullError.h
orgQhull::QhullFacet::neighborFacets
QhullFacetSet neighborFacets() const
Definition: QhullFacet.cpp:180
orgQhull::QhullHyperplane::iterator
const typedef coordT * iterator
Definition: QhullHyperplane.h:42
orgQhull::QhullLinkedList::last
const T last() const
Definition: QhullLinkedList.h:110
orgQhull::RoadTest::cleanup
void cleanup()
Executed after each test.
Definition: RoadTest.cpp:38
orgQhull::QhullHyperplane::constEnd
const_iterator constEnd() const
Definition: QhullHyperplane.h:98
orgQhull::QhullHyperplane::setOffset
void setOffset(coordT hyperplaneOffset)
Definition: QhullHyperplane.h:92


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