QhullPoint.h
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/QhullPoint.h#5 $$Change: 1382 $
00005 ** $DateTime: 2011/05/14 10:45:42 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 #ifndef QHPOINT_H
00010 #define QHPOINT_H
00011 
00012 #include "QhullError.h"
00013 #include "QhullIterator.h"
00014 #include "UsingLibQhull.h"
00015 #include "Coordinates.h"
00016 extern "C" {
00017     #include "libqhull/qhull_a.h"
00018 }
00019 
00020 #include <ostream>
00021 
00022 namespace orgQhull {
00023 
00024 #//Types
00025 
00026     class QhullPoint;
00028     class QhullPointIterator;
00029 
00030 class QhullPoint {
00031 
00033 
00034 private:
00035 #//Fields
00036     coordT             *point_coordinates;  // Keep pointers aligned
00037     int                 point_dimension;
00038 
00039 public:
00040 #//Subtypes
00041     typedef const coordT *              iterator;
00042     typedef const coordT *              const_iterator;
00043     typedef QhullPoint::iterator        Iterator;
00044     typedef QhullPoint::const_iterator  ConstIterator;
00045 
00046 #//Class methods -- Convert point to id w/o QhullQh data structure
00047     static int          id(const coordT *c) { return QhullPoint::id(UsingLibQhull::NOqhRunId, 0, c); }
00048     static int          id(int qhRunId, const coordT *c) { return QhullPoint::id(qhRunId, 0, c); }
00049     static int          id(int qhRunId, int dimension, const coordT *c);
00050 
00051 #//Construct
00052                         QhullPoint() : point_coordinates(0), point_dimension(0) {};
00053                         QhullPoint(int pointDimension, coordT *c) : point_coordinates(c), point_dimension(pointDimension) {}
00054     explicit            QhullPoint(Coordinates &c) : point_coordinates(c.data()), point_dimension(c.count()) {}
00055                         // Creates an alias.  Does not copy the point.  Needed for return by value and parameter passing.
00056                         QhullPoint(const QhullPoint &other)  : point_coordinates(other.point_coordinates), point_dimension(other.point_dimension) {}
00057                         // Creates an alias.  Does not copy the point.  Needed for vector<QhullPoint>
00058     QhullPoint         &operator=(const QhullPoint &other) { point_coordinates= other.point_coordinates; point_dimension= other.point_dimension; return *this; }
00059                        ~QhullPoint() {}
00060 
00061 #//Conversions
00062     // see coordinates()
00063 #ifndef QHULL_NO_STL
00064     std::vector<coordT> toStdVector() const;
00065 #endif //QHULL_NO_STL
00066 #ifdef QHULL_USES_QT
00067     QList<coordT>       toQList() const;
00068 #endif //QHULL_USES_QT
00069 
00070 #//Read-only
00071 public:
00072     const coordT       *coordinates() const { return point_coordinates; }
00073     coordT             *coordinates() { return point_coordinates; }
00074     int                 dimension() const { return point_dimension; }
00075     int                 id(int qhRunId) const { return id(qhRunId, dimension(), coordinates()); }
00076     int                 id() const { return id(UsingLibQhull::NOqhRunId, dimension(), coordinates()); }
00077     bool                isDefined() const { return point_coordinates!=0 && point_dimension>0; }
00078 
00079 #//Define
00080     void                advancePoint(int idx) { point_coordinates += idx*point_dimension; }
00081     void                defineAs(int pointDimension, coordT *c) { QHULL_ASSERT(pointDimension>=0); point_coordinates= c; point_dimension= pointDimension; }
00083     void                defineAs(QhullPoint &other) { point_coordinates= other.coordinates(); point_dimension= other.dimension(); }
00084     void                setCoordinates(coordT *c) { point_coordinates= c; }
00085     void                setDimension(int pointDimension) { point_dimension= pointDimension; }
00086 
00087 #//value
00088     double              distance(const QhullPoint &p) const;
00089 
00090 #//iterator
00091     iterator            begin() { return point_coordinates; }
00092     const_iterator      begin() const { return point_coordinates; }
00093     const_iterator      constBegin() const { return point_coordinates; }
00094     const_iterator      constEnd() const { return point_coordinates+point_dimension; }
00095     int                 count() { return dimension(); }
00096     iterator            end() { return point_coordinates+point_dimension; }
00097     const_iterator      end() const { return point_coordinates+point_dimension; }
00098     size_t              size() { return (size_t)dimension(); }
00099 
00100 #//Operator
00101     bool                operator==(const QhullPoint &other) const;
00102     bool                operator!=(const QhullPoint &other) const { return !operator==(other); }
00103     const coordT       &operator[](int idx) const { QHULL_ASSERT(idx>=0 && idx<point_dimension); return *(point_coordinates+idx); }
00104     coordT             &operator[](int idx) { QHULL_ASSERT(idx>=0 && idx<point_dimension); return *(point_coordinates+idx); }
00105 
00106     struct PrintPoint{
00107         const QhullPoint  *point;
00108         const char     *point_message;
00109         int             run_id;
00110         bool            with_identifier;
00111                         PrintPoint(int qhRunId, const char *message, bool withIdentifier, const QhullPoint &p) : point(&p), point_message(message), run_id(qhRunId), with_identifier(withIdentifier) {}
00112     };//PrintPoint
00113     PrintPoint          print() const { return  PrintPoint(UsingLibQhull::NOqhRunId, "", false, *this); }
00114     PrintPoint          print(int qhRunId) const { return PrintPoint(qhRunId, "", true, *this); }
00115     PrintPoint          print(int qhRunId, const char *message) const { return PrintPoint(qhRunId, message, false, *this); }
00116     PrintPoint          printWithIdentifier(int qhRunId, const char *message) const { return PrintPoint(qhRunId, message, true, *this); }
00117 
00118 };//QhullPoint
00119 
00120 QHULL_DECLARE_SEQUENTIAL_ITERATOR(QhullPoint, coordT)
00121 
00122 }//namespace orgQhull
00123 
00124 #//Global functions
00125 
00126 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPoint::PrintPoint &pr);
00127 std::ostream &operator<<(std::ostream &os, const orgQhull::QhullPoint &p); // FIXUP QH11017 OK in c program but not inline { os << p.print(orgQhull::UsingLibQhull::NOqhRunId, ""); return os; }
00128 
00129 #endif // QHPOINT_H
00130 
 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