SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PointVectorOperators.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 /// @todo Documentation Core/GeometryPrimitives/PointVectorOperators.h
34 
35 #ifndef CORE_GEOMETRY_POINTVECTOROPERATORS_H
36 #define CORE_GEOMETRY_POINTVECTOROPERATORS_H
37 
41 
42 namespace SCIRun {
43 namespace Core {
44 namespace Geometry {
45 
46  inline Point& Point::operator+=(const Vector& v)
47  {
48  d_[0]+=v.d_[0];
49  d_[1]+=v.d_[1];
50  d_[2]+=v.d_[2];
51  return *this;
52  }
53 
54  inline Point& Point::operator-=(const Vector& v)
55  {
56  d_[0]-=v.d_[0];
57  d_[1]-=v.d_[1];
58  d_[2]-=v.d_[2];
59  return *this;
60  }
61 
62  inline Vector::Vector(const Point& p)
63  {
64  d_[0] = p[0];
65  d_[1] = p[1];
66  d_[2] = p[2];
67  }
68 
69  inline Vector Point::operator+(const Point& p) const
70  {
71  return Vector(d_[0]+p.d_[0], d_[1]+p.d_[1], d_[2]+p.d_[2]);
72  }
73 
74  inline Vector Point::operator-(const Point& p) const
75  {
76  return Vector(d_[0]-p.d_[0], d_[1]-p.d_[1], d_[2]-p.d_[2]);
77  }
78 
79  inline Point Point::operator+(const Vector& v) const
80  {
81  return Point(d_[0]+v.d_[0], d_[1]+v.d_[1], d_[2]+v.d_[2]);
82  }
83 
84  inline Point Point::operator-(const Vector& v) const
85  {
86  return Point(d_[0]-v.d_[0], d_[1]-v.d_[1], d_[2]-v.d_[2]);
87  }
88 
89  inline double Dot(const Vector& v1, const Vector& v2)
90  {
91  return v1.d_[0]*v2.d_[0]+v1.d_[1]*v2.d_[1]+v1.d_[2]*v2.d_[2];
92  }
93 
94  inline double Dot(const Vector& v, const Point& p)
95  {
96  return v[0]*p[0]+v[1]*p[1]+v[2]*p[2];
97  }
98  inline Vector Vector::operator-(const Point& v2) const
99  {
100  return Vector(d_[0]-v2[0], d_[1]-v2[1], d_[2]-v2[2]);
101  }
102 
103 
104  inline Point::Point(const Vector& v)
105  {
106  d_[0] = v.d_[0];
107  d_[1] = v.d_[1];
108  d_[2] = v.d_[2];
109  }
110 
111 
112  inline Point& Point::operator-=(const Point& v)
113  {
114  d_[0]-=v.d_[0];
115  d_[1]-=v.d_[1];
116  d_[2]-=v.d_[2];
117  return *this;
118  }
119 
120 
121 
122 
123  inline Point& Point::operator/=(const double d)
124  {
125  d_[0]/=d;
126  d_[1]/=d;
127  d_[2]/=d;
128  return *this;
129  }
130 
131  inline Point Point::operator-() const
132  {
133  return Point(-d_[0], -d_[1], -d_[2]);
134  }
135 
136  inline Point Point::operator*(double d) const
137  {
138  return Point(d_[0]*d, d_[1]*d, d_[2]*d);
139  }
140 
141  inline Point Point::operator/(const double d) const
142  {
143  return Point(d_[0]/d,d_[1]/d,d_[2]/d);
144  }
145 
146  inline double& Point::operator()(int idx)
147  {
148  return d_[idx];
149  }
150 
151  inline double Point::operator()(int idx) const
152  {
153  return d_[idx];
154  }
155 
156  inline Point Interpolate(const Point& v1, const Point& v2,
157  double weight)
158  {
159  double weight1 = 1.0 - weight;
160  return Point(v2[0]*weight+v1[0]*weight1,
161  v2[1]*weight+v1[1]*weight1,
162  v2[2]*weight+v1[2]*weight1);
163  }
164 
165  inline void Point::addscaled(const Point& p, const double scale)
166  {
167  // this += p * w;
168  d_[0] += p.d_[0] * scale;
169  d_[1] += p.d_[1] * scale;
170  d_[2] += p.d_[2] * scale;
171  }
172 
173  inline double Dot(const Point& p, const Vector& v)
174  {
175  return p[0]*v[0]+p[1]*v[1]+p[2]*v[2];
176  }
177 
178  inline double Dot(const Point& p1, const Point& p2)
179  {
180  return p1[0]*p2[0] + p1[1]*p2[1] + p1[2]*p2[2];
181  }
182 }}}
183 
184 
185 #endif
Vector()
Definition: Vector.h:153
double & operator()(int idx)
Definition: PointVectorOperators.h:146
Vector operator-() const
Definition: Vector.h:360
Point & operator/=(const double)
Definition: PointVectorOperators.h:123
void addscaled(const Point &p, const double scale)
Definition: PointVectorOperators.h:165
Definition: Point.h:49
Point operator*(double) const
Definition: PointVectorOperators.h:136
Point()
Definition: Point.h:110
Definition: Vector.h:63
Point Interpolate(const Point &v1, const Point &v2, double weight)
Definition: PointVectorOperators.h:156
Point operator-() const
Definition: PointVectorOperators.h:131
v
Definition: readAllFields.py:42
Point operator/(const double) const
Definition: PointVectorOperators.h:141
Point & operator+=(const Vector &)
Definition: PointVectorOperators.h:46
double Dot(const Vector &v1, const Vector &v2)
Definition: PointVectorOperators.h:89
Point & operator-=(const Vector &)
Definition: PointVectorOperators.h:54
Vector operator+(const Point &) const
Definition: PointVectorOperators.h:69