QhullRidge_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/QhullRidge_test.cpp#3 $$Change: 1352 $
00005 ** $DateTime: 2011/03/27 18:16:41 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 //pre-compiled headers
00010 #include <iostream>
00011 #include "../road/RoadTest.h"
00012 
00013 #include "QhullRidge.h"
00014 #include "QhullError.h"
00015 #include "RboxPoints.h"
00016 #include "QhullFacet.h"
00017 #include "Qhull.h"
00018 
00019 using std::cout;
00020 using std::endl;
00021 using std::ostringstream;
00022 using std::ostream;
00023 using std::string;
00024 
00025 namespace orgQhull {
00026 
00027 class QhullRidge_test : public RoadTest
00028 {
00029     Q_OBJECT
00030 
00031 #//Test slots
00032 private slots:
00033     void cleanup();
00034     void t_construct();
00035     void t_getSet();
00036     void t_foreach();
00037     void t_io();
00038 };//QhullRidge_test
00039 
00040 void
00041 add_QhullRidge_test()
00042 {
00043     new QhullRidge_test();
00044 }
00045 
00046 //Executed after each testcase
00047 void QhullRidge_test::
00048 cleanup()
00049 {
00050     UsingLibQhull::checkQhullMemoryEmpty();
00051     RoadTest::cleanup();
00052 }
00053 
00054 void QhullRidge_test::
00055 t_construct()
00056 {
00057     // Qhull.runQhull() constructs QhullFacets as facetT
00058     QhullRidge r;
00059     QVERIFY(!r.isDefined());
00060     QCOMPARE(r.dimension(),0);
00061     RboxPoints rcube("c");
00062     Qhull q(rcube,"QR0");  // triangulation of rotated unit cube
00063     QhullFacet f(q.firstFacet());
00064     QhullRidgeSet rs(f.ridges());
00065     QVERIFY(!rs.isEmpty()); // Simplicial facets do not have ridges()
00066     QhullRidge r2(rs.first());
00067     QCOMPARE(r2.dimension(), 2); // One dimension lower than the facet
00068     r= r2;
00069     QVERIFY(r.isDefined());
00070     QCOMPARE(r.dimension(), 2);
00071     QhullRidge r3= r2.getRidgeT();
00072     QCOMPARE(r,r3);
00073     QhullRidge r4= r2.getBaseT();
00074     QCOMPARE(r,r4);
00075     QhullRidge r5= r2; // copy constructor
00076     QVERIFY(r5==r2);
00077     QVERIFY(r5==r);
00078 }//t_construct
00079 
00080 void QhullRidge_test::
00081 t_getSet()
00082 {
00083     RboxPoints rcube("c");
00084     {
00085         Qhull q(rcube,"QR0");  // triangulation of rotated unit cube
00086         QCOMPARE(q.facetCount(), 6);
00087         QCOMPARE(q.vertexCount(), 8);
00088         QhullFacet f(q.firstFacet());
00089         QhullRidgeSet rs= f.ridges();
00090         QhullRidgeSetIterator i(rs);
00091         while(i.hasNext()){
00092             const QhullRidge r= i.next();
00093             cout << r.id() << endl;
00094             QVERIFY(r.bottomFacet()!=r.topFacet());
00095             QCOMPARE(r.dimension(), 2); // Ridge one-dimension less than facet
00096             QVERIFY(r.id()>=0 && r.id()<9*27);
00097             QVERIFY(r.isDefined());
00098             QVERIFY(r==r);
00099             QVERIFY(r==i.peekPrevious());
00100             QCOMPARE(r.otherFacet(r.bottomFacet()),r.topFacet());
00101             QCOMPARE(r.otherFacet(r.topFacet()),r.bottomFacet());
00102         }
00103         QhullRidgeSetIterator i2(i);
00104         QEXPECT_FAIL("", "SetIterator copy constructor not reset to BOT", Continue);
00105         QVERIFY(!i2.hasPrevious());
00106     }
00107 }//t_getSet
00108 
00109 void QhullRidge_test::
00110 t_foreach()
00111 {
00112     RboxPoints rcube("c");  // cube
00113     {
00114         Qhull q(rcube, "QR0"); // rotated cube
00115         QhullFacet f(q.firstFacet());
00116         foreach (QhullRidge r, f.ridges()){  // Qt only
00117             QhullVertexSet vs= r.vertices();
00118             QCOMPARE(vs.count(), 2);
00119             foreach (QhullVertex v, vs){  // Qt only
00120                 QVERIFY(f.vertices().contains(v));
00121             }
00122         }
00123         QhullRidgeSet rs= f.ridges();
00124         QhullRidge r= rs.first();
00125         QhullRidge r2= r;
00126         QList<QhullVertex> vs;
00127         int count= 0;
00128         while(!count || r2!=r){
00129             ++count;
00130             QhullVertex v;
00131             QVERIFY2(r2.hasNextRidge3d(f),"A cube should only have non-simplicial facets.");
00132             QhullRidge r3= r2.nextRidge3d(f, &v);
00133             QVERIFY(!vs.contains(v));
00134             vs << v;
00135             r2= r2.nextRidge3d(f);
00136             QCOMPARE(r3, r2);
00137         }
00138         QCOMPARE(vs.count(), rs.count());
00139         QCOMPARE(count, rs.count());
00140     }
00141 }//t_foreach
00142 
00143 void QhullRidge_test::
00144 t_io()
00145 {
00146     RboxPoints rcube("c");
00147     {
00148         Qhull q(rcube, "");
00149         QhullFacet f(q.firstFacet());
00150         QhullRidgeSet rs= f.ridges();
00151         QhullRidge r= rs.first();
00152         ostringstream os;
00153         os << "Ridges Without runId\n" << rs << "Ridge\n" << r;
00154         os << "Ridge with runId\n" << r.print(q.runId());
00155         cout << os.str();
00156         QString s= QString::fromStdString(os.str());
00157         QCOMPARE(s.count(" r"), 6+2);
00158     }
00159 }//t_io
00160 
00161 }//orgQhull
00162 
00163 #include "moc/QhullRidge_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