use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class MeshEditor method smooth.
/**
* If the Content instance wraps a mesh, smooth it by the
* fraction K (0, 1).
* @param orig
* @param K
* @return
*/
public static List smooth(final List orig, final float K) {
// final List triangles = c.getMesh();
List triangles = new ArrayList();
triangles.addAll(orig);
if (0 != triangles.size() % 3) {
System.out.println("MeshEditor.smooth: need a list of points multiple of 3.");
return null;
}
// for each unique point, find which other points are linked by one edge to it.
// In the triangles List, there are only points, but each sequence of 3 points makes a triangle.
final HashMap ht = new HashMap();
for (int i = 0; i < triangles.size(); i += 3) {
// process one triangle at a time
Point3f p1 = (Point3f) triangles.get(i);
Point3f p2 = (Point3f) triangles.get(i + 1);
Point3f p3 = (Point3f) triangles.get(i + 2);
build(p1, p2, p3, ht);
build(p2, p3, p1, ht);
build(p3, p1, p2, ht);
}
/* // shrinkage correction works, but generates undesirably unsmooth edges
for (Iterator it = ht.values().iterator(); it.hasNext(); ) {
PointGroup pg = (PointGroup)it.next();
pg.computeVector(K);
}
for (Iterator it = ht.values().iterator(); it.hasNext(); ) {
PointGroup pg = (PointGroup)it.next();
pg.applyVector(ht);
}
*/
for (Iterator it = ht.values().iterator(); it.hasNext(); ) {
PointGroup pg = (PointGroup) it.next();
pg.smoothMembers(K);
}
return triangles;
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Object3DSurface method getNormalVertex.
public Point3f getNormalVertex(int idx) {
if (vertices_faces_index == null) {
computeUniqueVertices();
}
List<Integer> list = vertices_faces_index.get(idx);
Point3f N = new Point3f();
for (int i : list) {
N.add(getNormalFace(i));
}
float le = N.distance(new Point3f());
N.scale(1.0f / le);
return N;
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Object3DSurface method drawFacesCurvature.
public Content drawFacesCurvature(Image3DUniverse univ, double[] cur, String name, boolean useCalibration) {
List<Point3f> face = new ArrayList();
double min = cur[0];
double max = cur[0];
for (double d : cur) {
if (d < min) {
min = d;
}
if (d > max) {
max = d;
}
}
for (int i = 0; i < faces.size(); i += 3) {
Point3D P1 = new Point3D(faces.get(i));
if (!useCalibration) {
P1.scale(1.0 / resXY, 1.0 / resXY, 1.0 / resZ);
}
face.add(P1.getPoint3f());
P1 = new Point3D(faces.get(i + 1));
if (!useCalibration) {
P1.scale(1.0 / resXY, 1.0 / resXY, 1.0 / resZ);
}
face.add(P1.getPoint3f());
P1 = new Point3D(faces.get(i + 2));
if (!useCalibration) {
P1.scale(1.0 / resXY, 1.0 / resXY, 1.0 / resZ);
}
face.add(P1.getPoint3f());
Color3f col = new Color3f((float) ((cur[i] - min) / (max - min)), (float) ((cur[i] - min) / (max - min)), 0);
univ.addTriangleMesh(face, col, name + "_" + i);
}
return univ.getContent(name);
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Object3DSurface method computeBounding.
@Override
protected void computeBounding() {
xmin = Integer.MAX_VALUE;
xmax = 0;
ymin = Integer.MAX_VALUE;
ymax = 0;
zmin = Integer.MAX_VALUE;
zmax = 0;
Point3f vox;
for (Point3f vertice : vertices) {
vox = vertice;
if (vox.x < xmin) {
xmin = (int) vox.x;
}
if (vox.x > xmax) {
xmax = (int) vox.x;
}
if (vox.y < ymin) {
ymin = (int) vox.y;
}
if (vox.y > ymax) {
ymax = (int) vox.y;
}
if (vox.z < zmin) {
zmin = (int) vox.z;
}
if (vox.z > zmax) {
zmax = (int) vox.z;
}
}
}
use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.
the class Object3DSurface method scale.
public void scale(double scale) {
Point3D center = this.getCenterAsVector();
for (int i = 0; i < faces.size(); i++) {
Point3f P = this.getVertex(i);
// Point3D P0 = new Vector3D(P);
Point3D P0 = new Point3D(P);
Vector3D V0 = new Vector3D(center, P0);
Vector3D V1 = V0.multiply(scale);
Point3D P1 = new Vector3D(center);
P1.translate(V1);
P.set(P1.getPoint3f());
}
init();
// this.computeUniqueVertices();
}
Aggregations