Skip to content

Commit

Permalink
Removed use of omp get wall time functions
Browse files Browse the repository at this point in the history
  • Loading branch information
smistad committed Aug 8, 2023
1 parent b0abd44 commit ef64545
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 67 deletions.
3 changes: 1 addition & 2 deletions doc/pages/Python-tutorial-ultrasound.dox
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,7 @@ streamer = fast.ImageFileStreamer.create(

segmentationNetwork = fast.SegmentationNetwork.create(
fast.Config.getTestDataPath() + 'NeuralNetworkModels/jugular_vein_segmentation.onnx',
scaleFactor=1./255.,
inferenceEngine='OpenVINO'
scaleFactor=1./255.
).connect(streamer)

# Set up rendering
Expand Down
12 changes: 0 additions & 12 deletions source/FAST/Algorithms/CoherentPointDrift/Affine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ namespace fast {

void CoherentPointDriftAffine::maximization(Eigen::MatrixXf &fixedPoints, Eigen::MatrixXf &movingPoints) {

double startM = omp_get_wtime();

// Define some useful matrix sums
mPt1 = mResponsibilityMatrix.transpose().rowwise().sum(); // mNumFixedPoints x 1
mP1 = mResponsibilityMatrix.rowwise().sum(); // mNumMovingPoints x 1
mNp = mPt1.sum(); // 1 (sum of all P elements)
double timeEndMUseful = omp_get_wtime();

// Estimate new mean vectors
MatrixXf fixedMean = fixedPoints.transpose() * mPt1 / mNp;
Expand All @@ -40,7 +37,6 @@ namespace fast {
// Center point sets around estimated mean
MatrixXf fixedPointsCentered = fixedPoints - fixedMean.transpose().replicate(mNumFixedPoints, 1);
MatrixXf movingPointsCentered = movingPoints - movingMean.transpose().replicate(mNumMovingPoints, 1);
double timeEndMCenter = omp_get_wtime();

/* **********************************************************
* Find transformation parameters: affine matrix, translation
Expand All @@ -61,7 +57,6 @@ namespace fast {
mVariance = 10.0 * std::numeric_limits<double>::epsilon();
mRegistrationConverged = true;
}
double timeEndMParameters = omp_get_wtime();


/* ****************
Expand Down Expand Up @@ -94,13 +89,6 @@ namespace fast {
+ (mNp * mNumDimensions)/2 * log(mVariance);
mIterationError = std::fabs( (mObjectiveFunction - objectiveFunctionOld) / objectiveFunctionOld);
mRegistrationConverged = mIterationError <= mTolerance;

double endM = omp_get_wtime();
timeM += endM - startM;
timeMUseful += timeEndMUseful - startM;
timeMCenter += timeEndMCenter - timeEndMUseful;
timeMParameters += timeEndMParameters - timeEndMCenter;
timeMUpdate += endM - timeEndMParameters;
}

}
38 changes: 0 additions & 38 deletions source/FAST/Algorithms/CoherentPointDrift/CoherentPointDrift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ namespace fast {

void CoherentPointDrift::expectation(MatrixXf& fixedPoints, MatrixXf& movingPoints) {

double timeStartE = omp_get_wtime();

/* **********************************************************************************
* Calculate distances between the points in the two point sets
* Let row i in P equal the squared distances from all fixed points to moving point i
Expand Down Expand Up @@ -121,27 +119,16 @@ namespace fast {
mResponsibilityMatrix(row, col) = exp(norm / (-2.0 * mVariance));
}
}
double timeEndFirstLoop = omp_get_wtime();

#pragma omp parallel for
for (int col = 0; col < mNumFixedPoints; ++col) {
float denom = mResponsibilityMatrix.col(col).sum() + c;
mResponsibilityMatrix.col(col) /= max(denom, Eigen::NumTraits<float>::epsilon() );
}

// Update computation times
double timeEndE = omp_get_wtime();
timeEDistances += 0.0;
timeENormal += timeEndFirstLoop - timeStartE;
timeEPosterior += 0.0;
timeEPosteriorDivision += timeEndE - timeEndFirstLoop;
timeE += timeEndE - timeStartE;
}

void CoherentPointDrift::execute() {

double timeStart = omp_get_wtime();

// Store the point sets in matrices and store their dimensions
initializePointSets();
printCloudDimensions();
Expand All @@ -161,38 +148,13 @@ namespace fast {
/* *************************
* Get some points drifting!
* ************************/
double timeStartEM = omp_get_wtime();

while (mIteration < mMaxIterations && !mRegistrationConverged) {
// std::cout << "ITERATION " << (int) mIteration << std::endl;
expectation(mFixedPoints, mMovingPoints);
maximization(mFixedPoints, mMovingPoints);
mIteration++;
}


/* *****************
* Computation times
* ****************/
double timeEndEM = omp_get_wtime();
double timeTotalEM = timeEndEM - timeStartEM;

std::cout << "\nCOMPUTATION TIMES:\n";
std::cout << "Initialization of point sets and normalization: " << timeStartEM-timeStart << " s.\n";
std::cout << "EM converged in " << mIteration-1 << " iterations in " << timeTotalEM << " s.\n";
std::cout << "Time spent on expectation: " << timeE << " s\n";
std::cout << " - Calculating distances between points: " << timeEDistances << " s.\n";
std::cout << " - Normal distribution: " << timeENormal << " s.\n";
std::cout << " - Create denominator, no zero-elements: " << timeEPosterior << " s.\n";
std::cout << " - Posterior GMM probabilities, division: " << timeEPosteriorDivision << " s.\n";
std::cout << "Time spent on maximization: " << timeM << " s\n";
std::cout << " - Calculating P1, Pt1, Np: " << timeMUseful << " s.\n";
std::cout << " - Centering point clouds: " << timeMCenter << " s.\n";
std::cout << " - SVD: " << timeMSVD << " s.\n";
std::cout << " - Calculation transformation parameters: " << timeMParameters << " s.\n";
std::cout << " - Updating transformation and error: " << timeMUpdate << " s.\n";


/* ***********************************************
* Denormalize and set total transformation matrix
* **********************************************/
Expand Down
15 changes: 0 additions & 15 deletions source/FAST/Algorithms/CoherentPointDrift/Rigid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ namespace fast {
}

void CoherentPointDriftRigid::maximization(MatrixXf& fixedPoints, MatrixXf& movingPoints) {
double startM = omp_get_wtime();

// Calculate some useful matrix reductions
mP1 = VectorXf::Zero(mNumMovingPoints);
#pragma omp parallel for
Expand All @@ -46,7 +44,6 @@ namespace fast {
mP1 += mP1Local;
}
mNp = mPt1.sum(); // 1 (sum of all P elements)
double timeEndMUseful = omp_get_wtime();

// Estimate new mean vectors
MatrixXf fixedMean = fixedPoints.transpose() * mPt1 / mNp;
Expand All @@ -56,7 +53,6 @@ namespace fast {
MatrixXf fixedPointsCentered = fixedPoints - fixedMean.transpose().replicate(mNumFixedPoints, 1);
MatrixXf movingPointsCentered = movingPoints - movingMean.transpose().replicate(mNumMovingPoints, 1);

double timeEndMCenter = omp_get_wtime();


// Single value decomposition (SVD)
Expand All @@ -70,7 +66,6 @@ namespace fast {
Eigen::RowVectorXf C = Eigen::RowVectorXf::Ones(mNumDimensions);
C[mNumDimensions-1] = UVt.determinant();

double timeEndMSVD = omp_get_wtime();

/* ************************************************************
* Find transformation parameters: rotation, scale, translation
Expand All @@ -93,7 +88,6 @@ namespace fast {
mVariance = 10.0 * std::numeric_limits<double>::epsilon();
mRegistrationConverged = true;
}
double timeEndMParameters = omp_get_wtime();

/* ****************
* Update transform
Expand Down Expand Up @@ -127,15 +121,6 @@ namespace fast {
+ (mNp * mNumDimensions)/2 * log(mVariance);
mIterationError = std::fabs( (mObjectiveFunction - objectiveFunctionOld) / objectiveFunctionOld);
mRegistrationConverged = mIterationError <= mTolerance;


double endM = omp_get_wtime();
timeM += endM - startM;
timeMUseful += timeEndMUseful - startM;
timeMCenter += timeEndMCenter - timeEndMUseful;
timeMSVD += timeEndMSVD - timeEndMCenter;
timeMParameters += timeEndMParameters - timeEndMSVD;
timeMUpdate += endM - timeEndMParameters;
}


Expand Down

0 comments on commit ef64545

Please sign in to comment.