Add usage of command line.

This commit is contained in:
sunwen
2023-06-28 16:48:28 +08:00
parent b728b9e204
commit fad9168527
8 changed files with 130 additions and 36 deletions

41
src/common/fileHelper.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "fileHelper.h"
#include <sys/stat.h>
std::string Recon::getPath(const std::string &aFullPath)
{
size_t pos = aFullPath.find_last_of('/');
if (pos != std::string::npos)
{
return aFullPath.substr(0, pos);
}
return "";
}
bool Recon::endsWithMat(const std::string &aStr)
{
if (aStr.length() >= 4)
{
return (aStr.compare(aStr.length() - 4, 4, ".mat") == 0);
}
return false;
}
bool Recon::isDirectory(const std::string &aPath)
{
struct stat info;
if (stat(aPath.c_str(), &info) != 0)
{
return false;
}
return (info.st_mode & S_IFDIR) != 0;
}
std::string Recon::fixPathSlash(const std::string& aPath)
{
if(aPath.back() == '/')
{
return aPath;
}
return aPath + '/';
}

18
src/common/fileHelper.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef FILE_HELPER_H
#define FILE_HELPER_H
#include <string>
namespace Recon
{
const std::string DEFAULT_CONFIG_PATH = "/home/sun/UR/build/";
const std::string DEFAULT_OUTPUT_PATH = "/home/sun/USCT_Result.mat";
const std::string DEFAULT_OUTPUT_FILENAME = "USCT_Result.mat";
std::string getPath(const std::string &aFullPath);
bool endsWithMat(const std::string &aStr);
bool isDirectory(const std::string &aPath);
std::string fixPathSlash(const std::string& aPath);
}
#endif

View File

@@ -12,7 +12,6 @@ namespace Recon
const std::string ReconParamsFileName = "configReconstruction_USCT3Dv3.json";
const std::string ReflectParamsFileName = "configReflectionReconstruction_USCT3Dv3.json";
const std::string TransParramsFileName = "configTransmissionReconstruction_USCT3Dv3.json";
const std::string ConfigPath= "./";
Aurora::Matrix readToMatrix(const nlohmann::json& aJsonObj, bool aIsHorizontal = true)
{
@@ -37,14 +36,14 @@ namespace Recon
return Aurora::Matrix();
}
void initalizeConfigFromFiles()
void initalizeConfigFromFiles(const std::string aConfigPath)
{
nlohmann::json reconParamsJson;
nlohmann::json reflectParamsJson;
nlohmann::json transParamsJson;
std::ifstream reconParamsFile(ReconParamsFileName);
std::ifstream reflectParamsFile(ReflectParamsFileName);
std::ifstream transParamsFile(TransParramsFileName);
std::ifstream reconParamsFile(aConfigPath + ReconParamsFileName);
std::ifstream reflectParamsFile(aConfigPath + ReflectParamsFileName);
std::ifstream transParamsFile(aConfigPath + TransParramsFileName);
if(reconParamsFile.good())
{
reconParamsFile >> reconParamsJson;
@@ -111,7 +110,7 @@ namespace Recon
}
else
{
RECON_INFO(ReconParamsFileName + " not found.");
RECON_INFO(aConfigPath + ReconParamsFileName + " not found.");
}
if(reflectParamsFile.good())
@@ -360,7 +359,7 @@ namespace Recon
}
else
{
RECON_INFO(ReflectParamsFileName + " not found.");
RECON_INFO(aConfigPath + ReflectParamsFileName + " not found.");
}
if(transParamsFile.good())
@@ -611,14 +610,14 @@ namespace Recon
}
else
{
RECON_INFO(TransParramsFileName + " not found.");
RECON_INFO(aConfigPath + TransParramsFileName + " not found.");
}
reflectParams::expectedAScanDataLength = reconParams::expectedAScanDataLength;
reflectParams::gpuSelectionList = reconParams::gpuSelectionList;
transParams::gpuSelectionList = reconParams::gpuSelectionList;
}
void initalizeConfig()
void initalizeConfig(const std::string aConfigPath)
{
//reconParams.measurementInfo.ce
reconParams::useCEMeasured = true;
@@ -761,6 +760,6 @@ namespace Recon
transParams::runTransmissionReco = true;
transParams::nonNeg = false;
initalizeConfigFromFiles();
initalizeConfigFromFiles(aConfigPath);
}
}

View File

@@ -161,7 +161,7 @@ namespace Recon
EXTERN_C bool nonNeg;
}
void initalizeConfig();
void initalizeConfig(const std::string aConfigPath);
}
#endif //RECON_CONFIG_H

View File

