QhullVertexSet_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/QhullVertexSet_test.cpp#2 $$Change: 1342 $
00005 ** $DateTime: 2011/03/07 21:55:47 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 #include <iostream>
00010 #include "../road/RoadTest.h" // FIXUP First for QHULL_USES_QT
00011 
00012 #include "Qhull.h"
00013 #include "QhullError.h"
00014 #include "QhullFacet.h"
00015 #include "QhullFacetSet.h"
00016 
00017 using std::cout;
00018 using std::endl;
00019 using std::ostringstream;
00020 using std::ostream;
00021 using std::string;
00022 
00023 namespace orgQhull {
00024 
00025 class QhullFacetSet_test : public RoadTest
00026 {
00027     Q_OBJECT
00028 
00029 #//Test slots
00030 private slots:
00031     void cleanup();
00032     void t_construct();
00033     void t_convert();
00034     void t_readonly();
00035     void t_foreach();
00036     void t_io();
00037 };//QhullFacetSet_test
00038 
00039 void
00040 add_QhullFacetSet_test()
00041 {
00042     new QhullFacetSet_test();
00043 }
00044 
00045 //Executed after each testcase
00046 void QhullFacetSet_test::
00047 cleanup()
00048 {
00049     RoadTest::cleanup();
00050     UsingQhullLib::checkQhullMemoryEmpty();
00051 }
00052 
00053 void QhullFacetSet_test::
00054 t_construct()
00055 {
00056     RboxPoints rcube("c");
00057     Qhull q(rcube,"QR0");  // rotated unit cube
00058     QhullFacet f= q.firstFacet();
00059     QhullFacetSet fs2= f.neighborFacets();
00060     QVERIFY(!fs2.isEmpty());
00061     QCOMPARE(fs2.count(),4);
00062     QhullFacetSet fs4= fs2; // copy constructor
00063     QVERIFY(fs4==fs2);
00064     QhullFacetSet fs3(q.qhullQh()->facet_mergeset);
00065     QVERIFY(fs3.isEmpty());
00066 }//t_construct
00067 
00068 void QhullFacetSet_test::
00069 t_convert()
00070 {
00071     RboxPoints rcube("c");
00072     Qhull q(rcube,"QR0 QV2");  // rotated unit cube
00073     QhullFacet f= q.firstFacet();
00074     QhullFacetSet fs2= f.neighborFacets();
00075     QVERIFY(!fs2.isSelectAll());
00076     QCOMPARE(fs2.count(),2);
00077     std::vector<QhullFacet> fv= fs2.toStdVector();
00078     QCOMPARE(fv.size(), 2u);
00079     QList<QhullFacet> fv2= fs2.toQList();
00080     QCOMPARE(fv2.size(), 2);
00081     fs2.selectAll();
00082     QVERIFY(fs2.isSelectAll());
00083     std::vector<QhullFacet> fv3= fs2.toStdVector();
00084     QCOMPARE(fv3.size(), 4u);
00085     QList<QhullFacet> fv4= fs2.toQList();
00086     QCOMPARE(fv4.size(), 4);
00087 }//t_convert
00088 
00090 void QhullFacetSet_test::
00091 t_readonly()
00092 {
00093     RboxPoints rcube("c");
00094     Qhull q(rcube,"QV0");  // good facets are adjacent to point 0
00095     QhullFacetSet fs= q.firstFacet().neighborFacets();
00096     QVERIFY(!fs.isSelectAll());
00097     QCOMPARE(fs.count(), 2);
00098     fs.selectAll();
00099     QVERIFY(fs.isSelectAll());
00100     QCOMPARE(fs.count(), 4);
00101     fs.selectGood();
00102     QVERIFY(!fs.isSelectAll());
00103     QCOMPARE(fs.count(), 2);
00104     QhullFacet f= fs.first();
00105     QhullFacet f2= fs.last();
00106     fs.selectAll();
00107     QVERIFY(fs.contains(f));
00108     QVERIFY(fs.contains(f2));
00109     QVERIFY(f.isGood());
00110     QVERIFY(!f2.isGood());
00111     fs.selectGood();
00112     QVERIFY(fs.contains(f));
00113     QVERIFY(!fs.contains(f2));
00114 }//t_readonly
00115 
00116 void QhullFacetSet_test::
00117 t_foreach()
00118 {
00119     RboxPoints rcube("c");
00120     // Spot check predicates and accessors.  See QhullLinkedList_test
00121     Qhull q(rcube,"QR0");  // rotated unit cube
00122     QhullFacetSet fs= q.firstFacet().neighborFacets();
00123     QVERIFY(!fs.contains(q.firstFacet()));
00124     QVERIFY(fs.contains(fs.first()));
00125     QhullFacet f= q.firstFacet().next();
00126     if(!fs.contains(f)){
00127         f= f.next();
00128     }
00129     QVERIFY(fs.contains(f));
00130     QCOMPARE(fs.first(), *fs.begin());
00131     QCOMPARE(*(fs.end()-1), fs.last());
00132 }//t_foreach
00133 
00134 void QhullFacetSet_test::
00135 t_io()
00136 {
00137     RboxPoints rcube("c");
00138     {
00139         Qhull q(rcube,"QR0 QV0");   // good facets are adjacent to point 0
00140         QhullFacetSet fs= q.firstFacet().neighborFacets();
00141         ostringstream os;
00142         os << fs.print(q.runId(), "Neighbors of first facet with point 0");
00143         os << fs.printIdentifiers("\nFacet identifiers: ");
00144         cout<< os.str();
00145         QString facets= QString::fromStdString(os.str());
00146         QCOMPARE(facets.count(QRegExp(" f[0-9]")), 2+13*2);
00147     }
00148 }//t_io
00149 
00150 //FIXUP -- Move conditional, QhullFacetSet code to QhullFacetSet.cpp
00151 #ifndef QHULL_NO_STL
00152 std::vector<QhullFacet> QhullFacetSet::
00153 toStdVector() const
00154 {
00155     QhullSetIterator<QhullFacet> i(*this);
00156     std::vector<QhullFacet> vs;
00157     while(i.hasNext()){
00158         QhullFacet f= i.next();
00159         if(isSelectAll() || f.isGood()){
00160             vs.push_back(f);
00161         }
00162     }
00163     return vs;
00164 }//toStdVector
00165 #endif //QHULL_NO_STL
00166 
00167 #ifdef QHULL_USES_QT
00168 QList<QhullFacet> QhullFacetSet::
00169 toQList() const
00170 {
00171     QhullSetIterator<QhullFacet> i(*this);
00172     QList<QhullFacet> vs;
00173     while(i.hasNext()){
00174         QhullFacet f= i.next();
00175         if(isSelectAll() || f.isGood()){
00176             vs.append(f);
00177         }
00178     }
00179     return vs;
00180 }//toQList
00181 #endif //QHULL_USES_QT
00182 
00183 }//orgQhull
00184 
00185 #include "moc/QhullFacetSet_test.moc"


libqhull-ours
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:11