Ejemplo n.º 1
0
        private void ParameterControl_OnMouseMove(object sender, MouseEventArgs e)
        {
            Point position = e.GetPosition(this);
            KeyValuePair <int, double> newPosition = new KeyValuePair <int, double>(
                Posit <int> .GetPositFromViewer(position.X, HorizontalScross, ActualWidth, ParameterData.HorizontalTotal).Position,
                ActualHeight - position.Y);

            int    posDelta   = Math.Abs(_mousePosition.Key - newPosition.Key);
            double valueDelta = newPosition.Value - _mousePosition.Value;

            if (newPosition.Key > _mousePosition.Key)
            {
                for (int i = _mousePosition.Key; i <= newPosition.Key; i++)
                {
                    UpdateTargetAndData(position.X, new KeyValuePair <int, double>(
                                            i,
                                            _mousePosition.Value + valueDelta / posDelta * (i - _mousePosition.Key)));
                }
            }
            else if (newPosition.Key < _mousePosition.Key)
            {
                for (int i = newPosition.Key; i <= _mousePosition.Key; i++)
                {
                    UpdateTargetAndData(position.X, new KeyValuePair <int, double>(
                                            i,
                                            _mousePosition.Value - valueDelta / posDelta * (i - _mousePosition.Key)));
                }
            }
            else
            {
                UpdateTargetAndData(position.X, newPosition);
            }

            _mousePosition = newPosition;
        }
Ejemplo n.º 2
0
        public PlaybackView()
        {
            InitializeComponent();

            _timer = new DispatcherTimer(
                TimeSpan.FromSeconds(0.1),
                DispatcherPriority.Normal,
                (sender, args) =>
            {
                if (IsSoundLoaded)
                {
                    PlaybackSlider.Value = Player.Position.TotalMilliseconds;
                    try
                    {
                        SoundPosition =
                            new Posit <double>(Player.NaturalDuration.TimeSpan.TotalMilliseconds,
                                               Player.Position.TotalMilliseconds, 0);
                    }
                    catch (Exception e)
                    {
                        // Ignore
                    }
                }
            },
                Dispatcher.CurrentDispatcher);
        }
