Example #1
0
        public DensityPoint getCRSFromXYZ(double x, double y, double z)
        {
            EdVector vXYZIn = new EdVector();
            EdVector vCRS   = new EdVector();

            vXYZIn.vector[0] = x;
            vXYZIn.vector[1] = y;
            vXYZIn.vector[2] = z;
            //If the axes are all orthogonal
            if (w14_CELLB_X == 90 && w15_CELLB_Y == 90 && w16_CELLB_Z == 90)
            {
                for (int i = 0; i < 3; ++i)
                {
                    double startVal = vXYZIn.vector[i] - _origin.vector[i];
                    startVal      /= _cellDims[i] / _axisSampling[i];
                    vCRS.vector[i] = startVal;
                }
            }
            else // they are not orthogonal
            {
                EdVector vFraction = _deOrthoMat.multiply(vXYZIn);
                for (int i = 0; i < 3; ++i)
                {
                    double val = vFraction.vector[i] * _axisSampling[i] - _crsStart[_map2xyz[i]];
                    vCRS.vector[i] = val;
                }
            }
            double c = Convert.ToSingle(Math.Round(vCRS.vector[_map2crs[0]], 4));
            double r = Convert.ToSingle(Math.Round(vCRS.vector[_map2crs[1]], 4));
            double s = Convert.ToSingle(Math.Round(vCRS.vector[_map2crs[2]], 4));

            DensityPoint dp = new DensityPoint(c, r, s, 0, "CRS");

            return(dp);
        }
Example #2
0
        private void calculateOrigin()
        {
            // TODO I am ignoring the possibility of passing in the origin for now and using the dot product calc for non orthoganality.
            // The origin is perhaps used for cryoEM only and requires orthoganility

            // CRSSTART is w05_NXSTART, w06_NYSTART, w07_NZSTART
            // Cell dims w08_MX, w09_MY, w10_MZ;
            // Map of indices from crs to xyz is w17_MAPC, w18_MAPR, w19_MAPS

            EdVector vCRS = new EdVector();

            for (int i = 0; i < 3; ++i)
            {
                int startVal = 0;
                if (w17_MAPC == i)
                {
                    startVal = w05_NXSTART;
                }
                else if (w18_MAPR == i)
                {
                    startVal = w06_NYSTART;
                }
                else
                {
                    startVal = w07_NZSTART;
                }

                vCRS.vector[i] = startVal;
            }
            vCRS.vector[0] /= w08_MX;
            vCRS.vector[1] /= w09_MY;
            vCRS.vector[2] /= w10_MZ;

            _origin = _orthoMat.multiply(vCRS);
        }
Example #3
0
 public void movePoint(double distance, EdVector direction)
 {
     //TODO for now just add the amount to every point
     XYZ.x += distance * direction.x;
     XYZ.y += distance * direction.y;
     XYZ.z += distance * direction.z;
 }
Example #4
0
        public EdVector add(EdVector B)
        {
            double px = x + B.x;
            double py = y + B.y;
            double pz = z + B.z;

            return(new EdVector(px, py, pz));
        }
Example #5
0
        public EdVector subtract(EdVector B)
        {
            double px = x - B.x;
            double py = y - B.y;
            double pz = z - B.z;

            return(new EdVector(px, py, pz));
        }
Example #6
0
        public EdVector crossProduct(EdVector B)
        {
            double px = (y * B.z) - (z * B.y);
            double py = (z * B.x) - (x * B.z);
            double pz = (x * B.y) - (y * B.x);

            return(new EdVector(px, py, pz));
        }
Example #7
0
        public EdVector findOrthogonalToLine(EdVector line, EdVector plane)
        {
            EdVector O1 = findOrthogonalToPlane(this, line, plane);
            EdVector V1 = new EdVector(this.x + O1.x, this.y + O1.y, this.z + O1.z);
            EdVector O2 = findOrthogonalToPlane(this, line, V1);

            return(O2);
        }
Example #8
0
        public double distance(EdVector B)
        {
            double px = Math.Pow(x - B.x, 2);
            double py = Math.Pow(y - B.y, 2);
            double pz = Math.Pow(z - B.z, 2);

            return(Math.Sqrt(px + py + pz));
        }
Example #9
0
        public double dotProduct(EdVector B)
        {
            double px = x * B.x;
            double py = y * B.y;
            double pz = z * B.z;

            return(px + py + pz);
        }
Example #10
0
        public EdVector multiply(EdVector v)
        {//http://mlwiki.org/index.php/Matrix-Vector_Multiplication
            EdVector Ax = getColumn(0).scale(v.x);
            EdVector Ay = getColumn(1).scale(v.y);
            EdVector Az = getColumn(2).scale(v.z);
            EdVector A  = Ax.add(Ay).add(Az);

            return(A);
        }
Example #11
0
        public EdVector getColumn(int col)
        {
            EdVector colv = new EdVector();

            colv.vector[0] = matrix[0, col];
            colv.vector[1] = matrix[1, col];
            colv.vector[2] = matrix[2, col];
            return(colv);
        }
Example #12
0
        public EdVector findOrthogonalToPlane(EdVector A, EdVector B, EdVector C)
        {
            EdVector AB = new EdVector(B.x - A.x, B.y - A.y, B.z - A.z);
            EdVector AC = new EdVector(C.x - A.x, C.y - A.y, C.z - A.z);
            EdVector O  = AB.crossProduct(AC);

            O.normalise();
            return(O);
        }
Example #13
0
        public DensityPoint getXYZFromCRS(double c, double r, double s)
        {
            EdVector vXYZ   = new EdVector();
            EdVector vCRSIn = new EdVector();

            vCRSIn.vector[0] = c;
            vCRSIn.vector[1] = r;
            vCRSIn.vector[2] = s;
            //If the axes are all orthogonal
            if (w14_CELLB_X == 90 && w15_CELLB_Y == 90 && w16_CELLB_Z == 90)
            {
                for (int i = 0; i < 3; ++i)
                {
                    double startVal = vCRSIn.vector[_map2xyz[i]];
                    startVal      *= _cellDims[i] / _axisSampling[i];
                    startVal      += _origin.vector[i];
                    vXYZ.vector[i] = startVal;
                }
            }
            else // they are not orthogonal
            {
                EdVector vCRS = new EdVector();
                for (int i = 0; i < 3; ++i)
                {
                    Double startVal = 0;
                    if (w17_MAPC == i)
                    {
                        startVal = w05_NXSTART + c;
                    }
                    else if (w18_MAPR == i)
                    {
                        startVal = w06_NYSTART + r;
                    }
                    else
                    {
                        startVal = w07_NZSTART + s;
                    }

                    vCRS.vector[i] = startVal;
                }
                vCRS.vector[0] /= w08_MX;
                vCRS.vector[1] /= w09_MY;
                vCRS.vector[2] /= w10_MZ;
                vXYZ            = _orthoMat.multiply(vCRS);
            }
            DensityPoint dp = new DensityPoint(Convert.ToSingle(vXYZ.vector[0]), Convert.ToSingle(vXYZ.vector[1]), Convert.ToSingle(vXYZ.vector[2]), 0, "XYZ");

            return(dp);
        }