示例#1
0
        public void AngleBetweebVectorTest()
        {
            var v1    = new Vector3d(5, -2, 3);
            var angle = System.Math.Ceiling(v1.AngleInDegrees(new Vector3d(6, 4, -3)));

            System.Diagnostics.Debug.WriteLine(angle);
            Assert.True(angle == 75);
        }
示例#2
0
        void LoadFromSettings()
        {
            loading = true;
            Settings settings = Settings.Get <Settings>();

            if (settings != null)
            {
                this.Enabled = true;
                Vector3d cam = new Vector3d(settings.Read(Settings.CAMERA, Settings.X, 0f), settings.Read(Settings.CAMERA, Settings.Y, 50f), settings.Read(Settings.CAMERA, Settings.Z, 220f));

                SetNumericUpDownValue(this.CameraZ, (decimal)cam.Z);
                SetNumericUpDownValue(this.CameraY, (decimal)cam.Y);
                ILaserProxy laser = Settings.Get <ILaserProxy>();
                if (laser != null)
                {
                    int currentLaser = this.LaserComboBox.Items.Count == 0 ? -1 : this.LaserComboBox.SelectedIndex;
                    int lasercount   = laser.Count;
                    this.LaserComboBox.Items.Clear();
                    for (int i = 0; i < lasercount; i++)
                    {
                        this.LaserComboBox.Items.Add(String.Format("Laser {0}", i));
                    }
                    currentLaser = Math.Max(0, currentLaser);
                    this.LaserComboBox.SelectedIndex = currentLaser;
                    Vector3d laserLoc = new Vector3d(
                        settings.Read(Settings.LASER(currentLaser), Settings.X, 50f),
                        settings.Read(Settings.LASER(currentLaser), Settings.Y, (double)this.CameraY.Value),
                        settings.Read(Settings.LASER(currentLaser), Settings.Z, (double)this.CameraZ.Value)
                        );

                    double angle = laserLoc.AngleInDegrees(cam);
                    if (cam.X < laserLoc.X)
                    {
                        angle = -angle;
                    }

                    SetNumericUpDownValue(this.LaserX, (decimal)laserLoc.X);
                    this.LaserYLabel.Text = string.Format("{0:.0}", laserLoc.Y);
                    SetNumericUpDownValue(this.LaserZ, (decimal)laserLoc.Z);
                    SetNumericUpDownValue(this.LaserAngle, (decimal)angle);
                }
            }
            else
            {
                this.Enabled = false;
            }


            loading = false;
        }
示例#3
0
        void SaveToSettings(bool saveLaser, bool fromLaserPos)
        {
            Settings settings = Settings.Get <Settings>();

            if (settings != null)
            {
                settings.Write(Settings.CAMERA, Settings.Z, (double)this.CameraZ.Value);
                settings.Write(Settings.CAMERA, Settings.Y, (double)this.CameraY.Value);
                if (!saveLaser)
                {
                    for (int i = 0; i < this.LaserComboBox.Items.Count; i++)
                    {
                        settings.Write(Settings.LASER(i), Settings.Y, (double)this.CameraY.Value);
                    }
                }
                else
                {
                    int currentLaser = this.LaserComboBox.Items.Count == 0 ? -1 : this.LaserComboBox.SelectedIndex;
                    if (currentLaser >= 0)
                    {
                        if (fromLaserPos)
                        {
                            settings.Write(Settings.LASER(currentLaser), Settings.X, (double)this.LaserX.Value);
                            settings.Write(Settings.LASER(currentLaser), Settings.Z, (double)this.LaserZ.Value);
                        }
                        else
                        {
                            Vector3d cam      = new Vector3d(settings.Read(Settings.CAMERA, Settings.X, 0f), settings.Read(Settings.CAMERA, Settings.Y, 50f), settings.Read(Settings.CAMERA, Settings.Z, 220f));
                            Vector3d laserLoc = RotateY(cam, (double)LaserAngle.Value);
                            double   angle    = laserLoc.AngleInDegrees(cam);

                            settings.Write(Settings.LASER(currentLaser), Settings.X, laserLoc.X);
                            settings.Write(Settings.LASER(currentLaser), Settings.Z, laserLoc.Z);
                        }
                    }
                }
            }
        }
