SDIFMatrix.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _SdifMatrix_hxx_
00023 #define _SdifMatrix_hxx_
00024
00025 #include "SDIFHeader.hxx"
00026
00027 #undef CLAM_USE_XML
00028 #include "Array.hxx"
00029
00030 #include "SDIFType.hxx"
00031
00032 namespace SDIF
00033 {
00047 class Matrix
00048 {
00049 friend class File;
00050 protected:
00051 MatrixHeader mHeader;
00052
00053 Matrix(const MatrixHeader& header)
00054 :mHeader(header)
00055 {
00056 }
00057
00058 Matrix(
00059 const TypeId& type = TypeId::sDefault,DataType dataType = eUnknown,
00060 CLAM::TInt32 nRows = 0, CLAM::TInt32 nColumns = 0);
00061 virtual char* GetPtr(void) = 0;
00062 virtual void Resize(int nElems) = 0;
00063 virtual void SetSize(int nElems) = 0;
00064 public:
00065 virtual ~Matrix() { }
00066
00067 TypeId Type(void) {return mHeader.mType;}
00068
00069 CLAM::TInt32 Rows(void) { return mHeader.mnRows; }
00070 CLAM::TInt32 Columns(void) { return mHeader.mnColumns; }
00071 CLAM::TInt32 SizeInFile(void)
00072 {
00073 CLAM::TUInt32 nElems = mHeader.mnColumns*mHeader.mnRows;
00074 CLAM::TUInt32 elemSize = mHeader.mDataType&0xFF;
00075 CLAM::TUInt32 size = nElems*elemSize;
00076 CLAM::TUInt32 padding = 8-size&7;
00077
00078 return mHeader.SizeInFile()+size+padding;
00079 }
00080 };
00081
00082 template <class T=CLAM::TFloat32> class ConcreteMatrix:public Matrix
00083 {
00084 friend class File;
00085 private:
00086 CLAM::Array<T> mpData;
00087 public:
00094 ConcreteMatrix(
00095 const TypeId& type = TypeId::sDefault,
00096 CLAM::TInt32 nRows = 0, CLAM::TInt32 nColumns = 0)
00097 : Matrix(type,GetType<T>::Get(),nRows,nColumns)
00098 {
00099 CLAM::TInt32 nElems = Rows()*Columns();
00100 Resize(nElems);
00101 SetSize(nElems);
00102 }
00103
00104 ConcreteMatrix(const MatrixHeader& header)
00105 :Matrix(header)
00106 {
00107 CLAM::TInt32 nElems = Rows()*Columns();
00108 Resize(nElems);
00109 SetSize(nElems);
00110 }
00111
00112 char* GetPtr(void) { return (char*)mpData.GetPtr(); }
00113 void Resize(int nElems) { mpData.Resize(nElems); }
00114 void SetSize(int nElems) { mpData.SetSize(nElems); }
00115
00116
00121 T GetValue(CLAM::TInt32 row,CLAM::TInt32 col)
00122 {
00123 return mpData[row*mHeader.mnColumns + col];
00124 }
00125
00130 void SetValue(CLAM::TInt32 row,CLAM::TInt32 col,const T& val)
00131 {
00132 mpData[row*mHeader.mnColumns + col] = val;
00133 }
00134 };
00135 }
00136
00137 #endif//_SdifMatrix_hxx_
00138