Exemple #1
0
        public virtual void Scale(double factor)
        {
            double avrgX = 0, avrgY = 0;
            int    NumOfPoints = Vertices.Count;

            for (int ii = 0; ii < NumOfPoints; ii++)
            {
                avrgX += Vertices[ii].X / NumOfPoints;
                avrgY += Vertices[ii].Y / NumOfPoints;
            }

            for (int ii = 0; ii < NumOfPoints; ii++)
            {
                Vertices[ii] = new PointOnGrid((float)(Vertices[ii].X - avrgX),
                                               (float)(Vertices[ii].Y - avrgY));
            }

            for (int ii = 0; ii < NumOfPoints; ii++)
            {
                Vertices[ii] = new PointOnGrid((float)(Vertices[ii].X * factor),
                                               (float)(Vertices[ii].Y * factor));
            }

            for (int ii = 0; ii < NumOfPoints; ii++)
            {
                Vertices[ii] = new PointOnGrid((float)(Vertices[ii].X + avrgX),
                                               (float)(Vertices[ii].Y + avrgY));
            }

            maxXShape = (maxXShape - avrgX) * factor + avrgX;
            minXShape = (minXShape - avrgX) * factor + avrgX;
            maxYShape = (maxYShape - avrgX) * factor + avrgY;
            minYShape = (minYShape - avrgX) * factor + avrgY;
        }
Exemple #2
0
        private double GetDistanceToLine(PointOnGrid P1, PointOnGrid P2, PointOnGrid point)
        {
            double result = Math.Abs((P2.Y - P1.Y) * point.X - (P2.X - P1.X) * point.Y + P2.X * P1.Y - P2.Y * P1.X) /
                            P1.DistanceToOtherPoint(P2);

            return(result);
        }
Exemple #3
0
 public virtual void Shift(float dx, float dy)
 {
     for (int ii = 0; ii < Vertices.Count; ii++)
     {
         Vertices[ii] = new PointOnGrid(Vertices[ii].X + dx, Vertices[ii].Y + dy);
     }
 }
Exemple #4
0
        private void AddPSF(ushort[,] canvas, PointOnGrid projectedPoint, double intensity)
        {
            int width  = canvas.GetLength(1);
            int height = canvas.GetLength(0);


            for (int ii = -1; ii <= 1; ii += 2)
            {
                for (int jj = -1; jj <= 1; jj += 2)
                {
                    int newX = (int)projectedPoint.X + jj;
                    int newY = (int)projectedPoint.Y + ii;

                    bool b1 = newX > 0;
                    bool b2 = newX < width;
                    bool b3 = newY > 0;
                    bool b4 = newY < height;

                    if (b1 && b2 && b3 && b4)
                    {
                        canvas[newX, newY] += (ushort)(intensity / 8); //contribution from eight neighbours
                    }
                }
            }

            canvas[(int)projectedPoint.X, (int)projectedPoint.Y] += (ushort)intensity;
        }
Exemple #5
0
        public static PointOnGrid operator -(PointOnGrid p1, PointOnGrid p2)
        {
            PointOnGrid res = new PointOnGrid(0, 0, 0);

            res.X = (float)(p1.X - p2.X);
            res.Y = (float)(p1.Y - p2.Y);
            res.X = (float)(p1.Z - p2.Z);
            return(res);
        }
Exemple #6
0
        public static PointOnGrid operator *(PointOnGrid p, double scale)
        {
            PointOnGrid res = new PointOnGrid(0, 0, 0, p.Index, p.Intensity);

            res.X = (float)(p.X * scale);
            res.Y = (float)(p.Y * scale);
            res.Z = (float)(p.Z * scale);
            return(res);
        }
