org.scijava.vecmath.Point3f Java Examples

The following examples show how to use org.scijava.vecmath.Point3f. 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: Path.java    From SNT with GNU General Public License v3.0 6 votes vote down vote up
public Content addDiscsTo3DViewer(final Image3DUniverse univ, final Color3f c, final ImagePlus colorImage) {
	if (!hasCircles())
		return null;

	final Color3f[] originalColors = Pipe.getPointColors(precise_x_positions, precise_y_positions,
			precise_z_positions, c, colorImage);

	final List<Color3f> meshColors = new ArrayList<>();

	final int edges = 8;
	final List<Point3f> allTriangles = new ArrayList<>(edges * points);
	for (int i = 0; i < points; ++i) {
		final List<Point3f> discMesh = customnode.MeshMaker.createDisc(precise_x_positions[i],
				precise_y_positions[i], precise_z_positions[i], tangents_x[i], tangents_y[i], tangents_z[i],
				radiuses[i], 8);
		final int pointsInDiscMesh = discMesh.size();
		for (int j = 0; j < pointsInDiscMesh; ++j)
			meshColors.add(originalColors[i]);
		allTriangles.addAll(discMesh);
	}
	return univ.addTriangleMesh(allTriangles, meshColors, univ.getSafeContentName("Discs for path " + getName()));
}
 
Example #2
Source File: Display3D.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public Content asContent(final Display3D d3d) {
	double[] wi = widths;
	if (null == widths) {
		wi = new double[vs.getPoints(0).length];
		Arrays.fill(wi, 2.0);
	} else if (widths.length != vs.length()) {
		Utils.log("ERROR: widths.length != VectorString3D.length()");
		return null;
	}
	float transp = 1 - alpha;
	if (transp < 0) transp = 0;
	if (transp > 1) transp = 1;
	if (1 == transp) {
		Utils.log("WARNING: adding a 3D object fully transparent.");
	}
	final List<Point3f> triangles = Pipe.generateTriangles(Pipe.makeTube(vs.getPoints(0), vs.getPoints(1), vs.getPoints(2), wi, 1, 12, null), d3d.scale);
	final Content ct = d3d.universe.createContent(new CustomTriangleMesh(triangles, new Color3f(color), 0), title);
	ct.setTransparency(transp);
	ct.setLocked(true);
	return ct;
}
 
Example #3
Source File: Pipe.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Accepts an arrays as that returned from methods generateJoints and makeTube: first dimension is the list of points, second dimension is the number of vertices defining the circular cross section of the tube, and third dimension is the x,y,z of each vertex. */
static public List<Point3f> generateTriangles(final double[][][] all_points, final double scale) {
	final int n = all_points.length;
	final int parallels = all_points[0].length -1;
	final List<Point3f> list = new ArrayList<Point3f>();
	for (int i=0; i<n-1; i++) { //minus one since last is made with previous
		for (int j=0; j<parallels; j++) { //there are 12+12 triangles for each joint //it's up to 12+1 because first point is repeated at the end
			// first triangle in the quad
			list.add(new Point3f((float)(all_points[i][j][0] * scale), (float)(all_points[i][j][1] * scale), (float)(all_points[i][j][2] * scale)));
			list.add(new Point3f((float)(all_points[i][j+1][0] * scale), (float)(all_points[i][j+1][1] * scale), (float)(all_points[i][j+1][2] * scale)));
			list.add(new Point3f((float)(all_points[i+1][j][0] * scale), (float)(all_points[i+1][j][1] * scale), (float)(all_points[i+1][j][2] * scale)));

			// second triangle in the quad
			list.add(new Point3f((float)(all_points[i+1][j][0] * scale), (float)(all_points[i+1][j][1] * scale), (float)(all_points[i+1][j][2] * scale)));
			list.add(new Point3f((float)(all_points[i][j+1][0] * scale), (float)(all_points[i][j+1][1] * scale), (float)(all_points[i][j+1][2] * scale)));
			list.add(new Point3f((float)(all_points[i+1][j+1][0] * scale), (float)(all_points[i+1][j+1][1] * scale), (float)(all_points[i+1][j+1][2] * scale)));
		}
	}
	return list;
}
 
Example #4
Source File: MCCube.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
private void getTriangles(final List<Point3f> list, final Carrier car){
	final int cn = caseNumber(car);
	boolean directTable = !(isAmbigous(cn));
	directTable = true;

	// address in the table
	int offset = directTable ? cn*15 : (255-cn)*15;
	for(int index = 0; index < 5; index++){
		// if there's a triangle
		if (faces[offset] != -1) {
			// pick up vertexes of the current triangle
			list.add(new Point3f(this.e[faces[offset+0]]));
			list.add(new Point3f(this.e[faces[offset+1]]));
			list.add(new Point3f(this.e[faces[offset+2]]));
		}
		offset += 3;
	}
}
 
Example #5
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 #6
Source File: Profile.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Make a mesh as a calibrated list of 3D triangles.*/
static private List<Point3f> makeTriangles(final Profile[] p, final double scale) {
	try {
		final VectorString2D[] sv = new VectorString2D[p.length];
		boolean closed = true; // dummy initialization
		final Calibration cal = p[0].getLayerSet().getCalibrationCopy();
		cal.pixelWidth *= scale;
		cal.pixelHeight *= scale;
		for (int i=0; i<p.length; i++) {
			if (0 == p[i].n_points) continue;
			if (0 == i) closed = p[i].closed;
			else if (p[i].closed != closed) {
				Utils.log2("All profiles should be either open or closed, not mixed.");
				return null;
			}
			sv[i] = p[i].getPerimeter2D(cal);
		}
		return SkinMaker.generateTriangles(sv, -1, -1, closed);
	} catch (final Exception e) {
		IJError.print(e);
	}
	return null;
}
 
Example #7
Source File: AreaTree.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public MeshData generateMesh(final double scale, final int resample) {
	final HashMap<Layer,Area> areas = new HashMap<Layer,Area>();
	synchronized (node_layer_map) {
		for (final Map.Entry<Layer,Set<Node<Area>>> e : node_layer_map.entrySet()) {
			final Area a = new Area();
			for (final AreaNode nd : (Collection<AreaNode>) (Collection) e.getValue()) {
				if (null != nd.aw) a.add(nd.aw.getArea());
			}
			areas.put(e.getKey(), a);
		}
	}
	final List<Point3f> ps = AreaUtils.generateTriangles(this, scale, resample, areas);

	final List<Color3f> colors = new ArrayList<Color3f>();
	// Determine colors by proximity to a node, since there isn't any other way.
	// TODO
	Utils.log("WARNING: AreaTree multicolor 3D mesh is not yet implemented.");
	final Color3f cf = new Color3f(color);
	for (int i=0; i<ps.size(); i++) colors.add(cf);

	return new MeshData(ps, colors);
}
 
Example #8
Source File: AreaUtils.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param list The original points
 * @param output The accumulated list of modified points to construct a mesh from
 * @param verts The array of vertices, each index is filled if the point has been processed already.
 * @param la_Z The Layer to process points for.
 * @param la_thickness the thickness of that layer
 * @param layer_index The stack slice index corresponding to the Layer @param la.
 */
static private final void fix3DPoints(final List<Point3f> list, final TreeMap<Integer,Point3f> output, final Point3f[] verts, final double la_z, final double la_thickness, final int layer_index, final float dx, final float dy, final float rsw, final float rsh, final double sz, final int n_slices) {
	int fixed = 0;
	// Find all pixels that belong to the layer, and transform them back:
	for (int i=0; i<verts.length; i++) {
		if (null != verts[i]) continue; // already processed! The unprocessed Z is merely coincident with a processed Z.
		final Point3f p = list.get(i);
		final int pz = (int)(p.z + 0.05f);
		//final int pz = (int)(p.z + (0.5f * Math.signum(p.z)));
		if ( pz >= layer_index && pz < layer_index + n_slices) {
			// correct pixel position:
			// -- The 'rsw','rsh' scales back to LayerSet coords
			// -- The 'dx','dy' translates back to this AreaList bounding box
			p.x = p.x * rsw + dx;
			p.y = p.y * rsh + dy;

			// The Z is more complicated: the Z of the layer, scaled relative to the layer thickness
			p.z = (float)((la_z + la_thickness * (p.z - layer_index)) * sz); // using pixelWidth, not pixelDepth!

			verts[i] = p;
			output.put(i, p);
			fixed++;
		}
	}
	//Utils.log("fix between " + layer_index + " and " + (layer_index + n_slices) + " (" + fixed + ")");
}
 
Example #9
Source File: Display3D.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Creates a calibrated sphere to represent a point at LayerSet pixel coordinates wx, wy, wz, with radius wr.*/
public List<Point3f> createFatPoint(final double wx, final double wy, final double wz, final double wr, final Calibration cal) {
	final double[][][] globe = Ball.generateGlobe(12, 12);
	final int sign = cal.pixelDepth < 0 ? -1 : 1;
	for (int z=0; z<globe.length; z++) {
		for (int k=0; k<globe[0].length; k++) {
			globe[z][k][0] = (globe[z][k][0] * wr + wx) * scale * cal.pixelWidth;
			globe[z][k][1] = (globe[z][k][1] * wr + wy) * scale * cal.pixelHeight;
			globe[z][k][2] = (globe[z][k][2] * wr + wz) * scale * cal.pixelWidth * sign; // not pixelDepth, see day notes 20080227. Because pixelDepth is in microns/px, not in px/microns, and the z coord here is taken from the z of the layer, which is in pixels.
		}
	}
	final ArrayList<Point3f> list = new ArrayList<Point3f>();
	// create triangular faces and add them to the list
	for (int z=0; z<globe.length-1; z++) { // the parallels
		for (int k=0; k<globe[0].length -1; k++) { // meridian points
			// half quadrant (a triangle)
			list.add(new Point3f((float)globe[z][k][0], (float)globe[z][k][1], (float)globe[z][k][2]));
			list.add(new Point3f((float)globe[z+1][k+1][0], (float)globe[z+1][k+1][1], (float)globe[z+1][k+1][2]));
			list.add(new Point3f((float)globe[z+1][k][0], (float)globe[z+1][k][1], (float)globe[z+1][k][2]));
			// the other half quadrant
			list.add(new Point3f((float)globe[z][k][0], (float)globe[z][k][1], (float)globe[z][k][2]));
			list.add(new Point3f((float)globe[z][k+1][0], (float)globe[z][k+1][1], (float)globe[z][k+1][2]));
			list.add(new Point3f((float)globe[z+1][k+1][0], (float)globe[z+1][k+1][1], (float)globe[z+1][k+1][2]));
		}
	}
	return list;
}
 
Example #10
Source File: Connector.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public List<Point3f> getTargetPoints(final boolean calibrated) {
	if (null == root) return null;
	final List<Point3f> targets = new ArrayList<Point3f>();
	if (null == root.children) return targets;
	final float[] f = new float[2];
	for (final Node<Float> nd : root.children) {
		targets.add(fix(nd.asPoint(), calibrated, f));
	}
	return targets;
}
 
Example #11
Source File: Pipe.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Calibrated. */
@Override
   synchronized public List<Point3f> generateTriangles(final double scale, int parallels, final int resample) {
	if (n_points < 2) return null;
	// check minimum requirements.
	if (parallels < 3) parallels = 3;
	//
	final double[][][] all_points = generateJoints(parallels, resample, layer_set.getCalibrationCopy());
	return Pipe.generateTriangles(all_points, scale);
}
 