Ejemplo n.º 3
0
        public MainForm()
        {
            InitializeComponent();

            posit   = new Posit(positObject, -200);
            coposit = new CoplanarPosit(copositObject, 200);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the smaller of <see cref="Posit8"/> numbers.
        /// </summary>
        /// <param name="x">The first of two <see cref="Posit8"/> numbers to compare.</param>
        /// <param name="y">The second of two <see cref="Posit8"/> numbers to compare.</param>
        /// <returns>
        /// Parameter <paramref name="x"/> or <paramref name="y"/>,
        /// whichever is smaller. If <paramref name="x"/>, <paramref name="y"/>,
        /// or both <paramref name="x"/> and <paramref name="y"/>
        /// are equal to <c>NaR</c>, that value is returned.
        /// </returns>
        public static Posit8 Min(Posit8 x, Posit8 y)
        {
            if (Posit.IsNaR(x) || Posit.IsNaR(y))
            {
                return(Posit8.NaR);
            }

            return(x <= y ? x : y);
        }
Ejemplo n.º 5
0
        private void UpdateTimeLine()
        {
            if (PlaybackView.Current is null || !PlaybackView.Current.IsSoundLoaded ||
                PlaybackView.Current.SoundPosition is null)
            {
                FrameTimeMark.Visibility = Visibility.Collapsed;
                return;
            }
            if (!PlaybackView.Current.IsSoundLoaded)
            {
                return;
            }
            Posit <double> posit = PlaybackView.Current.SoundPosition;

            if (AutoScrollView.Current.IsAutoScrollEnabled)
            {
                Posit <int> conv = new Posit <int>(
                    ParameterData.HorizontalTotal,
                    (int)Math.Floor(posit.Position * ParameterData.HorizontalTotal / posit.Total),
                    0);
                var(v, p) = conv.GetHorizontalPosition(HorizontalScross, ActualWidth, (d, i) => d - i);
                if (v != Visibility.Visible)
                {
                    //FrameTimeMark.Visibility = Visibility.Collapsed;
                    // TODO
                }
                else
                {
                    FrameTimeMark.Visibility = Visibility.Visible;
                    FrameTimeMark.Margin     = new Thickness(p, 0, 0, 0);
                    if (ActualWidth - p < 150 && HorizontalScross.Position + 1200 <= HorizontalScross.Total)
                    {
                        HorizontalScross.Position += 1200;
                    }
                }
            }
            else
            {
                Posit <int> conv = new Posit <int>(
                    ParameterData.HorizontalTotal,
                    (int)Math.Floor(posit.Position * ParameterData.HorizontalTotal / posit.Total),
                    0);
                var(v, p) = conv.GetHorizontalPosition(HorizontalScross, ActualWidth, (d, i) => d - i);
                if (v != Visibility.Visible)
                {
                    FrameTimeMark.Visibility = Visibility.Collapsed;
                }
                else
                {
                    FrameTimeMark.Visibility = Visibility.Visible;
                    FrameTimeMark.Margin     = new Thickness(p, 0, 0, 0);
                }
            }
        }
Ejemplo n.º 6
0
        public Pozlama(PointF[] raw, Rectangle YuzR, Size Boyut)
        {
            this.boyut = Boyut;
            PointF[] giris = KartezyenDuzlemRef(raw, YuzR);
            this.sayac1 = 0;


            isaretle(giris);
            modelOlustur(ortalamaAl(giris));
            posit = new Posit(modelNoktalari.ToArray(), 640.0f);
        }
Ejemplo n.º 7
0
 public double Distance(Posit pos1, Posit pos2)
 {
     double R = 6371;
     double dLat = this.toRadian(pos2.Latitude - pos1.Latitude);
     double dLon = this.toRadian(pos2.Longitude - pos1.Longitude);
     double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
         Math.Cos(this.toRadian(pos1.Latitude)) * Math.Cos(this.toRadian(pos2.Latitude)) *
         Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
     double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
     double d = R * c;
     return d;
 }
Ejemplo n.º 8
0
        static void bitStepTest()
        {
            //Posit a = Posit.maxPos(5, 1);
            //a.sign = true;
            Posit a = Posit.Zero(5, 1);

            for (int i = 0; i < 16; ++i)
            {
                Console.WriteLine(string.Format("{0}: {1} = float:{2} = calc:{3}", i, a, a.ToFloat(), a.CalculatedValue()));
                a = a.BitStep(1);
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            /*
             * BitLattice bitLattice = new BitLattice(32);
             *
             * bitLattice.AddField("test", 12, 8);
             *
             * bitLattice.SetUInt("test", 123);
             *
             * Console.WriteLine(bitLattice.GetUInt("test"));
             * Console.Write(bitLattice);
             */

            /*
             * float x = 0.15625f;
             * BitLattice bitLattice = new BitLattice(BitConverter.GetBytes(x));
             * bitLattice.AddField("S", 31, 1);
             * bitLattice.AddField("Exponent", 23, 8);
             * bitLattice.AddField("Fraction", 0, 23);
             *
             * Console.WriteLine(bitLattice);
             * Console.WriteLine();
             * int es = 0;
             * Posit p = new Posit(32, es);
             * p.IntSign = 1;
             * p.regime = 4;
             * p.exponent = 17;
             * p.fraction = 123;
             *
             * BitLattice pbl = p.Encode();
             * Console.WriteLine(pbl);
             * BitArray pbr = pbl.ToBitArray();
             *
             * Posit p2 = new Posit(pbr, es);
             * BitLattice pbl2 = p2.Encode();
             * Console.WriteLine(pbl2);
             */

            //positTestCalcValue();
            //positTestFromFloat();
            //addTest();
            //testDiv();

            //bitStepTest();

            Posit p = new Posit(16, 4);

            p.fraction = 14986789;
            p.regime   = -1;
            p.exponent = 5;
            Console.WriteLine(string.Format("{0} = {1}", p, p.CalculatedValue()));
            Console.WriteLine(p.Encode());
        }
Ejemplo n.º 10
0
        static void lossTest()
        {
            List <Posit> allPos = new List <Posit>();
            Posit        a      = Posit.Zero(5, 1);

            allPos.Add(a);
            for (int i = 0; i < 16; ++i)
            {
                a = a.BitStep(1);
                allPos.Add(a);
            }
        }
Ejemplo n.º 11
0
        public double Distance(Posit pos1, Posit pos2)
        {
            double R    = 6371;
            double dLat = this.toRadian(pos2.Latitude - pos1.Latitude);
            double dLon = this.toRadian(pos2.Longitude - pos1.Longitude);
            double a    = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                          Math.Cos(this.toRadian(pos1.Latitude)) * Math.Cos(this.toRadian(pos2.Latitude)) *
                          Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
            double d = R * c;

            return(d);
        }
Ejemplo n.º 12
0
        private void ParameterControl_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point position = e.GetPosition(this);

            if (_isMouseDown)
            {
                return;
            }
            if (EditMode.Mode == EditModeEnum.Playback)
            {
                PlaybackView.Current.SetPosition(Posit <int> .GetPositFromViewer(position.X, HorizontalScross,
                                                                                 ActualWidth, ParameterData.HorizontalTotal));
            }
            _isMouseDown = true;
        }
Ejemplo n.º 13
0
        private async void AppBarButton_Click_1(object sender, RoutedEventArgs e)
        {
            pr.IsActive       = true;
            intro.Visibility  = Visibility.Collapsed;
            intro1.Visibility = Visibility.Collapsed;
            feed.Visibility   = Visibility.Visible;
            MobileServiceCollection <questions, questions> user;
            IMobileServiceTable <questions> userTable = App.MobileService.GetTable <questions>();

            user = await userTable.ToCollectionAsync();

            Logic();
            ourlistview.ItemsSource = user;
            // ourlistview.ItemsSource = myList;
            pr.IsActive = false;
        }
Ejemplo n.º 14
0
        //  users un;
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            useridnew = (String)e.Parameter;
            Geoposition pos = await loc.GetGeopositionAsync();

            lat  = pos.Coordinate.Latitude;
            lon  = pos.Coordinate.Longitude;
            user = new Posit(lat, lon);

            /*IEnumerable<double> latitemp = (await App.MobileService.GetTable<questions>()
             *                              .Select(questions => questions.location_latitude)
             *                              .ToListAsync());
             * IEnumerable<double> longitemp = (await App.MobileService.GetTable<questions>()
             *                          .Select(questions => questions.location_longitude)
             *                          .ToListAsync());
             *
             * for(int i=0;i<latitemp.Count();i++)
             * {
             * Posit a = new Posit(latitemp.ElementAt(i), longitemp.ElementAt(i));
             * }*/
        }
Ejemplo n.º 15
0
        static void positTestCalcValue()
        {
            //BitLattice bl = new BitLattice(16);
            //bl.AddField(Posit.SignField, bl.Size - 1, 1);
            //bl.AddField(Posit.RegimeField)
            BitArray br = new BitArray(16);

            byte[] bits = new byte[16] {
                1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0
            };
            for (int i = 0; i < bits.Length; ++i)
            {
                br.Set(i, bits[i] > 0);
            }

            Posit      p  = new Posit(br, 3);
            BitLattice bl = p.Encode();

            Console.WriteLine(string.Format("Value = {0}", p.CalculatedValue()));
            Console.WriteLine(bl);
        }
Ejemplo n.º 16
0
        public async void Logic()
        {
            List <questions> quest = (await App.MobileService.GetTable <questions>().ToListAsync());

            foreach (var item in quest)
            {
                double lat = item.location_latitude;
                double lon = item.location_longitude;
                Posit  a   = new Posit(lat, lon);

                if (item.radius == -1)
                {
                    myList.Add(item);
                }

                if (Distance(user, a) < item.radius)
                {
                    myList.Add(item);
                }
            }
        }
Ejemplo n.º 17
0
      //  users un;
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {

            useridnew = (String)e.Parameter;
            Geoposition pos = await loc.GetGeopositionAsync();
            lat=pos.Coordinate.Latitude;
            lon=pos.Coordinate.Longitude;
            user = new Posit(lat, lon);

            /*IEnumerable<double> latitemp = (await App.MobileService.GetTable<questions>()
                                            .Select(questions => questions.location_latitude)
                                            .ToListAsync());
            IEnumerable<double> longitemp = (await App.MobileService.GetTable<questions>()
                                        .Select(questions => questions.location_longitude)
                                        .ToListAsync());

            for(int i=0;i<latitemp.Count();i++)
           {
               Posit a = new Posit(latitemp.ElementAt(i), longitemp.ElementAt(i));
           }*/
        }
Ejemplo n.º 18
0
        public float[] rotasyon(PointF[] giris, Rectangle YuzR)
        {
            int CX = boyut.Width / 2;
            int CY = boyut.Height / 2;



            PointF[] giris2 = (PointF[])giris.Clone();
            if (sayac1 < 10)
            {
                PointF[] islenmis = KartezyenDuzlemRef(giris2, YuzR);
                isaretle(islenmis);
                modelOlustur(ortalamaAl(islenmis));
                posit = new Posit(modelNoktalari.ToArray(), 640.0f);
                sayac1++;
            }



            List <AForge.Point> ara = ortalamaAl(kartezyen(giris2));


            float[] sonuc = new float[3];
            posit.EstimatePose(ara.ToArray(), out this.Rotation, out this.Translation);
            this.Rotation.ExtractYawPitchRoll(out sonuc[0], out sonuc[1], out sonuc[2]);

            for (int i = 0; i < sonuc.Length; i++)
            {
                sonuc[i] *= (float)(180 / Math.PI);
            }

            sonuc[0]  = sonuc[0] / 1.5f;
            sonuc[1] += 0;

            return(sonuc);
        }
Ejemplo n.º 19
0
        static void positTestFromFloat()
        {
            //float x = 0.15625f;
            float      x   = -27.413f;
            BitLattice fbl = new BitLattice(BitConverter.GetBytes(x));

            fbl.AddField("S", 31, 1);
            fbl.AddField("Exponent", 23, 8);
            fbl.AddField("Fraction", 0, 23);

            Console.WriteLine(fbl);
            Console.WriteLine();

            Posit      p   = new Posit(x, 3);
            BitLattice pbl = p.Encode();

            Console.WriteLine(pbl);
            Console.WriteLine();
            BitLattice p2fbl;
            float      x2 = p.ToFloat(out p2fbl);

            Console.WriteLine(p2fbl);
            Console.WriteLine(string.Format("\nf = {0} p = {1} x2 = {2}", x, p.CalculatedValue(), x2));
        }
Ejemplo n.º 20
0
 public bool Equal(Posit p)
 {
     return(p.p == _Point);
 }
Ejemplo n.º 21
0
 public static bool Equal(Posit p1, Posit p2)
 {
     return((p1.x == p2.x) && (p1.z == p2.z));
 }
Ejemplo n.º 22
0
        static void addTest()
        {
            float af = 5.23f;  //-5.23f;//0.15625f;
            float bf = 49.11f; //49.1f;//-0.153f;
            float tf = 54.34f;

            Posit a = new Posit(af, 3);
            //a.fraction = 1;
            //a.exponent = 3;
            Posit b = new Posit(bf, 3);
            //b.fraction = 2;
            //b.exponent = 3;


            Posit t = new Posit(tf, 3); //[(+) reg=-1 exp=5 frac=125292250]
            //t.regime = -1;
            //t.exponent = 5;
            //t.fraction =
            BitLattice blt = t.Encode();

            Console.WriteLine(string.Format("test={0} calc={1} tofloat={2} posit={3}", tf, t.CalculatedValue(), t.ToFloat(), t));
            Console.WriteLine(blt);

            /*
             * blt[1] = true;
             * t.Decode(blt);
             * //t.regime = -1;
             * //t.exponent = 5;
             * //t.fraction = 125292250;
             * blt = t.Encode();
             * Console.WriteLine(string.Format("\ntest={0} calc={1} tofloat={2} posit={3}", tf, t.CalculatedValue(), t.ToFloat(), t));
             * Console.WriteLine(blt);
             */

            /*
             * t.regime = -1;
             * t.exponent = 5;
             * t.fraction = 125292250;
             * blt = t.Encode();
             * Console.WriteLine(string.Format("\ntest={0} calc={1} tofloat={2} posit={3}", tf, t.CalculatedValue(), t.ToFloat(), t));
             * Console.WriteLine(blt);
             */

            Posit c = a + b;

            BitLattice bla = a.Encode();
            BitLattice blb = b.Encode();
            BitLattice blc = c.Encode();

            Console.WriteLine(string.Format("\n\nfloat   {0} + {1} = {2}", af, bf, af + bf));
            Console.WriteLine(string.Format("calc    {0} + {1} = {2}", a.CalculatedValue(), b.CalculatedValue(), c.CalculatedValue()));
            Console.WriteLine(string.Format("tofloat {0} + {1} = {2}", a.ToFloat(), b.ToFloat(), c.ToFloat()));
            Console.WriteLine(string.Format("posit   {0} + {1} = {2}", a, b, c));

            Console.WriteLine("\na = " + a.CalculatedValue());
            Console.WriteLine(bla);
            Console.WriteLine("\nb = " + b.CalculatedValue());
            Console.WriteLine(blb);
            Console.WriteLine("\na + b = " + c.CalculatedValue());
            Console.WriteLine(blc);
        }
