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

📄 vnl_vector_fixed.h

📁 InsightToolkit-1.4.0(有大量的优化算法程序)
💻 H
📖 第 1 页 / 共 2 页
字号:


  //: Reverse the order of the elements
  //  Element i swaps with element size()-1-i
  void flip();

  //: Check that size()==sz if not, abort();
  // This function does or tests nothing if NDEBUG is defined
  void assert_size( unsigned sz ) const { assert( sz == n ); }

  //: Check that this is finite if not, abort();
  // This function does or tests nothing if NDEBUG is defined
  void assert_finite() const {
#ifndef NDEBUG
    assert_finite_internal();
#endif
  }

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

  //: Return true iff all the entries are zero.
  bool is_zero() const;

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

  //: Return true if *this == v
  bool operator_eq (vnl_vector_fixed<T,n> const& v) const {
    for( size_type i = 0; i < n; ++i ) {
      if( (*this)[i] != v[i] )
        return false;
    }
    return true;
  }

  //: Return true if *this == v
  bool operator_eq (vnl_vector<T> const& v) const {
    assert( v.size() == n );
    for( size_type i = 0; i < n; ++i ) {
      if( (*this)[i] != v[i] )
        return false;
    }
    return true;
  }


  //: Read from text stream
  bool read_ascii(vcl_istream& s);

  //: Display the vector
  // Output each element separated by a single space.
  void print( vcl_ostream& s ) const;

public:
  // Helper routines for arithmetic. n is the size, and is the
  // template parameter.

  inline static void add( const T* a, const T* b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a + *b;
      ++r; ++a; ++b;
    }
  }

  inline static void add( const T* a, T b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a + b;
      ++r; ++a;
    }
  }

  inline static void sub( const T* a, const T* b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a - *b;
      ++r; ++a; ++b;
    }
  }

  inline static void sub( const T* a, T b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a - b;
      ++r; ++a;
    }
  }

  inline static void sub( T a, const T* b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = a - *b;
      ++r; ++b;
    }
  }

  inline static void mul( const T* a, const T* b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a * *b;
      ++r; ++a; ++b;
    }
  }

  inline static void mul( const T* a, T b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a * b;
      ++r; ++a;
    }
  }

  inline static void div( const T* a, const T* b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a / *b;
      ++r; ++a; ++b;
    }
  }

  inline static void div( const T* a, T b, T* r ) {
    for( unsigned int i=0; i < n; ++i ) {
      *r = *a / b;
      ++r; ++a;
    }
  }


private:
  //: See assert_finite().
  void assert_finite_internal() const;

};



// Make the operators below inline because (1) they are small and
// (2) we then have less explicit instantiation trouble.



// --- Vector-scalar operators ----------------------------------------


//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator+( const vnl_vector_fixed<T,n>& v, T s )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::add( v.data_block(), s, r.data_block() );
  return r;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator+( T s, const vnl_vector_fixed<T,n>& v )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::add( v.data_block(), s, r.data_block() );
  return r;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator-( const vnl_vector_fixed<T,n>& v, T s )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::sub( v.data_block(), s, r.data_block() );
  return r;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator-( T s, const vnl_vector_fixed<T,n>& v )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::sub( s, v.data_block(), r.data_block() );
  return r;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator*( const vnl_vector_fixed<T,n>& v, T s )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::mul( v.data_block(), s, r.data_block() );
  return r;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator*( T s, const vnl_vector_fixed<T,n>& v )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::mul( v.data_block(), s, r.data_block() );
  return r;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator/( const vnl_vector_fixed<T,n>& v, T s )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::div( v.data_block(), s, r.data_block() );
  return r;
}


// --- Vector-vector operators ----------------------------------------


//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator+( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::add( a.data_block(), b.data_block(), r.data_block() );
  return r;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> operator-( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::sub( a.data_block(), b.data_block(), r.data_block() );
  return r;
}

template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> element_product( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::mul( a.data_block(), b.data_block(), r.data_block() );
  return r;  
}

template<class T, unsigned int n>
inline vnl_vector_fixed<T,n> element_quotient( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b )
{
  vnl_vector_fixed<T,n> r;
  vnl_vector_fixed<T,n>::div( a.data_block(), b.data_block(), r.data_block() );
  return r;  
}

template<class T>
vnl_vector_fixed<T,3> cross_3d (vnl_vector_fixed<T,3> const& v1, vnl_vector_fixed<T,3> const& v2)
{
  vnl_vector_fixed<T,3> result;

  result.x() = v1.y() * v2.z() - v1.z() * v2.y();
  result.y() = v1.z() * v2.x() - v1.x() * v2.z();
  result.z() = v1.x() * v2.y() - v1.y() * v2.x();
  return result;
}

