Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "QhullPointSet.h"
00010
00011 #include <iostream>
00012 #include <algorithm>
00013
00014 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
00015 #endif
00016
00017 namespace orgQhull {
00018
00019 #// Conversion
00020
00021
00022
00023 #ifndef QHULL_NO_STL
00024 std::vector<QhullPoint> QhullPointSet::
00025 toStdVector() const
00026 {
00027 QhullPointSetIterator i(*this);
00028 std::vector<QhullPoint> vs;
00029 while(i.hasNext()){
00030 vs.push_back(i.next());
00031 }
00032 return vs;
00033 }
00034 #endif //QHULL_NO_STL
00035
00036 #//Element-access
00037
00038 QhullPoint QhullPointSet::
00039 value(int idx) const
00040 {
00041
00042
00043 void **n= reinterpret_cast<void **>(&SETelem_(getSetT(), idx));
00044 coordT **n2= reinterpret_cast<coordT **>(n);
00045 if(idx>=0 && n<endPointer()){
00046 return QhullPoint(dimension(), *n2);
00047 }else{
00048 return QhullPoint();
00049 }
00050 }
00051
00054 QhullPoint QhullPointSet::
00055 value(int idx, QhullPoint &defaultValue) const
00056 {
00057
00058 void **n= reinterpret_cast<void **>(&SETelem_(getSetT(), idx));
00059 coordT **n2= reinterpret_cast<coordT **>(n);
00060 if(idx>=0 && n<endPointer()){
00061 return QhullPoint(dimension(), *n2);
00062 }else{
00063 return defaultValue;
00064 }
00065 }
00066
00067 #//Read-only
00068
00069 bool QhullPointSet::
00070 operator==(const QhullPointSet &o) const
00071 {
00072 if(dimension()!=o.dimension() || count()!=o.count()){
00073 return false;
00074 }
00075 QhullPointSetIterator i(*this);
00076 QhullPointSetIterator j(o);
00077 while(i.hasNext()){
00078 if(i.next()!=j.next()){
00079 return false;
00080 }
00081 }
00082 return true;
00083 }
00084
00085 #//Search
00086 bool QhullPointSet::
00087 contains(const QhullPoint &t) const
00088 {
00089 QhullPointSetIterator i(*this);
00090 while(i.hasNext()){
00091 if(i.next()==t){
00092 return true;
00093 }
00094 }
00095 return false;
00096 }
00097
00098 int QhullPointSet::
00099 count(const QhullPoint &t) const
00100 {
00101 int n= 0;
00102 QhullPointSetIterator i(*this);
00103 while(i.hasNext()){
00104 if(i.next()==t){
00105 ++n;
00106 }
00107 }
00108 return n;
00109 }
00110
00111 int QhullPointSet::
00112 indexOf(const QhullPoint &t) const
00113 {
00114 int idx= 0;
00115 QhullPointSetIterator i(*this);
00116 while(i.hasNext()){
00117 if(i.next()==t){
00118 return idx;
00119 }
00120 ++idx;
00121 }
00122 return -1;
00123 }
00124
00125 int QhullPointSet::
00126 lastIndexOf(const QhullPoint &t) const
00127 {
00128 int idx= count()-1;
00129 QhullPointSetIterator i(*this);
00130 i.toBack();
00131 while(i.hasPrevious()){
00132 if(i.previous()==t){
00133 break;
00134 }
00135 --idx;
00136 }
00137 return idx;
00138 }
00139
00140
00141 #//QhullPointSetIterator
00142
00143 bool QhullPointSetIterator::
00144 findNext(const QhullPoint &p)
00145 {
00146 while(i!=c->constEnd()){
00147 if(*i++ == p){
00148 return true;
00149 }
00150 }
00151 return false;
00152 }
00153
00154 bool QhullPointSetIterator::
00155 findPrevious(const QhullPoint &p)
00156 {
00157 while(i!=c->constBegin()){
00158 if(*(--i) == p){
00159 return true;
00160 }
00161 }
00162 return false;
00163 }
00164
00165 }
00166
00167 #//Global functions
00168
00169 using std::endl;
00170 using std::ostream;
00171 using orgQhull::QhullPoint;
00172 using orgQhull::QhullPointSet;
00173 using orgQhull::UsingLibQhull;
00174
00175 #//operator<<
00176
00177 ostream &
00178 operator<<(ostream &os, const QhullPointSet &ps)
00179 {
00180 os << ps.print(UsingLibQhull::NOqhRunId);
00181 return os;
00182 }
00183
00184 ostream &
00185 operator<<(ostream &os, const QhullPointSet::PrintIdentifiers &pr)
00186 {
00187 const QhullPointSet s= *pr.point_set;
00188 if (pr.print_message) {
00189 os << pr.print_message;
00190 }
00191 for(QhullPointSet::const_iterator i=s.begin(); i != s.end(); ++i){
00192 if(i!=s.begin()){
00193 os << " ";
00194 }
00195 const QhullPoint point= *i;
00196 int id= point.id(pr.run_id);
00197 os << "p" << id;
00198 }
00199 os << endl;
00200 return os;
00201 }
00202
00203 ostream &
00204 operator<<(ostream &os, const QhullPointSet::PrintPointSet &pr)
00205 {
00206 const QhullPointSet s= *pr.point_set;
00207 if (pr.print_message) {
00208 os << pr.print_message;
00209 }
00210 for(QhullPointSet::const_iterator i=s.begin(); i != s.end(); ++i){
00211 const QhullPoint point= *i;
00212 os << point.print(pr.run_id);
00213 }
00214 return os;
00215 }
00216
00217