#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 ResetRangeCnt()//重置各Range内数据量 { ColorRange::AllCnt = 0; for (auto& range : ranges) { range.Cnt = 0; } } void CalRangesPercent()//计算各Range内数据量占比 { 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: float * GetCsvData(const char * path, int & Rows, int & Cols); bool CreateImgFromData(float * pDataOrg, int Rows, int Cols, CImage & OutImg); CCriticalSection m_Section; public: ColorSchemeManager m_colorSchemeManager; CImage m_Img; }; extern CCsvToImg * gCsvToImg;