Skip to content

Commit

Permalink
Merge pull request #2023 from SCIInstitute/minor_issues
Browse files Browse the repository at this point in the history
Minor additions
  • Loading branch information
akenmorris committed Mar 22, 2023
2 parents f7a5020 + cb052e3 commit 91a2287
Show file tree
Hide file tree
Showing 8 changed files with 45,056 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Libs/Mesh/Mesh.cpp
Expand Up @@ -388,6 +388,19 @@ Mesh& Mesh::applyTransform(const MeshTransform transform) {
return *this;
}

Mesh& Mesh::rotate(const double angle, const Axis axis){

Vector rotation(makeVector({0, 0, 0}));
rotation[axis] = 1;
auto com = center();

MeshTransform transform = MeshTransform::New();
transform->Translate(com[0], com[1], com[2]);
transform->RotateWXYZ(angle,rotation[0], rotation[1], rotation[2]);
transform->Translate(-com[0], -com[1], -com[2]);
return applyTransform(transform);
}

Mesh& Mesh::fillHoles() {
auto filter = vtkSmartPointer<vtkFillHolesFilter>::New();
filter->SetInputData(this->poly_data_);
Expand Down
3 changes: 3 additions & 0 deletions Libs/Mesh/Mesh.h
Expand Up @@ -93,6 +93,9 @@ class Mesh {
/// applies the given transformation to the mesh
Mesh& applyTransform(const MeshTransform transform);

/// applies the given rotation to the given axis
Mesh& rotate(const double angle, const Axis axis);

/// finds holes in a mesh and closes them
Mesh& fillHoles();

Expand Down
8 changes: 8 additions & 0 deletions Libs/Python/ShapeworksPython.cpp
Expand Up @@ -1001,6 +1001,14 @@ PYBIND11_MODULE(shapeworks_py, m)
"applies the given transformation to the mesh",
"transform"_a, "imageTransform"_a=false)


.def("rotate",
[](Mesh& mesh, const double angle, const Axis axis) -> decltype(auto){
return mesh.rotate(angle, axis);
},
"rotate using axis by angle (in degrees)",
"angle"_a, "axis"_a)

.def("fillHoles",
&Mesh::fillHoles,
"finds holes in a mesh and closes them")
Expand Down
15 changes: 13 additions & 2 deletions Testing/PythonTests/rotate.py
Expand Up @@ -4,14 +4,25 @@

success = True

def rotateTest():
def rotateTest1():
img = Image(os.environ["DATA"] + "/la-bin-centered.nrrd")
img.rotate(0.7854, [1.0, 1.0, 1.0])

compareImg = Image(os.environ["DATA"] + "/rotate2.nrrd")

return img.compare(compareImg)

success &= utils.test(rotateTest)
success &= utils.test(rotateTest1)

def rotateTest2():
mesh = Mesh(os.environ["DATA"] + "/femur.ply")
mesh.rotate(90, Axis.Y)

compareMesh = Mesh(os.environ["DATA"] + "/rotated_mesh.ply")

return mesh == compareMesh

success &= utils.test(rotateTest2)


sys.exit(not success)
45,013 changes: 45,013 additions & 0 deletions Testing/data/rotated_mesh.ply

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/new/ssm-eval.md
Expand Up @@ -37,6 +37,7 @@ shapeworks readparticlesystem --name *.particles -- specificity --nmodes 1
```

## ShapeWorks Python tools

```python
# Read the particle files from a pre-trained shape model
particle_data = sw.ParticleSystem(<list of local point files>)
Expand All @@ -45,7 +46,7 @@ shapeworks.ShapeEvaluation.ComputeCompactness(particleSystem=particle_data, nMod
shapeworks.ShapeEvaluation.ComputeGeneralization(particleSystem=particle_data, nModes=1, saveTo=save_dir)
shapeworks.ShapeEvaluation.ComputeSpecificity(particleSystem=particle_data, nModes=1, saveTo=save_dir)
```

Details about the evaluation functions can be found [in the API Reference](http://sciinstitute.github.io/ShapeWorks/latest/api/Classes/classshapeworks_1_1ShapeEvaluation.html#function-shapeevaluation)

<p><video src="https://sci.utah.edu/~shapeworks/doc-resources/mp4s/eval_ShellDemo.mp4" autoplay muted loop controls style="width:100%"></p>

Expand Down
3 changes: 3 additions & 0 deletions docs/use-cases/stats-based/ellipsoid-evaluate.md
Expand Up @@ -48,6 +48,9 @@ allGeneralization = sw.ShapeEvaluation.ComputeFullGeneralization(particleSystem=
#Get specificity values for all modes
allSpecificity = sw.ShapeEvaluation.ComputeFullSpecificity(particleSystem=particle_data)
```

Details about the evaluation functions can be found [in the API Reference](http://sciinstitute.github.io/ShapeWorks/latest/api/Classes/classshapeworks_1_1ShapeEvaluation.html#function-shapeevaluation)

Generalization value of the 3rd mode - 0.09600121582319728

Generalization Best Reconstruction![Generalization Best Reconstruction](https://sci.utah.edu/~shapeworks/doc-resources/pngs/generalization_best_recon.png)
Expand Down
1 change: 1 addition & 0 deletions docs/use-cases/stats-based/ellipsoid-pca.md
Expand Up @@ -36,6 +36,7 @@ Using `shape_statistics` object, you can now extract the following entities:
* Dimension of each shape: `numDims()`
* Variance explained by each mode: `percentVarByMode()`

Details about shape statistics functions can be found [in the API Reference](http://sciinstitute.github.io/ShapeWorks/latest/api/Classes/classshapeworks_1_1ParticleShapeStatistics.html#function-particleshapestatistics)

When the use case is run, plots similar to those below will be generated.
![PCA Loading Violin Plot](https://sci.utah.edu/~shapeworks/doc-resources/pngs/pca_loadings_violin_plot.png)
Expand Down

0 comments on commit 91a2287

Please sign in to comment.