private void NewHeightMapDialog_Size_Ok()
		{
			if (machine.Mode == Machine.OperatingMode.Probe || Map != null)
				return;

			Map = new HeightMap(NewHeightMapDialog.GridSize, NewHeightMapDialog.Min, NewHeightMapDialog.Max);
			
			if (NewHeightMapDialog.GenerateTestPattern)
			{
				try
				{
					Map.FillWithTestPattern(NewHeightMapDialog.TestPattern);
					Map.NotProbed.Clear();
				}
				catch { MessageBox.Show("Error in test pattern"); }
			}

			Map.MapUpdated += Map_MapUpdated;
			UpdateProbeTabButtons();
			Map_MapUpdated();
		}
Esempio n. 2
0
		public GCodeFile ApplyHeightMap(HeightMap map)
		{
			double segmentLength = Math.Min(map.GridX, map.GridY);

			List<Command> newToolPath = new List<Command>();

			foreach (Command command in Toolpath)
			{
				if (command is MCode)
				{
					newToolPath.Add(command);
					continue;
				}
				else
				{
					Motion m = (Motion)command;

					foreach (Motion subMotion in m.Split(segmentLength))
					{
						subMotion.Start.Z += map.InterpolateZ(subMotion.Start.X, subMotion.Start.Y);
						subMotion.End.Z += map.InterpolateZ(subMotion.End.X, subMotion.End.Y);

						newToolPath.Add(subMotion);
					}
				}
			}

			return new GCodeFile(newToolPath);
		}
Esempio n. 3
0
        public static HeightMap Load(string path)
        {
            HeightMap map = new HeightMap();

            XmlReader r = XmlReader.Create(path);

            while (r.Read())
            {
                if (!r.IsStartElement())
                {
                    continue;
                }

                switch (r.Name)
                {
                case "heightmap":
                    map.Min    = new Vector2(double.Parse(r["MinX"], Constants.DecimalParseFormat), double.Parse(r["MinY"], Constants.DecimalParseFormat));
                    map.Max    = new Vector2(double.Parse(r["MaxX"], Constants.DecimalParseFormat), double.Parse(r["MaxY"], Constants.DecimalParseFormat));
                    map.SizeX  = int.Parse(r["SizeX"]);
                    map.SizeY  = int.Parse(r["SizeY"]);
                    map.Points = new double?[map.SizeX, map.SizeY];
                    break;

                case "point":
                    int    x = int.Parse(r["X"]), y = int.Parse(r["Y"]);
                    double height = double.Parse(r.ReadInnerXml(), Constants.DecimalParseFormat);

                    map.Points[x, y] = height;

                    if (height > map.MaxHeight)
                    {
                        map.MaxHeight = height;
                    }
                    if (height < map.MinHeight)
                    {
                        map.MinHeight = height;
                    }

                    break;
                }
            }

            r.Dispose();

            for (int x = 0; x < map.SizeX; x++)
            {
                for (int y = 0; y < map.SizeY; y++)
                {
                    if (!map.Points[x, y].HasValue)
                    {
                        map.NotProbed.Enqueue(new Tuple <int, int>(x, y));
                    }
                }

                if (++x >= map.SizeX)
                {
                    break;
                }

                for (int y = map.SizeY - 1; y >= 0; y--)
                {
                    if (!map.Points[x, y].HasValue)
                    {
                        map.NotProbed.Enqueue(new Tuple <int, int>(x, y));
                    }
                }
            }

            return(map);
        }
Esempio n. 4
0
		public static HeightMap Load(string path)
		{
			HeightMap map = new HeightMap();

			XmlReader r = XmlReader.Create(path);

			while (r.Read())
			{
				if (!r.IsStartElement())
					continue;

				switch (r.Name)
				{
					case "heightmap":
						map.Min = new Vector2(double.Parse(r["MinX"], Constants.DecimalParseFormat), double.Parse(r["MinY"], Constants.DecimalParseFormat));
						map.Max = new Vector2(double.Parse(r["MaxX"], Constants.DecimalParseFormat), double.Parse(r["MaxY"], Constants.DecimalParseFormat));
						map.SizeX = int.Parse(r["SizeX"]);
						map.SizeY = int.Parse(r["SizeY"]);
						map.Points = new double?[map.SizeX, map.SizeY];
						break;
					case "point":
						int x = int.Parse(r["X"]), y = int.Parse(r["Y"]);
						double height = double.Parse(r.ReadInnerXml(), Constants.DecimalParseFormat);

						map.Points[x, y] = height;

						if (height > map.MaxHeight)
							map.MaxHeight = height;
						if (height < map.MinHeight)
							map.MinHeight = height;

						break;
				}
			}

			r.Dispose();

			for (int x = 0; x < map.SizeX; x++)
			{
				for (int y = 0; y < map.SizeY; y++)
					if (!map.Points[x, y].HasValue)
						map.NotProbed.Enqueue(new Tuple<int, int>(x, y));

				if (++x >= map.SizeX)
					break;

				for (int y = map.SizeY - 1; y >= 0; y--)
					if (!map.Points[x, y].HasValue)
						map.NotProbed.Enqueue(new Tuple<int, int>(x, y));
			}

			return map;
		}