Files
UR/src/startReconstructions.cpp

215 lines
8.9 KiB
C++
Raw Normal View History

2023-06-02 15:34:22 +08:00
#include "startReconstructions.h"
#include "Data/TemperatureData.h"
#include "Function.h"
#include "config/config.h"
#include "common/getMeasurementMetaData.h"
#include "common/getGeometryInfo.h"
#include "common/estimatePulseLength.h"
#include "transmissionReconstruction/startTransmissionReconstruction.h"
#include <string>
#include <iostream>
#include "Parser/Parser.h"
#include "Parser/Data/MetaData.h"
#include "Matrix.h"
#include "Function1D.h"
#include "Function2D.h"
#include "src/common/ceMatchedFilterHandling.h"
#include "src/reflectionReconstruction/preprocessData/estimateOffset.h"
using namespace Recon;
using namespace Aurora;
void Recon::startReconstructions()
{
// std::string dataPath = "/home/AScans_Data/volunteer_20230328/20230328T123237/";
// std::string refPath = "/home/AScans_Data/volunteer_20230328/20230328T123237/";
std::string dataPath = "/home/AScans_Data/ADW_TAS_Issue/20230512T135108/";
std::string refPath = "/home/AScans_Data/ADW_TAS_Issue/20230512T141626/";
std::string outputPath;
Parser dataParser(dataPath);
Parser refParser(refPath);
std::string rootMeasUniqueID = dataParser.getMetaData().getMeasurementID();
std::string rootRefUniqueID = refParser.getMetaData().getMeasurementID();
//init total used receiver/emitter/motorPos
Matrix motorPosTotal, slList, snList, rlList, rnList;
if(transParams::runTransmissionReco && reflectParams::runReflectionReco)
{
motorPosTotal = auroraUnion(reflectParams::motorPos, transParams::motorPos);
slList = auroraUnion(reflectParams::senderTasList, transParams::senderTasList);
snList = auroraUnion(reflectParams::senderElementList, transParams::senderElementList);
rlList = auroraUnion(reflectParams::receiverTasList, transParams::receiverTasList);
rnList = auroraUnion(reflectParams::receiverElementList, transParams::receiverElementList);
}
else if(reflectParams::runReflectionReco)
{
motorPosTotal = reflectParams::motorPos;
slList = reflectParams::senderTasList;
snList = reflectParams::senderElementList;
rlList = reflectParams::receiverTasList;
rnList = reflectParams::receiverElementList;
}
else if(transParams::runTransmissionReco)
{
motorPosTotal = transParams::motorPos;
slList = transParams::senderTasList;
snList = transParams::senderElementList;
rlList = transParams::receiverTasList;
rnList = transParams::receiverElementList;
}
else
{
return;
}
//getMeasurementMetaData
double maxNumTAS = max(auroraUnion(slList, rlList)).getData()[0];
MeasurementInfo expInfo = loadMeasurementInfos(&dataParser);
TempInfo temp = getTemperatureInfo(&dataParser, maxNumTAS);
CEInfo ce = getCEInfo(&dataParser, expInfo);
TransFormInfo transformationInfo = getTransformationMatrix(&dataParser, motorPosTotal);
Matrix transformationMatrices = transformationInfo.rotationMatrix;
Matrix motorPosAvailable = transformationInfo.motorPos;
Matrix motorPosAvailableRef;
MeasurementInfo expInfoRef;
TempInfo tempRef;
CEInfo ceRef;
Matrix transformationMatricesRef;
if(transParams::runTransmissionReco)
{
expInfoRef = loadMeasurementInfos(&refParser);
tempRef = getTemperatureInfo(&refParser, maxNumTAS);
ceRef = getCEInfo(&refParser, expInfoRef);
transformationInfo = getTransformationMatrix(&refParser, motorPosTotal);
transformationMatricesRef = transformationInfo.rotationMatrix;
motorPosAvailableRef = transformationInfo.motorPos;
if(transformationMatricesRef.isNull())
{
Matrix motorPos1 = Matrix::fromRawData(new double[1] {1}, 1);
transformationMatricesRef = getTransformationMatrix(&refParser, motorPos1).rotationMatrix;
}
else
{
Matrix mpRef_inter = intersect(motorPosAvailableRef, transParams::motorPos);
//extractMatchingReferenceMotorPosition
for(int i=0; i<motorPosAvailable.getDimSize(0); ++i)
{
if (sum(mpRef_inter == motorPosAvailable.getData()[i],FunctionDirection::All).getData()[0] == 0)
{
motorPosAvailableRef.getData()[i] = max(mpRef_inter).getData()[0];
int a = 0;
}
}
}
}
else
{
transformationMatricesRef = Matrix();
motorPosAvailableRef = Matrix();
}
Matrix isEqual = (ce.ceRef == ceRef.ceRef);
if (sum(isEqual, FunctionDirection::All).getData()[0] == isEqual.getDataSize())
{
std::cout<<"CEs are not equal"<<std::endl;
}
if(!ce.ce.isNull() && !ceRef.ce.isNull())
{
isEqual = (ce.ce == ceRef.ce);
if (sum(isEqual, FunctionDirection::All).getData()[0] == isEqual.getDataSize())
{
std::cout<<"CEs are not equal."<<std::endl;
}
}
else
{
std::cout<<"CEs is null matrix."<<std::endl;
}
GeometryInfo geom = getGeometryInfo(motorPosAvailable, transformationMatrices, rlList, rnList, slList, snList);
PreComputes preComputes;
if((reflectParams::matchedFilterCeAScan && reflectParams::runReflectionReco) || transParams::runTransmissionReco)
{
if(ce.measuredCEUsed)
{
preComputes.matchedFilter = createMatchedFilter(ce.ce, ce.measuredCEUsed, reflectParams::findDefects, reconParams::removeOutliersFromCEMeasured, expInfo.Hardware);
}
else
{
preComputes.matchedFilter = createMatchedFilter(ce.ceRef, ce.measuredCEUsed, reflectParams::findDefects, reconParams::removeOutliersFromCEMeasured, expInfo.Hardware);
}
}
if(expInfo.sampleRate != reflectParams::aScanReconstructionFrequency)
{
reflectParams::expectedAScanDataLength = ceil(expInfo.numberSamples * ((double)reflectParams::aScanReconstructionFrequency / expInfo.sampleRate));
}
if(transParams::runTransmissionReco)
{
if(ceRef.measuredCEUsed)
{
preComputes.matchedFilterRef = createMatchedFilter(ceRef.ce, ceRef.measuredCEUsed, reflectParams::findDefects, reconParams::removeOutliersFromCEMeasured, expInfo.Hardware);
}
else
{
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;
preComputes.measuredCE_receiverIndices = ce.receiverIndices;
preComputes.offset = estimateOffset(expInfo, ce, preComputes.matchedFilter);
expInfo.matchedFilter = preComputes.matchedFilter;
expInfoRef.matchedFilter = preComputes.matchedFilterRef;
CeEstimatePulseLength ceEstimatePulseLength;
CeEstimatePulseLength ceEstimatePulseLengthRef;
if(ce.measuredCEUsed)
{
ceEstimatePulseLength.ce = mean(ce.ce, FunctionDirection::Row);
ceEstimatePulseLengthRef.ce = mean(ce.ce, FunctionDirection::Row);
ceEstimatePulseLength.ce_sf = reflectParams::aScanReconstructionFrequency;
ceEstimatePulseLengthRef.ce_sf = reflectParams::aScanReconstructionFrequency;
}
else
{
ceEstimatePulseLength.ce = ce.ceRef;
ceEstimatePulseLengthRef.ce = ceRef.ceRef;
ceEstimatePulseLength.ce_sf = reflectParams::aScanReconstructionFrequency;
ceEstimatePulseLengthRef.ce_sf = reflectParams::aScanReconstructionFrequency;
}
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());
for(int i=0; i<iMp.getDataSize(); ++i)
{
mpRef_interData[i] = motorPosAvailableRef[iMp[i] - 1];
}
Matrix mpRef_inter = Matrix::New(mpRef_interData, iMp.getDataSize());
Matrix slList_inter = intersect(slList, transParams::senderTasList);
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);
startTransmissionReconstruction(mp_inter, mpRef_inter, slList_inter, snList_inter, rlList_inter, rnList_inter, temp, tempRef, geom, geomRef, expInfo, expInfoRef, preComputes, &dataParser, &refParser);
}