public PartLocation Map2(PartLocation from)
        {
            if (ScaleX == 0 || ScaleY == 0)
            {
                throw new Exception("LeastSquareMapping not intialized");
            }

            var p = new PartLocation(from);

            p.X = (from.X + OffsetX) * ScaleX;
            // Why there's a -1 necessary here is beyond me but it works so
            p.Y = (from.Y + OffsetY) * ScaleY - 1;
            p.Rotate(Rotation_);

            return(p);
        }
Ejemplo n.º 2
0
        public void TakePhotoOfPartAtCurrentLocation(TapeObj t)
        {
            if (t == null)
            {
                return;
            }
            var dir = Global.BaseDirectory + @"\images\";

            Directory.CreateDirectory(dir);

            var size = t.GetComponentSize();

            if (size == null)
            {
                return;
            }
            var s = new PartLocation(size.Width, size.Height);                  //assumes 0 degree rotation

            s = (1.5 * s) / MainForm.cameraView.downVideoProcessing.mmPerPixel; //convert to pixels and ad extra 25%
            s.Rotate(t.PartAngle * Math.PI / 180d);                             //and rotate to final position
            s.X = Math.Abs(s.X);                                                //correct for sign changes
            s.Y = Math.Abs(s.Y);

            MainForm.cameraView.SetDownCameraFunctionSet("ComponentPhoto");
            Global.DoBackgroundWork(); //let new images be processed

            var topleft = MainForm.cameraView.downVideoProcessing.FrameCenter - (.5 * s);
            var rect    = new Rectangle(topleft.ToPoint(), s.ToSize());
            var filter  = new Crop(rect);

            using (var image = MainForm.cameraView.downVideoProcessing.GetMeasurementFrame()) {
                using (var cropped = filter.Apply(image)) {
                    var filename = dir + t.ID.Replace(" ", "_") + ".jpg";
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                    cropped.Save(filename, ImageFormat.Jpeg);
                    t.TemplateFilename = filename;
                }
            }
        }
Ejemplo n.º 3
0
        // Part Orientation = orientation if tape is perfectly oriented the way it is oriented
        // deltaOrientation = how far offf the tape is from it's stated orientation
        public PartLocation GetPartLocation(int componentNumber)
        {
            PartLocation part;

            if (FirstPart != null)
            {
                part = GetPartBasedLocation(componentNumber);
            }
            else
            {
                var offset = new PartLocation(componentNumber * PartPitch + HoleToPartSpacingX, HoleToPartSpacingY);
                // add the vector to the part rotated by the tape orientation
                part = new PartLocation(FirstHole) + offset.Rotate(TapeOrientation.ToRadians());
            }
            // add deviation from expected orientation to part orientation
            var deltaOrientation = tapeOrientation.ToRadians() - OriginalTapeOrientationVector.ToRadians();

            part.A = (OriginalPartOrientationVector.ToRadians() + deltaOrientation) * 180d / Math.PI;

            return(part);
        }
Ejemplo n.º 4
0
        public static PointF[] ToRotatedRectangle(Shapes.Rectangle s)
        {
            s.ToRawResolution();
            PointF[] p = new PointF[5];
            p[0].X = (float)s.Left; p[0].Y = (float)s.Top;
            p[1].X = (float)s.Right; p[1].Y = (float)s.Top;
            p[2].X = (float)s.Right; p[2].Y = (float)s.Bottom;
            p[3].X = (float)s.Left; p[3].Y = (float)s.Bottom;
            p[4].X = (float)s.Left; p[4].Y = (float)s.Top;

            // roate about center
            double       angle  = s.A * Math.PI / 180d;
            PartLocation center = new PartLocation(s);

            for (int i = 0; i < p.Length; i++)
            {
                PartLocation pp = new PartLocation(p[i]) - center; //shift to zero
                pp   = pp.Rotate(angle) + center;
                p[i] = pp.ToPointF();
            }

            return(p);
        }
