Add progress notify

This commit is contained in:
kradchen
2023-09-12 09:53:30 +08:00
parent 1e6dfaf212
commit b2721db958
12 changed files with 118 additions and 25 deletions

View File

@@ -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");

View File

@@ -16,6 +16,8 @@ public:
ATT
};
explicit DICOMExporter(const PatientData& aPatientData);
//仅仅用于测试!!!
DICOMExporter();
DICOMExporter(DICOMExporter &&) = default;
DICOMExporter(const DICOMExporter &) = default;
DICOMExporter &operator=(DICOMExporter &&) = default;

View File

@@ -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<spdlog::logger> getLogger(const char* title)
std::shared_ptr<spdlog::logger> getLogger(const char* title,const char * output)
{
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::info);
console_sink->set_pattern(fmt::format("[%Y-%m-%d %T .%f][{}] [%^%l%$] %v", title));
std::shared_ptr<spdlog::logger> logger(new spdlog::logger(title, {console_sink}));
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(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<spdlog::logger> logger(new spdlog::logger(title, {console_sink,file_sink}));
logger->set_level(spdlog::level::info);
logger->flush_on(spdlog::level::info);
return logger;

View File

@@ -1,6 +1,9 @@
#ifndef __LOG_H__
#define __LOG_H__
#include "spdlog/spdlog.h"
std::shared_ptr<spdlog::logger> getLogger(const char* title);
std::shared_ptr<spdlog::logger> getLogger(const char* title,const char * output);
#define RECON_TRACE(...) SPDLOG_TRACE( __VA_ARGS__)
@@ -9,3 +12,5 @@ std::shared_ptr<spdlog::logger> getLogger(const char* title);
#define RECON_INFO(...) SPDLOG_INFO(__VA_ARGS__)
#define RECON_ERROR(...) SPDLOG_ERROR( __VA_ARGS__)
#endif // __LOG_H__

36
src/log/notify.cpp Normal file
View File

@@ -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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> headers;
headers["Content-Type"] = "application/json";
auto resp = req.post(buffer,str,headers);
return resp->httpCode() == 200;
}
}

9
src/log/notify.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef __NOTIFY_H__
#define __NOTIFY_H__
#include <string>
namespace Recon {
bool notifyStart(const std::string& aReconID );
bool notifyFinish();
bool notifyProgress(int percent);
}
#endif // __NOTIFY_H__

View File

@@ -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())));
}
}

View File

@@ -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 <string>
@@ -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();
}

View File

@@ -4,7 +4,7 @@
#include <string>
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

View File

@@ -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: "<<index<<std::endl;
CREATE_BUFFER_CONDITION.notify_one();
}
Recon::notifyProgress(6+10*((i+1)*(j+1)/(aMotorPos.getDataSize()*(aSlList.getDataSize()/ transParams::senderTASSize))));
}
}
speedUpThread.join();

View File

@@ -7,6 +7,7 @@
#include "config/config.h"
#include "CudaEnvInit.h"
#include "log/notify.h"
#include "transmissionReconstruction/reconstruction/buildMatrix/buildMatrix.h"
#include "src/transmissionReconstruction/reconstruction/solvingEquationSystem/solve.h"
@@ -233,6 +234,7 @@ namespace Recon {
Matrix attValue = solveParameterIterator(buildMatrixR.M, bAtt, dims, false, transParams::nonNeg)[0][0];
result.outATT = attValue/100 ;
}
Recon::notifyProgress(10 + 10 * (iter/numIter));
}
return result;

View File

@@ -3,6 +3,7 @@
#include "Matrix.h"
#include "log/log.h"
#include "common/dataBlockCreation/removeDataFromArrays.h"
#include "log/notify.h"
#include "src/transmissionReconstruction/dataFilter/dataFilter.h"
#include "src/transmissionReconstruction/dataPreperation.h"
#include "src/common/getMeasurementMetaData.h"
@@ -25,21 +26,25 @@ TransmissionReconstructionResult Recon::startTransmissionReconstruction(const Au
{
RECON_INFO("Start getTransmissionData.");
auto transmissionData = getTransmissionData(aMotorPos, aMotoPosRef, aSlList, aSnList, aRlList, aRnList, aTemp, aTempRef,
aGeom, aGeomRef, aExpInfo, aExpInfoRef, aPreComputes, aParser, aParserRef);
aGeom, aGeomRef, aExpInfo, aExpInfoRef, aPreComputes, aParser, aParserRef);
Matrix dists = Recon::distanceBetweenTwoPoints(transmissionData.senderList, transmissionData.receiverList);
Matrix sosRef = Recon::temperatureToSoundSpeed(transmissionData.waterTempList, "marczak");
Recon::notifyProgress(17);
Matrix valid = Recon::checkTofDetections(transmissionData.tofDataTotal, dists, sosRef,
Recon::transParams::minSpeedOfSound,Recon::transParams::maxSpeedOfSound).valid;
Recon::notifyProgress(18);
if(transParams::qualityCheck)
{
qualityReview(sum(valid,Aurora::All)[0], transmissionData.dataInfo.numPossibleScans);
}
}
Recon::notifyProgress(19);
DiscretizePositionValues positionValues = Recon::discretizePositions(transmissionData.senderList, transmissionData.receiverList, Recon::transParams::numPixelXY);
Matrix tofData = removeDataFromArrays(transmissionData.tofDataTotal, valid);
Matrix attData = removeDataFromArrays(transmissionData.attDataTotal, valid);
Matrix senderList = removeDataFromArrays(positionValues.senderCoordList, valid);
Matrix reveiverList = removeDataFromArrays(positionValues.receiverCoordList, valid);
Recon::notifyProgress(20);
RECON_INFO("Start reconstructArt.");
auto transmissionReon = reconstructArt(tofData, attData, positionValues.dims, senderList, reveiverList, positionValues.res, aTemp.expectedSOSWater[0]);