Text archives Help
- From: sparker@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1242 - trunk/Core/Geometry
- Date: Sat, 2 Dec 2006 03:38:43 -0700 (MST)
Author: sparker
Date: Sat Dec 2 03:38:42 2006
New Revision: 1242
Modified:
trunk/Core/Geometry/Vector.h
trunk/Core/Geometry/VectorT.h
Log:
Implemented new operators used by the rtsl compiler. There are a few
versions of operator- that are #if 0'd out because they cause a problem
with the objviewer that I have not tracked down yet.
Modified: trunk/Core/Geometry/Vector.h
==============================================================================
--- trunk/Core/Geometry/Vector.h (original)
+++ trunk/Core/Geometry/Vector.h Sat Dec 2 03:38:42 2006
@@ -135,6 +135,19 @@
data[2] += v.data[2];
return *this;
}
+ Vector operator+(Real s) const {
+ Vector result;
+ result.data[0] = data[0] + s;
+ result.data[1] = data[1] + s;
+ result.data[2] = data[2] + s;
+ return result;
+ }
+ Vector& operator+=(Real s) {
+ data[0] += s;
+ data[1] += s;
+ data[2] += s;
+ return *this;
+ }
// - operator
Vector operator-(const Vector& v) const {
@@ -150,6 +163,19 @@
data[2] -= v.data[2];
return *this;
}
+ Vector operator-(Real s) const {
+ Vector result;
+ result.data[0] = data[0] - s;
+ result.data[1] = data[1] - s;
+ result.data[2] = data[2] - s;
+ return result;
+ }
+ Vector& operator-=(Real s) {
+ data[0] -= s;
+ data[1] -= s;
+ data[2] -= s;
+ return *this;
+ }
Vector operator-() const {
Vector result;
result.data[0] = -data[0];
@@ -330,6 +356,39 @@
return Vector(1,1,1);
}
+ Vector findPerpendicular() const {
+ Vector result;
+ float a0 = SCIRun::Abs(data[0]);
+ float a1 = SCIRun::Abs(data[1]);
+ float a2 = SCIRun::Abs(data[2]);
+ if(a0 < a1){
+ if(a0 < a2){
+ // 0 smallest
+ result.data[0] = 0;
+ result.data[1] = -data[2];
+ result.data[2] = data[1];
+ } else {
+ // 2 smallest
+ result.data[0] = -data[1];
+ result.data[1] = data[0];
+ result.data[2] = 0;
+ }
+ } else {
+ if(a1 < a2){
+ // 1 smallest
+ result.data[0] = data[2];
+ result.data[1] = 0;
+ result.data[2] = -data[0];
+ } else {
+ // 2 smallest
+ result.data[0] = -data[1];
+ result.data[1] = data[0];
+ result.data[2] = 0;
+ }
+ }
+ return result;
+ }
+
#ifndef SWIG // Swig balks about these functions, but when I rename
// them it doesn't do anything.
// Friend functions. These will allow the functions to access
@@ -374,6 +433,47 @@
return result;
}
+ template<typename S >
+ inline Vector operator+(S s, const Vector& v)
+ {
+ Real scalar = static_cast<Real>(s);
+ Vector result(scalar + v.data[0],
+ scalar + v.data[1],
+ scalar + v.data[2]);
+ return result;
+ }
+
+ template<typename S >
+ inline Vector operator+(const Vector& v, S s)
+ {
+ Real scalar = static_cast<Real>(s);
+ Vector result(v.data[0] + scalar,
+ v.data[1] + scalar,
+ v.data[2] + scalar);
+ return result;
+ }
+
+#if 0
+ template<typename S >
+ inline Vector operator-(S s, const Vector& v)
+ {
+ Real scalar = static_cast<Real>(s);
+ Vector result(scalar - v.data[0],
+ scalar - v.data[1],
+ scalar - v.data[2]);
+ return result;
+ }
+
+ template<typename S >
+ inline Vector operator-(const Vector& v, S s)
+ {
+ Real scalar = static_cast<Real>(s);
+ Vector result(v.data[0] - scalar,
+ v.data[1] - scalar,
+ v.data[2] - scalar);
+ return result;
+ }
+#endif
inline Real Dot(const Vector& v1, const Vector& v2)
{
return (v1.data[0] * v2.data[0] +
@@ -413,6 +513,15 @@
Vector result(Interpolate(v1.data[0], v2.data[0], weight),
Interpolate(v1.data[1], v2.data[1], weight),
Interpolate(v1.data[2], v2.data[2], weight));
+ return result;
+ }
+
+ inline Vector Interpolate(const Vector& v1, const Vector& v2, const
Vector& weight)
+ {
+ using SCIRun::Interpolate;
+ Vector result(Interpolate(v1.data[0], v2.data[0], weight[0]),
+ Interpolate(v1.data[1], v2.data[1], weight[1]),
+ Interpolate(v1.data[2], v2.data[2], weight[2]));
return result;
}
Modified: trunk/Core/Geometry/VectorT.h
==============================================================================
--- trunk/Core/Geometry/VectorT.h (original)
+++ trunk/Core/Geometry/VectorT.h Sat Dec 2 03:38:42 2006
@@ -143,6 +143,12 @@
result.data[i] = data[i] + v.data[i];
return result;
}
+ VectorT<T, Dim> operator+(T s) const {
+ VectorT<T, Dim> result;
+ for(int i=0;i<Dim;i++)
+ result.data[i] = data[i] + s;
+ return result;
+ }
VectorT<T, Dim>& operator+=(const VectorT<T, Dim>& v) {
for(int i=0;i<Dim;i++)
data[i] += v.data[i];
@@ -154,6 +160,12 @@
result.data[i] = data[i] - v.data[i];
return result;
}
+ VectorT<T, Dim> operator-(T s) const {
+ VectorT<T, Dim> result;
+ for(int i=0;i<Dim;i++)
+ result.data[i] = data[i] - s;
+ return result;
+ }
VectorT<T, Dim>& operator-=(const VectorT<T, Dim>& v) {
for(int i=0;i<Dim;i++)
data[i] -= v.data[i];
@@ -389,6 +401,18 @@
VectorT<T, Dim> result;
for(int i=0;i<Dim;i++)
result[i] = Interpolate(p1[i], p2[i], weight);
+ return result;
+ }
+
+ template<typename T, int Dim>
+ inline VectorT<T, Dim> Interpolate(const VectorT<T, Dim>& p1,
+ const VectorT<T, Dim>& p2,
+ const VectorT<T, Dim>& weight)
+ {
+ using SCIRun::Interpolate;
+ VectorT<T, Dim> result;
+ for(int i=0;i<Dim;i++)
+ result[i] = Interpolate(p1[i], p2[i], weight[i]);
return result;
}
- [MANTA] r1242 - trunk/Core/Geometry, sparker, 12/02/2006
Archive powered by MHonArc 2.6.16.