arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

arrayWrap5.h

Go to the documentation of this file.
00001 /*
00002  * $Id: arrayWrap5.h,v 1.2 2003/06/27 04:58:37 jmk Exp $
00003  */
00004 ///////////////////////////////////////////////////////////////////////////
00005 //              _____________  ______________________    __   __  _____
00006 //             /  ________  |  |   ___   ________   /   |  \ /  \   |
00007 //            |  |       |  |_ |  |_ |  |       /  /    \__  |      |
00008 //            |  |  ___  |  || |  || |  |      /  /        | |      |
00009 //            |  | |   \ |  || |  || |  |     /  /      \__/ \__/ __|__
00010 //            |  | |_@  ||  || |  || |  |    /  /          Institute
00011 //            |  |___/  ||  ||_|  || |  |   /  /_____________________
00012 //             \_______/  \______/ | |__|  /___________________________
00013 //                        |  |__|  |
00014 //                         \______/
00015 //                    University of Utah       
00016 //                           2002
00017 ///////////////////////////////////////////////////////////////////////////
00018 ////////////////////////////////////////////////////////////////////////
00019 // 1/13/03      Aaron Lefohn    Scientific Computing and Imaging Institute
00020 //                      Joe M. Kniss    School of Computing
00021 //                                                      University of Utah
00022 //
00023 //  arrayWrap5  - An Array WRAPPER class.
00024 //                      - This is a lightweight class that does NOT own its data.
00025 //                      - Copies of "arrayWrap5" objects are shallow.
00026 //                      - The constructor does NOT allocate any memory.
00027 //                              - The destructor does NOT free the memory.
00028 //                              - Accessors (In order of increasing overhead)
00029 //                                      1) The (i,j,k,m) operator is just as fast a built-in C/C++ array.
00030 //                                      2) The [] (slice) operator is next fastest 
00031 //                                         - 8% overhead for 1 level of slice
00032 //                                         - 20% overhead for 4D access via slices.
00033 //                                         - Only use slicing when you need it, otherwise use (i,j,k,m)!
00034 //
00035 ////////////////////////////////////////////////////////////////////////
00036 
00037 #ifndef ARRAY_WRAP_5_h
00038 #define ARRAY_WRAP_5_h
00039 
00040 #include <../arrayGutz/arrayBase.h>
00041 #include <assert.h>
00042 #include "arrayWrap2.h"
00043 
00044 namespace gutz {
00045 
00046 /////////////////////////
00047 // arrayWrap5
00048 /////////////////////////
00049 template <class T>
00050 class arrayWrap5 : public arrayBase<T>
00051 {
00052 public:
00053         // Constructors - Shallow wrap around data. No size checking!
00054         arrayWrap5();
00055         arrayWrap5( int d0, int d1, int d2, int d3, int d4, T* v );
00056         arrayWrap5( const arrayWrap5<T>& a );
00057         arrayWrap5<T>& operator=( const arrayWrap5<T>& a );
00058 
00059     virtual ~arrayWrap5();
00060 
00061         // Return a slice of data - Optimized by returning reference to arrayWrap3<T> member.
00062         inline arrayWrap4<T>&           operator[] (int i);
00063         inline const arrayWrap4<T>& operator[] (int i) const;
00064 
00065         // Return the element at data(i,j,k,m) - Faster than arr[i][j][k][m]
00066         inline T&                                       operator() (int i, int j, int k, int m, int n);
00067         inline const T&                         operator() (int i, int j, int k, int m, int n) const;
00068 
00069 protected:
00070 
00071         // The slice wrapper used in the [] operator. 
00072         // Mutable so that it can be changed by a const operator
00073         mutable arrayWrap4<T>  mSlice;  
00074         
00075 private:
00076         inline void setSlice( int i ) const;                                               // Set 'mSlice' to the ith slice of 'mData'
00077         inline int  address(  int i, int j, int k, int m, int n) const;// Get the address of the data(i,j)'th element
00078         inline void setData( T* d ) { mData = d; }                                         // Reset just data pointer
00079 };
00080 
00081 ////////////////////////////////////
00082 // Implementation
00083 ////////////////////////////////////
00084 
00085 // Constructors - All are shallow!!
00086 template <class T>
00087 arrayWrap5<T>::arrayWrap5 ()
00088 :arrayBase<T>(), mSlice(arrayWrap4<T>())
00089 {}
00090 
00091 template <class T>
00092 arrayWrap5<T>::arrayWrap5 (int d0, int d1, int d2, int d3, int d4, T* v)
00093 :arrayBase<T>(d0,d1,d2,d3,d4,v), mSlice(arrayWrap4<T>(d1,d2,d3,d4,v))
00094 {}
00095 
00096 // Copy Ctor
00097 template <class T>
00098 arrayWrap5<T>::arrayWrap5<T>( const arrayWrap5<T>& a ) : arrayBase<T>(a)
00099 {
00100         mSlice = a.mSlice;
00101 }
00102 
00103 // Assignment Op
00104 template <class T>
00105 arrayWrap5<T>& arrayWrap5<T>::operator=(const arrayWrap5<T>& a)
00106 {
00107         if( this != &a ) {
00108                 arrayBase<T>::operator=(a);// Call base class assign. op
00109                 mSlice = a.mSlice;
00110         }
00111         return *this;
00112 }
00113 
00114 // Destructor
00115 template <class T>
00116 arrayWrap5<T>::~arrayWrap5()
00117 {}
00118 
00119 // Accessing Operators
00120 template <class T>
00121 inline arrayWrap4<T>& arrayWrap5<T>::operator[] (int i)                                 
00122 { 
00123         setSlice(i);
00124         return mSlice; 
00125 }
00126 
00127 template <class T>
00128 inline const arrayWrap4<T>& arrayWrap5<T>::operator[] (int i) const     
00129 { 
00130         setSlice(i);
00131         return mSlice; 
00132 }
00133 
00134 template <class T>
00135 inline T& arrayWrap5<T>::operator() (int i, int j, int k, int m, int n)
00136 {
00137         return mData[ address(i,j,k,m,n) ];
00138 }
00139 
00140 template <class T>
00141 inline const T& arrayWrap5<T>::operator() (int i, int j, int k, int m, int n) const
00142 {
00143         return mData[ address(i,j,k,m,n) ];
00144 }
00145 
00146 template <class T>
00147 inline int arrayWrap5<T>::address( int i, int j, int k, int m, int n) const
00148 {
00149         //return i*mAxisDim[3]*mAxisDim[2]*mAxisDim[1] + j*mAxisDim[3]*mAxisDim[2] + k*mAxisDim[3] + m;
00150         return i*mAxisStride[0] + j*mAxisStride[1] + k*mAxisStride[2] + m*mAxisStride[3] + n;
00151 }
00152 
00153 // Set 'mSlice' to be the ith slice of 'mData'
00154 template <class T>
00155 inline void arrayWrap5<T>::setSlice( int i ) const
00156 {
00157         //int a = i * mAxisDim[1] * mAxisDim[2] * mAxisDim[3];
00158         int a = i * mAxisStride[0];
00159         assert( a < mSize );
00160         mSlice.setData( mData + a );
00161 }
00162 
00163 ////////////////////////////////////
00164 // Typedefs
00165 ////////////////////////////////////
00166 
00167 typedef arrayWrap5<char>        arrayw5c;
00168 typedef arrayWrap5<uchar>       arrayw5uc;
00169 typedef arrayWrap5<char>        arrayw5b;
00170 typedef arrayWrap5<uchar>       arrayw5ub;
00171 typedef arrayWrap5<short>       arrayw5s;
00172 typedef arrayWrap5<ushort>      arrayw5us;
00173 typedef arrayWrap5<int>         arrayw5i;
00174 typedef arrayWrap5<uint>        arrayw5ui;
00175 typedef arrayWrap5<long>        arrayw5l;
00176 typedef arrayWrap5<ulong>       arrayw5ul;
00177 typedef arrayWrap5<llong>       arrayw5ll;
00178 typedef arrayWrap5<ullong>      arrayw5ull;
00179 typedef arrayWrap5<float>       arrayw5f;
00180 typedef arrayWrap5<double>      arrayw5d;
00181 
00182 #ifdef USING_MATHGUTZ
00183         typedef arrayWrap5<vec2ub> arrayw5v2ub;
00184         typedef arrayWrap5<vec2i>  arrayw5v2i;
00185         typedef arrayWrap5<vec2ui> arrayw5v2ui;
00186         typedef arrayWrap5<vec2f>  arrayw5v2f;
00187 
00188         typedef arrayWrap5<vec3ub> arrayw5v3ub;
00189         typedef arrayWrap5<vec3i>  arrayw5v3i;
00190         typedef arrayWrap5<vec3ui> arrayw5v3ui;
00191         typedef arrayWrap5<vec3f>  arrayw5v3f;
00192 
00193         typedef arrayWrap5<vec4ub> arrayw5v4ub;
00194         typedef arrayWrap5<vec4i>  arrayw5v4i;
00195         typedef arrayWrap5<vec4ui> arrayw5v4ui;
00196         typedef arrayWrap5<vec4f>  arrayw5v4f;
00197 
00198         typedef arrayWrap5<mat2ub> arrayw5m2ub;
00199         typedef arrayWrap5<mat2i>  arrayw5m2i;
00200         typedef arrayWrap5<mat2ui> arrayw5m2ui;
00201         typedef arrayWrap5<mat2f>  arrayw5m2f;
00202 
00203         typedef arrayWrap5<mat3ub> arrayw5m3ub;
00204         typedef arrayWrap5<mat3i>  arrayw5m3i;
00205         typedef arrayWrap5<mat3ui> arrayw5m3ui;
00206         typedef arrayWrap5<mat3f>  arrayw5m3f;
00207 
00208         typedef arrayWrap5<mat4ub> arrayw5m4ub;
00209         typedef arrayWrap5<mat4i>  arrayw5m4i;
00210         typedef arrayWrap5<mat4ui> arrayw5m4ui;
00211         typedef arrayWrap5<mat4f>  arrayw5m4f;
00212 #endif
00213 
00214 } // End of namespace gutz
00215 
00216 #endif // arrayWrap5_h

Send questions, comments, and bug reports to:
jmk