QhullPoints.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2009-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/libqhullcpp/QhullPoints.cpp#3 $$Change: 1348 $
00005 ** $DateTime: 2011/03/25 23:54:58 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 #include "QhullPoints.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 // See qt-qhull.cpp for QList conversion
00021 
00022 #ifndef QHULL_NO_STL
00023 std::vector<QhullPoint> QhullPoints::
00024 toStdVector() const
00025 {
00026     QhullPointsIterator i(*this);
00027     std::vector<QhullPoint> vs;
00028     while(i.hasNext()){
00029         vs.push_back(i.next());
00030     }
00031     return vs;
00032 }//toStdVector
00033 #endif //QHULL_NO_STL
00034 
00035 #//Read-only
00036 
00037 bool QhullPoints::
00038 operator==(const QhullPoints &other) const
00039 {
00040     if(point_dimension!=other.point_dimension || (point_end-point_first) != (other.point_end-other.point_first)){
00041         return false;
00042     }
00043     const coordT *c= point_first;
00044     const coordT *c2= other.point_first;
00045     while(c<point_end){
00046         if(*c++!=*c2++){
00047             return false;
00048         }
00049     }
00050     return true;
00051 }//operator==
00052 
00053 
00054 #//ElementAccess
00055 QhullPoints QhullPoints::
00056 mid(int idx, int length) const
00057 {
00058     int n= count();
00059     if(idx<0 || idx>=n){
00060         n= 0;
00061     }else if(length<0 || idx+length>=n){
00062         n -= idx;
00063     }else{
00064         n -= idx+length;
00065     }
00066     return QhullPoints(point_dimension, n*point_dimension, point_first+idx*point_dimension);
00067 }//mid
00068 
00069 QhullPoint QhullPoints::
00070 value(int idx) const
00071 {
00072     QhullPoint p;
00073     if(idx>=0 && idx<count()){
00074         p.defineAs(point_dimension, point_first+idx*point_dimension);
00075     }
00076     return p;
00077 }//value
00078 
00079 QhullPoint QhullPoints::
00080 value(int idx, QhullPoint &defaultValue) const
00081 {
00082     QhullPoint p;
00083     if(idx>=0 && idx<count()){
00084         p.defineAs(point_dimension, point_first+idx*point_dimension);
00085     }else{
00086         p.defineAs(defaultValue);
00087     }
00088     return p;
00089 }//value
00090 
00091 #//Search
00092 
00093 bool QhullPoints::
00094 contains(const QhullPoint &t) const
00095 {
00096     const_iterator i= begin();
00097     while(i != end()){
00098         if(*i==t){
00099             return true;
00100         }
00101         i++;
00102     }
00103     return false;
00104 }//contains
00105 
00106 int QhullPoints::
00107 count(const QhullPoint &t) const
00108 {
00109     int n= 0;
00110     const_iterator i= begin();
00111     while(i != end()){
00112         if(*i==t){
00113             ++n;
00114         }
00115         i++;
00116     }
00117     return n;
00118 }//count
00119 
00120 int QhullPoints::
00121 indexOf(const coordT *pointCoordinates) const
00122 {
00123     if(!includesCoordinates(pointCoordinates) || dimension()==0){
00124         return -1;
00125     }
00126     size_t offset= pointCoordinates-point_first;
00127     int idx= (int)(offset/(size_t)dimension()); // int for error reporting
00128     int extra= (int)(offset%(size_t)dimension());
00129     if(extra!=0){
00130         throw QhullError(10066, "Qhull error: coordinates %x are not at point boundary (extra %d at index %d)", extra, idx, 0.0, pointCoordinates);
00131     }
00132     return idx;
00133 }//indexOf coordT
00134 
00135 int QhullPoints::
00136 indexOf(const coordT *pointCoordinates, int noThrow) const
00137 {
00138     size_t extra= 0;
00139     if(noThrow){
00140         if(!includesCoordinates(pointCoordinates) || dimension()==0){
00141             return -1;
00142         }
00143         extra= (pointCoordinates-point_first)%(size_t)dimension();
00144     }
00145     return indexOf(pointCoordinates-extra);
00146 }//indexOf coordT noThrow
00147 
00148 int QhullPoints::
00149 indexOf(const QhullPoint &t) const
00150 {
00151     int j=0;
00152     const_iterator i= begin();
00153     while(i!=end()){
00154         if(*i==t){
00155             return j;
00156         }
00157         ++i;
00158         ++j;
00159     }
00160     return -1;
00161 }//indexOf
00162 
00163 int QhullPoints::
00164 lastIndexOf(const QhullPoint &t) const
00165 {
00166     int j=count();
00167     const_iterator i= end();
00168     while(i != begin()){
00169         --i;
00170         --j;
00171         if(*i==t){
00172             return j;
00173         }
00174     }
00175     return -1;
00176 }//lastIndexOf
00177 
00178 #//QhullPointsIterator
00179 
00180 bool QhullPointsIterator::
00181 findNext(const QhullPoint &p)
00182 {
00183     while(i!=ps->constEnd()){
00184         if(*i++ == p){
00185             return true;
00186         }
00187     }
00188     return false;
00189 }//findNext
00190 
00191 bool QhullPointsIterator::
00192 findPrevious(const QhullPoint &p)
00193 {
00194     while(i!=ps->constBegin()){
00195         if(*--i == p){
00196             return true;
00197         }
00198     }
00199     return false;
00200 }//findPrevious
00201 
00202 }//namespace orgQhull
00203 
00204 #//Global functions
00205 
00206 using std::ostream;
00207 using orgQhull::QhullPoint;
00208 using orgQhull::QhullPoints;
00209 using orgQhull::QhullPointsIterator;
00210 
00211 ostream &
00212 operator<<(ostream &os, const QhullPoints &p)
00213 {
00214     QhullPointsIterator i(p);
00215     while(i.hasNext()){
00216         os << i.next();
00217     }
00218     return os;
00219 }//operator<<QhullPoints
00220 
00221 ostream &
00222 operator<<(ostream &os, const QhullPoints::PrintPoints &pr)
00223 {
00224     os << pr.point_message;
00225     QhullPoints ps= *pr.points;
00226     for(QhullPoints::iterator i=ps.begin(); i != ps.end(); ++i){
00227         QhullPoint p= *i;
00228         if(pr.with_identifier){
00229             os << p.printWithIdentifier(pr.run_id, "");
00230         }else{
00231             os << p.print(pr.run_id, "");
00232         }
00233     }
00234     return os;
00235 }//<<PrintPoints
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50