cmtkVector.txx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //  Copyright 2004-2009 SRI International
00005 //
00006 //  This file is part of the Computational Morphometry Toolkit.
00007 //
00008 //  http://www.nitrc.org/projects/cmtk/
00009 //
00010 //  The Computational Morphometry Toolkit is free software: you can
00011 //  redistribute it and/or modify it under the terms of the GNU General Public
00012 //  License as published by the Free Software Foundation, either version 3 of
00013 //  the License, or (at your option) any later version.
00014 //
00015 //  The Computational Morphometry Toolkit is distributed in the hope that it
00016 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00017 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License along
00021 //  with the Computational Morphometry Toolkit.  If not, see
00022 //  <http://www.gnu.org/licenses/>.
00023 //
00024 //  $Revision: 11 $
00025 //
00026 //  $LastChangedDate: 2009-05-30 11:30:08 -0700 (Sat, 30 May 2009) $
00027 //
00028 //  $LastChangedBy: torstenrohlfing $
00029 //
00030 */
00031 
00032 namespace
00033 cmtk
00034 {
00035 
00038 
00044 template<class T>
00045 Vector<T> operator+ ( const Vector<T>& p, const Vector<T>& delta )
00046 {
00047   assert ( p.Dim == delta.Dim );
00048 
00049   T* Result = Memory::AllocateArray<T>( p.Dim );
00050 #pragma omp parallel for if (p.Dim>1e4)
00051   for ( size_t i=0; i<p.Dim; ++i )
00052     Result[i] = p.Elements[i] + delta.Elements[i];
00053 
00054   return Vector<T>( p.Dim, Result );
00055 }
00056 
00062 template<class T>
00063 inline Vector<T> operator- 
00064 ( const Vector<T>& p, const Vector<T>& delta )
00065 {
00066   assert ( p.Dim == delta.Dim );
00067 
00068   T* Result = Memory::AllocateArray<T>( p.Dim );
00069 #pragma omp parallel for if (p.Dim>1e4)
00070   for ( size_t i=0; i<p.Dim; ++i )
00071     Result[i] = p.Elements[i] - delta.Elements[i];
00072 
00073   return Vector<T>( p.Dim, Result );
00074 }
00075 
00082 template<class T>
00083 Vector<T> operator* ( const T c, const Vector<T>& p ) 
00084 {
00085   T* Result = Memory::AllocateArray<T>( p.Dim );
00086 #pragma omp parallel for if (p.Dim>1e4)
00087   for ( size_t i=0; i<p.Dim; ++i )
00088     Result[i] = c * p.Elements[i];
00089 
00090   return Vector<T>( p.Dim, Result );
00091 }
00092 
00097 template<class T>
00098 Vector<T> CoordMult ( const Vector<T>& p, const Vector<T>& q ) 
00099 {
00100   assert ( p.Dim == q.Dim );
00101 
00102   T* Result = Memory::AllocateArray<T>( p.Dim );
00103 #pragma omp parallel for if (p.Dim>1e4)
00104   for ( size_t i=0; i<p.Dim; ++i )
00105     Result[i] = p.Elements[i] * q.Elements[i];
00106 
00107   return Vector<T>( p.Dim, Result );
00108 }
00109 
00115 template<class T> 
00116 inline T operator* ( const Vector<T>& p, const Vector<T>& q ) 
00117 {
00118   assert ( p.Dim == q.Dim );
00119 
00120   T Result = 0;
00121 #pragma omp parallel for if (p.Dim>1e4)
00122   for ( size_t i=0; i<p.Dim; ++i )
00123     Result += p.Elements[i] * q.Elements[i];
00124 
00125   return Result;
00126 }
00127 
00128 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines