// CCOS.Dev.FPD.DEMO.cpp : 定义 DLL 应用程序的导出函数。 // #include "CCOS.Dev.FPDDeviceMould.hpp" #include "Log4CPP.h" using namespace CCOS::Dev; using namespace CCOS::Dev::Detail::Detector; namespace nsFPD = CCOS::Dev::Detail::Detector; //extern Log4CPP::Logger* mLog::gLogger; //----------------------------------------------------------------------------- // AcqUnit //----------------------------------------------------------------------------- nsFPD::AcqUnit::AcqUnit(): m_strZskkFPDState("0"), m_strNoNeedWaitImage("0"), m_strLastImage(""), m_strAutonumousMapFinish("0"), m_strFluPPS("15.0"), m_strMaxFrameRate("30.0"), m_strAcqMode("RAD"), m_nFullWidth(3000), m_nFullHeight(3000), m_nPrevWidth(1500), m_nPrevHeight(1500), m_nBits(16), m_pFullImageQueue(NULL), m_pPrevImageData(NULL) { } nsFPD::AcqUnit:: ~AcqUnit() { } void OEM_IF nsFPD::AcqUnit::SetEventCenter(std::shared_ptr EventCenter) { m_EventCenter = EventCenter; } RET_STATUS nsFPD::AcqUnit::JSGetAcqMode(std::string& out) { out = m_strAcqMode; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::JSSetAcqMode(std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); FINFO("JSSetAcqMode. {$}", in.c_str()); if (json.GetFirstOf("P0") < 0) { return RET_STATUS::RET_FAILED; } string strMode = json["P0"].encode(); m_strAcqMode = strMode; RET_STATUS ret = SetAcqMode(m_strAcqMode); return ret; } RET_STATUS nsFPD::AcqUnit::JSSetResolution(std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); FINFO("JSSetResolution. {$}", in.c_str()); if (json.GetFirstOf("P0") < 0) { return RET_STATUS::RET_FAILED; } string strResolution = json["P0"].encode(); int nResolution = std::stoi(strResolution); RET_STATUS ret = SetResolution(nResolution); return ret; } RET_STATUS nsFPD::AcqUnit::SetResolution(int nResolution) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::JSSetGainMode(std::string in, std::string & out) { FINFO ("JSSetGainMode. {$}", in.c_str ()); ResDataObject json; json.decode(in.c_str()); string strP0 = (const char*)json["P0"]; float fGain = stof(strP0.c_str()); RET_STATUS ret = SetGainMode(fGain); out = "test@SetGainMode"; return ret; } RET_STATUS nsFPD::AcqUnit::JSSetBinningMode(std::string in, std::string& out) { FINFO ("JSSetBinningMode. {$}", in.c_str ()); ResDataObject json; json.decode(in.c_str()); string strP0 = (const char*)json["P0"]; string strP1 = (const char*)json["P1"]; int nX = atoi(strP0.c_str()); int nY = atoi(strP1.c_str()); RET_STATUS ret = SetBinningMode(nX, nY); out = "test@SetBinningMode"; return ret; } RET_STATUS nsFPD::AcqUnit::JSSetZoomMode(std::string in, std::string& out) { FINFO("JSSetZoomMode. {$}", in.c_str()); ResDataObject json; json.decode(in.c_str()); string strP0 = (const char*)json["P0"]; string strP1 = (const char*)json["P1"]; string strP2 = (const char*)json["P2"]; string strP3 = (const char*)json["P3"]; int nX1 = atoi(strP0.c_str()); int nY1 = atoi(strP1.c_str()); int nX2 = atoi(strP2.c_str()); int nY2 = atoi(strP3.c_str()); RET_STATUS ret = SetZoomMode(nX1, nY1, nX2, nY2); out = "test@SetZoomMode"; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::JSSetDemoImage(std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); string strP0, strP1, strP2; if (json.GetFirstOf("P0") >= 0) { strP0 = (const char*)json["P0"]; } if (json.GetFirstOf("P1") >= 0) { strP1 = (const char*)json["P1"]; } if (json.GetFirstOf("P2") >= 0) { strP2 = (const char*)json["P2"]; } FINFO("SetDemoImage in:{$}", in); out = "test@SetDemoImage"; SetDemoImage(strP0, strP1, strP2); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::SetDemoImage(string& strFile1, string& strFile2, string& strFile3) { return RET_STATUS::RET_SUCCEED; } bool nsFPD::AcqUnit::SetMaxBlockSize(const char *pQueName, DWORD BlockSize, DWORD FulBlockCount, DWORD PrevBlockCount) { return true; } bool nsFPD::AcqUnit::SetFulImageInfo(DWORD Height, DWORD Width, DWORD Bits, bool FetchFlag) { m_nFullWidth = Width; m_nFullHeight = Height; m_nBits = Bits; return true; } bool nsFPD::AcqUnit::SetPrevImageInfo(bool Support, DWORD Height, DWORD Width, bool FetchFlag) { m_nPrevWidth = Width; m_nPrevHeight = Height; return true; } RET_STATUS nsFPD::AcqUnit::JSGetZskkFPDState(std::string & out) { out = m_strZskkFPDState; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::SetZskkFPDState(string in) { FINFO("SetZskkFPDState in:{$}", in); if (in == "") { return RET_STATUS::RET_FAILED; } m_strZskkFPDState = in; m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::ZskkFPDState, m_strZskkFPDState); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::JSGetNoNeedWaitImage(std::string & out) { out = m_strNoNeedWaitImage; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::JSSetNoNeedWaitImage(std::string in) { FINFO("JSSetNoNeedWaitImage in:{$}", in); if (in == "") { return RET_STATUS::RET_FAILED; } m_strNoNeedWaitImage = in; return RET_STATUS::RET_SUCCEED; } void nsFPD::AcqUnit::SendNoNeedWaitImage(bool bflag) { FINFO("SendNoNeedWaitImage bflag:{$}", bflag); auto szFDinfo = std::to_string(bflag); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::NoNeedWaitImage, szFDinfo); } RET_STATUS nsFPD::AcqUnit::JSGetLastImage(std::string & out) { out = m_strLastImage; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::AddFrameWithRawHead(IMAGE_VIEW_TYPE eType, string ImageHead, unsigned short* pFrameBuff, DWORD FrameSize) { //FrameHeader ResDataObject json; if (IMAGE_FULL == eType) { json.add("ImageType", 0);//IMAGE_TYPE_2D: 0; IMAGE_TYPE_3D: 1 json.add("Viewtype", (int)eType); json.add("Sharememid", "0"); json.add("Imageid", "0"); json.add("Width", m_nFullWidth); json.add("Height", m_nFullHeight); json.add("Bit", m_nBits); } if (IMAGE_PREVIEW == eType || IMAGE_AEC_PREVIEW == eType) { json.add("ImageType", 0);//IMAGE_TYPE_2D: 0; IMAGE_TYPE_3D: 1 json.add("Viewtype", (int)eType); json.add("Sharememid", "0"); json.add("Imageid", "0"); json.add("Width", m_nPrevWidth); json.add("Height", m_nPrevHeight); json.add("Bit", m_nBits); } m_strLastImage = json.encode(); m_EventCenter->OnDataNotify((int)eType, AttrKey::ImgDataInfo, m_strLastImage, ImageHead, (char *)pFrameBuff, FrameSize * 2); FINFO("AddFrameWithRawHead FrameHeader:{$}", m_strLastImage.c_str()); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::AddFrameWithRawHead(IMAGE_VIEW_TYPE Type, string ImageHead, DWORD FrameSize) { m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::ImgDataInfo, ImageHead); return RET_STATUS::RET_SUCCEED; } DWORD nsFPD::AcqUnit::AddFrame(IMAGE_VIEW_TYPE Type, string ImageHead, unsigned short* pFrameBuff, DWORD FrameSize) { return 0; } /********************************************************************/ // //图像沿X轴做翻转, //pData:[IN][OUT] 图像数据 //nWidth[IN] nHeight[IN] /********************************************************************/ bool nsFPD::AcqUnit::FlipX(unsigned short* pData, unsigned int nWidth, unsigned int nHeight) { unsigned int j = 0; unsigned int i = 0; unsigned short temp; //修改翻转的判断,之前的代码会导致中央区域多翻转一个像素 for (i = 0; i < nWidth; i++) { for (j = 0; j < nHeight / 2; j++) { int nSrc = j * nWidth + i; int nDes = (nHeight - j - 1) * nWidth + i; temp = pData[nSrc]; pData[nSrc] = pData[nDes]; pData[nDes] = temp; } } return true; } /********************************************************************/ // //图像沿Y轴做翻转, //pData:[IN][OUT] 图像数据 //nWidth[IN] nHeight[IN] /********************************************************************/ bool nsFPD::AcqUnit::FlipY(unsigned short* pData, unsigned int nWidth, unsigned int nHeight) { unsigned int j = 0; unsigned int i = 0; unsigned short temp; //修改翻转的判断,之前的代码会导致中央区域多翻转一个像素 for (i = 0; i < nHeight; i++) { for (j = 0; j < nWidth / 2; j++) { temp = pData[i * nWidth + j]; pData[i * nWidth + j] = pData[(i + 1) * nWidth - j - 1]; pData[(i + 1) * nWidth - j - 1] = temp; } } return true; } /*** ** 说明:旋转图像 ** 参数:nAngle,顺时针旋转角度,0 90 180 270 ** addbyys20200810 ***/ bool nsFPD::AcqUnit::RotateImage(unsigned short* imageBuffer, int nImageHeight, int nImageWidth, int nAngle) { bool ret = true; if (NULL == imageBuffer || 0 == nImageHeight || 0 == nImageWidth) { return false; } int nTemp = 0; int i = 0, j = 0;//for loop unsigned short* ptempData; ptempData = new unsigned short[nImageHeight * nImageWidth]; switch (nAngle) { case 90: //顺时针旋转90° //TPRINTA_INFO("Rotate 90 degrees clockwise"); nTemp = nImageHeight; nImageHeight = nImageWidth; nImageWidth = nTemp; try { memcpy(ptempData, imageBuffer, nImageHeight * nImageWidth * sizeof(unsigned short)); for (i = 0; i < nImageHeight; i++) { for (j = 0; j < nImageWidth; j++) { imageBuffer[i * nImageWidth + j] = ptempData[(nImageWidth - 1 - j) * nImageHeight + i]; } } } catch (...) { //TPRINTA_INFO("Rotate image crashed"); ret = false; } break; case 180: //顺时针旋转180° //TPRINTA_INFO("Rotate 180 degrees clockwise"); try { memcpy(ptempData, imageBuffer, nImageHeight * nImageWidth * sizeof(unsigned short)); for (i = 0; i < nImageWidth * nImageHeight; i++) { imageBuffer[i] = ptempData[nImageWidth * nImageHeight - 1 - i]; } } catch (...) { //TPRINTA_INFO("Rotate image crashed"); ret = false; } break; case 270: //顺时针旋转270° //TPRINTA_INFO("Rotate 270 degrees clockwise"); nTemp = nImageHeight; nImageHeight = nImageWidth; nImageWidth = nTemp; try { memcpy(ptempData, imageBuffer, nImageWidth * nImageHeight * sizeof(unsigned short)); for (i = 0; i < nImageHeight; i++) { for (j = 0; j < nImageWidth; j++) { imageBuffer[i * nImageWidth + j] = ptempData[j * nImageHeight + (nImageHeight - 1 - i)]; } } } catch (...) { //TPRINTA_INFO("Rotate image crashed"); ret = false; } break; default: ret = false; break; } delete[] ptempData; ptempData = NULL; return ret; } RET_STATUS nsFPD::AcqUnit::SetGainMode(float nGain) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::SetBinningMode(int nBinningX, int nBinningY) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::SetZoomMode(int nZOOMX1, int nZOOMY1, int nZOOMX2, int nZOOMY2) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::JSAutonumousMapFinish(std::string& out) { out = m_strAutonumousMapFinish; return RET_STATUS::RET_SUCCEED; } void nsFPD::AcqUnit::SendAutonumousMapFinish(int nFlag) { string szFPDinfo = ""; szFPDinfo = to_string(nFlag); m_strAutonumousMapFinish = szFPDinfo; m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::AutonumousMapFinish, szFPDinfo); FINFO("SendAutonumousMapFinish({$})", szFPDinfo); return; } RET_STATUS nsFPD::AcqUnit::JSSetFluPPS(std::string in, std::string& out) { FINFO("JSSetFluPPS. {$}", in.c_str()); ResDataObject json; json.decode(in.c_str()); m_strFluPPS = (string)json[0]; float fluPPS = stof(m_strFluPPS.c_str()); return SetFluPPS(fluPPS); } RET_STATUS nsFPD::AcqUnit::JSGetFluPPS(std::string& out) { float pps = 0.0f; GetFluPPS(pps); out = std::to_string(pps); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::JSGetMaxFrameRate(std::string& out) { out = m_strMaxFrameRate; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::SetFluPPS(float fFluPPS) { return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::AcqUnit::GetFluPPS(float& fFluPPS) { return RET_STATUS::RET_SUCCEED; } void nsFPD::AcqUnit::FluPPSNotify(float nCurrentFps) { FINFO("FluPPSNotify current fps: {$}", nCurrentFps); string strFps = std::to_string(nCurrentFps); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::FluPPS, strFps); } void nsFPD::AcqUnit::SetMaxFrameRate(float fMaxFrameRate) { string strMaxFrameRate = std::to_string(fMaxFrameRate); m_strMaxFrameRate = strMaxFrameRate; } void nsFPD::AcqUnit::AcqModeNotify(string strAcqMode) { FINFO("AcqModeNotify strAcqMode: {$}", strAcqMode); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::AcqMode, strAcqMode); } void nsFPD::AcqUnit::ImagerPixelSpacingNotify(int nPixelSpacing) { FINFO("ImagerPixelSpacingNotify nPixelSpacing: {$}", nPixelSpacing); //这里要把DICOM字段的值通知到ImageSave float fTemp = nPixelSpacing / 1000.0f; char temp[20] = { 0 }; snprintf(temp, sizeof(temp), "%.3f\\%.3f", fTemp, fTemp); string strImagePixelSpacing = temp; FINFO("strImagePixelSpacing:{$}", strImagePixelSpacing); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::ImagerPixelSpacing, strImagePixelSpacing); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::DetectorElementSpacing, strImagePixelSpacing); } void nsFPD::AcqUnit::SidNotify(float fSid) { FINFO("SidNotify fSid: {$}", fSid); string strSid = to_string(fSid); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::DistanceSourcetoDetector, strSid); } void nsFPD::AcqUnit::SodNotify(float fSod) { FINFO("SodNotify fSod: {$}", fSod); string strSod = to_string(fSod); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::DistanceSourcetoPatient, strSod); } void nsFPD::AcqUnit::ErmfNotify(float fErmf) { FINFO("ErmfNotify fErmf: {$}", fErmf); string strErmf = to_string(fErmf); m_EventCenter->OnNotify((int)ATTRACTION_SET, AttrKey::EstimatedRadiographicMagnificationFactor, strErmf); } RET_STATUS nsFPD::AcqUnit::JSUpdateModeInRunning(std::string in, std::string& out) { FINFO("JSUpdateModeInRunning in:{$}", in); ResDataObject json; json.decode(in.c_str()); std::vector vAcqModeList; for (size_t i = 0; i < json.size(); i++) { AcqModeInfo temp; temp.nModeID = (int)json[i]["ModeID"]; temp.fFrequency = (float)json[i]["Frequency"]; vAcqModeList.push_back(temp); } return UpdateModeInRunning(vAcqModeList); } RET_STATUS nsFPD::AcqUnit::UpdateModeInRunning(std::vector& vAcqModeList) { return RET_STATUS::RET_SUCCEED; }