use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Mesh method getNormals.
// Compute face normals from full vertices list
private void getNormals() {
facesNormals = new ArrayList<Point3f>();
Point3f v1, v2, normal;
float n1, n2, n3, norm;
for (int i = 0; i < vertices.size(); i += 3) {
// 2 vectors
v1 = new Point3f(vertices.get(i + 1).x - vertices.get(i).x, vertices.get(i + 1).y - vertices.get(i).y, vertices.get(i + 1).z - vertices.get(i).z);
v2 = new Point3f(vertices.get(i + 2).x - vertices.get(i + 1).x, vertices.get(i + 2).y - vertices.get(i + 1).y, vertices.get(i + 2).z - vertices.get(i + 1).z);
// normal
n1 = (v1.y * v2.z) - (v1.z * v2.y);
n2 = (v1.z * v2.x) - (v1.x * v2.z);
n3 = (v1.x * v2.y) - (v1.y * v2.x);
// normalization
norm = (float) Math.sqrt((n1 * n1) + (n2 * n2) + (n3 * n3));
n1 = n1 / norm;
n2 = n2 / norm;
n3 = n3 / norm;
normal = new Point3f(n1, n2, n3);
// System.out.println(normal.toString());
facesNormals.add(normal);
}
// System.out.println("triangles.size: " + facesNormals.size());
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Mesh method computeMedian.
public Point3f computeMedian(List<Point3f> uV) {
int n = uV.size();
List<Float> x = new ArrayList<Float>();
List<Float> y = new ArrayList<Float>();
List<Float> z = new ArrayList<Float>();
for (int i = 0; i < n; i++) {
x.add(uV.get(i).x);
y.add(uV.get(i).y);
z.add(uV.get(i).z);
}
Collections.sort(x);
Collections.sort(y);
Collections.sort(z);
int n2 = (int) Math.floor(n / 2);
Point3f center = new Point3f(x.get(n2), y.get(n2), z.get(n2));
return center;
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Mesh method triangleBBox.
public ArrayList<Point3f> triangleBBox(Triangle t) {
ArrayList<Point3f> bBox = new ArrayList<Point3f>(2);
ArrayList<Integer> vts = t.getVertices();
float xm, ym, zm, xM, yM, zM;
xm = xM = vertexList.get(vts.get(0)).getPosition().x;
ym = yM = vertexList.get(vts.get(0)).getPosition().y;
zm = zM = vertexList.get(vts.get(0)).getPosition().z;
Point3f p;
for (int i = 1; i < vts.size(); i++) {
p = vertexList.get(vts.get(i)).getPosition();
if (xm > p.x) {
xm = p.x;
}
if (ym > p.y) {
ym = p.y;
}
if (zm > p.z) {
zm = p.z;
}
if (xM < p.x) {
xM = p.x;
}
if (yM < p.y) {
yM = p.y;
}
if (zM < p.z) {
zM = p.z;
}
}
p = new Point3f(xm - 0.1f, ym - 0.1f, zm - 0.1f);
bBox.add(p);
p = new Point3f(xM + 0.1f, yM + 0.1f, zM + 0.1f);
bBox.add(p);
return bBox;
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Mesh method computeBBox.
public ArrayList<Point3f> computeBBox(ArrayList<Point3f> uV) {
ArrayList<Point3f> bBox = new ArrayList<Point3f>(2);
float xm, ym, zm, xM, yM, zM;
xm = xM = uV.get(0).x;
ym = yM = uV.get(0).y;
zm = zM = uV.get(0).z;
Point3f p;
for (int i = 1; i < uV.size(); i++) {
p = uV.get(i);
if (xm > p.x) {
xm = p.x;
}
if (ym > p.y) {
ym = p.y;
}
if (zm > p.z) {
zm = p.z;
}
if (xM < p.x) {
xM = p.x;
}
if (yM < p.y) {
yM = p.y;
}
if (zM < p.z) {
zM = p.z;
}
}
p = new Point3f(xm - 1.0f, ym - 1.0f, zm - 1.0f);
bBox.add(p);
p = new Point3f(xM + 1.0f, yM + 1.0f, zM + 1.0f);
bBox.add(p);
return bBox;
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Mesh method computeVerticesNormals.
// Compute vertices normals by interpolation of faces normals
// Need
public void computeVerticesNormals(List<Integer> indices) {
getNormals();
verticesNormals = new ArrayList<Point3f>();
for (int i = 0; i < unique_vertices.size(); i++) {
float x, y, z;
int triangleIndex;
int cpt = 0;
Point3f P;
x = y = z = 0.f;
for (int j = 0; j < indices.size(); j++) {
if (indices.get(j) == i) {
triangleIndex = (j) / 3;
if (!Float.isNaN(facesNormals.get(triangleIndex).x)) {
x += facesNormals.get(triangleIndex).x;
y += facesNormals.get(triangleIndex).y;
z += facesNormals.get(triangleIndex).z;
// System.out.println("tI: "+triangleIndex);
cpt++;
}
}
}
P = new Point3f(x / (float) cpt, y / (float) cpt, z / (float) cpt);
verticesNormals.add(P);
}
}
Aggregations