// These overloads for the common case of mixing a fixed with a
// non-fixed. Because the operator* are templated, the fixed will not
// be automatically converted to a non-fixed-ref. These do it for you.

template<class T, unsigned int n>
inline vnl_vector<T> operator+( const vnl_vector_fixed<T,n>& a, const vnl_vector<T>& b ) {
  return a.as_ref() + b;
}

template<class T, unsigned int n>
inline vnl_vector<T> operator+( const vnl_vector<T>& a, const vnl_vector_fixed<T,n>& b ) {
  return a + b.as_ref();
}

template<class T, unsigned int n>
inline vnl_vector<T> operator-( const vnl_vector_fixed<T,n>& a, const vnl_vector<T>& b ) {
  return a.as_ref() - b;
}

template<class T, unsigned int n>
inline vnl_vector<T> operator-( const vnl_vector<T>& a, const vnl_vector_fixed<T,n>& b ) {
  return a - b.as_ref();
}


template<class T, unsigned n>
inline T dot_product( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b ) {
  return dot_product( a.as_ref(), b.as_ref() );
}

template<class T, unsigned n>
inline T dot_product( const vnl_vector_fixed<T,n>& a, const vnl_vector<T>& b ) {
  return dot_product( a.as_ref(), b );
}

template<class T, unsigned n>
inline T dot_product( const vnl_vector<T>& a, const vnl_vector_fixed<T,n>& b ) {
  return dot_product( a, b.as_ref() );
}

template<class T, unsigned int n>
inline vnl_matrix<T> outer_product( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b ) {
  return outer_product( a.as_ref(), b.as_ref());
}

template<class T,unsigned int n>
  inline vnl_vector_fixed<T,n> cross_3d( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b ) {
  return cross_3d( a.as_ref(), b.as_ref());
}

template<class T,unsigned int n>
  inline vnl_vector_fixed<T,n> cross_3d( const vnl_vector_fixed<T,n>& a, const vnl_vector<T>& b ) {
  return cross_3d( a.as_ref(), b);
}

template<class T,unsigned int n>
  inline vnl_vector_fixed<T,n> cross_3d( const vnl_vector<T>& a, const vnl_vector_fixed<T,n>& b ) {
  return cross_3d( a, b.as_ref());
}

template<class T, unsigned int n>
inline vnl_matrix<T> outer_product( const vnl_vector<T>& a, const vnl_vector_fixed<T,n>& b ) {
  return outer_product( a, b.as_ref());
}

template<class T, unsigned int n>
inline vnl_matrix<T> outer_product( const vnl_vector_fixed<T,n>& a, const vnl_vector<T>& b ) {
  return outer_product( a.as_ref(), b);
}

template<class T, unsigned n>
inline T angle( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b ) {
  return angle( a.as_ref(), b.as_ref() );
}

template<class T, unsigned n>
inline T angle( const vnl_vector_fixed<T,n>& a, const vnl_vector<T>& b ) {
  return angle( a.as_ref(), b );
}

template<class T, unsigned n>
inline T angle( const vnl_vector<T>& a, const vnl_vector_fixed<T,n>& b ) {
  return angle( a, b.as_ref() );
}


template<class T, unsigned n>
inline T vnl_vector_ssd( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b ) {
  return vnl_vector_ssd( a.as_ref(), b.as_ref() );
}

template<class T, unsigned n>
inline T vnl_vector_ssd( const vnl_vector_fixed<T,n>& a, const vnl_vector<T>& b ) {
  return vnl_vector_ssd( a.as_ref(), b );
}

template<class T, unsigned n>
inline T vnl_vector_ssd( const vnl_vector<T>& a, const vnl_vector_fixed<T,n>& b ) {
  return vnl_vector_ssd( a, b.as_ref() );
}






//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline bool operator==( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b )
{
  return a.operator_eq( b );
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline bool operator!=( const vnl_vector_fixed<T,n>& a, const vnl_vector_fixed<T,n>& b )
{
  return ! a.operator_eq( b );
}


// --- I/O operators -------------------------------------------------


//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline
vcl_ostream& operator<< ( vcl_ostream& ostr, const vnl_vector_fixed<T,n>& v ) {
  v.print( ostr );
  return ostr;
}

//: \relates vnl_vector_fixed
template<class T, unsigned int n>
inline
vcl_istream& operator>> ( vcl_istream& ostr, vnl_vector_fixed<T,n>& v ) {
  v.read_ascii( ostr );
  return ostr;
}

#endif // vnl_vector_fixed_h_

⌨️ 快捷键说明

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