11 #include "QhullError.h"
14 #include "QhullPoint.h"
15 #include "QhullPointSet.h"
16 #include "QhullRidge.h"
17 #include "QhullFacet.h"
18 #include "QhullFacetSet.h"
19 #include "QhullVertex.h"
27 #pragma warning( disable : 4611)
28 #pragma warning( disable : 4996)
35 s_empty_facet= {0,0,0,0,{0},
47 QhullFacet(
const Qhull &q)
48 : qh_facet(&s_empty_facet)
54 QhullFacet(
const Qhull &q, facetT *f)
55 : qh_facet(f ? f : &s_empty_facet)
67 QhullPoint QhullFacet::
68 getCenter(qh_PRINT printFormat)
72 }
else if(qh_qh->CENTERtype==qh_ASvoronoi){
73 if(!qh_facet->normal || !qh_facet->upperdelaunay || !qh_qh->ATinfinity){
74 if(!qh_facet->center){
76 qh_facet->center= qh_facetcenter(qh_qh, qh_facet->vertices);
78 qh_qh->NOerrexit=
true;
79 qh_qh->maybeThrowQhullMessage(QH_TRY_status);
81 return QhullPoint(qh_qh, qh_qh->hull_dim-1, qh_facet->center);
83 }
else if(qh_qh->CENTERtype==qh_AScentrum){
84 volatile int numCoords= qh_qh->hull_dim;
85 if(printFormat==qh_PRINTtriangles && qh_qh->DELAUNAY){
88 if(!qh_facet->center){
90 qh_facet->center= qh_getcentrum(qh_qh, getFacetT());
92 qh_qh->NOerrexit=
true;
93 qh_qh->maybeThrowQhullMessage(QH_TRY_status);
95 return QhullPoint(qh_qh, numCoords, qh_facet->center);
102 QhullHyperplane QhullFacet::
108 qh_outerinner(qh_qh,
const_cast<facetT *
>(getFacetT()), NULL, &inner);
110 h.setOffset(h.offset()-inner);
117 QhullHyperplane QhullFacet::
123 qh_outerinner(qh_qh,
const_cast<facetT *
>(getFacetT()), &outer, NULL);
125 h.setOffset(h.offset()-outer);
132 QhullFacet QhullFacet::
133 tricoplanarOwner()
const
135 if(qh_facet->tricoplanar){
136 if(qh_facet->isarea){
137 throw QhullError(10018,
"Qhull error: facetArea() or qh_getarea() previously called. triCoplanarOwner() is not available.");
139 return QhullFacet(qh_qh, qh_facet->f.triowner);
141 return QhullFacet(qh_qh);
144 QhullPoint QhullFacet::
147 if(qh_qh && qh_qh->CENTERtype!=qh_ASvoronoi){
148 throw QhullError(10052,
"Error: QhullFacet.voronoiVertex() requires option 'v' (qh_ASvoronoi)");
159 if(qh_qh && !qh_facet->isarea){
161 qh_facet->f.area= qh_facetarea(qh_qh, qh_facet);
162 qh_facet->isarea= True;
164 qh_qh->NOerrexit=
true;
165 qh_qh->maybeThrowQhullMessage(QH_TRY_status);
167 return qh_facet->f.area;
172 QhullPointSet QhullFacet::
173 coplanarPoints()
const
175 return QhullPointSet(qh_qh, qh_facet->coplanarset);
178 QhullFacetSet QhullFacet::
179 neighborFacets()
const
181 return QhullFacetSet(qh_qh, qh_facet->neighbors);
184 QhullPointSet QhullFacet::
185 outsidePoints()
const
187 return QhullPointSet(qh_qh, qh_facet->outsideset);
190 QhullRidgeSet QhullFacet::
193 return QhullRidgeSet(qh_qh, qh_facet->ridges);
196 QhullVertexSet QhullFacet::
199 return QhullVertexSet(qh_qh, qh_facet->vertices);
208 using orgQhull::QhullFacet;
209 using orgQhull::QhullFacetSet;
210 using orgQhull::QhullPoint;
211 using orgQhull::QhullPointSet;
212 using orgQhull::QhullRidge;
213 using orgQhull::QhullRidgeSet;
214 using orgQhull::QhullSetBase;
215 using orgQhull::QhullVertexSet;
218 operator<<(ostream &os,
const QhullFacet::PrintFacet &pr)
221 QhullFacet f= *pr.facet;
222 if(f.getFacetT()==0){
223 os <<
" NULLfacet" << endl;
226 if(f.getFacetT()==qh_MERGEridge){
227 os <<
" MERGEridge" << endl;
230 if(f.getFacetT()==qh_DUPLICATEridge){
231 os <<
" DUPLICATEridge" << endl;
234 os << f.printHeader();
235 if(!f.ridges().isEmpty()){
236 os << f.printRidges();
245 operator<<(ostream &os,
const QhullFacet::PrintCenter &pr)
247 facetT *f= pr.facet->getFacetT();
248 if(pr.facet->qh()->CENTERtype!=qh_ASvoronoi && pr.facet->qh()->CENTERtype!=qh_AScentrum){
255 if(pr.facet->qh()->CENTERtype==qh_ASvoronoi){
256 numCoords= pr.facet->qh()->hull_dim-1;
257 if(!f->normal || !f->upperdelaunay || !pr.facet->qh()->ATinfinity){
259 f->center= qh_facetcenter(pr.facet->qh(), f->vertices);
261 for(
int k=0; k<numCoords; k++){
262 os << f->center[k] <<
" ";
265 for(
int k=0; k<numCoords; k++){
266 os << qh_INFINITE <<
" ";
270 numCoords= pr.facet->qh()->hull_dim;
271 if(pr.print_format==qh_PRINTtriangles && pr.facet->qh()->DELAUNAY){
275 f->center= qh_getcentrum(pr.facet->qh(), f);
277 for(
int k=0; k<numCoords; k++){
278 os << f->center[k] <<
" ";
281 if(pr.print_format==qh_PRINTgeom && numCoords==2){
290 operator<<(ostream &os,
const QhullFacet::PrintFlags &p)
292 const facetT *f= p.facet->getFacetT();
297 os << (p.facet->isTopOrient() ?
" top" :
" bottom");
298 if(p.facet->isSimplicial()){
301 if(p.facet->isTriCoplanar()){
302 os <<
" tricoplanar";
304 if(p.facet->isUpperDelaunay()){
305 os <<
" upperDelaunay";
326 os <<
" mergehorizon";
329 os <<
" keepcentrum";
334 if(f->mergeridge && !f->mergeridge2){
335 os <<
" mergeridge1";
338 os <<
" mergeridge2";
347 os <<
" notfurthest";
361 operator<<(ostream &os,
const QhullFacet::PrintHeader &pr)
363 QhullFacet facet= *pr.facet;
364 facetT *f= facet.getFacetT();
365 os <<
"- f" << facet.id() << endl;
366 os << facet.printFlags(
" - flags:");
368 os <<
" - area: " << f->f.area << endl;
369 }
else if(pr.facet->qh()->NEWfacets && f->visible && f->f.replace){
370 os <<
" - replacement: f" << f->f.replace->id << endl;
371 }
else if(f->newfacet){
372 if(f->f.samecycle && f->f.samecycle != f){
373 os <<
" - shares same visible/horizon as f" << f->f.samecycle->id << endl;
375 }
else if(f->tricoplanar ){
377 os <<
" - owner of normal & centrum is facet f" << f->f.triowner->id << endl;
379 }
else if(f->f.newcycle){
380 os <<
" - was horizon to f" << f->f.newcycle->id << endl;
383 os <<
" - merges: " << f->nummerge << endl;
385 os << facet.hyperplane().print(
" - normal: ",
"\n - offset: ");
386 if(pr.facet->qh()->CENTERtype==qh_ASvoronoi || f->center){
387 os << facet.printCenter(qh_PRINTfacets,
" - center: ");
390 if(f->maxoutside > pr.facet->qh()->DISTround){
391 os <<
" - maxoutside: " << f->maxoutside << endl;
394 QhullPointSet ps= facet.outsidePoints();
396 QhullPoint furthest= ps.last();
398 os <<
" - outside set(furthest p" << furthest.id() <<
"):" << endl;
399 for(QhullPointSet::iterator i=ps.begin(); i!=ps.end(); ++i){
403 }
else if(ps.size()<21){
404 os << ps.print(
" - outside set:");
406 os <<
" - outside set: " << ps.size() <<
" points.";
407 os << furthest.print(
" Furthest");
409 #if !qh_COMPUTEfurthest
410 os <<
" - furthest distance= " << f->furthestdist << endl;
413 QhullPointSet cs= facet.coplanarPoints();
415 QhullPoint furthest= cs.last();
417 os <<
" - coplanar set(furthest p" << furthest.id() <<
"):" << endl;
418 for(QhullPointSet::iterator i=cs.begin(); i!=cs.end(); ++i){
422 }
else if(cs.size()<21){
423 os << cs.print(
" - coplanar set:");
425 os <<
" - coplanar set: " << cs.size() <<
" points.";
426 os << furthest.print(
" Furthest");
429 double d= facet.distance(furthest);
430 os <<
" furthest distance= " << d << endl;
432 QhullVertexSet vs= facet.vertices();
434 os << vs.print(
" - vertices:");
436 QhullFacetSet
fs= facet.neighborFacets();
439 os <<
fs.printIdentifiers(
" - neighboring facets:");
447 operator<<(ostream &os,
const QhullFacet::PrintRidges &pr)
449 const QhullFacet facet= *pr.facet;
450 facetT *f= facet.getFacetT();
451 QhullRidgeSet rs= facet.ridges();
453 if(f->visible && pr.facet->qh()->NEWfacets){
454 os <<
" - ridges(ids may be garbage):";
455 for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
457 os <<
" r" << r.id();
461 os <<
" - ridges:" << endl;
465 for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
467 r.getRidgeT()->seen=
false;
470 if(facet.dimension()==3){
471 for(QhullRidge r= rs.first(); !r.getRidgeT()->seen; r= r.nextRidge3d(facet)){
472 r.getRidgeT()->seen=
true;
475 if(!r.hasNextRidge3d(facet)){
480 QhullFacetSet ns(facet.neighborFacets());
481 for(QhullFacetSet::iterator i=ns.begin(); i!=ns.end(); ++i){
482 QhullFacet neighbor= *i;
483 QhullRidgeSet nrs(neighbor.ridges());
484 for(QhullRidgeSet::iterator j=nrs.begin(); j!=nrs.end(); ++j){
486 if(r.otherFacet(neighbor)==facet){
487 r.getRidgeT()->seen=
true;
494 if(ridgeCount!=rs.count()){
495 os <<
" - all ridges:";
496 for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
498 os <<
" r" << r.id();
502 for(QhullRidgeSet::iterator i=rs.begin(); i!=rs.end(); ++i){
504 if(!r.getRidgeT()->seen){
ostream & operator<<(ostream &os, const QhullFacet::PrintFacet &pr)
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.