001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.structure.geometry;
022
023import javax.vecmath.Matrix4d;
024import javax.vecmath.Point3d;
025
026/**
027 * The SuperPositionAbstract contains common code shared by all SuperPosition
028 * algorithm implementations.
029 *
030 * @author Aleix Lafita
031 * @since 5.0.0
032 *
033 */
034public abstract class SuperPositionAbstract implements SuperPosition {
035
036        protected boolean centered;
037
038        public SuperPositionAbstract(boolean centered) {
039                this.centered = centered;
040        }
041
042        @Override
043        public Matrix4d superposeAndTransform(Point3d[] fixed, Point3d[] moved) {
044                Matrix4d rotTrans = superpose(fixed, moved);
045                CalcPoint.transform(rotTrans, moved);
046                return rotTrans;
047        }
048
049        /**
050         * Check that the input to the superposition algorithms is valid.
051         *
052         * @param fixed
053         * @param moved
054         */
055        protected void checkInput(Point3d[] fixed, Point3d[] moved) {
056                if (fixed.length != moved.length)
057                        throw new IllegalArgumentException(
058                                        "Point arrays to superpose are of different lengths.");
059        }
060
061        /**
062         * @param centered
063         *            true if the point arrays are centered at the origin (faster),
064         *            false otherwise
065         */
066        public void setCentered(boolean centered) {
067                this.centered = centered;
068        }
069
070}