2023-05-19 17:32:31 +08:00
# include "getTransmissionData.h"
2023-12-22 11:17:18 +08:00
# include "getTransmissionData.cuh"
# include "AuroraDefs.h"
# include "CudaMatrix.h"
2023-06-02 15:34:22 +08:00
# include "Function.h"
# include "Function1D.h"
# include "Function2D.h"
# include "common/dataBlockCreation/removeDataFromArrays.h"
2023-09-12 09:53:30 +08:00
# include "log/notify.h"
2023-06-02 15:34:22 +08:00
# include "src//config/config.h"
# include "src/common/getGeometryInfo.h"
2023-05-19 17:32:31 +08:00
# include "src/common/temperatureCalculation/extractTasTemperature.h"
2023-06-02 15:34:22 +08:00
# include "src/common/dataBlockCreation/getAScanBlockPreprocessed.h"
# include "src/common/precalculateChannelList.h"
2023-05-19 17:32:31 +08:00
# include "src/transmissionReconstruction/dataFilter/sensitivityCalculations.h"
2023-06-02 15:34:22 +08:00
# include "src/transmissionReconstruction/dataFilter/estimateNoiseValueFromAScans.h"
2023-05-19 17:32:31 +08:00
# include "Matrix.h"
2023-06-02 15:34:22 +08:00
# include "Function3D.h"
# include "transmissionReconstruction/dataFilter/dataFilter.h"
# include "transmissionReconstruction/dataPreperation.h"
# include "transmissionReconstruction/detection/detection.h"
2023-05-19 17:32:31 +08:00
# include <cstddef>
2023-06-02 15:34:22 +08:00
# include <mkl_cblas.h>
# include <iostream>
# include <mkl_vml_functions.h>
2023-07-03 17:12:53 +08:00
# include <map>
# include <string>
# include <thread>
# include <mutex>
# include <condition_variable>
2023-05-19 17:32:31 +08:00
2023-12-22 11:17:18 +08:00
# include <cuda_runtime.h>
# include "Function1D.cuh"
# include "Function2D.cuh"
# include <sys/time.h>
2023-05-19 17:32:31 +08:00
using namespace Recon ;
using namespace Aurora ;
2023-06-02 15:34:22 +08:00
namespace
{
struct BlockOfTransmissionData
{
Matrix tofData ;
Matrix attData ;
Matrix senderBlock ;
Matrix receiverBlock ;
Matrix waterTempBlock ;
MetaInfos metaInfos ;
2023-06-07 16:28:41 +08:00
2023-12-22 11:17:18 +08:00
CudaMatrix ascanBlock ;
CudaMatrix ascanBlockRef ;
2023-06-07 16:28:41 +08:00
Matrix dists ;
Matrix distRefBlock ;
Matrix waterTempRefBlock ;
2023-06-02 15:34:22 +08:00
} ;
2023-07-03 17:12:53 +08:00
std : : map < std : : string , BlockOfTransmissionData > BLOCK_OF_TRANSIMISSIONDARA_BUFFER ;
std : : mutex CREATE_BUFFER_MUTEX ;
std : : condition_variable CREATE_BUFFER_CONDITION ;
std : : mutex PROCESS_BUFFER_MUTEX ;
std : : condition_variable PROCESS_BUFFER_CONDITION ;
int BUFFER_COUNT = 0 ;
2023-12-22 11:17:18 +08:00
int BUFFER_SIZE = 4 ; //<=8
void printTime ( )
{
struct timeval tpend ;
gettimeofday ( & tpend , NULL ) ;
int secofday = ( tpend . tv_sec + 3600 * 8 ) % 86400 ;
int hours = secofday / 3600 ;
int minutes = ( secofday - hours * 3600 ) / 60 ;
int seconds = secofday % 60 ;
int milliseconds = tpend . tv_usec / 1000 ;
std : : cout < < hours < < " : " < < minutes < < " : " < < seconds < < " . " < < milliseconds < < std : : endl ;
}
2023-07-03 17:12:53 +08:00
2023-12-22 11:17:18 +08:00
CudaMatrix prepareAScansForTransmissionDetection ( const CudaMatrix & aAscanBlock , const CudaMatrix & aGainBlock )
2023-06-02 15:34:22 +08:00
{
2023-12-22 11:17:18 +08:00
CudaMatrix result = aAscanBlock / repmat ( aGainBlock , aAscanBlock . getDimSize ( 0 ) , 1 ) ;
2023-06-02 15:34:22 +08:00
result = result - repmat ( mean ( result , FunctionDirection : : Column ) , result . getDimSize ( 0 ) , 1 ) ;
return result ;
}
2023-12-22 11:17:18 +08:00
Aurora : : CudaMatrix calculateSnr ( const Aurora : : CudaMatrix & aMDataBlock ,
float aReferenceNoise ) {
auto maxSignal = max ( abs ( aMDataBlock ) ) ;
auto snrBlock = 10 * log ( maxSignal / aReferenceNoise , 10 ) ;
return snrBlock ;
}
2023-06-02 15:34:22 +08:00
BlockOfTransmissionData getBlockOfTransmissionData ( const Matrix & aMp , const Matrix & aMpRef , const Matrix & aSl , const Matrix & aSn , const Matrix & aRlList , const Matrix & aRnList ,
const TasTemps & aTasTemps , const Matrix & aExpectedSOSWater , GeometryInfo aGeom , GeometryInfo & aGeomRef ,
const Matrix & aSnrRmsNoise , const Matrix & aSnrRmsNoiseRef , const MeasurementInfo & aExpInfo , const MeasurementInfo & aExpInfoRef ,
const PreComputes & aPreComputes , Parser * aParser , Parser * aParserRef )
{
BlockOfTransmissionData result ;
2023-12-22 11:17:18 +08:00
MetaInfos metaInfos ;
//printTime();
//2500ms
auto blockData = getAscanBlockPreprocessedCuda ( aParser , aMp , aSl , aSn , aRlList , aRnList , aGeom , aExpInfo , true , true ) ;
auto blockDataRef = getAscanBlockPreprocessedCuda ( aParserRef , aMpRef , aSl , aSn , aRlList , aRnList , aGeomRef , aExpInfoRef , true , true ) ;
//printTime();
//180ms
// auto t1 = blockData.ascanBlockPreprocessed.toDeviceMatrix();
// auto t2 = blockDataRef.ascanBlockPreprocessed.toDeviceMatrix();
// auto t3 = blockData.gainBlock.toDeviceMatrix();
// auto t4 = blockDataRef.gainBlock.toDeviceMatrix();
//printTime();
//20ms
CudaMatrix ascanBlock = prepareAScansForTransmissionDetection ( blockData . ascanBlockPreprocessed , blockData . gainBlock ) ;
CudaMatrix ascanBlockRef = prepareAScansForTransmissionDetection ( blockDataRef . ascanBlockPreprocessed , blockDataRef . gainBlock ) ;
//printTime();
//20ms
blockData . ascanBlockPreprocessed = CudaMatrix ( ) ;
blockDataRef . ascanBlockPreprocessed = CudaMatrix ( ) ;
2023-06-02 15:34:22 +08:00
if ( aExpInfo . Hardware = = " USCT3dv3 " )
{
Matrix channelList = precalculateChannelList ( aRlList , aRnList , aExpInfo , aPreComputes ) ;
2023-10-09 09:29:21 +08:00
float * channelListSizeData = Aurora : : malloc ( 2 ) ;
2023-06-02 15:34:22 +08:00
channelListSizeData [ 0 ] = channelList . getDimSize ( 0 ) ;
channelListSizeData [ 1 ] = channelList . getDimSize ( 1 ) ;
Matrix channelListSize = Matrix : : New ( channelListSizeData , 2 , 1 ) ;
Matrix ind = sub2ind ( channelListSize , { blockData . rlBlock , blockData . rnBlock } ) ;
size_t channelListBlockSize = ind . getDataSize ( ) ;
2023-10-09 09:29:21 +08:00
float * channelListBlockData = Aurora : : malloc ( channelListBlockSize ) ;
2023-06-02 15:34:22 +08:00
for ( size_t i = 0 ; i < channelListBlockSize ; + + i )
{
channelListBlockData [ i ] = channelList [ ind [ i ] - 1 ] ;
}
Matrix channelListBlock = Matrix : : New ( channelListBlockData , 1 , channelListBlockSize ) ;
2023-12-22 11:17:18 +08:00
//printTime();
//20ms
CudaMatrix fx = fft ( ascanBlock ) ;
//printTime();
//50ms
// float* fhData = nullptr;
// cudaMalloc((void**)&fhData, sizeof(float) * aExpInfo.matchedFilter.getDimSize(0) * channelListBlockSize * Aurora::Complex);
// CudaMatrix fh = CudaMatrix::fromRawData(fhData, aExpInfo.matchedFilter.getDimSize(0), channelListBlockSize, 1, Aurora::Complex);
// size_t matchedFilterRowDataSize = aExpInfo.matchedFilter.getDimSize(0)*2;
// for(size_t i=0; i<channelListBlockSize; ++i)
// {
// cudaMemcpy(fhData, aExpInfo.matchedFilter.getData() + (size_t)(channelListBlock[i] - 1) * matchedFilterRowDataSize, sizeof(float) * matchedFilterRowDataSize, cudaMemcpyHostToDevice);
// fhData += matchedFilterRowDataSize;
// }
Aurora : : CudaMatrix matchedFilterDevice = aExpInfo . matchedFilter . toDeviceMatrix ( ) ;
Aurora : : CudaMatrix channelListBlockDevice = channelListBlock . toDeviceMatrix ( ) ;
Aurora : : CudaMatrix fh = createFhMatrix ( matchedFilterDevice , channelListBlockDevice ) ;
//printTime();
//20ms
CudaMatrix complex = getTransmissionDataSubFunction ( fx , fh ) ;
2023-06-02 15:34:22 +08:00
ascanBlock = Aurora : : real ( ifft ( complex ) ) ;
2023-12-22 11:17:18 +08:00
//printTime();
//20s
2023-06-02 15:34:22 +08:00
fx = fft ( ascanBlockRef ) ;
2023-12-22 11:17:18 +08:00
//printTime();
//50ms
// cudaMalloc((void**)&fhData, sizeof(float) * aExpInfo.matchedFilter.getDimSize(0) * channelListBlockSize * Aurora::Complex);
// fh = CudaMatrix::fromRawData(fhData, aExpInfoRef.matchedFilter.getDimSize(0), channelListBlockSize, 1, Aurora::Complex);
// matchedFilterRowDataSize = aExpInfoRef.matchedFilter.getDimSize(0)*2;
// for(size_t i=0; i<channelListBlockSize; ++i)
// {
// cudaMemcpy(fhData, aExpInfoRef.matchedFilter.getData() + (size_t)(channelListBlock[i] - 1) * matchedFilterRowDataSize, sizeof(float) * matchedFilterRowDataSize, cudaMemcpyHostToDevice);
// fhData += matchedFilterRowDataSize;
// }
matchedFilterDevice = aExpInfoRef . matchedFilter . toDeviceMatrix ( ) ;
fh = createFhMatrix ( matchedFilterDevice , channelListBlockDevice ) ;
//printTime();
//20ms
complex = getTransmissionDataSubFunction ( fx , fh ) ;
2023-06-02 15:34:22 +08:00
ascanBlockRef = Aurora : : real ( ifft ( complex ) ) ;
2023-12-22 11:17:18 +08:00
//printTime();
//20ms
2023-06-02 15:34:22 +08:00
}
else
{
transParams : : detectionWindowSOS = transParams : : pulseLengthSamples ;
transParams : : detectionWindowATT = transParams : : pulseLengthSamples ;
}
if ( transParams : : applyCalib )
{
2023-12-22 11:17:18 +08:00
metaInfos . snrValues = calculateSnr ( ascanBlock , aSnrRmsNoise [ 0 ] ) . toHostMatrix ( ) ;
metaInfos . snrValuesRef = calculateSnr ( ascanBlockRef , aSnrRmsNoiseRef [ 0 ] ) . toHostMatrix ( ) ;
2023-06-02 15:34:22 +08:00
}
2023-12-22 11:17:18 +08:00
// printTime();
//3ms
2023-06-02 15:34:22 +08:00
Matrix dists = distanceBetweenTwoPoints ( blockData . senderPositionBlock , blockData . receiverPositionBlock ) ;
Matrix distRefBlock = distanceBetweenTwoPoints ( blockDataRef . senderPositionBlock , blockDataRef . receiverPositionBlock ) ;
2023-12-22 11:17:18 +08:00
//printTime();
//2ms
2023-06-02 15:34:22 +08:00
Matrix waterTempBlock = calculateWaterTemperature ( aTasTemps . waterTempPreCalc_sl , aTasTemps . waterTempPreCalc_rl , blockData . slBlock , blockData . rlBlock , blockData . mpBlock ) ;
Matrix waterTempRefBlock = calculateWaterTemperature ( aTasTemps . waterTempRefPreCalc_sl , aTasTemps . waterTempRefPreCalc_rl , blockData . slBlock , blockData . rlBlock , blockDataRef . mpBlock ) ;
2023-12-22 11:17:18 +08:00
// printTime();
// 1ms
// if(transParams::saveDetection || transParams::outlierOnTasDetection || transParams::saveDebugInfomation)
// {
// metaInfos.mpBlock = blockData.mpBlock;
// metaInfos.slBlock = blockData.slBlock;
// metaInfos.snBlock = blockData.snBlock;
// metaInfos.rlBlock = blockData.rlBlock;
// metaInfos.rnBlock = blockData.rnBlock;
// }
2023-06-02 15:34:22 +08:00
result . metaInfos = metaInfos ;
result . senderBlock = blockData . senderPositionBlock ;
result . receiverBlock = blockData . receiverPositionBlock ;
result . waterTempBlock = waterTempBlock ;
2023-06-07 16:28:41 +08:00
result . ascanBlock = ascanBlock ;
result . ascanBlockRef = ascanBlockRef ;
result . dists = dists ;
result . distRefBlock = distRefBlock ;
result . waterTempRefBlock = waterTempRefBlock ;
2023-06-02 15:34:22 +08:00
2023-06-07 16:28:41 +08:00
// DetectResult detect = transmissionDetection(ascanBlock, ascanBlockRef, dists, distRefBlock, waterTempBlock, waterTempRefBlock, aExpectedSOSWater[0]);
// result.attData = detect.att;
// result.tofData = detect.tof;
2023-12-22 11:17:18 +08:00
//printTime();
2023-06-02 15:34:22 +08:00
return result ;
}
2023-06-07 16:28:41 +08:00
2023-06-02 15:34:22 +08:00
}
2023-07-03 17:12:53 +08:00
void getBlockOfTransmissionDataInThread ( size_t aIndex , const Matrix & aMp , const Matrix & aMpRef , const Matrix & aSl , const Matrix & aSn , const Matrix & aRlList , const Matrix & aRnList ,
const TasTemps & aTasTemps , const Matrix & aExpectedSOSWater , GeometryInfo aGeom , GeometryInfo aGeomRef ,
const Matrix & aSnrRmsNoise , const Matrix & aSnrRmsNoiseRef , const MeasurementInfo & aExpInfo , const MeasurementInfo & aExpInfoRef ,
2023-12-22 11:17:18 +08:00
const PreComputes & aPreComputes , Parser * aParser , Parser * aParserRef , unsigned int aGPUId )
2023-07-03 17:12:53 +08:00
{
2023-12-22 11:17:18 +08:00
cudaSetDevice ( aGPUId ) ;
2023-07-03 17:12:53 +08:00
auto buffer = getBlockOfTransmissionData ( aMp , aMpRef , aSl , aSn , aRlList , aRnList , aTasTemps ,
aExpectedSOSWater , aGeom , aGeomRef , aSnrRmsNoise , aSnrRmsNoiseRef ,
aExpInfo , aExpInfoRef , aPreComputes , aParser , aParserRef ) ;
std : : unique_lock < std : : mutex > lock ( CREATE_BUFFER_MUTEX ) ;
BLOCK_OF_TRANSIMISSIONDARA_BUFFER [ std : : to_string ( aIndex ) ] = buffer ;
std : : cout < < " Add: " < < aIndex < < std : : endl ;
lock . unlock ( ) ;
PROCESS_BUFFER_CONDITION . notify_one ( ) ;
}
void createThreadForGetBlockOfTransmissionData ( const Matrix & aMotorPos , const Matrix & aMotoPosRef , const Matrix & aSlList , const Matrix & aSnList , const Matrix & aRlList , const Matrix & aRnList ,
const TasTemps & aTasTemps , const Matrix & aExpectedSOSWater , GeometryInfo aGeom , GeometryInfo aGeomRef ,
const Matrix & aSnrRmsNoise , const Matrix & aSnrRmsNoiseRef , const MeasurementInfo & aExpInfo , const MeasurementInfo & aExpInfoRef ,
const PreComputes & aPreComputes , Parser * aParser , Parser * aParserRef )
{
size_t vectorSize = aMotorPos . getDataSize ( ) * ( aSlList . getDataSize ( ) / transParams : : senderTASSize ) * ( aSnList . getDataSize ( ) / transParams : : senderElementSize ) ;
std : : thread speedUpThread [ vectorSize ] ;
for ( int i = 0 ; i < aMotorPos . getDataSize ( ) ; + + i )
{
for ( int j = 0 ; j < aSlList . getDataSize ( ) / transParams : : senderTASSize ; + + j )
{
for ( int k = 0 ; k < aSnList . getDataSize ( ) / transParams : : senderElementSize ; + + k )
{
size_t index = i * ( aSlList . getDataSize ( ) / transParams : : senderTASSize ) * ( aSnList . getDataSize ( ) / transParams : : senderElementSize ) +
j * ( aSnList . getDataSize ( ) / transParams : : senderElementSize ) + k ;
Matrix mp = aMotorPos ( i ) . toMatrix ( ) ;
Matrix mpRef = aMotoPosRef ( i ) . toMatrix ( ) ;
Matrix sl = aSlList . block ( 0 , transParams : : senderTASSize * j , transParams : : senderTASSize * j + transParams : : senderTASSize - 1 ) ;
Matrix sn = aSnList . block ( 0 , transParams : : senderElementSize * k , transParams : : senderElementSize * k + transParams : : senderElementSize - 1 ) ;
std : : unique_lock < std : : mutex > lock ( CREATE_BUFFER_MUTEX ) ;
CREATE_BUFFER_CONDITION . wait ( lock , [ ] { return BUFFER_COUNT < BUFFER_SIZE ; } ) ;
+ + BUFFER_COUNT ;
lock . unlock ( ) ;
2023-12-22 11:17:18 +08:00
speedUpThread [ index ] = std : : thread ( getBlockOfTransmissionDataInThread , index , mp , mpRef , sl , sn , aRlList , aRnList , aTasTemps , aExpectedSOSWater , aGeom , aGeomRef , aSnrRmsNoise , aSnrRmsNoiseRef , aExpInfo , aExpInfoRef , aPreComputes , aParser , aParserRef , index % BUFFER_SIZE ) ;
2023-07-03 17:12:53 +08:00
}
}
}
for ( auto & t : speedUpThread )
{
t . join ( ) ;
}
}
2023-06-02 15:34:22 +08:00
TransmissionData Recon : : getTransmissionData ( const Aurora : : Matrix & aMotorPos , const Aurora : : Matrix & aMotoPosRef , const Aurora : : Matrix & aSlList ,
2023-05-19 17:32:31 +08:00
const Aurora : : Matrix & aSnList , const Aurora : : Matrix & aRlList , const Aurora : : Matrix & aRnList ,
const TempInfo & aTemp , const TempInfo & aTempRef , GeometryInfo & aGeom ,
GeometryInfo & aGeomRef , const MeasurementInfo & aExpInfo , const MeasurementInfo & aExpInfoRef ,
2023-06-02 15:34:22 +08:00
const PreComputes & aPreComputes , Parser * aParser , Parser * aParserRef )
2023-05-19 17:32:31 +08:00
{
2023-06-02 15:34:22 +08:00
//推测是已经完成过透射重建并从完成的透射重建读取数据
2023-05-19 17:32:31 +08:00
//暂不考虑此逻辑运行
// if transParams.detection.forceRedetect == 0 && exist(transParams.pathSaveDetection, 'dir') && size(dir(transParams.pathSaveDetection), 1) > 2 % i.e. detection folder exists and is not empty
// % Load transmission detection data
// writeReconstructionLog('Loading transmission detection data. All available data from given motor positions are taken.', 1);
// [tofDataTotal, attDataTotal, senderList, receiverList, waterTempList, dataInfo] = loadTransmissionDetectionData(transParams.pathSaveDetection, transParams.pathData, motorPos, expInfo.rootMeasUniqueID);
TasTemps tasTemps ;
tasTemps . waterTempPreCalc_rl = extractTasTemperature ( aTemp . tasTemperature , aRlList , aMotorPos , aTemp . jumoTemp , transParams : : minTemperature , transParams : : maxTemperature ) ;
tasTemps . waterTempPreCalc_sl = extractTasTemperature ( aTemp . tasTemperature , aSlList , aMotorPos , aTemp . jumoTemp , transParams : : minTemperature , transParams : : maxTemperature ) ;
tasTemps . waterTempRefPreCalc_rl = extractTasTemperature ( aTempRef . tasTemperature , aRlList , aMotoPosRef , aTempRef . jumoTemp , transParams : : minTemperature , transParams : : maxTemperature ) ;
tasTemps . waterTempRefPreCalc_sl = extractTasTemperature ( aTempRef . tasTemperature , aSlList , aMotoPosRef , aTempRef . jumoTemp , transParams : : minTemperature , transParams : : maxTemperature ) ;
2023-05-23 09:45:21 +08:00
aGeom . sensData = precalcSensitivity ( aSlList , aSnList , aRlList , aRnList , aMotorPos , aGeom ) ;
aGeomRef . sensData = aGeom . sensData ;
2023-05-19 17:32:31 +08:00
2023-06-02 15:34:22 +08:00
Matrix rmsNoise , rmsNoiseRef ;
if ( transParams : : applyCalib )
{
rmsNoise = estimateNoiseValueFromAScans ( aSnList , aRnList , aGeom , aExpInfo , aParser ) ;
rmsNoiseRef = estimateNoiseValueFromAScans ( aSnList , aRnList , aGeom , aExpInfo , aParserRef ) ;
}
size_t numScans = aMotorPos . getDataSize ( ) * aSlList . getDataSize ( ) * aSnList . getDataSize ( ) * aRlList . getDataSize ( ) * aRnList . getDataSize ( ) ;
2023-10-09 09:29:21 +08:00
Matrix tofDataTotal = Matrix : : fromRawData ( new float [ numScans ] , 1 , numScans ) + NAN ;
Matrix attDataTotal = Matrix : : fromRawData ( new float [ numScans ] , 1 , numScans ) + NAN ;
2023-06-02 15:34:22 +08:00
Matrix waterTempList = zeros ( 1 , numScans , 1 ) ;
Matrix senderList = zeros ( 3 , numScans , 1 ) ;
Matrix receiverList = zeros ( 3 , numScans , 1 ) ;
Matrix snrValues = zeros ( 1 , numScans , 1 ) ;
Matrix snrValuesRef = zeros ( 1 , numScans , 1 ) ;
Matrix mpBlockTotal ;
Matrix slBlockTotal ;
Matrix snBlockTotal ;
Matrix rlBlockTotal ;
Matrix rnBlockTotal ;
if ( transParams : : saveDetection | | transParams : : outlierOnTasDetection | | transParams : : saveDebugInfomation )
{
mpBlockTotal = zeros ( 1 , numScans , 1 ) ;
slBlockTotal = zeros ( 1 , numScans , 1 ) ;
snBlockTotal = zeros ( 1 , numScans , 1 ) ;
rlBlockTotal = zeros ( 1 , numScans , 1 ) ;
rnBlockTotal = zeros ( 1 , numScans , 1 ) ;
}
2023-07-03 17:12:53 +08:00
std : : thread speedUpThread = std : : thread ( createThreadForGetBlockOfTransmissionData , aMotorPos , aMotoPosRef , aSlList , aSnList , aRlList , aRnList , tasTemps , aTemp . expectedSOSWater , aGeom , aGeomRef , rmsNoise , rmsNoiseRef , aExpInfo , aExpInfoRef , aPreComputes , aParser , aParserRef ) ;
2023-06-02 15:34:22 +08:00
int numData = 0 ;
int numPossibleScans = 0 ;
2023-07-03 17:12:53 +08:00
sched_param sch ;
int policy ;
pthread_getschedparam ( pthread_self ( ) , & policy , & sch ) ;
sch . sched_priority = 50 ;
if ( pthread_setschedparam ( pthread_self ( ) , SCHED_FIFO , & sch ) )
2023-06-02 15:34:22 +08:00
{
2023-07-03 17:12:53 +08:00
std : : cerr < < " Failed to set thread priority " < < std : : endl ;
2023-06-07 16:28:41 +08:00
}
for ( int i = 0 ; i < aMotorPos . getDataSize ( ) ; + + i )
{
for ( int j = 0 ; j < aSlList . getDataSize ( ) / transParams : : senderTASSize ; + + j )
{
for ( int k = 0 ; k < aSnList . getDataSize ( ) / transParams : : senderElementSize ; + + k )
{
size_t index = i * ( aSlList . getDataSize ( ) / transParams : : senderTASSize ) * ( aSnList . getDataSize ( ) / transParams : : senderElementSize ) +
2023-07-03 17:12:53 +08:00
j * ( aSnList . getDataSize ( ) / transParams : : senderElementSize ) + k ;
std : : unique_lock < std : : mutex > lock ( PROCESS_BUFFER_MUTEX ) ;
PROCESS_BUFFER_CONDITION . wait ( lock , [ index ] { return BLOCK_OF_TRANSIMISSIONDARA_BUFFER . find ( std : : to_string ( index ) ) ! = BLOCK_OF_TRANSIMISSIONDARA_BUFFER . end ( ) ; } ) ;
lock . unlock ( ) ;
2023-06-07 16:28:41 +08:00
2023-07-03 17:12:53 +08:00
auto blockData = BLOCK_OF_TRANSIMISSIONDARA_BUFFER [ std : : to_string ( index ) ] ;
2023-12-22 11:17:18 +08:00
cudaSetDevice ( index % BUFFER_SIZE ) ;
2023-07-03 17:12:53 +08:00
DetectResult detect = transmissionDetection ( blockData . ascanBlock , blockData . ascanBlockRef ,
2023-12-22 11:17:18 +08:00
blockData . dists . toDeviceMatrix ( ) , blockData . distRefBlock . toDeviceMatrix ( ) ,
2023-07-03 17:12:53 +08:00
blockData . waterTempBlock , blockData . waterTempRefBlock ,
2023-06-07 16:28:41 +08:00
aTemp . expectedSOSWater [ 0 ] ) ;
2023-07-03 17:12:53 +08:00
blockData . attData = detect . att ;
blockData . tofData = detect . tof ;
BlockOfTransmissionData transmissionBlock = blockData ;
2023-06-02 15:34:22 +08:00
size_t numUsedData = transmissionBlock . senderBlock . getDimSize ( 1 ) ;
if ( transParams : : applyCalib )
{
2023-10-09 09:29:21 +08:00
cblas_scopy ( numUsedData , transmissionBlock . metaInfos . snrValues . getData ( ) , 1 , snrValues . getData ( ) + numData , 1 ) ;
cblas_scopy ( numUsedData , transmissionBlock . metaInfos . snrValuesRef . getData ( ) , 1 , snrValuesRef . getData ( ) + numData , 1 ) ;
2023-06-02 15:34:22 +08:00
}
int rows = transmissionBlock . senderBlock . getDimSize ( 0 ) ;
2023-10-09 09:29:21 +08:00
cblas_scopy ( numUsedData * rows , transmissionBlock . senderBlock . getData ( ) , 1 , senderList . getData ( ) + numData * rows , 1 ) ;
cblas_scopy ( numUsedData * rows , transmissionBlock . receiverBlock . getData ( ) , 1 , receiverList . getData ( ) + numData * rows , 1 ) ;
cblas_scopy ( numUsedData , transmissionBlock . tofData . getData ( ) , 1 , tofDataTotal . getData ( ) + numData , 1 ) ;
cblas_scopy ( numUsedData , transmissionBlock . attData . getData ( ) , 1 , attDataTotal . getData ( ) + numData , 1 ) ;
cblas_scopy ( numUsedData , transmissionBlock . waterTempBlock . getData ( ) , 1 , waterTempList . getData ( ) + numData , 1 ) ;
2023-06-02 15:34:22 +08:00
2023-12-22 11:17:18 +08:00
// if(transParams::saveDetection || transParams::outlierOnTasDetection || transParams::saveDebugInfomation)
// {
// cblas_scopy(numUsedData, transmissionBlock.metaInfos.mpBlock.getData(), 1, mpBlockTotal.getData() + numData, 1);
// cblas_scopy(numUsedData, transmissionBlock.metaInfos.slBlock.getData(), 1, slBlockTotal.getData() + numData, 1);
// cblas_scopy(numUsedData, transmissionBlock.metaInfos.snBlock.getData(), 1, snBlockTotal.getData() + numData, 1);
// cblas_scopy(numUsedData, transmissionBlock.metaInfos.rlBlock.getData(), 1, rlBlockTotal.getData() + numData, 1);
// cblas_scopy(numUsedData, transmissionBlock.metaInfos.rnBlock.getData(), 1, rnBlockTotal.getData() + numData, 1);
// }
2023-06-02 15:34:22 +08:00
numData + = numUsedData ;
2023-07-03 17:12:53 +08:00
std : : unique_lock < std : : mutex > lockBufferCount ( CREATE_BUFFER_MUTEX ) ;
BLOCK_OF_TRANSIMISSIONDARA_BUFFER . erase ( std : : to_string ( index ) ) ;
- - BUFFER_COUNT ;
lockBufferCount . unlock ( ) ;
std : : cout < < " Remove: " < < index < < std : : endl ;
CREATE_BUFFER_CONDITION . notify_one ( ) ;
2023-06-02 15:34:22 +08:00
}
2023-12-22 11:17:18 +08:00
//Recon::notifyProgress(6+10*((i+1)*(j+1)/(aMotorPos.getDataSize()*(aSlList.getDataSize()/ transParams::senderTASSize))));
2023-06-02 15:34:22 +08:00
}
}
2023-07-03 17:12:53 +08:00
speedUpThread . join ( ) ;
2023-06-02 15:34:22 +08:00
2023-10-09 09:29:21 +08:00
float * filterData = Aurora : : malloc ( tofDataTotal . getDataSize ( ) ) ;
2023-06-02 15:34:22 +08:00
for ( int i = 0 ; i < tofDataTotal . getDataSize ( ) ; + + i )
{
if ( tofDataTotal [ i ] ! = tofDataTotal [ i ] )
{
filterData [ i ] = 0 ;
}
else
{
filterData [ i ] = 1 ;
}
}
Matrix filter = Matrix : : New ( filterData , 1 , tofDataTotal . getDataSize ( ) ) ;
if ( transParams : : applyCalib )
{
snrValues = removeDataFromArrays ( snrValues , filter ) ;
snrValuesRef = removeDataFromArrays ( snrValuesRef , filter ) ;
}
senderList = removeDataFromArrays ( senderList , filter ) ;
receiverList = removeDataFromArrays ( receiverList , filter ) ;
tofDataTotal = removeDataFromArrays ( tofDataTotal , filter ) ;
attDataTotal = removeDataFromArrays ( attDataTotal , filter ) ;
waterTempList = removeDataFromArrays ( waterTempList , filter ) ;
2023-12-22 11:17:18 +08:00
// if(transParams::saveDebugInfomation || transParams::outlierOnTasDetection || transParams::saveDetection)
// {
// mpBlockTotal = removeDataFromArrays(mpBlockTotal, filter);
// slBlockTotal = removeDataFromArrays(slBlockTotal, filter);
// snBlockTotal = removeDataFromArrays(snBlockTotal, filter);
// rlBlockTotal = removeDataFromArrays(rlBlockTotal, filter);
// rnBlockTotal = removeDataFromArrays(rnBlockTotal, filter);
// }
2023-06-02 15:34:22 +08:00
Matrix valid ;
if ( transParams : : applyCalib )
{
valid = findDefectTransmissionData ( Matrix : : copyFromRawData ( snrValues . getData ( ) , 1 , numData ) , transParams : : snrThreshold ) *
findDefectTransmissionData ( Matrix : : copyFromRawData ( snrValuesRef . getData ( ) , 1 , numData ) , transParams : : snrThreshold ) ;
}
else
{
valid = zeros ( 1 , numData ) + 1 ;
}
DataInfo dataInfno ;
2023-10-09 09:29:21 +08:00
float * findDefectData = Aurora : : malloc ( valid . getDataSize ( ) ) ;
2023-06-02 15:34:22 +08:00
int findDefectDataIndex = 0 ;
for ( int i = 0 ; i < valid . getDataSize ( ) ; + + i )
{
if ( valid [ i ] = = 0 )
{
findDefectData [ findDefectDataIndex ] = i + 1 ;
+ + findDefectDataIndex ;
}
}
dataInfno . findDefect = Matrix : : New ( findDefectData , 1 , findDefectDataIndex ) ;
2023-12-22 11:17:18 +08:00
// if(transParams::saveDebugInfomation)
// {
// dataInfno.sn = snBlockTotal;
// dataInfno.sl = slBlockTotal;
// dataInfno.rn = rnBlockTotal;
// dataInfno.rl = rlBlockTotal;
// dataInfno.mp = mpBlockTotal;
// }
2023-06-02 15:34:22 +08:00
tofDataTotal = removeDataFromArrays ( tofDataTotal , valid ) ;
attDataTotal = removeDataFromArrays ( attDataTotal , valid ) ;
senderList = removeDataFromArrays ( senderList , valid ) ;
receiverList = removeDataFromArrays ( receiverList , valid ) ;
waterTempList = removeDataFromArrays ( waterTempList , valid ) ;
dataInfno . numPossibleScans = numData ;
dataInfno . numValidScans = sum ( valid ) ;
2023-06-27 09:13:34 +08:00
//以下逻辑config默认值不走。后续再实现todo
2023-06-02 15:34:22 +08:00
// if(transParams.detection.outlierOnTasDetection)
// snBlockTotal = snBlockTotal(valid);
// slBlockTotal = slBlockTotal(valid);
// rnBlockTotal = rnBlockTotal(valid);
// rlBlockTotal = rlBlockTotal(valid);
// outliers = analyzeDetections(slBlockTotal, snBlockTotal, rlBlockTotal, rnBlockTotal, tofDataTotal);
// tofDataTotal = tofDataTotal(~outliers);
// attDataTotal = attDataTotal(:,~outliers);
// senderList = senderList(:,~outliers);
// receiverList = receiverList(:,~outliers);
// waterTempList = waterTempList(~outliers);
// writeReconstructionLog(sprintf('Removed additionally %i outliers. \n',sum(outliers)),1);
// writeReconstructionLog(sprintf('Total data after 3 filter steps: Taken %d/%d AScans for reconstruction (%.2f percent).', numel(tofDataTotal), numScans, (numel(tofDataTotal) / numScans)*100), 1)
// end
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// if transParams.detection.saveDetection % writing the detected values to file
// writeReconstructionLog('Save transmission detections.', 1);
// if(~transParams.detection.outlierOnTasDetection)
// snBlockTotal = snBlockTotal(valid);
// slBlockTotal = slBlockTotal(valid);
// rnBlockTotal = rnBlockTotal(valid);
// rlBlockTotal = rlBlockTotal(valid);
// end
// mpBlockTotal = mpBlockTotal(valid);
// if(transParams.detection.outlierOnTasDetection)
// snBlockTotal = snBlockTotal(~outliers);
// slBlockTotal = slBlockTotal(~outliers);
// rnBlockTotal = rnBlockTotal(~outliers);
// rlBlockTotal = rlBlockTotal(~outliers);
// mpBlockTotal = mpBlockTotal(~outliers);
// end
// saveTransmisssionDetectionData(transParams.pathSaveDetection, tofDataTotal, attDataTotal, senderList, receiverList, mpBlockTotal, slBlockTotal, snBlockTotal, rlBlockTotal, rnBlockTotal, waterTempList, expInfo.rootMeasUniqueID, dataInfo);
// end
TransmissionData result ;
result . attDataTotal = attDataTotal ;
result . tofDataTotal = tofDataTotal ;
result . receiverList = receiverList ;
result . senderList = senderList ;
result . dataInfo = dataInfno ;
result . waterTempList = waterTempList ;
return result ;
2023-05-19 17:32:31 +08:00
}