Example #12
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public MeasurementPair(final Node<T> a, final Node<T> b, final List<Node<T>> path) {
	super(a, b, path);
	this.distance = new MeasurePathDistance<T>(Tree.this, a, b, path).getDistance();
	this.data = calibratedData();
	this.coords = new ArrayList<Point3f>();
	final AffineTransform aff = toCalibration();
	final float[] fp = new float[2];
	for (final Node<T> nd : path) {
		fp[0] = nd.x;
		fp[1] = nd.y;
		aff.transform(fp, 0, fp, 0, 1);
		coords.add(new Point3f(fp[0], fp[1], (float)nd.getLayer().getCalibratedZ()));
	}
}
 
Example #13
Source File: Path.java    From SNT with GNU General Public License v3.0 5 votes vote down vote up
public java.util.List<Point3f> getPoint3fList() {
	final ArrayList<Point3f> linePoints = new ArrayList<>();
	for (int i = 0; i < points; ++i) {
		linePoints.add(new Point3f((float) precise_x_positions[i], (float) precise_y_positions[i],
				(float) precise_z_positions[i]));
	}
	return linePoints;
}
 
Example #14
Source File: AreaList.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public List<Point3f> generateTriangles(final double scale, final int resample) {
	final HashMap<Layer,Area> areas = new HashMap<Layer,Area>();
	for (final Map.Entry<Long,Area> e : ht_areas.entrySet()) {
		areas.put(layer_set.getLayer((Long)e.getKey()), (Area)e.getValue());
	}
	return AreaUtils.generateTriangles(this, scale, resample, areas);
}
 
Example #15
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Expects a non-null float[] for reuse, and modifies @param p in place. */
protected Point3f fix(final Point3f p, final boolean calibrated, final float[] f) {
	f[0] = p.x;
	f[1] = p.y;
	this.at.transform(f, 0, f, 0, 1);
	p.x = f[0];
	p.y = f[1];
	if (calibrated) {
		final Calibration cal = layer_set.getCalibration();
		p.x *= cal.pixelWidth;
		p.y *= cal.pixelHeight;
		p.z *= cal.pixelWidth; // not pixelDepth!
	}
	return p;
}
 
Example #16
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getShortTitle() {
	final String title = getTitle();
	if (null != title && !getClass().getSimpleName().toLowerCase().equals(title.toLowerCase())) return title;
	if (null == root) return "Empty";
	final Point3f p = getOriginPoint(true);
	return new StringBuilder("Root: x=").append(p.x).append(", y=" + p.y).append(" z=").append(p.z).toString();
}
 
Example #17
Source File: M.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Compute the area of the triangle defined by 3 points in 3D space, returning half of the length of the vector resulting from the cross product of vectors p1p2 and p1p3. */
static public final double measureArea(final Point3f p1, final Point3f p2, final Point3f p3) {
	// Distance from p1 to line p2-p3, times length of line p2-p3, divided by 2:
	return 0.5 * M.distancePointToLine(p1.x, p1.y, p1.z,
					   p2.x, p2.y, p2.z,
					   p3.x, p3.y, p3.z)
		   * p2.distance(p3);
}
 
Example #18
Source File: Treeline.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
static private final List<Point3f> transform(final Transform3D t, final List<Point3f> plane, final float x, final float y, final float z, final float radius) {
	final List<Point3f> ps = new ArrayList<Point3f>(plane.size());
	for (final Point3f p2 : plane) {
		final Point3f p = new Point3f(p2);
		p.scale(radius);
		t.transform(p);
		p.x += x;
		p.y += y;
		p.z += z;
		ps.add(p);
	}
	return ps;
}
 
Example #19
Source File: Treeline.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
static private final void addTriangles(final List<Point3f> ps, final List<Point3f> parent_verts, final List<Point3f> child_verts, final int i0, final int i1) {
	// one triangle
	ps.add(new Point3f(parent_verts.get(i0)));
	ps.add(new Point3f(parent_verts.get(i1)));
	ps.add(new Point3f(child_verts.get(i0)));
	// another
	ps.add(new Point3f(parent_verts.get(i1)));
	ps.add(new Point3f(child_verts.get(i1)));
	ps.add(new Point3f(child_verts.get(i0)));
}
 
