public static Bitmap MakeBlendMap(ProjectorEntry pe, int blur, int blurIterations, float gamma) { BlendPoint pnt = new BlendPoint(); Bitmap bmpBlend = new Bitmap(512, 512); double xFactor = 512.0 / pe.Width; double yFactor = 512.0 / pe.Height; Graphics g = Graphics.FromImage(bmpBlend); g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; List <PointF> points = new List <PointF>(); foreach (BlendPoint bp in pe.BlendPolygon) { points.Add(new PointF((float)(bp.X * xFactor), (float)(bp.Y * yFactor))); } Brush brush = new SolidBrush(Color.FromArgb(255, Gamma(pe.WhiteBalance.Red, gamma), Gamma(pe.WhiteBalance.Green, gamma), Gamma(pe.WhiteBalance.Blue, gamma))); if (points.Count < 3) { g.Clear(Color.White); } else { g.Clear(Color.Black); g.FillPolygon(brush, points.ToArray()); } g.Flush(); g.Dispose(); g = null; brush.Dispose(); for (int i = 0; i < blurIterations; i++) { BlurBitmap(bmpBlend, blur); } bmpBlend = GammaBmp(bmpBlend, gamma); return(bmpBlend); }
public static Bitmap MakeBlendMap(ProjectorEntry pe, int blur, int blurIterations, float gamma) { BlendPoint pnt = new BlendPoint(); Bitmap bmpBlend = new Bitmap(512, 512); double xFactor = 512.0/pe.Width; double yFactor = 512.0/pe.Height; Graphics g = Graphics.FromImage(bmpBlend); g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; List<PointF> points = new List<PointF>(); foreach (BlendPoint bp in pe.BlendPolygon) { points.Add(new PointF((float)(bp.X*xFactor), (float)(bp.Y*yFactor))); } Brush brush = new SolidBrush(Color.FromArgb(255, Gamma(pe.WhiteBalance.Red, gamma), Gamma(pe.WhiteBalance.Green, gamma), Gamma(pe.WhiteBalance.Blue, gamma))); if (points.Count < 3) { g.Clear(Color.White); } else { g.Clear(Color.Black); g.FillPolygon(brush, points.ToArray()); } g.Flush(); g.Dispose(); g = null; brush.Dispose(); for (int i = 0; i < blurIterations; i++) { BlurBitmap(bmpBlend, blur); } bmpBlend = GammaBmp(bmpBlend, gamma); return bmpBlend; }
private void TransferEdges(ProjectorEntry pe) { var pointList = new SortedList<double, BlendPoint>(); foreach (var edge in CalibrationInfo.Edges) { var right = false; if (edge.Right == pe.ID) { right = true; } else if (edge.Left != pe.ID) { continue; } foreach (var edgePoint in edge.Points) { if (!edgePoint.Blend) { continue; } var pnt = right ? edgePoint.Right : edgePoint.Left; var blend = new BlendPoint {X = pnt.X, Y = pnt.Y}; var angle = Math.Atan2(pnt.X - (pe.Width / 2.0), pnt.Y - (pe.Height / 2.0)); if (!pointList.ContainsKey(angle)) { pointList.Add(angle, blend); } } } foreach (var blend in pointList.Values) { pe.BlendPolygon.Add(blend); } }
private void AddPointToTree() { if (PointTree.SelectedNode == null) { return; } if (Align.Selected) { // Code to build sets of points //if (Control.ModifierKeys == Keys.Alt || Control.ModifierKeys == (Keys.Alt | Keys.Shift)) //{ // bool North = Control.ModifierKeys == (Keys.Alt | Keys.Shift); // if (PointTree.SelectedNode.Tag is ProjectorEntry) // { // Random rnd = new Random(); // ProjectorEntry pe = PointTree.SelectedNode.Tag as ProjectorEntry; // for (double alt = 0; alt < 90; alt+=15) // { // //double alt = alts[i]; // double steps = 25; // //if (i == 3) // //{ // // steps = 5; // //} // for (double az = 0; az < 360; az += 360 / steps) // { // GroundTruthPoint pnt = new GroundTruthPoint(); // int cX = pe.Width / 2; // int cY = pe.Height / 2; // cY = 120; // double rad = pe.Height / 2; // rad = pe.Width / 2; // double az2 = az - 90; // pnt.X = cX + (float)Math.Cos(az2 / 180 * Math.PI) * ((90 - alt) / 90) * rad; // pnt.Y = cY - (float)Math.Sin(az2 / 180 * Math.PI) * ((90 - alt) / 90) * rad; // pnt.X += rnd.NextDouble() / 1000f; // pnt.Y += rnd.NextDouble() / 1000f; // //pnt.X = pe.Width / 2; // //pnt.Y = pe.Height / 2; // pnt.Alt = alt; // pnt.Az = az; // pnt.AxisType = AxisTypes.Both; // if (pnt.Y > 0) // { // pe.Constraints.Add(pnt); // pe.SelectedGroundTruth = pe.Constraints.Count - 1; // TreeNode child = PointTree.SelectedNode.Nodes.Add(pnt.ToString()); // child.Tag = pnt; // } // } // } // } if (ModifierKeys == Keys.Alt || ModifierKeys == (Keys.Alt | Keys.Shift)) { if (PointTree.SelectedNode.Tag is ProjectorEntry) { var pe = PointTree.SelectedNode.Tag as ProjectorEntry; for (var i = 0; i < 4; i++) { var alt = alts[i]; double steps = 25; if (i == 3) { steps = 5; } for (var az = 7.2; az < 360; az += 360 / steps) { var pnt = new GroundTruthPoint { X = pe.Width/2.0, Y = pe.Height/2.0, Alt = alt, Az = az, AxisType = AxisTypes.Both }; if (altCenter[pe.ID - 1] < 70) { if (((Math.Abs(az - centers[pe.ID - 1]) < 55) || (Math.Abs((az - 360) - centers[pe.ID - 1]) < 55)) && alt < 75) { pe.Constraints.Add(pnt); pe.SelectedGroundTruth = pe.Constraints.Count - 1; var child = PointTree.SelectedNode.Nodes.Add(pnt.ToString()); child.Tag = pnt; } } else if (altCenter[pe.ID - 1] == 70) { if (((Math.Abs(az - centers[pe.ID - 1]) < 95) || (Math.Abs((az - 360) - centers[pe.ID - 1]) < 95)) && alt > 25) { pe.Constraints.Add(pnt); pe.SelectedGroundTruth = pe.Constraints.Count - 1; var child = PointTree.SelectedNode.Nodes.Add(pnt.ToString()); child.Tag = pnt; } } } } } return; } if (PointTree.SelectedNode.Tag is ProjectorEntry) { var pe = PointTree.SelectedNode.Tag as ProjectorEntry; var props = new GroundTruthPointProperties(); var pnt = new GroundTruthPoint {X = pe.Width/2.0, Y = pe.Height/2.0}; props.Target = pnt; if (props.ShowDialog() == DialogResult.OK) { pe.Constraints.Add(pnt); pe.SelectedGroundTruth = pe.Constraints.Count - 1; var child = PointTree.SelectedNode.Nodes.Add(pnt.ToString()); child.Tag = pnt; PointTree.SelectedNode = child; } return; } var groundTruthPoint = PointTree.SelectedNode.Tag as GroundTruthPoint; if (groundTruthPoint != null) { var pe = PointTree.SelectedNode.Parent.Tag as ProjectorEntry; var props = new GroundTruthPointProperties(); var pnt = new GroundTruthPoint {X = pe.Width/2.0, Y = pe.Height/2.0}; props.Target = pnt; if (props.ShowDialog() == DialogResult.OK) { var index = pe.Constraints.IndexOf(groundTruthPoint) + 1; pe.Constraints.Insert(index, pnt); var child = PointTree.SelectedNode.Parent.Nodes.Insert(PointTree.SelectedNode.Index + 1, pnt.ToString()); child.Tag = pnt; PointTree.SelectedNode = child; } return; } if (PointTree.SelectedNode.Tag is Edge) { var edge = PointTree.SelectedNode.Tag as Edge; var ep = new EdgePoint {Left = new GroundTruthPoint(), Right = new GroundTruthPoint()}; ep.Left.X = CalibrationInfo.ProjLookup[edge.Left].Width / 2.0; ep.Left.Y = CalibrationInfo.ProjLookup[edge.Left].Height / 2.0; ep.Right.X = CalibrationInfo.ProjLookup[edge.Left].Width / 2.0; ep.Right.Y = CalibrationInfo.ProjLookup[edge.Left].Height / 2.0; edge.Points.Add(ep); var child = PointTree.SelectedNode.Nodes.Add(ep.ToString()); child.Tag = ep; PointTree.SelectedNode = child; return; } if (PointTree.SelectedNode.Tag is EdgePoint) { var edge = PointTree.SelectedNode.Parent.Tag as Edge; var ep = new EdgePoint {Left = new GroundTruthPoint(), Right = new GroundTruthPoint()}; ep.Left.X = CalibrationInfo.ProjLookup[edge.Left].Width / 2.0; ep.Left.Y = CalibrationInfo.ProjLookup[edge.Left].Height / 2.0; ep.Right.X = CalibrationInfo.ProjLookup[edge.Left].Width / 2.0; ep.Right.Y = CalibrationInfo.ProjLookup[edge.Left].Height / 2.0; edge.Points.Insert(PointTree.SelectedNode.Index + 1, ep); var child = PointTree.SelectedNode.Parent.Nodes.Insert(PointTree.SelectedNode.Index + 1, ep.ToString()); child.Tag = ep; PointTree.SelectedNode = child; return; } if (PointTree.SelectedNode.Text == "Edges") { var edge = new Edge(-1, -1); var props = new EdgeProperties {Edge = edge}; edge.Owner = CalibrationInfo; if (props.ShowDialog() == DialogResult.OK) { if (edge.Left != -1 && edge.Right != -1 && edge.Right != edge.Left) { CalibrationInfo.AddEdge(edge); ReloadPointTree(); } } } } else { if (PointTree.SelectedNode.Tag is ProjectorEntry) { var pe = PointTree.SelectedNode.Tag as ProjectorEntry; var pnt = new BlendPoint {X = pe.Width/2.0, Y = pe.Height/2.0}; pe.BlendPolygon.Add(pnt); pe.SelectedBlendPoint = pe.BlendPolygon.Count - 1; var child = PointTree.SelectedNode.Nodes.Add(pnt.ToString()); child.Tag = pnt; PointTree.SelectedNode = child; return; } if (PointTree.SelectedNode.Parent != null && PointTree.SelectedNode.Parent.Tag is ProjectorEntry) { var bp = (BlendPoint)PointTree.SelectedNode.Tag; var pe = PointTree.SelectedNode.Parent.Tag as ProjectorEntry; var pnt = new BlendPoint {X = pe.Width/2.0, Y = pe.Height/2.0}; var index = pe.BlendPolygon.IndexOf(bp) + 1; pe.BlendPolygon.Insert(index, pnt); pe.SelectedBlendPoint = index + 1; var child = PointTree.SelectedNode.Parent.Nodes.Insert(index, pnt.ToString()); child.Tag = pnt; PointTree.SelectedNode = child; } } }
private void TransferEdges(ProjectorEntry pe) { SortedList<double, BlendPoint> pointList = new SortedList<double, BlendPoint>(); foreach (Edge edge in CalibrationInfo.Edges) { bool right = false; if (edge.Right == pe.ID) { right = true; } else if (edge.Left != pe.ID) { continue; } foreach (EdgePoint edgePoint in edge.Points) { GroundTruthPoint pnt; if (!edgePoint.Blend) { continue; } if (right) { pnt = edgePoint.Right; } else { pnt = edgePoint.Left; } BlendPoint blend = new BlendPoint(); blend.X = pnt.X; blend.Y = pnt.Y; double angle = Math.Atan2(pnt.X - (pe.Width / 2), pnt.Y - (pe.Height / 2)); if (!pointList.ContainsKey(angle)) { pointList.Add(angle, blend); } } } foreach (BlendPoint blend in pointList.Values) { pe.BlendPolygon.Add(blend); } }