Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include "../road/RoadTest.h"
00012
00013 #include "QhullFacetSet.h"
00014 #include "QhullError.h"
00015 #include "QhullFacet.h"
00016 #include "Qhull.h"
00017
00018 using std::cout;
00019 using std::endl;
00020 using std::ostringstream;
00021 using std::ostream;
00022 using std::string;
00023
00024 namespace orgQhull {
00025
00026 class QhullFacetSet_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_readonly();
00036 void t_foreach();
00037 void t_io();
00038 };
00039
00040 void
00041 add_QhullFacetSet_test()
00042 {
00043 new QhullFacetSet_test();
00044 }
00045
00046
00047 void QhullFacetSet_test::
00048 cleanup()
00049 {
00050 RoadTest::cleanup();
00051 UsingLibQhull::checkQhullMemoryEmpty();
00052 }
00053
00054 void QhullFacetSet_test::
00055 t_construct()
00056 {
00057 RboxPoints rcube("c");
00058 Qhull q(rcube,"QR0");
00059 QhullFacet f= q.firstFacet();
00060 QhullFacetSet fs2= f.neighborFacets();
00061 QVERIFY(!fs2.isEmpty());
00062 QCOMPARE(fs2.count(),4);
00063 QhullFacetSet fs4= fs2;
00064 QVERIFY(fs4==fs2);
00065 QhullFacetSet fs3(q.qhullQh()->facet_mergeset);
00066 QVERIFY(fs3.isEmpty());
00067 }
00068
00069 void QhullFacetSet_test::
00070 t_convert()
00071 {
00072 RboxPoints rcube("c");
00073 Qhull q2(rcube,"QR0 QV2");
00074 QhullFacet f2= q2.firstFacet();
00075 QhullFacetSet fs2= f2.neighborFacets();
00076 QVERIFY(!fs2.isSelectAll());
00077 QCOMPARE(fs2.count(),2);
00078 std::vector<QhullFacet> fv= fs2.toStdVector();
00079 QCOMPARE(fv.size(), 2u);
00080 QList<QhullFacet> fv2= fs2.toQList();
00081 QCOMPARE(fv2.size(), 2);
00082 fs2.selectAll();
00083 QVERIFY(fs2.isSelectAll());
00084 std::vector<QhullFacet> fv3= fs2.toStdVector();
00085 QCOMPARE(fv3.size(), 4u);
00086 QList<QhullFacet> fv4= fs2.toQList();
00087 QCOMPARE(fv4.size(), 4);
00088 }
00089
00091 void QhullFacetSet_test::
00092 t_readonly()
00093 {
00094 RboxPoints rcube("c");
00095 Qhull q(rcube,"QV0");
00096 QhullFacetSet fs= q.firstFacet().neighborFacets();
00097 QVERIFY(!fs.isSelectAll());
00098 QCOMPARE(fs.count(), 2);
00099 fs.selectAll();
00100 QVERIFY(fs.isSelectAll());
00101 QCOMPARE(fs.count(), 4);
00102 fs.selectGood();
00103 QVERIFY(!fs.isSelectAll());
00104 QCOMPARE(fs.count(), 2);
00105 QhullFacet f= fs.first();
00106 QhullFacet f2= fs.last();
00107 fs.selectAll();
00108 QVERIFY(fs.contains(f));
00109 QVERIFY(fs.contains(f2));
00110 QVERIFY(f.isGood());
00111 QVERIFY(!f2.isGood());
00112 fs.selectGood();
00113 QVERIFY(fs.contains(f));
00114 QVERIFY(!fs.contains(f2));
00115 }
00116
00117 void QhullFacetSet_test::
00118 t_foreach()
00119 {
00120 RboxPoints rcube("c");
00121
00122 Qhull q(rcube,"QR0");
00123 QhullFacetSet fs= q.firstFacet().neighborFacets();
00124 QVERIFY(!fs.contains(q.firstFacet()));
00125 QVERIFY(fs.contains(fs.first()));
00126 QhullFacet f= q.firstFacet().next();
00127 if(!fs.contains(f)){
00128 f= f.next();
00129 }
00130 QVERIFY(fs.contains(f));
00131 QCOMPARE(fs.first(), *fs.begin());
00132 QCOMPARE(*(fs.end()-1), fs.last());
00133 }
00134
00135 void QhullFacetSet_test::
00136 t_io()
00137 {
00138 RboxPoints rcube("c");
00139 {
00140 Qhull q(rcube,"QR0 QV0");
00141 QhullFacetSet fs= q.firstFacet().neighborFacets();
00142 ostringstream os;
00143 os << fs.print(q.runId(), "Neighbors of first facet with point 0");
00144 os << fs.printIdentifiers("\nFacet identifiers: ");
00145 cout << os.str();
00146 QString facets= QString::fromStdString(os.str());
00147 QCOMPARE(facets.count(QRegExp(" f[0-9]")), 2+13*2);
00148 }
00149 }
00150
00151 }
00152
00153 #include "moc/QhullFacetSet_test.moc"