Skip to content

Commit 6ba6a2f

Browse files
committed
Add ability to load ParticleShapeStatistics from ShapeWorks Project via python
1 parent 114e6b0 commit 6ba6a2f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Libs/Particles/ParticleShapeStatistics.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ int ParticleShapeStatistics::read_point_files(const std::string& s) {
476476
}
477477

478478
//---------------------------------------------------------------------------
479-
ParticleShapeStatistics::ParticleShapeStatistics(std::shared_ptr<Project> project) {
479+
ParticleShapeStatistics::ParticleShapeStatistics(std::shared_ptr<Project> project) { load_from_project(project); }
480+
481+
//---------------------------------------------------------------------------
482+
void ParticleShapeStatistics::load_from_project(std::shared_ptr<Project> project) {
480483
std::vector<Eigen::VectorXd> points;
481484
std::vector<int> groups;
482485
for (auto& s : project->get_subjects()) {
@@ -566,6 +569,13 @@ int ParticleShapeStatistics::do_pca(ParticleSystemEvaluation ParticleSystemEvalu
566569
return do_pca(particlePoints, domainsPerShape);
567570
}
568571

572+
//---------------------------------------------------------------------------
573+
int ParticleShapeStatistics::do_pca(std::shared_ptr<Project> project) {
574+
load_from_project(project);
575+
compute_modes();
576+
return 0;
577+
}
578+
569579
//---------------------------------------------------------------------------
570580
int ParticleShapeStatistics::compute_modes() {
571581
SW_DEBUG("computing PCA modes");

Libs/Particles/ParticleShapeStatistics.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class Project;
1919
class ParticleShapeStatistics {
2020
public:
2121
ParticleShapeStatistics(){};
22-
ParticleShapeStatistics(std::shared_ptr<Project> project);
22+
explicit ParticleShapeStatistics(std::shared_ptr<Project> project);
2323
~ParticleShapeStatistics(){};
2424

2525
int do_pca(std::vector<std::vector<Point>> global_pts, int domainsPerShape = 1);
2626

2727
int do_pca(ParticleSystemEvaluation particleSystem, int domainsPerShape = 1);
2828

29+
int do_pca(std::shared_ptr<Project> project);
30+
2931
//! Loads a set of point files and pre-computes some statistics.
3032
int import_points(std::vector<Eigen::VectorXd> points, std::vector<int> group_ids);
3133

@@ -138,6 +140,8 @@ class ParticleShapeStatistics {
138140
//! Set the meshes for each sample (used for some evaluation metrics)
139141
void set_meshes(const std::vector<Mesh>& meshes) { meshes_ = meshes; }
140142

143+
void load_from_project(std::shared_ptr<Project> project);
144+
141145
private:
142146
unsigned int num_samples_group1_;
143147
unsigned int num_samples_group2_;

Libs/Python/ShapeworksPython.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,14 @@ PYBIND11_MODULE(shapeworks_py, m) {
12811281

12821282
.def(py::init<>())
12831283

1284+
// int do_pca(ParticleSystemEvaluation particleSystem, int domainsPerShape = 1);
12841285
.def("PCA", py::overload_cast<ParticleSystemEvaluation, int>(&ParticleShapeStatistics::do_pca),
12851286
"calculates the eigen values and eigen vectors of the data", "particleSystem"_a, "domainsPerShape"_a = 1)
12861287

1288+
// int do_pca(std::shared_ptr<Project> project);
1289+
.def("PCA", py::overload_cast<std::shared_ptr<Project>>(&ParticleShapeStatistics::do_pca),
1290+
"calculates the eigen values and eigen vectors of the data from a project", "project"_a)
1291+
12871292
.def("principalComponentProjections", &ParticleShapeStatistics::principal_component_projections,
12881293
"projects the original data on the calculated principal components")
12891294

0 commit comments

Comments
 (0)