vector.hpp
Go to the documentation of this file.
00001 /*
00002   * Software License Agreement (BSD License)
00003   *
00004   *  Point Cloud Library (PCL) - www.pointclouds.org
00005   *  Copyright (c) 2009-2012, Willow Garage, Inc.
00006   *  Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho,
00007   *                      Johns Hopkins University
00008   *
00009   *  All rights reserved.
00010   *
00011   *  Redistribution and use in source and binary forms, with or without
00012   *  modification, are permitted provided that the following conditions
00013   *  are met:
00014   *
00015   *   * Redistributions of source code must retain the above copyright
00016   *     notice, this list of conditions and the following disclaimer.
00017   *   * Redistributions in binary form must reproduce the above
00018   *     copyright notice, this list of conditions and the following
00019   *     disclaimer in the documentation and/or other materials provided
00020   *     with the distribution.
00021   *   * Neither the name of Willow Garage, Inc. nor the names of its
00022   *     contributors may be used to endorse or promote products derived
00023   *     from this software without specific prior written permission.
00024   *
00025   *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026   *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027   *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00028   *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00029   *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00030   *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00031   *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00032   *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033   *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00034   *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00035   *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036   *  POSSIBILITY OF SUCH DAMAGE.
00037   *
00038   * $Id: vector.hpp 5036 2012-03-12 08:54:15Z rusu $
00039   *
00040   */
00041 
00042 #ifndef PCL_SURFACE_IMPL_POISSON_VECTOR_H_
00043 #define PCL_SURFACE_IMPL_POISSON_VECTOR_H_
00044 
00045 
00046 
00047 namespace pcl
00048 {
00049   namespace poisson
00050   {
00052     // Vector //
00054     template <class T>
00055     Vector<T>::Vector () : m_pV (0), m_N (0)
00056     {
00057     }
00058 
00059     template <class T>
00060     Vector<T>::Vector (const Vector<T> &V) : m_pV (0), m_N (0)
00061     {
00062       Resize (V.m_N);
00063       memcpy (m_pV, V.m_pV, m_N*sizeof(T));
00064     }
00065 
00066     template <class T>
00067     Vector<T>::Vector (size_t N) : m_pV (0), m_N (0)
00068     {
00069       Resize (N);
00070     }
00071 
00072     template <class T> void
00073     Vector<T>::Resize (size_t N)
00074     {
00075       if (m_N!=N)
00076       {
00077         if (m_N)
00078         {
00079           delete[] m_pV;
00080         }
00081         m_pV=NULL;
00082         m_N = N;
00083         if (N)
00084         {
00085           m_pV = new T[N];
00086         }
00087       }
00088       memset (m_pV, 0, N*sizeof(T));
00089     }
00090 
00091     template <class T>
00092     Vector<T>::Vector (size_t N, T *pV)
00093     {
00094       Resize (N);
00095       memcpy (m_pV, pV, N*sizeof(T));
00096     }
00097 
00098     template <class T>
00099     Vector<T>::~Vector (){Resize (0); }
00100 
00101     template <class T> Vector<T>&
00102     Vector<T>::operator = (const Vector &V)
00103     {
00104       Resize (V.m_N);
00105       memcpy (m_pV, V.m_pV, m_N*sizeof(T));
00106       return *this;
00107     }
00108 
00109     template <class T> size_t
00110     Vector<T>::Dimensions () const {return m_N; }
00111 
00112     template <class T> void
00113     Vector<T>::SetZero (void)
00114     {
00115       for (size_t i=0; i<m_N; i++)
00116         m_pV[i] = T (0);
00117     }
00118 
00119     template <class T> const T&
00120     Vector<T>::operator () (size_t i) const
00121     {
00122       Assert (i < m_N);
00123       return m_pV[i];
00124     }
00125 
00126     template <class T> T&
00127     Vector<T>::operator () (size_t i)
00128     {
00129       return m_pV[i];
00130     }
00131 
00132     template <class T> const T&
00133     Vector<T>::operator [] (size_t i) const
00134     {
00135       return m_pV[i];
00136     }
00137 
00138     template <class T> T&
00139     Vector<T>::operator [] (size_t i)
00140     {
00141       return m_pV[i];
00142     }
00143 
00144     template <class T> Vector<T>
00145     Vector<T>::operator * (const T &A) const
00146     {
00147       Vector V (*this);
00148       for (size_t i=0; i<m_N; i++)
00149         V.m_pV[i] *= A;
00150       return V;
00151     }
00152 
00153     template <class T> Vector<T>&
00154     Vector<T>::operator *= (const T &A)
00155     {
00156       for (size_t i=0; i<m_N; i++)
00157         m_pV[i] *= A;
00158       return *this;
00159     }
00160 
00161     template <class T> Vector<T>
00162     Vector<T>::operator / (const T &A) const
00163     {
00164       Vector V (*this);
00165       for (size_t i=0; i<m_N; i++)
00166         V.m_pV[i] /= A;
00167       return V;
00168     }
00169     template <class T> Vector<T>&
00170     Vector<T>::operator /= (const T &A)
00171     {
00172       for (size_t i=0; i<m_N; i++)
00173         m_pV[i] /= A;
00174       return *this;
00175     }
00176     template <class T> Vector<T>
00177     Vector<T>::operator + (const Vector<T> &V0) const
00178     {
00179       Vector<T> V (m_N);
00180       for (size_t i=0; i<m_N; i++)
00181         V.m_pV[i] = m_pV[i] + V0.m_pV[i];
00182 
00183       return V;
00184     }
00185     template <class T> Vector<T>&
00186     Vector<T>::AddScaled (const Vector<T> &V,const T &scale)
00187     {
00188       for (size_t i=0; i<m_N; i++)
00189         m_pV[i] += V.m_pV[i]*scale;
00190 
00191       return *this;
00192     }
00193     template <class T> Vector<T>&
00194     Vector<T>::SubtractScaled (const Vector<T> &V,const T &scale)
00195     {
00196       for (size_t i=0; i<m_N; i++)
00197         m_pV[i] -= V.m_pV[i]*scale;
00198 
00199       return *this;
00200     }
00201     template <class T> void
00202     Vector<T>::Add (const Vector<T> &V1,const T &scale1,const Vector<T> &V2,const T &scale2,Vector<T> &Out)
00203     {
00204       for (size_t i=0; i<V1.m_N; i++)
00205         Out.m_pV[i]=V1.m_pV[i]*scale1+V2.m_pV[i]*scale2;
00206     }
00207     template <class T> void
00208     Vector<T>::Add (const Vector<T> &V1,const T &scale1,const Vector<T> &V2,Vector<T> &Out)
00209     {
00210       for (size_t i=0; i<V1.m_N; i++)
00211         Out.m_pV[i]=V1.m_pV[i]*scale1+V2.m_pV[i];
00212     }
00213     template <class T> Vector<T>&
00214     Vector<T>::operator += (const Vector<T> &V)
00215     {
00216       for (size_t i=0; i<m_N; i++)
00217         m_pV[i] += V.m_pV[i];
00218 
00219       return *this;
00220     }
00221     template <class T> Vector<T>
00222     Vector<T>::operator - (const Vector<T> &V0) const
00223     {
00224       Vector<T> V (m_N);
00225       for (size_t i=0; i<m_N; i++)
00226         V.m_pV[i] = m_pV[i] - V0.m_pV[i];
00227 
00228       return V;
00229     }
00230     template <class T> Vector<T>
00231     Vector<T>::operator - (void) const
00232     {
00233       Vector<T> V (m_N);
00234 
00235       for (size_t i=0; i<m_N; i++)
00236         V.m_pV[i] = - m_pV[i];
00237 
00238       return V;
00239     }
00240     template <class T> Vector<T>&
00241     Vector<T>::operator -= (const Vector<T> &V)
00242     {
00243       for (size_t i=0; i<m_N; i++)
00244         m_pV[i] -= V.m_pV[i];
00245 
00246       return *this;
00247     }
00248     template <class T> T
00249     Vector<T>::Norm (size_t Ln) const
00250     {
00251       T N = T ();
00252       for (size_t i = 0; i<m_N; i++)
00253         N += pow (m_pV[i], static_cast<T> (Ln));
00254       return pow (N, static_cast<T> (1.0) / Ln);
00255     }
00256 
00257     template <class T> void
00258     Vector<T>::Normalize ()
00259     {
00260       T N = 1.0f / Norm (2);
00261       for (size_t i = 0; i<m_N; i++)
00262         m_pV[i] *= N;
00263     }
00264 
00265     template <class T> T
00266     Vector<T>::Length () const
00267     {
00268       T N = T ();
00269       for (size_t i = 0; i<m_N; i++)
00270         N += m_pV[i]*m_pV[i];
00271       return sqrt (N);
00272     }
00273 
00274     template <class T> T
00275     Vector<T>::Dot (const Vector<T> &V) const
00276     {
00277       T V0 = T ();
00278       for (size_t i = 0; i < m_N; i++)
00279         V0 += m_pV[i] * V.m_pV[i];
00280 
00281       return (V0);
00282     }
00283 
00285     // NVector //
00287     template <class T,int Dim>
00288     NVector<T,Dim>::NVector ()
00289     {
00290       m_N = 0;
00291       m_pV = 0;
00292     }
00293     template <class T,int Dim>
00294     NVector<T,Dim>::NVector (const NVector<T,Dim> &V)
00295     {
00296       m_N = 0;
00297       m_pV = 0;
00298       Resize (V.m_N);
00299       memcpy (m_pV, V.m_pV, m_N*sizeof(T)*Dim);
00300     }
00301     template <class T,int Dim>
00302     NVector<T,Dim>::NVector (size_t N)
00303     {
00304       m_N=0;
00305       m_pV=0;
00306       Resize (N);
00307     }
00308     template <class T,int Dim> void
00309     NVector<T,Dim>::Resize (size_t N)
00310     {
00311       if (m_N!=N)
00312       {
00313         if (m_N)
00314         {
00315           delete[] m_pV;
00316         }
00317         m_pV=NULL;
00318         m_N = N;
00319         if (N)
00320         {
00321           m_pV = new T[Dim*N];
00322         }
00323       }
00324       memset (m_pV, 0, N*sizeof(T)*Dim);
00325     }
00326     template <class T,int Dim>
00327     NVector<T,Dim>::NVector (size_t N, T *pV)
00328     {
00329       Resize (N);
00330       memcpy (m_pV, pV, N*sizeof(T)*Dim);
00331     }
00332     template <class T,int Dim>
00333     NVector<T,Dim>::~NVector (){Resize (0); }
00334     template <class T,int Dim> NVector<T,Dim>&
00335     NVector<T,Dim>::operator = (const NVector &V)
00336     {
00337       Resize (V.m_N);
00338       memcpy (m_pV, V.m_pV, m_N*sizeof(T)*Dim);
00339       return *this;
00340     }
00341     template <class T,int Dim> size_t
00342     NVector<T,Dim>::Dimensions () const {return m_N; }
00343     template <class T,int Dim> void
00344     NVector<T,Dim>::SetZero (void){for (size_t i=0; i<m_N*Dim; i++)
00345                                    {
00346                                      m_pV[i] = T (0);
00347                                    }
00348     }
00349     template <class T,int Dim> const T*
00350     NVector<T,Dim>::operator () (size_t i) const
00351     {
00352       Assert (i < m_N);
00353       return &m_pV[i*Dim];
00354     }
00355     template <class T,int Dim> T*
00356     NVector<T,Dim>::operator () (size_t i)
00357     {
00358       return &m_pV[i*Dim];
00359     }
00360     template <class T,int Dim> const T*
00361     NVector<T,Dim>::operator [] (size_t i) const
00362     {
00363       return &m_pV[i*Dim];
00364     }
00365     template <class T,int Dim> T*
00366     NVector<T,Dim>::operator [] (size_t i)
00367     {
00368       return &m_pV[i*Dim];
00369     }
00370     template <class T,int Dim> NVector<T,Dim>
00371     NVector<T,Dim>::operator * (const T &A) const
00372     {
00373       NVector<T,Dim> V (*this);
00374       for (size_t i=0; i<m_N*Dim; i++)
00375         V.m_pV[i] *= A;
00376       return V;
00377     }
00378     template <class T,int Dim> NVector<T,Dim>&
00379     NVector<T,Dim>::operator *= (const T &A)
00380     {
00381       for (size_t i=0; i<m_N*Dim; i++)
00382         m_pV[i] *= A;
00383       return *this;
00384     }
00385     template <class T,int Dim> NVector<T,Dim>
00386     NVector<T,Dim>::operator / (const T &A) const
00387     {
00388       NVector<T,Dim> V (*this);
00389       for (size_t i=0; i<m_N*Dim; i++)
00390         V.m_pV[i] /= A;
00391       return V;
00392     }
00393     template <class T,int Dim> NVector<T,Dim>&
00394     NVector<T,Dim>::operator /= (const T &A)
00395     {
00396       for (size_t i=0; i<m_N*Dim; i++)
00397         m_pV[i] /= A;
00398       return *this;
00399     }
00400     template <class T,int Dim> NVector<T,Dim>
00401     NVector<T,Dim>::operator + (const NVector<T,Dim> &V0) const
00402     {
00403       NVector<T,Dim> V (m_N);
00404       for (size_t i=0; i<m_N*Dim; i++)
00405         V.m_pV[i] = m_pV[i] + V0.m_pV[i];
00406 
00407       return V;
00408     }
00409     template <class T,int Dim> NVector<T,Dim>&
00410     NVector<T,Dim>::AddScaled (const NVector<T,Dim> &V,const T &scale)
00411     {
00412       for (size_t i=0; i<m_N*Dim; i++)
00413         m_pV[i] += V.m_pV[i]*scale;
00414 
00415       return *this;
00416     }
00417     template <class T,int Dim> NVector<T,Dim>&
00418     NVector<T,Dim>::SubtractScaled (const NVector<T,Dim> &V,const T &scale)
00419     {
00420       for (size_t i=0; i<m_N*Dim; i++)
00421         m_pV[i] -= V.m_pV[i]*scale;
00422 
00423       return *this;
00424     }
00425     template <class T,int Dim> void
00426     NVector<T,Dim>::Add (const NVector<T,Dim> &V1,const T &scale1,const NVector<T,Dim> &V2,const T &scale2,NVector<T,
00427                                                                                                                    Dim>
00428                          &Out)
00429     {
00430       for (size_t i=0; i<V1.m_N*Dim; i++)
00431         Out.m_pV[i]=V1.m_pV[i]*scale1+V2.m_pV[i]*scale2;
00432     }
00433     template <class T,int Dim> void
00434     NVector<T,Dim>::Add (const NVector<T,Dim> &V1,const T &scale1,const NVector<T,Dim> &V2,NVector<T,Dim> &Out)
00435     {
00436       for (size_t i=0; i<V1.m_N*Dim; i++)
00437         Out.m_pV[i]=V1.m_pV[i]*scale1+V2.m_pV[i];
00438     }
00439     template <class T,int Dim> NVector<T,Dim>&
00440     NVector<T,Dim>::operator += (const NVector<T,Dim> &V)
00441     {
00442       for (size_t i=0; i<m_N*Dim; i++)
00443         m_pV[i] += V.m_pV[i];
00444 
00445       return *this;
00446     }
00447     template <class T,int Dim> NVector<T,Dim>
00448     NVector<T,Dim>::operator - (const NVector<T,Dim> &V0) const
00449     {
00450       NVector<T,Dim> V (m_N);
00451       for (size_t i=0; i<m_N*Dim; i++)
00452         V.m_pV[i] = m_pV[i] - V0.m_pV[i];
00453 
00454       return V;
00455     }
00456     template <class T,int Dim> NVector<T,Dim>
00457     NVector<T,Dim>::operator - (void) const
00458     {
00459       NVector<T,Dim> V (m_N);
00460 
00461       for (size_t i=0; i<m_N*Dim; i++)
00462         V.m_pV[i] = - m_pV[i];
00463 
00464       return V;
00465     }
00466     template <class T,int Dim> NVector<T,Dim>&
00467     NVector<T,Dim>::operator -= (const NVector<T,Dim> &V)
00468     {
00469       for (size_t i=0; i<m_N*Dim; i++)
00470         m_pV[i] -= V.m_pV[i];
00471 
00472       return *this;
00473     }
00474     template <class T,int Dim> T
00475     NVector<T,Dim>::Norm (size_t Ln) const
00476     {
00477       T N = T ();
00478       for (size_t i = 0; i<m_N*Dim; i++)
00479         N += pow (m_pV[i], static_cast<T> (Ln));
00480       return pow (N, static_cast<T> (1.0) / Ln);
00481     }
00482     template <class T,int Dim> void
00483     NVector<T,Dim>::Normalize ()
00484     {
00485       T N = 1.0f/Norm (2);
00486       for (size_t i = 0; i<m_N*3; i++)
00487         m_pV[i] *= N;
00488     }
00489     template <class T,int Dim> T
00490     NVector<T,Dim>::Length () const
00491     {
00492       T N = T ();
00493       for (size_t i = 0; i<m_N*Dim; i++)
00494         N += m_pV[i]*m_pV[i];
00495       return sqrt (N);
00496     }
00497     template <class T,int Dim> T
00498     NVector<T,Dim>::Dot (const NVector<T,Dim> &V) const
00499     {
00500       T V0 = T ();
00501       for (size_t i=0; i<m_N*Dim; i++)
00502         V0 += m_pV[i]*V.m_pV[i];
00503 
00504       return V0;
00505     }
00506 
00507   }
00508 }
00509 #endif /* PCL_SURFACE_IMPL_POISSON_VECTOR_H_ */


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:18:55