Java Code Examples for org.scijava.vecmath.Point3f#set()

The following examples show how to use org.scijava.vecmath.Point3f#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCCube.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * computes the interpolated point along a specified whose
 * intensity equals the reference value
 * @param v1 first extremity of the edge
 * @param v2 second extremity of the edge
 * @param result stores the resulting edge
 * return the point on the edge where intensity equals the isovalue;
 * @return false if the interpolated point is beyond edge boundaries
 */
private boolean computeEdge(final Point3f v1, final int i1,
			    final Point3f v2, final int i2,
			    final Point3f result, final Carrier car) {

	// 30 --- 50 --- 70 : t=0.5
	// 70 --- 50 --- 30 : t=0.5
	///int i1 = car.intensity(v1);
	///int i2 = car.intensity(v2);
	if(i2 < i1)
		return computeEdge(v2, i2, v1, i1, result, car);

	final float t = (car.threshold - i1) / (float) (i2 - i1);
	if (t >= 0 && t <= 1) {
		// v1 + t*(v2-v1)
		result.set(v2);
		result.sub(v1);
		result.scale(t);
		result.add(v1);
		return true;
	}
	result.set(-1, -1, -1);
	return false;
}
 
Example 2
Source File: M.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/** Returns a "3D Viewer"-ready list mesh, centered at 0,0,0 and with radius as the radius of the enclosing sphere. */
static public final List<Point3f> createIcosahedron(int subdivisions, final float radius) {
	List<Point3f> ps = new ArrayList<Point3f>();
	for (int i=0; i<icosfaces.length; i++) {
		for (int k=0; k<3; k++) {
			ps.add(new Point3f(icosahedron[icosfaces[i][k]]));
		}
	}
	while (subdivisions-- > 0) {
		final List<Point3f> sub = new ArrayList<Point3f>();
		// Take three consecutive points, which define a face, and create 4 faces out of them.
		for (int i=0; i<ps.size(); i+=3) {
			final Point3f p0 = ps.get(i);
			final Point3f p1 = ps.get(i+1);
			final Point3f p2 = ps.get(i+2);

			final Point3f p01 = new Point3f((p0.x + p1.x)/2, (p0.y + p1.y)/2, (p0.z + p1.z)/2);
			final Point3f p02 = new Point3f((p0.x + p2.x)/2, (p0.y + p2.y)/2, (p0.z + p2.z)/2);
			final Point3f p12 = new Point3f((p1.x + p2.x)/2, (p1.y + p2.y)/2, (p1.z + p2.z)/2);
			// lower left:
			sub.add(p0);
			sub.add(p01);
			sub.add(p02);
			// upper:
			sub.add(new Point3f(p01)); // as copies
			sub.add(p1);
			sub.add(p12);
			// lower right:
			sub.add(new Point3f(p12));
			sub.add(p2);
			sub.add(new Point3f(p02));
			// center:
			sub.add(new Point3f(p01));
			sub.add(new Point3f(p12));
			sub.add(new Point3f(p02));
		}
		ps = sub;
	}

	// Project all vertices to the surface of a sphere of radius 1
	final Vector3f v = new Vector3f();
	for (final Point3f p : ps) {
		v.set(p);
		v.normalize();
		v.scale(radius);
		p.set(v);
	}

	return ps;
}