public double[] GetDisparitiesLK(Image<Gray, byte> leftImg, Image<Gray, byte> rightImg, PointF[] points, Image<Gray, short> precalcDepthMap, VisualOdometerDisparitiesParams parameters) { var param = (VisualOdometerDisparitiesParamsLK)parameters; var res = new double[points.Count()]; Size WinSize = param.WinSize;// new Size(80, 80); int PyrLevel = param.PyrLevel;// 4; MCvTermCriteria PyrLkTerm = param.PyrLkTerm;// new MCvTermCriteria(100, 0.001); var status = new Byte[points.Count()]; var error = new float[points.Count()]; var rightPoints = new PointF[points.Count()]; var subCorners = new PointF[1][]; subCorners[0] = points; leftImg.FindCornerSubPix( subCorners, new Size(11, 11), new Size(-1, -1), new MCvTermCriteria(30, 0.01)); var leftCorners = subCorners[0]; var gpuP = new GpuPyrLKOpticalFlow(WinSize, PyrLevel, 30, false); OpticalFlow.PyrLK( leftImg, rightImg, leftCorners, WinSize, PyrLevel, PyrLkTerm, out rightPoints, out status, out error); for (int i = 0; i < points.Count(); ++i) { if (status[i] == 1) { var disp = leftCorners[i].X - rightPoints[i].X; if (disp < 0) { res[i] = -1; } else { res[i] = disp; } } else { res[i] = -1; } } return res; }
private static RectangleF FindMinRectangle(PointF[] srcPoints) { if (srcPoints == null || srcPoints.Count() == 0) { return new RectangleF(); } var maxLeftPoint = srcPoints.First(); var maxRightPoint = srcPoints.Last(); foreach (var srcPoint in srcPoints) { if (srcPoint.X < maxLeftPoint.X) { maxLeftPoint.X = srcPoint.X; } if (srcPoint.Y < maxLeftPoint.Y) { maxLeftPoint.Y = srcPoint.Y; } if (srcPoint.X > maxRightPoint.X) { maxRightPoint.X = srcPoint.X; } if (srcPoint.Y > maxRightPoint.Y) { maxRightPoint.Y = srcPoint.Y; } } return new RectangleF(maxLeftPoint.X, maxLeftPoint.Y, maxRightPoint.X - maxLeftPoint.X, maxRightPoint.Y - maxLeftPoint.Y); }
private static bool isPointInPolygon(PointF[] polygon, PointF 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; }
public double[] GetDisparities(Image<Gray, byte> leftImg, Image<Gray, byte> rightImg, PointF[] points, Image<Gray, short> precalcDepthMap, VisualOdometerDisparitiesParams parameters) { //TEST LK //return this.GetDisparitiesLK(leftImg, rightImg, points, precalcDepthMap, parameters); //// var res = new double[points.Count()]; for (int i = 0; i < points.Count(); ++i) { if (points[i].X >= leftImg.Width || points[i].X < 0 || points[i].Y >= leftImg.Height || points[i].Y < 0) { res[i] = -1; continue; } res[i] = precalcDepthMap[(int)points[i].Y, (int)points[i].X].Intensity; } return res; }
public static float CalcCircumference(PointF[] points) { float P = 0; int type = points.Count(); for (int i = 0; i < type - 1; i++) { P += sideLength(points[i], points[i + 1]); } P += sideLength(points[0], points[type - 1]); Console.WriteLine(P); return P; }
private void DrawGraps() { var g = Graphics.FromImage(DrawArea); float yStep = (float) ((DrawArea.Height - VerticalShiftLine)*0.01); float xStep = (float) ((DrawArea.Width - HorisontalShiftLine)*0.01); int t = 0; foreach (var curve in Curves) { if (curve.Length > 1) { var points = new PointF[curve.Length]; float xValue = 0.0f; float yValue = 0.0f; for (int i = 0; i < curve.Length; i++) { xValue = curve.GetData().XPercent[i]; yValue = curve.GetData().YPercent[i]; if (xValue > 100) xValue = 100f; if (yValue > 100) yValue = 100f; if (xValue < 0) xValue = 0f; if (yValue < 0) yValue = 0f; points[i].X = xValue*xStep + HorisontalShiftLine; points[i].Y = DrawArea.Height - yValue*yStep - VerticalShiftLine; } if (points.Count() > 1) g.DrawCurve(new Pen(curve.ColorCurve, 3), points); } } }
private void drawGrid(Graphics graphics, double maxValue, PointF[] avgpoints, float yScale, float xScale) { using (var gridPen = new Pen(Color.LightGray)) { for (int i = 10; i < maxValue; i += 10) { var gridLine = new PointF[2]; gridLine[0] = new PointF(0, i); gridLine[1] = new PointF(avgpoints.Count() - 1, i); drawGraphLine(graphics, gridLine, gridPen, yScale, xScale); } for (int i = 50; i < avgpoints.Count(); i += 50) { var gridLine = new PointF[2]; gridLine[0] = new PointF(i, 0); gridLine[1] = new PointF(i, (int)maxValue); drawGraphLine(graphics, gridLine, gridPen, yScale, xScale); } } }
public Matrix<double>[] ReprojectTo3d(Image<Gray, byte> leftImg, double[] disps, PointF[] points, Matrix<double> Q) { var res = new Matrix<double>[points.Count()]; for (int i = 0; i < points.Count(); ++i) { if (points[i].X >= leftImg.Width || points[i].X < 0 || points[i].Y >= leftImg.Height || points[i].Y < 0) { res[i] = null; continue; } // if (disps[i] <= 0) { res[i] = null; continue; } var p = new Matrix<double>(new double[,] { {points[i].X}, {points[i].Y}, {disps[i]}, {1} }); var ph3d = Q.Mul(p); if (ph3d[3, 0] == 0) { res[i] = null; continue; } res[i] = new Matrix<double>(new double[,] { {ph3d[0, 0] / ph3d[3, 0]}, {ph3d[1, 0] / ph3d[3, 0]}, {ph3d[2, 0] / ph3d[3, 0]} }); } return res; }
public void GetFeaturesOpticFlow(PointF[] origF, Image<Gray, byte> img1, Image<Gray, byte> img2, out PointF[] prevCorrFeatures, out PointF[] currCorrFeatures, VisualOdometerFeaturesOpticFlowParams parameters) { var param = (VisualOdometerFeaturesOpticFlowParamsLK)parameters; Size WinSize = param.WinSize;// new Size(80, 80); int PyrLevel = param.PyrLevel;// 4; MCvTermCriteria PyrLkTerm = param.PyrLkTerm;// new MCvTermCriteria(100, 0.001); var status = new Byte[origF.Count()]; var error = new float[origF.Count()]; var currFeatures = new PointF[origF.Count()]; OpticalFlow.PyrLK( img1, img2, origF, WinSize, PyrLevel, PyrLkTerm, out currFeatures, out status, out error); List<PointF> pAct = new List<PointF>(); List<PointF> cAct = new List<PointF>(); for (int i = 0; i < origF.Count(); ++i) { if (status[i] == 1) { pAct.Add(origF[i]); cAct.Add(currFeatures[i]); } } prevCorrFeatures = pAct.ToArray(); currCorrFeatures = cAct.ToArray(); }
//Allow the user to import an array of points to be used to draw a signature in the view, with new //lines indicated by a PointF.Empty in the array. public void LoadPoints(PointF[] loadedPoints) { if (loadedPoints == null || loadedPoints.Count () == 0) return; var startIndex = 0; var emptyIndex = loadedPoints.ToList ().IndexOf (PointF.Empty); if (emptyIndex == -1) emptyIndex = loadedPoints.Count (); //Clear any existing paths or points. paths = new List<UIBezierPath> (); points = new List<PointF[]> (); do { //Create a new path and set the line options currentPath = UIBezierPath.Create (); currentPath.LineWidth = StrokeWidth; currentPath.LineJoinStyle = CGLineJoin.Round; currentPoints = new List<PointF> (); //Move to the first point and add that point to the current_points array. currentPath.MoveTo (loadedPoints [startIndex]); currentPoints.Add (loadedPoints [startIndex]); //Iterate through the array until an empty point (or the end of the array) is reached, //adding each point to the current_path and to the current_points array. for (var i = startIndex + 1; i < emptyIndex; i++) { currentPath.AddLineTo (loadedPoints [i]); currentPoints.Add (loadedPoints [i]); } //Add the current_path and current_points list to their respective Lists before //starting on the next line to be drawn. paths.Add (currentPath); points.Add (currentPoints.ToArray ()); //Obtain the indices for the next line to be drawn. startIndex = emptyIndex + 1; if (startIndex < loadedPoints.Count () - 1) { emptyIndex = loadedPoints.ToList ().IndexOf (PointF.Empty, startIndex); if (emptyIndex == -1) emptyIndex = loadedPoints.Count (); } else emptyIndex = startIndex; } while (startIndex < emptyIndex); //Obtain the image for the imported signature and display it in the image view. imageView.Image = GetImage (false); //Display the clear button. btnClear.Hidden = false; SetNeedsDisplay (); }
public void DrawSegments(PointF[] Stroke) { if (RenderMethod == RenderMode.Standard) { // Ensure that surface is visible if (!this.Visible) { this.TopMost = true; this.Show(); } // Create list of points that are new this draw List<PointF> NewPoints = new List<PointF>(); // Get number of points added since last draw including last point of last stroke and add new points to new points list int iDelta = Stroke.Count() - LastStroke.Count() + 1; NewPoints.AddRange(Stroke.Skip(Stroke.Count() - iDelta).Take(iDelta)); // Draw new line segments to main drawing surface SurfaceGraphics.DrawLines(DrawingPen, NewPoints.Select(p => TranslatePoint(p)).ToArray()); // Set last stroke to copy of current stroke // ToList method creates value copy of stroke list and assigns it to last stroke LastStroke = Stroke.ToList(); } else { foreach (CompatibilitySurface surface in CompatibilitySurfaces) surface.SurfaceGraphics.DrawLines(DrawingPen, surface.OffsetPoints(Stroke)); } }
private void Calibrate(IEnumerable<Image<Gray, byte>> images, int nx, int ny, int useUncalibrated, float _squareSize /* Chessboard square size in cm */) { int displayCorners = 1; int showUndistorted = 1; bool isVerticalStereo = false;//OpenCV can handle left-right //or up-down camera arrangements const int maxScale = 1; //FILE* f = fopen(imageList, "rt"); int i, j, lr, nframes, n = nx*ny, N = 0; List<MCvPoint3D32f> objectPoints; var points = new List<MCvPoint2D64f>[2]; List<int> npoints; List<char>[] active = new List<char>[2]; var temp = new PointF[n]; var imageSize = new System.Drawing.Size(0,0); // ARRAY AND VECTOR STORAGE: Matrix<double> _M1 = new Matrix<double>(3, 3); Matrix<double> _M2 = new Matrix<double>(3, 3); Matrix<double> _D1 = new Matrix<double>(1, 5); Matrix<double> _D2 = new Matrix<double>(1, 5); Matrix<double> _R = new Matrix<double>(3, 3); Matrix<double> _T = new Matrix<double>(3, 1); Matrix<double> _E = new Matrix<double>(3, 3); Matrix<double> _F = new Matrix<double>(3, 3); Matrix<double> _Q = new Matrix<double>(4, 4); double [,] M1 = _M1.Data; double [,] M2 = _M2.Data; double [,] D1 = _D1.Data; double [,] D2 = _D2.Data; double [,] R = _R.Data; double [,] T = _T.Data; double [,] E = _E.Data; double [,] F = _F.Data; double [,] Q = _Q.Data; for(i=0;i<images.Count();i++) { int count = 0, result=0; lr = i % 2; List<MCvPoint2D64f> pts = points[lr]; var img = images.ElementAt(i); imageSize = img.Size; //FIND CHESSBOARDS AND CORNERS THEREIN: for( int s = 1; s <= maxScale; s++ ) { var timg = img; if( s > 1 ) { timg=new Image<Gray,byte>(img.Width * s, img.Height * s); img.Resize(timg.Width, timg.Height, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC); } temp = Emgu.CV.CameraCalibration.FindChessboardCorners(timg, new Size(nx, ny), Emgu.CV.CvEnum.CALIB_CB_TYPE.ADAPTIVE_THRESH | Emgu.CV.CvEnum.CALIB_CB_TYPE.NORMALIZE_IMAGE); Emgu.CV.CameraCalibration. result = temp.Count(); if( timg != img ) timg.Dispose(); if( result == 0 || s == maxScale) for( j = 0; j < count; j++ ) { temp[j].X /= s; temp[j].Y /= s; } if( result ) break; } if( displayCorners ) { printf("%s\n", buf); IplImage* cimg = cvCreateImage( imageSize, 8, 3 ); cvCvtColor( img, cimg, CV_GRAY2BGR ); cvDrawChessboardCorners( cimg, cvSize(nx, ny), &temp[0], count, result ); cvShowImage( "corners", cimg ); cvReleaseImage( &cimg ); if( cvWaitKey(0) == 27 ) //Allow ESC to quit exit(-1); } else putchar('.'); N = pts.size(); pts.resize(N + n, cvPoint2D32f(0,0)); active[lr].push_back((uchar)result); //assert( result != 0 ); if( result ) { //Calibration will suffer without subpixel interpolation cvFindCornerSubPix( img, &temp[0], count, cvSize(11, 11), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 30, 0.01) ); copy( temp.begin(), temp.end(), pts.begin() + N ); } cvReleaseImage( &img ); } fclose(f); printf("\n"); // HARVEST CHESSBOARD 3D OBJECT POINT LIST: nframes = active[0].size();//Number of good chessboads found objectPoints.resize(nframes*n); for( i = 0; i < ny; i++ ) for( j = 0; j < nx; j++ ) objectPoints[i*nx + j] = cvPoint3D32f(i*squareSize, j*squareSize, 0); for( i = 1; i < nframes; i++ ) copy( objectPoints.begin(), objectPoints.begin() + n, objectPoints.begin() + i*n ); npoints.resize(nframes,n); N = nframes*n; CvMat _objectPoints = cvMat(1, N, CV_32FC3, &objectPoints[0] ); CvMat _imagePoints1 = cvMat(1, N, CV_32FC2, &points[0][0] ); CvMat _imagePoints2 = cvMat(1, N, CV_32FC2, &points[1][0] ); CvMat _npoints = cvMat(1, npoints.size(), CV_32S, &npoints[0] ); cvSetIdentity(&_M1); cvSetIdentity(&_M2); cvZero(&_D1); cvZero(&_D2); // CALIBRATE THE STEREO CAMERAS printf("Running stereo calibration ..."); fflush(stdout); cvStereoCalibrate( &_objectPoints, &_imagePoints1, &_imagePoints2, &_npoints, &_M1, &_D1, &_M2, &_D2, imageSize, &_R, &_T, &_E, &_F, cvTermCriteria(CV_TERMCRIT_ITER+ CV_TERMCRIT_EPS, 100, 1e-5), CV_CALIB_FIX_ASPECT_RATIO + CV_CALIB_ZERO_TANGENT_DIST + CV_CALIB_SAME_FOCAL_LENGTH ); printf(" done\n"); // CALIBRATION QUALITY CHECK // because the output fundamental matrix implicitly // includes all the output information, // we can check the quality of calibration using the // epipolar geometry constraint: m2^t*F*m1=0 vector<CvPoint3D32f> lines[2]; points[0].resize(N); points[1].resize(N); _imagePoints1 = cvMat(1, N, CV_32FC2, &points[0][0] ); _imagePoints2 = cvMat(1, N, CV_32FC2, &points[1][0] ); lines[0].resize(N); lines[1].resize(N); CvMat _L1 = cvMat(1, N, CV_32FC3, &lines[0][0]); CvMat _L2 = cvMat(1, N, CV_32FC3, &lines[1][0]); //Always work in undistorted space cvUndistortPoints( &_imagePoints1, &_imagePoints1, &_M1, &_D1, 0, &_M1 ); cvUndistortPoints( &_imagePoints2, &_imagePoints2, &_M2, &_D2, 0, &_M2 ); cvComputeCorrespondEpilines( &_imagePoints1, 1, &_F, &_L1 ); cvComputeCorrespondEpilines( &_imagePoints2, 2, &_F, &_L2 ); double avgErr = 0; for( i = 0; i < N; i++ ) { double err = fabs(points[0][i].x*lines[1][i].x + points[0][i].y*lines[1][i].y + lines[1][i].z) + fabs(points[1][i].x*lines[0][i].x + points[1][i].y*lines[0][i].y + lines[0][i].z); avgErr += err; } printf( "avg err = %g\n", avgErr/(nframes*n) ); //COMPUTE AND DISPLAY RECTIFICATION if( showUndistorted ) { CvMat* mx1 = cvCreateMat( imageSize.height, imageSize.width, CV_32F ); CvMat* my1 = cvCreateMat( imageSize.height, imageSize.width, CV_32F ); CvMat* mx2 = cvCreateMat( imageSize.height, imageSize.width, CV_32F ); CvMat* my2 = cvCreateMat( imageSize.height, imageSize.width, CV_32F ); CvMat* img1r = cvCreateMat( imageSize.height, imageSize.width, CV_8U ); CvMat* img2r = cvCreateMat( imageSize.height, imageSize.width, CV_8U ); CvMat* disp = cvCreateMat( imageSize.height, imageSize.width, CV_16S ); CvMat* vdisp = cvCreateMat( imageSize.height, imageSize.width, CV_8U ); CvMat* pair; double R1[3][3], R2[3][3], P1[3][4], P2[3][4];
private double GetFit(PointF[] Pts, out SizeF EllipseDims) { float MinX, MinY, MaxX, MaxY; if (Pts.Length > 0) { MinX = MaxX = Pts[0].X; MinY = MaxY = Pts[0].Y; } else { EllipseDims = new SizeF(0f, 0f); return 0d; } Action<PointF> CheckMins = f => { MinX = Math.Min(MinX, f.X); MinY = Math.Min(MinY, f.Y); MaxX = Math.Max(MaxX, f.X); MaxY = Math.Max(MaxY, f.Y); }; for (int i = 1; i < Pts.Length; i++) CheckMins(Pts[i]); RectangleF BoundBox = new RectangleF(MinX, MinY, MaxX - MinX + 1, MaxY - MinY + 1); EllipseDims = BoundBox.Size; //Area of an ellipse = a*b*PI //We can't assume that the ellipse contains all of the specified points (e.g. hollow rectangle) //So we need to count which ones it does contain int[] temp; int count; return Constants.CalcFit( count = Pts.Count( p => p.X >= (temp = GetXs(mEllHeight, mEllWidth, mImgSec.Height, mImgSec.Width, (int)p.Y, mRotation))[0] && p.X <= temp[1]), (int)(BoundBox.Width / 2f * BoundBox.Height / 2f * Math.PI - count)); //The following is brilliant but stupid //I'd love to follow up on all of this //Basically, it creates an ellipse from four points //But it's getting too long, so, for now, I'll cheap out and just fit the bounding box /* * http://mathforum.org/library/drmath/view/54485.html * http://www.algebra.com/algebra/homework/equations/THEO-20100329.lesson * Correlation between nonstandard * ax^2+cy^2+dx+ey+f=0 * and standard * (x-H)^2/A^2+(y-K)^2/B^2=1 * * H = -d/(2a) * K = -e/(2c) * A^2 = (-f+d^2/(4a)+e^2/(4c))/a * B^2 = (-f+d^2/(4a)+e^2/(4c))/c * * Now, based on that relationship, and that A > width/2, you can deduce * a=(-4f+d^2/a+e^2/2)/w^2 * Where w is the maximum width needed for the ellipse * Now to solve for all the others: since we'll be working with four points, we can deduce four variables, C, D, E, and F * f = -a*k^2-c*h^2-d*k-e*h * c = -(a*m^2+d*m+f+e*n)/n^2 * d = -(a*o^2+p*(c*p+e)+f)/o * e = -(a*q^2+c*r^2+d*q+f)/r * * For each one of those, plug in a different point * * f=-a*x1^2-c*y1-d*x1-e*y1 * c=-(a*x2^2+d*x2+f+e*y2)/y2^2 * substitute and solve for f * f=-a*x1^2-(-(a*x2^2+d*x2+f+e*y2)/y2^2)*y1-d*x1-e*y1 * * if x1=k, y1=h, x2=m, y2=n, x3=o, y3=p, x4=q, y4=r * * f=-a*k^2-(-(a*m^2+d*m+f+e*n)/n^2)*h-d*k-e*h * f=(a*(k^2 n^2-h m^2)+d (k n^2-h m)+e h (n-1) n)/(h-n^2) * f=(((k*n^2-h*m)*(-(p*((p*(-(a*m^2)-d*m-f-e*n))/n^2+e))-a*o^2-f))/o+a*(k^2*n^2-h*m^2)+e*h*(n-1)*n)/(h-n^2) * f=((a*(k^2*n^2-h*m^2))/(h-n^2)+(a*m^2*p^2*(k*n^2-h*m))/(n^2*o*(h-n^2))-(a*o*(k*n^2-h*m))/(h-n^2)+(d*m*p^2*(k*n^2-h*m))/(n^2*o*(h-n^2))+(g*p^2*(k*n^2-h*m))/(n*o*(h-n^2))-(g*p*(k*n^2-h*m))/(o*(h-n^2))+(g*h*(n-1)*n)/(h-n^2))/(-(p^2*(k*n^2-h*m))/(n^2*o*(h-n^2))+(k*n^2-h*m)/(o*(h-n^2))+1) * f = (f1+f2)/f3 * f1 = (a*(k^2*n^2-h*m^2))/(h-n^2)+(a*m^2*p^2*(k*n^2-h*m))/(n^2*o*(h-n^2))-(a*o*(k*n^2-h*m))/(h-n^2)+(d*m*p^2*(k*n^2-h*m))/(n^2*o*(h-n^2)) * f2 = (g*p^2*(k*n^2-h*m))/(n*o*(h-n^2))-(g*p*(k*n^2-h*m))/(o*(h-n^2))+(g*h*(n-1)*n)/(h-n^2) * f3 = (-(p^2*(k*n^2-h*m))/(n^2*o*(h-n^2))+(k*n^2-h*m)/(o*(h-n^2))+1) * * finding c and e in terms of d, * c = (-(m (-a o^2-p (c p+e)-f))/o-a m^2-f-e n)/n^2 * e = (-a o^2 q+a o q^2+c o r^2-c p^2 q+f o-f q)/(p q-o r) * combine * c = (-(m (-p ((-a o^2 q+a o q^2+c o r^2-c p^2 q+f o-f q)/(p q-o r)+c p)-a o^2-f))/o-(n (-a o^2 q+a o q^2+c o r^2-c p^2 q+f o-f q))/(p q-o r)-a m^2-f)/n^2 * or, in terms of c * * * * so */ }
public void DrawDays(Graphics graphics, RectangleF outer, RectangleF inner, PointF[] points) { if (!points.Any()) throw new ArgumentException(); var brush = GetSolidBrush(LineColor); var textBrush = GetSolidBrush(Color); var font = GetFont("Arial", 12); var oldest = GetOldestMondaiResult(); var newest = GetNewestMondaiResult(); var height = outer.Bottom - inner.Bottom; // var oldestRectangle = new RectangleF(outer.Left, inner.Bottom, 100f, height); var oldestRectangle = new RectangleF(points.Last().X, inner.Bottom, 100f, height); var newestRectangle = new RectangleF(points.First().X, inner.Bottom, 100f, height); var stringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near, }; // 現在時刻からの最古の日数と最新の日数を表示。最新の日数は最古の日数と被らない限り表示する。 // var d0 = MondaiResult.GetStringFromTimeSpan(EPuzzleTime.Now - oldest.StartTime); var d0 = (EPuzzleTime.Now - oldest.StartTime).GetShortString(); var size0 = MeasureString(d0, font); // oldestRectangle.X -= size0.Width / 2f; var r0 = new RectangleF(oldestRectangle.Left, oldestRectangle.Top, size0.Width, size0.Height); graphics.DrawString(d0, font, textBrush, oldestRectangle, stringFormat); // var d1 = MondaiResult.GetStringFromTimeSpan(EPuzzleTime.Now - newest.StartTime); var d1 = (EPuzzleTime.Now - newest.StartTime).GetShortString(); var size1 = MeasureString(d1, font); newestRectangle.X -= size1.Width / 2f; var r1 = new RectangleF(newestRectangle.Left, newestRectangle.Top, size1.Width, size1.Height); if (!r0.IntersectsWith(r1)) { graphics.DrawString(d1, font, textBrush, newestRectangle, stringFormat); } if (2 > points.Count()) return; var newest2 = OrderedItems[1]; var newest2Rectangle = new RectangleF(points[1].X, inner.Bottom, 100f, height); // var d2 = MondaiResult.GetStringFromTimeSpan(EPuzzleTime.Now - newest2.StartTime); var d2 = (EPuzzleTime.Now - newest2.StartTime).GetShortString(); var size2 = MeasureString(d2, font); newest2Rectangle.X -= size2.Width / 2f; var r2 = new RectangleF(newest2Rectangle.Left, newest2Rectangle.Top, size2.Width, size2.Height); if (!(r0.IntersectsWith(r2) || r1.IntersectsWith(r2))) { graphics.DrawString(d2, font, textBrush, newest2Rectangle, stringFormat); } }
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e) { Point offset = Point.Empty; offset.X += splitContainer1.Panel1.AutoScrollPosition.X; offset.Y += splitContainer1.Panel1.AutoScrollPosition.Y; //RectangleF cameraRect = new RectangleF(offset.X * -1, offset.Y * -1, splitContainer1.Panel1.Width, splitContainer1.Panel1.Height); foreach (cObject obj in objectManager.ObjectList) { if (obj != objectManager.SelectedObject) { //e.Graphics.DrawImage(obj.Image, obj.Rectangle); e.Graphics.DrawImage(obj.Image, new RectangleF((obj.Position.X * zoomLevel + offset.X), (obj.Position.Y * zoomLevel + offset.Y) , obj.Image.Width * zoomLevel, obj.Image.Height * zoomLevel), new RectangleF(0, 0, obj.Image.Width, obj.Image.Height), GraphicsUnit.Pixel); } } if (objectManager.SelectedObject != null) { //e.Graphics.DrawImage(objectManager.SelectedObject.Image, objectManager.SelectedObject.Rectangle); //e.Graphics.DrawRectangle(new Pen(Color.Black, 3), objectManager.SelectedObject.Rectangle); e.Graphics.DrawImage(objectManager.SelectedObject.Image, new RectangleF((objectManager.SelectedObject.Position.X * zoomLevel + offset.X) , (objectManager.SelectedObject.Position.Y * zoomLevel + offset.Y) , objectManager.SelectedObject.Image.Width * zoomLevel, objectManager.SelectedObject.Image.Height * zoomLevel), new RectangleF(0, 0, objectManager.SelectedObject.Image.Width, objectManager.SelectedObject.Image.Height), GraphicsUnit.Pixel); e.Graphics.DrawRectangle(new Pen(Color.Black, 3), (objectManager.SelectedObject.Position.X * zoomLevel + offset.X) , (objectManager.SelectedObject.Position.Y * zoomLevel + offset.Y) , objectManager.SelectedObject.Image.Width * zoomLevel, objectManager.SelectedObject.Image.Height * zoomLevel); if (collisionPolygonToolStripMenuItem.Checked) { if (objectManager.SelectedObject.CollisionPoints.Count > 0) { if (objectManager.SelectedObject.CollisionPoints.Count > 1) { Pen pen = new Pen(Color.Red, 2); PointF[] tempy = new PointF[objectManager.SelectedObject.CollisionPoints.Count]; objectManager.SelectedObject.CollisionPoints.CopyTo(tempy); for(int i = 0; i < tempy.Count(); ++i) { tempy[i] = new PointF((tempy[i].X * zoomLevel + offset.X), (tempy[i].Y * zoomLevel + offset.Y)); } e.Graphics.DrawLines(pen, tempy); if (objectManager.SelectedObject.CollisionPoints.Count > 2) { e.Graphics.DrawLine(pen, new PointF(tempy[0].X, tempy[0].Y), new PointF(tempy[tempy.Count() - 1].X, tempy[tempy.Count() - 1].Y)); if (objectManager.SelectedObject.CollisionPoints.Count > 3) label_NotConvex.Visible = !isConvex; } } foreach (PointF p in objectManager.SelectedObject.CollisionPoints) { if (objectManager.SelectedObject.SelectedPoint != -1 && p == objectManager.SelectedObject.CollisionPoints[objectManager.SelectedObject.SelectedPoint]) { e.Graphics.DrawEllipse(new Pen(Color.Blue, 4), (p.X * zoomLevel - (pointSize / 2) + offset.X), (p.Y * zoomLevel - (pointSize / 2) + offset.Y), pointSize, pointSize); continue; } e.Graphics.FillEllipse(new SolidBrush(Color.Blue), (p.X * zoomLevel - (pointSize / 2) + offset.X), (p.Y * zoomLevel - (pointSize / 2) + offset.Y), pointSize, pointSize); } } } } }