Exemple #1
0
        public static Vector3 GetCornerPointToAxis(CameraPosition cameraPosition, Quaternion axis, Direction direction)
        {
            // Orientation in Viewing direction
            var a1 = cameraPosition.Width / 2;
            var a2 = cameraPosition.Height / 2;
            var a3 = (double)cameraPosition.FocalLength;

            var angleY = Math.Atan(a1 / a3);
            var angleX = Math.Atan(a2 / a3);

            // Set sign for corner
            switch (direction)
            {
                default:
                case Direction.TopLeft:
                    break;
                case Direction.TopRight:
                    angleX = -angleX;
                    break;
                case Direction.BottomLeft:
                    angleY = -angleY;
                    break;
                case Direction.BottomRight:
                    angleX = -angleX;
                    angleY = -angleY;
                    break;
            }

            // Rotation matrices
            var xm = new SharpDX.Matrix
            {
                M11 = 1,
                M22 = (float)Math.Cos(angleX),
                M32 = (float)Math.Sin(angleX),
                M23 = (float)-Math.Sin(angleX),
                M33 = (float)Math.Cos(angleX)
            };

            var ym = new SharpDX.Matrix
            {
                M11 = (float)Math.Cos(angleY),
                M31 = (float)-Math.Sin(angleY),
                M22 = 1,
                M13 = (float)Math.Sin(angleY),
                M33 = (float)Math.Cos(angleY)
            };

            // Rotate the point by multiplying with quaternion and conjugate of quaternion
            var rot = Quaternion.RotationMatrix(xm) * Quaternion.RotationMatrix(ym) * axis;

            return Rotate(rot, new Vector3(0, 0, 1));
        }
        public static List<CameraPosition> ReadScannerPositions(string file)
        {
            var retList = new List<CameraPosition>();

            string line;
            using (StreamReader reader = new StreamReader(file))
            {
                do
                {
                    line = reader.ReadLine();
                } while (!line.StartsWith("Scans") );

                line = reader.ReadLine();

                do
                {
                    if (line.StartsWith("#"))
                    {
                        line = reader.ReadLine();
                        continue;
                    }

                    var vals = line.Split(' ');
                    var cp = new CameraPosition
                    {
                        Type = CameraPosition.CameraType.Spherical,
                        CameraCenter = new Vector3(float.Parse(vals[1]), float.Parse(vals[3]), -float.Parse(vals[2])),
                        Name = vals[0].Trim('"'),
                        OpeningAngleVerticalTo = -Math.PI/2.0 * 2.0/3.0
                    };

                    cp.Orientation = Quaternion.RotationAxis(
                        new Vector3(
                            float.Parse(vals[4]),
                            float.Parse(vals[6]),
                            -float.Parse(vals[5])),
                        (float)((float.Parse(vals[7])) * Math.PI / 180.0));

                    retList.Add(cp);

                    line = reader.ReadLine();
                } while (!line.StartsWith("}"));
            }

            return retList;
        }