Ejemplo n.º 23
0
        private async void AppBarButton_Click_1(object sender, RoutedEventArgs e)
        {
            pr.IsActive = true;
            intro.Visibility = Visibility.Collapsed;
            intro1.Visibility = Visibility.Collapsed;
            feed.Visibility = Visibility.Visible;
        MobileServiceCollection<questions, questions> user;
        IMobileServiceTable<questions> userTable = App.MobileService.GetTable<questions>();

           user = await userTable.ToCollectionAsync();
           
        Logic();
        ourlistview.ItemsSource = user;
       // ourlistview.ItemsSource = myList;
            pr.IsActive = false;
            
        }
Ejemplo n.º 24
0
        public async void Logic()
        {
            List<questions> quest = (await App.MobileService.GetTable<questions>().ToListAsync());

            foreach (var item in quest)
            {
                double lat = item.location_latitude;
                double lon = item.location_longitude;
                Posit a = new Posit(lat, lon);

                if (item.radius == -1)
                {
                    myList.Add(item);

                }

                if (Distance(user, a) < item.radius)
                {
                    myList.Add(item);
                }

            }

        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            PlayController playController = new PlayController();

            while (true)
            {
                Console.WriteLine($"Вы игрок {playController.CurrentPlayer.Name}");
                //список(список где 0 элемент откуда вожможно движени, а дальше куда)
                var Pos = playController.GetPossibleMoves();
                //список(список где 0 элемент откуда должно движени, а дальше куда)
                var Jump = playController.GetJump();



                List <int> Posit;
                Console.WriteLine();
                Draw(playController);
                if (Jump != null)
                {
                    Console.WriteLine("Должен бить:");
                    Posit = Jump.ConvertAll(j => j[0]);
                }
                else
                {
                    Console.WriteLine("Введи откуда пойдешь:");
                    Posit = Pos.ConvertAll(p => p[0]);
                }

                ////Список всех возможных фигуг двигающиеся
                //var Posit = Pos.ConvertAll(p => p[0]);
                ////Список все возможных движений
                //var Jumpt = Jump.ConvertAll(j => j[0]);

                int pos;
                while (!int.TryParse(Console.ReadLine(), out pos) || !Posit.Contains(pos))
                {
                    Console.WriteLine("Неверно");
                }
                //Список все возможных движений
                //var Positio = Pos.Find(p=>p[0]==pos).Skip(1);

                List <int> Positio;
                if (Jump != null)
                {
                    Console.WriteLine("Введи кого будешь бить пойдешь");
                    Positio = Jump.FindAll(j => j[0] == pos).Select(j => j[1]).ToList();
                }
                else
                {
                    Console.WriteLine("Введи куда пойдешь");
                    Positio = Pos.Find(p => p[0] == pos).Skip(1).ToList();
                }

                int posnew;
                while (!int.TryParse(Console.ReadLine(), out posnew) || !Positio.Contains(posnew))
                {
                    Console.WriteLine("Неверно");
                }
                playController.Move(pos, posnew);
                playController.ChangePlayer();
            }



            Console.ReadLine();
        }
Ejemplo n.º 26
0
        private void UpdateData(double x, KeyValuePair <int, double> position)
        {
            if (_target is null)
            {
                return;
            }

            if (!_isMouseDown)
            {
                // Idle
                // TODO
                return;
            }
            switch (EditMode.Mode)
            {
            case EditModeEnum.Pencil:
            {
                if (_hitTarget)
                {
                    _target.Value.Position = Posit <double> .GetValueFromViewer(position.Value, VerticalScross,
                                                                                ActualHeight, ParameterData.VerticalTotal).Position;

                    UpdateView();
                }
                else
                {
                    Models.Parameter parameter = new Models.Parameter(
                        new Posit <int>(ParameterData.HorizontalTotal, position.Key, 0),
                        Posit <double> .GetValueFromViewer(position.Value, VerticalScross, ActualHeight, ParameterData.VerticalTotal));
                    ParameterData.ParameterList.Add(parameter);
                    FrameParameterContainer.Children.Add(parameter);
                    UpdateView();
                }
                break;
            }

            case EditModeEnum.Eraser:
            {
                if (_hitTarget)
                {
                    FrameParameterContainer.Children.Remove(_target);
                    ParameterData.ParameterList.Remove(_target);
                    UpdateView();
                }
                break;
            }

            case EditModeEnum.Playback:
            {
                PlaybackView.Current.SetPosition(Posit <int> .GetPositFromViewer(x, HorizontalScross,
                                                                                 ActualWidth, ParameterData.HorizontalTotal));
                break;
            }

            default:     // Arrow
            {
                DragRect(x);
                break;
            }
            }
        }
