55 #include <visp3/core/vpColVector.h>
56 #include <visp3/core/vpException.h>
57 #include <visp3/core/vpMath.h>
58 #include <visp3/core/vpDebug.h>
59 #include <visp3/core/vpRotationVector.h>
68 "Cannot add (%dx1) column vector to (%dx1) column vector",
73 for (
unsigned int i=0;i<
rowNum;i++)
74 r[i] = (*
this)[i] + v[i];
84 "Cannot add (%dx1) column vector to (%dx1) column vector",
88 for (
unsigned int i=0;i<
rowNum;i++)
98 "Cannot substract (%dx1) column vector to (%dx1) column vector",
102 for (
unsigned int i=0;i<
rowNum;i++)
120 "Cannot compute the dot product between column vectors with different dimensions (%d) and (%d)",
125 for (
unsigned int i=0;i<
rowNum;i++)
126 r += (*
this)[i] * v[i];
142 for (
unsigned int i=0; i<
rowNum; i++) {
143 for (
unsigned int j=0; j<v.
getCols(); j++) {
144 M[i][j] = (*this)[i] * v[j];
155 "Bad size during vpColVector (%dx1) and vpColVector (%dx1) substraction",
160 for (
unsigned int i=0;i<
rowNum;i++)
161 v[i] = (*
this)[i] - m[i];
221 unsigned int rnrows = r+nrows ;
225 "Bad row dimension (%d > %d) used to initialize vpColVector",
231 for (
unsigned int i=r ; i < rnrows; i++)
238 for (
unsigned int i=0; i< v.
size(); i++)
245 for (
unsigned int i=0; i< p.
size(); i++)
252 for (
unsigned int i=0; i< v.
size(); i++)
260 for(
unsigned int i=0; i< M.
getCols(); i++)
261 (*
this)[i] = M[i][j];
274 "Cannot construct a (%dx1) row vector from a (%dx%d) matrix",
278 for(
unsigned int i=0; i< M.
getRows(); i++)
279 (*
this)[i] = M[i][0];
286 :
vpArray2D<double>(1, (unsigned int)v.size())
288 for(
unsigned int i=0; i< v.size(); i++)
295 :
vpArray2D<double>(1, (unsigned int)v.size())
297 for(
unsigned int i=0; i< v.size(); i++)
298 (*
this)[i] = (double)(v[i]);
323 double *vd = A.
data ;
double *d =
data ;
325 for (
unsigned int i=0; i<
rowNum; i++)
354 double *vd = v.
data ;
double *d =
data ;
356 for (
unsigned int i=0;i<
rowNum;i++)
357 *(vd++) = (*d++) * x;
380 for (
unsigned int i=0;i<
rowNum;i++)
404 for (
unsigned int i=0;i<
rowNum;i++)
432 double *vd = v.
data ;
double *d =
data ;
434 for (
unsigned int i=0;i<
rowNum;i++)
435 *(vd++) = (*d++) / x;
448 "Cannot transform a (%dx%d) matrix into a column vector",
469 resize((
unsigned int)v.size());
470 for(
unsigned int i=0; i<v.size(); i++)
479 resize((
unsigned int)v.size());
480 for(
unsigned int i=0; i<v.size(); i++)
481 (*
this)[i] = (float)v[i];
487 unsigned int k = v.
rowNum ;
507 unsigned int k = tv.
getRows() ;
526 unsigned int k = rv.
getRows() ;
612 for (
unsigned int i=0; i<
rowNum; i++) {
613 for (
unsigned int j=0; j<
colNum; j++) {
625 for (
unsigned int i=0;i<
rowNum;i++)
681 "Cannot compute the dot product: first vector empty")) ;
685 "Cannot compute the dot product: second vector empty")) ;
689 "Cannot compute the dot product between column vectors with different dimensions (%d) and (%d)",
693 double *ad = a.
data ;
double *bd = b.
data ;
696 for (
unsigned int i=0 ; i < a.
getRows() ; i++)
697 c += *(ad++)* *(bd++) ;
731 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
732 *
this /= sqrt(sum_square) ;
747 "Cannot sort content of column vector: vector empty")) ;
751 unsigned int nb_permutation = 1 ;
753 while (nb_permutation !=0 )
756 for (
unsigned int j = v.
getRows()-1 ; j >= i+1 ; j--)
758 if ((tab[j]>tab[j-1]))
760 double tmp = tab[j] ;
781 "Cannot sort content of column vector: vector empty")) ;
785 unsigned int nb_permutation = 1 ;
787 while (nb_permutation !=0 )
790 for (
unsigned int j = v.
getRows()-1 ; j >= i+1 ; j--)
792 if ((tab[j]<tab[j-1]))
794 double tmp = tab[j] ;
897 unsigned int nrA = A.
getRows();
898 unsigned int nrB = B.
getRows();
900 if (nrA == 0 && nrB == 0) {
918 for (
unsigned int i=0; i<nrA; i++)
921 for (
unsigned int i=0; i<nrB; i++)
932 "Cannot compute column vector mean: vector empty")) ;
935 double *vd = v.
data ;
936 for (
unsigned int i=0 ; i < v.
getRows() ; i++)
950 "Cannot compute column vector median: vector empty")) ;
953 std::vector<double> vectorOfDoubles(v.
size());
954 for(
unsigned int i = 0; i < v.
size(); i++) {
955 vectorOfDoubles[i] = v[i];
969 "Cannot compute column vector stdev: vector empty")) ;
972 double mean_value =
mean(v);
973 double sum_squared_diff = 0.0;
974 for(
unsigned int i = 0; i < v.
size(); i++) {
975 sum_squared_diff += (v[i]-mean_value) * (v[i]-mean_value);
978 double divisor = (double) v.
size();
979 if(useBesselCorrection && v.
size() > 1) {
983 return std::sqrt(sum_squared_diff / divisor);
1006 "Cannot compute skew vector of a non 3-dimention vector (%d)",
1011 M[0][0] = 0 ; M[0][1] = -v[2] ; M[0][2] = v[1] ;
1012 M[1][0] = v[2] ; M[1][1] = 0 ; M[1][2] = -v[0] ;
1013 M[2][0] = -v[1] ; M[2][1] = v[0] ; M[2][2] = 0 ;
1031 "Cannot compute the cross product between column vector with dimension %d and %d",
1058 if(
dsize!=nrows*ncols) {
1060 "Cannot reshape (%dx1) column vector in (%dx%d) matrix",
1070 for(
unsigned int j =0; j< ncols; j++)
1071 for(
unsigned int i =0; i< nrows; i++)
1072 M[i][j]=
data[j*ncols+i];
1111 for (
unsigned int j=0; j < v.
size(); j++)
1112 (*
this)[i+j] = v[j];
1137 typedef std::string::size_type size_type;
1142 std::vector<std::string> values(m*n);
1143 std::ostringstream oss;
1144 std::ostringstream ossFixed;
1145 std::ios_base::fmtflags original_flags = oss.flags();
1148 ossFixed.setf ( std::ios::fixed, std::ios::floatfield );
1150 size_type maxBefore=0;
1151 size_type maxAfter=0;
1153 for (
unsigned int i=0;i<m;++i) {
1156 if (oss.str().find(
"e")!=std::string::npos){
1158 ossFixed << (*this)[i];
1159 oss.str(ossFixed.str());
1162 values[i]=oss.str();
1163 size_type thislen=values[i].size();
1164 size_type p=values[i].find(
'.');
1166 if (p==std::string::npos){
1176 size_type totalLength=length;
1180 maxAfter=std::min(maxAfter, totalLength-maxBefore);
1181 if (maxAfter==1) maxAfter=0;
1186 if (intro) s <<intro;
1187 s <<
"["<<m<<
","<<n<<
"]=\n";
1189 for (
unsigned int i=0;i<m;i++) {
1191 size_type p=values[i].find(
'.');
1192 s.setf(std::ios::right, std::ios::adjustfield);
1193 s.width((std::streamsize)maxBefore);
1194 s <<values[i].substr(0,p).c_str();
1197 s.setf(std::ios::left, std::ios::adjustfield);
1198 if (p!=std::string::npos){
1199 s.width((std::streamsize)maxAfter);
1200 s <<values[i].substr(p,maxAfter).c_str();
1203 s.width((std::streamsize)maxAfter);
1213 s.flags(original_flags);
1215 return (
int)(maxBefore+maxAfter);
1225 double sum_square=0.0;
1228 for (
unsigned int i=0;i<
rowNum;i++) {
1246 for (
unsigned int i=0;i<
dsize;i++) {
1247 x = *(
data +i); norm += x*x;
1267 for (
unsigned int i=0;i<
rowNum;i++){
1268 x = fabs ( (*
this)[i] ) ;
Implementation of a matrix and operations on matrices.
Implementation of a generic rotation vector.
vp_deprecated void init()
static vpColVector invSort(const vpColVector &v)
void stack(const double &d)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
static vpColVector sort(const vpColVector &v)
static double stdev(const vpColVector &v, const bool useBesselCorrection=false)
double euclideanNorm() const
Implementation of row vector and the associated operations.
static double getMedian(const std::vector< double > &v)
vpColVector operator*(const double &x, const vpColVector &v)
vpColVector operator/(const double x) const
vpColVector operator+(const vpColVector &v) const
Operator that allows to add two column vectors.
error that can be emited by ViSP classes.
Type * data
Address of the first element of the data array.
Implementation of a generic 2D array used as vase class of matrices and vectors.
vpColVector & operator*=(double x)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
Return the number of columns of the 2D array.
vpColVector operator-() const
static double median(const vpColVector &v)
static Type maximum(const Type &a, const Type &b)
vpColVector & operator/=(double x)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
unsigned int rowNum
Number of rows in the array.
double infinityNorm() const
vpColVector & normalize()
vpColVector & operator<<(const vpColVector &v)
static double mean(const vpColVector &v)
unsigned int getRows() const
Return the number of rows of the 2D array.
vpColVector & operator-=(vpColVector v)
Operator that allows to substract two column vectors.
unsigned int colNum
Number of columns in the array.
void insert(unsigned int i, const vpColVector &v)
vpColVector & operator=(const vpColVector &v)
Copy operator. Allow operation such as A = v.
vpColVector & operator+=(vpColVector v)
Operator that allows to add two column vectors.
Implementation of column vector and the associated operations.
static double dotProd(const vpColVector &a, const vpColVector &b)
vpRowVector transpose() const
Implementation of a pose vector and operations on poses.
vpColVector()
Basic constructor that creates an empty 0-size column vector.
static vpMatrix skew(const vpColVector &v)
unsigned int dsize
Current array size (rowNum * colNum)
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
double operator*(const vpColVector &x) const
Class that consider the case of a translation vector.
double ** rowPtrs
Address of the first element of each rows.
void resize(const unsigned int i, const bool flagNullify=true)