⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrixlist.inl

📁 图像分割算法
💻 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<T>::MatrixList(void)
{
	planes = 0;
	xDim = 0;
	yDim = 0;
	list = 0;
}


template< class T >
MatrixList<T>::MatrixList(MatrixList<T>& ml)
{
	planes = ml.planes;
	xDim = ml.xDim;
	yDim = ml.yDim;
	list = new (std::nothrow) Matrix<T>[ml.planes];
	Utility::CheckPointer(list);
	for(int i=0; i<planes; i++)
	{
		list[i] = ml.list[i];
	}
}

template< class T >
MatrixList<T>::MatrixList(Matrix<T>& m)
{
	planes = 1;
	list = new (std::nothrow) Matrix<T>[1];
	Utility::CheckPointer(list);
	xDim = m.Columns();
	yDim = m.Rows();
	list[0] = m;
}

template< class T >
MatrixList<T>::MatrixList(Matrix<T>& m1, Matrix<T>& 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<T>[2];
	Utility::CheckPointer(list);
	xDim = m1.Columns();
	yDim = m1.Rows();
	list[0] = m1;
	list[1] = m2;
}


template< class T >
MatrixList<T>::MatrixList(Matrix<T>& m1, Matrix<T>& m2, Matrix<T>& 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<T>[3];
	Utility::CheckPointer(list);
	xDim = m1.Columns();
	yDim = m1.Rows();
	list[0] = m1;
	list[1] = m2;
	list[2] = m3;
}


template< class T >
MatrixList<T>::MatrixList(int l, int rows, int cols)
{
	planes = l;
	xDim = cols;
	yDim = rows;
	
	list = new (std::nothrow) Matrix<T>[l];
	Utility::CheckPointer(list);
	
	for(int i=0; i<l; i++)
	{
		list[i] = Matrix<T>(rows, cols);
	}
}


template< class T >
MatrixList<T>::~MatrixList(void)
{
	delete [] list;
}


template< class T >
void MatrixList<T>::PushBack(Matrix<T>& m)
{
	if(list ==0)
	{
		planes = 1;
		list = new (std::nothrow) Matrix<T>[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<T> *temp = new (std::nothrow) Matrix<T>[planes+1];
		Utility::CheckPointer(temp);
		for(int i=0;i<planes;i++)
		{
			temp[i] = list[i];
		}
		temp[planes] = m;
		planes++;
		delete [] list;
		list = temp;
	}
}


template< class T >
void MatrixList<T>::PushFront(Matrix<T>& m)
{
	if(list ==0)
	{
		planes = 1;
		list = new (std::nothrow) Matrix<T>[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<T> *temp = new (std::nothrow) Matrix<T>[planes+1];
		Utility::CheckPointer(temp);
		for(int i=0;i<planes;i++)
		{
			temp[i+1] = list[i];
		}
		temp[0] = m;
		planes++;
		delete [] list;
		list = temp;
	}
}


template< class T >
void MatrixList<T>::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<T> *temp = new (std::nothrow) Matrix<T>[planes-1];
		Utility::CheckPointer(temp);
		for(int i=0;i<planes-1;i++)
		{
			temp[i] = list[i];
		}
		planes--;
		delete [] list;
		list = temp;
	}
}

template< class T >
void MatrixList<T>::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<T> *temp = new (std::nothrow) Matrix<T>[planes-1];
		Utility::CheckPointer(temp);
		for(int i=1;i<planes;i++)
		{
			temp[i-1] = list[i];
		}
		planes--;
		delete [] list;
		list = temp;
	}
}



template< class T >
int MatrixList<T>::Planes() const
{
	return planes;
}

template< class T >
int MatrixList<T>::Rows() const
{
	return yDim;
}

template< class T >
int MatrixList<T>::Columns() const
{
	return xDim;
}


template< class T >
int MatrixList<T>::XDim() const
{
	return xDim;
}

template< class T >
int MatrixList<T>::YDim() const
{
	return yDim;
}


template< class T >
MatrixList<T>& MatrixList<T>::operator= (MatrixList<T>& ml)
{
	if(&ml != this)
	{
		planes = ml.planes;
		xDim = ml.xDim;
		yDim = ml.yDim;
		
		delete [] list;
		list = new (std::nothrow) Matrix<T>[ml.planes];
		Utility::CheckPointer(list);
		for(int i=0; i<planes; i++)
		{
			list[i] = ml.list[i];
		}
	}
	return *this;
}



template< class T >
Matrix<T>& MatrixList<T>::operator[] (const int i)
{
	return list[i];
}



template< class T >
Matrix<T>& MatrixList<T>::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];
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -