DrawStithchingBase.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace PaintDotNet.Annotation.ImageCollect
  8. {
  9. public enum LockType
  10. {
  11. NULL = 0,
  12. AREA = 1,
  13. SIZE = 2
  14. }
  15. public abstract class DrawStithchingBase : DrawObject
  16. {
  17. public static int ViewWidth = 2048;
  18. public static int ViewHeight = 2048;
  19. public static float Interval = 0.1f;
  20. private static int _OffsetX;
  21. private static int _OffsetY;
  22. public static int OffsetX { get => _OffsetX + SystemOffset; set { _OffsetX = value; } }
  23. public static int OffsetY { get => _OffsetY + SystemOffset; set { _OffsetY = value; } }
  24. private const int SystemOffset = 21;
  25. protected int[] tiles = new int[2];
  26. protected List<ZScanParameter> zscan = new List<ZScanParameter>();
  27. /// <summary>
  28. /// 锁定方式
  29. /// </summary>
  30. public static LockType lockType = LockType.NULL;
  31. protected RectangleF rectangleMax = new RectangleF();
  32. protected List<Dictionary<int, object>> _points = new List<Dictionary<int, object>>();
  33. /// <summary>
  34. /// 获取拼图区域划分的网格数
  35. /// </summary>
  36. public virtual int[] GetTiles()
  37. {
  38. int[] result = new int[2];
  39. result[0] = tiles[0];// * 2;
  40. result[1] = tiles[1];// * 2;
  41. return result;
  42. }
  43. public virtual int ColumnNum { get => tiles[0]; }
  44. public virtual int RowNum { get => tiles[1]; }
  45. public List<int> deletedPointId = new List<int>();
  46. /// <summary>
  47. /// 获取拼图区域面积
  48. /// </summary>
  49. /// <returns></returns>
  50. public virtual double GetArea()
  51. {
  52. double m_unitLength;
  53. this.ISurfaceBox.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out m_unitLength);
  54. double area = Math.Round((rectangleMax.Width * m_unitLength * rectangleMax.Height * m_unitLength / 1000000), 3);
  55. return area;
  56. }
  57. public virtual void Lock(LockType type)
  58. {
  59. lockType = type;
  60. }
  61. public virtual List<Dictionary<int, object>> GetViewPoints()
  62. {
  63. return _points;
  64. }
  65. public virtual void DeletePoint(int index)
  66. {
  67. deletedPointId.Add(index);
  68. }
  69. public virtual void SetZAxisScan(ZScanParameter zScanParameter, int pIndex = 999999)
  70. {
  71. if (pIndex == 999999)
  72. {
  73. zscan.Clear();
  74. for (int j = 0; j < tiles[1]; j++)
  75. {
  76. for (int i = 0; i < tiles[0]; i++)
  77. {
  78. zscan.Add(zScanParameter.Clone());
  79. }
  80. }
  81. }
  82. else
  83. {
  84. zscan[pIndex] = zScanParameter.Clone();
  85. }
  86. }
  87. public virtual ZScanParameter GetZAxisScan(int index)
  88. {
  89. return zscan[index];
  90. }
  91. /// <summary>
  92. /// 计算偏移后的点
  93. /// </summary>
  94. protected Func<float, float, PointF> OffsetPointF = (x, y) => new PointF(x + OffsetX, y + OffsetY);
  95. }
  96. public class ZScanParameter
  97. {
  98. public double Start;
  99. public double Stop;
  100. public int Times = 5;
  101. public double Track;
  102. public ZScanParameter Clone()
  103. {
  104. return MemberwiseClone() as ZScanParameter;
  105. }
  106. }
  107. }