コード例 #1
0
 public static string SaveVectorDataAsImagePlot(this IEnumerable <double> enumSource, string fileName, SequencesDrawingVariants variant = SequencesDrawingVariants.circles)
 {
     if (fileName != "")
     {
         try
         {
             MultipleScatterAndFunctionsRepresentation plotter = new MultipleScatterAndFunctionsRepresentation(2560, 1600);
             DenseVector xSpace     = DenseVector.Create(enumSource.Count(), idx => (double)idx);
             DenseVector funcValues = DenseVector.OfEnumerable(enumSource);
             plotter.dvScatterXSpace.Add(xSpace);
             plotter.dvScatterFuncValues.Add(funcValues);
             plotter.scatterDrawingVariants.Add(variant);
             plotter.scatterLineColors.Add(new Bgr(Color.Green));
             plotter.Represent();
             plotter.SaveToImage(fileName);
             return(fileName);
         }
         catch (Exception ex)
         {
             return("");
         }
     }
     return("");
 }
コード例 #2
0
        public Bitmap RepresentTopo(Size imgSizeToGenerate)
        {
            if (imgShorelinesBackground == null)
            {
                ReadShorelineData();
            }

            if (imgSizeToGenerate.Width * imgSizeToGenerate.Height == 0)
            {
                imgSizeToGenerate = imgSize;
            }

            double scaleWidth  = (double)imgSizeToGenerate.Width / (double)imgShorelinesBackground.Width;
            double scaleHeight = (double)imgSizeToGenerate.Height / (double)imgShorelinesBackground.Height;
            double scale       = Math.Min(scaleWidth, scaleHeight);

            if (scale > 1.0d)
            {
                ReadShorelineData(currentShorelineDetailsLevel);
            }

            // scaleFactor = scale;


            Image <Bgr, byte> imgRetImg = imgShorelinesBackground.Copy();

            // imgRetImg = imgRetImg.Resize(scale, Emgu.CV.CvEnum.INTER.CV_INTER_LANCZOS4);


            foreach (TrackData currTrackDatum in lTracksData)
            {
                Point[] PointsSequence = currTrackDatum.TrackPointsSequenceToDraw(imgRetImg.Size, ptdLeftTopGPS,
                                                                                  ptdRightBottomGPS);
                //int lineWidth = 4; //Convert.ToInt32(Math.Min(imgSizeToGenerate.Width, imgSizeToGenerate.Height)/180.0d);
                int lineWidth = Convert.ToInt32(Math.Min(imgSizeToGenerate.Width, imgSizeToGenerate.Height) / 180.0d);
                if (trackLineWidth > 0)
                {
                    lineWidth = trackLineWidth;
                }
                imgRetImg.DrawPolyline(PointsSequence, false, currTrackDatum.lineColor, lineWidth);
            }


            foreach (Tuple <GPSdata, SequencesDrawingVariants, Bgr> markerData in listMarkers)
            {
                GPSdata currGPSpos = markerData.Item1;
                SequencesDrawingVariants drawingVariant = markerData.Item2;
                Bgr currColor = markerData.Item3;

                PointF currMarkerPointF = ImgPointOfGPS(currGPSpos,
                                                        new SizeD(imgRetImg.Size.Width, imgRetImg.Size.Height), ptdLeftTopGPS, ptdRightBottomGPS).PointF();

                int lineWidth = 4; // Convert.ToInt32(Math.Min(imgSizeToGenerate.Width, imgSizeToGenerate.Height) / 180.0d);


                imgRetImg.Draw(new CircleF(currMarkerPointF, lineWidth), currColor, lineWidth);
            }


            return(imgRetImg.Bitmap);
        }
        private void RepresentScatter()
        {
            if ((dvScatterXSpace.Count == 0) || (dvScatterFuncValues.Count == 0))
            {
                return;
            }

            koeffY = ((double)pictureHeight - btmServiceSpaceGapY - topServiceSpaceGapY) / (overallFuncMax - overallFuncMin);
            koeffX = ((double)pictureWidth - leftServiceSpaceGapX - rightServiceSpaceGapX) / (xSpaceMax - xSpaceMin);
            if (equalScale)
            {
                double koeff = Math.Min(koeffY, koeffX);
                koeffY = koeff;
                koeffX = koeff;
            }


            for (int seqIndex = 0; seqIndex < dvScatterFuncValues.Count; seqIndex++)
            {
                List <Point> pointsList = new List <Point>();
                for (int i = 0; i < dvScatterXSpace[seqIndex].Count; i++)
                {
                    int yCoordinate = Convert.ToInt32(pictureHeight - btmServiceSpaceGapY - (dvScatterFuncValues[seqIndex][i] - overallFuncMin) * koeffY);
                    int xCoordinate = Convert.ToInt32(leftServiceSpaceGapX + (dvScatterXSpace[seqIndex][i] - xSpaceMin) * koeffX);
                    pointsList.Add(new Point(xCoordinate, yCoordinate));
                }

                Bgr curSeqColor = new Bgr(255, 0, 0);
                try
                {
                    curSeqColor = scatterLineColors[seqIndex];
                }
                catch (Exception)
                {
                    curSeqColor = new Bgr(255, 0, 0);
                }

                SequencesDrawingVariants currentDrawingVariant = SequencesDrawingVariants.polyline;
                try
                {
                    currentDrawingVariant = scatterDrawingVariants[seqIndex];
                }
                catch (Exception)
                {
                    currentDrawingVariant = SequencesDrawingVariants.polyline;
                }

                switch (currentDrawingVariant)
                {
                case SequencesDrawingVariants.circles:
                {
                    foreach (Point thePoint in pointsList)
                    {
                        theImage.Draw(new CircleF(thePoint, 3), curSeqColor, 2);
                    }
                    break;
                }

                case SequencesDrawingVariants.squares:
                {
                    foreach (Point thePoint in pointsList)
                    {
                        List <Point> squareVertices = new List <Point>();
                        squareVertices.Add(new Point(thePoint.X - 2, thePoint.Y - 2));
                        squareVertices.Add(new Point(thePoint.X - 2, thePoint.Y + 2));
                        squareVertices.Add(new Point(thePoint.X + 2, thePoint.Y + 2));
                        squareVertices.Add(new Point(thePoint.X + 2, thePoint.Y - 2));
                        theImage.DrawPolyline(squareVertices.ToArray(), true, curSeqColor, 2);
                    }
                    break;
                }

                case SequencesDrawingVariants.triangles:
                {
                    foreach (Point thePoint in pointsList)
                    {
                        List <Point> triangleVertices = new List <Point>();
                        triangleVertices.Add(new Point(thePoint.X - 2, thePoint.Y - 2));
                        triangleVertices.Add(new Point(thePoint.X, thePoint.Y + 2));
                        triangleVertices.Add(new Point(thePoint.X + 2, thePoint.Y - 2));
                        theImage.DrawPolyline(triangleVertices.ToArray(), true, curSeqColor, 2);
                    }
                    break;
                }

                case SequencesDrawingVariants.polyline:
                {
                    theImage.DrawPolyline(pointsList.ToArray(), false, curSeqColor, 2);
                    break;
                }
                }
            }
        }