示例#4
0
        private bool Helper_FindNeighbours(ref List <Vertex> pointsTarget, ref List <Vertex> pointsSource, KDTreeVertex kdTree, int keepOnlyPoints)
        {
            if (!FixedTestPoints)
            {
                if (KDTreeVertex.KDTreeMode == KDTreeMode.Stark)
                {
                    pointsTarget = kdTree.FindNearest_Stark(pointsSource, pointsTarget);
                }
                else if (KDTreeVertex.KDTreeMode == KDTreeMode.Rednaxala)
                {
                    pointsTarget = kdTree.FindNearest_Rednaxela(pointsSource, pointsTarget, keepOnlyPoints);
                }
                else if (KDTreeVertex.KDTreeMode == KDTreeMode.BruteForce)
                {
                    pointsTarget = kdTree.FindNearest_BruteForce(pointsSource, pointsTarget);
                }

                if (NormalsCheck)
                {
                    //adjust normals - because of Search, the number of PointTarget my be different

                    int pointsRemoved = 0;
                    for (int i = pointsTarget.Count - 1; i >= 0; i--)
                    {
                        Vector3d vT = pointsTarget[i].Vector;
                        Vector3d vS = pointsSource[i].Vector;
                        //double angle = Vector3d.CalculateAngle(vT, vS);
                        int      indexVec = pointsTarget[i].IndexInModel;
                        Vector3d vTNormal = NormalsTarget[pointsTarget[i].IndexInModel];
                        //Vector3d vTNormal = NormalsTarget[i];
                        Vector3d vSNormal = NormalsSource[i];

                        double angle = vTNormal.AngleInDegrees(vSNormal);
                        //double angle = vT.AngleInDegrees(vS);
                        if (Math.Abs(angle) > 30)
                        {
                            pointsTarget.RemoveAt(i);
                            pointsSource.RemoveAt(i);
                            pointsRemoved++;
                        }
                    }
                    Debug.WriteLine("--NormalCheck: Removed a total of: " + pointsRemoved.ToString());
                }

                if (pointsTarget.Count != pointsSource.Count)
                {
                    MessageBox.Show("Error finding neighbours, found " + pointsTarget.Count.ToString() + " out of " + pointsSource.Count.ToString());
                    return(false);
                }
            }
            else
            {
                //adjust number of points - for the case if there are outliers
                int min = pointsSource.Count;
                if (pointsTarget.Count < min)
                {
                    min = pointsTarget.Count;
                    pointsSource.RemoveRange(pointsTarget.Count, pointsSource.Count - min);
                }
                else
                {
                    pointsTarget.RemoveRange(pointsSource.Count, pointsTarget.Count - min);
                }
            }
            return(true);
        }
示例#5
0
		void LoadFromSettings()
		{
			loading = true;
			Settings settings = Settings.Get<Settings>();
			if(settings!=null)
			{
				this.Enabled=true;
				Vector3d cam = new Vector3d(settings.Read(Settings.CAMERA, Settings.X, 0f), settings.Read(Settings.CAMERA, Settings.Y, 50f), settings.Read(Settings.CAMERA, Settings.Z, 220f));

				SetNumericUpDownValue(this.CameraZ,(decimal)cam.Z);
				SetNumericUpDownValue(this.CameraY,(decimal)cam.Y);
				ILaserProxy laser = Settings.Get<ILaserProxy>();
				if (laser != null)
				{
					int currentLaser = this.LaserComboBox.Items.Count == 0 ? -1 : this.LaserComboBox.SelectedIndex;
					int lasercount = laser.Count;
					this.LaserComboBox.Items.Clear();
					for (int i = 0; i < lasercount; i++)
					{
						this.LaserComboBox.Items.Add(String.Format("Laser {0}", i));
					}
					currentLaser = Math.Max(0, currentLaser);
					this.LaserComboBox.SelectedIndex = currentLaser;
					Vector3d laserLoc = new Vector3d(
					settings.Read(Settings.LASER(currentLaser), Settings.X, 50f),
					settings.Read(Settings.LASER(currentLaser), Settings.Y, (double)this.CameraY.Value),
					settings.Read(Settings.LASER(currentLaser), Settings.Z, (double)this.CameraZ.Value)
				  );

					double angle = laserLoc.AngleInDegrees(cam);
					if(cam.X < laserLoc.X)
						angle = -angle;

					SetNumericUpDownValue(this.LaserX,(decimal)laserLoc.X);
					this.LaserYLabel.Text = string.Format("{0:.0}",laserLoc.Y);
					SetNumericUpDownValue(this.LaserZ,(decimal)laserLoc.Z);
					SetNumericUpDownValue(this.LaserAngle,(decimal) angle);
				}
			}
			else
				this.Enabled=false;


			loading = false;
		}