Java Code Examples for net.imglib2.RealPoint#getDoublePosition()

The following examples show how to use net.imglib2.RealPoint#getDoublePosition() . 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: Geom3DUtils.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a 4D vector [a,b,c,d] that defines a 3D plane in the following way: ax+by+cz+d=0.
 *
 * The normal vector of the plane is calculated by taking the cross-product of the two vectors within the plane
 * formed between 3 points that are passed as parameters: P1->P2 and P1->P3.
 *
 * @param p1
 * @param p2
 * @param p3
 * @return
 */
public static Vec4d createPlane(final RealPoint p1, final RealPoint p2, final RealPoint p3)
{
	// p1 -> p2
	final Vec3d p12 = new Vec3d(
			p2.getDoublePosition(0) - p1.getDoublePosition(0),
			p2.getDoublePosition(1) - p1.getDoublePosition(1),
			p2.getDoublePosition(2) - p1.getDoublePosition(2));

	// p1 -> p3
	final Vec3d p13 = new Vec3d(
			p3.getDoublePosition(0) - p1.getDoublePosition(0),
			p3.getDoublePosition(1) - p1.getDoublePosition(1),
			p3.getDoublePosition(2) - p1.getDoublePosition(2));

	final Vec3d normal = new Vec3d();
	normal.cross(p12, p13);
	normal.normalize();

	// plug the coordinates of any given point in the plane into the plane equation to find the last component of the equation
	final double d = -normal.dot(new Vec3d(p1.getDoublePosition(0), p1.getDoublePosition(1), p1.getDoublePosition(2)));

	return new Vec4d(normal.x, normal.y, normal.z, d);
}
 
