Java Code Examples for javax.vecmath.Matrix4d#setIdentity()

The following examples show how to use javax.vecmath.Matrix4d#setIdentity() . 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: VirtualInstanceCollectionMessageBodyWriter.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void writeTo(VirtualInstanceCollection virtualInstanceCollection, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws UnsupportedEncodingException {
    String charSet = "UTF-8";
    JsonGenerator jg = Json.createGenerator(new OutputStreamWriter(entityStream, charSet));
    jg.writeStartArray();

    Matrix4d gM = new Matrix4d();
    gM.setIdentity();

    PartLink virtualRootPartLink = getVirtualRootPartLink(virtualInstanceCollection);
    List<PartLink> path = new ArrayList<>();
    path.add(virtualRootPartLink);
    InstanceBodyWriterTools.generateInstanceStreamWithGlobalMatrix(productService, path, gM, virtualInstanceCollection, new ArrayList<>(), jg);
    jg.writeEnd();
    jg.flush();
}
 
Example 2
Source File: InstanceBodyWriterTools.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
static Matrix4d combineTransformation(Matrix4d matrix, Vector3d translation, Vector3d rotation) {
    Matrix4d gM = new Matrix4d(matrix);
    Matrix4d m = new Matrix4d();

    m.setIdentity();
    m.setTranslation(translation);
    gM.mul(m);

    m.setIdentity();
    m.rotZ(rotation.z);
    gM.mul(m);

    m.setIdentity();
    m.rotY(rotation.y);
    gM.mul(m);

    m.setIdentity();
    m.rotX(rotation.x);
    gM.mul(m);

    return gM;
}
 
Example 3
Source File: SpaceGroup.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Matrix4d getMatrixFromAlgebraic(String transfAlgebraic) {
	String[] parts = transfAlgebraic.toUpperCase().split(",");
	double[] xCoef = convertAlgebraicStrToCoefficients(parts[0].trim());
	double[] yCoef = convertAlgebraicStrToCoefficients(parts[1].trim());
	double[] zCoef = convertAlgebraicStrToCoefficients(parts[2].trim());

	Matrix4d mat = new Matrix4d();
	mat.setIdentity();
	mat.setRotation(new Matrix3d(xCoef[0],xCoef[1],xCoef[2],yCoef[0],yCoef[1],yCoef[2],zCoef[0],zCoef[1],zCoef[2]));
	mat.setTranslation(new Vector3d(xCoef[3],yCoef[3],zCoef[3]));
	return mat;
	//return new Matrix4d(xCoef[0],xCoef[1],xCoef[2],xCoef[3],
	//					yCoef[0],yCoef[1],yCoef[2],yCoef[3],
	//					zCoef[0],zCoef[1],zCoef[2],zCoef[3],
	//					0,0,0,1);
}
 
Example 4
Source File: DHBuilderApp.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
protected void testEnd() {
	Matrix4d identity = new Matrix4d();
	identity.setIdentity();
	
	// restore the initial theta for each link
	for(int i=0;i<links.size();++i) {
		DHLink bone=links.get(i);
		// allow editing of all DH parameters
		bone.flags = LinkAdjust.ALL;
		// undo changes to theta values
		bone.setTheta(thetaAtTestStart[i]);
		bone.refreshPoseMatrix();
		// set all models back to world origin
		if(bone.getModel()!=null) {
			bone.getModel().adjustMatrix(identity);
		}
	}
	endEffectorTarget.setPoseWorld(endEffector.getPoseWorld());
}
 
Example 5
Source File: RotationGroup.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void setC1(int n) {
	Rotation r = new Rotation();
	List<Integer> permutation = new ArrayList<Integer>(n);
	for (int i = 0; i < n; i++) {
		permutation.add(i);
	}
	r.setPermutation(permutation);
	Matrix4d m = new Matrix4d();
	m.setIdentity();
	r.setTransformation(m);
	r.setAxisAngle(new AxisAngle4d());
	r.setFold(1);
	r.setScores(new QuatSymmetryScores());
	rotations.add(r);
	pointGroup = "C1";
}
 
Example 6
Source File: SymmetryAxes.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Return the transformation that needs to be applied to a
 * repeat in order to superimpose onto repeat 0.
 *
 * @param repeat the repeat index
 * @return transformation matrix for the repeat
 */