Ejemplo n.º 27
0
 public Parameter(Posit <int> position, Posit <double> value)
     : base(position)
 {
     _value = value;
 }
Ejemplo n.º 28
0
        // Estimate 3D position
        private void EstimatePose( )
        {
            try
            {
                // check if all image coordinates are specified
                if ((string.IsNullOrEmpty(imagePoint1Box.Text)) ||
                    (string.IsNullOrEmpty(imagePoint2Box.Text)) ||
                    (string.IsNullOrEmpty(imagePoint3Box.Text)) ||
                    (string.IsNullOrEmpty(imagePoint4Box.Text)))
                {
                    throw new ApplicationException("Some image coordinates are not specified.");
                }

                // check if all model coordnates are specified
                if ((string.IsNullOrEmpty(modelPoint1xBox.Text)) ||
                    (string.IsNullOrEmpty(modelPoint2xBox.Text)) ||
                    (string.IsNullOrEmpty(modelPoint3xBox.Text)) ||
                    (string.IsNullOrEmpty(modelPoint4xBox.Text)) ||
                    (string.IsNullOrEmpty(modelPoint1yBox.Text)) ||
                    (string.IsNullOrEmpty(modelPoint2yBox.Text)) ||
                    (string.IsNullOrEmpty(modelPoint3yBox.Text)) ||
                    (string.IsNullOrEmpty(modelPoint4yBox.Text)) ||
                    ((!useCoplanarPosit) && (
                         (string.IsNullOrEmpty(modelPoint1zBox.Text)) ||
                         (string.IsNullOrEmpty(modelPoint2zBox.Text)) ||
                         (string.IsNullOrEmpty(modelPoint3zBox.Text)) ||
                         (string.IsNullOrEmpty(modelPoint4zBox.Text)))))
                {
                    throw new ApplicationException("Some model coordinates are not specified.");
                }

                // calculate model's center
                Vector3 modelCenter = new Vector3(
                    (modelPoints[0].X + modelPoints[1].X + modelPoints[2].X + modelPoints[3].X) / 4,
                    (modelPoints[0].Y + modelPoints[1].Y + modelPoints[2].Y + modelPoints[3].Y) / 4,
                    (modelPoints[0].Z + modelPoints[1].Z + modelPoints[2].Z + modelPoints[3].Z) / 4
                    );

                // calculate ~ model's radius
                modelRadius = 0;
                foreach (Vector3 modelPoint in modelPoints)
                {
                    float distanceToCenter = (modelPoint - modelCenter).Norm;
                    if (distanceToCenter > modelRadius)
                    {
                        modelRadius = distanceToCenter;
                    }
                }

                if (!useCoplanarPosit)
                {
                    Posit posit = new Posit(modelPoints, focalLength);
                    posit.EstimatePose(imagePoints, out rotationMatrix, out translationVector);

                    bestPoseButton.Visible = alternatePoseButton.Visible = false;
                }
                else
                {
                    CoplanarPosit coposit = new CoplanarPosit(modelPoints, focalLength);
                    coposit.EstimatePose(imagePoints, out rotationMatrix, out translationVector);

                    bestRotationMatrix    = coposit.BestEstimatedRotation;
                    bestTranslationVector = coposit.BestEstimatedTranslation;

                    alternateRotationMatrix    = coposit.AlternateEstimatedRotation;
                    alternateTranslationVector = coposit.AlternateEstimatedTranslation;

                    bestPoseButton.Visible = alternatePoseButton.Visible = true;
                }

                isPoseEstimated = true;
                UpdateEstimationInformation( );
                pictureBox.Invalidate( );
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 29
0
 protected MusiqualControl(Posit <int> position)
 {
     _position = position;
 }