153 lines
2.6 KiB
C++
153 lines
2.6 KiB
C++
#ifndef __QUADRANTINFO_H__
|
|
#define __QUADRANTINFO_H__
|
|
|
|
// 辅助T3DimArray完成区域扩大,不用在析构函数里处理指针
|
|
template<typename T>
|
|
class QuadrantInfo
|
|
{
|
|
public:
|
|
|
|
QuadrantInfo();
|
|
void GetMinXYZ(int &nX, int &nY, int &nZ);
|
|
void SetMinXYZ(int nX, int nY, int nZ);
|
|
void GetMaxXYZ(int &nX, int &nY, int &nZ);
|
|
void SetMaxXYZ(int nX, int nY, int nZ);
|
|
void GetPtr();
|
|
void SetPtr(T*** pVal);
|
|
// 将src指针中的数据移入当前对象中
|
|
void CopyData(const QuadrantInfo &src);
|
|
void Delete();
|
|
|
|
private:
|
|
|
|
// 判断src表示的区域是否在当前对象区域内
|
|
bool IsInZone(const QuadrantInfo &src);
|
|
|
|
private:
|
|
|
|
int m_nMinX, m_nMinY, m_nMinZ;
|
|
int m_nMaxX, m_nMaxY, m_nMaxZ;
|
|
T*** m_pArray;
|
|
|
|
};
|
|
|
|
template<typename T>
|
|
QuadrantInfo<T>::QuadrantInfo()
|
|
{
|
|
m_nMinX = 0;
|
|
m_nMinY = 0;
|
|
m_nMinZ = 0;
|
|
m_nMaxX = 0;
|
|
m_nMaxY = 0;
|
|
m_nMaxZ = 0;
|
|
m_pArray = NULL;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::GetMinXYZ(int &nX, int &nY, int &nZ)
|
|
{
|
|
nX = m_nMinX;
|
|
nY = m_nMinY;
|
|
nZ = m_nMinZ;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::SetMinXYZ(int nX, int nY, int nZ)
|
|
{
|
|
m_nMinX = nX;
|
|
m_nMinY = nY;
|
|
m_nMinZ = nZ;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::GetMaxXYZ(int &nX, int &nY, int &nZ)
|
|
{
|
|
nX = m_nMaxX;
|
|
nY = m_nMaxY;
|
|
nZ = m_nMaxZ;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::SetMaxXYZ(int nX, int nY, int nZ)
|
|
{
|
|
m_nMaxX = nX;
|
|
m_nMaxY = nY;
|
|
m_nMaxZ = nZ;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::GetPtr()
|
|
{
|
|
return m_pArray;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::SetPtr(T*** pVal)
|
|
{
|
|
m_pArray = pVal;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::CopyData(const QuadrantInfo &src)
|
|
{
|
|
if (IsInZone(src))
|
|
{
|
|
if (m_pArray != NULL && src.m_pArray != NULL)
|
|
{
|
|
for (int x = src.m_nMinX; x <= src.m_nMaxX; x++)
|
|
{
|
|
for (int y = src.m_nMinY; y <= src.m_nMaxY; y++)
|
|
{
|
|
for (int z = src.m_nMinZ; z <= src.m_nMaxZ; z++)
|
|
{
|
|
m_pArray[x][y][z] = src.m_pArray[x][y][z];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
template<typename T>
|
|
bool QuadrantInfo<T>::IsInZone(const QuadrantInfo &src)
|
|
{
|
|
if (m_nMinX <= src.m_nMinX && m_nMaxX >= src.m_nMaxX
|
|
&& m_nMinY <= src.m_nMinY && m_nMaxY >= src.m_nMaxY
|
|
&& m_nMinZ <= src.m_nMinZ && m_nMaxZ >= src.m_nMaxZ)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
template<typename T>
|
|
void QuadrantInfo<T>::Delete()
|
|
{
|
|
if (m_pArray == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 删除z
|
|
for (int x = m_nMinX; x < m_nMaxX + 1; x++)
|
|
{
|
|
for (int y = m_nMinY; y < m_nMaxY + 1; y++)
|
|
{
|
|
delete[] m_pArray[x][y];
|
|
}
|
|
}
|
|
|
|
// 删除y
|
|
for (x = m_nMinX; x < m_nMaxX + 1; x++)
|
|
{
|
|
delete[] m_pArray[x];
|
|
}
|
|
|
|
// 删除x
|
|
delete[] m_pArray;
|
|
m_pArray = NULL;
|
|
}
|
|
|
|
#endif
|
|
|