QhullVertex_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/QhullVertex_test.cpp#4 $$Change: 1382 $
00005 ** $DateTime: 2011/05/14 10:45:42 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 //pre-compiled headers
00009 #include <iostream>
00010 #include "../road/RoadTest.h"
00011 
00012 #include "QhullVertex.h"
00013 #include "Coordinates.h"
00014 #include "QhullError.h"
00015 #include "RboxPoints.h"
00016 #include "QhullFacet.h"
00017 #include "QhullFacetSet.h"
00018 #include "QhullVertexSet.h"
00019 #include "Qhull.h"
00020 
00021 using std::cout;
00022 using std::endl;
00023 using std::ostringstream;
00024 using std::ostream;
00025 using std::string;
00026 
00027 namespace orgQhull {
00028 
00029 class QhullVertex_test : public RoadTest
00030 {
00031     Q_OBJECT
00032 
00033 #//Test slots
00034 private slots:
00035     void cleanup();
00036     void t_constructConvert();
00037     void t_getSet();
00038     void t_foreach();
00039     void t_io();
00040 };//QhullVertex_test
00041 
00042 void
00043 add_QhullVertex_test()
00044 {
00045     new QhullVertex_test();
00046 }
00047 
00048 //Executed after each testcase
00049 void QhullVertex_test::
00050 cleanup()
00051 {
00052     UsingLibQhull::checkQhullMemoryEmpty();
00053     RoadTest::cleanup();
00054 }
00055 
00056 void QhullVertex_test::
00057 t_constructConvert()
00058 {
00059     // Qhull.runQhull() constructs QhullFacets as facetT
00060     QhullVertex v;
00061     QVERIFY(!v.isDefined());
00062     QCOMPARE(v.dimension(),0);
00063     RboxPoints rcube("c");
00064     Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00065     QhullVertex v2(q.beginVertex());
00066     QCOMPARE(v2.dimension(),3);
00067     v= v2;  // copy assignment
00068     QVERIFY(v.isDefined());
00069     QCOMPARE(v.dimension(),3);
00070     QhullVertex v5= v2; // copy constructor
00071     QVERIFY(v5==v2);
00072     QVERIFY(v5==v);
00073     QhullVertex v3= v2.getVertexT();
00074     QCOMPARE(v,v3);
00075     QhullVertex v4= v2.getBaseT();
00076     QCOMPARE(v,v4);
00077 }//t_constructConvert
00078 
00079 void QhullVertex_test::
00080 t_getSet()
00081 {
00082     RboxPoints rcube("c");
00083     {
00084         Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00085         QCOMPARE(q.facetCount(), 12);
00086         QCOMPARE(q.vertexCount(), 8);
00087 
00088         // Also spot-test QhullVertexList.  See QhullLinkedList_test.cpp
00089         QhullVertexList vs= q.vertexList();
00090         QhullVertexListIterator i(vs);
00091         while(i.hasNext()){
00092             const QhullVertex v= i.next();
00093             cout << v.id() << endl;
00094             QCOMPARE(v.dimension(),3);
00095             QVERIFY(v.id()>=0 && v.id()<9);
00096             QVERIFY(v.isDefined());
00097             if(i.hasNext()){
00098                 QCOMPARE(v.next(), i.peekNext());
00099                 QVERIFY(v.next()!=v);
00100                 QVERIFY(v.next().previous()==v);
00101             }
00102             QVERIFY(i.hasPrevious());
00103             QCOMPARE(v, i.peekPrevious());
00104         }
00105         QhullVertexListIterator i2(i);
00106         QEXPECT_FAIL("", "ListIterator copy constructor not reset to BOT", Continue);
00107         QVERIFY(!i2.hasPrevious());
00108 
00109         // test point()
00110         foreach (QhullVertex v, q.vertexList()){  // Qt only
00111             QhullPoint p= v.point();
00112             int j= p.id(q.runId());
00113             cout << "Point " << j << ":\n" << p.print(q.runId()) << endl;
00114             QVERIFY(j>=0 && j<8);
00115         }
00116     }
00117 }//t_getSet
00118 
00119 void QhullVertex_test::
00120 t_foreach()
00121 {
00122     RboxPoints rcube("c W0 300");  // 300 points on surface of cube
00123     {
00124         Qhull q(rcube, "QR0 Qc"); // keep coplanars, thick facet, and rotate the cube
00125         foreach (QhullVertex v, q.vertexList()){  // Qt only
00126             QhullFacetSet fs= v.neighborFacets();
00127             QCOMPARE(fs.count(), 3);
00128             foreach (QhullFacet f, fs){  // Qt only
00129                 QVERIFY(f.vertices().contains(v));
00130             }
00131         }
00132     }
00133 }//t_foreach
00134 
00135 void QhullVertex_test::
00136 t_io()
00137 {
00138     RboxPoints rcube("c");
00139     {
00140         Qhull q(rcube, "");
00141         QhullVertex v= q.beginVertex();
00142         ostringstream os;
00143         os << "Vertex and vertices w/o runId:\n";
00144         os << v;
00145         QhullVertexSet vs= q.firstFacet().vertices();
00146         os << vs;
00147         os << "Vertex and vertices w/ runId:\n";
00148         os << v.print(q.runId());
00149         os << vs.print(q.runId(), "vertices:");
00150         cout << os.str();
00151         QString s= QString::fromStdString(os.str());
00152         QCOMPARE(s.count("(v"), 10);
00153         QCOMPARE(s.count(": f"), 2);
00154     }
00155     RboxPoints r10("10 D3");  // Without QhullVertex::facetNeighbors
00156     {
00157         Qhull q(r10, "");
00158         QhullVertex v= q.beginVertex();
00159         ostringstream os;
00160         os << "\nTry again with simplicial facets.  No neighboring facets listed for vertices.\n";
00161         os << "Vertex and vertices w/o runId:\n";
00162         os << v;
00163         q.defineVertexNeighborFacets();
00164         os << "This time with neighborFacets() defined for all vertices:\n";
00165         os << v;
00166         cout << os.str();
00167         QString s= QString::fromStdString(os.str());
00168         QCOMPARE(s.count(": f"), 1);
00169 
00170         Qhull q2(r10, "v"); // Voronoi diagram
00171         QhullVertex v2= q2.beginVertex();
00172         ostringstream os2;
00173         os2 << "\nTry again with Voronoi diagram of simplicial facets.  Neighboring facets automatically defined for vertices.\n";
00174         os2 << "Vertex and vertices w/o runId:\n";
00175         os2 << v2;
00176         cout << os2.str();
00177         QString s2= QString::fromStdString(os2.str());
00178         QCOMPARE(s2.count(": f"), 1);
00179     }
00180 }//t_io
00181 
00182 }//orgQhull
00183 
00184 #include "moc/QhullVertex_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