Skip to content

Commit 94cab3e

Browse files
committed
Add TIME_SCOPE profiling instrumentation across groom, mesh, image, analysis, and CLI pipelines
1 parent dac1415 commit 94cab3e

11 files changed

Lines changed: 53 additions & 0 deletions

File tree

Applications/shapeworks/Command.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Command.h"
2+
#include <Profiling.h>
23
#include <sstream>
34

45
namespace shapeworks {
@@ -22,6 +23,7 @@ std::vector<std::string> Command::parse_args(const std::vector<std::string> &arg
2223
///////////////////////////////////////////////////////////////////////////////
2324
int Command::run(SharedCommandData &sharedData)
2425
{
26+
TIME_SCOPE(QString::fromStdString(name()));
2527
const optparse::Values &options = parser.get_parsed_options();
2628

2729
return this->execute(options, sharedData) ? EXIT_SUCCESS : EXIT_FAILURE;

Libs/Alignment/Procrustes3D.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Procrustes3D.h"
22

3+
#include <Profiling.h>
34
#include <vnl/algo/vnl_svd.h>
45

56
#include <iostream>
@@ -44,6 +45,7 @@ void Procrustes3D::RemoveTranslation(SimilarityTransformListType& transforms, Sh
4445

4546
//---------------------------------------------------------------------------
4647
void Procrustes3D::AlignShapes(SimilarityTransformListType& transforms, ShapeListType& shapes) {
48+
TIME_SCOPE("Procrustes3D::AlignShapes");
4749
const RealType SOS_EPSILON = 1.0e-8;
4850

4951
PointType center;

Libs/Analyze/Analyze.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <Groom/GroomParameters.h>
44
#include <Logging.h>
5+
#include <Profiling.h>
56
#include <MeshWarper.h>
67
#include <Particles/ParticleNormalEvaluation.h>
78
#include <StringUtils.h>
@@ -167,6 +168,7 @@ Analyze::Analyze(ProjectHandle project) : project_(project), mesh_manager_(new M
167168

168169
//---------------------------------------------------------------------------
169170
void Analyze::run_offline_analysis(std::string outfile, float range, float steps) {
171+
TIME_SCOPE("Analyze::run_offline_analysis");
170172
SW_LOG("ShapeWorks Offline Analysis");
171173
if (!project_->get_particles_present()) {
172174
throw std::runtime_error("Project has not been optimized, please run optimize first");
@@ -478,6 +480,7 @@ bool Analyze::update_shapes() {
478480

479481
//---------------------------------------------------------------------------
480482
bool Analyze::compute_stats() {
483+
TIME_SCOPE("Analyze::compute_stats");
481484
if (stats_ready_) {
482485
return true;
483486
}

Libs/Analyze/Reconstruction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "itkNrrdImageIOFactory.h"
2424
#include "itkMetaImageIOFactory.h"
2525
#include "Reconstruction.h"
26+
#include <Profiling.h>
2627

2728
#include <vtkLoopSubdivisionFilter.h>
2829
#include <vtkButterflySubdivisionFilter.h>
@@ -67,6 +68,7 @@ vtkSmartPointer<vtkPolyData> Reconstruction<TTransformType,TInterpolatorType, TC
6768
std::vector< PointArrayType > local_pts,
6869
std::vector< PointArrayType > global_pts,
6970
std::vector<std::string> distance_transform) {
71+
TIME_SCOPE("Reconstruction::getDenseMean");
7072
if (!this->denseDone_ || !local_pts.empty() ||
7173
!distance_transform.empty() || !global_pts.empty()) {
7274
this->denseDone_ = false;
@@ -439,6 +441,7 @@ void Reconstruction<TTransformType,TInterpolatorType, TCoordRep, PixelType, Imag
439441
std::vector< PointArrayType > local_pts,
440442
std::vector< PointArrayType > global_pts,
441443
std::vector<std::string> distance_transform) {
444+
TIME_SCOPE("Reconstruction::computeDenseMean");
442445
try {
443446
//turn the sets of global points to one sparse global mean.
444447
float init[] = { 0.f,0.f,0.f };

Libs/Groom/Groom.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <GroomParameters.h>
33
#include <Image/Image.h>
44
#include <Logging.h>
5+
#include <Profiling.h>
56
#include <Mesh/Mesh.h>
67
#include <Mesh/MeshUtils.h>
78
#include <Optimize/Constraints/Constraints.h>
@@ -32,6 +33,7 @@ Groom::Groom(ProjectHandle project) : project_{project} {}
3233

3334
//---------------------------------------------------------------------------
3435
bool Groom::run() {
36+
TIME_SCOPE("Groom::run");
3537
ShapeWorksUtils::setup_threads();
3638

3739
used_names_.clear();
@@ -124,6 +126,7 @@ bool Groom::run() {
124126

125127
//---------------------------------------------------------------------------
126128
bool Groom::image_pipeline(std::shared_ptr<Subject> subject, size_t domain) {
129+
TIME_SCOPE("Groom::image_pipeline");
127130
// grab parameters
128131
auto params = GroomParameters(project_, project_->get_domain_names()[domain]);
129132

@@ -321,6 +324,7 @@ bool Groom::run_image_pipeline(Image& image, GroomParameters params) {
321324

322325
//---------------------------------------------------------------------------
323326
bool Groom::mesh_pipeline(std::shared_ptr<Subject> subject, size_t domain) {
327+
TIME_SCOPE("Groom::mesh_pipeline");
324328
// grab parameters
325329
auto params = GroomParameters(project_, project_->get_domain_names()[domain]);
326330

@@ -557,6 +561,7 @@ bool Groom::get_aborted() { return abort_; }
557561

558562
//---------------------------------------------------------------------------
559563
bool Groom::run_alignment() {
564+
TIME_SCOPE("Groom::run_alignment");
560565
size_t num_domains = project_->get_number_of_domains_per_subject();
561566
SW_DEBUG("Running alignment, number of domains = {}", num_domains);
562567
auto subjects = project_->get_subjects();

Libs/Image/Image.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Image.h"
22

33
#include <Logging.h>
4+
#include <Profiling.h>
45
#include <itkAntiAliasBinaryImageFilter.h>
56
#include <itkBinaryFillholeImageFilter.h>
67
#include <itkBinaryThresholdImageFilter.h>
@@ -104,6 +105,7 @@ Image& Image::operator=(Image&& img) {
104105
}
105106

106107
Image::ImageType::Pointer Image::read(const std::string& pathname) {
108+
TIME_SCOPE("Image::read");
107109
ImageUtils::register_itk_factories();
108110

109111
if (pathname.empty()) {
@@ -327,6 +329,7 @@ Image::ImageType::Pointer Image::readDICOMImage(const std::string& pathname) {
327329
}
328330

329331
Image& Image::write(const std::string& filename, bool compressed) {
332+
TIME_SCOPE("Image::write");
330333
if (!this->itk_image_) {
331334
throw std::invalid_argument("Image invalid");
332335
}
@@ -351,6 +354,7 @@ Image& Image::write(const std::string& filename, bool compressed) {
351354
}
352355

353356
Image& Image::antialias(unsigned iterations, double maxRMSErr, int layers) {
357+
TIME_SCOPE("Image::antialias");
354358
if (layers < 0) {
355359
throw std::invalid_argument("layers must be >= 0");
356360
}
@@ -405,6 +409,7 @@ Image& Image::resample(const TransformPtr transform, const Point3 origin, Dims d
405409
}
406410

407411
Image& Image::resample(const Vector3& spacing, Image::InterpolationType interp) {
412+
TIME_SCOPE("Image::resample");
408413
// compute logical dimensions that keep all image data for this spacing
409414
Dims inputDims(this->dims());
410415
Vector3 inputSpacing(this->spacing());
@@ -518,6 +523,7 @@ Image& Image::pad(IndexRegion& region, PixelType value) {
518523
}
519524

520525
Image& Image::pad(Dims lowerExtendRegion, Dims upperExtendRegion, PixelType value) {
526+
TIME_SCOPE("Image::pad");
521527
using FilterType = itk::ConstantPadImageFilter<ImageType, ImageType>;
522528
FilterType::Pointer filter = FilterType::New();
523529

@@ -632,6 +638,7 @@ Image& Image::binarize(PixelType minVal, PixelType maxVal, PixelType innerVal, P
632638
}
633639

634640
Image& Image::computeDT(PixelType isoValue) {
641+
TIME_SCOPE("Image::computeDT");
635642
using FilterType = itk::ReinitializeLevelSetImageFilter<ImageType>;
636643
FilterType::Pointer filter = FilterType::New();
637644

@@ -732,6 +739,7 @@ Image& Image::applyIntensityFilter(double minVal, double maxVal) {
732739
}
733740

734741
Image& Image::gaussianBlur(double sigma) {
742+
TIME_SCOPE("Image::gaussianBlur");
735743
using BlurType = itk::DiscreteGaussianImageFilter<ImageType, ImageType>;
736744
BlurType::Pointer blur = BlurType::New();
737745

@@ -744,6 +752,7 @@ Image& Image::gaussianBlur(double sigma) {
744752
}
745753

746754
Image& Image::crop(PhysicalRegion region, const int padding) {
755+
TIME_SCOPE("Image::crop");
747756
region.shrink(physicalBoundingBox()); // clip region to fit inside image
748757
if (!region.valid()) {
749758
throw std::invalid_argument("Invalid region specified (it may lie outside physical bounds of image).");
@@ -862,6 +871,7 @@ Image& Image::setCoordsys(ImageType::DirectionType coordsys) {
862871
}
863872

864873
Image& Image::isolate() {
874+
TIME_SCOPE("Image::isolate");
865875
typedef itk::Image<unsigned char, 3> IsolateType;
866876
typedef itk::CastImageFilter<ImageType, IsolateType> ToIntType;
867877
ToIntType::Pointer filter = ToIntType::New();

Libs/Mesh/Mesh.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "Image.h"
6464
#include "Libs/Optimize/Domain/Surface.h"
6565
#include "Logging.h"
66+
#include "Profiling.h"
6667
#include "MeshComputeThickness.h"
6768
#include "MeshUtils.h"
6869
#include "PreviewMeshQC/FEAreaCoverage.h"
@@ -273,6 +274,7 @@ Mesh& Mesh::coverage(const Mesh& otherMesh, bool allowBackIntersections, double
273274
}
274275

275276
Mesh& Mesh::smooth(int iterations, double relaxation) {
277+
TIME_SCOPE("Mesh::smooth");
276278
auto smoother = vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
277279

278280
smoother->SetInputData(this->poly_data_);
@@ -293,6 +295,7 @@ Mesh& Mesh::smooth(int iterations, double relaxation) {
293295
}
294296

295297
Mesh& Mesh::smoothSinc(int iterations, double passband) {
298+
TIME_SCOPE("Mesh::smoothSinc");
296299
auto smoother = vtkSmartPointer<vtkWindowedSincPolyDataFilter>::New();
297300
smoother->SetInputData(this->poly_data_);
298301
// minimum of 2. See docs of vtkWindowedSincPolyDataFilter for explanation
@@ -316,6 +319,7 @@ Mesh& Mesh::smoothSinc(int iterations, double passband) {
316319
}
317320

318321
Mesh& Mesh::remesh(int numVertices, double adaptivity) {
322+
TIME_SCOPE("Mesh::remesh");
319323
// ACVD is very noisy to std::cout, even with console output set to zero
320324
// setting the failbit on std::cout will silence this until it's cleared below
321325
// std::cout.setstate(std::ios_base::failbit);
@@ -385,6 +389,7 @@ Mesh& Mesh::reflect(const Axis& axis, const Vector3& origin) {
385389
}
386390

387391
MeshTransform Mesh::createTransform(const Mesh& target, Mesh::AlignmentType align, unsigned iterations) {
392+
TIME_SCOPE("Mesh::createTransform");
388393
return createRegistrationTransform(target, align, iterations);
389394
}
390395

@@ -413,6 +418,7 @@ Mesh& Mesh::rotate(const double angle, const Axis axis) {
413418
}
414419

415420
Mesh& Mesh::fillHoles(double hole_size) {
421+
TIME_SCOPE("Mesh::fillHoles");
416422
auto filter = vtkSmartPointer<vtkFillHolesFilter>::New();
417423
filter->SetInputData(this->poly_data_);
418424
filter->SetHoleSize(hole_size);
@@ -430,6 +436,7 @@ Mesh& Mesh::fillHoles(double hole_size) {
430436
}
431437

432438
Mesh& Mesh::clean() {
439+
TIME_SCOPE("Mesh::clean");
433440
auto clean = vtkSmartPointer<vtkCleanPolyData>::New();
434441
clean->ConvertPolysToLinesOff();
435442
clean->ConvertLinesToPointsOff();
@@ -669,6 +676,7 @@ bool Mesh::detectTriangular() {
669676
}
670677

671678
std::vector<Field> Mesh::distance(const Mesh& target, const DistanceMethod method) const {
679+
TIME_SCOPE("Mesh::distance");
672680
if (target.numPoints() == 0 || numPoints() == 0) {
673681
throw std::invalid_argument("meshes must have points");
674682
}
@@ -832,6 +840,7 @@ bool Mesh::isPointInside(const Point3 point) const {
832840
}
833841

834842
double Mesh::geodesicDistance(int source, int target) const {
843+
TIME_SCOPE("Mesh::geodesicDistance");
835844
if (source < 0 || target < 0 || numPoints() < source || numPoints() < target) {
836845
throw std::invalid_argument("requested point ids outside range of points available in mesh");
837846
}
@@ -841,6 +850,7 @@ double Mesh::geodesicDistance(int source, int target) const {
841850
}
842851

843852
Field Mesh::geodesicDistance(const Point3 landmark) const {
853+
TIME_SCOPE("Mesh::geodesicDistance");
844854
auto distance = vtkSmartPointer<vtkDoubleArray>::New();
845855
distance->SetNumberOfComponents(1);
846856
distance->SetNumberOfTuples(numPoints());
@@ -856,6 +866,7 @@ Field Mesh::geodesicDistance(const Point3 landmark) const {
856866
}
857867

858868
Field Mesh::geodesicDistance(const std::vector<Point3> curve) const {
869+
TIME_SCOPE("Mesh::geodesicDistance");
859870
auto minDistance = vtkSmartPointer<vtkDoubleArray>::New();
860871
minDistance->SetNumberOfComponents(1);
861872
minDistance->SetNumberOfTuples(numPoints());
@@ -875,6 +886,7 @@ Field Mesh::geodesicDistance(const std::vector<Point3> curve) const {
875886
}
876887

877888
Field Mesh::curvature(const CurvatureType type) const {
889+
TIME_SCOPE("Mesh::curvature");
878890
Eigen::MatrixXd V = points();
879891
Eigen::MatrixXi F = faces();
880892

Libs/Particles/ShapeEvaluation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ShapeEvaluation.h"
22

33
#include <Logging.h>
4+
#include <Profiling.h>
45
#include <tbb/parallel_for.h>
56

67
#include <Eigen/Core>
@@ -34,6 +35,7 @@ double ShapeEvaluation::compute_compactness(const ParticleSystemEvaluation& part
3435
//---------------------------------------------------------------------------
3536
Eigen::VectorXd ShapeEvaluation::compute_full_compactness(const ParticleSystemEvaluation& particle_system,
3637
std::function<void(float)> progress_callback) {
38+
TIME_SCOPE("ShapeEvaluation::compute_full_compactness");
3739
const int n = particle_system.num_samples();
3840
const int d = particle_system.num_dims();
3941
const int num_modes = n - 1; // the number of modes is one less than the number of samples
@@ -64,6 +66,7 @@ Eigen::VectorXd ShapeEvaluation::compute_full_compactness(const ParticleSystemEv
6466
//---------------------------------------------------------------------------
6567
double ShapeEvaluation::compute_generalization(const ParticleSystemEvaluation& particle_system, const int num_modes,
6668
const std::string& save_to, bool surface_distance_mode) {
69+
TIME_SCOPE("ShapeEvaluation::compute_generalization");
6770
const long n = particle_system.num_samples();
6871
const long d = particle_system.num_dims();
6972
const Eigen::MatrixXd& p = particle_system.get_matrix();
@@ -155,6 +158,7 @@ Eigen::VectorXd ShapeEvaluation::compute_full_generalization(const ParticleSyste
155158
std::function<void(float)> progress_callback,
156159
std::function<bool()> check_abort,
157160
bool surface_distance_mode) {
161+
TIME_SCOPE("ShapeEvaluation::compute_full_generalization");
158162
const long n = particle_system.num_samples(); // number of samples
159163
const long d = particle_system.num_dims(); // number of dimensions (e.g. number of particles * 3)
160164
const Eigen::MatrixXd& p = particle_system.get_matrix();
@@ -224,6 +228,7 @@ Eigen::VectorXd ShapeEvaluation::compute_full_generalization(const ParticleSyste
224228
//---------------------------------------------------------------------------
225229
double ShapeEvaluation::compute_specificity(const ParticleSystemEvaluation& particle_system, const int num_modes,
226230
const std::string& save_to, bool surface_distance_mode) {
231+
TIME_SCOPE("ShapeEvaluation::compute_specificity");
227232
const long n = particle_system.num_samples();
228233
const long d = particle_system.num_dims();
229234
int num_values = particle_system.get_num_values_per_particle();
@@ -327,6 +332,7 @@ Eigen::VectorXd ShapeEvaluation::compute_full_specificity(const ParticleSystemEv
327332
std::function<void(float)> progress_callback,
328333
std::function<bool()> check_abort,
329334
bool surface_distance_mode) {
335+
TIME_SCOPE("ShapeEvaluation::compute_full_specificity");
330336
const long n = particle_system.num_samples();
331337
const long d = particle_system.num_dims();
332338
const int num_values = particle_system.get_num_values_per_particle();

Studio/Data/Session.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <JsonProjectReader.h>
3030
#include <JsonProjectWriter.h>
3131
#include <Logging.h>
32+
#include <Profiling.h>
3233
#include <MeshManager.h>
3334
#include <Project/Project.h>
3435
#include <Shape.h>
@@ -107,6 +108,7 @@ void Session::set_parent(QWidget* parent) { parent_ = parent; }
107108

108109
//---------------------------------------------------------------------------
109110
bool Session::save_project(QString filename) {
111+
TIME_SCOPE("Session::save_project");
110112
QProgressDialog progress("Saving Project...", "Abort", 0, 100, parent_);
111113
progress.setWindowModality(Qt::WindowModal);
112114
progress.setMinimumDuration(2000);
@@ -201,6 +203,7 @@ bool Session::save_project(QString filename) {
201203

202204
//---------------------------------------------------------------------------
203205
bool Session::load_project(QString filename) {
206+
TIME_SCOPE("Session::load_project");
204207
modified_ = false;
205208

206209

Studio/Data/ShapeWorksWorker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Data/ShapeWorksWorker.h>
33
#include <Groom/Groom.h>
44
#include <Logging.h>
5+
#include <Profiling.h>
56
#include <Optimize/Optimize.h>
67
#include <Optimize/OptimizeParameters.h>
78
#include <Shape.h>
@@ -31,6 +32,7 @@ void ShapeworksWorker::process() {
3132
switch (this->type_) {
3233
case ShapeworksWorker::GroomType:
3334
try {
35+
TIME_SCOPE("studio_groom");
3436
this->groom_->run();
3537
} catch (itk::ExceptionObject& ex) {
3638
SW_ERROR("{}", std::string("ITK Exception: ") + ex.GetDescription());
@@ -56,6 +58,7 @@ void ShapeworksWorker::process() {
5658
break;
5759
case ShapeworksWorker::OptimizeType:
5860
try {
61+
TIME_SCOPE("studio_optimize");
5962
SW_LOG("Loading data...");
6063
this->optimize_parameters_->set_up_optimize(this->optimize_.data());
6164
SW_LOG("Optimizing correspondence...");
@@ -90,6 +93,7 @@ void ShapeworksWorker::process() {
9093
break;
9194
case ShapeworksWorker::ReconstructType:
9295
try {
96+
TIME_SCOPE("studio_reconstruct");
9397
SW_LOG("Warping to mean space...");
9498
for (int i = 0; i < this->session_->get_domains_per_shape(); i++) {
9599
auto shapes = this->session_->get_shapes();

0 commit comments

Comments
 (0)