@@ -1,24 +1,66 @@
#include "config/config.h"
#include <vector>
#define EIGEN_USE_MKL_ALL
#include <iostream>
#include <algorithm>
#include <complex>
#include "common/ceMatchedFilterHandling.h"
#include "MatlabReader.h"
#include "src/common/fileHelper.h"
#include "startReconstructions.h"
#include "log/log.h"
int main()
/* 0 is data path.
1 is dataRef path.
2 is output path.
3 is config file path.
*/
int main(int argc, char *argv[])
{
auto defaultLogger = getLogger("Main");
spdlog::set_default_logger(defaultLogger);
int argNum = 4;
std::vector<std::string> args(argNum);
args[0] = "";
args[1] = "";
args[2] = Recon::DEFAULT_OUTPUT_PATH;
args[3] = Recon::DEFAULT_CONFIG_PATH;
argc = argc <= argNum? argc-1 : argNum;
for (int i = 0; i < argc; i++)
{
args[i] = argv[i+1];
}
if(args[0].empty())
{
RECON_INFO("No reconstruction data.");
return 0;
}
std::string configPath = Recon::fixPathSlash(args[3]);
Recon::initalizeConfig(configPath);
if( args[1].empty() && Recon::transParams::runTransmissionReco)
{
RECON_INFO("Running transmission reconstruction, but no refrence data.");
return 0;
}
std::string outPutPath = args[2];
std::string directoryPath = outPutPath;
if(Recon::endsWithMat(outPutPath))
{
directoryPath = Recon::getPath(outPutPath);
}
else
{
outPutPath = Recon::fixPathSlash(outPutPath) + Recon::DEFAULT_OUTPUT_FILENAME;
}
if(!Recon::isDirectory(directoryPath))
{
RECON_INFO("Output directory is not valid.");
return 0;
}
std::string dataPath = Recon::fixPathSlash(args[0]);
std::string dataRefPath = Recon::fixPathSlash(args[1]);
RECON_INFO("start");
Recon::initalizeConfig();
Recon::startReconstructions();
Recon::startReconstructions(dataPath, dataRefPath, outPutPath);
SPDLOG_INFO("finish");
return 0;
}

View File

@@ -29,18 +29,11 @@
using namespace Recon;
using namespace Aurora;
void Recon::startReconstructions()
void Recon::startReconstructions(const std::string& aDataPath, const std::string& aDataRefPath, const std::string& aOutputPath)
{
std::string dataPath = "/home/AScans_Data/ADW_TAS_Issue/20230418T145123/";
std::string refPath = "/home/AScans_Data/ADW_TAS_Issue/20230418T141000/";
//std::string dataPath = "/home/AScans_Data/volunteer_20230620/20230620T120410/";
//std::string refPath = "/home/AScans_Data/volunteer_20230620/20230620T122424/";
//std::string dataPath = "/home/AScans_Data/10VolunteerStudyData/20221107/20221107T142539";
//std::string refPath = "/home/AScans_Data/10VolunteerStudyData/20221107/20221107T152522";
std::string outputPath = "/home/sun/20230627_20230418T145123_UR.mat";
MatlabWriter writer(outputPath);
Parser dataParser(dataPath);
Parser refParser(refPath);
MatlabWriter writer(aOutputPath);
Parser dataParser(aDataPath);
Parser refParser(aDataRefPath);
//init total used receiver/emitter/motorPos
Matrix motorPosTotal, slList, snList, rlList, rnList;
if(transParams::runTransmissionReco && reflectParams::runReflectionReco)

View File

@@ -1,9 +1,10 @@
#ifndef START_RECONSTRUCTIONS_H
#define START_RECONSTRUCTIONS_H
#include <string>
namespace Recon
{
void startReconstructions();
void startReconstructions(const std::string& aDataPath, const std::string& aDataRefPath, const std::string& aOutputPath);
}
#endif

View File

@@ -67,7 +67,7 @@ TEST_F(Reconstruction_Test, determineOptimalPulse) {
TEST_F(Reconstruction_Test, reconstructionSAFT) {
Recon::initalizeConfig();
Recon::initalizeConfig("");
MatlabReader m("/home/sun/testData/recontructSAFT.mat");
auto Ascans = m.read("AScans");
auto AttenuationMap3D = m.read("AttenuationMap3D");
@@ -107,7 +107,7 @@ TEST_F(Reconstruction_Test, reconstructionSAFT) {
}
TEST_F(Reconstruction_Test, preprocessAScanBlockForReflection) {
Recon::initalizeConfig();
Recon::initalizeConfig("");
MatlabReader m2("/home/krad/TestData/preprocessRefC.mat");
auto blockedAScans = m2.read("blockedAScans");
auto blockedMP = m2.read("blockedMP");