QhullRidge_test.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2008-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/qhulltest/QhullRidge_test.cpp#3 $$Change: 2062 $
5 ** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled headers
10 #include <iostream>
11 #include "RoadTest.h" // QT_VERSION
12 
13 #include "libqhullcpp/QhullRidge.h"
14 #include "libqhullcpp/QhullError.h"
15 #include "libqhullcpp/RboxPoints.h"
16 #include "libqhullcpp/QhullFacet.h"
17 #include "libqhullcpp/Qhull.h"
18 
19 using std::cout;
20 using std::endl;
21 using std::ostringstream;
22 using std::ostream;
23 using std::string;
24 
25 namespace orgQhull {
26 
27 class QhullRidge_test : public RoadTest
28 {
29  Q_OBJECT
30 
31 #
32 private slots:
33  void cleanup();
34  void t_construct();
35  void t_getSet();
36  void t_foreach();
37  void t_io();
38 };//QhullRidge_test
39 
40 void
42 {
43  new QhullRidge_test(); // RoadTest::s_testcases
44 }
45 
46 //Executed after each testcase
49 {
51 }
52 
55 {
56  // Qhull.runQhull() constructs QhullFacets as facetT
57  RboxPoints rcube("c");
58  Qhull q(rcube,"QR0"); // triangulation of rotated unit cube
59  QhullRidge r(q);
60  QVERIFY(!r.isValid());
61  QCOMPARE(r.dimension(),2);
62  QhullFacet f(q.firstFacet());
63  QhullRidgeSet rs(f.ridges());
64  QVERIFY(!rs.isEmpty()); // Simplicial facets do not have ridges()
65  QhullRidge r2(rs.first());
66  QCOMPARE(r2.dimension(), 2); // One dimension lower than the facet
67  r= r2;
68  QVERIFY(r.isValid());
69  QCOMPARE(r.dimension(), 2);
70  QhullRidge r3(q, r2.getRidgeT());
71  QCOMPARE(r,r3);
72  QhullRidge r4(q, r2.getBaseT());
73  QCOMPARE(r,r4);
74  QhullRidge r5= r2; // copy constructor
75  QVERIFY(r5==r2);
76  QVERIFY(r5==r);
77 }//t_construct
78 
81 {
82  RboxPoints rcube("c");
83  {
84  Qhull q(rcube,"QR0"); // triangulation of rotated unit cube
85  QCOMPARE(q.facetCount(), 6);
86  QCOMPARE(q.vertexCount(), 8);
87  QhullFacet f(q.firstFacet());
88  QhullRidgeSet rs= f.ridges();
90  while(i.hasNext()){
91  const QhullRidge r= i.next();
92  cout << r.id() << endl;
93  QVERIFY(r.bottomFacet()!=r.topFacet());
94  QCOMPARE(r.dimension(), 2); // Ridge one-dimension less than facet
95  QVERIFY(r.id()>=0 && r.id()<9*27);
96  QVERIFY(r.isValid());
97  QVERIFY(r==r);
98  QVERIFY(r==i.peekPrevious());
99  QCOMPARE(r.otherFacet(r.bottomFacet()),r.topFacet());
100  QCOMPARE(r.otherFacet(r.topFacet()),r.bottomFacet());
101  }
102  }
103 }//t_getSet
104 
107 {
108  RboxPoints rcube("c"); // cube
109  {
110  Qhull q(rcube, "QR0"); // rotated cube
111  QhullFacet f(q.firstFacet());
112  foreach (const QhullRidge &r, f.ridges()){ // Qt only
113  QhullVertexSet vs= r.vertices();
114  QCOMPARE(vs.count(), 2);
115  foreach (const QhullVertex &v, vs){ // Qt only
116  QVERIFY(f.vertices().contains(v));
117  }
118  }
119  QhullRidgeSet rs= f.ridges();
120  QhullRidge r= rs.first();
121  QhullRidge r2= r;
122  QList<QhullVertex> vs;
123  int count= 0;
124  while(!count || r2!=r){
125  ++count;
126  QhullVertex v(q);
127  QVERIFY2(r2.hasNextRidge3d(f),"A cube should only have non-simplicial facets.");
128  QhullRidge r3= r2.nextRidge3d(f, &v);
129  QVERIFY(!vs.contains(v));
130  vs << v;
131  r2= r2.nextRidge3d(f);
132  QCOMPARE(r3, r2);
133  }
134  QCOMPARE(vs.count(), rs.count());
135  QCOMPARE(count, rs.count());
136  }
137 }//t_foreach
138 
141 {
142  RboxPoints rcube("c");
143  {
144  Qhull q(rcube, "");
145  QhullFacet f(q.firstFacet());
146  QhullRidgeSet rs= f.ridges();
147  QhullRidge r= rs.first();
148  ostringstream os;
149  os << "Ridges\n" << rs << "Ridge\n" << r;
150  os << r.print("\nRidge with message");
151  cout << os.str();
152  QString s= QString::fromStdString(os.str());
153  QCOMPARE(s.count(" r"), 6);
154  }
155 }//t_io
156 
157 }//orgQhull
158 
159 #include "moc/QhullRidge_test.moc"
QhullFacet otherFacet(const QhullFacet &f) const
Definition: QhullRidge.h:90
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
q
A QhullFacet is the C++ equivalent to Qhull&#39;s facetT*.
Definition: QhullFacet.h:37
Faster then interator/const_iterator due to T::base_type.
Definition: QhullSet.h:283
QhullFacet firstFacet() const
Definition: Qhull.h:108
QhullFacet bottomFacet() const
Definition: QhullRidge.h:82
list v
Definition: obb.py:45
QhullRidge nextRidge3d(const QhullFacet &f) const
Definition: QhullRidge.h:95
countT vertexCount() const
Definition: Qhull.h:86
bool isValid() const
Definition: QhullRidge.h:87
Interface to Qhull from C++.
Definition: Qhull.h:43
countT id() const
Definition: QhullRidge.h:86
bool hasNextRidge3d(const QhullFacet &f) const
Definition: QhullRidge.cpp:49
r2
void cleanup()
Executed after each test.
Definition: RoadTest.cpp:38
void add_QhullRidge_test()
QhullVertexSet vertices() const
Definition: QhullRidge.h:97
int dimension() const
Definition: QhullRidge.h:83
countT count(const T &t) const
Definition: QhullSet.h:389
QhullFacet topFacet() const
Definition: QhullRidge.h:91
countT facetCount() const
Definition: Qhull.h:72


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:02