1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (c) 2009-2012 C.B. Barber. All rights reserved.
|
---|
4 | ** $Id: //main/2011/qhull/src/libqhullcpp/QhullHyperplane.h#6 $$Change: 1464 $
|
---|
5 | ** $DateTime: 2012/01/25 22:58:41 $$Author: bbarber $
|
---|
6 | **
|
---|
7 | ****************************************************************************/
|
---|
8 |
|
---|
9 | #ifndef QHHYPERPLANE_H
|
---|
10 | #define QHHYPERPLANE_H
|
---|
11 |
|
---|
12 | #include "QhullError.h"
|
---|
13 | #include "QhullIterator.h"
|
---|
14 | #include "UsingLibQhull.h"
|
---|
15 | extern "C" {
|
---|
16 | #include "libqhull/qhull_a.h"
|
---|
17 | }
|
---|
18 |
|
---|
19 | #include <ostream>
|
---|
20 |
|
---|
21 | namespace orgQhull {
|
---|
22 | #//ClassRef
|
---|
23 | class QhullPoint;
|
---|
24 |
|
---|
25 | #//Types
|
---|
26 | //! QhullHyperplane as an offset, dimension, and pointer to coordinates
|
---|
27 | class QhullHyperplane;
|
---|
28 | //! Java-style iterator for QhullHyperplane coordinates
|
---|
29 | class QhullHyperplaneIterator;
|
---|
30 |
|
---|
31 | class QhullHyperplane { // Similar to QhullPoint
|
---|
32 |
|
---|
33 | private:
|
---|
34 | #//Fields
|
---|
35 | coordT *hyperplane_coordinates; // Keep pointers aligned
|
---|
36 | int hyperplane_dimension;
|
---|
37 | coordT hyperplane_offset;
|
---|
38 |
|
---|
39 | public:
|
---|
40 | #//Subtypes
|
---|
41 | typedef const coordT * iterator;
|
---|
42 | typedef const coordT * const_iterator;
|
---|
43 | typedef QhullHyperplane::iterator Iterator;
|
---|
44 | typedef QhullHyperplane::const_iterator ConstIterator;
|
---|
45 |
|
---|
46 | #//Construct
|
---|
47 | QhullHyperplane() : hyperplane_coordinates(0), hyperplane_dimension(0), hyperplane_offset(0.0) {};
|
---|
48 | QhullHyperplane(int hyperplaneDimension, coordT *c, coordT hyperplaneOffset) : hyperplane_coordinates(c), hyperplane_dimension(hyperplaneDimension), hyperplane_offset(hyperplaneOffset) {}
|
---|
49 | // Creates an alias. Does not copy the hyperplane's coordinates. Needed for return by value and parameter passing.
|
---|
50 | QhullHyperplane(const QhullHyperplane &other) : hyperplane_coordinates(other.hyperplane_coordinates), hyperplane_dimension(other.hyperplane_dimension), hyperplane_offset(other.hyperplane_offset) {}
|
---|
51 | // Creates an alias. Does not copy the hyperplane's coordinates. Needed for vector<QhullHyperplane>
|
---|
52 | QhullHyperplane &operator=(const QhullHyperplane &other) { hyperplane_coordinates= other.hyperplane_coordinates; hyperplane_dimension= other.hyperplane_dimension; hyperplane_offset= other.hyperplane_offset; return *this; }
|
---|
53 | ~QhullHyperplane() {}
|
---|
54 |
|
---|
55 | #//Conversions --
|
---|
56 | //! Includes offset at end
|
---|
57 | #ifndef QHULL_NO_STL
|
---|
58 | std::vector<coordT> toStdVector() const;
|
---|
59 | #endif //QHULL_NO_STL
|
---|
60 | #ifdef QHULL_USES_QT
|
---|
61 | QList<coordT> toQList() const;
|
---|
62 | #endif //QHULL_USES_QT
|
---|
63 |
|
---|
64 | #//Read-only
|
---|
65 | public:
|
---|
66 | const coordT *coordinates() const { return hyperplane_coordinates; }
|
---|
67 | coordT *coordinates() { return hyperplane_coordinates; }
|
---|
68 | int dimension() const { return hyperplane_dimension; }
|
---|
69 | bool isDefined() const { return hyperplane_coordinates!=0 && hyperplane_dimension>0; }
|
---|
70 | coordT offset() const { return hyperplane_offset; }
|
---|
71 |
|
---|
72 | #//Define
|
---|
73 | void defineAs(int hyperplaneDimension, coordT *c, coordT hyperplaneOffset) { QHULL_ASSERT(hyperplaneDimension>=0); hyperplane_coordinates= c; hyperplane_dimension= hyperplaneDimension; hyperplane_offset= hyperplaneOffset; }
|
---|
74 | //! Creates an alias to other
|
---|
75 | void defineAs(QhullHyperplane &other) { hyperplane_coordinates= other.coordinates(); hyperplane_dimension= other.dimension(); hyperplane_offset= other.offset(); }
|
---|
76 | void setCoordinates(coordT *c) { hyperplane_coordinates= c; }
|
---|
77 | void setDimension(int hyperplaneDimension) { hyperplane_dimension= hyperplaneDimension; }
|
---|
78 | void setOffset(coordT hyperplaneOffset) { hyperplane_offset= hyperplaneOffset; }
|
---|
79 |
|
---|
80 | #//value
|
---|
81 | double distance(const QhullPoint &p) const;
|
---|
82 | double norm() const;
|
---|
83 |
|
---|
84 | #//iterator
|
---|
85 | iterator begin() { return hyperplane_coordinates; }
|
---|
86 | const_iterator begin() const { return hyperplane_coordinates; }
|
---|
87 | const_iterator constBegin() const { return hyperplane_coordinates; }
|
---|
88 | const_iterator constEnd() const { return hyperplane_coordinates+hyperplane_dimension; }
|
---|
89 | int count() { return dimension(); }
|
---|
90 | iterator end() { return hyperplane_coordinates+hyperplane_dimension; }
|
---|
91 | const_iterator end() const { return hyperplane_coordinates+hyperplane_dimension; }
|
---|
92 | size_t size() { return (size_t)dimension(); }
|
---|
93 |
|
---|
94 | #//Operator
|
---|
95 | bool operator==(const QhullHyperplane &other) const;
|
---|
96 | bool operator!=(const QhullHyperplane &other) const { return !operator==(other); }
|
---|
97 | const coordT &operator[](int idx) const { QHULL_ASSERT(idx>=0 && idx<hyperplane_dimension); return *(hyperplane_coordinates+idx); }
|
---|
98 | coordT &operator[](int idx) { QHULL_ASSERT(idx>=0 && idx<hyperplane_dimension); return *(hyperplane_coordinates+idx); }
|
---|
99 |
|
---|
100 | #//IO
|
---|
101 | struct PrintHyperplane{
|
---|
102 | const QhullHyperplane *hyperplane;
|
---|
103 | const char *print_message;
|
---|
104 | const char *hyperplane_offset_message;
|
---|
105 | PrintHyperplane(const char *message, const char *offsetMessage, const QhullHyperplane &p) : hyperplane(&p), print_message(message), hyperplane_offset_message(offsetMessage) {}
|
---|
106 | };//PrintHyperplane
|
---|
107 | PrintHyperplane print() const { return PrintHyperplane(0, 0, *this); }
|
---|
108 | PrintHyperplane print(const char *message, const char *offsetMessage) const { return PrintHyperplane(message, offsetMessage, *this); }
|
---|
109 |
|
---|
110 | };//QhullHyperplane
|
---|
111 |
|
---|
112 | QHULL_DECLARE_SEQUENTIAL_ITERATOR(QhullHyperplane, coordT)
|
---|
113 |
|
---|
114 | }//namespace orgQhull
|
---|
115 |
|
---|
116 | #//Global functions
|
---|
117 |
|
---|
118 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullHyperplane::PrintHyperplane &pr);
|
---|
119 | std::ostream &operator<<(std::ostream &os, const orgQhull::QhullHyperplane &p); //FIXUP QH11015 -- multiple instances if define here
|
---|
120 |
|
---|
121 | #endif // QHHYPERPLANE_H
|
---|
122 |
|
---|