mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-18 19:39:43 +08:00
123445
This commit is contained in:
@ -13,6 +13,9 @@ file(GLOB_RECURSE SRC_LIST "source/*.cpp")
|
||||
include_directories("source")
|
||||
include_directories("source/ATP")
|
||||
include_directories("source/Logger")
|
||||
include_directories("source/ZZ_SDK")
|
||||
include_directories("source/Settings")
|
||||
include_directories("source/Thread")
|
||||
|
||||
add_executable( TowerOptoSifAndSpectral
|
||||
main.cpp
|
||||
|
3
main.cpp
3
main.cpp
@ -2,7 +2,7 @@
|
||||
#include "ATPControl_Serial_QT.h"
|
||||
#include "Logger.h"
|
||||
using namespace std;
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -12,6 +12,7 @@ int main(int argc, char *argv[])
|
||||
//QT_LOG::ZZ_InitLogger(QCoreApplication::applicationDirPath() + "/Log/");
|
||||
QString qstrTest="This is a test message 2";
|
||||
qDebug() << qstrTest;
|
||||
cout << "This is a test message";
|
||||
//////////////////////////////////////////////////////////////////////////test
|
||||
ZZ_ATPControl_Serial_Qt m_ctrlATP;
|
||||
QByteArray qbTest;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "ATPControl_Serial_QT.h"
|
||||
#include "ZZ_Math_HDRONLY.h"
|
||||
|
||||
ZZ_ATPControl_Serial_Qt::ZZ_ATPControl_Serial_Qt()
|
||||
{
|
||||
@ -62,17 +63,47 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceInfo()
|
||||
qbSend.clear();
|
||||
qbRecv.clear();
|
||||
qbSend.append(GET_PN_NUMBER);
|
||||
SendCommand(qbSend);
|
||||
RecvData(qbRecv);
|
||||
ParseData(qbRecv);
|
||||
int iRes = SendCommand(qbSend);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = RecvData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = ParseData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
m_adiDeviceInfo.strPN = qbRecv.data();
|
||||
|
||||
qbSend.clear();
|
||||
qbRecv.clear();
|
||||
qbSend.append(GET_SN_NUMBER);
|
||||
SendCommand(qbSend);
|
||||
RecvData(qbRecv);
|
||||
ParseData(qbRecv);
|
||||
iRes = SendCommand(qbSend);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = RecvData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = ParseData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
m_adiDeviceInfo.strSN = qbRecv.data();
|
||||
|
||||
|
||||
@ -86,22 +117,62 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceAttribute()
|
||||
qbSend.clear();
|
||||
qbRecv.clear();
|
||||
qbSend.append(GET_MIN_INTEGRATION_TIME);
|
||||
SendCommand(qbSend);
|
||||
RecvData(qbRecv);
|
||||
ParseData(qbRecv);
|
||||
int iRes = SendCommand(qbSend);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = RecvData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = ParseData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
m_adaDeviceAttr.iMinIntegrationTime = (ZZ_U8)qbRecv[1] + (ZZ_U8)qbRecv[0] * 256;
|
||||
|
||||
qbSend.clear();
|
||||
qbRecv.clear();
|
||||
qbSend.append(GET_MAX_INTEGRATION_TIME);
|
||||
SendCommand(qbSend);
|
||||
RecvData(qbRecv);
|
||||
ParseData(qbRecv);
|
||||
iRes = SendCommand(qbSend);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = RecvData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = ParseData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
m_adaDeviceAttr.iMaxIntegrationTime = (ZZ_U8)qbRecv[1] + (ZZ_U8)qbRecv[0] * 256;
|
||||
|
||||
|
||||
SetExposureTime(m_adaDeviceAttr.iMinIntegrationTime);
|
||||
SingleShot(m_adaDeviceAttr.iPixels);
|
||||
iRes = SetExposureTime(m_adaDeviceAttr.iMinIntegrationTime);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Call SetExposureTime error.Exit Code:2";
|
||||
return 2;
|
||||
}
|
||||
iRes = SingleShot(m_adaDeviceAttr.iPixels);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Call SingleShot error.Exit Code:3";
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
qbSend.clear();
|
||||
@ -110,15 +181,30 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceAttribute()
|
||||
qbSend.resize(3);
|
||||
qbSend[1] = 0x00;
|
||||
qbSend[2] = 0x01;
|
||||
SendCommand(qbSend);
|
||||
RecvData(qbRecv);
|
||||
ParseData(qbRecv);
|
||||
|
||||
iRes = SendCommand(qbSend);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = RecvData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = ParseData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
float fWaveLengthCoef[4];
|
||||
memcpy(fWaveLengthCoef, qbRecv.data()+16, 4 * sizeof(float));
|
||||
// for ()
|
||||
// {
|
||||
// }
|
||||
for (int i=0;i< m_adaDeviceAttr.iPixels;i++)
|
||||
{
|
||||
m_adaDeviceAttr.fWaveLength[i] = fWaveLengthCoef[0] * i*i*i + fWaveLengthCoef[1] * i*i + fWaveLengthCoef[2] * i + fWaveLengthCoef[3];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -144,7 +230,7 @@ int ZZ_ATPControl_Serial_Qt::SendCommand(QByteArray qbCommand)
|
||||
qint64 qi64Write= m_pSerialPort->write(qbSend);
|
||||
if (qi64Write != qbSend.size())
|
||||
{
|
||||
qDebug() << "Err:write Failed.Exit Code:1";
|
||||
qDebug() << "Err:write Failed.Exit Code:1"<< qi64Write;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -165,7 +251,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData(QByteArray &qbData)
|
||||
|
||||
if (iCounter > 10)
|
||||
{
|
||||
qDebug() << "Err:RecvData Failed,Not Enough Data.Exit Code:1"<<qbData.size();
|
||||
qDebug() << "Err:RecvData Failed,Not Enough Data.Exit Code:1"<< qbData.size();
|
||||
return 1;
|
||||
}
|
||||
iCounter++;
|
||||
@ -228,6 +314,136 @@ int ZZ_ATPControl_Serial_Qt::ParseData(QByteArray &qbData)
|
||||
|
||||
int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fMaxScaleFactor, float &fPredictedExposureTime)
|
||||
{
|
||||
using namespace ZZ_MATH;
|
||||
int iDeviceDepth = 65535;
|
||||
|
||||
bool bFlagIsOverTrying = false;
|
||||
bool bFlagIsLowerMinExposureTime = false;
|
||||
bool bFlagIsOverMaxExposureTime = false;
|
||||
bool bFlagIsAutoExposureOK = false;
|
||||
bool bFlagIsAutoExposureFailed = false;
|
||||
|
||||
bool bIsValueOverflow = false;
|
||||
bool bIsLastValueOverflow = false;
|
||||
|
||||
float fExposureTime = 0;
|
||||
float fTempExposureTime = 0;
|
||||
double fLastExposureTime = 0.1;
|
||||
int iRepeatCount = 0;
|
||||
|
||||
int iRes = SetExposureTime(2000);//need change to load from files
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed)
|
||||
{
|
||||
ATPDataFrame dfTemp;
|
||||
|
||||
if (iRepeatCount++ > 30)
|
||||
{
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
bFlagIsOverTrying = true;
|
||||
break;
|
||||
}
|
||||
|
||||
fExposureTime = (float)m_adaDeviceAttr.iMinIntegrationTime;
|
||||
fTempExposureTime = fExposureTime;
|
||||
|
||||
iRes = SingleShot(dfTemp);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2";
|
||||
return 2;
|
||||
}
|
||||
|
||||
HeapSort(dfTemp.usData, m_adaDeviceAttr.iPixels);
|
||||
|
||||
double dSum = 0;
|
||||
int iCount = m_adaDeviceAttr.iPixels / 100;
|
||||
for (int i = 0; i < iCount; i++)
|
||||
{
|
||||
dSum += dfTemp.usData[i];
|
||||
}
|
||||
double dTemp = dSum / iCount;
|
||||
|
||||
if (dTemp >= iDeviceDepth * 0.99)
|
||||
{
|
||||
bIsValueOverflow = true;
|
||||
if (!bIsLastValueOverflow)
|
||||
{
|
||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
fExposureTime = fExposureTime / 2;
|
||||
}
|
||||
}
|
||||
|
||||
else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor)
|
||||
{
|
||||
bFlagIsAutoExposureOK = 1;
|
||||
}
|
||||
else if (dTemp > iDeviceDepth * fMaxScaleFactor)
|
||||
{
|
||||
bIsValueOverflow = true;
|
||||
if (!bIsLastValueOverflow)
|
||||
{
|
||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
fExposureTime = fExposureTime * 3 / 4;
|
||||
}
|
||||
}
|
||||
else if (dTemp < iDeviceDepth * fMinScaleFactor)
|
||||
{
|
||||
bIsValueOverflow = false;
|
||||
if (bIsLastValueOverflow)
|
||||
{
|
||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
double dFactor;
|
||||
dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor);
|
||||
fExposureTime = (float)(fExposureTime / dFactor);
|
||||
}
|
||||
if (/*fExposureTime > 100 || */fExposureTime < 10)
|
||||
{
|
||||
bFlagIsAutoExposureOK = false;
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
bFlagIsLowerMinExposureTime = true;
|
||||
}
|
||||
}
|
||||
bIsLastValueOverflow = bIsValueOverflow;
|
||||
fLastExposureTime = fTempExposureTime;
|
||||
|
||||
if (fExposureTime > 13000)
|
||||
{
|
||||
bFlagIsAutoExposureOK = false;
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
fPredictedExposureTime = 13000;
|
||||
iRes = SetExposureTime(13000);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3";
|
||||
return 3;
|
||||
}
|
||||
bFlagIsOverMaxExposureTime = true;
|
||||
break;
|
||||
}
|
||||
|
||||
iRes = SetExposureTime((int)fExposureTime);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4";
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
fPredictedExposureTime = fExposureTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -282,9 +498,6 @@ int ZZ_ATPControl_Serial_Qt::SingleShot(ATPDataFrame &dfData)
|
||||
|
||||
}
|
||||
|
||||
//int isize = qbRecv.size();
|
||||
//m_adaDeviceAttr.iPixels = isize / 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,6 @@ public:
|
||||
ZZ_ATPControl_Serial_Qt();
|
||||
virtual ~ZZ_ATPControl_Serial_Qt();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////shutter control stub code s
|
||||
int SetExtShutter(int iShutterA,int iShutterB); //0:close 1:open
|
||||
//////////////////////////////////////////////////////////////////////////shutter control stub code e
|
||||
public:
|
||||
int SetBaudRate(int iBaud);
|
||||
|
||||
@ -28,6 +25,7 @@ public:
|
||||
int SingleShotDeducted(ATPDataFrame &dfData);
|
||||
|
||||
int SetExposureTime(int iExposureTimeInMS);
|
||||
int GetExposureTime(int &iExposureTimeInMS);
|
||||
|
||||
//int GetWaveLength(float *pfWaveLength);
|
||||
int GetDeviceInfo();
|
||||
@ -49,6 +47,10 @@ private:
|
||||
//ATP
|
||||
ATPDeviceInfo m_adiDeviceInfo;
|
||||
ATPDeviceAttribute m_adaDeviceAttr;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////shutter control stub code s
|
||||
int SetExtShutter(int iShutterA, int iShutterB); //0:close 1:open
|
||||
//////////////////////////////////////////////////////////////////////////shutter control stub code e
|
||||
int SendCommand(QByteArray qbCommand);
|
||||
int RecvData(QByteArray &qbData);
|
||||
int ParseData(QByteArray &qbData);
|
||||
|
0
source/ATP/ATPDataFileProcessor.cpp
Normal file
0
source/ATP/ATPDataFileProcessor.cpp
Normal file
1
source/ATP/ATPDataFileProcessor.h
Normal file
1
source/ATP/ATPDataFileProcessor.h
Normal file
@ -0,0 +1 @@
|
||||
#pragma once
|
@ -39,6 +39,7 @@ namespace ZZ_MISCDEF
|
||||
const int SET_GPIO = 0x61;
|
||||
//const int SYNCHRONIZATION_GET_DARK = 0x23
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////device
|
||||
enum Model
|
||||
{
|
||||
ATP1010 = 0,
|
||||
@ -67,6 +68,37 @@ namespace ZZ_MISCDEF
|
||||
float fWaveLength[4096];
|
||||
|
||||
}ATPDeviceAttribute;
|
||||
//////////////////////////////////////////////////////////////////////////config file
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace ZZ_DATAFILE
|
||||
{
|
||||
typedef struct tagEnvironmentalContext
|
||||
{
|
||||
|
||||
|
||||
}EnvironmentalContext;
|
||||
|
||||
typedef struct tagIS1Information
|
||||
{
|
||||
|
||||
|
||||
}IS1Info;
|
||||
|
||||
typedef struct tagISIFInformation
|
||||
{
|
||||
|
||||
|
||||
}ISIFInfo;
|
||||
|
||||
typedef struct tagATPDataHeader
|
||||
{
|
||||
|
||||
|
||||
}ATPDataHeader;
|
||||
}
|
||||
|
||||
}
|
||||
|
25
source/Settings/SystemConfigger.cpp
Normal file
25
source/Settings/SystemConfigger.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "SystemConfigger.h"
|
||||
|
||||
ZZ_SysConfigger::ZZ_SysConfigger(QObject *parent /*= nullptr*/)
|
||||
{
|
||||
m_qstrFilePath = QCoreApplication::applicationDirPath()+ "/Settings/DeviceSettings.ini";
|
||||
}
|
||||
|
||||
ZZ_SysConfigger::~ZZ_SysConfigger()
|
||||
{
|
||||
}
|
||||
|
||||
int ZZ_SysConfigger::LoadSettings_IS1()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_SysConfigger::LoadSettings_iSIF()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_SysConfigger::LoadSettings_System()
|
||||
{
|
||||
return 0;
|
||||
}
|
21
source/Settings/SystemConfigger.h
Normal file
21
source/Settings/SystemConfigger.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class ZZ_SysConfigger :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ZZ_SysConfigger(QObject *parent = nullptr);
|
||||
virtual ~ZZ_SysConfigger();
|
||||
public:
|
||||
int LoadSettings_IS1();
|
||||
int LoadSettings_iSIF();
|
||||
int LoadSettings_System();
|
||||
|
||||
private:
|
||||
QString m_qstrFilePath;
|
||||
};
|
0
source/Thread/ThreadDataGrabber.cpp
Normal file
0
source/Thread/ThreadDataGrabber.cpp
Normal file
1
source/Thread/ThreadDataGrabber.h
Normal file
1
source/Thread/ThreadDataGrabber.h
Normal file
@ -0,0 +1 @@
|
||||
#pragma once
|
0
source/Thread/ThreadIS1Controller.cpp
Normal file
0
source/Thread/ThreadIS1Controller.cpp
Normal file
1
source/Thread/ThreadIS1Controller.h
Normal file
1
source/Thread/ThreadIS1Controller.h
Normal file
@ -0,0 +1 @@
|
||||
#pragma once
|
12
source/Thread/ThreadISIFController.h
Normal file
12
source/Thread/ThreadISIFController.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
|
||||
|
||||
|
||||
class ZZ_iSIFControlThread :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ZZ_iSIFControlThread(QObject* parent = nullptr);
|
||||
~ZZ_iSIFControlThread();
|
||||
};
|
0
source/Thread/ThreadiSIFController.cpp
Normal file
0
source/Thread/ThreadiSIFController.cpp
Normal file
84
source/ZZ_SDK/ZZ_Math_HDRONLY.h
Normal file
84
source/ZZ_SDK/ZZ_Math_HDRONLY.h
Normal file
@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
namespace ZZ_MATH
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
void MinHeapify(T*arry, int size, int element)
|
||||
{
|
||||
int lchild = element * 2 + 1, rchild = lchild + 1;
|
||||
while (rchild < size)
|
||||
{
|
||||
if (arry[element] <= arry[lchild] && arry[element] <= arry[rchild])
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (arry[lchild] <= arry[rchild])
|
||||
{
|
||||
std::swap(arry[element], arry[lchild]);
|
||||
element = lchild;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::swap(arry[element], arry[rchild]);
|
||||
element = rchild;
|
||||
}
|
||||
lchild = element * 2 + 1;
|
||||
rchild = lchild + 1;
|
||||
}
|
||||
if (lchild < size&&arry[lchild] < arry[element])
|
||||
{
|
||||
std::swap(arry[lchild], arry[element]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void MaxHeapify(T*arry, int size, int element)
|
||||
{
|
||||
int lchild = element * 2 + 1, rchild = lchild + 1;
|
||||
while (rchild < size)
|
||||
{
|
||||
if (arry[element] >= arry[lchild] && arry[element] >= arry[rchild])
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (arry[lchild] >= arry[rchild])
|
||||
{
|
||||
std::swap(arry[element], arry[lchild]);
|
||||
element = lchild;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::swap(arry[element], arry[rchild]);
|
||||
element = rchild;
|
||||
}
|
||||
lchild = element * 2 + 1;
|
||||
rchild = lchild + 1;
|
||||
}
|
||||
if (lchild<size&&arry[lchild]>arry[element])
|
||||
{
|
||||
std::swap(arry[lchild], arry[element]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void HeapSort(T*arry, int size)
|
||||
{
|
||||
int i;
|
||||
for (i = size - 1; i >= 0; i--)
|
||||
{
|
||||
MinHeapify(arry, size, i);
|
||||
}
|
||||
while (size > 0)
|
||||
{
|
||||
std::swap(arry[size - 1], arry[0]);
|
||||
|
||||
size--;
|
||||
MinHeapify(arry, size, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user