Example 2
Source File: ConsensusWarpFieldBuilder.java    From render with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds the specified consensus set data to this builder so that it can be
 * used by the {@link #build} method later.
 *
 * @param  alignmentModel  alignment model for this consensus point set.
 * @param  points          set of points associated with the model.
 */
public void addConsensusSetData(final Affine2D alignmentModel,
                                final List<RealPoint> points) {

    final ARGBType consensusSetIndex = new ARGBType(consensusSetModelList.size());
    consensusSetModelList.add(alignmentModel);

    double x;
    double y;
    for (final RealPoint point : points) {
        x = point.getDoublePosition(0) / pixelsPerColumn;
        y = point.getDoublePosition(1) / pixelsPerRow;
        consensusSetIndexSamples.add(new RealPoint(x, y), consensusSetIndex);
    }

}
 
Example 3
Source File: DefaultSmallestEnclosingRectangle.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Rotates the given Polygon2D consisting of a list of RealPoints by the
 * given angle about the given center.
 *
 * @param inPoly A Polygon2D consisting of a list of RealPoint RealPoints
 * @param angle the rotation angle
 * @param center the rotation center
 * @return a rotated polygon
 */
private Polygon2D rotate(final Polygon2D inPoly, final double angle,
	final RealLocalizable center)
{

	List<RealLocalizable> out = new ArrayList<>();

	for (RealLocalizable RealPoint : GeomUtils.vertices(inPoly)) {

		// double angleInRadians = Math.toRadians(angleInDegrees);
		double cosTheta = Math.cos(angle);
		double sinTheta = Math.sin(angle);

		double x = cosTheta * (RealPoint.getDoublePosition(0) - center
			.getDoublePosition(0)) - sinTheta * (RealPoint.getDoublePosition(1) -
				center.getDoublePosition(1)) + center.getDoublePosition(0);

		double y = sinTheta * (RealPoint.getDoublePosition(0) - center
			.getDoublePosition(0)) + cosTheta * (RealPoint.getDoublePosition(1) -
				center.getDoublePosition(1)) + center.getDoublePosition(1);

		out.add(new RealPoint(x, y));
	}

	return new DefaultWritablePolygon2D(out);
}
 
Example 4
Source File: Geom3DUtils.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the length of the vector between (0,0,0) and the given point.
 *
 * @param point
 * @return
 */
public static double length(final RealPoint point)
{
	double sqLen = 0;
	for (int d = 0; d < point.numDimensions(); ++d)
		sqLen += point.getDoublePosition(d) * point.getDoublePosition(d);
	return Math.sqrt(sqLen);
}
 
Example 5
Source File: DerivedMatchGroup.java    From render with GNU General Public License v2.0 5 votes vote down vote up
private static double[][] buildLocationArray(final List<RealPoint> pointList) {
    final double[][] locations = new double[2][pointList.size()];
    final double[] xLocations = locations[0];
    final double[] yLocations = locations[1];
    int i = 0;
    for (final RealPoint point : pointList) {
        xLocations[i] = point.getDoublePosition(0);
        yLocations[i] = point.getDoublePosition(1);
        i++;
    }
    return locations;
}
 
Example 6
Source File: DefaultDetectJunctions.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private RealPoint averagePoints(ArrayList<RealPoint> list) {
	double[] pos = { 0, 0 };
	for (RealPoint p : list) {
		pos[0] += p.getDoublePosition(0);
		pos[1] += p.getDoublePosition(1);
	}
	pos[0] /= list.size();
	pos[1] /= list.size();
	return new RealPoint(pos);
}
 
Example 7
Source File: ShowSegmentationDemo.java    From sciview with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private double dist(long[] pos, RealPoint realPoint) {
    return ( pos[0] - realPoint.getDoublePosition(0) ) * ( pos[0] - realPoint.getDoublePosition(0) ) +
            ( pos[1] - realPoint.getDoublePosition(1) ) * ( pos[1] - realPoint.getDoublePosition(1) ) +
            ( pos[2] - realPoint.getDoublePosition(2) ) * ( pos[2] - realPoint.getDoublePosition(2) );
}
 
Example 8
Source File: DefaultVoxelization3D.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public RandomAccessibleInterval<BitType> calculate(Mesh input) {

	Img<BitType> outImg = ops.create().img(new FinalInterval(width, height, depth), new BitType());

	Vertices verts = input.vertices();

	RealPoint minPoint = new RealPoint(verts.iterator().next());
	RealPoint maxPoint = new RealPoint(verts.iterator().next());

	for (RealLocalizable v : verts) {
		if (v.getDoublePosition(0) < minPoint.getDoublePosition(0))
			minPoint.setPosition(v.getDoublePosition(0), 0);
		if (v.getDoublePosition(1) < minPoint.getDoublePosition(1))
			minPoint.setPosition(v.getDoublePosition(1), 1);
		if (v.getDoublePosition(2) < minPoint.getDoublePosition(2))
			minPoint.setPosition(v.getDoublePosition(2), 2);

		if (v.getDoublePosition(0) > maxPoint.getDoublePosition(0))
			maxPoint.setPosition(v.getDoublePosition(0), 0);
		if (v.getDoublePosition(1) > maxPoint.getDoublePosition(1))
			maxPoint.setPosition(v.getDoublePosition(1), 1);
		if (v.getDoublePosition(2) > maxPoint.getDoublePosition(2))
			maxPoint.setPosition(v.getDoublePosition(2), 2);
	}

	RealPoint dimPoint = new RealPoint((maxPoint.getDoublePosition(0) - minPoint.getDoublePosition(0)),
			(maxPoint.getDoublePosition(1) - minPoint.getDoublePosition(1)),
			(maxPoint.getDoublePosition(2) - minPoint.getDoublePosition(2)));

	double[] stepSizes = new double[3];
	stepSizes[0] = dimPoint.getDoublePosition(0) / width;
	stepSizes[1] = dimPoint.getDoublePosition(1) / height;
	stepSizes[2] = dimPoint.getDoublePosition(2) / depth;

	double[] voxelHalfsize = new double[3];
	for (int k = 0; k < stepSizes.length; k++)
		voxelHalfsize[k] = stepSizes[k] / 2.0;

	for (final Triangle tri : input.triangles()) {
		final Vector3D v1 = new Vector3D(tri.v0x(), tri.v0y(), tri.v0z());
		final Vector3D v2 = new Vector3D(tri.v1x(), tri.v1y(), tri.v1z());
		final Vector3D v3 = new Vector3D(tri.v2x(), tri.v2y(), tri.v2z());

		double[] minSubBoundary = new double[] {
				Math.min(Math.min(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0),
				Math.min(Math.min(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1),
				Math.min(Math.min(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) };
		double[] maxSubBoundary = new double[] {
				Math.max(Math.max(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0),
				Math.max(Math.max(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1),
				Math.max(Math.max(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) };

		RandomAccess<BitType> ra = outImg.randomAccess();// Should use the
															// interval
															// implementation
															// for speed

		long[] indices = new long[3];
		for (indices[0] = (long) Math.floor(minSubBoundary[0] / stepSizes[0]); indices[0] < Math
				.floor(maxSubBoundary[0] / stepSizes[0]); indices[0]++) {
			for (indices[1] = (long) Math.floor(minSubBoundary[1] / stepSizes[1]); indices[1] < Math
					.floor(maxSubBoundary[1] / stepSizes[1]); indices[1]++) {
				for (indices[2] = (long) Math.floor(minSubBoundary[2] / stepSizes[2]); indices[2] < Math
						.floor(maxSubBoundary[2] / stepSizes[2]); indices[2]++) {
					ra.setPosition(indices);
					if (!ra.get().get())// Don't check if voxel is already
										// filled
					{
						double[] voxelCenter = new double[3];

						for (int k = 0; k < 3; k++)
							voxelCenter[k] = indices[k] * stepSizes[k] + voxelHalfsize[k];

						if (triBoxOverlap(voxelCenter, voxelHalfsize, v1, v2, v3) == 1) {
							ra.get().set(true);
						}
					}
				}
			}
		}
	}

	return outImg;
}
 
Example 9
Source File: Geom3DUtils.java    From paintera with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the Z plane coordinate in camera space where the point is located.
 *
 * Note that for performance reasons the {@code point} parameter will be modified by this method!
 *
 * @param cameraToWorldTransform
 * @param point
 * @return
 */
public static double cameraZPlane(final AffineTransform3D cameraToWorldTransform, final RealPoint point)
{
	cameraToWorldTransform.applyInverse(point, point);
	return point.getDoublePosition(2);
}