Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

vnl_vector_fixed.h

Go to the documentation of this file.
00001 #ifndef vnl_vector_fixed_h_
00002 #define vnl_vector_fixed_h_
00003 
00004 // This is vxl/vnl/vnl_vector_fixed.h
00005 
00006 #include <vcl_cstring.h> // memcpy()
00007 #include <vnl/vnl_vector_ref.h>
00008 #include <vnl/vnl_c_vector.h>
00009 
00010 template <class T, int n>
00011 class vnl_vector_fixed;
00012 
00013 template <class T, int n>
00014 vnl_vector_fixed<T,n> element_product (vnl_vector_fixed<T,n> const&,
00015                                        vnl_vector_fixed<T,n> const&);
00016 
00017 template <class T, int n>
00018 vnl_vector_fixed<T,n> element_quotient (vnl_vector_fixed<T,n> const&,
00019                                         vnl_vector_fixed<T,n> const&);
00020 
00021 
00022 
00023 //:
00024 // \file
00025 // \brief Fixed length stack-stored vnl_vector
00026 // \author Andrew W. Fitzgibbon, Oxford RRG, 04 Aug 96
00027 
00028 //: Fixed length stack-stored vnl_vector.
00029 //    vnl_vector_fixed is a fixed-length, stack storage vnl_vector.
00030 //  vnl_vector_fixed allocates storage space,
00031 //  and passes reference to this space to vnl_vector_ref
00032 //  See the docs for vnl_matrix_ref
00033 
00034 // Modifications
00035 // LSB Manchester 16/3/01 Binary I/O added
00036 
00037 //: fixed length  stack-stored vnl_vector.
00038 export template <class T, int n>
00039 class vnl_vector_fixed : public vnl_vector_ref<T> {
00040   typedef vnl_vector_ref<T> Base;
00041 public:
00042   //: Construct an uninitialized n-vector
00043   vnl_vector_fixed():Base(n, space) {}
00044 
00045   //: Construct an n-vector copy of rhs.  Does not check that rhs
00046   //  is the right size.
00047   vnl_vector_fixed(vnl_vector<T> const& rhs):Base(n, space) {
00048     if (rhs.size() != n)
00049       vnl_error_vector_dimension ("vnl_vector_fixed(const vnl_vector&) ", n, rhs.size());
00050     memcpy(space, rhs.data_block(), sizeof space);
00051   }
00052 
00053   //:
00054   // GCC generates (and calls) this even though above should do...
00055   vnl_vector_fixed(vnl_vector_fixed<T,n> const& rhs):Base(n, space) {
00056     memcpy(space, rhs.space, sizeof space);
00057   }
00058 
00059   //: Constructs n-vector with elements initialised to v
00060   vnl_vector_fixed (T const& v): Base(n,space) {
00061     for(int i = 0; i < n; ++i)
00062       data[i] = v;
00063   }
00064 
00065   //: Constructs 3D vector(px, py, pz )
00066   vnl_vector_fixed (T const& px, T const& py, T const& pz): Base(n,space) { 
00067     if (n != 3) vnl_error_vector_dimension ("constructor (x,y,z): n != 3", n, 3);
00068     data[0] = px;
00069     data[1] = py;
00070     data[2] = pz;
00071   }
00072 
00073   //: Constructs 2D vector  (px, py)
00074   vnl_vector_fixed (T const& px, T const& py): Base(n,space) { 
00075     if (n != 2) vnl_error_vector_dimension ("constructor (x,y): n != 2", n, 2);
00076     data[0] = px;
00077     data[1] = py;
00078   }
00079 
00080   vnl_vector_fixed<T,n>& operator=(vnl_vector_fixed<T,n> const& rhs) {
00081     memcpy(space, rhs.space, sizeof space);
00082     return *this;
00083   }
00084 
00085   vnl_vector_fixed<T,n>& operator=(vnl_vector<T> const& rhs) {
00086     if (rhs.size() != n)
00087       vnl_error_vector_dimension ("operator=", n, rhs.size());
00088     memcpy(space, rhs.data_block(), sizeof space);
00089     return *this;
00090   }
00091 
00092   vnl_vector_fixed<T,n>& operator= (T const& t)
00093     { vnl_vector<T>::operator=  (t); return *this; }
00094   vnl_vector_fixed<T,n>& operator+= (T const t)
00095     { vnl_vector<T>::operator+= (t); return *this; }
00096   vnl_vector_fixed<T,n>& operator-= (T const t)
00097     { vnl_vector<T>::operator-= (t); return *this; }
00098   vnl_vector_fixed<T,n>& operator*= (T const t)
00099     { vnl_vector<T>::operator*= (t); return *this; }
00100   vnl_vector_fixed<T,n>& operator/= (T const t)
00101     { vnl_vector<T>::operator/= (t); return *this; }
00102 
00103   vnl_vector_fixed<T,n>& operator+= (vnl_vector<T> const& rhs)
00104     { vnl_vector<T>::operator+= (rhs); return *this; }
00105   vnl_vector_fixed<T,n>& operator-= (vnl_vector<T> const& rhs)
00106     { vnl_vector<T>::operator-= (rhs); return *this; }
00107 
00108   vnl_vector_fixed<T,n> operator- () const
00109     { return  (vnl_vector_fixed<T,n> (*this) *= -1); }
00110   vnl_vector_fixed<T,n> operator+ (T const t) const
00111     { return  (vnl_vector_fixed<T,n> (*this) += t); }
00112   vnl_vector_fixed<T,n> operator- (T const t) const
00113     { return  (vnl_vector_fixed<T,n> (*this) -= t); }
00114   vnl_vector_fixed<T,n> operator* (T const t) const
00115     { return  (vnl_vector_fixed<T,n> (*this) *= t); }
00116   vnl_vector_fixed<T,n> operator/ (T const t) const
00117     { return  (vnl_vector_fixed<T,n> (*this) /= t); }
00118 
00119   vnl_vector_fixed<T,n> operator+ (vnl_vector<T> const& rhs) const
00120     { return  (vnl_vector_fixed<T,n> (*this) += rhs); }
00121   vnl_vector_fixed<T,n> operator- (vnl_vector<T> const& rhs) const
00122     { return  (vnl_vector_fixed<T,n> (*this) -= rhs); }
00123 
00124   vnl_vector_fixed<T,n> apply(T (*f)(T)) {
00125     vnl_vector_fixed<T,n> ret;
00126     vnl_c_vector<T>::apply(this->data, num_elmts, f, ret.data);
00127     return ret;
00128   }
00129   vnl_vector_fixed<T,n> apply(T (*f)(T const&)) {
00130     vnl_vector_fixed<T,n> ret;
00131     vnl_c_vector<T>::apply(this->data, num_elmts, f, ret.data);
00132     return ret;
00133   }
00134 
00135   // do not specialize operations with vnl_matrix, since the size of the result
00136   // vector is not known at compile time
00137   //  vnl_vector_fixed<T,n> operator* (vnl_matrix<T> const& m) const;
00138   //friend vnl_vector_fixed<T,n> operator* (vnl_matrix<T> const& m, vnl_vector_fixed<T,n> const& v);
00139   // do not specialize extract for the same reason as above
00140   //  vnl_vector_fixed<T,n> extract (unsigned int len, unsigned int start=0) const; // subvector
00141   vnl_vector_fixed<T,n>& update (vnl_vector<T> const& v, unsigned int start=0)
00142     { return (vnl_vector_fixed<T,n>&) vnl_vector<T>::update (v, start); }
00143 
00144   //: v /= sqrt(dot(v,v))
00145   vnl_vector_fixed<T,n>& normalize()  
00146     { return (vnl_vector_fixed<T,n>&) vnl_vector<T>::normalize(); }
00147 
00148   friend vnl_vector_fixed<T,n> element_product VCL_NULL_TMPL_ARGS (vnl_vector_fixed<T,n> const&,
00149                                                                    vnl_vector_fixed<T,n> const&);
00150   friend vnl_vector_fixed<T,n> element_quotient VCL_NULL_TMPL_ARGS (vnl_vector_fixed<T,n> const&,
00151                                                                     vnl_vector_fixed<T,n> const&);
00152 
00153 public:
00154   // void these methods on vnl_vector_fixed, since they deallocate the underlying
00155   // storage
00156 
00157   //: v = m * v
00158   vnl_vector<T>& pre_multiply (vnl_matrix<T> const&);
00159 
00160   //: v = v * m
00161   vnl_vector<T>& post_multiply (vnl_matrix<T> const&); 
00162   vnl_vector<T>& operator*= (vnl_matrix<T> const&);
00163 
00164 
00165 
00166 private:
00167   T space[n];
00168 };
00169 
00170 #ifndef VCL_SUNPRO_CC_50 // does not allow funtions templated over non-types.
00171 // define inline friends.
00172 template <class T, int n>
00173 inline vnl_vector_fixed<T,n> operator+(T const t, vnl_vector_fixed<T,n> const & rhs)
00174 { return  (vnl_vector_fixed<T,n> (rhs) += t); }
00175 
00176 template <class T, int n>
00177 inline vnl_vector_fixed<T,n> operator-(T const t, vnl_vector_fixed<T,n> const & rhs)
00178 { return  (( - vnl_vector_fixed<T,n> (rhs)) += t); }
00179 
00180 template <class T, int n>
00181 inline vnl_vector_fixed<T,n> operator*(T const t, vnl_vector_fixed<T,n> const& rhs)
00182 { return  (vnl_vector_fixed<T,n> (rhs) *= t); }
00183 
00184 template <class T, int n>
00185 inline vnl_vector_fixed<T,n> element_product (vnl_vector_fixed<T,n> const& a,
00186                                        vnl_vector_fixed<T,n> const& b)
00187 {
00188   vnl_vector_fixed<T,n> ret (a);
00189   for (int i=0; i<n; i++) ret[i] *= b[i];
00190   return ret;
00191 }
00192 
00193 template <class T, int n>
00194 inline vnl_vector_fixed<T,n> element_quotient (vnl_vector_fixed<T,n> const& a,
00195                                         vnl_vector_fixed<T,n> const& b)
00196 {
00197   vnl_vector_fixed<T,n> ret (a);
00198   for (int i=0; i<n; i++) ret[i] /= b[i];
00199   return ret;
00200 }
00201 #endif
00202 
00203 #if defined(VCL_SGI_CC_7)
00204 template <class T, int n>
00205 inline
00206 vcl_ostream &operator<<(vcl_ostream &os, vnl_vector_fixed<T, n> const &v) {
00207   return os << (vnl_vector<T>const&)v;
00208 }
00209 #endif
00210 
00211 //                                        what's this?
00212 #if !defined (VCL_SUNPRO_CC) && ! defined (_ODI_OSSG_)
00213 
00214 vnl_vector_fixed<double,3> cross_3d (vnl_vector_fixed<double,3> const& vect1,
00215                                      vnl_vector_fixed<double,3> const& vect2);
00216 vnl_vector_fixed<float,3> cross_3d (vnl_vector_fixed<float,3> const& vect1,
00217                                     vnl_vector_fixed<float,3> const& vect2);
00218 vnl_vector_fixed<int,3> cross_3d (vnl_vector_fixed<int,3> const& vect1,
00219                                   vnl_vector_fixed<int,3> const& vect2);
00220 #endif
00221 
00222 
00223 #endif // vnl_vector_fixed_h_

Generated at Wed Mar 12 01:13:16 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000