/// <summary> /// Exports a slice of the SAR field at the plane defined by the normal direction and location parameters. /// </summary> /// <param name="fileName">Name of the output .png file.</param> /// <param name="direction">Normal direction of the SAR slice plane.</param> /// <param name="location">Location of the slice along the normal direction.</param> public void ToPNG(string fileName, ENormDir direction, double location) { int imageSize = 512; // TBD double clipdB = -40.0; // TBD FieldSlice fieldSlice = GetFieldSlice(direction, location); int pixelSizeX, pixelSizeY; double fieldSizeX = fieldSlice.Mesh[0].Last() - fieldSlice.Mesh[0].First(); double fieldSizeY = fieldSlice.Mesh[1].Last() - fieldSlice.Mesh[1].First(); double stepSize; if (fieldSizeX > fieldSizeY) { pixelSizeX = imageSize; pixelSizeY = (int)(imageSize * fieldSizeY / fieldSizeX); stepSize = fieldSizeX / (imageSize - 1); } else { pixelSizeY = imageSize; pixelSizeX = (int)(imageSize * fieldSizeX / fieldSizeY); stepSize = fieldSizeY / (imageSize - 1); } Bitmap bmp = new Bitmap(pixelSizeX, pixelSizeY, System.Drawing.Imaging.PixelFormat.Format32bppRgb); double fieldStartX = fieldSlice.Mesh[0][0]; double fieldStartY = fieldSlice.Mesh[1][0]; double fieldMax = fieldSlice.Max(); for (int x = 0; x < pixelSizeX; x++) { for (int y = 0; y < pixelSizeY; y++) { double valSAR = fieldSlice.GetValueAt( fieldSlice.Mesh[0][0] + x * stepSize, fieldSlice.Mesh[1][0] + y * stepSize); double valSARdB = 10 * Math.Log10(valSAR); valSARdB -= 10 * Math.Log10(fieldMax); double hueSARdB = valSARdB / clipdB * 240.0; hueSARdB = hueSARdB > 240.0 ? 240.0 : hueSARdB; bmp.SetPixel(x, y, ColorFromHSV(hueSARdB, 1.0, 0.9)); } } bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); }
public void SAR_GetValueAt_NonGridPoint_ReturnsGridPointValue() { double refFieldValue = 2.0; double[][] mesh = SAR_BuildExampleMesh(); double[,] field = SAR_BuildConstantField(mesh, refFieldValue); Postprocess.FieldSlice fieldSlice = new FieldSlice(mesh, field); double dutFieldValue = fieldSlice.GetValueAt((mesh[0][1] + mesh[0][2]) / 2, (mesh[1][1] + mesh[1][2]) / 2); Assert.Equal(refFieldValue, dutFieldValue); }
public void SAR_GetValueAt_OutOfRangeInput_ThrowsException() { double refFieldValue = 2.0; double[][] mesh = SAR_BuildExampleMesh(); double[,] field = SAR_BuildConstantField(mesh, refFieldValue); Postprocess.FieldSlice fieldSlice = new FieldSlice(mesh, field); Assert.Throws<ArgumentException>( delegate { fieldSlice.GetBoundingMeshIndeces(mesh[0][0] - 1.0, mesh[1][0] - 0.0); }); }
public void SAR_GetBoundingMeshIndeces_NonGridPointInput_ReturnsCorrectValue() { double[][] mesh = SAR_BuildExampleMesh(); Postprocess.FieldSlice fieldSlice = new FieldSlice(mesh, null); int[,] refIndeces = new int[2,2] { {1, 2}, {1, 2} }; int[,] dutIndeces = fieldSlice.GetBoundingMeshIndeces(mesh[0][1] + 0.1, mesh[1][1] + 0.1); Assert.Equal(refIndeces, dutIndeces); }
public void SAR_GetBoundingMeshIndeces_OutOfRangeInput_ThrowsException() { double[][] mesh = SAR_BuildExampleMesh(); Postprocess.FieldSlice fieldSlice = new FieldSlice(mesh, null); Assert.Throws<ArgumentException>( delegate { fieldSlice.GetBoundingMeshIndeces(mesh[0][0] - 1.0, mesh[1][0] - 1.0); }); }