00001 /**************************************************************************** 00002 ** 00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved. 00004 ** $Id: //main/2011/qhull/src/libqhullcpp/QhullFacetSet.cpp#4 $$Change: 1382 $ 00005 ** $DateTime: 2011/05/14 10:45:42 $$Author: bbarber $ 00006 ** 00007 ****************************************************************************/ 00008 00009 #//! QhullFacetSet -- Qhull's linked facets, as a C++ class 00010 00011 #include "QhullFacet.h" 00012 #include "QhullFacetSet.h" 00013 #include "QhullPoint.h" 00014 #include "QhullRidge.h" 00015 #include "QhullVertex.h" 00016 00017 using std::string; 00018 using std::vector; 00019 00020 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4 00021 #pragma warning( disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable 00022 #pragma warning( disable : 4996) // function was declared deprecated(strcpy, localtime, etc.) 00023 #endif 00024 00025 namespace orgQhull { 00026 00027 #//Conversion 00028 00029 // See qt-qhull.cpp for QList conversions 00030 00031 #ifndef QHULL_NO_STL 00032 std::vector<QhullFacet> QhullFacetSet:: 00033 toStdVector() const 00034 { 00035 QhullSetIterator<QhullFacet> i(*this); 00036 std::vector<QhullFacet> vs; 00037 while(i.hasNext()){ 00038 QhullFacet f= i.next(); 00039 if(isSelectAll() || f.isGood()){ 00040 vs.push_back(f); 00041 } 00042 } 00043 return vs; 00044 }//toStdVector 00045 #endif //QHULL_NO_STL 00046 00047 #//Read-only 00048 00049 bool QhullFacetSet:: 00050 contains(const QhullFacet &facet) const 00051 { 00052 if(isSelectAll()){ 00053 return QhullSet<QhullFacet>::contains(facet); 00054 } 00055 for(QhullFacetSet::const_iterator i=begin(); i != end(); ++i){ 00056 QhullFacet f= *i; 00057 if(f==facet && f.isGood()){ 00058 return true; 00059 } 00060 } 00061 return false; 00062 }//contains 00063 00064 int QhullFacetSet:: 00065 count() const 00066 { 00067 if(isSelectAll()){ 00068 return QhullSet<QhullFacet>::count(); 00069 } 00070 int counter= 0; 00071 for(QhullFacetSet::const_iterator i=begin(); i != end(); ++i){ 00072 QhullFacet f= *i; 00073 if(f.isGood()){ 00074 counter++; 00075 } 00076 } 00077 return counter; 00078 }//count 00079 00080 int QhullFacetSet:: 00081 count(const QhullFacet &facet) const 00082 { 00083 if(isSelectAll()){ 00084 return QhullSet<QhullFacet>::count(facet); 00085 } 00086 int counter= 0; 00087 for(QhullFacetSet::const_iterator i=begin(); i != end(); ++i){ 00088 QhullFacet f= *i; 00089 if(f==facet && f.isGood()){ 00090 counter++; 00091 } 00092 } 00093 return counter; 00094 }//count 00095 00096 }//namespace orgQhull 00097 00098 #//Global functions 00099 00100 using std::endl; 00101 using std::ostream; 00102 using orgQhull::QhullFacet; 00103 using orgQhull::QhullFacetSet; 00104 using orgQhull::UsingLibQhull; 00105 00106 ostream & 00107 operator<<(ostream &os, const QhullFacetSet &fs) 00108 { 00109 os << fs.print(UsingLibQhull::NOqhRunId, ""); 00110 return os; 00111 }//<<QhullFacetSet 00112 00113 ostream & 00114 00115 operator<<(ostream &os, const QhullFacetSet::PrintFacetSet &pr) 00116 { 00117 QhullFacetSet fs= *pr.facet_set; 00118 for(QhullFacetSet::iterator i=fs.begin(); i != fs.end(); ++i){ 00119 QhullFacet f= *i; 00120 if(fs.isSelectAll() || f.isGood()){ 00121 os << f.print(pr.run_id); 00122 } 00123 } 00124 return os; 00125 }//<< QhullFacetSet::PrintFacetSet 00126 00128 ostream & 00129 operator<<(ostream &os, const QhullFacetSet::PrintIdentifiers &p) 00130 { 00131 os << p.print_message; 00132 for(QhullFacetSet::const_iterator i=p.facet_set->begin(); i!=p.facet_set->end(); ++i){ 00133 const QhullFacet f= *i; 00134 if(f.getFacetT()==qh_MERGEridge){ 00135 os << " MERGE"; 00136 }else if(f.getFacetT()==qh_DUPLICATEridge){ 00137 os << " DUP"; 00138 }else if(p.facet_set->isSelectAll() || f.isGood()){ 00139 os << " f" << f.id(); 00140 } 00141 } 00142 os << endl; 00143 return os; 00144 }//<<QhullFacetSet::PrintIdentifiers 00145