QhullFacet.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/libqhullcpp/QhullFacet.cpp#3 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #
10 
11 #include "libqhullcpp/QhullFacet.h"
12 
13 #include "libqhullcpp/QhullError.h"
14 #include "libqhullcpp/Qhull.h"
15 #include "libqhullcpp/QhullSet.h"
16 #include "libqhullcpp/QhullPoint.h"
18 #include "libqhullcpp/QhullRidge.h"
21 
22 #include <ostream>
23 
24 using std::endl;
25 using std::ostream;
26 
27 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
28 #pragma warning( disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
29 #pragma warning( disable : 4996) // function was declared deprecated(strcpy, localtime, etc.)
30 #endif
31 
32 namespace orgQhull {
33 
34 #
35 facetT QhullFacet::
36 s_empty_facet= {0,0,0,0,{0},
37  0,0,0,0,0,
38  0,0,0,0,0,
39  0,0,0,0,0,
40  0,0,0,0,0,
41  0,0,0,0,0,
42  0,0,0,0,0,
43  0,0,0,0};
44 
45 #
46 
48 QhullFacet(const Qhull &q)
49 : qh_facet(&s_empty_facet)
50 , qh_qh(q.qh())
51 {
52 }
53 
55 QhullFacet(const Qhull &q, facetT *f)
56 : qh_facet(f ? f : &s_empty_facet)
57 , qh_qh(q.qh())
58 {
59 }
60 
61 #
62 
69 getCenter(qh_PRINT printFormat)
70 {
71  if(!qh_qh){
72  // returns QhullPoint()
73  }else if(qh_qh->CENTERtype==qh_ASvoronoi){
75  if(!qh_facet->center){
76  QH_TRY_(qh_qh){ // no object creation -- destructors skipped on longjmp()
78  }
79  qh_qh->NOerrexit= true;
80  qh_qh->maybeThrowQhullMessage(QH_TRY_status);
81  }
83  }
84  }else if(qh_qh->CENTERtype==qh_AScentrum){
85  volatile int numCoords= qh_qh->hull_dim;
86  if(printFormat==qh_PRINTtriangles && qh_qh->DELAUNAY){
87  numCoords--;
88  }
89  if(!qh_facet->center){
90  QH_TRY_(qh_qh){ // no object creation -- destructors skipped on longjmp()
92  }
93  qh_qh->NOerrexit= true;
94  qh_qh->maybeThrowQhullMessage(QH_TRY_status);
95  }
96  return QhullPoint(qh_qh, numCoords, qh_facet->center);
97  }
98  return QhullPoint();
99  }//getCenter
100 
104 innerplane() const{
105  QhullHyperplane h;
106  if(qh_qh){
107  realT inner;
108  // Does not error, TRY_QHULL_ not needed
109  qh_outerinner(qh_qh, const_cast<facetT *>(getFacetT()), NULL, &inner);
110  h= hyperplane();
111  h.setOffset(h.offset()-inner); //inner is negative
112  }
113  return h;
114 }//innerplane
115 
119 outerplane() const{
120  QhullHyperplane h;
121  if(qh_qh){
122  realT outer;
123  // Does not error, TRY_QHULL_ not needed
124  qh_outerinner(qh_qh, const_cast<facetT *>(getFacetT()), &outer, NULL);
125  h= hyperplane();
126  h.setOffset(h.offset()-outer); //outer is positive
127  }
128  return h;
129 }//outerplane
130 
135 {
136  if(qh_facet->tricoplanar){
137  if(qh_facet->isarea){
138  throw QhullError(10018, "Qhull error: facetArea() or qh_getarea() previously called. triCoplanarOwner() is not available.");
139  }
140  return QhullFacet(qh_qh, qh_facet->f.triowner);
141  }
142  return QhullFacet(qh_qh);
143 }//tricoplanarOwner
144 
147 {
149  throw QhullError(10052, "Error: QhullFacet.voronoiVertex() requires option 'v' (qh_ASvoronoi)");
150  }
151  return getCenter();
152 }//voronoiVertex
153 
154 #
155 
156 double QhullFacet::
159 {
160  if(qh_qh && !qh_facet->isarea){
161  QH_TRY_(qh_qh){ // no object creation -- destructors skipped on longjmp()
163  qh_facet->isarea= True;
164  }
165  qh_qh->NOerrexit= true;
166  qh_qh->maybeThrowQhullMessage(QH_TRY_status);
167  }
168  return qh_facet->f.area;
169 }//facetArea
170 
171 #
172 
175 {
177 }//coplanarPoints
178 
181 {
183 }//neighborFacets
184 
187 {
189 }//outsidePoints
190 
192 ridges() const
193 {
195 }//ridges
196 
198 vertices() const
199 {
201 }//vertices
202 
203 }//namespace orgQhull
204 
205 #
206 
207 using std::ostream;
208 
217 
218 ostream &
219 operator<<(ostream &os, const QhullFacet::PrintFacet &pr)
220 {
221  os << pr.message;
222  QhullFacet f= *pr.facet;
223  if(f.getFacetT()==0){ // Special values from set iterator
224  os << " NULLfacet" << endl;
225  return os;
226  }
227  if(f.getFacetT()==qh_MERGEridge){
228  os << " MERGEridge" << endl;
229  return os;
230  }
231  if(f.getFacetT()==qh_DUPLICATEridge){
232  os << " DUPLICATEridge" << endl;
233  return os;
234  }
235  os << f.printHeader();
236  if(!f.ridges().isEmpty()){
237  os << f.printRidges();
238  }
239  return os;
240 }//operator<< PrintFacet
241 
245 ostream &
246 operator<<(ostream &os, const QhullFacet::PrintCenter &pr)
247 {
248  facetT *f= pr.facet->getFacetT();
249  if(pr.facet->qh()->CENTERtype!=qh_ASvoronoi && pr.facet->qh()->CENTERtype!=qh_AScentrum){
250  return os;
251  }
252  if (pr.message){
253  os << pr.message;
254  }
255  int numCoords;
256  if(pr.facet->qh()->CENTERtype==qh_ASvoronoi){
257  numCoords= pr.facet->qh()->hull_dim-1;
258  if(!f->normal || !f->upperdelaunay || !pr.facet->qh()->ATinfinity){
259  if(!f->center){
260  f->center= qh_facetcenter(pr.facet->qh(), f->vertices);
261  }
262  for(int k=0; k<numCoords; k++){
263  os << f->center[k] << " "; // FIXUP QH11010 qh_REAL_1
264  }
265  }else{
266  for(int k=0; k<numCoords; k++){
267  os << qh_INFINITE << " "; // FIXUP QH11010 qh_REAL_1
268  }
269  }
270  }else{ // qh CENTERtype==qh_AScentrum
271  numCoords= pr.facet->qh()->hull_dim;
272  if(pr.print_format==qh_PRINTtriangles && pr.facet->qh()->DELAUNAY){
273  numCoords--;
274  }
275  if(!f->center){
276  f->center= qh_getcentrum(pr.facet->qh(), f);
277  }
278  for(int k=0; k<numCoords; k++){
279  os << f->center[k] << " "; // FIXUP QH11010 qh_REAL_1
280  }
281  }
282  if(pr.print_format==qh_PRINTgeom && numCoords==2){
283  os << " 0";
284  }
285  os << endl;
286  return os;
287 }//operator<< PrintCenter
288 
290 ostream &
291 operator<<(ostream &os, const QhullFacet::PrintFlags &p)
292 {
293  const facetT *f= p.facet->getFacetT();
294  if(p.message){
295  os << p.message;
296  }
297 
298  os << (p.facet->isTopOrient() ? " top" : " bottom");
299  if(p.facet->isSimplicial()){
300  os << " simplicial";
301  }
302  if(p.facet->isTriCoplanar()){
303  os << " tricoplanar";
304  }
305  if(p.facet->isUpperDelaunay()){
306  os << " upperDelaunay";
307  }
308  if(f->visible){
309  os << " visible";
310  }
311  if(f->newfacet){
312  os << " new";
313  }
314  if(f->tested){
315  os << " tested";
316  }
317  if(!f->good){
318  os << " notG";
319  }
320  if(f->seen){
321  os << " seen";
322  }
323  if(f->coplanar){
324  os << " coplanar";
325  }
326  if(f->mergehorizon){
327  os << " mergehorizon";
328  }
329  if(f->keepcentrum){
330  os << " keepcentrum";
331  }
332  if(f->dupridge){
333  os << " dupridge";
334  }
335  if(f->mergeridge && !f->mergeridge2){
336  os << " mergeridge1";
337  }
338  if(f->mergeridge2){
339  os << " mergeridge2";
340  }
341  if(f->newmerge){
342  os << " newmerge";
343  }
344  if(f->flipped){
345  os << " flipped";
346  }
347  if(f->notfurthest){
348  os << " notfurthest";
349  }
350  if(f->degenerate){
351  os << " degenerate";
352  }
353  if(f->redundant){
354  os << " redundant";
355  }
356  os << endl;
357  return os;
358 }//operator<< PrintFlags
359 
361 ostream &
362 operator<<(ostream &os, const QhullFacet::PrintHeader &pr)
363 {
364  QhullFacet facet= *pr.facet;
365  facetT *f= facet.getFacetT();
366  os << "- f" << facet.id() << endl;
367  os << facet.printFlags(" - flags:");
368  if(f->isarea){
369  os << " - area: " << f->f.area << endl; //FIXUP QH11010 2.2g
370  }else if(pr.facet->qh()->NEWfacets && f->visible && f->f.replace){
371  os << " - replacement: f" << f->f.replace->id << endl;
372  }else if(f->newfacet){
373  if(f->f.samecycle && f->f.samecycle != f){
374  os << " - shares same visible/horizon as f" << f->f.samecycle->id << endl;
375  }
376  }else if(f->tricoplanar /* !isarea */){
377  if(f->f.triowner){
378  os << " - owner of normal & centrum is facet f" << f->f.triowner->id << endl;
379  }
380  }else if(f->f.newcycle){
381  os << " - was horizon to f" << f->f.newcycle->id << endl;
382  }
383  if(f->nummerge){
384  os << " - merges: " << f->nummerge << endl;
385  }
386  os << facet.hyperplane().print(" - normal: ", "\n - offset: "); // FIXUP QH11010 %10.7g
387  if(pr.facet->qh()->CENTERtype==qh_ASvoronoi || f->center){
388  os << facet.printCenter(qh_PRINTfacets, " - center: ");
389  }
390 #if qh_MAXoutside
391  if(f->maxoutside > pr.facet->qh()->DISTround){
392  os << " - maxoutside: " << f->maxoutside << endl; //FIXUP QH11010 %10.7g
393  }
394 #endif
395  QhullPointSet ps= facet.outsidePoints();
396  if(!ps.isEmpty()){
397  QhullPoint furthest= ps.last();
398  if (ps.size() < 6) {
399  os << " - outside set(furthest p" << furthest.id() << "):" << endl;
400  for(QhullPointSet::iterator i=ps.begin(); i!=ps.end(); ++i){
401  QhullPoint p= *i;
402  os << p.print(" ");
403  }
404  }else if(ps.size()<21){
405  os << ps.print(" - outside set:");
406  }else{
407  os << " - outside set: " << ps.size() << " points.";
408  os << furthest.print(" Furthest");
409  }
410 #if !qh_COMPUTEfurthest
411  os << " - furthest distance= " << f->furthestdist << endl; //FIXUP QH11010 %2.2g
412 #endif
413  }
414  QhullPointSet cs= facet.coplanarPoints();
415  if(!cs.isEmpty()){
416  QhullPoint furthest= cs.last();
417  if (cs.size() < 6) {
418  os << " - coplanar set(furthest p" << furthest.id() << "):" << endl;
419  for(QhullPointSet::iterator i=cs.begin(); i!=cs.end(); ++i){
420  QhullPoint p= *i;
421  os << p.print(" ");
422  }
423  }else if(cs.size()<21){
424  os << cs.print(" - coplanar set:");
425  }else{
426  os << " - coplanar set: " << cs.size() << " points.";
427  os << furthest.print(" Furthest");
428  }
429  // FIXUP QH11027 Can/should zinc_(Zdistio) be called from C++ interface
430  double d= facet.distance(furthest);
431  os << " furthest distance= " << d << endl; //FIXUP QH11010 %2.2g
432  }
433  QhullVertexSet vs= facet.vertices();
434  if(!vs.isEmpty()){
435  os << vs.print(" - vertices:");
436  }
437  QhullFacetSet fs= facet.neighborFacets();
438  fs.selectAll();
439  if(!fs.isEmpty()){
440  os << fs.printIdentifiers(" - neighboring facets:");
441  }
442  return os;
443 }//operator<< PrintHeader
444 
445 
447 ostream &
448 operator<<(ostream &os, const QhullFacet::PrintRidges &pr)
449 {
450  const QhullFacet facet= *pr.facet;
451  facetT *f= facet.getFacetT();
452  QhullRidgeSet rs= facet.ridges();
453  if(!rs.isEmpty()){
454  if(f->visible && pr.facet->qh()->NEWfacets){
455  os << " - ridges(ids may be garbage):";
456  for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
457  QhullRidge r= *i;
458  os << " r" << r.id();
459  }
460  os << endl;
461  }else{
462  os << " - ridges:" << endl;
463  }
464 
465  // Keep track of printed ridges
466  for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
467  QhullRidge r= *i;
468  r.getRidgeT()->seen= false;
469  }
470  int ridgeCount= 0;
471  if(facet.dimension()==3){
472  for(QhullRidge r= rs.first(); !r.getRidgeT()->seen; r= r.nextRidge3d(facet)){
473  r.getRidgeT()->seen= true;
474  os << r.print("");
475  ++ridgeCount;
476  if(!r.hasNextRidge3d(facet)){
477  break;
478  }
479  }
480  }else {
481  QhullFacetSet ns(facet.neighborFacets());
482  for(QhullFacetSet::iterator i=ns.begin(); i!=ns.end(); ++i){
483  QhullFacet neighbor= *i;
484  QhullRidgeSet nrs(neighbor.ridges());
485  for(QhullRidgeSet::iterator j=nrs.begin(); j!=nrs.end(); ++j){
486  QhullRidge r= *j;
487  if(r.otherFacet(neighbor)==facet){
488  r.getRidgeT()->seen= true;
489  os << r.print("");
490  ridgeCount++;
491  }
492  }
493  }
494  }
495  if(ridgeCount!=rs.count()){
496  os << " - all ridges:";
497  for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
498  QhullRidge r= *i;
499  os << " r" << r.id();
500  }
501  os << endl;
502  }
503  for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
504  QhullRidge r= *i;
505  if(!r.getRidgeT()->seen){
506  os << r.print("");
507  }
508  }
509  }
510  return os;
511 }//operator<< PrintRidges
512 
513 // "No conversion" error if defined inline
514 ostream &
515 operator<<(ostream &os, QhullFacet &f)
516 {
517  os << f.print("");
518  return os;
519 }//<< QhullFacet
int hull_dim
Definition: libqhull.h:591
QhullRidgeSet ridges() const
Definition: QhullFacet.cpp:192
flagT newfacet
Definition: libqhull.h:320
QhullFacet otherFacet(const QhullFacet &f) const
Definition: QhullRidge.h:90
flagT notfurthest
Definition: libqhull.h:329
QhullHyperplane hyperplane() const
Definition: QhullFacet.h:72
QhullHyperplane innerplane() const
Definition: QhullFacet.cpp:104
setT * neighbors
Definition: libqhull.h:299
iterator begin()
Definition: QhullSet.h:177
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
coordT * center
Definition: libqhull.h:286
void maybeThrowQhullMessage(int exitCode)
Definition: QhullQh.cpp:118
ridgeT * getRidgeT() const
Definition: QhullRidge.h:85
bool isEmpty() const
Definition: QhullSet.h:70
flagT mergehorizon
Definition: libqhull.h:341
facetT * newcycle
Definition: libqhull.h:282
A QhullFacet is the C++ equivalent to Qhull&#39;s facetT*.
Definition: QhullFacet.h:37
QhullPointSet coplanarPoints() const
Definition: QhullFacet.cpp:174
boolT ATinfinity
Definition: libqhull.h:482
ostream & operator<<(ostream &os, const QhullFacet::PrintFacet &pr)
Definition: QhullFacet.cpp:219
#define QH_TRY_(qh)
Definition: QhullQh.h:31
countT id() const
Definition: QhullFacet.h:73
QhullPoint voronoiVertex()
Definition: QhullFacet.cpp:146
qh_CENTER CENTERtype
Definition: libqhull.h:716
QhullPoint getCenter()
Definition: QhullFacet.h:67
setT * coplanarset
Definition: libqhull.h:305
qhT qh_qh
Definition: global.c:26
size_t size() const
Definition: QhullSet.h:73
PrintHyperplane print(const char *message) const
boolT DELAUNAY
Definition: libqhull.h:491
#define qh_MERGEridge
Definition: poly.h:57
setT * ridges
Definition: libqhull.h:297
double facetArea()
Disables tricoplanarOwner()
Definition: QhullFacet.cpp:158
facetT * getFacetT() const
Definition: QhullFacet.h:71
QhullVertexSet vertices() const
Definition: QhullFacet.cpp:198
#define qh_DUPLICATEridge
Definition: poly.h:46
setT * vertices
Definition: libqhull.h:295
PrintFlags printFlags(const char *message) const
Definition: QhullFacet.h:126
const T last() const
Definition: QhullSet.h:163
realT qh_facetarea(facetT *facet)
Definition: geom2.c:457
#define True
Definition: libqhull.h:129
QhullQh * qh_qh
QhullQh/qhT for facetT, may be 0.
Definition: QhullFacet.h:46
static facetT s_empty_facet
Definition: QhullFacet.h:49
setT * outsideset
Definition: libqhull.h:302
flagT tested
Definition: libqhull.h:343
flagT dupridge
Definition: libqhull.h:336
unsigned nummerge
Definition: libqhull.h:312
int dimension() const
Definition: QhullFacet.h:66
#define qh
Definition: libqhull.h:457
countT id() const
Definition: QhullPoint.h:91
facetT * qh_facet
Corresponding facetT, may be 0 for corner cases (e.g., *facetSet.end()==0) and tricoplanarOwner() ...
Definition: QhullFacet.h:45
flagT redundant
Definition: libqhull.h:347
flagT upperdelaunay
Definition: libqhull.h:328
flagT flipped
Definition: libqhull.h:327
const PrintVertexSet print(const char *message) const
pointT * qh_getcentrum(facetT *facet)
Definition: geom.c:700
PrintRidges printRidges()
Definition: QhullFacet.h:138
QhullSet< QhullRidge > QhullRidgeSet
Definition: QhullFacet.h:33
flagT mergeridge2
Definition: libqhull.h:339
QhullFacetSet neighborFacets() const
Definition: QhullFacet.cpp:180
qh_PRINT
Definition: libqhull.h:161
Interface to Qhull from C++.
Definition: Qhull.h:43
countT id() const
Definition: QhullRidge.h:86
PrintHeader printHeader()
Definition: QhullFacet.h:132
PrintPointSet print(const char *message) const
Definition: QhullPointSet.h:66
coordT maxoutside
Definition: libqhull.h:267
flagT isarea
Definition: libqhull.h:333
PrintRidge print(const char *message) const
Definition: QhullRidge.h:106
boolT NOerrexit
Definition: libqhull.h:737
facetT * samecycle
Definition: libqhull.h:280
iterator end()
Definition: QhullSet.h:181
QhullQh * qh() const
Definition: QhullFacet.h:86
flagT keepcentrum
Definition: libqhull.h:344
flagT visible
Definition: libqhull.h:321
PrintIdentifiers printIdentifiers(const char *message) const
Definition: QhullFacetSet.h:85
flagT newmerge
Definition: libqhull.h:345
coordT furthestdist
Definition: libqhull.h:264
QhullHyperplane outerplane() const
Definition: QhullFacet.cpp:119
facetT * replace
Definition: libqhull.h:278
double distance(const Coordinates &c) const
Undefined if c.size() != dimension()
Definition: QhullFacet.h:92
flagT mergeridge
Definition: libqhull.h:337
#define qh_INFINITE
Definition: user.h:475
void selectAll()
operator==() does not depend on isGood()
Definition: QhullFacetSet.h:67
void qh_outerinner(facetT *facet, realT *outerplane, realT *innerplane)
Definition: geom2.c:1279
PrintPoint print(const char *message) const
Definition: QhullPoint.h:123
flagT seen
Definition: libqhull.h:325
flagT good
Definition: libqhull.h:332
PrintFacet print(const char *message)
Definition: QhullFacet.h:119
flagT seen
Definition: libqhull.h:377
QhullPointSet outsidePoints() const
Definition: QhullFacet.cpp:186
PrintCenter printCenter(qh_PRINT printFormat, const char *message)
Definition: QhullFacet.h:112
facetT * triowner
Definition: libqhull.h:284
realT area
Definition: libqhull.h:277
unsigned id
Definition: libqhull.h:311
#define realT
Definition: user.h:154
flagT coplanar
Definition: libqhull.h:340
coordT * normal
Definition: libqhull.h:274
void setOffset(coordT hyperplaneOffset)
QhullFacet tricoplanarOwner() const
Definition: QhullFacet.cpp:134
union facetT::@20 f
flagT tricoplanar
Definition: libqhull.h:314
pointT * qh_facetcenter(setT *vertices)
Definition: geom2.c:591
flagT degenerate
Definition: libqhull.h:346


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