use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class CPDTest method main.
public static void main(String[] args) {
AffineTransform3d trans = new AffineTransform3d();
RotationMatrix3d R = new RotationMatrix3d(0.7605, -0.6307, 0.1541, 0.6485, 0.7263, -0.2279, 0.0318, 0.2733, 0.9614);
double s = 2.7;
trans.setA(R, new Vector3d(s, s, s), new Vector3d(0, 0, 0));
trans.setTranslation(new Vector3d(1, 2, 3));
Point3d[] X = get3DFish();
int N = X.length;
int M = N - 20;
Point3d[] Y = new Point3d[M];
Point3d[] out = new Point3d[M];
for (int i = 0; i < N; i++) {
if (i < M) {
Y[i] = new Point3d(X[i]);
out[i] = new Point3d();
}
X[i].transform(trans);
}
double w = 0.01;
double lambda = 0.1;
double beta2 = 3.5;
CPD.verbose = true;
ScaledRigidTransform3d rigidT = CPD.rigid(X, Y, w, 1e-10, 100, true, out);
AffineTransform3d affT = CPD.affine(X, Y, w, 1e-10, 100, out);
CPD.coherent(X, Y, lambda, beta2, w, 1e-10, 100, out);
System.out.println("Original: \n" + trans.toString());
System.out.println("Rigid Computed: \n" + rigidT.toString());
System.out.println("Affine Computed: \n" + affT.toString());
for (int i = 0; i < M; i++) {
System.out.println(X[i].toString() + "\n" + out[i].toString() + "\n");
}
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class ConstrainedTranslator3d method render.
public void render(Renderer renderer, int flags) {
if (!myVisibleP) {
return;
}
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setLineWidth(myLineWidth);
renderer.pushModelMatrix();
Vector3d t = myXDraggerToWorld.p;
renderer.translateModelMatrix(t.x, t.y, t.z);
renderer.scaleModelMatrix(mySize);
if (renderObject == null) {
renderObject = createRenderable();
}
int gidx = selected ? 1 : 0;
renderer.drawLines(renderObject, gidx);
renderer.popModelMatrix();
renderer.setShading(savedShading);
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class HalfEdge method projectionParameter.
/**
* Computes the projection parameter of a point <code>px</code>
* with respect to a line defined by points <code>p0</code> and
* <code>p1</code>. This is the value <i>s</i> such that
* <pre>
* pp = (1-s) p0 + s p1
* </pre>
* gives the projection of <code>px-p0</code> onto the line. If
* <code>p0</code> and <code>p1</code> are identical, the
* method returns positive infinity.
*
* @param p0 first point defining the line
* @param p1 second point defining the libe
* @param px point for which the project parameter should be computed
* @return parameter s which projects px onto the line
*/
public static double projectionParameter(Point3d p0, Point3d p1, Point3d px) {
Vector3d del10 = new Vector3d();
Vector3d delx0 = new Vector3d();
del10.sub(p1, p0);
delx0.sub(px, p0);
double len10Sqr = del10.normSquared();
if (len10Sqr == 0) {
return Double.POSITIVE_INFINITY;
} else {
return del10.dot(delx0) / len10Sqr;
}
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class PolygonalMesh method translateToCenterOfVolume.
/**
* Translates the vertices of this mesh so that its origin coincides
* with the center of volume. The topology of the mesh remains unchanged.
*/
public void translateToCenterOfVolume() {
Vector3d off = new Vector3d();
computeCentreOfVolume(off);
off.negate();
translate(off);
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class PolygonalMesh method setHardEdgesFromNormals.
/**
*/
public boolean setHardEdgesFromNormals() {
HashSet<HalfEdge> hardSet = new HashSet<HalfEdge>();
if (myNormals == null || myNormals.size() == numVertices()) {
// multiple normals.
return false;
}
for (Vertex3d vtx : myVertices) {
Iterator<HalfEdge> it = vtx.getIncidentHalfEdges();
while (it.hasNext()) {
HalfEdge he = it.next();
if (hardEdgeInferredFromNormals(he)) {
hardSet.add(he);
he.setHard(true);
}
}
}
ArrayList<Vector3d> normals = new ArrayList<Vector3d>();
int[] indices = computeVertexNormals(normals, myMultiAutoNormalsP);
// now see if the normals and indices equal those within the mesh, to
// within 1e-8
double eps = 1e-8;
boolean normalsEqual = false;
if (myNormals.size() == normals.size()) {
int i;
for (i = 0; i < myNormals.size(); i++) {
Vector3d nrm0 = myNormals.get(i);
Vector3d nrm1 = normals.get(i);
if (!nrm0.epsilonEquals(nrm1, eps)) {
break;
}
}
if (i == myNormals.size()) {
normalsEqual = Arrays.equals(myNormalIndices, indices);
}
}
if (!normalsEqual) {
myNormalsExplicitP = true;
// leave the half edges set
return false;
} else {
myNormalsExplicitP = false;
myAutoNormalsValidP = true;
return true;
}
}
Aggregations