⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vnl_matrix_fixed_ref.h

📁 DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.
💻 H
📖 第 1 页 / 共 3 页
字号:
  //: Return minimum value of elements
  T min_value() const { return vnl_c_vector<T>::min_value(begin(), size()); }

  //: Return maximum value of elements
  T max_value() const { return vnl_c_vector<T>::max_value(begin(), size()); }

  //: Return mean of all matrix elements
  T mean() const { return vnl_c_vector<T>::mean(begin(), size()); }

  // predicates

  //: Return true iff the size is zero.
  bool empty() const { return num_rows==0 && num_cols==0; }

  //:  Return true if all elements equal to identity.
  bool is_identity() const;

  //:  Return true if all elements equal to identity, within given tolerance
  bool is_identity(double tol) const;

  //: Return true if all elements equal to zero.
  bool is_zero() const;

  //: Return true if all elements equal to zero, within given tolerance
  bool is_zero(double tol) const;

  //: Return true if finite
  bool is_finite() const;

  //: Return true if matrix contains NaNs
  bool has_nans() const;

  //: abort if size is not as expected
  // This function does or tests nothing if NDEBUG is defined
  void assert_size(unsigned rows, unsigned cols) const
  {
#ifndef NDEBUG
    assert_size_internal(rows, cols);
#endif
  }
  //: abort if matrix contains any INFs or NANs.
  // This function does or tests nothing if NDEBUG is defined
  void assert_finite() const
  {
#ifndef NDEBUG
    assert_finite_internal();
#endif
  }

  static void add( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::add(a,b,r); }
  static void add( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::add(a,b,r); }
  static void sub( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::sub(a,b,r); }
  static void sub( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::sub(a,b,r); }
  static void sub( T a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::sub(a,b,r); }
  static void mul( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::mul(a,b,r); }
  static void mul( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::mul(a,b,r); }
  static void div( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::div(a,b,r); }
  static void div( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::div(a,b,r); }

  static bool equal( const T* a, const T* b ) { return vnl_matrix_fixed<T,num_rows,num_cols>::equal(a,b); }

 private:
  const vnl_matrix_fixed_ref_const<T,num_rows,num_cols> & operator=(const vnl_matrix_fixed_ref_const<T,num_rows,num_cols>& ) const
  {
    assert(!"Assignment is illegal for a vnl_matrix_fixed_ref_const");
    return *this;
  }

  void assert_finite_internal() const;

  void assert_size_internal(unsigned, unsigned) const;
};


template <class T, unsigned num_rows, unsigned num_cols>
class vnl_matrix_fixed_ref : public vnl_matrix_fixed_ref_const<T,num_rows,num_cols>
{
  typedef vnl_matrix_fixed_ref_const<T,num_rows,num_cols> base;

 public:
  // this is the only point where the const_cast happens
  // the base class is used to store the pointer, so that conversion is not necessary
  T * data_block() const {
    return const_cast<T*>(this->data_);
  }
  vnl_matrix_fixed_ref(vnl_matrix_fixed<T,num_rows,num_cols>& rhs)
    : base(rhs.data_block())
  {
  }
  explicit vnl_matrix_fixed_ref(T * dataptr)
    : base(dataptr)
  {
  }

  //: Copy another vnl_matrix_fixed<T,m,n> into this.
  vnl_matrix_fixed_ref const & operator=(const vnl_matrix_fixed_ref_const<T,num_rows,num_cols>& rhs) const
  {
    vcl_memcpy(data_block(), rhs.data_block(), num_rows*num_cols*sizeof(T));
    return *this;
  }

  // Basic 2D-Array functionality-------------------------------------------

  //: set element
  void put (unsigned r, unsigned c, T const& v) { (*this)(r,c) = v; }

  //: get element
  T    get (unsigned r, unsigned c) const { return (*this)(r,c); }

  //: return pointer to given row
  // No boundary checking here.
  T  * operator[] (unsigned r) const { return data_block() + num_cols * r; }


  //: Access an element for reading or writing
  // There are assert style boundary checks - #define NDEBUG to turn them off.
  T       & operator() (unsigned r, unsigned c) const
  {
#if VNL_CONFIG_CHECK_BOUNDS  && (!defined NDEBUG)
    assert(r<num_rows);   // Check the row index is valid
    assert(c<num_cols);   // Check the column index is valid
#endif
    return *(this->data_block() + num_cols * r + c);
  }


  // Filling and copying------------------------------------------------

  //: Set all elements of matrix to specified value.
  // Complexity $O(r.c)$
  void fill (T) const;

  //: Set all diagonal elements of matrix to specified value.
  // Complexity $O(\min(r,c))$
  void fill_diagonal (T) const;

  //: Fill (laminate) this matrix with the given data.
  // We assume that p points to a contiguous rows*cols array, stored rowwise.
  void copy_in(T const *) const;

  //: Fill (laminate) this matrix with the given data.
  // A synonym for copy_in()
  void set(T const *d) const { copy_in(d); }

  //: Fill the given array with this matrix.
  // We assume that p points to a contiguous rows*cols array, stored rowwise.
  // No bounds checking on the array

  //: Transpose this matrix efficiently, if it is a square matrix
  void inplace_transpose() const;


  // Arithmetic ----------------------------------------------------
  // note that these functions should not pass scalar as a const&.
  // Look what would happen to A /= A(0,0).

