~ubuntu-branches/ubuntu/trusty/qhull/trusty-proposed

« back to all changes in this revision

Viewing changes to src/qhulltest/QhullVertex_test.cpp

  • Committer: Package Import Robot
  • Author(s): Barak A. Pearlmutter
  • Date: 2014-02-13 11:09:12 UTC
  • mfrom: (8.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140213110912-ifwyxorlsnnl1ebh
Tags: 2012.1-4
Add convenience link to #include <qhull/qhull.h> to simplify transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (c) 2008-2012 C.B. Barber. All rights reserved.
 
4
** $Id: //main/2011/qhull/src/qhulltest/QhullVertex_test.cpp#6 $$Change: 1490 $
 
5
** $DateTime: 2012/02/19 20:27:01 $$Author: bbarber $
 
6
**
 
7
****************************************************************************/
 
8
//pre-compiled headers
 
9
#include <iostream>
 
10
#include "RoadTest.h"
 
11
 
 
12
#include "QhullVertex.h"
 
13
#include "Coordinates.h"
 
14
#include "QhullError.h"
 
15
#include "RboxPoints.h"
 
16
#include "QhullFacet.h"
 
17
#include "QhullFacetSet.h"
 
18
#include "QhullVertexSet.h"
 
19
#include "Qhull.h"
 
20
 
 
21
using std::cout;
 
22
using std::endl;
 
23
using std::ostringstream;
 
24
using std::ostream;
 
25
using std::string;
 
26
 
 
27
namespace orgQhull {
 
28
 
 
29
class QhullVertex_test : public RoadTest
 
30
{
 
31
    Q_OBJECT
 
32
 
 
33
#//Test slots
 
34
private slots:
 
35
    void cleanup();
 
36
    void t_constructConvert();
 
37
    void t_getSet();
 
38
    void t_foreach();
 
39
    void t_io();
 
40
};//QhullVertex_test
 
41
 
 
42
void
 
43
add_QhullVertex_test()
 
44
{
 
45
    new QhullVertex_test();
 
46
}
 
47
 
 
48
//Executed after each testcase
 
49
void QhullVertex_test::
 
50
cleanup()
 
51
{
 
52
    UsingLibQhull::checkQhullMemoryEmpty();
 
53
    RoadTest::cleanup();
 
54
}
 
55
 
 
56
void QhullVertex_test::
 
57
t_constructConvert()
 
58
{
 
59
    // Qhull.runQhull() constructs QhullFacets as facetT
 
60
    QhullVertex v;
 
61
    QVERIFY(!v.isDefined());
 
62
    QCOMPARE(v.dimension(),0);
 
63
    RboxPoints rcube("c");
 
64
    Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
 
65
    QhullVertex v2(q.beginVertex());
 
66
    QCOMPARE(v2.dimension(),3);
 
67
    v= v2;  // copy assignment
 
68
    QVERIFY(v.isDefined());
 
69
    QCOMPARE(v.dimension(),3);
 
70
    QhullVertex v5= v2; // copy constructor
 
71
    QVERIFY(v5==v2);
 
72
    QVERIFY(v5==v);
 
73
    QhullVertex v3= v2.getVertexT();
 
74
    QCOMPARE(v,v3);
 
75
    QhullVertex v4= v2.getBaseT();
 
76
    QCOMPARE(v,v4);
 
77
}//t_constructConvert
 
78
 
 
79
void QhullVertex_test::
 
80
t_getSet()
 
81
{
 
82
    RboxPoints rcube("c");
 
83
    {
 
84
        Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
 
85
        QCOMPARE(q.facetCount(), 12);
 
86
        QCOMPARE(q.vertexCount(), 8);
 
87
 
 
88
        // Also spot-test QhullVertexList.  See QhullLinkedList_test.cpp
 
89
        QhullVertexList vs= q.vertexList();
 
90
        QhullVertexListIterator i(vs);
 
91
        while(i.hasNext()){
 
92
            const QhullVertex v= i.next();
 
93
            cout << v.id() << endl;
 
94
            QCOMPARE(v.dimension(),3);
 
95
            QVERIFY(v.id()>=0 && v.id()<9);
 
96
            QVERIFY(v.isDefined());
 
97
            if(i.hasNext()){
 
98
                QCOMPARE(v.next(), i.peekNext());
 
99
                QVERIFY(v.next()!=v);
 
100
                QVERIFY(v.next().previous()==v);
 
101
            }
 
102
            QVERIFY(i.hasPrevious());
 
103
            QCOMPARE(v, i.peekPrevious());
 
104
        }
 
105
        QhullVertexListIterator i2(i);
 
106
        QEXPECT_FAIL("", "ListIterator copy constructor not reset to BOT", Continue);
 
107
        QVERIFY(!i2.hasPrevious());
 
108
 
 
109
        // test point()
 
110
        foreach (QhullVertex v, q.vertexList()){  // Qt only
 
111
            QhullPoint p= v.point();
 
112
            int j= p.id(q.runId());
 
113
            cout << "Point " << j << ":\n" << p.print(q.runId()) << endl;
 
114
            QVERIFY(j>=0 && j<8);
 
115
        }
 
116
    }
 
117
}//t_getSet
 
118
 
 
119
void QhullVertex_test::
 
120
t_foreach()
 
121
{
 
122
    RboxPoints rcube("c W0 300");  // 300 points on surface of cube
 
123
    {
 
124
        Qhull q(rcube, "QR0 Qc"); // keep coplanars, thick facet, and rotate the cube
 
125
        foreach (QhullVertex v, q.vertexList()){  // Qt only
 
126
            QhullFacetSet fs= v.neighborFacets();
 
127
            QCOMPARE(fs.count(), 3);
 
128
            foreach (QhullFacet f, fs){  // Qt only
 
129
                QVERIFY(f.vertices().contains(v));
 
130
            }
 
131
        }
 
132
    }
 
133
}//t_foreach
 
134
 
 
135
void QhullVertex_test::
 
136
t_io()
 
137
{
 
138
    RboxPoints rcube("c");
 
139
    {
 
140
        Qhull q(rcube, "");
 
141
        QhullVertex v= q.beginVertex();
 
142
        ostringstream os;
 
143
        os << "Vertex and vertices w/o runId:\n";
 
144
        os << v;
 
145
        QhullVertexSet vs= q.firstFacet().vertices();
 
146
        os << vs;
 
147
        os << "Vertex and vertices w/ runId:\n";
 
148
        os << v.print(q.runId());
 
149
        os << vs.print(q.runId(), "vertices:");
 
150
        cout << os.str();
 
151
        QString s= QString::fromStdString(os.str());
 
152
        QCOMPARE(s.count("(v"), 10);
 
153
        QCOMPARE(s.count(": f"), 2);
 
154
    }
 
155
    RboxPoints r10("10 D3");  // Without QhullVertex::facetNeighbors
 
156
    {
 
157
        Qhull q(r10, "");
 
158
        QhullVertex v= q.beginVertex();
 
159
        ostringstream os;
 
160
        os << "\nTry again with simplicial facets.  No neighboring facets listed for vertices.\n";
 
161
        os << "Vertex and vertices w/o runId:\n";
 
162
        os << v;
 
163
        q.defineVertexNeighborFacets();
 
164
        os << "This time with neighborFacets() defined for all vertices:\n";
 
165
        os << v;
 
166
        cout << os.str();
 
167
        QString s= QString::fromStdString(os.str());
 
168
        QCOMPARE(s.count(": f"), 1);
 
169
 
 
170
        Qhull q2(r10, "v"); // Voronoi diagram
 
171
        QhullVertex v2= q2.beginVertex();
 
172
        ostringstream os2;
 
173
        os2 << "\nTry again with Voronoi diagram of simplicial facets.  Neighboring facets automatically defined for vertices.\n";
 
174
        os2 << "Vertex and vertices w/o runId:\n";
 
175
        os2 << v2;
 
176
        cout << os2.str();
 
177
        QString s2= QString::fromStdString(os2.str());
 
178
        QCOMPARE(s2.count(": f"), 1);
 
179
    }
 
180
}//t_io
 
181
 
 
182
}//orgQhull
 
183
 
 
184
#include "moc/QhullVertex_test.moc"