use of org.scijava.vecmath.Vector3d in project mcib3d-core by mcib3d.
the class Deriche method newPosition.
// Calcul d'un point (position) à partir d'un point initial, un vecteur
// de direction et un entier n
public Vector3d newPosition(Point3f position, Point3f direction, float n) {
double posX, posY, posZ;
posX = Math.round(position.x + (direction.x * n));
posY = Math.round(position.y + (direction.y * n));
posZ = Math.round(position.z + (direction.z * n));
Vector3d vec = new Vector3d(posX, posY, posZ);
return vec;
}
use of org.scijava.vecmath.Vector3d in project TrakEM2 by trakem2.
the class VectorString3D method mirror.
/**
* Where axis is any of VectorString.X_AXIS, .Y_AXIS or .Z_AXIS,
* and the mirroring is done relative to the local 0,0 of this VectorString.
*/
public void mirror(final int axis) {
final Transform3D t = new Transform3D();
switch(axis) {
case VectorString.X_AXIS:
t.setScale(new Vector3d(-1, 1, 1));
tags ^= MIRROR_X;
break;
case VectorString.Y_AXIS:
t.setScale(new Vector3d(1, -1, 1));
tags ^= MIRROR_Y;
break;
case VectorString.Z_AXIS:
t.setScale(new Vector3d(1, 1, -1));
tags ^= MIRROR_Z;
break;
default:
return;
}
final Point3d p = new Point3d();
transform(x, y, z, t, p);
if (null != this.vx)
transform(vx, vy, vz, t, p);
if (null != this.rvx)
transform(rvx, rvy, rvz, t, p);
}
use of org.scijava.vecmath.Vector3d in project TrakEM2 by trakem2.
the class M method distancePointToSegmentSq.
public static final double distancePointToSegmentSq(final Vector3d p, final Vector3d v1, final Vector3d v2) {
final Vector3d v = new Vector3d();
v.sub(v2, v1);
final Vector3d w = new Vector3d();
w.sub(p, v1);
final double c1 = w.dot(v);
if (c1 <= 0)
return distanceSq(p, v1);
final double c2 = v.dot(v);
if (c2 <= c1)
return distanceSq(p, v2);
final double b = c1 / c2;
final Vector3d pb = new Vector3d(v);
pb.scale(b);
pb.add(v1);
return distanceSq(p, pb);
}
use of org.scijava.vecmath.Vector3d in project TrakEM2 by trakem2.
the class M method distancePointToSegment.
/**
* Minimum distance between point v0 and a line segment defined by points v1 and v2.
*/
public static final double distancePointToSegment(final Vector3d p, final Vector3d v1, final Vector3d v2) {
final Vector3d v = new Vector3d();
v.sub(v2, v1);
final Vector3d w = new Vector3d();
w.sub(p, v1);
final double c1 = w.dot(v);
if (c1 <= 0)
return distance(p, v1);
final double c2 = v.dot(v);
if (c2 <= c1)
return distance(p, v2);
final double b = c1 / c2;
final Vector3d pb = new Vector3d(v);
pb.scale(b);
pb.add(v1);
return distance(p, pb);
}
use of org.scijava.vecmath.Vector3d in project TrakEM2 by trakem2.
the class Compare method gatherChains.
/**
* Gather chains for all projects considering the cp.regex, and transforms all relative to the reference Project p[0].
* Will ignore any for which a match exists in @param ignore.
*/
public static final Object[] gatherChains(final Project[] p, final CATAParameters cp, final String[] ignore) throws Exception {
String regex_exclude = null;
if (null != ignore) {
final StringBuilder sb = new StringBuilder();
for (final String ig : ignore) {
sb.append("(.*").append(ig).append(".*)|");
}
sb.setLength(sb.length() - 1);
regex_exclude = sb.toString();
}
Utils.logAll("Compare/gatherChains: using ignore string: " + regex_exclude);
Utils.logAll("Compare/gatherChains: using regex: " + cp.regex);
// gather all chains
// to keep track of each project's chains
final ArrayList[] p_chains = new ArrayList[p.length];
final ArrayList<Chain> chains = new ArrayList<Chain>();
for (int i = 0; i < p.length; i++) {
// for each project:
if (null == cp.regex) {
p_chains[i] = createPipeChains(p[i].getRootProjectThing(), p[i].getRootLayerSet(), regex_exclude);
} else {
// Search (shallow) for cp.regex matches
for (final ProjectThing pt : p[i].getRootProjectThing().findChildren(cp.regex, regex_exclude, true)) {
final ArrayList<Chain> ac = createPipeChains(pt, p[i].getRootLayerSet(), regex_exclude);
if (null == p_chains[i])
p_chains[i] = ac;
else
p_chains[i].addAll(ac);
}
// empty
if (null == p_chains[i])
p_chains[i] = new ArrayList<Chain>();
}
chains.addAll(p_chains[i]);
// calibrate
final Calibration cal = p[i].getRootLayerSet().getCalibrationCopy();
for (final Chain chain : (ArrayList<Chain>) p_chains[i]) chain.vs.calibrate(cal);
}
final int n_chains = chains.size();
// register all, or relative
if (4 == cp.transform_type) {
// compute global average delta
if (0 == cp.delta) {
for (final Chain chain : chains) {
cp.delta += (chain.vs.getAverageDelta() / n_chains);
}
}
Utils.log2("Using delta: " + cp.delta);
for (final Chain chain : chains) {
// BEFORE making it relative
chain.vs.resample(cp.delta, cp.with_source);
chain.vs.relative();
}
} else {
if (3 == cp.transform_type) {
// '3' means moving least squares computed from 3D landmarks
Utils.log2("Moving Least Squares Registration based on common fiducial points");
// Find fiducial points, if any
final HashMap<Project, Map<String, Tuple3d>> fiducials = new HashMap<Project, Map<String, Tuple3d>>();
for (final Project pr : p) {
final Set<ProjectThing> fids = pr.getRootProjectThing().findChildrenOfTypeR("fiducial_points");
if (null == fids || 0 == fids.size()) {
Utils.log("No fiducial points found in project: " + pr);
} else {
// the first fiducial group
fiducials.put(pr, Compare.extractPoints(fids.iterator().next()));
}
}
if (!fiducials.isEmpty()) {
// Register all VectorString3D relative to the first project:
final List<VectorString3D> lvs = new ArrayList<VectorString3D>();
final Calibration cal2 = p[0].getRootLayerSet().getCalibrationCopy();
for (final Chain chain : chains) {
final Project pr = chain.pipes.get(0).getProject();
// first project is reference, no need to transform.
if (pr == p[0])
continue;
lvs.clear();
lvs.add(chain.vs);
chain.vs = transferVectorStrings(lvs, fiducials.get(pr), fiducials.get(p[0])).get(0);
// Set (but do not apply!) the calibration of the reference project
chain.vs.setCalibration(cal2);
}
}
} else if (cp.transform_type < 3) {
// '0', '1' and '2' involve a 3D affine computed from the 3 axes
// no need //VectorString3D[][] vs_axes = new VectorString3D[p.length][];
Vector3d[][] o = new Vector3d[p.length][];
for (int i = 0; i < p.length; i++) {
// 1 - find pipes to work as axes for each project
final ArrayList<ZDisplayable> pipes = p[i].getRootLayerSet().getZDisplayables(Line3D.class, true);
final String[] pipe_names = new String[pipes.size()];
for (int k = 0; k < pipes.size(); k++) {
pipe_names[k] = p[i].getMeaningfulTitle(pipes.get(k));
}
final int[] s = findFirstXYZAxes(cp.preset, pipes, pipe_names);
// if axes are -1, forget it: not found
if (-1 == s[0] || -1 == s[1] || -1 == s[2]) {
Utils.log("Can't find axes for project " + p[i]);
o = null;
return null;
}
// obtain axes and origin
final Object[] pack = obtainOrigin(new Line3D[] { (Line3D) pipes.get(s[0]), (Line3D) pipes.get(s[1]), (Line3D) pipes.get(s[2]) }, cp.transform_type, // will be null for the first, which will then be non-null and act as the reference for the others.
o[0]);
// no need //vs_axes[i] = (VectorString3D[])pack[0];
o[i] = (Vector3d[]) pack[1];
}
/* // OLD WAY
// match the scales to make the largest be 1.0
final double scaling_factor = VectorString3D.matchOrigins(o, transform_type);
Utils.log2("matchOrigins scaling factor: " + scaling_factor + " for transform_type " + transform_type);
*/
// transform all except the first (which acts as reference)
final Transform3D M_ref = Compare.createTransform(o[0]);
for (int i = 1; i < p.length; i++) {
final Vector3d trans = new Vector3d(-o[i][3].x, -o[i][3].y, -o[i][3].z);
final Transform3D M_query = Compare.createTransform(o[i]);
// The transfer T transform: from query space to reference space.
final Transform3D T = new Transform3D(M_ref);
T.mulInverse(M_query);
for (final Chain chain : (ArrayList<Chain>) p_chains[i]) {
// in place
chain.vs.transform(T);
}
}
}
// compute global average delta, after correcting calibration and transformation
if (0 == cp.delta) {
for (final Chain chain : chains) {
cp.delta += (chain.vs.getAverageDelta() / n_chains);
}
}
Utils.log2("Using delta: " + cp.delta);
// After calibration and transformation, resample all to the same delta
for (final Chain chain : chains) chain.vs.resample(cp.delta, cp.with_source);
}
return new Object[] { chains, p_chains };
}
Aggregations