Ejemplo n.º 5
0
        // Part Orientation = orientation if tape is perfectly oriented the way it is oriented
        // deltaOrientation = how far offf the tape is from it's stated orientation
        public PartLocation GetPartLocation(int componentNumber)
        {
            PartLocation part;
            if (FirstPart != null) {
                part = GetPartBasedLocation(componentNumber);
            } else {
                var offset = new PartLocation(componentNumber * PartPitch + HoleToPartSpacingX, HoleToPartSpacingY);
                // add the vector to the part rotated by the tape orientation
                part = new PartLocation(FirstHole) + offset.Rotate(TapeOrientation.ToRadians());
            }
            // add deviation from expected orientation to part orientation
            var deltaOrientation = tapeOrientation.ToRadians() - OriginalTapeOrientationVector.ToRadians();
            part.A = (OriginalPartOrientationVector.ToRadians() + deltaOrientation) * 180d / Math.PI;

            return part;
        }
        public PartLocation Map2(PartLocation from)
        {
            if (ScaleX == 0 || ScaleY == 0) throw new Exception("LeastSquareMapping not intialized");

            var p = new PartLocation(from);

            p.X = (from.X + OffsetX) * ScaleX;
            // Why there's a -1 necessary here is beyond me but it works so
            p.Y = (from.Y + OffsetY) * ScaleY - 1;
            p.Rotate(Rotation_);

            return p;
        }
Ejemplo n.º 7
0
        public void TakePhotoOfPartAtCurrentLocation(TapeObj t)
        {
            if (t == null) return;
            var dir = Global.BaseDirectory + @"\images\";
            Directory.CreateDirectory(dir);

            var size = t.GetComponentSize();
            if (size == null) return;
            var s = new PartLocation(size.Width, size.Height); //assumes 0 degree rotation
            s = (1.5 * s) / MainForm.cameraView.downVideoProcessing.mmPerPixel; //convert to pixels and ad extra 25%
            s.Rotate(t.PartAngle * Math.PI / 180d); //and rotate to final position
            s.X = Math.Abs(s.X); //correct for sign changes
            s.Y = Math.Abs(s.Y);

            MainForm.cameraView.SetDownCameraFunctionSet("ComponentPhoto");
            Global.DoBackgroundWork(); //let new images be processed

            var topleft = MainForm.cameraView.downVideoProcessing.FrameCenter - (.5 * s);
            var rect = new Rectangle(topleft.ToPoint(), s.ToSize());
            var filter = new Crop(rect);

            using (var image = MainForm.cameraView.downVideoProcessing.GetMeasurementFrame()) {
                using (var cropped = filter.Apply(image)) {
                    var filename = dir + t.ID.Replace(" ", "_") + ".jpg";
                    if (File.Exists(filename)) File.Delete(filename);
                    cropped.Save(filename, ImageFormat.Jpeg);
                    t.TemplateFilename = filename;
                }
            }
        }
