Exemple #1
0
/*!
  Initialize the row vector from a part of an input row vector \e v.

  \param v : Input row vector used for initialization.
  \param c : column index in \e v that corresponds to the first element of the row vector to contruct.
  \param ncols : Number of columns of the constructed row vector.

  The sub-vector starting from v[c] element and ending on v[c+ncols-1] element
  is used to initialize the contructed row vector.

  The following code shows how to use this function:
\code
#include <visp3/core/vpRowVector.h>

int main()
{
  vpRowVector v(4);
  int val = 0;
  for(size_t i=0; i<v.getCols(); i++) {
    v[i] = val++;
  }
  std::cout << "v: " << v << std::endl;

  vpRowVector w;
  w.init(v, 1, 2);
  std::cout << "w: " << w << std::endl;
}
\endcode
  It produces the following output:
  \code
v: 0 1 2 3
w: 1 2
  \endcode
 */
void
vpRowVector::init(const vpRowVector &v, unsigned int c, unsigned int ncols)
{
  unsigned int cncols = c+ncols ;

  if (cncols > v.getCols())
    throw(vpException(vpException::dimensionError,
                      "Bad column dimension (%d > %d) used to initialize vpRowVector",
                      cncols, v.getCols()));
  resize(ncols);
  if (this->rowPtrs == NULL) // Fix coverity scan: explicit null dereferenced
    return; // Noting to do
  for (unsigned int i=0 ; i < ncols; i++)
    (*this)[i] = v[i+c];
}
Exemple #2
0
/*!
  Compute the standard deviation value of all the elements of the vector.
*/
double
vpRowVector::stdev(const vpRowVector &v, const bool useBesselCorrection)
{
  if (v.data==NULL) {
    throw(vpException(vpException::fatalError,
                      "Cannot compute mean value of an empty row vector"));
  }

  double mean_value = mean(v);
  double sum_squared_diff = 0.0;
  for(unsigned int i = 0; i < v.size(); i++) {
    sum_squared_diff += (v[i]-mean_value) * (v[i]-mean_value);
  }

  double divisor = (double) v.size();
  if(useBesselCorrection && v.size() > 1) {
    divisor = divisor-1;
  }

  return std::sqrt(sum_squared_diff / divisor);
}