diff --git a/CcdDataImageProcessing/CcdDataImageProcessing.rc b/CcdDataImageProcessing/CcdDataImageProcessing.rc index 7597604..9eaa63b 100644 Binary files a/CcdDataImageProcessing/CcdDataImageProcessing.rc and b/CcdDataImageProcessing/CcdDataImageProcessing.rc differ diff --git a/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj b/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj index 900a382..04e8c15 100644 --- a/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj +++ b/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj @@ -29,8 +29,8 @@ Application true v140 - Unicode - Dynamic + MultiByte + Static Application @@ -187,6 +187,7 @@ + @@ -195,6 +196,7 @@ + Create diff --git a/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj.filters b/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj.filters index a550caf..2c7eb44 100644 --- a/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj.filters +++ b/CcdDataImageProcessing/CcdDataImageProcessing.vcxproj.filters @@ -36,6 +36,9 @@ 头文件 + + 头文件 + @@ -50,6 +53,9 @@ 源文件 + + 源文件 + diff --git a/CcdDataImageProcessing/CcdDataImageProcessingDlg.cpp b/CcdDataImageProcessing/CcdDataImageProcessingDlg.cpp index 1551dac..ba4e544 100644 --- a/CcdDataImageProcessing/CcdDataImageProcessingDlg.cpp +++ b/CcdDataImageProcessing/CcdDataImageProcessingDlg.cpp @@ -10,19 +10,7 @@ #define FILE_CCD_IMAGE_INFO_PATH _T("ccd_image_info.csv") #define FILE_CCD_DATAT_PATH _T("ccd_data_path.csv") -// ɫ -#define RED RGB(255, 0, 0) -#define ORANGE RGB(255, 165, 0) -#define YELLOW RGB(255, 255, 0) -#define GREEN RGB(0, 255, 0) -#define CYAN RGB(0, 255, 255) -#define BLUE RGB(0, 0, 255) -#define PURPLE RGB(128, 0, 128) -#define GREY RGB(169, 169, 169) -#define PINK RGB(255, 192, 203) -#define BLACK RGB(0, 0, 0) -#define WHITE RGB(255, 255, 255) -#define BROWN RGB(165, 42, 42) + // ؼIDӳ const int minEnergyCtrlIds[] = { IDC_MIN_ENERGY_EDIT1, IDC_MIN_ENERGY_EDIT2, IDC_MIN_ENERGY_EDIT3, @@ -53,8 +41,8 @@ const TCHAR* colorNames[] = { #ifdef _DEBUG #define new DEBUG_NEW #endif -ColorSchemeManager m_colorSchemeManager; -std::map m_proportionEnergy; +//ColorSchemeManager m_colorSchemeManager; + // Ӧó򡰹ڡ˵ CAboutDlg Ի @@ -171,11 +159,12 @@ void CCcdDataImageProcessingDlg::DoDataExchange(CDataExchange* pDX) DDX_Control(pDX, IDC_CCD_DATA_PATH_EDIT, m_CddDataPath); + DDX_Control(pDX, IDC_PIC_CTRL, m_PicCtrl); } BEGIN_MESSAGE_MAP(CCcdDataImageProcessingDlg, CDialogEx) ON_WM_SYSCOMMAND() - ON_WM_PAINT() +// ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_IMAGE_INFO_SAVE_BUTTON, &CCcdDataImageProcessingDlg::OnBnClickedImageInfoSaveButton) ON_BN_CLICKED(IDC_DLG_MIN_BUTTON, &CCcdDataImageProcessingDlg::OnBnClickedDlgMinButton) @@ -184,6 +173,7 @@ BEGIN_MESSAGE_MAP(CCcdDataImageProcessingDlg, CDialogEx) ON_BN_CLICKED(IDC_SLECT_PATH_BUTTON, &CCcdDataImageProcessingDlg::OnBnClickedSlectPathButton) ON_WM_PAINT() ON_BN_CLICKED(IDC_SAVE_IMAGE_BUTTON, &CCcdDataImageProcessingDlg::OnBnClickedSaveImageButton) + ON_WM_TIMER() END_MESSAGE_MAP() @@ -223,7 +213,7 @@ BOOL CCcdDataImageProcessingDlg::OnInitDialog() OnInitEnergyInfo(); OnInitCcdDataPath(); OnInitAll(); - + SetTimer(0, 500, NULL); return TRUE; // ǽõؼ򷵻 TRUE } @@ -313,7 +303,7 @@ void CCcdDataImageProcessingDlg::OnBnClickedImageInfoSaveButton() } // ʾɹ - AfxMessageBox(_T("CCDͼɫϢѱ棡")); + //AfxMessageBox(_T("CCDͼɫϢѱ棡"),MB_TOPMOST); } @@ -570,17 +560,9 @@ void CCcdDataImageProcessingDlg::OnBnClickedSlectPathButton() void CCcdDataImageProcessingDlg::OnBnClickedImageGenerateButton() { - // TODO: ִ - // һεĻ - m_data.clear(); // ֮ǰ - + CWaitCursor wait; CString cddDataPathInfo; GetDlgItemText(IDC_CCD_DATA_PATH_EDIT, cddDataPathInfo); - CStringA cstrA(cddDataPathInfo); // CString תΪ CStringA - std::string stdStr = cstrA.GetString(); // CStringA תΪ std::string - CFileMgr fileMgr; - fileMgr.ReadFileToStrVec(stdStr, m_data); // ļ energy_data.csv - m_colorSchemeManager.addScheme("Scheme1"); // Ӷɫ //---ȡз-------------------------------------------- @@ -620,42 +602,42 @@ void CCcdDataImageProcessingDlg::OnBnClickedImageGenerateButton() float maxEnergyValue = _tstof(maxEnergy); // תΪ float // ɫ - COLORREF color = WHITE; // ĬɫΪɫ + COLORREF color = RGB_WHITE; // ĬɫΪɫ if (colorCombo == colorNames[0]) { // Red - color = RED; + color = RGB_RED; } else if (colorCombo == colorNames[1]) { // Orange - color = ORANGE; + color = RGB_ORANGE; } else if (colorCombo == colorNames[2]) { // Yellow - color = YELLOW; + color = RGB_YELLOW; } else if (colorCombo == colorNames[3]) { // Green - color = GREEN; + color = RGB_GREEN; } else if (colorCombo == colorNames[4]) { // Cyan - color = CYAN; + color = RGB_CYAN; } else if (colorCombo == colorNames[5]) { // Blue - color = BLUE; + color = RGB_BLUE; } else if (colorCombo == colorNames[6]) { // Purple - color = PURPLE; + color = RGB_PURPLE; } else if (colorCombo == colorNames[7]) { // Grey - color = GREY; + color = RGB_GREY; } else if (colorCombo == colorNames[8]) { // Pink - color = PINK; + color = RGB_PINK; } else if (colorCombo == colorNames[9]) { // Black - color = BLACK; + color = RGB_BLACK; } else if (colorCombo == colorNames[10]) { // White - color = WHITE; + color = RGB_WHITE; } else if (colorCombo == colorNames[11]) { // Brown - color = BROWN; + color = RGB_BROWN; } // ѡӷΧ @@ -667,143 +649,154 @@ void CCcdDataImageProcessingDlg::OnBnClickedImageGenerateButton() //---ͼ-------------------------------------------------------- m_colorSchemeManager.setCurrentScheme("Scheme1"); // õǰɫΪ Scheme1 + gCsvToImg->m_colorSchemeManager = m_colorSchemeManager; + gCsvToImg->ReadCsv2Img(cddDataPathInfo); - // ػԻǿˢ - Invalidate(); // ǴΪЧ - UpdateWindow(); // ˢ´ - printf("11"); + auto Db2CString=[](float val) + { + CString str; + str.Format("%.3f", val); + return str; + }; + + auto ¤tScheme = gCsvToImg->m_colorSchemeManager.currentScheme; + + //CEdit ؼеռֵ (ûȫʱ쳣) + try + { + m_ProportionEnergy1.SetWindowText(Db2CString(currentScheme->ranges.at(0).dPercent)); + m_ProportionEnergy2.SetWindowText(Db2CString(currentScheme->ranges.at(1).dPercent)); + m_ProportionEnergy3.SetWindowText(Db2CString(currentScheme->ranges.at(2).dPercent)); + m_ProportionEnergy4.SetWindowText(Db2CString(currentScheme->ranges.at(3).dPercent)); + m_ProportionEnergy5.SetWindowText(Db2CString(currentScheme->ranges.at(4).dPercent)); + m_ProportionEnergy6.SetWindowText(Db2CString(currentScheme->ranges.at(5).dPercent)); + m_ProportionEnergy7.SetWindowText(Db2CString(currentScheme->ranges.at(6).dPercent)); + m_ProportionEnergy8.SetWindowText(Db2CString(currentScheme->ranges.at(7).dPercent)); + m_ProportionEnergy9.SetWindowText(Db2CString(currentScheme->ranges.at(8).dPercent)); + m_ProportionEnergy10.SetWindowText(Db2CString(currentScheme->ranges.at(9).dPercent)); + } + catch (...){} + + UpdateWindow(); } // ֵɫ COLORREF CCcdDataImageProcessingDlg::GetColorFromEnergy(float energy) { if (m_colorSchemeManager.currentScheme == nullptr) { - return WHITE; + return RGB_WHITE; } return m_colorSchemeManager.currentScheme->getColor(energy); } -void CCcdDataImageProcessingDlg::OnPaint() -{ - CPaintDC dc(this); // 豸 - CRect clientRect; - GetClientRect(&clientRect); // ȡͻ - - // ñɫ - dc.FillSolidRect(clientRect, RGB(255, 255, 255)); - - // - CFont font; - font.CreatePointFont(120, _T("Arial")); - dc.SelectObject(&font); - - // - int numRows = m_data.size(); - int numCols = (numRows > 0) ? m_data[0].size() : 0; - - // Ϊգǰ - if (numRows == 0 || numCols == 0) { - dc.TextOut(10, 10, _T("No data available")); - return; - } - - // ȡڵĿȺ͸߶ - int maxImageWidth = clientRect.Width(); // ʹôڵĿ - int maxImageHeight = clientRect.Height(); // ʹôڵĸ߶ - - // ÿݿĴСΣ - float pointSize; - if (numCols > 0) { - // ʹڿȶ̬ÿݿĴС - float maxPointSizeWidth = static_cast(maxImageWidth) / numCols; // ÿݿڿϵС - pointSize = static_cast(maxPointSizeWidth); // ѡƵĴС - } - else { - pointSize = 10; // ĬϴС - } - - // ߶ȿÿռ䣬̬ÿݿĸ߶ - int pointSizeHeight; - if (numRows > 0) { - // ʹڸ߶ȶ̬ÿݿĴС - float maxPointSizeHeight = static_cast(maxImageHeight) / numRows; // ÿݿڸ߶ϵС - pointSizeHeight = static_cast(maxPointSizeHeight); // ѡ߶ƵĴС - } - else { - pointSizeHeight = 10; // ĬϴС - } - - // ȡСֵȷݵܹӦ - if (pointSize > pointSizeHeight)pointSize = pointSizeHeight; - - // pointSize ̫СһСֵ - if (pointSize < 0.5) { - pointSize = 0.5; // ȷÿݵΪ 1 - } - - // ƫʹͼұߣϱϱ - int offsetX = 0; - int offsetY = 0; - - // ÿݵ - for (int row = 0; row < numRows; ++row) { - for (int col = 0; col < numCols; ++col) { - // ȷÿԪضЧ - if (row < m_data.size() && col < m_data[row].size()) { - try { - float energy = std::stof(m_data[row][col]); // ַתΪ - - // ͳ - if (energy < m_minEnergy) m_minEnergy = energy; // Сֵ - if (energy > m_maxEnergy) m_maxEnergy = energy; // ֵ - - m_NumEnergy++; - - // ȡֵӦɫ - COLORREF color = GetColorFromEnergy(energy); - dc.SetDCBrushColor(color); // ûˢɫ - - // 㵱ǰݵλãƫ - float scaledX = col * pointSize + offsetX; - float scaledY = row * pointSize + offsetY; - - // ݿ - CRect rect(scaledX, scaledY, scaledX + pointSize, scaledY + pointSize); - dc.FillSolidRect(rect, color); - } - catch (const std::invalid_argument& e) { - // ЧַĬֵ - continue; // ޷תΪ floatǰԪ - } - } - } - } - - // ʾСֵ - CString str; - str.Format(_T("Min Energy: %.2f, Max Energy: %.2f"), m_minEnergy, m_maxEnergy); - dc.TextOut(0, 1300, str); - UpProportionEnergy(); -} - -COLORREF ColorScheme::getColor(float energy) -{ - - for (const auto& range : ranges) { - if (energy >= range.minEnergy && energy <= range.maxEnergy) { - - //HWND hwd = (HWND)range.proportionEnergy; - //CString str; - //GetDlgItemText(range.proportionEnergy, str); // ȡؼָ - m_proportionEnergy[range.proportionEnergy]++; - return range.color; - } - } - return WHITE; // ĬϷذɫ - -} - +//void CCcdDataImageProcessingDlg::OnPaint() +//{ +// +// +// gCsvToImg->ShowLastImg(&m_PicCtrl); +// return; +// +// CPaintDC dc(this); // 豸 +// CRect clientRect; +// GetClientRect(&clientRect); // ȡͻ +// +// // ñɫ +// dc.FillSolidRect(clientRect, RGB(255, 255, 255)); +// +// // +// CFont font; +// font.CreatePointFont(120, _T("Arial")); +// dc.SelectObject(&font); +// +// // +// int numRows = m_data.size(); +// int numCols = (numRows > 0) ? m_data[0].size() : 0; +// +// // Ϊգǰ +// if (numRows == 0 || numCols == 0) { +// dc.TextOut(10, 10, _T("No data available")); +// return; +// } +// +// // ȡڵĿȺ͸߶ +// int maxImageWidth = clientRect.Width(); // ʹôڵĿ +// int maxImageHeight = clientRect.Height(); // ʹôڵĸ߶ +// +// // ÿݿĴСΣ +// float pointSize; +// if (numCols > 0) { +// // ʹڿȶ̬ÿݿĴС +// float maxPointSizeWidth = static_cast(maxImageWidth) / numCols; // ÿݿڿϵС +// pointSize = static_cast(maxPointSizeWidth); // ѡƵĴС +// } +// else { +// pointSize = 10; // ĬϴС +// } +// +// // ߶ȿÿռ䣬̬ÿݿĸ߶ +// int pointSizeHeight; +// if (numRows > 0) { +// // ʹڸ߶ȶ̬ÿݿĴС +// float maxPointSizeHeight = static_cast(maxImageHeight) / numRows; // ÿݿڸ߶ϵС +// pointSizeHeight = static_cast(maxPointSizeHeight); // ѡ߶ƵĴС +// } +// else { +// pointSizeHeight = 10; // ĬϴС +// } +// +// // ȡСֵȷݵܹӦ +// if (pointSize > pointSizeHeight)pointSize = pointSizeHeight; +// +// // pointSize ̫СһСֵ +// if (pointSize < 0.5) { +// pointSize = 0.5; // ȷÿݵΪ 1 +// } +// +// // ƫʹͼұߣϱϱ +// int offsetX = 0; +// int offsetY = 0; +// +// // ÿݵ +// for (int row = 0; row < numRows; ++row) { +// for (int col = 0; col < numCols; ++col) { +// // ȷÿԪضЧ +// if (row < m_data.size() && col < m_data[row].size()) { +// try { +// float energy = std::stof(m_data[row][col]); // ַתΪ +// +// // ͳ +// if (energy < m_minEnergy) m_minEnergy = energy; // Сֵ +// if (energy > m_maxEnergy) m_maxEnergy = energy; // ֵ +// +// m_NumEnergy++; +// +// // ȡֵӦɫ +// COLORREF color = GetColorFromEnergy(energy); +// dc.SetDCBrushColor(color); // ûˢɫ +// +// // 㵱ǰݵλãƫ +// float scaledX = col * pointSize + offsetX; +// float scaledY = row * pointSize + offsetY; +// +// // ݿ +// CRect rect(scaledX, scaledY, scaledX + pointSize, scaledY + pointSize); +// dc.FillSolidRect(rect, color); +// } +// catch (const std::invalid_argument& e) { +// // ЧַĬֵ +// continue; // ޷תΪ floatǰԪ +// } +// } +// } +// } +// +// // ʾСֵ +// CString str; +// str.Format(_T("Min Energy: %.2f, Max Energy: %.2f"), m_minEnergy, m_maxEnergy); +// dc.TextOut(0, 1300, str); +// UpProportionEnergy(); +//} void CCcdDataImageProcessingDlg::OnBnClickedSaveImageButton() { @@ -815,7 +808,8 @@ void CCcdDataImageProcessingDlg::OnBnClickedSaveImageButton() CString savePath = saveFileDlg.GetPathName(); // 2. ͼ񱣴溯 - SaveImage(savePath); + gCsvToImg->SaveLastImg(savePath); + //SaveImage(savePath); } } @@ -851,3 +845,14 @@ void CCcdDataImageProcessingDlg::SaveImage(const CString& savePath) } } + + +void CCcdDataImageProcessingDlg::OnTimer(UINT_PTR nIDEvent) +{ + // TODO: ڴϢ/Ĭֵ + gCsvToImg->ShowLastImg(&m_PicCtrl); + + + + CDialogEx::OnTimer(nIDEvent); +} diff --git a/CcdDataImageProcessing/CcdDataImageProcessingDlg.h b/CcdDataImageProcessing/CcdDataImageProcessingDlg.h index 0930bdc..1690734 100644 --- a/CcdDataImageProcessing/CcdDataImageProcessingDlg.h +++ b/CcdDataImageProcessing/CcdDataImageProcessingDlg.h @@ -1,14 +1,14 @@ // CcdDataImageProcessingDlg.h : ͷļ // - +#include "CsvToImg.h" #pragma once #include "afxwin.h" #include #include "FileMgr.h" #include #include -#define WHITE RGB(255, 255, 255) // WHITE ɫ + // CCcdDataImageProcessingDlg Ի class CCcdDataImageProcessingDlg : public CDialogEx @@ -33,7 +33,7 @@ protected: // ɵϢӳ亯 virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); - afx_msg void OnPaint(); +// afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() public: @@ -95,6 +95,7 @@ public: CStatic m_StaticCtrl; // ݳԱ + ColorSchemeManager m_colorSchemeManager; std::vector> m_data; // 洢ȡ float m_minEnergy, m_maxEnergy; float m_SumEnergy, m_NumEnergy; @@ -120,56 +121,8 @@ public: BOOL FileExists(const CString& strFilePath); COLORREF GetColorFromEnergy(float energy);// ֵɫ + CStatic m_PicCtrl; + afx_msg void OnTimer(UINT_PTR nIDEvent); }; -// ɫΧṹ -struct ColorRange { - float minEnergy; - float maxEnergy; - COLORREF color; - const int proportionEnergy; - ColorRange(float minE, float maxE, COLORREF col, const int proportionE) - : minEnergy(minE), maxEnergy(maxE), color(col), proportionEnergy(proportionE){} -}; - -// ɫ -class ColorScheme { -public: - std::string name; // - std::vector ranges; // 洢ΧͶӦɫ - - // ĬϹ캯 - ColorScheme() : name("") {} - - // 캯 - ColorScheme(std::string schemeName) : name(schemeName) {} - - // Χ - void addRange(float minEnergy, float maxEnergy, COLORREF color, const int proportionEnergy) { - ranges.push_back(ColorRange{ minEnergy, maxEnergy, color ,proportionEnergy}); - } - - // ֵضӦɫ - COLORREF getColor(float energy); -}; - -// ɫ -class ColorSchemeManager { -public: - std::map schemes; - ColorScheme* currentScheme; - - ColorSchemeManager() : currentScheme(nullptr) {} - - void addScheme(const std::string& name) { - schemes[name] = ColorScheme(name); - } - - void setCurrentScheme(const std::string& name) { - currentScheme = &schemes[name]; - } -}; - -extern ColorSchemeManager m_colorSchemeManager; -extern std::map m_proportionEnergy; diff --git a/CcdDataImageProcessing/CsvToImg.cpp b/CcdDataImageProcessing/CsvToImg.cpp new file mode 100644 index 0000000..54ffa4e --- /dev/null +++ b/CcdDataImageProcessing/CsvToImg.cpp @@ -0,0 +1,139 @@ +#include "stdafx.h" +#include "CsvToImg.h" + + +CCsvToImg * gCsvToImg = new CCsvToImg; +std::map m_proportionEnergy; +int ColorRange::AllCnt = 0; +CCsvToImg::CCsvToImg() +{ +} + + +CCsvToImg::~CCsvToImg() +{ +} + +bool CCsvToImg::ReadCsv2Img(CString CsvPath) +{ + m_colorSchemeManager.currentScheme->RestRangeCnt(); + int Rows = 0, Cols = 0; + int* pData= GetCsvData(CsvPath, Rows, Cols); + CreateImgFromData(pData, Rows, Cols, m_Img); + delete []pData; + return false; +} + +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); +} + + +int * CCsvToImg::GetCsvData(const char * path, int & Rows, int & Cols) +{ + std::ifstream file; + std::string sFilePath = path; + file.open(sFilePath, std::ifstream::in | std::ofstream::binary); + + if (!file.good()) + return NULL; + + std::stringstream buffer; + buffer << file.rdbuf(); + string sFile = buffer.str(); + const int size = sFile.size(); + const char *str = sFile.c_str(); + + int * p = new int[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[8]{ 0 }; + memcpy(s, str + start, end); + p[idx++] = atoi(s); + start = i + 1; + end = 0; + } + else if (str[i] == '\r') + { + char s[8]{ 0 }; + memcpy(s, str + start, end); + p[idx++] = atoi(s); + + start = i + 2; + ++i; + end = 0; + RowCnt++; + } + else + { + end++; + } + } + int ColCnt = idx / RowCnt; + Cols = ColCnt; + Rows = RowCnt; + return p; +} + +bool CCsvToImg::CreateImgFromData(int * pDataOrg, int Rows, int Cols, CImage & image) +{ + CSingleLock sLck(&m_Section, TRUE); + image.Destroy(); + image.Create(Rows, Cols,24); + byte* pSourceData = (byte*)image.GetBits(); + int image_pitch = 3; + + int r = 0, g = 0, b = 0; + int idx = 0; + for (int i = 0; i < Rows; i++) + { + for (int j = 0; j < Cols; j++) + { + + image.SetPixel(i, j, m_colorSchemeManager.currentScheme->getColor(*pDataOrg++)); + //RGB + /*if (pDataOrg[idx++]<100) + { + image.SetPixel(i, j, RGB_GREEN); + + / **(pSourceData + j * image_pitch + i * 3) = 0;//R + *(pSourceData + j * image_pitch + i * 3 + 1) = 0;//G + *(pSourceData + j * image_pitch + i * 3 + 2) = 255;* / + } + else + { + image.SetPixel(i, j, RGB_RED); + } */ + } + } + m_colorSchemeManager.currentScheme->CalRangesPercent(); + return true; +} diff --git a/CcdDataImageProcessing/CsvToImg.h b/CcdDataImageProcessing/CsvToImg.h new file mode 100644 index 0000000..041641b --- /dev/null +++ b/CcdDataImageProcessing/CsvToImg.h @@ -0,0 +1,127 @@ +#pragma once +#include +#include +#include +#include +#define RGB_WHITE RGB(255, 255, 255) // WHITE ɫ +// ɫ +#define RGB_RED RGB(255, 0, 0) +#define RGB_ORANGE RGB(255, 165, 0) +#define RGB_YELLOW RGB(255, 255, 0) +#define RGB_GREEN RGB(0, 255, 0) +#define RGB_CYAN RGB(0, 255, 255) +#define RGB_BLUE RGB(0, 0, 255) +#define RGB_PURPLE RGB(128, 0, 128) +#define RGB_GREY RGB(169, 169, 169) +#define RGB_PINK RGB(255, 192, 203) +#define RGB_BLACK RGB(0, 0, 0) +#define RGB_WHITE RGB(255, 255, 255) +#define RGB_BROWN RGB(165, 42, 42) +using namespace std; + +extern std::map m_proportionEnergy; +// ɫΧṹ +struct ColorRange +{ + float minEnergy=0; + float maxEnergy=0; + COLORREF color; + const int proportionEnergy=0; + ColorRange(float minE, float maxE, COLORREF col, const int proportionE) + : minEnergy(minE), maxEnergy(maxE), color(col), proportionEnergy(proportionE) {} + + int Cnt = 0; + static int AllCnt ; + float dPercent = 0; +}; + +// ɫ +class ColorScheme { +public: + std::string name; // + std::vector ranges; // 洢ΧͶӦɫ + + // ĬϹ캯 + ColorScheme() : name("") {} + + // 캯 + ColorScheme(std::string schemeName) : name(schemeName) {} + + // Χ + void addRange(float minEnergy, float maxEnergy, COLORREF color, const int proportionEnergy) + { + ranges.emplace_back( minEnergy, maxEnergy, color ,proportionEnergy); + } + + // ֵضӦɫ + COLORREF getColor(float energy) + { + for (auto& range : ranges) { + if (energy >= range.minEnergy && energy <= range.maxEnergy) + { + m_proportionEnergy[range.proportionEnergy]++; + range.Cnt++; + ColorRange::AllCnt++; + return range.color; + } + } + ColorRange::AllCnt++; + return RGB_WHITE; // ĬϷذɫ + } + + void RestRangeCnt() + { + ColorRange::AllCnt = 0; + for (auto& range : ranges) + { + range.Cnt = 0; + } + } + void CalRangesPercent() + { + for (auto& range : ranges) + { + range.dPercent = double(range.Cnt*100) / ColorRange::AllCnt; + } + } +}; + +// ɫ +class ColorSchemeManager +{ +public: + std::map schemes; + ColorScheme* currentScheme; + + ColorSchemeManager() : currentScheme(nullptr) {} + + void addScheme(const std::string& name) + { + schemes[name] = ColorScheme(name); + } + + void setCurrentScheme(const std::string& name) + { + currentScheme = &schemes[name]; + } +}; + +class CCsvToImg +{ +public: + CCsvToImg(); + virtual ~CCsvToImg(); + + bool ReadCsv2Img(CString CsvPath); + bool ShowLastImg(CWnd * pSHowWnd); + bool SaveLastImg(const CString& savePath); +private: + int * GetCsvData(const char * path, int & Rows, int & Cols); + bool CreateImgFromData(int * pDataOrg, int Rows, int Cols, CImage & OutImg); + CCriticalSection m_Section; +public: + ColorSchemeManager m_colorSchemeManager; + CImage m_Img; +}; + +extern CCsvToImg * gCsvToImg; \ No newline at end of file diff --git a/CcdDataImageProcessing/FileMgr.cpp b/CcdDataImageProcessing/FileMgr.cpp index dbabfe6..049b0b7 100644 --- a/CcdDataImageProcessing/FileMgr.cpp +++ b/CcdDataImageProcessing/FileMgr.cpp @@ -37,12 +37,12 @@ void CFileMgr::ReadFileToStrVec(const std::string& filePath, std::vector