|
|
|||
File indexing completed on 2026-06-02 08:48:23
0001 #ifndef VECTOR_D_H 0002 #define VECTOR_D_H 0003 0004 /** 0005 * @file VectorD.h 0006 * @author Bryan BERTHOU (SPhN / CEA Saclay) 0007 * @date 07 September 2015 0008 * @version 1.0 0009 */ 0010 0011 #include <string> 0012 #include <vector> 0013 #include <stddef.h> 0014 0015 //#include "../matrix/MatrixD.h" 0016 0017 namespace NumA { 0018 class Vector2D; 0019 class Vector3D; 0020 class Vector4D; 0021 } /* namespace NumA */ 0022 0023 namespace NumA { 0024 0025 class MatrixD; 0026 0027 /** 0028 * @class VectorD 0029 * 0030 * @brief Object representing a mathematical vector. 0031 */ 0032 0033 class VectorD { 0034 public: 0035 /** 0036 * Default constructor. 0037 */ 0038 VectorD(); 0039 0040 /** 0041 * Construct a vector of given size initialized at 0. 0042 * @param size Size of the vector. 0043 */ 0044 VectorD(size_t size); 0045 0046 /** 0047 * Construct a vector of given size initialized at initValue. 0048 * @param size Size of the vector. 0049 * @param initValue Default value for the coefficients. 0050 */ 0051 VectorD(size_t size, double initValue); 0052 0053 /** 0054 * Copy constructor. 0055 * @param vector std::vector<double> 0056 */ 0057 VectorD(const std::vector<double> &vector); 0058 0059 /** 0060 * Copy constructor. 0061 * @param vector VectorD 0062 */ 0063 VectorD(const VectorD &vector); 0064 0065 /** 0066 * Copy constructor. 0067 * @param vector Vector2D 0068 */ 0069 VectorD(const Vector2D &vector); 0070 0071 /** 0072 * Copy constructor. 0073 * @param vector Vector3D 0074 */ 0075 VectorD(const Vector3D &vector); 0076 0077 /** 0078 * Copy constructor. 0079 * @param vector Vector4D 0080 */ 0081 VectorD(const Vector4D &vector); 0082 0083 /** 0084 * Default destructor. 0085 */ 0086 virtual ~VectorD(); 0087 0088 void push_back(double value); ///< Same as std::vector. 0089 void resize(size_t n, double value = 0.); ///< Same as std::vector. 0090 void assign(size_t n, double value = 0.); ///< Same as std::vector. 0091 0092 /** 0093 * @return size_t Size of the vector. 0094 */ 0095 size_t size() const; 0096 0097 /** 0098 * Returns a subset of the vector: [startPos:endPos[ 0099 * @param startPos 0100 * @param endPos 0101 * @return VectorD 0102 */ 0103 VectorD sub(size_t startPos, size_t endPos) const; 0104 0105 /** 0106 * Scalar product. 0107 * @param rhs VectorD of same size. 0108 * @return double 0109 */ 0110 double operator *(const VectorD &rhs) const; 0111 0112 /** 0113 * Subtraction. 0114 * @param rhs VectorD of same size. 0115 * @return VectorD of same size. 0116 */ 0117 VectorD operator -(const VectorD &rhs) const; 0118 /** 0119 * Addition. 0120 * @param rhs VectorD of same size. 0121 * @return VectorD of same size. 0122 */ 0123 VectorD operator +(const VectorD &rhs) const; 0124 0125 // Vector/double operations 0126 /** 0127 * Multiplication of all coefficients by a scalar. 0128 * @param rhs Scalar. 0129 * @return Vector. 0130 */ 0131 VectorD operator*(double rhs) const; 0132 /** 0133 * Addition of all coefficients with a scalar. 0134 * @param rhs Scalar. 0135 * @return Vector. 0136 */ 0137 VectorD operator+(double rhs) const; 0138 /** 0139 * Subtraction of all coefficient with a scalar. 0140 * @param rhs Scalar. 0141 * @return Vector. 0142 */ 0143 VectorD operator-(double rhs) const; 0144 /** 0145 * Division of all coefficients by a scalar. 0146 * @param rhs Scalar. 0147 * @return Vector. 0148 */ 0149 VectorD operator/(double rhs) const; 0150 0151 /** 0152 * Norm 2. 0153 * @return double 0154 */ 0155 double norm() const; 0156 0157 /** 0158 * Conversion to a matrix of one column. 0159 * @return MatrixD typed vector column. 0160 */ 0161 MatrixD toMatrix(); 0162 0163 /** 0164 * Direct accessor in memory with the specified index value n. 0165 * @param n 0166 * @return double 0167 */ 0168 double& operator [](size_t n); 0169 double& at(size_t n); ///< Same as std::vector. 0170 0171 /** 0172 * Direct accessor in memory with the specified index value n. 0173 * @param n 0174 * @return double 0175 */ 0176 const double& operator [](size_t n) const; 0177 const double& at(size_t n) const; ///< Same as std::vector. 0178 0179 /** 0180 * Concatenation of two vectors. 0181 * @param V1 0182 * @param V2 0183 * @return VectorD of size V1.size() + V2.size() 0184 */ 0185 static VectorD concatenate(const VectorD& V1, const VectorD& V2); 0186 0187 const std::vector<double>& toStdVector() const; ///< Conversion to std::vector. 0188 0189 /** 0190 * Return a formatted characters string to display vector's values. 0191 * 0192 * @return std::string 0193 */ 0194 std::string toString() const; 0195 0196 private: 0197 std::vector<double> m_vector; ///< An array of double to represent the vector in memory. 0198 }; 0199 0200 } /* namespace NumA */ 0201 0202 #endif /* VECTOR_D_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|