public Matrix4d getRepeatTransform(int repeat){

	Matrix4d transform = new Matrix4d();
	transform.setIdentity();

	int[] counts = getAxisCounts(repeat);

	for(int t = counts.length-1; t>=0; t--) {
		if( counts[t] == 0 )
			continue;
		Matrix4d axis = new Matrix4d(axes.get(t).getOperator());
		for(int i=0;i<counts[t];i++) {
			transform.mul(axis);
		}
	}
	return transform;
}
 
Example 7
Source File: TestMultipleAlignmentScorer.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generates a simple MultipleAlignment: 3 structures with the
 * same Atoms but incorreclty aligned with gaps.
 *
 * @return MultipleAlignment gapped MSTA
 * @throws StructureException
 */
private MultipleAlignment gappedMSTA() throws StructureException{

	//Generate three identical Atom arrays
	List<Atom[]> atomArrays = new ArrayList<Atom[]>(30);
	for (int i=0; i<3; i++) atomArrays.add(makeDummyCA(30));

	//Generate alignment with nulls and some missalignments
	List<List<Integer>> alnRes = new ArrayList<List<Integer>>(3);
	List<Integer> chain1 = Arrays.asList(
			1, 2, 	 3, 5, 8, 10, 12, 	 15, 17,  19, 22, null, 24, 27);
	List<Integer> chain2 = Arrays.asList(
			1, null, 3, 6, 9, 11, 12,   15, null, 18, 22, 24,   26, 28);
	List<Integer> chain3 = Arrays.asList(
			1, 2,    4, 7, 9, 10, null, 15, null, 17, 22, 24,   26, 28);

	alnRes.add(chain1);
	alnRes.add(chain2);
	alnRes.add(chain3);

	//MultipleAlignment generation
	MultipleAlignment msa = new MultipleAlignmentImpl();
	msa.getEnsemble().setAtomArrays(atomArrays);
	BlockSet bs = new BlockSetImpl(msa);
	Block b = new BlockImpl(bs);
	b.setAlignRes(alnRes);

	//We want the identity transfromations to mantain the missalignments
	Matrix4d ident = new Matrix4d();
	ident.setIdentity();
	bs.setTransformations(Arrays.asList(ident,ident,ident));

	return msa;
}
 
Example 8
Source File: TestMultipleAlignmentScorer.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generates a simple MultipleAlignment: 3 structures with the same
 * Atoms but incorreclty aligned (offset of 1 position) without gaps.
 *
 * @return MultipleAlignment simple MSTA
 * @throws StructureException
 */
private MultipleAlignment simpleMSTA() throws StructureException{

	//Generate three identical Atom arrays
	List<Atom[]> atomArrays = new ArrayList<Atom[]>(52);
	for (int i=0; i<3; i++) atomArrays.add(makeDummyCA(52));

	//Generate the incorrect alignment (0-1-2,1-2-3,etc)
	List<List<Integer>> alnRes = new ArrayList<List<Integer>>(3);
	for (int str=0; str<3; str++){
		List<Integer> chain = new ArrayList<Integer>(50);
		for (int res=0; res<50; res++) chain.add(res+str);
		alnRes.add(chain);
	}

	//MultipleAlignment generation
	MultipleAlignment msa = new MultipleAlignmentImpl();
	msa.getEnsemble().setAtomArrays(atomArrays);
	BlockSet bs = new BlockSetImpl(msa);
	Block b = new BlockImpl(bs);
	b.setAlignRes(alnRes);

	//We want the identity transfromations to maintain the missalignment
	Matrix4d ident = new Matrix4d();
	ident.setIdentity();
	bs.setTransformations(Arrays.asList(ident,ident,ident));

	return msa;
}
 
Example 9
Source File: C2RotationSolver.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addEOperation() {
	List<Integer> permutation = Arrays.asList(0,1);
	Matrix4d transformation = new Matrix4d();
	transformation.setIdentity();
	combineWithTranslation(transformation);
	AxisAngle4d axisAngle = new AxisAngle4d();
	QuatSymmetryScores scores = new QuatSymmetryScores();
	int fold = 1; // ??
	Rotation rotation = createSymmetryOperation(permutation, transformation, axisAngle, fold, scores);
	rotations.addRotation(rotation);
}
 
Example 10
Source File: SuperPositionQCP.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Superposition coords2 onto coords1 -- in other words, coords2 is rotated,
 * coords1 is held fixed
 */
