$search
00001 /* 00002 * Copyright (C) 2009 00003 * Robert Bosch LLC 00004 * Research and Technology Center North America 00005 * Palo Alto, California 00006 * 00007 * All rights reserved. 00008 * 00009 *------------------------------------------------------------------------------ 00010 * project ....: Autonomous Technologies 00011 * file .......: rtcArray3.h 00012 * authors ....: Benjamin Pitzer 00013 * organization: Robert Bosch LLC 00014 * creation ...: 08/16/2006 00015 * modified ...: $Date: 2009-01-21 18:19:16 -0800 (Wed, 21 Jan 2009) $ 00016 * changed by .: $Author: benjaminpitzer $ 00017 * revision ...: $Revision: 14 $ 00018 */ 00019 #ifndef RTC_ARRAY3_H 00020 #define RTC_ARRAY3_H 00021 00022 //== INCLUDES ================================================================== 00023 #include "rtc/rtcMath.h" 00024 #include "rtc/rtcVec3.h" 00025 #include "rtc/rtcArray.h" 00026 00027 //== NAMESPACES ================================================================ 00028 namespace rtc { 00029 00030 // Forward declarations 00031 template <class T, int K> class Array; // K-dimensional array 00032 template <class T> class Array3; // 3-dimensional array 00033 template <class T> class Vec3; // 3d Vector 00034 00038 template <class T> 00039 class Array3: public Array<T,3> { 00040 public: 00041 // Constructors/Destructor 00042 Array3(); 00043 Array3(int n1, int n2, int n3); 00044 Array3(const Array<T,3>& a); 00045 00046 // Mutators 00047 void setSize(int n1, int n2, int n3); 00048 T& operator () (int i1, int i2, int i3); 00049 00050 // Accessors 00051 T operator () (int i1, int i2, int i3) const; 00052 00053 // Helper functions 00054 int indexOf(int i1, int i2, int i3) const; 00055 00056 // inherit member data and functions of parent 00057 using Array<T,3>::x; 00058 using Array<T,3>::reset; 00059 using Array<T,3>::operator (); 00060 00061 protected: 00062 // inherit member data and functions of parent 00063 using Array<T,3>::dim; 00064 using Array<T,3>::mul; 00065 using Array<T,3>::len; 00066 }; 00067 00068 // Declare a few common typdefs 00069 typedef Array3<bool> Array3b; 00070 typedef Array3<char> Array3c; 00071 typedef Array3<unsigned char> Array3uc; 00072 typedef Array3<int> Array3i; 00073 typedef Array3<float> Array3f; 00074 typedef Array3<double> Array3d; 00075 00076 //============================================================================== 00077 // Array3<T> 00078 //============================================================================== 00079 00080 // Constructors/Destructor 00081 00084 template <class T> 00085 inline Array3<T>::Array3() : Array<T,3>() {} 00086 00090 template <class T> 00091 inline Array3<T>::Array3(int n1, int n2, int n3) : Array<T,3>() { 00092 setSize(n1,n2,n3); 00093 } 00094 00097 template <class T> 00098 inline Array3<T>::Array3(const Array<T,3>& a) : Array<T,3>(a) { 00099 } 00100 00101 // Mutators 00102 00106 template <class T> 00107 inline void Array3<T>::setSize(int n1, int n2, int n3) { 00108 Array<T,3>::setSize(Vec3i(n1,n2,n3)); 00109 } 00110 00115 template <class T> 00116 inline T& Array3<T>::operator () (int i1, int i2, int i3) { 00117 return x[indexOf(i1,i2,i3)]; 00118 } 00119 00120 // Accessors 00121 00126 template <class T> 00127 inline T Array3<T>::operator () (int i1, int i2, int i3) const { 00128 return x[indexOf(i1,i2,i3)]; 00129 } 00130 00131 // Helper functions (used internally only) 00132 00137 template <class T> 00138 inline int Array3<T>::indexOf(int i1, int i2, int i3) const { 00139 #if AR_CHECK_BOUNDS 00140 if (i1<0 || i1>=dim(0) || 00141 i2<0 || i2>=dim(1) || 00142 i3<0 || i3>=dim(2)) { 00143 std::stringstream ss; 00144 ss << "Error. Indices" << i1 << ", " << i2 << ", " << i3; 00145 ss << " exceed bounds [0, "; 00146 ss << dim(0) << "] or [0, " << dim(1); 00147 ss << "] or [0, " << dim(2) << "]."; 00148 ss << std::endl << std::flush; 00149 throw Exception(ss.str()); 00150 } 00151 #endif 00152 return i1*mul(0)+i2*mul(1)+i3; 00153 } 00154 00155 //============================================================================== 00156 } // namespace rtc 00157 //============================================================================== 00158 #endif // RTC_ARRAY_H defined 00159 //============================================================================== 00160