SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Point.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 ///////////////////////////
30 // PORTED SCIRUN v4 CODE //
31 ///////////////////////////
32 
33 #ifndef CORE_GEOMETRY_POINT_H
34 #define CORE_GEOMETRY_POINT_H
35 
36 #include <string>
37 #include <vector>
38 #include <algorithm>
42 
43 namespace SCIRun {
44 namespace Core {
45 namespace Geometry {
46 
47  class Vector;
48 
49 class Point
50 {
51 private:
52  double d_[3];
53 public:
54  inline explicit Point(const Vector& v);
55  inline Point(double x, double y, double z)
56  { d_[0] = x; d_[1] = y; d_[2] = z; }
57  SCISHARE Point(double, double, double, double);
58  inline Point(const Point&);
59  inline Point();
60  inline Point& operator=(const Point&);
61  inline Vector operator+(const Point&) const;
62  inline Vector operator-(const Point&) const;
63  inline Point operator+(const Vector&) const;
64  inline Point operator-(const Vector&) const;
65  inline Point operator*(double) const;
66  inline Point& operator*=(const double);
67  Point& operator+=(const Vector&);
68  Point& operator-=(const Vector&);
69  inline Point& operator+=(const Point&);
70  inline Point& operator-=(const Point&);
71  inline Point& operator/=(const double);
72  inline Point operator/(const double) const;
73  inline Point operator-() const;
74  inline double& operator()(int idx);
75  inline double operator()(int idx) const;
76  inline void addscaled(const Point& p, const double scale); // this += p * w;
77  inline void x(const double);
78  inline double x() const;
79  inline void y(const double);
80  inline double y() const;
81  inline void z(const double);
82  inline double z() const;
83 
84  inline double& operator[](int idx)
85  {
86  return d_[idx];
87  }
88 
89  inline double operator[](int idx) const
90  {
91  return d_[idx];
92  }
93 
94  SCISHARE std::string get_string() const;
95 
96  SCISHARE friend std::ostream& operator<<(std::ostream& os, const Point& p);
97  SCISHARE friend std::istream& operator>>(std::istream& os, Point& p);
98 };
99 
100 SCISHARE bool operator==(const Point& p1, const Point& p2);
101 SCISHARE bool operator!=(const Point& p1, const Point& p2);
102 
103 inline Point::Point(const Point& p)
104 {
105  d_[0] = p.d_[0];
106  d_[1] = p.d_[1];
107  d_[2] = p.d_[2];
108 }
109 
110 inline Point::Point()
111 {
112  d_[0] = 0.0;
113  d_[1] = 0.0;
114  d_[2] = 0.0;
115 }
116 
117 inline Point& Point::operator=(const Point& p)
118 {
119  d_[0] = p.d_[0];
120  d_[1] = p.d_[1];
121  d_[2] = p.d_[2];
122  return *this;
123 }
124 
125 inline void Point::x(const double d)
126 {
127  d_[0]=d;
128 }
129 
130 inline double Point::x() const
131 {
132  return d_[0];
133 }
134 
135 inline void Point::y(const double d)
136 {
137  d_[1]=d;
138 }
139 
140 inline double Point::y() const
141 {
142  return d_[1];
143 }
144 
145 inline void Point::z(const double d)
146 {
147  d_[2]=d;
148 }
149 
150 inline double Point::z() const
151 {
152  return d_[2];
153 }
154 
155 inline Point& Point::operator*=(const double d)
156 {
157  d_[0]*=d;
158  d_[1]*=d;
159  d_[2]*=d;
160  return *this;
161 }
162 
164 {
165  d_[0]+=v.d_[0];
166  d_[1]+=v.d_[1];
167  d_[2]+=v.d_[2];
168  return *this;
169 }
170 
171 // Actual declarations of these functions (as 'friend' above doesn't
172 // (depending on the compiler) actually declare them.
173 SCISHARE Point AffineCombination(const Point&, double, const Point&, double,
174  const Point&, double, const Point&, double);
175 SCISHARE Point AffineCombination(const Point&, double, const Point&, double,
176  const Point&, double);
177 SCISHARE Point AffineCombination(const Point&, double, const Point&, double);
178 
179 SCISHARE void Pio( Piostream&, Point& );
180 
181 inline
182 Point operator*(double d, const Point &p) {
183  return p*d;
184 }
185 inline
186 Point operator+(const Vector &v, const Point &p) {
187  return p+v;
188 }
189 
190 SCISHARE std::ostream& operator<<(std::ostream& os, const Point& p);
191 SCISHARE std::istream& operator>>(std::istream& os, Point& p);
192 SCISHARE Point centroid(const std::vector<Point>& points);
193 
194 inline Point Min(const Point& p1, const Point& p2)
195 {
196  double x=std::min(p1[0], p2[0]);
197  double y=std::min(p1[1], p2[1]);
198  double z=std::min(p1[2], p2[2]);
199  return Point(x,y,z);
200 }
201 
202 inline Point Max(const Point& p1, const Point& p2)
203 {
204  double x=std::max(p1[0], p2[0]);
205  double y=std::max(p1[1], p2[1]);
206  double z=std::max(p1[2], p2[2]);
207  return Point(x,y,z);
208 }
209 
210 
211 }}
212 
213 /// @todo: This one is obsolete when last part dynamic compilation is gone
214 SCISHARE const std::string& Point_get_h_file_path();
215 SCISHARE const SCIRun::TypeDescription* get_type_description(Core::Geometry::Point*);
216 }
217 
219 
220 #endif
SCISHARE std::string get_string() const
Definition: Point.cc:37
Point Min(const Point &p1, const Point &p2)
Definition: Point.h:194
double & operator()(int idx)
Definition: PointVectorOperators.h:146
Definition: Persistent.h:89
SCISHARE const std::string & Point_get_h_file_path()
Definition: Point.cc:165
SCISHARE friend std::ostream & operator<<(std::ostream &os, const Point &p)
SCISHARE Point centroid(const std::vector< Point > &points)
Point & operator/=(const double)
Definition: PointVectorOperators.h:123
void addscaled(const Point &p, const double scale)
Definition: PointVectorOperators.h:165
Definition: Point.h:49
Definition: TypeDescription.h:45
#define SCISHARE
Definition: share.h:39
Point operator*(double) const
Definition: PointVectorOperators.h:136
Point operator+(const Vector &v, const Point &p)
Definition: Point.h:186
Point()
Definition: Point.h:110
SCISHARE std::istream & operator>>(std::istream &os, Point &p)
Definition: Point.cc:105
Definition: Vector.h:63
SCISHARE std::ostream & operator<<(std::ostream &os, const Point &p)
Definition: Point.cc:99
Point operator-() const
Definition: PointVectorOperators.h:131
double & operator[](int idx)
Definition: Point.h:84
v
Definition: readAllFields.py:42
double operator[](int idx) const
Definition: Point.h:89
SCISHARE bool operator!=(const Point &p1, const Point &p2)
Definition: Point.cc:49
Point operator/(const double) const
Definition: PointVectorOperators.h:141
double y() const
Definition: Point.h:140
Point Max(const Point &p1, const Point &p2)
Definition: Point.h:202
Point & operator+=(const Vector &)
Definition: PointVectorOperators.h:46
double x() const
Definition: Point.h:130
SCISHARE Point AffineCombination(const Point &, double, const Point &, double, const Point &, double, const Point &, double)
SCISHARE bool operator==(const Point &p1, const Point &p2)
Definition: Point.cc:44
Point operator*(double d, const Point &p)
Definition: Point.h:182
Point & operator-=(const Vector &)
Definition: PointVectorOperators.h:54
Point & operator*=(const double)
Definition: Point.h:155
SCISHARE friend std::istream & operator>>(std::istream &os, Point &p)
Point & operator=(const Point &)
Definition: Point.h:117
double z() const
Definition: Point.h:150
SCISHARE void Pio(Piostream &, BBox &)
Definition: BBox.cc:134
Vector operator+(const Point &) const
Definition: PointVectorOperators.h:69
Point(double x, double y, double z)
Definition: Point.h:55
const TypeDescription * get_type_description(Core::Basis::ConstantBasis< T > *)
Definition: Constant.h:209