  //: Add \a s to each element of lhs matrix in situ
  vnl_matrix_fixed_ref const& operator+= (T s) const
  {
    base::add( data_block(), s, data_block() ); return *this;
  }

  //: Subtract \a s from each element of lhs matrix in situ
  vnl_matrix_fixed_ref const& operator-= (T s) const
  {
    base::sub( data_block(), s, data_block() ); return *this;
  }

  //:
  vnl_matrix_fixed_ref const& operator*= (T s) const
  {
    base::mul( data_block(), s, data_block() ); return *this;
  }

  //:
  vnl_matrix_fixed_ref const& operator/= (T s) const
  {
    base::div( data_block(), s, data_block() ); return *this;
  }

  //:
  vnl_matrix_fixed_ref const & operator+= (vnl_matrix_fixed_ref_const<T,num_rows,num_cols> const& m) const
  {
    base::add( data_block(), m.data_block(), data_block() ); return *this;
  }

  //:
  vnl_matrix_fixed_ref const& operator+= (vnl_matrix<T> const& m) const
  {
    assert( m.rows() == num_rows && m.cols() == num_cols );
    base::add( data_block(), m.data_block(), data_block() ); return *this;
  }

  //:
  vnl_matrix_fixed_ref const& operator-= (vnl_matrix_fixed_ref_const<T,num_rows,num_cols> const& m) const
  {
    base::sub( data_block(), m.data_block(), data_block() ); return *this;
  }

  //:
  vnl_matrix_fixed_ref const& operator-= (vnl_matrix<T> const& m) const
  {
    assert( m.rows() == num_rows && m.cols() == num_cols );
    base::sub( data_block(), m.data_block(), data_block() ); return *this;
  }

  //: Negate all elements of matrix
  vnl_matrix_fixed<T,num_rows,num_cols> operator- () const
  {
    vnl_matrix_fixed<T,num_rows,num_cols> r;
    base::sub( T(0), data_block(), r.data_block() );
    return r;
  }

  //:
  vnl_matrix_fixed_ref const& operator*= (vnl_matrix_fixed_ref_const<T,num_cols,num_cols> const& s) const
  {
    vnl_matrix_fixed<T, num_rows, num_cols> out;
    for (unsigned i = 0; i < num_rows; ++i)
      for (unsigned j = 0; j < num_cols; ++j)
      {
        T accum = this->operator()(i,0) * s(0,j);
        for (unsigned k = 1; k < num_cols; ++k)
          accum += this->operator()(i,k) * s(k,j);
        out(i,j) = accum;
      }
    *this = out;
    return *this;
  }

#ifdef VCL_VC_6
  template<unsigned o>
  vnl_matrix_fixed<T,num_rows,o> operator*( vnl_matrix_fixed_fake_base<o,num_cols,T> const& mat ) const
  {
    vnl_matrix_fixed<T,num_cols,o> const& b = static_cast<vnl_matrix_fixed<T,num_cols,o> const&>(mat);
    return vnl_matrix_fixed_mat_mat_mult<T,num_rows,num_cols,o>( *this, b );
  }
  vnl_vector_fixed<T, num_rows> operator*( vnl_vector_fixed_ref_const<T, num_cols> const& b) const
  {
    return vnl_matrix_fixed_mat_vec_mult<T,num_rows,num_cols>(*this,b);
  }
#endif


  //: Set values of this matrix to those of M, starting at [top,left]
  vnl_matrix_fixed_ref const & update (vnl_matrix<T> const&, unsigned top=0, unsigned left=0) const;

  //: Set the elements of the i'th column to v[j]  (No bounds checking)
  void set_column(unsigned i, T const * v) const;

  //: Set the elements of the i'th column to value
  void set_column(unsigned i, T value ) const;

  //: Set j-th column to v
  void set_column(unsigned j, vnl_vector<T> const& v) const;

  //: Set columns to those in M, starting at starting_column
  void set_columns(unsigned starting_column, vnl_matrix<T> const& M) const;

  //: Set the elements of the i'th row to v[j]  (No bounds checking)
  void set_row   (unsigned i, T const * v) const;

  //: Set the elements of the i'th row to value
  void set_row   (unsigned i, T value ) const;

  //: Set the i-th row
  void set_row   (unsigned i, vnl_vector<T> const&) const;


  // mutators

  //: Set this matrix to an identity matrix
  //  Abort if the matrix is not square
  void set_identity() const;

  //: Reverse order of rows.
  void flipud() const;

  //: Reverse order of columns.
  void fliplr() const;

  //: Normalize each row so it is a unit vector
  //  Zero rows are ignored
  void normalize_rows() const;

  //: Normalize each column so it is a unit vector
  //  Zero columns are ignored
  void normalize_columns() const;

  //: Scale elements in given row by a factor of T
  void scale_row   (unsigned row, T value) const;

  //: Scale elements in given column by a factor of T
  void scale_column(unsigned col, T value) const;


  ////----------------------- Input/Output ----------------------------

  // : Read a vnl_matrix from an ascii vcl_istream, automatically determining file size if the input matrix has zero size.
  bool read_ascii(vcl_istream& s) const;


  //----------------------------------------------------------------------
  // Conversion to vnl_matrix_ref.

  // The const version of as_ref should return a const vnl_matrix_ref
  // so that the vnl_matrix_ref::non_const() cannot be used on
  // it. This prevents a const vnl_matrix_fixed from being cast into a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -