Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, 00006 are permitted provided that the following conditions are met: 00007 00008 Redistributions of source code must retain the above copyright notice, this list of 00009 conditions and the following disclaimer. Redistributions in binary form must reproduce 00010 the above copyright notice, this list of conditions and the following disclaimer 00011 in the documentation and/or other materials provided with the distribution. 00012 00013 Neither the name of the Johns Hopkins University nor the names of its contributors 00014 may be used to endorse or promote products derived from this software without specific 00015 prior written permission. 00016 00017 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 00018 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 00019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00020 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00022 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00023 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00024 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00025 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00026 DAMAGE. 00027 */ 00028 00029 #ifndef __VECTOR_HPP 00030 #define __VECTOR_HPP 00031 00032 #define Assert assert 00033 #include <assert.h> 00034 00035 00036 namespace pcl 00037 { 00038 namespace poisson 00039 { 00040 template<class T> 00041 class Vector 00042 { 00043 public: 00044 Vector(); 00045 Vector( const Vector<T>& V ); 00046 Vector( size_t N ); 00047 Vector( size_t N, T* pV ); 00048 ~Vector(); 00049 00050 const T& operator () (size_t i) const; 00051 T& operator () (size_t i); 00052 const T& operator [] (size_t i) const; 00053 T& operator [] (size_t i); 00054 00055 void SetZero(); 00056 00057 size_t Dimensions() const; 00058 void Resize( size_t N ); 00059 00060 Vector operator * (const T& A) const; 00061 Vector operator / (const T& A) const; 00062 Vector operator - (const Vector& V) const; 00063 Vector operator + (const Vector& V) const; 00064 00065 Vector& operator *= (const T& A); 00066 Vector& operator /= (const T& A); 00067 Vector& operator += (const Vector& V); 00068 Vector& operator -= (const Vector& V); 00069 00070 Vector& AddScaled(const Vector& V,const T& scale); 00071 Vector& SubtractScaled(const Vector& V,const T& scale); 00072 static void Add(const Vector& V1,const T& scale1,const Vector& V2,const T& scale2,Vector& Out); 00073 static void Add(const Vector& V1,const T& scale1,const Vector& V2,Vector& Out); 00074 00075 Vector operator - () const; 00076 00077 Vector& operator = (const Vector& V); 00078 00079 T Dot( const Vector& V ) const; 00080 00081 T Length() const; 00082 00083 T Norm( size_t Ln ) const; 00084 void Normalize(); 00085 00086 bool write( FILE* fp ) const; 00087 bool write( const char* fileName ) const; 00088 bool read( FILE* fp ); 00089 bool read( const char* fileName ); 00090 00091 T* m_pV; 00092 protected: 00093 size_t m_N; 00094 00095 }; 00096 00097 template<class T,int Dim> 00098 class NVector 00099 { 00100 public: 00101 NVector(); 00102 NVector( const NVector& V ); 00103 NVector( size_t N ); 00104 NVector( size_t N, T* pV ); 00105 ~NVector(); 00106 00107 const T* operator () (size_t i) const; 00108 T* operator () (size_t i); 00109 const T* operator [] (size_t i) const; 00110 T* operator [] (size_t i); 00111 00112 void SetZero(); 00113 00114 size_t Dimensions() const; 00115 void Resize( size_t N ); 00116 00117 NVector operator * (const T& A) const; 00118 NVector operator / (const T& A) const; 00119 NVector operator - (const NVector& V) const; 00120 NVector operator + (const NVector& V) const; 00121 00122 NVector& operator *= (const T& A); 00123 NVector& operator /= (const T& A); 00124 NVector& operator += (const NVector& V); 00125 NVector& operator -= (const NVector& V); 00126 00127 NVector& AddScaled(const NVector& V,const T& scale); 00128 NVector& SubtractScaled(const NVector& V,const T& scale); 00129 static void Add(const NVector& V1,const T& scale1,const NVector& V2,const T& scale2,NVector& Out); 00130 static void Add(const NVector& V1,const T& scale1,const NVector& V2, NVector& Out); 00131 00132 NVector operator - () const; 00133 00134 NVector& operator = (const NVector& V); 00135 00136 T Dot( const NVector& V ) const; 00137 00138 T Length() const; 00139 00140 T Norm( size_t Ln ) const; 00141 void Normalize(); 00142 00143 T* m_pV; 00144 protected: 00145 size_t m_N; 00146 00147 }; 00148 00149 } 00150 } 00151 00152 00153 #include "vector.hpp" 00154 00155 #endif