Skip to content

Commit c443a08

Browse files
committed
PCAnalyzer: Allow vertices as input
1 parent 98abe57 commit c443a08

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/main/java/sc/fiji/snt/analysis/PCAnalyzer.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
package sc.fiji.snt.analysis;
2424

25+
import net.imagej.mesh.Vertex;
26+
import net.imagej.mesh.Vertices;
2527
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
2628
import org.apache.commons.math3.linear.EigenDecomposition;
2729
import org.apache.commons.math3.linear.RealMatrix;
@@ -33,6 +35,7 @@
3335

3436
import java.util.ArrayList;
3537
import java.util.Collection;
38+
import java.util.Iterator;
3639
import java.util.List;
3740

3841
/**
@@ -95,6 +98,21 @@ public static PrincipalAxis[] getPrincipalAxes(final Path path) {
9598
return getPrincipalAxes(path.getNodes());
9699
}
97100

101+
/**
102+
* Computes the principal axes from the vertices of a mesh
103+
*
104+
* @param vertices the collection of vertices to analyze
105+
* @return array of three PrincipalAxis objects ordered by decreasing variance
106+
* (primary, secondary, tertiary), or null if computation fails
107+
*/
108+
public static PrincipalAxis[] getPrincipalAxes(final Vertices vertices) {
109+
final List<SNTPoint> points = new ArrayList<>((int)vertices.size());
110+
for (final Vertex vertex : vertices) {
111+
points.add(SNTPoint.of(vertex.x(), vertex.y(), vertex.z()));
112+
}
113+
return getPrincipalAxes(points);
114+
}
115+
98116
/**
99117
* Computes the principal axes for a collection of SNTPoints.
100118
*

0 commit comments

Comments
 (0)