You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
2.1 KiB
C++
120 lines
2.1 KiB
C++
#include "stdafx.h"
|
|
#include "CsvToImg.h"
|
|
|
|
|
|
CCsvToImg * gCsvToImg = new CCsvToImg;
|
|
std::map<const int, int> m_proportionEnergy;
|
|
int ColorRange::AllCnt = 0;
|
|
CCsvToImg::CCsvToImg()
|
|
{
|
|
}
|
|
|
|
|
|
CCsvToImg::~CCsvToImg()
|
|
{
|
|
}
|
|
|
|
bool CCsvToImg::ReadCsv2Img(CString CsvPath)
|
|
{
|
|
m_colorSchemeManager.currentScheme->ResetRangeCnt();
|
|
int Rows = 0, Cols = 0;
|
|
float* pData= GetCsvData(CsvPath, Rows, Cols);
|
|
if (!pData)
|
|
return false;
|
|
CreateImgFromData(pData, Rows, Cols, m_Img);
|
|
m_colorSchemeManager.currentScheme->CalRangesPercent();
|
|
delete []pData;
|
|
return true;
|
|
}
|
|
|
|
bool CCsvToImg::ShowLastImg(CWnd * pSHowWnd)
|
|
{
|
|
CSingleLock sLck(&m_Section, TRUE);
|
|
if (m_Img.IsNull())
|
|
return false;
|
|
CDC* pDC = pSHowWnd->GetDC();
|
|
HDC hDc = pDC->m_hDC;
|
|
RECT WndRect;
|
|
pSHowWnd->GetClientRect(&WndRect);
|
|
pDC->SetStretchBltMode(HALFTONE);
|
|
m_Img.StretchBlt(hDc, WndRect);
|
|
ReleaseDC(pSHowWnd->m_hWnd, hDc);
|
|
return true;
|
|
}
|
|
|
|
bool CCsvToImg::SaveLastImg(const CString & savePath)
|
|
{
|
|
if (m_Img.IsNull())
|
|
return false;
|
|
m_Img.Save(savePath);
|
|
}
|
|
|
|
#include "BeamCsvParserMT.h"
|
|
float * CCsvToImg::GetCsvData(const char * path, int & Rows, int & Cols)
|
|
{
|
|
CMappedFile mFile(path);
|
|
if (!mFile.IsValid())
|
|
return NULL;
|
|
|
|
const int size = mFile.Size();
|
|
const char *str = mFile.Data();
|
|
|
|
float * p = new float[size]();
|
|
|
|
int start = 0;
|
|
int end = 0;
|
|
|
|
int RowCnt = 0;
|
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
if (str[i] == ',')
|
|
{
|
|
char s[64]{ 0 };
|
|
memcpy(s, str + start, end);
|
|
p[idx++] = atof(s);
|
|
start = i + 1;
|
|
end = 0;
|
|
}
|
|
else if (str[i] == '\r')
|
|
{
|
|
char s[64]{ 0 };
|
|
memcpy(s, str + start, end);
|
|
p[idx++] = atof(s);
|
|
|
|
start = i + 2;
|
|
++i;
|
|
end = 0;
|
|
RowCnt++;
|
|
}
|
|
else
|
|
{
|
|
end++;
|
|
}
|
|
}
|
|
int ColCnt = idx / RowCnt;
|
|
Cols = ColCnt;
|
|
Rows = RowCnt;
|
|
return p;
|
|
}
|
|
|
|
bool CCsvToImg::CreateImgFromData(float * pDataOrg, int Rows, int Cols, CImage & image)
|
|
{
|
|
CSingleLock sLck(&m_Section, TRUE);
|
|
image.Destroy();
|
|
image.Create(Cols, Rows,24);
|
|
|
|
BYTE r = 0, g = 0, b = 0;
|
|
for (int i = 0; i < Rows; i++)
|
|
{
|
|
for (int j = 0; j < Cols; j++)
|
|
{
|
|
m_colorSchemeManager.currentScheme->getColor(*pDataOrg++,r,g,b);
|
|
image.SetPixelRGB(j, i, r,g,b);
|
|
}
|
|
}
|
|
return true;
|
|
}
|