Exemple #7
0
        internal double DistanceToContour(List <PointOnGrid> contourPoints, PointOnGrid point, ref int iClosest)
        {
            double minDistance = 1e6;

            for (int ii = 0; ii < contourPoints.Count; ii++)
            {
                if (ii == contourPoints.Count - 1)
                {
                    if (contourPoints[ii].DistanceToOtherPoint(contourPoints[0]) > 1e-4)
                    {
                        //todo add intensity effect
                        double dist = GetDistanceToLine(contourPoints[ii], contourPoints[0], point);
                        if (dist < minDistance)
                        {
                            iClosest    = ii;
                            minDistance = dist;
                        }
                    }
                    else
                    {
                    }
                }
                else if (ii == 0)
                {
                    if (contourPoints[ii].DistanceToOtherPoint(contourPoints[0]) > 1e-4)
                    {
                        //todo add intensity effect
                        double dist = GetDistanceToLine(contourPoints[ii], contourPoints[0], point);
                        if (dist < minDistance)
                        {
                            iClosest    = ii;
                            minDistance = dist;
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    if (contourPoints[ii].DistanceToOtherPoint(contourPoints[ii + 1]) > 1e-4)
                    {
                        double dist = GetDistanceToLine(contourPoints[ii], contourPoints[ii + 1], point);

                        if (dist < minDistance)
                        {
                            iClosest    = ii;
                            minDistance = dist;
                        }
                    }
                    else
                    {
                    }
                }
            }
            return(minDistance);
        }
Exemple #8
0
        internal bool IsPointInPolygon(List <PointOnGrid> polygon, PointOnGrid testPoint)
        {
            bool result = false;
            int  j      = polygon.Count() - 1;

            for (int i = 0; i < polygon.Count(); i++)
            {
                if (polygon[i].Y < testPoint.Y && polygon[j].Y >= testPoint.Y || polygon[j].Y < testPoint.Y && polygon[i].Y >= testPoint.Y)
                {
                    if (polygon[i].X + (testPoint.Y - polygon[i].Y) / (polygon[j].Y - polygon[i].Y) * (polygon[j].X - polygon[i].X) < testPoint.X)
                    {
                        result = !result;
                    }
                }
                j = i;
            }
            return(result);
        }
Exemple #9
0
        /// <param name="ang">Degrees of rotation [°]</param>
        public virtual void Rotate(double ang)
        {
            ang = ang * Math.PI / 180;
            double[] RotMat = new double[]
            {
                Math.Cos(ang), -Math.Sin(ang),
                Math.Sin(ang), Math.Cos(ang)
            };

            for (int ii = 0; ii < Vertices.Count; ii++)
            {
                float newX = (float)(Vertices[ii].X * RotMat[0] + Vertices[ii].Y * RotMat[1]);
                float newY = (float)(Vertices[ii].X * RotMat[2] + Vertices[ii].Y * RotMat[3]);
                Vertices[ii] = new PointOnGrid(newX, newY);
            }

            maxXShape = (maxXShape * RotMat[0] + maxYShape * RotMat[1]);
            minXShape = (minXShape * RotMat[0] + minYShape * RotMat[1]);
            maxYShape = (maxXShape * RotMat[2] + maxYShape * RotMat[3]);
            minYShape = (minXShape * RotMat[2] + minYShape * RotMat[3]);
        }
Exemple #10
0
        public double DistanceToOtherPoint(PointOnGrid otherPoint)
        {
            double result = Math.Sqrt(Math.Pow(Y - otherPoint.Y, 2) - Math.Pow(otherPoint.X - otherPoint.X, 2));

            return(result);
        }
Exemple #11
0
        internal double DistanceToContour(List <PointOnGrid> contourPoints, PointOnGrid point)
        {
            int iDummy = 0;

            return(DistanceToContour(contourPoints, point, ref iDummy));
        }
Exemple #12
0
        internal virtual void ScaleTargetAndAddToCanvas(ushort[,] canvas, List <PointOnGrid> contour, MaxMin maxMin, ref RectangleF rect)
        {
            int width  = canvas.GetLength(1);
            int height = canvas.GetLength(0);



            double xcg = minXShape + (maxXShape - minXShape) / 2;
            double ycg = minYShape + (maxYShape - minYShape) / 2;
            double RadiusAroundShape = Math.Sqrt(((maxXShape - minXShape) / 2) * ((maxXShape - minXShape) / 2) +
                                                 ((maxYShape - minYShape) / 2) * ((maxYShape - minYShape) / 2));

            //assume parabolic dispersion
            double b = maxMin.Max;
            double a = (maxMin.Min - b) / Math.Pow(RadiusAroundShape, 2);


            rect.X      = (float)minXShape;
            rect.Y      = (float)minYShape;
            rect.Width  = (float)(maxXShape - minXShape);
            rect.Height = (float)(maxYShape - minYShape);

            double dist = 0, intensity = 0;
            int    maxComponenets = contour.Max(p => p.Component);

            for (int ii = (int)minYShape; ii < (int)maxYShape; ii++) //Rows
            {
                for (int jj = (int)minXShape; jj < maxXShape; jj++)  //Columns
                {
                    PointOnGrid candidate = new PointOnGrid(jj, ii);
                    if (IsPointInPolygon(contour, candidate))
                    {
                        area++;

                        if (true)
                        {
                            dist = DistanceToContour(contour, candidate);
                            double intensity_temp = intensity;
                            intensity = maxMin.Max - dist * (maxMin.Max - maxMin.Min) / (RadiusAroundShape / 2);
                            var diff = Math.Abs(intensity_temp - intensity);
                        }
                        else if (true)
                        {
                            for (int kk = 1; kk <= maxComponenets; kk++)
                            {
                                if (IsPointInPolygon(contour, candidate))
                                {
                                    //contour.ToCSV().WriteCSV(@"c:\temp\contour.csv");
                                    if (IsPointInPolygon(contour.FindAll(p => p.Component == kk).ToList(), candidate))
                                    {
                                        intensity = maxMin.Min + (maxMin.Max - maxMin.Min) * (1D / maxComponenets) * kk;
                                    }
                                }
                            }
                        }
                        else
                        {
                            dist = Math.Sqrt((candidate.X - xcg) * (candidate.X - xcg) +
                                             (candidate.Y - ycg) * (candidate.Y - ycg));
                            intensity = (maxMin.Max - maxMin.Min) - a * Math.Pow(dist, 2);
                        }


                        if ((double)(canvas[(int)candidate.X, (int)candidate.Y] + intensity) > (double)ushort.MaxValue)
                        {
                            canvas[(int)candidate.X, (int)candidate.Y] = ushort.MaxValue - 1;
                        }
                        else
                        {
                            //AddPSF(canvas, projectedPoints[ii], intensity);
                            checked
                            {
                                canvas[(int)candidate.X, (int)candidate.Y] += (ushort)intensity;
                            }
                        }
                    }
                }
            }
        }