private void calcTransformation() {

	// transformation.set(rotmat,new Vector3d(0,0,0), 1);
	transformation.set(rotmat);
	// long t2 = System.nanoTime();
	// System.out.println("create transformation: " + (t2-t1));
	// System.out.println("m3d -> m4d");
	// System.out.println(transformation);

	// combine with x -> origin translation
	Matrix4d trans = new Matrix4d();
	trans.setIdentity();
	trans.setTranslation(new Vector3d(xtrans));
	transformation.mul(transformation, trans);
	// System.out.println("setting xtrans");
	// System.out.println(transformation);

	// combine with origin -> y translation
	ytrans.negate();
	Matrix4d transInverse = new Matrix4d();
	transInverse.setIdentity();
	transInverse.setTranslation(new Vector3d(ytrans));
	transformation.mul(transInverse, transformation);
	// System.out.println("setting ytrans");
	// System.out.println(transformation);
}
 
Example 11
Source File: DHRobotEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public Matrix4d getParentMatrix() {
	if( parent == null || !(parent instanceof PoseEntity) ) {
		Matrix4d m = new Matrix4d();
		m.setIdentity();
		return m;
	} else {
		return ((PoseEntity)parent).getPose();
	}
}
 
Example 12
Source File: InstanceCollectionMessageBodyWriter.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void writeTo(InstanceCollection instanceCollection, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws UnsupportedEncodingException {
    String charSet = "UTF-8";
    JsonGenerator jg = Json.createGenerator(new OutputStreamWriter(entityStream, charSet));
    jg.writeStartArray();

    Matrix4d gM = new Matrix4d();
    gM.setIdentity();
    InstanceBodyWriterTools.generateInstanceStreamWithGlobalMatrix(productService, null, gM, instanceCollection, new ArrayList<>(), jg);
    jg.writeEnd();
    jg.flush();
}
 
Example 13
Source File: Robot_Phybot.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
public void setupModels(DHRobotEntity robot) {
	material = new MaterialEntity();
	float r=0.75f;
	float g=0.15f;
	float b=0.15f;
	material.setDiffuseColor(r,g,b,1);
	
	try {
		robot.links.get(0).setModelFilename("/Sixi/anchor.stl");
		robot.links.get(1).setModelFilename("/Sixi/shoulder.stl");
		robot.links.get(2).setModelFilename("/Sixi/bicep.stl");
		robot.links.get(3).setModelFilename("/Sixi/elbow.stl");
		robot.links.get(5).setModelFilename("/Sixi/forearm.stl");
		robot.links.get(6).setModelFilename("/Sixi/wrist.stl");
		robot.links.get(7).setModelFilename("/Sixi/hand.stl");

		for( DHLink link : robot.links ) link.setModelScale(0.1f);
		robot.links.get(1).getModel().adjustOrigin(new Vector3d(0, 0, -25));
		robot.links.get(2).getModel().adjustOrigin(new Vector3d(0, -5, -25));
		robot.links.get(2).getModel().adjustRotation(new Vector3d(-11.3,0,0));
		
		robot.links.get(5).getModel().adjustOrigin(new Vector3d(0, 0, -60));
		robot.links.get(6).getModel().adjustOrigin(new Vector3d(0, 0, -70));
		robot.links.get(7).getModel().adjustOrigin(new Vector3d(0, 0, -74));

		Matrix4d rot = new Matrix4d();
		Matrix4d rotX = new Matrix4d();
		Matrix4d rotY = new Matrix4d();
		Matrix4d rotZ = new Matrix4d();
		rot.setIdentity();
		rotX.rotX((float)Math.toRadians(90));
		rotY.rotY((float)Math.toRadians(0));
		rotZ.rotZ((float)Math.toRadians(0));
		rot.set(rotX);
		rot.mul(rotY);
		rot.mul(rotZ);
		Matrix4d pose = new Matrix4d(rot);
		Vector3d adjustPos = new Vector3d(0, 5, -50);
		pose.transform(adjustPos);
		
		robot.links.get(3).getModel().adjustOrigin(adjustPos);
		robot.links.get(3).getModel().adjustRotation(new Vector3d(90, 0, 0));
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 14
Source File: CrystalBuilder.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Apply the NCS operators in the given Structure adding new chains as needed.
 * All chains are (re)assigned ids of the form: original_chain_id+ncs_operator_index+{@value #NCS_CHAINID_SUFFIX_CHAR}.
 * @param structure
 *          the structure to expand
 * @param chainOrigNames
 *          new chain names mapped to the original chain names
 * @param chainNcsOps
 *          new chain names mapped to the ncs operators that was used to generate them
 * @since 5.0.0
 */
public static void expandNcsOps(Structure structure, Map<String,String> chainOrigNames, Map<String,Matrix4d> chainNcsOps) {
	PDBCrystallographicInfo xtalInfo = structure.getCrystallographicInfo();
	if (xtalInfo ==null) return;

	if (xtalInfo.getNcsOperators()==null || xtalInfo.getNcsOperators().length==0)
		return;

	List<Chain> chainsToAdd = new ArrayList<>();

	Matrix4d identity = new Matrix4d();
	identity.setIdentity();

	Matrix4d[] ncsOps = xtalInfo.getNcsOperators();

	for (Chain c:structure.getChains()) {
		String cOrigId = c.getId();
		String cOrigName = c.getName();

		for (int iOperator = 0; iOperator < ncsOps.length; iOperator++) {
			Matrix4d m = ncsOps[iOperator];

			Chain clonedChain = (Chain)c.clone();
			String newChainId = cOrigId+(iOperator+1)+NCS_CHAINID_SUFFIX_CHAR;
			String newChainName = cOrigName+(iOperator+1)+NCS_CHAINID_SUFFIX_CHAR;
			clonedChain.setId(newChainId);
			clonedChain.setName(newChainName);

			setChainIdsInResidueNumbers(clonedChain, newChainName);
			Calc.transform(clonedChain, m);

			chainsToAdd.add(clonedChain);
			c.getEntityInfo().addChain(clonedChain);

			chainOrigNames.put(newChainName,cOrigName);
			chainNcsOps.put(newChainName,m);
		}

		chainNcsOps.put(cOrigName,identity);
		chainOrigNames.put(cOrigName,cOrigName);
	}

	chainsToAdd.forEach(structure::addChain);
}
 
Example 15
Source File: ReferenceSuperimposer.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void superimpose(MultipleAlignment alignment)
		throws StructureException {

	//Check for inconsistencies in the alignment
	if(alignment.getEnsemble() == null) {
		throw new NullPointerException("No ensemble set for this alignment."
				+ " Structure information cannot be obtained.");
	}
	if (alignment.size() < 1) {
		throw new IndexOutOfBoundsException(
				"No aligned structures, alignment size == 0.");
	}
	if (alignment.getCoreLength() < 1){
		throw new IndexOutOfBoundsException(
				"Alignment too short, core alignment length < 1.");
	}

	List<Atom[]> atomArrays = alignment.getAtomArrays();
	if (atomArrays.size() <= reference) {
		throw new IndexOutOfBoundsException(String.format(
				"Invalid reference structure: requested %d but "
						+ "only %d structures.",
						reference,atomArrays.size()));
	}

	alignment.clear();

	//Calculate BlockSet transformations
	for (BlockSet bs:alignment.getBlockSets()){

		//Block transformations
		List<Matrix4d> transforms =
				new ArrayList<Matrix4d>(atomArrays.size());

		//Loop through structures
		for (int i=0; i<atomArrays.size(); i++){

			if( i == reference) {
				//Identity operation
				Matrix4d ident = new Matrix4d();
				ident.setIdentity();
				transforms.add(ident);
				continue;
			}

			Atom[] ref = atomArrays.get(reference);
			Atom[] curr = atomArrays.get(i);

			List<Atom> atomSet1 = new ArrayList<Atom>();
			List<Atom> atomSet2 = new ArrayList<Atom>();

			for( Block blk : bs.getBlocks() ) {
				if( blk.size() != atomArrays.size()) {
					throw new IllegalStateException(String.format(
							"Mismatched block length. Expected %d "
									+ "structures, found %d.",
									atomArrays.size(),blk.size() ));
				}
				//Loop through all aligned residues
				for (int j=0; j<blk.length(); j++){
					Integer pos1 = blk.getAlignRes().get(reference).get(j);
					Integer pos2 = blk.getAlignRes().get(i).get(j);

					if (pos1==null || pos2==null) continue;
					atomSet1.add(ref[pos1]);
					atomSet2.add(curr[pos2]);
				}
			}
			Atom[] array1 = atomSet1.toArray(new Atom[atomSet1.size()]);
			Atom[] array2 = atomSet2.toArray(new Atom[atomSet2.size()]);

			array2 = StructureTools.cloneAtomArray(array2);

			//From the superimposer we obtain the rotation and translation
			Matrix4d trans = SuperPositions.superpose(Calc.atomsToPoints(array1),
					Calc.atomsToPoints(array2));
			transforms.add(trans);
		}
		//Set transformation of the BlockSet
		bs.setTransformations(transforms);
	}
}
 
Example 16
Source File: CoreSuperimposer.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void superimpose(MultipleAlignment alignment)
		throws StructureException {

	//Check for inconsistencies in the alignment
	if(alignment.getEnsemble() == null) {
		throw new NullPointerException("No ensemble set for this alignment."
				+ " Structure information cannot be obtained.");
	}
	if (alignment.size() < 1) {
		throw new IndexOutOfBoundsException(
				"No aligned structures, alignment size == 0.");
	}
	if (alignment.getCoreLength() < 1){
		throw new IndexOutOfBoundsException(
				"Alignment too short, core alignment length < 1.");
	}

	List<Atom[]> atomArrays = alignment.getAtomArrays();
	if (atomArrays.size() <= reference) {
		throw new IndexOutOfBoundsException(String.format(
				"Invalid reference structure: requested %d but "
						+ "only %d structures.",
						reference,atomArrays.size()));
	}

	alignment.clear();

	//Calculate BlockSet transformations
	for (BlockSet bs:alignment.getBlockSets()){

		//Block transformations
		List<Matrix4d> transforms =
				new ArrayList<Matrix4d>(atomArrays.size());

		//Loop through structures
		for (int i=0; i<atomArrays.size(); i++){

			if( i == reference) {
				//Identity operation
				Matrix4d ident = new Matrix4d();
				ident.setIdentity();
				transforms.add(ident);
				continue;
			}

			Atom[] ref = atomArrays.get(reference);
			Atom[] curr = atomArrays.get(i);

			List<Atom> atomSet1 = new ArrayList<Atom>();
			List<Atom> atomSet2 = new ArrayList<Atom>();

			for( Block blk : bs.getBlocks() ) {

				if( blk.size() != atomArrays.size()) {
					throw new IllegalStateException(String.format(
							"Mismatched block length. Expected %d "
									+ "structures, found %d.",
									atomArrays.size(),blk.size() ));
				}

				List<Integer> corePositions =
						MultipleAlignmentTools.getCorePositions(blk);

				//Loop through all aligned residues
				for (int j=0; j<blk.length(); j++){
					//Check that the position is in the core
					if (!corePositions.contains(j)) continue;

					Integer pos1 = blk.getAlignRes().get(reference).get(j);
					Integer pos2 = blk.getAlignRes().get(i).get(j);

					if (pos1==null || pos2==null) continue;

					atomSet1.add(ref[pos1]);
					atomSet2.add(curr[pos2]);
				}
			}
			Atom[] array1 = atomSet1.toArray(new Atom[atomSet1.size()]);
			Atom[] array2 = atomSet2.toArray(new Atom[atomSet2.size()]);

			array2 = StructureTools.cloneAtomArray(array2);

			//From the superimposer we obtain the rotation and translation
			Matrix4d trans = SuperPositions.superpose(Calc.atomsToPoints(array1),
					Calc.atomsToPoints(array2));
			transforms.add(trans);
		}
		//Set transformation of the BlockSet
		bs.setTransformations(transforms);
	}
}
 
Example 17
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4d a() {
	Matrix4d var = new Matrix4d();
	var.setIdentity();
	return var;
}
 
Example 18
Source File: SymmetryAxes.java    From biojava with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Return all symmetry axes of of the structure: the set of axes that
 * describe all parts of the structure. This combines the elementary
 * axes to generate all possible axes. The axes are returned in the repeat
 * degrees.
 * @return axes all symmetry axes of the structure.
 */
public List<Axis> getSymmetryAxes(){

	List<Axis> symmAxes = new ArrayList<>();

	Matrix4d prior = new Matrix4d();
	prior.setIdentity();

	getSymmetryAxes(symmAxes,prior,0,0);


	return symmAxes;
}