20 #ifndef MIRTK_Vector_H 21 #define MIRTK_Vector_H 23 #include "mirtk/Object.h" 25 #include "mirtk/Math.h" 26 #include "mirtk/Indent.h" 27 #include "mirtk/Cfstream.h" 28 #include "mirtk/Memory.h" 29 #include "mirtk/Array.h" 97 void Resize(
int,
double = .0);
109 operator bool()
const;
118 void Put(
int,
double);
121 const double &
Get(
int)
const;
247 void Permute(
const Array<int> &);
256 void Read(
const char *);
259 void Write(
const char *)
const;
276 bool WriteMAT(
const char *,
const char * =
"A")
const;
283 #include "mirtk/Vector3D.h" 284 #include "mirtk/Vector4D.h" 416 }
else if (
_rows != n) {
417 double *vector =
new double[n];
418 const int m = min(n,
_rows);
419 for (
int i = 0; i < m; ++i) vector[i] =
_vector[i];
420 for (
int i = m; i < n; ++i) vector[i] = value;
428 inline Vector::operator bool()
const 552 return (
Vector(*
this) -= x);
558 return (
Vector(*
this) += x);
564 return (
Vector(*
this) *= x);
570 return (
Vector(*
this) /= x);
614 cerr <<
"Vector::operator-=: Size mismatch" << endl;
625 cerr <<
"Vector::operator+=: Size mismatch" << endl;
636 cerr <<
"Vector::operator*=: Size mismatch" << endl;
647 cerr <<
"Vector::operator/=: Size mismatch" << endl;
657 return (
Vector(*
this) -= v);
663 return (
Vector(*
this) += v);
669 return (
Vector(*
this) *= v);
675 return (
Vector(*
this) /= v);
686 for (
int i = 0; i <
_rows; ++i) {
695 return !(*
this == v);
702 for (
int i = 0; i <
_rows; ++i) {
716 cerr <<
"Vector::ScalarProduct: Size mismatch" << endl;
720 for (
int i = 0; i <
_rows; ++i) {
748 cerr <<
"Vector::CrossProduct: Size mismatch" << endl;
753 for (
int i = 0; i <
_rows; ++i) {
796 double norm =
Norm();
797 if (norm != .0) (*this) /= norm;
804 for (
int i = 0; i <
_rows; i++) {
819 #endif // MIRTK_Vector_H double Mean() const
Compute mean value of vector components.
Vector operator/(double) const
Return result of division by a double.
bool operator!=(const Vector &) const
Comparison operator !=.
Vector & operator/=(double)
Division by a double.
Vector & Put(const Vector3D< T > &)
Initialize from 3D vector.
double Sum() const
Returns sum of a vector components.
void Print(Indent=0) const
Print vector.
const double & Get(int) const
Gets vector value.
Vector CrossProduct(const Vector &) const
Vector/cross product.
Vector & operator-=(double)
Subtraction of a double.
void Permute(const Array< int > &)
Permute vector elements (cf. PermuteRows)
bool operator==(const Vector &) const
Comparison operator ==.
void Write(const char *) const
Write vector to file.
Vector operator-() const
Unary negation operator.
double * _vector
Vector elements.
bool WriteMAT(const char *, const char *="A") const
double * RawPointer(int r=0)
Get pointer to linear memory which stores vector elements.
void Read(const char *)
Read vector from file.
MIRTKCU_API bool fequal(double a, double b, double tol=1e-12)
Vector()
Default constructor.
int Rows() const
Returns number of rows.
double Norm() const
Returns norm of a vector.
double & operator()(int)
Puts vector value.
Vector & operator=(double)
Assignment of double.
Vector operator+(double) const
Return result of addition of a double.
friend ostream & operator<<(ostream &, const Vector &)
Interface to output stream.
double DotProduct(const Vector &) const
Scalar/dot product.
Vector & operator*=(double)
Multiplication with a double.
double ScalarProduct(const Vector &) const
Scalar/dot product.
Vector & Normalize()
Normalize vector.
Vector & Inverse()
Replace each vector element by its inverse.
void PermuteRows(Array< int >)
Permute vector elements.
bool operator<(const Vector &) const
Comparison operator <.
void Resize(int, double=.0)
Change size of vector, preserving existing rows.
Vector operator*(double) const
Return result of multiplication with a double.
void Initialize(int)
Intialize matrix with number of rows.
friend istream & operator>>(istream &, Vector &)
Interface to input stream.
Vector & operator+=(double)
Addition of a double.