QhullPointSet_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (p) 2009-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/QhullPointSet_test.cpp#4 $$Change: 1382 $
00005 ** $DateTime: 2011/05/14 10:45:42 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 //pre-compiled header
00010 #include <iostream>
00011 #include "../road/RoadTest.h" // QT_VERSION
00012 
00013 #include "QhullPointSet.h"
00014 #include "RboxPoints.h"
00015 #include "QhullPoint.h"
00016 #include "QhullFacet.h"
00017 #include "QhullFacetList.h"
00018 #include "Qhull.h"
00019 
00020 using std::cout;
00021 using std::endl;
00022 using std::ostringstream;
00023 
00024 namespace orgQhull {
00025 
00026 class QhullPointSet_test : public RoadTest
00027 {
00028     Q_OBJECT
00029 
00030 #//Test slots
00031 private slots:
00032     void cleanup();
00033     void t_construct();
00034     void t_convert();
00035     void t_element();
00036     void t_iterator();
00037     void t_const_iterator();
00038     void t_search();
00039     void t_pointset_iterator();
00040     void t_io();
00041 };//QhullPointSet_test
00042 
00043 void
00044 add_QhullPointSet_test()
00045 {
00046     new QhullPointSet_test();
00047 }
00048 
00049 //Executed after each testcase
00050 void QhullPointSet_test::
00051 cleanup()
00052 {
00053     UsingLibQhull::checkQhullMemoryEmpty();
00054     RoadTest::cleanup();
00055 }
00056 
00057 void QhullPointSet_test::
00058 t_construct()
00059 {
00060     RboxPoints rcube("c W0 1000");
00061     Qhull q(rcube,"Qc");  // cube with 1000 coplanar points
00062     int coplanarCount= 0;
00063     foreach(QhullFacet f, q.facetList()){
00064         QhullPointSet ps(q.dimension(), f.getFacetT()->outsideset);
00065         QCOMPARE(ps.dimension(), 3);
00066         QVERIFY(ps.isEmpty());
00067         QVERIFY(ps.empty());
00068         QCOMPARE(ps.count(), 0);
00069         QCOMPARE(ps.size(), 0u);
00070         QhullPointSet ps2(q.dimension(), f.getFacetT()->coplanarset);
00071         QCOMPARE(ps2.dimension(), 3);
00072         QVERIFY(!ps2.isEmpty());
00073         QVERIFY(!ps2.empty());
00074         coplanarCount += ps2.count();
00075         QCOMPARE(ps2.count(), (int)ps2.size());
00076         QhullPointSet ps3(ps2);
00077         QCOMPARE(ps3.dimension(), 3);
00078         QVERIFY(!ps3.isEmpty());
00079         QCOMPARE(ps3.count(), ps2.count());
00080         QVERIFY(ps3==ps2);
00081         QVERIFY(ps3!=ps);
00082         // ps4= ps3; //compiler error
00083     }
00084     QCOMPARE(coplanarCount, 1000);
00085 }//t_construct
00086 
00087 void QhullPointSet_test::
00088 t_convert()
00089 {
00090     RboxPoints rcube("c W0 1000");
00091     Qhull q(rcube,"Qc");  // cube with 1000 coplanar points
00092     QhullFacet f= q.firstFacet();
00093     QhullPointSet ps= f.coplanarPoints();
00094     QCOMPARE(ps.dimension(), 3);
00095     QVERIFY(ps.count()>=1);   // Sometimes no coplanar points
00096     std::vector<QhullPoint> vs= ps.toStdVector();
00097     QCOMPARE(vs.size(), ps.size());
00098     QhullPoint p= ps[0];
00099     QhullPoint p2= vs[0];
00100     QCOMPARE(p, p2);
00101     QList<QhullPoint> qs= ps.toQList();
00102     QCOMPARE(qs.size(), static_cast<int>(ps.size()));
00103     QhullPoint p3= qs[0];
00104     QCOMPARE(p3, p);
00105 }//t_convert
00106 
00107 // readonly tested in t_construct
00108 //   dimension, empty, isEmpty, ==, !=, size
00109 
00110 void QhullPointSet_test::
00111 t_element()
00112 {
00113     RboxPoints rcube("c W0 1000");
00114     Qhull q(rcube,"Qc");  // cube with 1000 coplanar points
00115     QhullFacet f= q.firstFacet();
00116     QhullPointSet ps= f.coplanarPoints();
00117     QVERIFY(ps.count()>=3);  // Sometimes no coplanar points
00118     QhullPoint p= ps[0];
00119     QCOMPARE(p, ps[0]);
00120     QhullPoint p2= ps[ps.count()-1];
00121     QCOMPARE(ps.at(1), ps[1]);
00122     QCOMPARE(ps.first(), p);
00123     QCOMPARE(ps.front(), ps.first());
00124     QCOMPARE(ps.last(), p2);
00125     QCOMPARE(ps.back(), ps.last());
00126     QhullPoint p8;
00127     QCOMPARE(ps.value(2), ps[2]);
00128     QCOMPARE(ps.value(-1), p8);
00129     QCOMPARE(ps.value(ps.count()), p8);
00130     QCOMPARE(ps.value(ps.count(), p), p);
00131     QVERIFY(ps.value(1, p)!=p);
00132     QhullPointSet ps8= f.coplanarPoints();
00133     QhullPointSet::Iterator i= ps8.begin();
00134     foreach(QhullPoint p9, ps){  // Qt only
00135         QCOMPARE(p9.dimension(), 3);
00136         QCOMPARE(p9, *i++);
00137     }
00138 }//t_element
00139 
00140 void QhullPointSet_test::
00141 t_iterator()
00142 {
00143     RboxPoints rcube("c W0 1000");
00144     Qhull q(rcube,"Qc");  // cube with 1000 coplanar points
00145     QhullFacet f= q.firstFacet();
00146     QhullPointSet ps= f.coplanarPoints();
00147     QVERIFY(ps.count()>=3);  // Sometimes no coplanar points
00148     QhullPointSet::Iterator i= ps.begin();
00149     QhullPointSet::iterator i2= ps.begin();
00150     QVERIFY(i==i2);
00151     QVERIFY(i>=i2);
00152     QVERIFY(i<=i2);
00153     i= ps.begin();
00154     QVERIFY(i==i2);
00155     i2= ps.end();
00156     QVERIFY(i!=i2);
00157     QhullPoint p= *i;
00158     QCOMPARE(p.dimension(), ps.dimension());
00159     QCOMPARE(p, ps[0]);
00160     i2--;
00161     QhullPoint p2= *i2;
00162     QCOMPARE(p2.dimension(), ps.dimension());
00163     QCOMPARE(p2, ps.last());
00164     QhullPointSet::Iterator i5(i2);
00165     QCOMPARE(*i2, *i5);
00166     QhullPointSet::Iterator i3= i+1;
00167     QVERIFY(i!=i3);
00168     QCOMPARE(i[1], *i3);
00169     (i3= i)++;
00170     QCOMPARE((*i3)[0], ps[1][0]);
00171     QCOMPARE((*i3).dimension(), 3);
00172 
00173     QVERIFY(i==i);
00174     QVERIFY(i!=i3);
00175     QVERIFY(i<i3);
00176     QVERIFY(i<=i3);
00177     QVERIFY(i3>i);
00178     QVERIFY(i3>=i);
00179 
00180     QhullPointSet::ConstIterator i4= ps.begin();
00181     QVERIFY(i==i4); // iterator COMP const_iterator
00182     QVERIFY(i<=i4);
00183     QVERIFY(i>=i4);
00184     QVERIFY(i4==i); // const_iterator COMP iterator
00185     QVERIFY(i4<=i);
00186     QVERIFY(i4>=i);
00187     QVERIFY(i>=i4);
00188     QVERIFY(i4<=i);
00189     QVERIFY(i2!=i4);
00190     QVERIFY(i2>i4);
00191     QVERIFY(i2>=i4);
00192     QVERIFY(i4!=i2);
00193     QVERIFY(i4<i2);
00194     QVERIFY(i4<=i2);
00195     ++i4;
00196     QVERIFY(i<i4);
00197     QVERIFY(i<=i4);
00198     QVERIFY(i4>i);
00199     QVERIFY(i4>=i);
00200 
00201     i= ps.begin();
00202     i2= ps.begin();
00203     QCOMPARE(i, i2++);
00204     QCOMPARE(*i2, ps[1]);
00205     QCOMPARE(++i, i2);
00206     QCOMPARE(i, i2--);
00207     QCOMPARE(i2, ps.begin());
00208     QCOMPARE(--i, i2);
00209     QCOMPARE(i2+=ps.count(), ps.end());
00210     QCOMPARE(i2-=ps.count(), ps.begin());
00211     QCOMPARE(i2+0, ps.begin());
00212     QCOMPARE(i2+ps.count(), ps.end());
00213     i2 += ps.count();
00214     i= i2-0;
00215     QCOMPARE(i, i2);
00216     i= i2-ps.count();
00217     QCOMPARE(i, ps.begin());
00218     QCOMPARE(i2-i, ps.count());
00219 
00220     //ps.begin end tested above
00221 
00222     // QhullPointSet is const-only
00223 }//t_iterator
00224 
00225 void QhullPointSet_test::
00226 t_const_iterator()
00227 {
00228     RboxPoints rcube("c W0 1000");
00229     Qhull q(rcube,"Qc");  // cube with 1000 coplanar points
00230     QhullFacet f= q.firstFacet();
00231     QhullPointSet ps= f.coplanarPoints();
00232     QVERIFY(ps.count()>=3);  // Sometimes no coplanar points
00233     QhullPointSet::ConstIterator i= ps.begin();
00234     QhullPointSet::const_iterator i2= ps.begin();
00235     QVERIFY(i==i2);
00236     QVERIFY(i>=i2);
00237     QVERIFY(i<=i2);
00238 
00239     // See t_iterator for const_iterator COMP iterator
00240 
00241     i= ps.begin();
00242     QVERIFY(i==i2);
00243     i2= ps.end();
00244     QVERIFY(i!=i2);
00245     QhullPoint p= *i; // QhullPoint is the base class for QhullPointSet::iterator
00246     QCOMPARE(p.dimension(), ps.dimension());
00247     QCOMPARE(p, ps[0]);
00248     i2--;
00249     QhullPoint p2= *i2;
00250     QCOMPARE(p2.dimension(), ps.dimension());
00251     QCOMPARE(p2, ps.last());
00252     QhullPointSet::ConstIterator i5(i2);
00253     QCOMPARE(*i2, *i5);
00254 
00255 
00256     QhullPointSet::ConstIterator i3= i+1;
00257     QVERIFY(i!=i3);
00258     QCOMPARE(i[1], *i3);
00259 
00260     QVERIFY(i==i);
00261     QVERIFY(i!=i3);
00262     QVERIFY(i<i3);
00263     QVERIFY(i<=i3);
00264     QVERIFY(i3>i);
00265     QVERIFY(i3>=i);
00266 
00267     // QhullPointSet is const-only
00268 }//t_const_iterator
00269 
00270 
00271 void QhullPointSet_test::
00272 t_search()
00273 {
00274     RboxPoints rcube("c W0 1000");
00275     Qhull q(rcube,"Qc");  // cube with 1000 coplanar points
00276     QhullFacet f= q.firstFacet();
00277     QhullPointSet ps= f.coplanarPoints();
00278     QVERIFY(ps.count()>=3);  // Sometimes no coplanar points
00279     QhullPoint p= ps.first();
00280     QhullPoint p2= ps.last();
00281     QVERIFY(ps.contains(p));
00282     QVERIFY(ps.contains(p2));
00283     QVERIFY(p!=p2);
00284     QhullPoint p3= ps[2];
00285     QVERIFY(ps.contains(p3));
00286     QVERIFY(p!=p3);
00287     QhullPoint p4;
00288     QCOMPARE(ps.indexOf(p), 0);
00289     QCOMPARE(ps.indexOf(p2), ps.count()-1);
00290     QCOMPARE(ps.indexOf(p3), 2);
00291     QCOMPARE(ps.indexOf(p4), -1);
00292     QCOMPARE(ps.lastIndexOf(p), 0);
00293     QCOMPARE(ps.lastIndexOf(p2), ps.count()-1);
00294     QCOMPARE(ps.lastIndexOf(p3), 2);
00295     QCOMPARE(ps.lastIndexOf(p4), -1);
00296 }//t_search
00297 
00298 void QhullPointSet_test::
00299 t_pointset_iterator()
00300 {
00301     RboxPoints rcube("c W0 1000");
00302     Qhull q(rcube,"Qc");  // cube with 1000 coplanar points
00303     QhullFacet f= q.firstFacet();
00304     QhullPointSet ps2= f.outsidePoints();
00305     QVERIFY(ps2.count()==0); // No outside points after constructing the convex hull
00306     QhullPointSetIterator i2= ps2;
00307     QVERIFY(!i2.hasNext());
00308     QVERIFY(!i2.hasPrevious());
00309     i2.toBack();
00310     QVERIFY(!i2.hasNext());
00311     QVERIFY(!i2.hasPrevious());
00312 
00313     QhullPointSet ps= f.coplanarPoints();
00314     QVERIFY(ps.count()>=3);  // Sometimes no coplanar points
00315     QhullPointSetIterator i(ps);
00316     i2= ps;
00317     QVERIFY(i2.hasNext());
00318     QVERIFY(!i2.hasPrevious());
00319     QVERIFY(i.hasNext());
00320     QVERIFY(!i.hasPrevious());
00321     i2.toBack();
00322     i.toFront();
00323     QVERIFY(!i2.hasNext());
00324     QVERIFY(i2.hasPrevious());
00325     QVERIFY(i.hasNext());
00326     QVERIFY(!i.hasPrevious());
00327 
00328     QhullPoint p= ps[0];
00329     QhullPoint p2(ps[0]);
00330     QCOMPARE(p, p2);
00331     QVERIFY(p==p2);
00332     QhullPoint p3(ps.last());
00333  // p2[0]= 0.0;
00334     QVERIFY(p==p2);
00335     QCOMPARE(i2.peekPrevious(), p3);
00336     QCOMPARE(i2.previous(), p3);
00337     QCOMPARE(i2.previous(), ps[ps.count()-2]);
00338     QVERIFY(i2.hasPrevious());
00339     QCOMPARE(i.peekNext(), p);
00340     // i.peekNext()= 1.0; // compiler error
00341     QCOMPARE(i.next(), p);
00342     QhullPoint p4= i.peekNext();
00343     QVERIFY(p4!=p3);
00344     QCOMPARE(i.next(), p4);
00345     QVERIFY(i.hasNext());
00346     i.toFront();
00347     QCOMPARE(i.next(), p);
00348 }//t_pointset_iterator
00349 
00350 void QhullPointSet_test::
00351 t_io()
00352 {
00353     ostringstream os;
00354     RboxPoints rcube("c W0 120");
00355     Qhull q(rcube,"Qc");  // cube with 100 coplanar points
00356     QhullFacet f= q.firstFacet();
00357     QhullPointSet ps= f.coplanarPoints();
00358     QVERIFY(ps.count()>=3);  // Sometimes no coplanar points
00359     os << "QhullPointSet from coplanarPoints\n" << ps << endl;
00360     os << "\nRunId\n" << ps.print(q.runId());
00361     os << ps.print(q.runId(), "\nRunId w/ message\n");
00362     cout << os.str();
00363     QString s= QString::fromStdString(os.str());
00364     QCOMPARE(s.count("p"), 3*ps.count()+1);
00365     // QCOMPARE(s.count(QRegExp("f\\d")), 3*7 + 13*3*2);
00366 }//t_io
00367 
00368 }//orgQhull
00369 
00370 #include "moc/QhullPointSet_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