submatrix.inl

来自「图像分割算法」· INL 代码 · 共 221 行

INL
221
字号
//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 >
SubMatrix<T>::SubMatrix(void)
{
	xDim = 0;
	yDim = 0;
	columns = 0;
	clean = 0;
}


template< class T >
SubMatrix<T>::SubMatrix(SubMatrix<T> &m) 
{
	xDim = m.xDim;
	yDim = m.yDim;
	columns = m.columns;
	clean = new (std::nothrow) Cleaner<T>(columns);
	Utility::CheckPointer(clean);

}




template< class T >
SubMatrix<T>::~SubMatrix(void)
{
	
	if(clean != 0)
	{
		delete clean;
	}

}









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

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


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

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

template< class T >
SubMatrix<T>& SubMatrix<T>::operator= (T init)
{
	for(int i=0;i<xDim;i++)
	{
		for(int j=0;j<yDim;j++)
		{
			columns[i][j] = init;
		}
	}

	return *this;
}


template< class T >
SubMatrix<T>& SubMatrix<T>::operator= (SubMatrix<T>& m)
{
	if(&m != this)
	{
		if(xDim != m.xDim || yDim != m.yDim)
		{
			cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
			Utility::RunTimeError("(Sub)Matrices must be same size for the assignment!");
		}
		for(int i=0;i<m.xDim;i++)
		{
			for(int j=0;j<m.yDim;j++)
			{
				columns[i][j] = m.columns[i][j];
			}
		}
	}

	return *this;
}



template< class T >
SubMatrix<T>& SubMatrix<T>::operator= (Matrix<T>& m)
{
	if(xDim != m.xDim || yDim != m.yDim)
	{
		cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
		Utility::RunTimeError("(Sub)Matrices must be same size for the assignment!");
	}
	for(int i=0;i<m.xDim;i++)
	{
		for(int j=0;j<m.yDim;j++)
		{
			columns[i][j] = m.ElemNC(j,i);
		}
	}
	
	
	return *this;
}



template< class T >
inline T& SubMatrix<T>::operator() (const int j, const int i)
{

#ifdef CIMPL_BOUNDS_CHECK
	if(i<0 || i>=xDim || j<0 || j>=yDim)
	{
		cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
		Utility::RunTimeError("Index outside bounds!");
	}
#endif

	return columns[i][j];

}

template< class T >
inline Vector<T>& SubMatrix<T>::operator[] (const int i)
{
	return columns[i];
}











⌨️ 快捷键说明

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