QhullFacet_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/QhullFacet_test.cpp#4 $$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 "QhullFacet.h"
00014 #include "QhullError.h"
00015 #include "Coordinates.h"
00016 #include "RboxPoints.h"
00017 #include "QhullFacetList.h"
00018 #include "QhullFacetSet.h"
00019 #include "QhullPointSet.h"
00020 #include "QhullRidge.h"
00021 #include "Qhull.h"
00022 
00023 using std::cout;
00024 using std::endl;
00025 using std::ostringstream;
00026 using std::ostream;
00027 using std::string;
00028 
00029 namespace orgQhull {
00030 
00031 class QhullFacet_test : public RoadTest
00032 {
00033     Q_OBJECT
00034 
00035 #//Test slots
00036 private slots:
00037     void cleanup();
00038     void t_constructConvert();
00039     void t_getSet();
00040     void t_value();
00041     void t_foreach();
00042     void t_io();
00043 };//QhullFacet_test
00044 
00045 void
00046 add_QhullFacet_test()
00047 {
00048     new QhullFacet_test();
00049 }
00050 
00051 //Executed after each testcase
00052 void QhullFacet_test::
00053 cleanup()
00054 {
00055     UsingLibQhull::checkQhullMemoryEmpty();
00056     RoadTest::cleanup();
00057 }
00058 
00059 void QhullFacet_test::
00060 t_constructConvert()
00061 {
00062     // Qhull.runQhull() constructs QhullFacets as facetT
00063     QhullFacet f;
00064     QVERIFY(!f.isDefined());
00065     QCOMPARE(f.dimension(),0);
00066     RboxPoints rcube("c");
00067     Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00068     QhullFacet f2(q.beginFacet());
00069     QCOMPARE(f2.dimension(),3);
00070     f= f2; // copy assignment
00071     QVERIFY(f.isDefined());
00072     QCOMPARE(f.dimension(),3);
00073     QhullFacet f5= f2;
00074     QVERIFY(f5==f2);
00075     QVERIFY(f5==f);
00076     QhullFacet f3= f2.getFacetT();
00077     QCOMPARE(f,f3);
00078     QhullFacet f4= f2.getBaseT();
00079     QCOMPARE(f,f4);
00080 }//t_constructConvert
00081 
00082 void QhullFacet_test::
00083 t_getSet()
00084 {
00085     RboxPoints rcube("c");
00086     {
00087         Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00088         QCOMPARE(q.facetCount(), 12);
00089         QCOMPARE(q.vertexCount(), 8);
00090         QhullFacetListIterator i(q.facetList());
00091         while(i.hasNext()){
00092             const QhullFacet f= i.next();
00093             cout << f.id() << endl;
00094             QCOMPARE(f.dimension(),3);
00095             QVERIFY(f.id()>0 && f.id()<=39);
00096             QVERIFY(f.isDefined());
00097             if(i.hasNext()){
00098                 QCOMPARE(f.next(), i.peekNext());
00099                 QVERIFY(f.next()!=f);
00100             }
00101             QVERIFY(i.hasPrevious());
00102             QCOMPARE(f, i.peekPrevious());
00103         }
00104         QhullFacetListIterator i2(i);
00105         QEXPECT_FAIL("", "ListIterator copy constructor not reset to BOT", Continue);
00106         QVERIFY(!i2.hasPrevious());
00107 
00108         // test tricoplanarOwner
00109         QhullFacet facet = q.beginFacet();
00110         QhullFacet tricoplanarOwner = facet.tricoplanarOwner();
00111         int tricoplanarCount= 0;
00112         i.toFront();
00113         while(i.hasNext()){
00114             const QhullFacet f= i.next();
00115             if(f.tricoplanarOwner()==tricoplanarOwner){
00116                 tricoplanarCount++;
00117             }
00118         }
00119         QCOMPARE(tricoplanarCount, 2);
00120         int tricoplanarCount2= 0;
00121         foreach (QhullFacet f, q.facetList()){  // Qt only
00122             QhullHyperplane h= f.hyperplane();
00123             cout << "Hyperplane: " << h << endl;
00124             QCOMPARE(h.count(), 3);
00125             QCOMPARE(h.offset(), -0.5);
00126             double n= h.norm();
00127             QCOMPARE(n, 1.0);
00128             QhullHyperplane hi= f.innerplane(q.runId());
00129             QCOMPARE(hi.count(), 3);
00130             double innerOffset= hi.offset()+0.5;
00131             cout << "InnerPlane: " << hi << "innerOffset+0.5 " << innerOffset << endl;
00132             QVERIFY(innerOffset >= 0.0);
00133             QhullHyperplane ho= f.outerplane(q.runId());
00134             QCOMPARE(ho.count(), 3);
00135             double outerOffset= ho.offset()+0.5;
00136             cout << "OuterPlane: " << ho << "outerOffset+0.5 " << outerOffset << endl;
00137             QVERIFY(outerOffset <= 0.0);
00138             QVERIFY(outerOffset-innerOffset < 1e-7);
00139             for(int k= 0; k<3; k++){
00140                 QVERIFY(ho[k]==hi[k]);
00141                 QVERIFY(ho[k]==h[k]);
00142             }
00143             QhullPoint center= f.getCenter(q.runId());
00144             cout << "Center: " << center << endl;
00145             double d= f.distance(center);
00146             QVERIFY(d < innerOffset-outerOffset);
00147             QhullPoint center2= f.getCenter(q.runId(), qh_PRINTcentrums);
00148             QCOMPARE(center, center2);
00149             if(f.tricoplanarOwner()==tricoplanarOwner){
00150                 tricoplanarCount2++;
00151             }
00152         }
00153         QCOMPARE(tricoplanarCount2, 2);
00154         Qhull q2(rcube,"d Qz Qt QR0");  // 3-d triangulation of Delaunay triangulation (the cube)
00155         QhullFacet f2= q2.firstFacet();
00156         QhullPoint center3= f2.getCenter(q.runId(), qh_PRINTtriangles);
00157         QCOMPARE(center3.dimension(), 3);
00158         QhullPoint center4= f2.getCenter(q.runId());
00159         QCOMPARE(center4.dimension(), 3);
00160         for(int k= 0; k<3; k++){
00161             QVERIFY(center4[k]==center3[k]);
00162         }
00163         Qhull q3(rcube,"v Qz QR0");  // Voronoi diagram of a cube (one vertex)
00164 
00165         UsingLibQhull::setGlobalDistanceEpsilon(1e-12); // Voronoi vertices are not necessarily within distance episilon
00166         foreach(QhullFacet f, q3.facetList()){ //Qt only
00167             if(f.isGood()){
00168                 QhullPoint p= f.voronoiVertex(q3.runId());
00169                 cout << p.print(q3.runId(), "Voronoi vertex: ")
00170                     << " DistanceEpsilon " << UsingLibQhull::globalDistanceEpsilon() << endl;
00171                 QCOMPARE(p, q3.origin());
00172             }
00173         }
00174     }
00175 }//t_getSet
00176 
00177 void QhullFacet_test::
00178 t_value()
00179 {
00180     RboxPoints rcube("c");
00181     {
00182         Qhull q(rcube, "");
00183         coordT c[]= {0.0, 0.0, 0.0};
00184         foreach (QhullFacet f, q.facetList()){  // Qt only
00185             double d= f.distance(q.origin());
00186             QCOMPARE(d, -0.5);
00187             double d0= f.distance(c);
00188             QCOMPARE(d0, -0.5);
00189             double facetArea= f.facetArea(q.runId());
00190             QCOMPARE(facetArea, 1.0);
00191             #if qh_MAXoutside
00192                 double maxoutside= f.getFacetT()->maxoutside;
00193                 QVERIFY(maxoutside<1e-7);
00194             #endif
00195         }
00196     }
00197 }//t_value
00198 
00199 void QhullFacet_test::
00200 t_foreach()
00201 {
00202     RboxPoints rcube("c W0 300");  // cube plus 300 points on its surface
00203     {
00204         Qhull q(rcube, "QR0 Qc"); // keep coplanars, thick facet, and rotate the cube
00205         int coplanarCount= 0;
00206         foreach(const QhullFacet f, q.facetList()){
00207             QhullPointSet coplanars= f.coplanarPoints();
00208             coplanarCount += coplanars.count();
00209             QhullFacetSet neighbors= f.neighborFacets();
00210             QCOMPARE(neighbors.count(), 4);
00211             QhullPointSet outsides= f.outsidePoints();
00212             QCOMPARE(outsides.count(), 0);
00213             QhullRidgeSet ridges= f.ridges();
00214             QCOMPARE(ridges.count(), 4);
00215             QhullVertexSet vertices= f.vertices();
00216             QCOMPARE(vertices.count(), 4);
00217             int ridgeCount= 0;
00218             QhullRidge r= ridges.first();
00219             for(int r0= r.id(); ridgeCount==0 || r.id()!=r0; r= r.nextRidge3d(f)){
00220                 ++ridgeCount;
00221                 if(!r.hasNextRidge3d(f)){
00222                     QFAIL("Unexpected simplicial facet.  They only have ridges to non-simplicial neighbors.");
00223                 }
00224             }
00225             QCOMPARE(ridgeCount, 4);
00226         }
00227         QCOMPARE(coplanarCount, 300);
00228     }
00229 }//t_foreach
00230 
00231 void QhullFacet_test::
00232 t_io()
00233 {
00234     RboxPoints rcube("c");
00235     {
00236         Qhull q(rcube, "");
00237         QhullFacet f= q.beginFacet();
00238         cout << f;
00239         ostringstream os;
00240         os << f.printHeader(q.runId());
00241         os << f.printFlags("    - flags:");
00242         os << f.printCenter(q.runId(), qh_PRINTfacets, "    - center:");
00243         os << f.printRidges(q.runId());
00244         cout << os.str();
00245         ostringstream os2;
00246         os2 << f.print(q.runId());  // invokes print*()
00247         QString facetString2= QString::fromStdString(os2.str());
00248         facetString2.replace(QRegExp("\\s\\s+"), " ");
00249         ostringstream os3;
00250         q.setOutputStream(&os3);
00251         q.outputQhull("f");
00252         QString facetsString= QString::fromStdString(os3.str());
00253         QString facetString3= facetsString.mid(facetsString.indexOf("- f1\n"));
00254         facetString3= facetString3.left(facetString3.indexOf("\n- f")+1);
00255         facetString3.replace(QRegExp("\\s\\s+"), " ");
00256         QCOMPARE(facetString2, facetString3);
00257     }
00258 }//t_io
00259 
00260 // toQhullFacet is static_cast only
00261 
00262 }//orgQhull
00263 
00264 #include "moc/QhullFacet_test.moc"


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