Point Cloud Library (PCL)  1.14.1-dev
vector.h
1 /*
2 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12 
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28 
29 #ifndef __VECTOR_HPP
30 #define __VECTOR_HPP
31 
32 #define Assert assert
33 #include <assert.h>
34 
35 
36 namespace pcl
37 {
38  namespace poisson
39  {
40  template<class T>
41  class Vector
42  {
43  public:
44  Vector();
45  Vector( const Vector<T>& V );
46  Vector( std::size_t N );
47  Vector( std::size_t N, T* pV );
48  ~Vector();
49 
50  const T& operator () (std::size_t i) const;
51  T& operator () (std::size_t i);
52  const T& operator [] (std::size_t i) const;
53  T& operator [] (std::size_t i);
54 
55  void SetZero();
56 
57  std::size_t Dimensions() const;
58  void Resize( std::size_t N );
59 
60  Vector operator * (const T& A) const;
61  Vector operator / (const T& A) const;
62  Vector operator - (const Vector& V) const;
63  Vector operator + (const Vector& V) const;
64 
65  Vector& operator *= (const T& A);
66  Vector& operator /= (const T& A);
67  Vector& operator += (const Vector& V);
68  Vector& operator -= (const Vector& V);
69 
70  Vector& AddScaled(const Vector& V,const T& scale);
71  Vector& SubtractScaled(const Vector& V,const T& scale);
72  static void Add(const Vector& V1,const T& scale1,const Vector& V2,const T& scale2,Vector& Out);
73  static void Add(const Vector& V1,const T& scale1,const Vector& V2,Vector& Out);
74 
75  Vector operator - () const;
76 
77  Vector& operator = (const Vector& V);
78 
79  T Dot( const Vector& V ) const;
80 
81  T Length() const;
82 
83  T Norm( std::size_t Ln ) const;
84  void Normalize();
85 
86  bool write( FILE* fp ) const;
87  bool write( const char* fileName ) const;
88  bool read( FILE* fp );
89  bool read( const char* fileName );
90 
91  T* m_pV;
92  protected:
93  std::size_t m_N;
94 
95  };
96 
97  template<class T,int Dim>
98  class NVector
99  {
100  public:
101  NVector();
102  NVector( const NVector& V );
103  NVector( std::size_t N );
104  NVector( std::size_t N, T* pV );
105  ~NVector();
106 
107  const T* operator () (std::size_t i) const;
108  T* operator () (std::size_t i);
109  const T* operator [] (std::size_t i) const;
110  T* operator [] (std::size_t i);
111 
112  void SetZero();
113 
114  std::size_t Dimensions() const;
115  void Resize( std::size_t N );
116 
117  NVector operator * (const T& A) const;
118  NVector operator / (const T& A) const;
119  NVector operator - (const NVector& V) const;
120  NVector operator + (const NVector& V) const;
121 
122  NVector& operator *= (const T& A);
123  NVector& operator /= (const T& A);
124  NVector& operator += (const NVector& V);
125  NVector& operator -= (const NVector& V);
126 
127  NVector& AddScaled(const NVector& V,const T& scale);
128  NVector& SubtractScaled(const NVector& V,const T& scale);
129  static void Add(const NVector& V1,const T& scale1,const NVector& V2,const T& scale2,NVector& Out);
130  static void Add(const NVector& V1,const T& scale1,const NVector& V2, NVector& Out);
131 
132  NVector operator - () const;
133 
134  NVector& operator = (const NVector& V);
135 
136  T Dot( const NVector& V ) const;
137 
138  T Length() const;
139 
140  T Norm( std::size_t Ln ) const;
141  void Normalize();
142 
143  T* m_pV;
144  protected:
145  std::size_t m_N;
146 
147  };
148 
149  }
150 }
151 
152 
153 #include "vector.hpp"
154 
155 #endif
NVector operator*(const T &A) const
Definition: vector.hpp:360
static void Add(const NVector &V1, const T &scale1, const NVector &V2, const T &scale2, NVector &Out)
Definition: vector.hpp:415
NVector & operator-=(const NVector &V)
Definition: vector.hpp:452
const T * operator[](std::size_t i) const
Definition: vector.hpp:350
NVector & AddScaled(const NVector &V, const T &scale)
Definition: vector.hpp:399
NVector & operator/=(const T &A)
Definition: vector.hpp:383
NVector operator-() const
Definition: vector.hpp:442
void Resize(std::size_t N)
Definition: vector.hpp:309
T Dot(const NVector &V) const
Definition: vector.hpp:483
std::size_t m_N
Definition: vector.h:145
const T * operator()(std::size_t i) const
Definition: vector.hpp:339
std::size_t Dimensions() const
Definition: vector.hpp:335
NVector operator+(const NVector &V) const
Definition: vector.hpp:390
T Norm(std::size_t Ln) const
Definition: vector.hpp:460
NVector & SubtractScaled(const NVector &V, const T &scale)
Definition: vector.hpp:407
NVector & operator+=(const NVector &V)
Definition: vector.hpp:425
NVector operator/(const T &A) const
Definition: vector.hpp:375
NVector & operator=(const NVector &V)
Definition: vector.hpp:328
NVector & operator*=(const T &A)
Definition: vector.hpp:368
const T & operator()(std::size_t i) const
Definition: vector.hpp:95
Vector operator+(const Vector &V) const
Definition: vector.hpp:146
Vector & SubtractScaled(const Vector &V, const T &scale)
Definition: vector.hpp:163
Vector & AddScaled(const Vector &V, const T &scale)
Definition: vector.hpp:155
T Norm(std::size_t Ln) const
Definition: vector.hpp:216
Vector & operator/=(const T &A)
Definition: vector.hpp:139
bool read(FILE *fp)
Definition: vector.hpp:267
Vector & operator+=(const Vector &V)
Definition: vector.hpp:181
Vector operator*(const T &A) const
Definition: vector.hpp:116
static void Add(const Vector &V1, const T &scale1, const Vector &V2, const T &scale2, Vector &Out)
Definition: vector.hpp:171
std::size_t m_N
Definition: vector.h:93
std::size_t Dimensions() const
Definition: vector.hpp:91
void Resize(std::size_t N)
Definition: vector.hpp:63
const T & operator[](std::size_t i) const
Definition: vector.hpp:106
Vector & operator=(const Vector &V)
Definition: vector.hpp:84
T Length() const
Definition: vector.hpp:231
bool write(FILE *fp) const
Definition: vector.hpp:276
Vector & operator-=(const Vector &V)
Definition: vector.hpp:208
Vector operator/(const T &A) const
Definition: vector.hpp:131
Vector operator-() const
Definition: vector.hpp:198
Vector & operator*=(const T &A)
Definition: vector.hpp:124
T Dot(const Vector &V) const
Definition: vector.hpp:239