Example #20
Source File: MCCube.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
private MCCube() {
	this.v = new Point3f[8];
	for(int i = 0; i < 8; i++)
		v[i] = new Point3f();
	this.e = new Point3f[12];
	for(int i = 0; i < 12; i++)
		e[i] = new Point3f();
}
 
Example #21
Source File: Ball.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Returns a Point3f for every x,y,z ball, in calibrated world space. */
public List<Point3f> asWorldPoints() {
	final ArrayList<Point3f> ps = new ArrayList<Point3f>();
	for (final double[] d : getWorldBalls()) {
		ps.add(new Point3f((float)d[0], (float)d[1], (float)d[2]));
	}
	return ps;
}
 
Example #22
Source File: MCCube.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a list of triangles from the specified image data and the
 * given isovalue.
 * @param volume
 * @param thresh
 * @return
 */
public static final List<Point3f> getTriangles(final Volume volume, final int thresh){
	final List<Point3f> tri = new ArrayList<Point3f>();
	final Carrier car = new Carrier();
	car.w = volume.xDim;
	car.h = volume.yDim;
	car.d = volume.zDim;
	car.threshold = thresh + 0.5f;
	car.volume = volume;

	if (volume instanceof ImgLibVolume && ((ImgLibVolume)volume).getImage().getContainer() instanceof ShapeList) {
		getShapeListImageTriangles((ImgLibVolume)volume, car, tri);
	} else {
		final MCCube cube = new MCCube();
		for(int z = -1; z < car.d+1; z+=1){
			for(int x = -1; x < car.w+1; x+=1){
				for(int y = -1; y < car.h+1; y+=1){
					cube.init(x, y, z);
					cube.computeEdges(car);
					cube.getTriangles(tri, car);
				}
			}
			IJ.showProgress(z, car.d-2);
		}
	}

	// convert pixel coordinates
	for(int i = 0; i < tri.size(); i++) {
		final Point3f p = (Point3f)tri.get(i);
		p.x = (float) (p.x * volume.pw + volume.minCoord.x);
		p.y = (float) (p.y * volume.ph + volume.minCoord.y);
		p.z = (float) (p.z * volume.pd + volume.minCoord.z);
	}
	return tri;
}
 
Example #23
Source File: SimpleNeuriteTracer.java    From SNT with GNU General Public License v3.0 5 votes vote down vote up
protected void addSphere(final String name, final double x, final double y, final double z, final Color color,
		final double radius) {
	if (use3DViewer) {
		final List<Point3f> sphere = customnode.MeshMaker.createSphere(x, y, z, radius);
		univ.addTriangleMesh(sphere, new Color3f(color), name);
	}
}
 
Example #24
Source File: Node.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public Point3f asPoint() {
	return new Point3f(x, y, (float)la.getZ());
}
 
Example #25
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;
}
 
Example #26
Source File: MCCube.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
final int intensity(final Point3f p) {
	if(p.x < 0 || p.y < 0 || p.z < 0
		|| p.x >= w || p.y >= h || p.z >= d)
		return 0;
	return volume.load((int)p.x, (int)p.y, (int)p.z);
}
 
Example #27
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public Point3f getFirstNodeCoordinates() {
	return new Point3f(firstx, firsty, (float)(path.get(0).la.getZ() * cal.pixelWidth));
}
 
Example #28
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public Point3f getLastNodeCoordinates() {
	if (1 == path.size()) {
		return getFirstNodeCoordinates();
	}
	return new Point3f(fpB[0], fpB[1], (float)(path.get(path.size()-1).la.getZ() * cal.pixelWidth));
}
 
Example #29
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public MeshData(final List<Point3f> v, final List<Color3f> c) {
	this.verts = v;
	this.colors = c;
}
 
Example #30
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public Point3f getOriginPoint(final boolean calibrated) {
	if (null == root) return null;
	return fix(root.asPoint(), calibrated, new float[2]);
}