a
This commit is contained in:
@@ -0,0 +1,396 @@
|
||||
// SptPtSort.cpp: implementation of the CSptPtSort class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "SptPtSort.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CSptPtSort::CSptPtSort()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSptPtSort::~CSptPtSort()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CSptPtSort::MultiChannlePtSortForMNB(CPtrArray* pSptPtArray)
|
||||
{
|
||||
if (NULL == pSptPtArray)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("pSptPtArray不能为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("pSptPtArray can not be null."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
m_mapSptKey.clear();
|
||||
STSptPtSubKetVt sptKeyInfoVt;
|
||||
int iSize = pSptPtArray->GetSize();
|
||||
CSptRecord *pSptRecord = NULL;
|
||||
std::map<int, STSptPtSubKetVt>::iterator iter;
|
||||
STSptPtSubKetVt stSptPtVt;
|
||||
//首先构建MAP表
|
||||
int i = 0;
|
||||
for (i = 0; i < iSize; i++)
|
||||
{
|
||||
pSptRecord = (CSptRecord*)pSptPtArray->GetAt(i);
|
||||
if (pSptRecord == NULL)
|
||||
continue;
|
||||
|
||||
//int iATmp = (pSptRecord->m_iC1 < 1) ? 0 : pSptRecord->m_iC1;
|
||||
//int iAB = ((iATmp << 16) | (WORD)(pSptRecord->m_iC2));
|
||||
iter = m_mapSptKey.find(pSptRecord->m_iTsn);
|
||||
STSptPtSubKeyInfo stSubKeyInfo;
|
||||
stSubKeyInfo.iPosIndex = i;
|
||||
stSubKeyInfo.wMPt = pSptRecord->m_iP1;
|
||||
stSubKeyInfo.wNPt = pSptRecord->m_iP2;
|
||||
stSubKeyInfo.bIsFind = false;
|
||||
//如果查找到
|
||||
if (iter != m_mapSptKey.end())
|
||||
{
|
||||
iter->second.mapSptSubkeyInfo[pSptRecord->m_iP1] = stSubKeyInfo;
|
||||
}
|
||||
//如果没有查找到则将新的点作为节点插入
|
||||
else
|
||||
{
|
||||
stSptPtVt.ClearContent();
|
||||
stSptPtVt.mapSptSubkeyInfo[pSptRecord->m_iP1] = stSubKeyInfo;
|
||||
m_mapSptKey[pSptRecord->m_iTsn] = stSptPtVt;
|
||||
}
|
||||
}
|
||||
CPtrArray sortPtrArr;
|
||||
sortPtrArr.RemoveAll();
|
||||
iter = m_mapSptKey.begin();
|
||||
|
||||
//开始遍历整个MAP表,获取排序后的
|
||||
for (; iter != m_mapSptKey.end(); iter++)
|
||||
{
|
||||
int iFindCnt = 1;
|
||||
std::map<int, STSptPtSubKeyInfo>::iterator subIter = iter->second.mapSptSubkeyInfo.begin();
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(subIter->second.iPosIndex));
|
||||
int iSize = iter->second.mapSptSubkeyInfo.size();
|
||||
subIter->second.bIsFind = true;
|
||||
int iN = subIter->second.wNPt;
|
||||
std::map<int, STSptPtSubKeyInfo>::iterator iterLastMinM = subIter;
|
||||
while (iFindCnt < iSize)
|
||||
{
|
||||
subIter = iter->second.mapSptSubkeyInfo.find(iN);
|
||||
//用此时的N去查找,如果查找到,则直接用该值作为下一个MN的位置
|
||||
if (subIter != iter->second.mapSptSubkeyInfo.end())
|
||||
{
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(subIter->second.iPosIndex));
|
||||
iN = subIter->second.wNPt;
|
||||
subIter->second.bIsFind = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (iterLastMinM != iter->second.mapSptSubkeyInfo.end())
|
||||
{
|
||||
iterLastMinM++;
|
||||
//如果没有被使用
|
||||
if (false == iterLastMinM->second.bIsFind)
|
||||
{
|
||||
iterLastMinM->second.bIsFind = true;
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(iterLastMinM->second.iPosIndex));
|
||||
iN = iterLastMinM->second.wNPt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iFindCnt++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//开始将排序好的链表代替原有的
|
||||
if (iSize != sortPtrArr.GetSize())
|
||||
{
|
||||
CString strErr = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("多通道错误的排序点。初始大小= %d,排序大小= %d"), iSize, sortPtrArr.GetSize());
|
||||
AfxMessageBox(strErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Sort point of multi-channel error.orginal size = %d, sort size = %d"), iSize, sortPtrArr.GetSize());
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pSptPtArray->RemoveAll();
|
||||
int iTsn = 0;
|
||||
CString strLog;
|
||||
strLog.Format(_T("\n\nCSptPtSort::MultiChannlePtSortForMNB 测点排序----------------begin---\n"));
|
||||
OutputDebugString(strLog);
|
||||
for (i = 0; i < iSize; i++)
|
||||
{
|
||||
pSptRecord = (CSptRecord*)sortPtrArr.GetAt(i);
|
||||
pSptRecord->m_iTsn = ++iTsn;
|
||||
strLog.Format(_T("CSptPtSort::MultiChannlePtSortForMNB Tsn=%d,A=%d,M=%d,N=%d,B=%d,k=%d,n=%d,level=%d\n"),
|
||||
pSptRecord->m_iTsn, pSptRecord->m_iC1, pSptRecord->m_iP1, pSptRecord->m_iP2,
|
||||
pSptRecord->m_iC2, pSptRecord->m_fK, pSptRecord->m_iN, pSptRecord->m_iLevel);
|
||||
OutputDebugString(strLog);
|
||||
pSptPtArray->Add(pSptRecord);
|
||||
}
|
||||
|
||||
strLog.Format(_T("CSptPtSort::MultiChannlePtSortForMNB 测点排序----------------end---\n\n"));
|
||||
OutputDebugString(strLog);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSptPtSort::MultiChannlePtSort(CPtrArray* pSptPtArray)
|
||||
{
|
||||
if (NULL == pSptPtArray)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("pSptPtArray不能为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("pSptPtArray can not be null."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
m_mapSptKey.clear();
|
||||
STSptPtSubKetVt sptKeyInfoVt;
|
||||
int iSize = pSptPtArray->GetSize();
|
||||
CSptRecord *pSptRecord = NULL;
|
||||
std::map<int,STSptPtSubKetVt>::iterator iter;
|
||||
STSptPtSubKetVt stSptPtVt;
|
||||
//首先构建MAP表
|
||||
int i = 0;
|
||||
for (i = 0; i < iSize; i++)
|
||||
{
|
||||
pSptRecord = (CSptRecord*)pSptPtArray->GetAt(i);
|
||||
int iATmp = (pSptRecord->m_iC1 < 1 ) ? 0 : pSptRecord->m_iC1;
|
||||
int iAB = ((iATmp << 16) | (WORD)(pSptRecord->m_iC2));
|
||||
iter = m_mapSptKey.find(iAB);
|
||||
STSptPtSubKeyInfo stSubKeyInfo;
|
||||
stSubKeyInfo.iPosIndex = i;
|
||||
stSubKeyInfo.wMPt = pSptRecord->m_iP1;
|
||||
stSubKeyInfo.wNPt = pSptRecord->m_iP2;
|
||||
stSubKeyInfo.bIsFind = false;
|
||||
//如果查找到
|
||||
if (iter != m_mapSptKey.end())
|
||||
{
|
||||
iter->second.mapSptSubkeyInfo[pSptRecord->m_iP1] = stSubKeyInfo;
|
||||
}
|
||||
//如果没有查找到则将新的点作为节点插入
|
||||
else
|
||||
{
|
||||
stSptPtVt.ClearContent();
|
||||
stSptPtVt.mapSptSubkeyInfo[pSptRecord->m_iP1] = stSubKeyInfo;
|
||||
m_mapSptKey[iAB] = stSptPtVt;
|
||||
}
|
||||
}
|
||||
CPtrArray sortPtrArr;
|
||||
sortPtrArr.RemoveAll();
|
||||
iter = m_mapSptKey.begin();
|
||||
|
||||
//开始遍历整个MAP表,获取排序后的
|
||||
for (; iter != m_mapSptKey.end(); iter++)
|
||||
{
|
||||
int iFindCnt = 1;
|
||||
std::map<int,STSptPtSubKeyInfo>::iterator subIter = iter->second.mapSptSubkeyInfo.begin();
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(subIter->second.iPosIndex));
|
||||
int iSize = iter->second.mapSptSubkeyInfo.size();
|
||||
subIter->second.bIsFind = true;
|
||||
int iN = subIter->second.wNPt;
|
||||
std::map<int,STSptPtSubKeyInfo>::iterator iterLastMinM = subIter;
|
||||
while(iFindCnt < iSize)
|
||||
{
|
||||
subIter = iter->second.mapSptSubkeyInfo.find(iN);
|
||||
//用此时的N去查找,如果查找到,则直接用该值作为下一个MN的位置
|
||||
if (subIter != iter->second.mapSptSubkeyInfo.end())
|
||||
{
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(subIter->second.iPosIndex));
|
||||
iN = subIter->second.wNPt;
|
||||
subIter->second.bIsFind = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(iterLastMinM != iter->second.mapSptSubkeyInfo.end())
|
||||
{
|
||||
iterLastMinM++;
|
||||
//如果没有被使用
|
||||
if (false == iterLastMinM->second.bIsFind)
|
||||
{
|
||||
iterLastMinM->second.bIsFind = true;
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(iterLastMinM->second.iPosIndex));
|
||||
iN = iterLastMinM->second.wNPt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iFindCnt++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//开始将排序好的链表代替原有的
|
||||
if (iSize != sortPtrArr.GetSize())
|
||||
{
|
||||
CString strErr = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("多通道错误的排序点。初始大小= %d,排序大小= %d"), iSize, sortPtrArr.GetSize());
|
||||
AfxMessageBox(strErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Sort point of multi-channel error.orginal size = %d, sort size = %d"), iSize, sortPtrArr.GetSize());
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pSptPtArray->RemoveAll();
|
||||
int iTsn = 0;
|
||||
for (i = 0; i < iSize; i++)
|
||||
{
|
||||
pSptRecord = (CSptRecord*)sortPtrArr.GetAt(i);
|
||||
pSptRecord->m_iTsn = ++iTsn;
|
||||
pSptPtArray->Add(pSptRecord);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CSptPtSort::MultiChannlePtCplSort(CPtrArray* pSptPtArray)
|
||||
{
|
||||
if (NULL == pSptPtArray)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("pSptPtArray不能为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("pSptPtArray can not be null."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
m_mapSptKey.clear();
|
||||
STSptPtSubKetVt sptKeyInfoVt;
|
||||
int iSize = pSptPtArray->GetSize();
|
||||
CSptRecord *pSptRecord = NULL;
|
||||
std::map<int,STSptPtSubKetVt>::iterator iter;
|
||||
STSptPtSubKetVt stSptPtVt;
|
||||
//首先构建MAP表
|
||||
int i = 0;
|
||||
for (i = 0; i < iSize; i++)
|
||||
{
|
||||
pSptRecord = (CSptRecord*)pSptPtArray->GetAt(i);
|
||||
int iATmp = (pSptRecord->m_iC1 < 1 ) ? 0 : pSptRecord->m_iC1;
|
||||
int iAB = ((iATmp << 16) | (WORD)(pSptRecord->m_iC2));
|
||||
iter = m_mapSptKey.find(iAB);
|
||||
STSptPtSubKeyInfo stSubKeyInfo;
|
||||
stSubKeyInfo.iPosIndex = i;
|
||||
stSubKeyInfo.wMPt = pSptRecord->m_iP1;
|
||||
stSubKeyInfo.wNPt = pSptRecord->m_iP2;
|
||||
stSubKeyInfo.bIsFind = false;
|
||||
std::map<int, STSptPtCplSubkeyInfo>::iterator iterCplSubKey;
|
||||
//如果查找到AB
|
||||
if (iter != m_mapSptKey.end())
|
||||
{
|
||||
//继续查找M
|
||||
iterCplSubKey = iter->second.mapSptCplSubkey.find(stSubKeyInfo.wMPt);
|
||||
//如果查找到M,则往同一个M的容器里插入
|
||||
if (iterCplSubKey != iter->second.mapSptCplSubkey.end())
|
||||
iterCplSubKey->second.vtSptSubkey.push_back(stSubKeyInfo);
|
||||
else
|
||||
{
|
||||
STSptPtCplSubkeyInfo stCplSubKeyTmp;
|
||||
stCplSubKeyTmp.vtSptSubkey.push_back(stSubKeyInfo);
|
||||
iter->second.mapSptCplSubkey[stSubKeyInfo.wMPt] = stCplSubKeyTmp;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//如果没有查找到则将新的点作为节点插入
|
||||
else
|
||||
{
|
||||
stSptPtVt.ClearContent();
|
||||
STSptPtCplSubkeyInfo stCplSubKey;
|
||||
stCplSubKey.vtSptSubkey.push_back(stSubKeyInfo);
|
||||
stSptPtVt.mapSptCplSubkey[stSubKeyInfo.wMPt] = stCplSubKey;
|
||||
m_mapSptKey[iAB] = stSptPtVt;
|
||||
}
|
||||
}
|
||||
CPtrArray sortPtrArr;
|
||||
sortPtrArr.RemoveAll();
|
||||
iter = m_mapSptKey.begin();
|
||||
|
||||
//开始遍历整个MAP表,获取排序后的
|
||||
for (; iter != m_mapSptKey.end(); iter++)
|
||||
{
|
||||
std::map<int,STSptPtCplSubkeyInfo>::iterator iterCplSubKey = iter->second.mapSptCplSubkey.begin();
|
||||
for (; iterCplSubKey != iter->second.mapSptCplSubkey.end(); iterCplSubKey++)
|
||||
{
|
||||
//开始遍历同一个M值里的vector的循环
|
||||
while(1)
|
||||
{
|
||||
int iIndex = iterCplSubKey->second.FindMinNPosIndex();
|
||||
if (iIndex < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(iterCplSubKey->second.vtSptSubkey[iIndex].iPosIndex));
|
||||
WORD wNPos = iterCplSubKey->second.vtSptSubkey[iIndex].wNPt;
|
||||
iterCplSubKey->second.vtSptSubkey[iIndex].bIsFind = true;
|
||||
std::map<int,STSptPtCplSubkeyInfo>::iterator iterTmp;
|
||||
while(1)
|
||||
{
|
||||
//此时开始以N的值作为M来进行搜索
|
||||
iterTmp = iter->second.mapSptCplSubkey.find(wNPos);
|
||||
//如果没有找到则退出循环
|
||||
if (iterTmp == iter->second.mapSptCplSubkey.end())
|
||||
{
|
||||
break;
|
||||
}
|
||||
//如果找到的,之前已经被用过了,也推出循环
|
||||
int iTmpIndex = iterTmp->second.FindMinNPosIndex();
|
||||
if (iTmpIndex < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sortPtrArr.Add(pSptPtArray->GetAt(iterTmp->second.vtSptSubkey[iTmpIndex].iPosIndex));
|
||||
iterTmp->second.vtSptSubkey[iTmpIndex].bIsFind = true;
|
||||
wNPos = iterTmp->second.vtSptSubkey[iTmpIndex].wNPt;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//开始将排序好的链表代替原有的
|
||||
if (iSize != sortPtrArr.GetSize())
|
||||
{
|
||||
CString strErr = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("多通道错误的排序点。初始大小= %d,排序大小= %d"), iSize, sortPtrArr.GetSize());
|
||||
AfxMessageBox(strErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Sort point of multi-channel error.orginal size = %d, sort size = %d"), iSize, sortPtrArr.GetSize());
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pSptPtArray->RemoveAll();
|
||||
int iTsn = 0;
|
||||
for (i = 0; i < iSize; i++)
|
||||
{
|
||||
pSptRecord = (CSptRecord*)sortPtrArr.GetAt(i);
|
||||
pSptRecord->m_iTsn = ++iTsn;
|
||||
pSptPtArray->Add(pSptRecord);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user