schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace XImagingXhandler.XDAL
{
    /// <summary>
    /// 板位表校准后的坐标x轴,y轴,z轴值计算写入数据库
    /// </summary>
    public class LatticeCalc
    {
        #region 判断是否在同一平面内平行或符合误差范围(四点定位法)
        /// <summary>
        /// 判断是否在同一平面内平行或符合误差范围(四点定位法)
        /// </summary>
        /// <param name="lattices">多个板位采集点对象数据集</param>
        /// <param name="rangeVal">允许的误差范围值</param>
        /// <returns>true:在允许范围内;false:不在允许范围内</returns>
        public bool isEnableValue(List<Lattice> lattices, double rangeVal)
        {
            bool bResult = true;
 
            if (lattices.Count >= 2)
            {
                if (lattices.Count == 2)
                {
                    if (lattices[0].lattice_X - rangeVal < lattices[1].lattice_X && lattices[1].lattice_X < lattices[0].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                }
                if (lattices.Count == 3)
                {
                    if (lattices[0].lattice_X - rangeVal < lattices[2].lattice_X && lattices[2].lattice_X < lattices[0].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
 
                    if (lattices[0].lattice_Y - rangeVal < lattices[1].lattice_Y && lattices[1].lattice_Y < lattices[0].lattice_Y + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                    if (lattices[2].lattice_Z - rangeVal < lattices[0].lattice_Z && lattices[0].lattice_Z < lattices[2].lattice_Z + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                    if (lattices[1].lattice_Z - rangeVal < lattices[0].lattice_Z && lattices[0].lattice_Z < lattices[1].lattice_Z + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                }
                if (lattices.Count == 4)
                {
                    if (lattices[0].lattice_X - rangeVal < lattices[1].lattice_X && lattices[1].lattice_X < lattices[0].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
 
                    if (lattices[1].lattice_X - rangeVal < lattices[2].lattice_X && lattices[2].lattice_X < lattices[1].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                    if (lattices[2].lattice_X - rangeVal < lattices[3].lattice_X && lattices[3].lattice_X < lattices[2].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                    if (lattices[3].lattice_X - rangeVal < lattices[4].lattice_X && lattices[4].lattice_X < lattices[3].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                    if (lattices[4].lattice_X - rangeVal < lattices[0].lattice_X && lattices[0].lattice_X < lattices[4].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                    if (lattices[3].lattice_X - rangeVal < lattices[1].lattice_X && lattices[1].lattice_X < lattices[3].lattice_X + rangeVal)
                    {
 
                    }
                    else
                    {
                        bResult = false;
                    }
                }
            }
            return bResult;
        }
        #endregion
 
        #region 根据标定采集的点,计算出板位坐标和偏转角(四点定位法)
        /// <summary>
        /// 根据标定采集的点,计算出板位坐标和偏转角(四点定位法)
        /// </summary>
        /// <param name="lattices">移采集的点位坐标实体集合</param>
        /// <param name="rangeVal">精度值</param>
        /// <returns>校准后的板位对象包含点位偏转值</returns>
        public Lattice GenerateLatticeData(List<Lattice> lattices, double rangeVal)
        {
            Lattice lattice = new Lattice();
 
            lattice.lattice_id = lattices[0].lattice_id;
            lattice.lattice_num = lattices[0].lattice_num;
            lattice.lattice_X = lattices[0].lattice_X;
            lattice.lattice_Y = lattices[0].lattice_Y;
            lattice.lattice_Z = lattices[0].lattice_Z;
            lattice.software_information_id = lattices[0].software_information_id;
            lattice.lattice_length = lattices[0].lattice_length;
            lattice.lattice_width = lattices[0].lattice_width;
            lattice.lattice_height = lattices[0].lattice_height;
 
            if (lattices.Count > 3)
            {
 
                //第一条和第二条为X轴校准,比较y轴差值
                double cVal1 = (double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y;
                double cVal2 = (double)lattices[2].lattice_X - (double)lattices[0].lattice_X;
 
                double Q1 = 0;
                double Q2 = 0;
 
                if (Math.Abs(cVal1) > rangeVal)
                {
                    //需要计算转角值
                    Q1 = Math.Atan2(Math.Abs((double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y), Math.Abs((double)lattices[1].lattice_X - (double)lattices[0].lattice_X));//角度
                }
                if (Math.Abs(cVal2) > rangeVal)
                {
                    //需要计算转角值
                    Q2 = Math.Atan2(Math.Abs((double)lattices[2].lattice_X - (double)lattices[0].lattice_X), Math.Abs((double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y));//角度
                }
 
                lattice.lattice_lp_X = Q1;
                lattice.lattice_lp_Y = Q2;
            }
 
            if (lattices.Count == 2)
            {
 
                //第一条和第二条为X轴校准,比较y轴差值
                double cVal1 = (double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y;
                //double cVal2 = (double)lattices[2].lattice_X - (double)lattices[0].lattice_X;
 
                double Q1 = 0;
                double Q2 = 0;
 
                if (Math.Abs(cVal1) > rangeVal)
                {
                    //需要计算转角值
                    Q1 = Math.Atan2(Math.Abs((double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y), Math.Abs((double)lattices[1].lattice_X - (double)lattices[0].lattice_X));//角度
                }
                //if (Math.Abs(cVal2) > rangeVal)
                //{
                //    //需要计算转角值
                //    Q2 = Math.Atan2(Math.Abs((double)lattices[2].lattice_X - (double)lattices[0].lattice_X), Math.Abs((double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y));//角度
                //}
                Q2 = Q1;
 
                lattice.lattice_lp_X = Q1;
                lattice.lattice_lp_Y = Q2;
            }
 
            //if (lattices.Count == 1)
            //{
 
            //    //第一条和第二条为X轴校准,比较y轴差值
            //    double cVal1 = (double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y;
            //    //double cVal2 = (double)lattices[2].lattice_X - (double)lattices[0].lattice_X;
 
            //    double Q1 = 0;
            //    double Q2 = 0;
 
            //    if (Math.Abs(cVal1) > rangeVal)
            //    {
            //        //需要计算转角值
            //        Q1 = Math.Atan2(Math.Abs((double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y), Math.Abs((double)lattices[1].lattice_X - (double)lattices[0].lattice_X));//角度
            //    }
            //    //if (Math.Abs(cVal2) > rangeVal)
            //    //{
            //    //    //需要计算转角值
            //    //    Q2 = Math.Atan2(Math.Abs((double)lattices[2].lattice_X - (double)lattices[0].lattice_X), Math.Abs((double)lattices[1].lattice_Y - (double)lattices[0].lattice_Y));//角度
            //    //}
            //    Q2 = Q1;
 
            //    lattice.lattice_lp_X = Q1;
            //    lattice.lattice_lp_Y = Q2;
            //}
 
            return lattice;
        }
        #endregion
 
        #region 根据标定采集的耗材A1孔坐标,计算出板位左上角的坐标(A1孔中心定位法)
        /// <summary>
        /// 根据标定采集的耗材A1孔坐标,计算出板位左上角的坐标(A1孔中心定位法)
        /// </summary>
        /// <param name="lattices">移采集的点位坐标实体集合</param>
        /// <param name="labware">耗材实体</param>
        /// <returns>利用A1孔中心定位法计算出的板位左上角坐标的板位对象</returns>
        public Lattice GenerateLatticeData(List<Lattice> lattices, Labware labware)
        {
            Lattice lattice = new Lattice();
 
            lattice.lattice_id = lattices[0].lattice_id;
            lattice.lattice_num = lattices[0].lattice_num;
            lattice.lattice_X = lattices[0].lattice_X;
            lattice.lattice_Y = lattices[0].lattice_Y;
            lattice.lattice_Z = lattices[0].lattice_Z;
            lattice.software_information_id = lattices[0].software_information_id;
            lattice.lattice_length = lattices[0].lattice_length;
            lattice.lattice_width = lattices[0].lattice_width;
            lattice.lattice_height = lattices[0].lattice_height;
 
            if (lattices.Count == 1)
            {
                //根据校准的A1孔坐标换算出板位左上角的坐标
                if (labware.well_shape == 1)//圆形
                {
                    lattice.lattice_X = lattices[0].lattice_X + labware.a1_distance_x;
                    lattice.lattice_Y = lattices[0].lattice_Y - labware.a1_distance_y;
                    lattice.lattice_lp_X = 0;
                    lattice.lattice_lp_Y = 0;
 
                }
                else if (labware.well_shape == 2)//方形
                {
                    lattice.lattice_X = lattices[0].lattice_X + labware.a1_distance_x;
                    lattice.lattice_Y = lattices[0].lattice_Y - labware.a1_distance_y;
                    lattice.lattice_lp_X = 0;
                    lattice.lattice_lp_Y = 0;
                }
            }
 
            return lattice;
        }
        #endregion
 
        #region 根据标定板位上刻度为A1的中心焦点(如果是单通道,采集四个点,如果是8通道,采集左上角一个点),计算出板位左上角的坐标(原点在右上角)
        /// <summary>
        /// 根据标定板位上刻度为A1的中心焦点(如果是单通道,采集四个点,如果是8通道,采集左上角一个点),计算出板位左上角的坐标(原点在右上角)
        /// </summary>
        /// <param name="lattices">移采集的点位坐标实体集合</param>
        /// <param name="labware">耗材实体</param>
        /// <returns>在某个通道臂下,最终板位左上角的坐标</returns>
        public Lattice GenerateLatticeDataForX1(List<Lattice> lattices, Labware labware)
        {
            Lattice lattice = new Lattice();
 
            lattice.lattice_id = lattices[0].lattice_id;
            lattice.lattice_num = lattices[0].lattice_num;
            lattice.lattice_X = lattices[0].lattice_X;
            lattice.lattice_Y = lattices[0].lattice_Y;
            lattice.lattice_Z = lattices[0].lattice_Z;
            lattice.software_information_id = lattices[0].software_information_id;
            lattice.lattice_length = lattices[0].lattice_length;
            lattice.lattice_width = lattices[0].lattice_width;
            lattice.lattice_height = lattices[0].lattice_height;
 
            if (lattices.Count == 1)
            {
                lattice.lattice_X = lattices[0].lattice_X + 14.40d;
                lattice.lattice_Y = lattices[0].lattice_Y - 11.25d;
                lattice.lattice_Z = lattices[0].lattice_Z + 10.09 + (labware.tip_length - labware.press_tipinto_depth);
                lattice.lattice_lp_X = 0;
                lattice.lattice_lp_Y = 0;
            }
            return lattice;
        }
        #endregion
 
        #region 根据标定小孔采集点(如果是单通道,采集四个点,如果是8通道,采集左上角一个点),计算出板位左上角的坐标(原点在左上角)
        /// <summary>
        /// 根据标定小孔采集点(如果是单通道,采集四个点,如果是8通道,采集左上角一个点),计算出板位左上角的坐标(原点在左上角)
        /// </summary>
        /// <param name="lattices">移采集的点位坐标实体集合</param>
        /// <param name="labware">耗材实体</param>
        /// <returns>在某个通道臂下,最终板位左上角的坐标</returns>
        public Lattice GenerateLatticeDataForLite(List<Lattice> lattices, Labware labware)
        {
            Lattice lattice = new Lattice();
 
            lattice.lattice_id = lattices[0].lattice_id;
            lattice.lattice_num = lattices[0].lattice_num;
            lattice.lattice_X = lattices[0].lattice_X;
            lattice.lattice_Y = lattices[0].lattice_Y;
            lattice.lattice_Z = lattices[0].lattice_Z;
            lattice.software_information_id = lattices[0].software_information_id;
            lattice.lattice_length = lattices[0].lattice_length;
            lattice.lattice_width = lattices[0].lattice_width;
            lattice.lattice_height = lattices[0].lattice_height;
 
            if (lattices.Count == 1)
            {
                lattice.lattice_X = lattices[0].lattice_X - 14.40d;
                lattice.lattice_Y = lattices[0].lattice_Y - 11.25d;
                lattice.lattice_Z = lattices[0].lattice_Z + 10.09 + (labware.tip_length - labware.press_tipinto_depth);
                lattice.lattice_lp_X = 0;
                lattice.lattice_lp_Y = 0;
            }
            return lattice;
        }
        #endregion
    }
}