QhullSet_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/QhullSet_test.cpp#3 $$Change: 2062 $
5 ** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled headers
10 #include <iostream>
11 #include "RoadTest.h" // QT_VERSION
12 
13 #include "libqhullcpp/QhullRidge.h"
15 #include "libqhullcpp/Qhull.h"
16 #include "libqhullcpp/RboxPoints.h"
17 
18 #include <QtCore/QList>
19 
20 using std::cout;
21 using std::endl;
22 
23 namespace orgQhull {
24 
25 class QhullSet_test : public RoadTest
26 {
27  Q_OBJECT
28 
29 #
30 private slots:
31  void cleanup();
32  void t_qhullsetbase();
33  void t_convert();
34  void t_element();
35  void t_search();
36  void t_iterator();
37  void t_const_iterator();
38  void t_qhullset_iterator();
39  void t_io();
40 };//QhullSet_test
41 
42 void
44 {
45  new QhullSet_test(); // RoadTest::s_testcases
46 }
47 
48 //Executed after each testcase
49 void QhullSet_test::
51 {
53 }
54 
55 // Test QhullFacetSet and QhullSet.
56 // Use QhullRidgeSet to test methods overloaded by QhullFacetSet
57 
58 void QhullSet_test::
60 {
61  RboxPoints rcube("c");
62  {
63  Qhull q(rcube,"QR0"); // triangulation of rotated unit cube
64  // Fake an empty set. Default constructor not defined. No memory allocation.
65  QhullFacet f4 = q.beginFacet();
66  QhullFacetSet fs = f4.neighborFacets();
67  fs.defineAs(q.qh()->other_points); // Force an empty set
68  QVERIFY(fs.isEmpty());
69  QCOMPARE(fs.count(), 0);
70  QCOMPARE(fs.size(), 0u);
71  QCOMPARE(fs.begin(), fs.end()); // beginPointer(), endPointer()
72  QVERIFY(QhullSetBase::isEmpty(fs.getSetT()));
73 
74  QhullRidgeSet rs = f4.ridges();
75  QVERIFY(!rs.isEmpty());
76  QCOMPARE(rs.count(), 4);
77  QCOMPARE(rs.size(), 4u);
78  QVERIFY(rs.begin()!=rs.end());
79  QVERIFY(!QhullSetBase::isEmpty(rs.getSetT()));
80  QhullRidgeSet rs2= rs; // copy constructor
81  // rs= rs2; // disabled. Would not copy ridges
82  QCOMPARE(rs2, rs);
83 
84  QCOMPARE(q.facetCount(), 6);
85  QhullFacet f = q.beginFacet();
86  QhullFacetSet fs2 = f.neighborFacets();
87  QCOMPARE(fs2.count(), 4);
88  QCOMPARE(fs2.size(), 4u);
89  QVERIFY(!fs2.isEmpty());
90  QVERIFY(!QhullSetBase::isEmpty(fs2.getSetT()));
91  QVERIFY(fs!=fs2);
92  setT *s= fs2.getSetT();
93  fs.defineAs(s);
94  QVERIFY(fs==fs2);
95  QCOMPARE(fs[1], fs2[1]); // elementPointer
96  QhullFacetSet fs3(fs2);
97  QVERIFY(fs3==fs);
98  // fs= fs2; // disabled. Would not copy facets
99  QhullFacetSet fs4= fs2; // copy constructor
100  QVERIFY(fs4==fs2);
101  }
102 }//t_qhullsetbase
103 
104 // constructors tested by t_qhullsetbase
105 
106 void QhullSet_test::
108 {
109  RboxPoints rcube("c");
110  {
111  Qhull q(rcube,"QR0"); // rotated unit cube
112  QhullFacet f= q.firstFacet();
113  f= f.next();
114  QhullRidgeSet rs= f.ridges();
115  QCOMPARE(rs.count(),4);
116  std::vector<QhullRidge> rv= rs.toStdVector();
117  QCOMPARE(rv.size(), 4u);
118  QList<QhullRidge> rv2= rs.toQList();
119  QCOMPARE(rv2.size(), 4);
120  std::vector<QhullRidge>::iterator i= rv.begin();
121  foreach(QhullRidge r, rv2){ // Qt only
122  QhullRidge r2= *i++;
123  QCOMPARE(r, r2);
124  }
125 
126  Qhull q2(rcube,"Qt QR0"); // triangulation of rotated unit cube
127  QCOMPARE(q2.facetCount(), 12);
128  QhullFacet f2 = q2.beginFacet();
129  QhullFacetSet fs = f2.neighborFacets();
130  QCOMPARE(fs.size(), 3U);
131  std::vector<QhullFacet> vs= fs.toStdVector();
132  QCOMPARE(vs.size(), fs.size());
133  for(int k= fs.count(); k--; ){
134  QCOMPARE(vs[k], fs[k]);
135  }
136  QList<QhullFacet> qv= fs.toQList();
137  QCOMPARE(qv.count(), fs.count());
138  for(int k= fs.count(); k--; ){
139  QCOMPARE(qv[k], fs[k]);
140  }
141  }
142 }//t_convert
143 
144 //ReadOnly (count, isEmpty) tested by t_convert
145 // operator== tested by t_search
146 
147 void QhullSet_test::
149 {
150  RboxPoints rcube("c");
151  Qhull q(rcube,"QR0"); // rotated unit cube
152  QhullFacet f = q.beginFacet();
153  QhullFacetSet fs = f.neighborFacets();
154 
155  QCOMPARE(fs.at(1), fs[1]);
156  QCOMPARE(fs.first(), fs[0]);
157  QCOMPARE(fs.front(), fs.first());
158  QCOMPARE(fs.last(), fs.at(3));
159  QCOMPARE(fs.back(), fs.last());
160  facetT **d = fs.data();
161  facetT * const *d2= fs.data();
162  facetT * const *d3= fs.constData();
163  QVERIFY(d==d2);
164  QVERIFY(d2==d3);
165  QCOMPARE(QhullFacet(q, *d), fs.first());
166  QhullFacetSet::iterator i(q.qh(), d+4);
167  QCOMPARE(i, fs.end());
168  QCOMPARE(d[4], static_cast<facetT *>(0));
169  QhullFacet f4(q, d[4]);
170  QVERIFY(!f4.isValid());
171  QCOMPARE(fs.second(), fs[1]);
172  const QhullFacet f2= fs.second();
173  QVERIFY(f2==fs[1]);
174  const QhullFacet f3= fs[1];
175  QCOMPARE(f2, f3);
176 
177  QCOMPARE(fs.value(2), fs[2]);
178  QCOMPARE(fs.value(-1), QhullFacet());
179  QCOMPARE(fs.value(10), QhullFacet());
180  QCOMPARE(fs.value(2, f), fs[2]);
181  QCOMPARE(fs.value(4, f), f);
182  // mid() not available (read-only)
183 }//t_element
184 
185 void QhullSet_test::
187 {
188  RboxPoints rcube("c");
189  Qhull q(rcube,"QR0"); // rotated unit cube
190  QhullFacet f = q.beginFacet();
191  QhullFacetSet fs = f.neighborFacets();
192  QhullFacet f2= *fs.begin();
193  QhullFacet f3= fs.last();
194  QVERIFY(fs.contains(f2));
195  QVERIFY(fs.contains(f3));
196  QVERIFY(!fs.contains(f));
197 
198  QhullFacetSet fs2= f2.neighborFacets();
199  QVERIFY(fs==fs);
200  QVERIFY(fs!=fs2);
201  QCOMPARE(fs.count(f2), 1);
202  QCOMPARE(fs.count(f3), 1);
203  QCOMPARE(fs.count(f), 0);
204  QCOMPARE(fs.indexOf(f2), 0);
205  QCOMPARE(fs.indexOf(f3), 3);
206  QCOMPARE(fs.indexOf(f), -1);
207  QCOMPARE(fs.lastIndexOf(f2), 0);
208  QCOMPARE(fs.lastIndexOf(f3), 3);
209  QCOMPARE(fs.lastIndexOf(f), -1);
210 }//t_search
211 
212 void QhullSet_test::
214 {
215  RboxPoints rcube("c");
216  {
217  Qhull q(rcube,"QR0"); // rotated unit cube
218  QhullFacet f = q.beginFacet();
219  QhullFacetSet fs = f.neighborFacets();
221  QhullFacetSet::iterator i2= fs.begin();
222  QVERIFY(i==i2);
223  QVERIFY(i>=i2);
224  QVERIFY(i<=i2);
225  i= fs.begin();
226  QVERIFY(i==i2);
227  i2= fs.end();
228  QVERIFY(i!=i2);
229  QhullFacet f3(*i);
230  i2--;
231  QhullFacet f2= *i2;
232  QCOMPARE(f3.id(), fs[0].id());
233  QCOMPARE(f2.id(), fs[3].id());
235  QCOMPARE(*i2, *i3);
236 
237  (i3= i)++;
238  QCOMPARE((*i3).id(), fs[1].id());
239  QVERIFY(i==i);
240  QVERIFY(i!=i2);
241  QVERIFY(i<i2);
242  QVERIFY(i<=i2);
243  QVERIFY(i2>i);
244  QVERIFY(i2>=i);
245 
247  QVERIFY(i==i4); // iterator COMP const_iterator
248  QVERIFY(i<=i4);
249  QVERIFY(i>=i4);
250  QVERIFY(i4==i); // const_iterator COMP iterator
251  QVERIFY(i4<=i);
252  QVERIFY(i4>=i);
253  QVERIFY(i>=i4);
254  QVERIFY(i4<=i);
255  QVERIFY(i2!=i4);
256  QVERIFY(i2>i4);
257  QVERIFY(i2>=i4);
258  QVERIFY(i4!=i2);
259  QVERIFY(i4<i2);
260  QVERIFY(i4<=i2);
261  ++i4;
262  QVERIFY(i<i4);
263  QVERIFY(i<=i4);
264  QVERIFY(i4>i);
265  QVERIFY(i4>=i);
266 
267  i= fs.begin();
268  i2= fs.begin();
269  QCOMPARE(i, i2++);
270  QCOMPARE(*i2, fs[1]);
271  QCOMPARE(++i, i2);
272  QCOMPARE(i, i2--);
273  QCOMPARE(i2, fs.begin());
274  QCOMPARE(--i, i2);
275  QCOMPARE(i2 += 4, fs.end());
276  QCOMPARE(i2 -= 4, fs.begin());
277  QCOMPARE(i2+0, fs.begin());
278  QCOMPARE(i2+4, fs.end());
279  i2 += 4;
280  i= i2-0;
281  QCOMPARE(i, i2);
282  i= i2-4;
283  QCOMPARE(i, fs.begin());
284  QCOMPARE(i2-i, 4);
285 
286  //fs.begin end tested above
287 
288  // QhullFacetSet is const-only
289  }
290 }//t_iterator
291 
292 void QhullSet_test::
294 {
295  RboxPoints rcube("c");
296  {
297  Qhull q(rcube,"QR0"); // rotated unit cube
298  QhullFacet f = q.beginFacet();
299  QhullFacetSet fs = f.neighborFacets();
301  QhullFacetSet::const_iterator i2= fs.begin();
302  QVERIFY(i==i2);
303  QVERIFY(i>=i2);
304  QVERIFY(i<=i2);
305  i= fs.begin();
306  QVERIFY(i==i2);
307  i2= fs.end();
308  QVERIFY(i!=i2);
309  QhullFacet f3(*i);
310  i2--;
311  QhullFacet f2= *i2;
312  QCOMPARE(f3.id(), fs[0].id());
313  QCOMPARE(f2.id(), fs[3].id());
315  QCOMPARE(*i2, *i3);
316 
317  (i3= i)++;
318  QCOMPARE((*i3).id(), fs[1].id());
319  QVERIFY(i==i);
320  QVERIFY(i!=i2);
321  QVERIFY(i<i2);
322  QVERIFY(i<=i2);
323  QVERIFY(i2>i);
324  QVERIFY(i2>=i);
325 
326  // See t_iterator for const_iterator COMP iterator
327 
328  i= fs.begin();
329  i2= fs.constBegin();
330  QCOMPARE(i, i2++);
331  QCOMPARE(*i2, fs[1]);
332  QCOMPARE(++i, i2);
333  QCOMPARE(i, i2--);
334  QCOMPARE(i2, fs.constBegin());
335  QCOMPARE(--i, i2);
336  QCOMPARE(i2+=4, fs.constEnd());
337  QCOMPARE(i2-=4, fs.constBegin());
338  QCOMPARE(i2+0, fs.constBegin());
339  QCOMPARE(i2+4, fs.constEnd());
340  i2 += 4;
341  i= i2-0;
342  QCOMPARE(i, i2);
343  i= i2-4;
344  QCOMPARE(i, fs.constBegin());
345  QCOMPARE(i2-i, 4);
346 
347  // QhullFacetSet is const-only
348  }
349 }//t_const_iterator
350 
351 void QhullSet_test::
353 {
354  RboxPoints rcube("c");
355  Qhull q(rcube,"QR0"); // rotated unit cube
356  // Fake an empty set. Default constructor not defined. No memory allocation.
357  QhullFacet f = q.beginFacet();
358  QhullFacetSet fs = f.neighborFacets();
359  fs.defineAs(q.qh()->other_points);
360  QhullFacetSetIterator i(fs);
361  QCOMPARE(fs.count(), 0);
362  QVERIFY(!i.hasNext());
363  QVERIFY(!i.hasPrevious());
364  i.toBack();
365  QVERIFY(!i.hasNext());
366  QVERIFY(!i.hasPrevious());
367 
368  QhullFacet f2 = q.beginFacet();
369  QhullFacetSet fs2 = f2.neighborFacets();
370  QhullFacetSetIterator i2(fs2);
371  QCOMPARE(fs2.count(), 4);
372  i= fs2;
373  QVERIFY(i2.hasNext());
374  QVERIFY(!i2.hasPrevious());
375  QVERIFY(i.hasNext());
376  QVERIFY(!i.hasPrevious());
377  i2.toBack();
378  i.toFront();
379  QVERIFY(!i2.hasNext());
380  QVERIFY(i2.hasPrevious());
381  QVERIFY(i.hasNext());
382  QVERIFY(!i.hasPrevious());
383 
384  // i at front, i2 at end/back, 4 neighbors
385  QhullFacetSet fs3 = f2.neighborFacets(); // same as fs2
386  QhullFacet f3(fs2[0]);
387  QhullFacet f4= fs3[0];
388  QCOMPARE(f3, f4);
389  QVERIFY(f3==f4);
390  QhullFacet f5(fs3[1]);
391  QVERIFY(f4!=f5);
392  QhullFacet f6(fs3[2]);
393  QhullFacet f7(fs3[3]);
394  QCOMPARE(i2.peekPrevious(), f7);
395  QCOMPARE(i2.previous(), f7);
396  QCOMPARE(i2.previous(), f6);
397  QCOMPARE(i2.previous(), f5);
398  QCOMPARE(i2.previous(), f4);
399  QVERIFY(!i2.hasPrevious());
400  QCOMPARE(i.peekNext(), f4);
401  // i.peekNext()= 1.0; // compiler error
402  QCOMPARE(i.next(), f4);
403  QCOMPARE(i.peekNext(), f5);
404  QCOMPARE(i.next(), f5);
405  QCOMPARE(i.next(), f6);
406  QCOMPARE(i.next(), f7);
407  QVERIFY(!i.hasNext());
408  i.toFront();
409  QCOMPARE(i.next(), f4);
410 }//t_qhullset_iterator
411 
412 void QhullSet_test::
414 {
415  RboxPoints rcube("c");
416  Qhull q(rcube,"QR0"); // rotated unit cube
417  // Fake an empty set. Default constructor not defined. No memory allocation.
418  QhullFacet f= q.beginFacet();
420  fs.defineAs(q.qh()->other_points);
421  cout << "INFO: empty set" << fs << std::endl;
422  QhullFacet f2= q.beginFacet();
423  QhullFacetSet fs2= f2.neighborFacets();
424  cout << "INFO: Neighboring facets\n";
425  cout << fs2 << std::endl;
426 
427  QhullRidgeSet rs= f.ridges();
428  cout << "INFO: Ridges for a facet\n";
429  cout << rs << std::endl;
430 }//t_io
431 
432 }//namespace orgQhull
433 
434 #include "moc/QhullSet_test.moc"
orgQhull::QhullSet::constData
const T::base_type * constData() const
end element is NULL
Definition: QhullSet.h:157
orgQhull::QhullFacetSet::count
countT count() const
Filtered by facet.isGood(). May be 0 when !isEmpty().
Definition: QhullFacetSet.cpp:67
U
U
orgQhull::QhullSet< QhullFacet >::Iterator
QhullSet< QhullFacet >::iterator Iterator
Definition: QhullSet.h:116
orgQhull::QhullSetBase::isEmpty
bool isEmpty() const
Definition: QhullSet.h:76
orgQhull::QhullSet_test::t_convert
void t_convert()
Definition: QhullSet_test.cpp:107
orgQhull::QhullSet::first
const T first() const
Definition: QhullSet.h:163
orgQhull::add_QhullSet_test
void add_QhullSet_test()
Definition: QhullSet_test.cpp:43
orgQhull::QhullSet::value
T value(countT idx) const
Definition: QhullSet.h:365
orgQhull::QhullFacetSet
Definition: QhullFacetSet.h:33
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::QhullFacetSet::contains
bool contains(const QhullFacet &f) const
Definition: QhullFacetSet.cpp:52
orgQhull::QhullSet::indexOf
countT indexOf(const T &t) const
Definition: QhullSet.h:193
qv
qv
QhullFacetSet.h
orgQhull::QhullSet::toStdVector
std::vector< T > toStdVector() const
Definition: QhullSet.h:334
Qhull.h
q2
q2
orgQhull::QhullSet::lastIndexOf
countT lastIndexOf(const T &t) const
Definition: QhullSet.h:412
orgQhull::QhullSet< QhullFacet >::ConstIterator
QhullSet< QhullFacet >::const_iterator ConstIterator
Definition: QhullSet.h:118
orgQhull::QhullSet::data
T::base_type * data()
Definition: QhullSet.h:158
orgQhull::QhullSetIterator
Faster then interator/const_iterator due to T::base_type.
Definition: QhullSet.h:289
octree.r
r
Definition: octree.py:9
facetT
Definition: libqhull.h:262
orgQhull::QhullSet::second
const T second() const
Definition: QhullSet.h:175
orgQhull::QhullFacet::isValid
bool isValid() const
Definition: QhullFacet.h:81
orgQhull::QhullSetIterator::previous
T previous()
Definition: QhullSet.h:320
orgQhull::QhullSet::back
const T back() const
Definition: QhullSet.h:154
orgQhull::QhullSet_test::t_iterator
void t_iterator()
Definition: QhullSet_test.cpp:213
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::QhullSetIterator::toBack
void toBack()
Definition: QhullSet.h:321
orgQhull::QhullSetBase::size
size_t size() const
Definition: QhullSet.h:79
orgQhull::QhullSet::constEnd
const_iterator constEnd() const
Definition: QhullSet.h:186
orgQhull::QhullSetIterator::toFront
void toFront()
Definition: QhullSet.h:322
setT
Definition: qset.h:83
orgQhull::QhullSet::isEmpty
bool isEmpty() const
Definition: QhullSet.h:76
d
d
QhullRidge.h
orgQhull::QhullSet::count
countT count(const T &t) const
Definition: QhullSet.h:395
orgQhull::QhullRidge
Definition: QhullRidge.h:58
orgQhull::QhullFacet::next
QhullFacet next() const
Definition: QhullFacet.h:87
orgQhull::QhullSet
Definition: QhullSet.h:105
orgQhull::QhullSetBase::getSetT
setT * getSetT() const
Definition: QhullSet.h:75
orgQhull::QhullSet_test::t_search
void t_search()
Definition: QhullSet_test.cpp:186
orgQhull::QhullFacetSet::toStdVector
std::vector< QhullFacet > toStdVector() const
Definition: QhullFacetSet.cpp:35
orgQhull::QhullFacet::id
countT id() const
Definition: QhullFacet.h:79
orgQhull::QhullSetIterator::peekNext
T peekNext() const
Definition: QhullSet.h:318
q
q
orgQhull::QhullSet_test::cleanup
void cleanup()
Definition: QhullSet_test.cpp:50
orgQhull::QhullSet_test::t_const_iterator
void t_const_iterator()
Definition: QhullSet_test.cpp:293
orgQhull::QhullSet_test::t_qhullsetbase
void t_qhullsetbase()
Definition: QhullSet_test.cpp:59
orgQhull::QhullSet_test::t_element
void t_element()
Definition: QhullSet_test.cpp:148
orgQhull::QhullSet::last
const T last() const
Definition: QhullSet.h:169
orgQhull::QhullSet_test::t_io
void t_io()
Definition: QhullSet_test.cpp:413
orgQhull::QhullSetIterator::hasPrevious
bool hasPrevious() const
Definition: QhullSet.h:316
orgQhull::RoadTest
Definition: RoadTest.h:54
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::QhullSet::constBegin
const_iterator constBegin() const
Definition: QhullSet.h:185
orgQhull::QhullFacet::ridges
QhullRidgeSet ridges() const
Definition: QhullFacet.cpp:192
RoadTest.h
r2
r2
orgQhull::QhullSetIterator::next
T next()
Definition: QhullSet.h:317
orgQhull::QhullSet::front
const T front() const
Definition: QhullSet.h:166
orgQhull::QhullSet::begin
iterator begin()
Definition: QhullSet.h:183
orgQhull::QhullSet_test::t_qhullset_iterator
void t_qhullset_iterator()
Definition: QhullSet_test.cpp:352
RboxPoints.h
orgQhull::QhullFacet::neighborFacets
QhullFacetSet neighborFacets() const
Definition: QhullFacet.cpp:180
orgQhull::RoadTest::cleanup
void cleanup()
Executed after each test.
Definition: RoadTest.cpp:38
orgQhull::QhullSet::end
iterator end()
Definition: QhullSet.h:187
orgQhull::QhullSetIterator::hasNext
bool hasNext() const
Definition: QhullSet.h:315
orgQhull::QhullSet_test
Definition: QhullSet_test.cpp:25
orgQhull::QhullSetIterator::peekPrevious
T peekPrevious() const
Definition: QhullSet.h:319


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