www.pudn.com > Image_segment.rar > MatrixList.inl
//Copyright (c) 2004-2005, Baris Sumengen //All rights reserved. // // CIMPL Matrix Performance Library // //Redistribution and use in source and binary //forms, with or without modification, are //permitted provided that the following //conditions are met: // // * No commercial use is allowed. // This software can only be used // for non-commercial purposes. This // distribution is mainly intended for // academic research and teaching. // * Redistributions of source code must // retain the above copyright notice, this // list of conditions and the following // disclaimer. // * Redistributions of binary form must // mention the above copyright notice, this // list of conditions and the following // disclaimer in a clearly visible part // in associated product manual, // readme, and web site of the redistributed // software. // * Redistributions in binary form must // reproduce the above copyright notice, // this list of conditions and the // following disclaimer in the // documentation and/or other materials // provided with the distribution. // * The name of Baris Sumengen may not be // used to endorse or promote products // derived from this software without // specific prior written permission. // //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT //HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT //NOT LIMITED TO, THE IMPLIED WARRANTIES OF //MERCHANTABILITY AND FITNESS FOR A PARTICULAR //PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE //CONTRIBUTORS BE LIABLE FOR ANY //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, //EXEMPLARY, OR CONSEQUENTIAL DAMAGES //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT //OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, //DATA, OR PROFITS; OR BUSINESS INTERRUPTION) //HOWEVER CAUSED AND ON ANY THEORY OF //LIABILITY, WHETHER IN CONTRACT, STRICT //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR //OTHERWISE) ARISING IN ANY WAY OUT OF THE USE //OF THIS SOFTWARE, EVEN IF ADVISED OF THE //POSSIBILITY OF SUCH DAMAGE. template< class T > MatrixList::MatrixList(void) { planes = 0; xDim = 0; yDim = 0; list = 0; } template< class T > MatrixList ::MatrixList(MatrixList & ml) { planes = ml.planes; xDim = ml.xDim; yDim = ml.yDim; list = new (std::nothrow) Matrix [ml.planes]; Utility::CheckPointer(list); for(int i=0; i MatrixList ::MatrixList(Matrix & m) { planes = 1; list = new (std::nothrow) Matrix [1]; Utility::CheckPointer(list); xDim = m.Columns(); yDim = m.Rows(); list[0] = m; } template< class T > MatrixList ::MatrixList(Matrix & m1, Matrix & m2) { if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns()) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("Matrix dimensions does not match to each other!"); } planes = 2; list = new (std::nothrow) Matrix [2]; Utility::CheckPointer(list); xDim = m1.Columns(); yDim = m1.Rows(); list[0] = m1; list[1] = m2; } template< class T > MatrixList ::MatrixList(Matrix & m1, Matrix & m2, Matrix & m3) { if(m1.Rows() != m2.Rows() || m1.Rows() != m3.Rows() || m2.Rows() != m3.Rows() || m1.Columns() != m2.Columns() || m1.Columns() != m3.Columns() || m2.Columns() != m3.Columns()) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("Matrix dimensions does not match to each other!"); } planes = 3; list = new (std::nothrow) Matrix [3]; Utility::CheckPointer(list); xDim = m1.Columns(); yDim = m1.Rows(); list[0] = m1; list[1] = m2; list[2] = m3; } template< class T > MatrixList ::MatrixList(int l, int rows, int cols) { planes = l; xDim = cols; yDim = rows; list = new (std::nothrow) Matrix [l]; Utility::CheckPointer(list); for(int i=0; i (rows, cols); } } template< class T > MatrixList ::~MatrixList(void) { delete [] list; } template< class T > void MatrixList ::PushBack(Matrix & m) { if(list ==0) { planes = 1; list = new (std::nothrow) Matrix [1]; Utility::CheckPointer(list); xDim = m.Columns(); yDim = m.Rows(); list[0] = m; //cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; //Utility::RunTimeError("MatrixList needs to be initialized first before appending new matrices!"); } else { if(m.Rows() != yDim || m.Columns() != xDim) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("Matrix dimensions does not match to MatrixList!"); } Matrix *temp = new (std::nothrow) Matrix [planes+1]; Utility::CheckPointer(temp); for(int i=0;i void MatrixList ::PushFront(Matrix & m) { if(list ==0) { planes = 1; list = new (std::nothrow) Matrix [1]; Utility::CheckPointer(list); xDim = m.Columns(); yDim = m.Rows(); list[0] = m; //cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; //Utility::RunTimeError("MatrixList needs to be initialized first before appending new matrices!"); } else { if(m.Rows() != yDim || m.Columns() != xDim) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("Matrix dimensions does not match to MatrixList!"); } Matrix *temp = new (std::nothrow) Matrix [planes+1]; Utility::CheckPointer(temp); for(int i=0;i void MatrixList ::PopBack(void) { if(list == 0) { Utility::Warning("MatrixList is empty. Nothing to pop!"); } else if(planes == 1) { delete [] list; list = 0; planes = 0; xDim = 0; yDim = 0; } else { Matrix *temp = new (std::nothrow) Matrix [planes-1]; Utility::CheckPointer(temp); for(int i=0;i void MatrixList ::PopFront(void) { if(list == 0) { Utility::Warning("MatrixList is empty. Nothing to pop!"); } else if(planes == 1) { delete [] list; list = 0; planes = 0; xDim = 0; yDim = 0; } else { Matrix *temp = new (std::nothrow) Matrix [planes-1]; Utility::CheckPointer(temp); for(int i=1;i int MatrixList ::Planes() const { return planes; } template< class T > int MatrixList ::Rows() const { return yDim; } template< class T > int MatrixList ::Columns() const { return xDim; } template< class T > int MatrixList ::XDim() const { return xDim; } template< class T > int MatrixList ::YDim() const { return yDim; } template< class T > MatrixList & MatrixList ::operator= (MatrixList & ml) { if(&ml != this) { planes = ml.planes; xDim = ml.xDim; yDim = ml.yDim; delete [] list; list = new (std::nothrow) Matrix [ml.planes]; Utility::CheckPointer(list); for(int i=0; i Matrix & MatrixList ::operator[] (const int i) { return list[i]; } template< class T > Matrix & MatrixList ::operator() (const int i) { #ifdef CIMPL_BOUNDS_CHECK if(i<0 || i>=planes) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("Index outside bounds!"); } #endif return list[i]; }