SGolaySmoothingFilter::SGolaySmoothingFilter(int size, int degree) : m_windowSize(size + (size + 1) % 2), m_degree(degree), m_values(VectorN(0.0, degree)), m_windowData(VectorN(0.0, m_windowSize)), m_coeffMatrix(MatrixN(0.0, m_degree + 1, m_windowSize)) { // initialize matrix of coefficients MatrixN designMatrix(1.0, m_windowSize, m_degree + 1); // generate a vector of the intervals across the window, centered at zero, // each vector is raised to the power of its column index. note the first // column is skipped because a^0 is always 1 and the matrix has been // initialized to 1. for(int row = 0; row < m_windowSize; row++) { for(int col = 1; col < m_degree + 1; col++) { double base = row - (m_windowSize - 1); designMatrix[row][col] = std::pow(base, col); } } MatrixN JxJT = (designMatrix.transpose() * designMatrix); m_coeffMatrix = JxJT.inverse() * designMatrix.transpose(); }
/** Get a unit vector perpendicular to this one. */ VectorN getOrthogonalDirection() const { return ((this->maxAbsAxis() == 0) ? VectorN(y(), -x(), 0) : VectorN(0, z(), -y())).unit(); }
/** Swizzle operator, returns ZZZ. */ VectorN zzz() const { return VectorN (z(), z(), z()); }
/** Cross-product of this vector with another. */ VectorN cross(VectorN const & rhs) const { return VectorN((*this)[1] * rhs[2] - (*this)[2] * rhs[1], (*this)[2] * rhs[0] - (*this)[0] * rhs[2], (*this)[0] * rhs[1] - (*this)[1] * rhs[0]); }
/** Swizzle operator, returns XZZ. */ VectorN xzz() const { return VectorN (x(), z(), z()); }
/** Swizzle operator, returns YZZ. */ VectorN yzz() const { return VectorN (y(), z(), z()); }
/** Swizzle operator, returns YYZ. */ VectorN yyz() const { return VectorN (y(), y(), z()); }
/** Swizzle operator, returns ZYZ. */ VectorN zyz() const { return VectorN (z(), y(), z()); }
/** Swizzle operator, returns ZXZ. */ VectorN zxz() const { return VectorN (z(), x(), z()); }
/** Swizzle operator, returns XYZ. */ VectorN xyz() const { return VectorN (x(), y(), z()); }
/** Swizzle operator, returns YXZ. */ VectorN yxz() const { return VectorN (y(), x(), z()); }
/** Swizzle operator, returns XXZ. */ VectorN xxz() const { return VectorN (x(), x(), z()); }
/** Swizzle operator, returns ZXY. */ VectorN zxy() const { return VectorN (z(), x(), y()); }
/** Swizzle operator, returns YXY. */ VectorN yxy() const { return VectorN (y(), x(), y()); }
/** Swizzle operator, returns XXY. */ VectorN xxy() const { return VectorN (x(), x(), y()); }