From b2721db9589f365c73123c9c99ef27f02c44429a Mon Sep 17 00:00:00 2001 From: kradchen Date: Tue, 12 Sep 2023 09:53:30 +0800 Subject: [PATCH] Add progress notify --- src/common/DICOMExporter.cpp | 30 +++++++++++++--- src/common/DICOMExporter.h | 2 ++ src/log/log.cpp | 9 +++-- src/log/log.h | 7 +++- src/log/notify.cpp | 36 +++++++++++++++++++ src/log/notify.h | 9 +++++ .../startReflectionReconstruction.cpp | 3 ++ src/startReconstructions.cpp | 30 +++++++++------- src/startReconstructions.h | 2 +- .../detection/getTransmissionData.cpp | 2 ++ .../reconstruction/reconstruction.cpp | 2 ++ .../startTransmissionReconstruction.cpp | 11 ++++-- 12 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 src/log/notify.cpp create mode 100644 src/log/notify.h diff --git a/src/common/DICOMExporter.cpp b/src/common/DICOMExporter.cpp index 73f8917..ff02116 100644 --- a/src/common/DICOMExporter.cpp +++ b/src/common/DICOMExporter.cpp @@ -96,6 +96,21 @@ namespace Recon mStudyDate = date.data(); mStudyTime = time.data(); } + + DICOMExporter::DICOMExporter() + { + //prepare Study + dcmGenerateUniqueIdentifier(mStudyInstanceUID,SITE_STUDY_UID_ROOT); + + OFDateTime currentDateTime; + currentDateTime.setCurrentDateTime(); + OFString date; + currentDateTime.getDate().getISOFormattedDate(date,false); + OFString time; + currentDateTime.getTime().getISOFormattedTime(time,true,false,false,false); + mStudyDate = date.data(); + mStudyTime = time.data(); + } DICOMExporter::~DICOMExporter() { @@ -138,13 +153,18 @@ namespace Recon ::initialSeriesTime(dataset); - dataset->putAndInsertString(DCM_InstitutionName, mPatientData.getInstituationName().data()); - dataset->putAndInsertString(DCM_InstitutionAddress, mPatientData.getInstituationAddress().data()); - dataset->putAndInsertString(DCM_ReferringPhysicianName, mPatientData.getOperatorName().data()); - dataset->putAndInsertString(DCM_PatientName, mPatientData.getPatientName().data()); + dataset->putAndInsertString(DCM_InstitutionName, mPatientData.getInstituationName().empty()? + "InstName":mPatientData.getInstituationName().data()); + dataset->putAndInsertString(DCM_InstitutionAddress, mPatientData.getInstituationAddress().empty()? + "default addr":mPatientData.getInstituationAddress().data()); + dataset->putAndInsertString(DCM_ReferringPhysicianName,mPatientData.getOperatorName().empty()? + "ReferringPhysician": mPatientData.getOperatorName().data()); + dataset->putAndInsertString(DCM_PatientName, mPatientData.getPatientName().empty()? + "TestPatient":mPatientData.getPatientName().data()); dataset->putAndInsertString(DCM_PatientSex, mPatientData.getPatientSex().data()); dataset->putAndInsertString(DCM_PatientBirthDate, mPatientData.getPatientBirthDate().data()); - dataset->putAndInsertString(DCM_PatientID, mPatientData.getPatientID().data()); + dataset->putAndInsertString(DCM_PatientID, mPatientData.getPatientID().empty()? + "TestPatID":mPatientData.getPatientID().data()); dataset->putAndInsertString(DCM_Laterality, mPatientData.getLaterality().data()); dataset->putAndInsertString(DCM_StudyID, "0"); diff --git a/src/common/DICOMExporter.h b/src/common/DICOMExporter.h index 82e1314..a8876dc 100644 --- a/src/common/DICOMExporter.h +++ b/src/common/DICOMExporter.h @@ -16,6 +16,8 @@ public: ATT }; explicit DICOMExporter(const PatientData& aPatientData); + //仅仅用于测试!!! + DICOMExporter(); DICOMExporter(DICOMExporter &&) = default; DICOMExporter(const DICOMExporter &) = default; DICOMExporter &operator=(DICOMExporter &&) = default; diff --git a/src/log/log.cpp b/src/log/log.cpp index 2a690a0..dbb94f6 100644 --- a/src/log/log.cpp +++ b/src/log/log.cpp @@ -2,14 +2,17 @@ #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/basic_file_sink.h" -#include "spdlog/spdlog.h" -std::shared_ptr getLogger(const char* title) +std::shared_ptr getLogger(const char* title,const char * output) { auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::info); console_sink->set_pattern(fmt::format("[%Y-%m-%d %T .%f][{}] [%^%l%$] %v", title)); - std::shared_ptr logger(new spdlog::logger(title, {console_sink})); + + auto file_sink = std::make_shared(fmt::format("{0}/log.log", output)); + file_sink->set_level(spdlog::level::info); + file_sink->set_pattern(fmt::format("[%Y-%m-%d %T .%f][{}] [%^%l%$] %v", title)); + std::shared_ptr logger(new spdlog::logger(title, {console_sink,file_sink})); logger->set_level(spdlog::level::info); logger->flush_on(spdlog::level::info); return logger; diff --git a/src/log/log.h b/src/log/log.h index e3be8eb..cc66233 100644 --- a/src/log/log.h +++ b/src/log/log.h @@ -1,6 +1,9 @@ +#ifndef __LOG_H__ +#define __LOG_H__ + #include "spdlog/spdlog.h" -std::shared_ptr getLogger(const char* title); +std::shared_ptr getLogger(const char* title,const char * output); #define RECON_TRACE(...) SPDLOG_TRACE( __VA_ARGS__) @@ -9,3 +12,5 @@ std::shared_ptr getLogger(const char* title); #define RECON_INFO(...) SPDLOG_INFO(__VA_ARGS__) #define RECON_ERROR(...) SPDLOG_ERROR( __VA_ARGS__) + +#endif // __LOG_H__ \ No newline at end of file diff --git a/src/log/notify.cpp b/src/log/notify.cpp new file mode 100644 index 0000000..62a5029 --- /dev/null +++ b/src/log/notify.cpp @@ -0,0 +1,36 @@ +#include "notify.h" +#include "Request.h" +#include "log/log.h" +namespace Recon { +std::string ReconID; +Req::Request req; +bool notifyStart(const std::string& aReconID ){ + ReconID = aReconID; + Req::Request::Init(); + req.setClientCertificate("/home/krad/workdir/ReconTester/client.crt","/home/krad/workdir/ReconTester/client.key"); + std::string str = "{\"ReconID\": \""+ReconID+"\"}"; + std::unordered_map headers; + headers["Content-Type"] = "application/json"; + auto resp = req.post("https://127.0.0.1:5002/Task/Start/",str,headers); + return resp->httpCode() == 200; +} + +bool notifyFinish(){ + std::string str = "{\"ReconID\": \""+ReconID+"\"}"; + std::unordered_map headers; + headers["Content-Type"] = "application/json"; + auto resp = req.post("https://127.0.0.1:5002/Task/Finish/",str,headers); + Req::Request::Dispose(); + return resp->httpCode() == 200; +} + +bool notifyProgress( int percent){ + char buffer[2048] = {0}; + sprintf(buffer, "https://192.168.1.15:5003/Task/Notify/%d/", percent); + std::string str = "{\"ReconID\": \""+ReconID+"\"}"; + std::unordered_map headers; + headers["Content-Type"] = "application/json"; + auto resp = req.post(buffer,str,headers); + return resp->httpCode() == 200; +} +} \ No newline at end of file diff --git a/src/log/notify.h b/src/log/notify.h new file mode 100644 index 0000000..e890d9b --- /dev/null +++ b/src/log/notify.h @@ -0,0 +1,9 @@ +#ifndef __NOTIFY_H__ +#define __NOTIFY_H__ +#include +namespace Recon { + bool notifyStart(const std::string& aReconID ); + bool notifyFinish(); + bool notifyProgress(int percent); +} +#endif // __NOTIFY_H__ \ No newline at end of file diff --git a/src/reflectionReconstruction/startReflectionReconstruction.cpp b/src/reflectionReconstruction/startReflectionReconstruction.cpp index 067280e..d0e897d 100644 --- a/src/reflectionReconstruction/startReflectionReconstruction.cpp +++ b/src/reflectionReconstruction/startReflectionReconstruction.cpp @@ -9,6 +9,7 @@ #include "common/precalculateChannelList.h" #include "common/dataBlockCreation/getAScanBlockPreprocessed.h" #include "common/dataBlockCreation/removeDataFromArrays.h" +#include "log/notify.h" #include "reflectionReconstruction/preprocessData/determineOptimalPulse.h" #include "reflectionReconstruction/reconstructionSAFT/reconstructionSAFT.h" #include "src/reflectionReconstruction/preprocessData/preprocessAScanBlockForReflection.h" @@ -90,6 +91,8 @@ Aurora::Matrix Recon::startReflectionReconstruction( Parser* aParser, int aSAFT_ aSAFT_mode, aTransRecos, Env); RECON_INFO("Reflection Reconstructon: " + std::to_string(j)); } + Recon::notifyProgress(25+73*((j*i)/(aMotorPos.getDataSize() * aSlList.getDataSize()))); + } } diff --git a/src/startReconstructions.cpp b/src/startReconstructions.cpp index 1325cbf..a73b255 100644 --- a/src/startReconstructions.cpp +++ b/src/startReconstructions.cpp @@ -8,6 +8,7 @@ #include "common/getMeasurementMetaData.h" #include "common/getGeometryInfo.h" #include "common/estimatePulseLength.h" +#include "log/notify.h" #include "transmissionReconstruction/startTransmissionReconstruction.h" #include @@ -30,7 +31,7 @@ using namespace Recon; using namespace Aurora; -void Recon::startReconstructions(const std::string& aDataPath, const std::string& aDataRefPath, const std::string& aOutputPath) +int Recon::startReconstructions(const std::string& aDataPath, const std::string& aDataRefPath, const std::string& aOutputPath) { MatlabWriter writer(aOutputPath); Parser dataParser(aDataPath); @@ -39,14 +40,16 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string exporter.setExportBasePath(aOutputPath); if(!dataParser.getShotList()->isValid()) { + RECON_INFO("startReconstructions with {0}.",aDataPath); + RECON_INFO("data path is invalid."); - return; + return -9; } if(!refParser.getShotList()->isValid()) { RECON_INFO("empty water path is invalid."); - return; + return -10; } //init total used receiver/emitter/motorPos Matrix motorPosTotal, slList, snList, rlList, rnList; @@ -76,7 +79,7 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string } else { - return; + return -12; } //getMeasurementMetaData @@ -93,6 +96,7 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string TempInfo tempRef; CEInfo ceRef; Matrix transformationMatricesRef; + Recon::notifyProgress(1); if(transParams::runTransmissionReco) { expInfoRef = loadMeasurementInfos(&refParser); @@ -125,7 +129,7 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string transformationMatricesRef = Matrix(); motorPosAvailableRef = Matrix(); } - + Recon::notifyProgress(2); if(!ce.ce.isNull() && !ceRef.ce.isNull()) { Matrix isEqual = (ce.ce == ceRef.ce); @@ -152,12 +156,12 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string preComputes.matchedFilter = createMatchedFilter(ce.ceRef, ce.measuredCEUsed, reflectParams::findDefects, reconParams::removeOutliersFromCEMeasured, expInfo.Hardware); } } - + Recon::notifyProgress(3); if(expInfo.sampleRate != reflectParams::aScanReconstructionFrequency) { reflectParams::expectedAScanDataLength = ceil(expInfo.numberSamples * ((double)reflectParams::aScanReconstructionFrequency / expInfo.sampleRate)); } - + Recon::notifyProgress(4); TransmissionReconstructionResult transmissionResult; bool sosAvailable = false; bool attAvailable = false; @@ -171,7 +175,6 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string { preComputes.matchedFilterRef = createMatchedFilter(ceRef.ceRef, ceRef.measuredCEUsed, reflectParams::findDefects, reconParams::removeOutliersFromCEMeasured, expInfo.Hardware); } - preComputes.timeInterval = (double)1 / reflectParams::aScanReconstructionFrequency; preComputes.measuredCEUsed = ce.measuredCEUsed; preComputes.measuredCE_TASIndices = ce.tasIndices; @@ -200,7 +203,6 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string transParams::pulseLengthSamples = estimatePulseLength(ceEstimatePulseLength, reflectParams::aScanReconstructionFrequency); transParams::pulseLengthRefSamples = estimatePulseLength(ceEstimatePulseLengthRef, reflectParams::aScanReconstructionFrequency); - Matrix iMp; Matrix mp_inter = intersect(motorPosAvailable, transParams::motorPos, iMp); double* mpRef_interData = Aurora::malloc(iMp.getDataSize()); @@ -213,12 +215,12 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string Matrix snList_inter = intersect(snList, transParams::senderElementList); Matrix rlList_inter = intersect(rlList, transParams::receiverTasList); Matrix rnList_inter = intersect(rnList, transParams::receiverElementList); - transParams::aScanReconstructionFrequency = reflectParams::aScanReconstructionFrequency; transParams::gpuSelectionList = reconParams::gpuSelectionList; GeometryInfo geomRef = getGeometryInfo(motorPosAvailableRef, transformationMatricesRef, rlList, rnList, slList, snList); RECON_INFO("Start transmissionRecostruction."); + Recon::notifyProgress(5); transmissionResult = startTransmissionReconstruction(mp_inter, mpRef_inter, slList_inter, snList_inter, rlList_inter, rnList_inter, temp, tempRef, geom, geomRef, expInfo, expInfoRef, preComputes, &dataParser, &refParser); attAvailable = true; sosAvailable = true; @@ -232,10 +234,12 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string { Matrix recoSOS = transmissionResult.recoSOS; Matrix recoATT = transmissionResult.recoATT; - precalcImageParameters(geom); + precalcImageParameters(geom); + Recon::notifyProgress(21); //检测可使用内存是否足够,输出警报用,todo //checkEnvAndMemory(reflectParams.imageInfos.IMAGE_XYZ); auto preProcessData = preprocessTransmissionReconstructionForReflection(recoSOS, recoATT, transmissionResult.ddmis, geom, temp); + Recon::notifyProgress(22); Matrix mp_inter = intersect(motorPosAvailable, reflectParams::motorPos); Matrix slList_inter = intersect(slList, reflectParams::senderTasList); Matrix snList_inter = intersect(snList, reflectParams::senderElementList); @@ -248,11 +252,13 @@ void Recon::startReconstructions(const std::string& aDataPath, const std::string preComputes.offset = estimateOffset(expInfo, ce, preComputes.matchedFilter); reflectParams::gpuSelectionList = reconParams::gpuSelectionList; + Recon::notifyProgress(25); RECON_INFO("Start reflectionRecostruction."); Matrix env = startReflectionReconstruction(&dataParser, preProcessData.saftMode, mp_inter, slList_inter, snList_inter, rlList_inter, rnList_inter, geom, preProcessData.transRecos, expInfo, preComputes); // writer.setMatrix(env, "reflect"); exporter.exportDICOM(env, Recon::DICOMExporter::REFL); + Recon::notifyProgress(99); } - + return 0; // writer.write(); } \ No newline at end of file diff --git a/src/startReconstructions.h b/src/startReconstructions.h index 017958c..ff92aa9 100644 --- a/src/startReconstructions.h +++ b/src/startReconstructions.h @@ -4,7 +4,7 @@ #include namespace Recon { - void startReconstructions(const std::string& aDataPath, const std::string& aDataRefPath, const std::string& aOutputPath); + int startReconstructions(const std::string& aDataPath, const std::string& aDataRefPath, const std::string& aOutputPath); } #endif \ No newline at end of file diff --git a/src/transmissionReconstruction/detection/getTransmissionData.cpp b/src/transmissionReconstruction/detection/getTransmissionData.cpp index a0838cf..2d606fe 100644 --- a/src/transmissionReconstruction/detection/getTransmissionData.cpp +++ b/src/transmissionReconstruction/detection/getTransmissionData.cpp @@ -3,6 +3,7 @@ #include "Function1D.h" #include "Function2D.h" #include "common/dataBlockCreation/removeDataFromArrays.h" +#include "log/notify.h" #include "src//config/config.h" #include "src/common/getGeometryInfo.h" #include "src/common/temperatureCalculation/extractTasTemperature.h" @@ -370,6 +371,7 @@ TransmissionData Recon::getTransmissionData(const Aurora::Matrix& aMotorPos, con std::cout<<"Remove: "<