Ejemplo n.º 8
0
        public void Recomputer3()
        {
            // calculate centroids
            int fiducialCount = 0;

            List<PartLocation> sourceFiducials = new List<PartLocation>();
            List<PartLocation> destFiducials = new List<PartLocation>();

            PartLocation tempDest;

            foreach (var fiducial in source.Where(part => part.physicalComponent.IsFiducial).ToArray())
            {
                sourceCentroidX += fiducial.physicalComponent.X_nominal;
                sourceCentroidY += fiducial.physicalComponent.Y_nominal;
                sourceFiducials.Add(fiducial);

                tempDest = dest[source.IndexOf(fiducial)];

                if (tempDest.physicalComponent != null) {
                    destCentroidX += tempDest.physicalComponent.X_machine;
                    destCentroidY += tempDest.physicalComponent.Y_machine;
                } else {
                    destCentroidX += tempDest.X;
                    destCentroidY += tempDest.Y;
                }
                destFiducials.Add(tempDest);

                fiducialCount++;
            }
            sourceCentroidX /= fiducialCount;
            sourceCentroidY /= fiducialCount;

            destCentroidX /= fiducialCount;
            destCentroidY /= fiducialCount;

            OffsetX = -sourceCentroidX + destCentroidX;
            OffsetY = -sourceCentroidY + destCentroidY;

            List <double> destRotation = new List<double>();
            List <double> sourceRotation = new List<double>();
            List <double> destOffset = new List<double>();
            List <double> sourceOffset = new List<double>();
            List <double> scale = new List<double>();
            List<double> rotationOffset = new List<double>();

            ScaleX = 0; ScaleY = 0; Rotation_ = 0;

            // Calculate offsets from centroids, rotation from source to destination and scale difference
            PartLocation sourceFiducial = null, destFiducial = null;
            for (int i=0; i<fiducialCount; i++) {
                sourceFiducial = sourceFiducials.ElementAt(i);
                destFiducial = destFiducials.ElementAt(i);
                /*
                sourceOffset.Add(Math.Sqrt(Math.Pow(sourceFiducial.X -
                    sourceCentroidX, 2) + Math.Pow(sourceFiducial.Y -
                    sourceCentroidY, 2)));
                destOffset.Add(Math.Sqrt(Math.Pow(destFiducial.X -
                    destCentroidX, 2) + Math.Pow(destFiducial.Y -
                    destCentroidY, 2)));
                 */
                /*
                sourceRotation.Add(Math.Asin((sourceFiducial.Y - sourceCentroidY) /
                    sourceOffset[i]));
                if ((sourceFiducial.X - sourceCentroidX) < 0) {
                    sourceRotation[i] = Math.PI - sourceRotation[i]; }
                if (sourceRotation[i] < 0) { sourceRotation[i] += Math.PI * 2; }

                destRotation.Add(Math.Asin((destFiducial.Y - destCentroidY) /
                    destOffset[i]));
                if ((destFiducial.X - destCentroidX) < 0) {
                    destRotation[i] = Math.PI - destRotation[i]; }
                if (destRotation[i] < 0) { destRotation[i] += Math.PI * 2; }
                */
                sourceRotation.Add(Math.Atan2(sourceFiducial.Y - sourceCentroidY,
                    sourceFiducial.X - sourceCentroidX));
                destRotation.Add(Math.Atan2(destFiducial.Y - destCentroidY,
                    destFiducial.X - destCentroidX));

                rotationOffset.Add(destRotation[i] - sourceRotation[i]);

                //scale.Add(destOffset[i] / sourceOffset[i]);

                Rotation_ += rotationOffset[i];
                ScaleX += (destFiducial.X - destCentroidX) / (sourceFiducial.X - sourceCentroidX);
                ScaleY += (destFiducial.Y - destCentroidY) / (sourceFiducial.Y - sourceCentroidY);
            }

            Rotation_ /= fiducialCount;
            ScaleX /= fiducialCount;
            ScaleY /= fiducialCount;

            var p = new PartLocation();
            double xFid, yFid;
            foreach (PartLocation fiducial in sourceFiducials)
            {
                p.X = (fiducial.X - sourceCentroidX) * ScaleX;
                p.Y = (fiducial.Y - sourceCentroidY) * ScaleY;
                p.Rotate(Rotation_);
                p.X += sourceCentroidX + OffsetX;
                p.Y += sourceCentroidY + OffsetY;
            }
        }
Ejemplo n.º 9
0
        public PartLocation Map2(PartLocation from)
        {
            if (ScaleX == 0 || ScaleY == 0) throw new Exception("LeastSquareMapping not intialized");

            var p = new PartLocation(from);

            //(Rotation * (x - SourceCentroid)) + Offset + SourceCentroid;
            /*
            p.X = (from.X + OffsetX) * ScaleX; // -0.5;
            p.Y = (from.Y + OffsetY) * ScaleY; // -1;
            p.Rotate(Rotation_);
            */
            p.X = (from.X - sourceCentroidX) * ScaleX;
            p.Y = (from.Y - sourceCentroidY) * ScaleY;
            p.Rotate(Rotation_);
            p.X += sourceCentroidX + OffsetX;
            p.Y += sourceCentroidY + OffsetY;

            // double check this
            p.A = from.A + Angle;

            return p;
        }
Ejemplo n.º 10
0
        public static PointF[] ToRotatedRectangle(Shapes.Rectangle s)
        {
            s.ToRawResolution();
            PointF[] p = new PointF[5];
            p[0].X = (float)s.Left; p[0].Y = (float)s.Top;
            p[1].X = (float)s.Right; p[1].Y = (float)s.Top;
            p[2].X = (float)s.Right; p[2].Y = (float)s.Bottom;
            p[3].X = (float)s.Left; p[3].Y = (float)s.Bottom;
            p[4].X = (float)s.Left; p[4].Y = (float)s.Top;

            // roate about center
            double angle = s.A * Math.PI / 180d;
            PartLocation center = new PartLocation(s);
            for (int i = 0; i < p.Length; i++) {
                PartLocation pp = new PartLocation(p[i]) - center; //shift to zero
                pp = pp.Rotate(angle) + center;
                p[i] = pp.ToPointF();
            }

            return p;
        }