Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use non-normalized normals in Mesh centroid #655

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/main/java/net/imagej/ops/geom/CentroidMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public RealLocalizable calculate(final Mesh input) {
final long v0 = input.triangles().vertex0(i);
final long v1 = input.triangles().vertex1(i);
final long v2 = input.triangles().vertex2(i);
final double nx = input.triangles().nx(i);
final double ny = input.triangles().ny(i);
final double nz = input.triangles().nz(i);
final double v0x = input.vertices().x(v0);
final double v0y = input.vertices().y(v0);
final double v0z = input.vertices().z(v0);
Expand All @@ -82,6 +79,18 @@ public RealLocalizable calculate(final Mesh input) {
final double v2x = input.vertices().x(v2);
final double v2y = input.vertices().y(v2);
final double v2z = input.vertices().z(v2);

// Recompute (non-normalized) normals
final double ux = v1x - v0x;
final double uy = v1y - v0y;
final double uz = v1z - v0z;
final double vx = v2x - v0x;
final double vy = v2y - v0y;
final double vz = v2z - v0z;
final double nx = (uy * vz - uz * vy);
final double ny = -(ux * vz - uz * vx);
final double nz = (ux * vy - uy * vx);

c_x += (1 / 24d) * nx * (Math.pow((v0x + v1x), 2)
+ Math.pow((v1x + v2x), 2)
+ Math.pow((v2x + v0x), 2));
Expand All @@ -98,6 +107,6 @@ public RealLocalizable calculate(final Mesh input) {
c_y *= d;
c_z *= d;

return new RealPoint(-c_x, -c_y, -c_z);
return new RealPoint(c_x, c_y, c_z);
}
}
Loading