//Write X and Y coordinates of the mouse click to a csv file private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { System.Drawing.Point point = pictureBox1.PointToClient(Cursor.Position); int xPos = (int)(point.X / zoomScale); int yPos = (int)(point.Y / zoomScale); //Calculate the centroid of the ROI if the auto-centre option is on. Alter the x and y position. if (autoCentreCheckBox.Checked) { calculateCentrePoint(xPos, yPos, out xPos, out yPos); } //calculateCentrePoint(point.X, point.Y, out xPos, out yPos); //Search the list of output data for a point with the same cell number and picture number. If it exists, replace it with //the new point that was just clicked. int index = outputData.FindIndex(positionData => positionData != null && positionData.pictureNum == currentImage + 1 && positionData.cell == cellNumber); if (index != -1) { outputData[index] = new positionData { cell = cellNumber, pictureNum = currentImage + 1, xPosition = xPos, yPosition = yPos }; } else //add the datapoint to the list if it doesn't exist { outputData.Add(new positionData { cell = cellNumber, pictureNum = currentImage + 1, xPosition = xPos, yPosition = yPos }); } //Sort the list. First by cell number and then by picture number. outputData = outputData.OrderBy(x => x.cell).ThenBy(x => x.pictureNum).ToList(); //Draw a points and lines connecting updateImage(); } //Delete current point if the mouse click was a right click else if (e.Button == MouseButtons.Right) { //Search the list of output data for a point with the same cell number and picture number. If it exists, delete the point int index = outputData.FindIndex(positionData => positionData != null && positionData.pictureNum == currentImage + 1 && positionData.cell == cellNumber); if (index != -1) { outputData.RemoveAt(index); //Delete the point updateImage(); } } }
//Update the image displayed in the picturebox and the "Image: current/total" Label //TODO: select the current image on the listboxs public void updateImage() { if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } Image image = Image.FromFile(imageFilePath[currentImage]); //Convert if indexed to non-indexed - NOTE: only converts 8bppIndexed right now because I didn't have any other images to test - Jeff 2018/04/14 if (image.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { pictureBox1.Image = Indexed2Image(image, System.Drawing.Imaging.PixelFormat.Format24bppRgb); } else { pictureBox1.Image = image; } //Draw all the circles of the previous images. For example, if you are on image number 20, it will draw the circles from images 1 to 19 //Might have performance issues in this method once we start getting to the upper data points if (showPrevCheckBox.Checked) { int xLast = 0, yLast = 0; foreach (var prevDataPoint in outputData) { //Draw connecting lines to each dot if (prevDataPoint.pictureNum <= currentImage + 1) { DrawCircle(prevDataPoint.xPosition, prevDataPoint.yPosition, prevDataPoint.cell); if (prevDataPoint.pictureNum == 1) { xLast = prevDataPoint.xPosition; yLast = prevDataPoint.yPosition; } else { DrawLine(xLast, yLast, prevDataPoint.xPosition, prevDataPoint.yPosition, prevDataPoint.cell); } } xLast = prevDataPoint.xPosition; yLast = prevDataPoint.yPosition; } } else { foreach (var prevDataPoint in outputData) { if (prevDataPoint.pictureNum == currentImage + 1) { DrawCircle(prevDataPoint.xPosition, prevDataPoint.yPosition, prevDataPoint.cell); } } } //Draw the number of the cell of the last point in each cell number series for (int i = 1; i <= totalNumCells; i++) { positionData lastCellInSeries = new positionData(); lastCellInSeries = outputData.Where(dataPoint => dataPoint.cell == i).Where(datapoint => datapoint.pictureNum <= currentImage + 1).OrderByDescending(x => x.pictureNum).FirstOrDefault(); if (lastCellInSeries != null) { DrawCell(lastCellInSeries.xPosition, lastCellInSeries.yPosition, lastCellInSeries.cell); } } //Update the image ##/## label imageLabel.Text = "Image: " + (currentImage + 1).ToString() + "/" + numImages.ToString(); //Update the cell # label cellNumberLabel.Text = "CELL #: " + cellNumber.ToString(); }