QhullSet_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2009-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/QhullSet_test.cpp#2 $$Change: 1342 $
00005 ** $DateTime: 2011/03/07 21:55:47 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 //pre-compiled headers
00010 #include <iostream>
00011 #include <QtCore/QList>
00012 #include "../road/RoadTest.h" // QT_VERSION
00013 
00014 #include "QhullRidge.h"
00015 #include "QhullFacetSet.h"
00016 #include "Qhull.h"
00017 
00018 using std::cout;
00019 using std::endl;
00020 
00021 namespace orgQhull {
00022 
00023 class QhullSet_test : public RoadTest
00024 {
00025     Q_OBJECT
00026 
00027 #//Test slots
00028 private slots:
00029     void cleanup();
00030     void t_qhullsetbase();
00031     void t_convert();
00032     void t_element();
00033     void t_search();
00034     void t_iterator();
00035     void t_const_iterator();
00036     void t_qhullset_iterator();
00037     void t_io();
00038 };//QhullSet_test
00039 
00040 void
00041 add_QhullSet_test()
00042 {
00043     new QhullSet_test();
00044 }
00045 
00046 //Executed after each testcase
00047 void QhullSet_test::
00048 cleanup()
00049 {
00050     UsingLibQhull::checkQhullMemoryEmpty();
00051     RoadTest::cleanup();
00052 }
00053 
00054 // Test QhullFacetSet and QhullSet.
00055 // Use QhullRidgeSet to test methods overloaded by QhullFacetSet
00056 
00057 void QhullSet_test::
00058 t_qhullsetbase()
00059 {
00060     RboxPoints rcube("c");
00061     {
00062         Qhull q(rcube,"QR0");  // triangulation of rotated unit cube
00063         // Fake an empty set.  Default constructor not defined.  No memory allocation.
00064         QhullFacet f4 = q.beginFacet();
00065         QhullFacetSet fs = f4.neighborFacets();
00066         fs.defineAs(q.qhullQh()->other_points); // Force an empty set
00067         QVERIFY(fs.isEmpty());
00068         QVERIFY(fs.empty());
00069         QCOMPARE(fs.count(), 0);
00070         QCOMPARE(fs.size(), 0u);
00071         QCOMPARE(fs.begin(), fs.end()); // beginPointer(), endPointer()
00072         QVERIFY(QhullSetBase::isEmpty(fs.getSetT()));
00073 
00074         QhullRidgeSet rs = f4.ridges();
00075         QVERIFY(!rs.isEmpty());
00076         QVERIFY(!rs.empty());
00077         QCOMPARE(rs.count(), 4);
00078         QCOMPARE(rs.size(), 4u);
00079         QVERIFY(rs.begin()!=rs.end());
00080         QVERIFY(!QhullSetBase::isEmpty(rs.getSetT()));
00081         QhullRidgeSet rs2= rs; // copy constructor
00082         // rs= rs2; // disabled.  Would not copy ridges
00083         QCOMPARE(rs2, rs);
00084 
00085         QCOMPARE(q.facetCount(), 6);
00086         QhullFacet f = q.beginFacet();
00087         QhullFacetSet fs2 = f.neighborFacets();
00088         QCOMPARE(fs2.count(), 4);
00089         QCOMPARE(fs2.size(), 4u);
00090         QVERIFY(!fs2.isEmpty());
00091         QVERIFY(!QhullSetBase::isEmpty(fs2.getSetT()));
00092         QVERIFY(!fs2.empty());
00093         QVERIFY(fs!=fs2);
00094         setT *s= fs2.getSetT();
00095         fs.defineAs(s);
00096         QVERIFY(fs==fs2);
00097         QCOMPARE(fs[1], fs2[1]); // elementPointer
00098         QhullFacetSet fs3(fs2);
00099         QVERIFY(fs3==fs);
00100         // fs= fs2; // disabled.  Would not copy facets
00101         QhullFacetSet fs4= fs2; // copy constructor
00102         QVERIFY(fs4==fs2);
00103     }
00104 }//t_qhullsetbase
00105 
00106 // constructors tested by t_qhullsetbase
00107 
00108 void QhullSet_test::
00109 t_convert()
00110 {
00111     RboxPoints rcube("c");
00112     {
00113         Qhull q(rcube,"QR0");  // rotated unit cube
00114         QhullFacet f= q.firstFacet();
00115         f= f.next();
00116         QhullRidgeSet rs= f.ridges();
00117         QCOMPARE(rs.count(),4);
00118         std::vector<QhullRidge> rv= rs.toStdVector();
00119         QCOMPARE(rv.size(), 4u);
00120         QList<QhullRidge> rv2= rs.toQList();
00121         QCOMPARE(rv2.size(), 4);
00122         std::vector<QhullRidge>::iterator i= rv.begin();
00123         foreach(QhullRidge r, rv2){  // Qt only
00124             QhullRidge r2= *i++;
00125             QCOMPARE(r, r2);
00126         }
00127 
00128         Qhull q2(rcube,"Qt QR0");  // triangulation of rotated unit cube
00129         QCOMPARE(q2.facetCount(), 12);
00130         QhullFacet f2 = q2.beginFacet();
00131         QhullFacetSet fs = f2.neighborFacets();
00132         QCOMPARE(fs.size(), 3U);
00133         std::vector<QhullFacet> vs= fs.toStdVector();
00134         QCOMPARE(vs.size(), fs.size());
00135         for(int k= fs.count(); k--; ){
00136             QCOMPARE(vs[k], fs[k]);
00137         }
00138         QList<QhullFacet> qv= fs.toQList();
00139         QCOMPARE(qv.count(), fs.count());
00140         for(int k= fs.count(); k--; ){
00141             QCOMPARE(qv[k], fs[k]);
00142         }
00143     }
00144 }//t_convert
00145 
00146 //ReadOnly (count, isEmpty) tested by t_convert
00147 //  operator== tested by t_search
00148 
00149 void QhullSet_test::
00150 t_element()
00151 {
00152     RboxPoints rcube("c");
00153     Qhull q(rcube,"QR0");  // rotated unit cube
00154     QhullFacet f = q.beginFacet();
00155     QhullFacetSet fs = f.neighborFacets();
00156 
00157     QCOMPARE(fs.at(1), fs[1]);
00158     QCOMPARE(fs.first(), fs[0]);
00159     QCOMPARE(fs.front(), fs.first());
00160     QCOMPARE(fs.last(), fs.at(3));
00161     QCOMPARE(fs.back(), fs.last());
00162     QhullFacet *d= fs.data();
00163     const QhullFacet *d2= fs.data();
00164     const QhullFacet *d3= fs.constData();
00165     QVERIFY(d==d2);
00166     QVERIFY(d2==d3);
00167     QCOMPARE(*d, fs.first());
00168     QCOMPARE(d+4, fs.end());
00169     QCOMPARE((d+4)->getFacetT(), static_cast<facetT *>(0));
00170     QhullFacet f4= *(d+4);
00171     QVERIFY(!f4.isDefined());
00172     QCOMPARE(fs.second(), fs[1]);
00173     const QhullFacet f2= fs.second();
00174     QVERIFY(f2==fs[1]);
00175     const QhullFacet f3= fs[1];
00176     QCOMPARE(f2, f3);
00177 
00178     QCOMPARE(fs.value(2), fs[2]);
00179     QCOMPARE(fs.value(-1), QhullFacet());
00180     QCOMPARE(fs.value(10), QhullFacet());
00181     QCOMPARE(fs.value(2, f), fs[2]);
00182     QCOMPARE(fs.value(4, f), f);
00183     // mid() not available (read-only)
00184 }//t_element
00185 
00186 void QhullSet_test::
00187 t_search()
00188 {
00189     RboxPoints rcube("c");
00190     Qhull q(rcube,"QR0");  // rotated unit cube
00191     QhullFacet f = q.beginFacet();
00192     QhullFacetSet fs = f.neighborFacets();
00193     QhullFacet f2= *fs.begin();
00194     QhullFacet f3= fs.last();
00195     QVERIFY(fs.contains(f2));
00196     QVERIFY(fs.contains(f3));
00197     QVERIFY(!fs.contains(f));
00198 
00199     QhullFacetSet fs2= f2.neighborFacets();
00200     QVERIFY(fs==fs);
00201     QVERIFY(fs!=fs2);
00202     QCOMPARE(fs.count(f2), 1);
00203     QCOMPARE(fs.count(f3), 1);
00204     QCOMPARE(fs.count(f), 0);
00205     QCOMPARE(fs.indexOf(f2), 0);
00206     QCOMPARE(fs.indexOf(f3), 3);
00207     QCOMPARE(fs.indexOf(f), -1);
00208     QCOMPARE(fs.lastIndexOf(f2), 0);
00209     QCOMPARE(fs.lastIndexOf(f3), 3);
00210     QCOMPARE(fs.lastIndexOf(f), -1);
00211 }//t_search
00212 
00213 void QhullSet_test::
00214 t_iterator()
00215 {
00216     RboxPoints rcube("c");
00217     {
00218         Qhull q(rcube,"QR0");  // rotated unit cube
00219         QhullFacet f = q.beginFacet();
00220         QhullFacetSet fs = f.neighborFacets();
00221         QhullFacetSet::Iterator i= fs.begin();
00222         QhullFacetSet::iterator i2= fs.begin();
00223         QVERIFY(i==i2);
00224         QVERIFY(i>=i2);
00225         QVERIFY(i<=i2);
00226         i= fs.begin();
00227         QVERIFY(i==i2);
00228         i2= fs.end();
00229         QVERIFY(i!=i2);
00230         QhullFacet f3(*i);
00231         i2--;
00232         QhullFacet f2= *i2;
00233         QCOMPARE(f3.id(), fs[0].id());
00234         QCOMPARE(f2.id(), fs[3].id());
00235         QhullFacetSet::Iterator i3(i2);
00236         QCOMPARE(*i2, *i3);
00237 
00238         (i3= i)++;
00239         QCOMPARE((*i3).id(), fs[1].id());
00240         QVERIFY(i==i);
00241         QVERIFY(i!=i2);
00242         QVERIFY(i<i2);
00243         QVERIFY(i<=i2);
00244         QVERIFY(i2>i);
00245         QVERIFY(i2>=i);
00246 
00247         QhullFacetSet::ConstIterator i4= fs.begin();
00248         QVERIFY(i==i4); // iterator COMP const_iterator
00249         QVERIFY(i<=i4);
00250         QVERIFY(i>=i4);
00251         QVERIFY(i4==i); // const_iterator COMP iterator
00252         QVERIFY(i4<=i);
00253         QVERIFY(i4>=i);
00254         QVERIFY(i>=i4);
00255         QVERIFY(i4<=i);
00256         QVERIFY(i2!=i4);
00257         QVERIFY(i2>i4);
00258         QVERIFY(i2>=i4);
00259         QVERIFY(i4!=i2);
00260         QVERIFY(i4<i2);
00261         QVERIFY(i4<=i2);
00262         ++i4;
00263         QVERIFY(i<i4);
00264         QVERIFY(i<=i4);
00265         QVERIFY(i4>i);
00266         QVERIFY(i4>=i);
00267 
00268         i= fs.begin();
00269         i2= fs.begin();
00270         QCOMPARE(i, i2++);
00271         QCOMPARE(*i2, fs[1]);
00272         QCOMPARE(++i, i2);
00273         QCOMPARE(i, i2--);
00274         QCOMPARE(i2, fs.begin());
00275         QCOMPARE(--i, i2);
00276         QCOMPARE(i2 += 4, fs.end());
00277         QCOMPARE(i2 -= 4, fs.begin());
00278         QCOMPARE(i2+0, fs.begin());
00279         QCOMPARE(i2+4, fs.end());
00280         i2 += 4;
00281         i= i2-0;
00282         QCOMPARE(i, i2);
00283         i= i2-4;
00284         QCOMPARE(i, fs.begin());
00285         QCOMPARE(i2-i, 4);
00286 
00287         //fs.begin end tested above
00288 
00289         // QhullFacetSet is const-only
00290     }
00291 }//t_iterator
00292 
00293 void QhullSet_test::
00294 t_const_iterator()
00295 {
00296     RboxPoints rcube("c");
00297     {
00298         Qhull q(rcube,"QR0");  // rotated unit cube
00299         QhullFacet f = q.beginFacet();
00300         QhullFacetSet fs = f.neighborFacets();
00301         QhullFacetSet::ConstIterator i= fs.begin();
00302         QhullFacetSet::const_iterator i2= fs.begin();
00303         QVERIFY(i==i2);
00304         QVERIFY(i>=i2);
00305         QVERIFY(i<=i2);
00306         i= fs.begin();
00307         QVERIFY(i==i2);
00308         i2= fs.end();
00309         QVERIFY(i!=i2);
00310         QhullFacet f3(*i);
00311         i2--;
00312         QhullFacet f2= *i2;
00313         QCOMPARE(f3.id(), fs[0].id());
00314         QCOMPARE(f2.id(), fs[3].id());
00315         QhullFacetSet::ConstIterator i3(i2);
00316         QCOMPARE(*i2, *i3);
00317 
00318         (i3= i)++;
00319         QCOMPARE((*i3).id(), fs[1].id());
00320         QVERIFY(i==i);
00321         QVERIFY(i!=i2);
00322         QVERIFY(i<i2);
00323         QVERIFY(i<=i2);
00324         QVERIFY(i2>i);
00325         QVERIFY(i2>=i);
00326 
00327         // See t_iterator for const_iterator COMP iterator
00328 
00329         i= fs.begin();
00330         i2= fs.constBegin();
00331         QCOMPARE(i, i2++);
00332         QCOMPARE(*i2, fs[1]);
00333         QCOMPARE(++i, i2);
00334         QCOMPARE(i, i2--);
00335         QCOMPARE(i2, fs.constBegin());
00336         QCOMPARE(--i, i2);
00337         QCOMPARE(i2+=4, fs.constEnd());
00338         QCOMPARE(i2-=4, fs.constBegin());
00339         QCOMPARE(i2+0, fs.constBegin());
00340         QCOMPARE(i2+4, fs.constEnd());
00341         i2 += 4;
00342         i= i2-0;
00343         QCOMPARE(i, i2);
00344         i= i2-4;
00345         QCOMPARE(i, fs.constBegin());
00346         QCOMPARE(i2-i, 4);
00347 
00348         // QhullFacetSet is const-only
00349     }
00350 }//t_const_iterator
00351 
00352 void QhullSet_test::
00353 t_qhullset_iterator()
00354 {
00355     RboxPoints rcube("c");
00356     Qhull q(rcube,"QR0");  // rotated unit cube
00357     // Fake an empty set.  Default constructor not defined.  No memory allocation.
00358     QhullFacet f = q.beginFacet();
00359     QhullFacetSet fs = f.neighborFacets();
00360     fs.defineAs(q.qhullQh()->other_points);
00361     QhullFacetSetIterator i= fs;
00362     QCOMPARE(fs.count(), 0);
00363     QVERIFY(!i.hasNext());
00364     QVERIFY(!i.hasPrevious());
00365     i.toBack();
00366     QVERIFY(!i.hasNext());
00367     QVERIFY(!i.hasPrevious());
00368 
00369     QhullFacet f2 = q.beginFacet();
00370     QhullFacetSet fs2 = f2.neighborFacets();
00371     QhullFacetSetIterator i2(fs2);
00372     QCOMPARE(fs2.count(), 4);
00373     i= fs2;
00374     QVERIFY(i2.hasNext());
00375     QVERIFY(!i2.hasPrevious());
00376     QVERIFY(i.hasNext());
00377     QVERIFY(!i.hasPrevious());
00378     i2.toBack();
00379     i.toFront();
00380     QVERIFY(!i2.hasNext());
00381     QVERIFY(i2.hasPrevious());
00382     QVERIFY(i.hasNext());
00383     QVERIFY(!i.hasPrevious());
00384 
00385     // i at front, i2 at end/back, 4 neighbors
00386     QhullFacetSet fs3 = f2.neighborFacets(); // same as fs2
00387     QhullFacet f3(fs2[0]);
00388     QhullFacet f4= fs3[0];
00389     QCOMPARE(f3, f4);
00390     QVERIFY(f3==f4);
00391     QhullFacet f5(fs3[1]);
00392     QVERIFY(f4!=f5);
00393     QhullFacet f6(fs3[2]);
00394     QhullFacet f7(fs3[3]);
00395     QCOMPARE(i2.peekPrevious(), f7);
00396     QCOMPARE(i2.previous(), f7);
00397     QCOMPARE(i2.previous(), f6);
00398     QCOMPARE(i2.previous(), f5);
00399     QCOMPARE(i2.previous(), f4);
00400     QVERIFY(!i2.hasPrevious());
00401     QCOMPARE(i.peekNext(), f4);
00402     // i.peekNext()= 1.0; // compiler error
00403     QCOMPARE(i.next(), f4);
00404     QCOMPARE(i.peekNext(), f5);
00405     QCOMPARE(i.next(), f5);
00406     QCOMPARE(i.next(), f6);
00407     QCOMPARE(i.next(), f7);
00408     QVERIFY(!i.hasNext());
00409     i.toFront();
00410     QCOMPARE(i.next(), f4);
00411 }//t_qhullset_iterator
00412 
00413 void QhullSet_test::
00414 t_io()
00415 {
00416     RboxPoints rcube("c");
00417     Qhull q(rcube,"QR0");  // rotated unit cube
00418     // Fake an empty set.  Default constructor not defined.  No memory allocation.
00419     QhullFacet f= q.beginFacet();
00420     QhullFacetSet fs= f.neighborFacets();
00421     fs.defineAs(q.qhullQh()->other_points);
00422     cout << "INFO:     empty set" << fs << std::endl;
00423     QhullFacet f2= q.beginFacet();
00424     QhullFacetSet fs2= f2.neighborFacets();
00425     cout << "INFO:   Neighboring facets\n";
00426     cout << fs2 << std::endl;
00427 
00428     QhullRidgeSet rs= f.ridges();
00429     cout << "INFO:   Ridges for a facet\n";
00430     cout << rs << std::endl;
00431 }//t_io
00432 
00433 }//namespace orgQhull
00434 
00435 #include "moc/QhullSet_test.moc"
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50