algoLib/sourceCode/beltTearingDetection.cpp

1296 lines
40 KiB
C++
Raw Normal View History

2025-06-08 10:46:41 +08:00
#include <vector>
#include "SG_baseDataType.h"
#include "SG_baseAlgo_Export.h"
#include "beltTearingDetection_Export.h"
#include <opencv2/opencv.hpp>
#include "SG_errCode.h"
typedef struct
{
int tearID;
int vGap_num;
double vGap_depth_max;
double vGap_width_max;
double vGap_width_sum; //<2F><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>ֵ
int hGap_num;
double hGap_depth_max;
double hGap_width_max; //<2F><><EFBFBD><EFBFBD>ֵΪ˺<CEAA><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double hGap_width_sum; //<2F><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>ֵ
}SSG_tearProcessInfo; //˺<>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double _getGapDepth(std::vector<SVzNL3DPosition>& vldPts, int start, int end)
{
double start_z = vldPts[start].pt3D.z;
double end_z = vldPts[end].pt3D.z;
double max_z = start_z;
for (int i = start+1; i <= end; i++)
{
if (max_z < vldPts[i].pt3D.z)
max_z = vldPts[i].pt3D.z;
}
double depth = max_z - (start_z + end_z) / 2;
return depth;
}
void _combineROI(SSG_ROIRectD* roi, SSG_ROIRectD* sub_roi)
{
if (roi->left > sub_roi->left)
roi->left = sub_roi->left;
if (roi->right < sub_roi->right)
roi->right = sub_roi->right;
if (roi->top > sub_roi->top)
roi->top = sub_roi->top;
if (roi->bottom < sub_roi->bottom)
roi->bottom = sub_roi->bottom;
return;
}
bool compareByStartY(const SSG_basicFeatureGap& a, const SSG_basicFeatureGap& b) {
return a.gap_start < b.gap_start;
}
//<2F><>ֱɨ<D6B1><C9A8><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
//<2F><>ֱɨ<D6B1><C9A8><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>1mm<6D><6D>ʹ<EFBFBD>ò<EFBFBD><C3B2>ֹ<EFBFBD>ʽ<EFBFBD><CABD>
void sg_bearTearing_vLineProc(
SVzNL3DLaserLine* a_line, //<2F><>ǰɨ<C7B0><C9A8><EFBFBD><EFBFBD>
int lineIdx, //<2F><>ǰɨ<C7B0><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const SSG_beltTearingParam measureParam,
std::vector<SSG_basicFeatureGap>& vLineFeatures)
{
//double minGapW = 1.0;
//<2F><>դ<EFBFBD><D5A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ͳ<><CDB3>Gap
std::vector<SVzNL3DPosition> vldPts;
std::vector<SSG_RUN> gaps;
int preIdx = -1;
int vldPtSize = 0;
int gapSize = 0;
for (int i = 0; i < a_line->nPositionCnt; i++)
{
SVzNL3DPosition a_pt = a_line->p3DPosition[i];
if (a_pt.pt3D.z > 1e-4)
{
a_pt.nPointIdx = -1;
if (preIdx >= 0)
{
int gapPtNum = i - preIdx - 1;
double gapW = abs(a_pt.pt3D.y - vldPts[vldPtSize - 1].pt3D.y);
if ((gapPtNum >= 2) && (gapW > 1.0))
{
SSG_RUN a_gap = { vldPtSize-1, 2, 0};//vldGap
gaps.push_back(a_gap);
vldPts[vldPtSize - 1].nPointIdx = gapSize;
a_pt.nPointIdx = gapSize;
gapSize++;
}
}
vldPts.push_back(a_pt);
vldPtSize++;
preIdx = i;
}
}
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD>ײ<EFBFBD><D7B2><EFBFBD>ֵ
std::vector<double> difference;
std::vector<int> diffBinValue;
difference.resize(vldPts.size());
diffBinValue.resize(vldPts.size());
for (int i = 1, i_max = vldPts.size(); i < i_max; i++)
{
double a_difference = (vldPts[i].pt3D.z - vldPts[i-1].pt3D.z) / (vldPts[i].pt3D.y - vldPts[i - 1].pt3D.y);
difference[i] = a_difference;
int a_binValue;
a_binValue = a_difference > measureParam.differnceBinTh ? 1 : (a_difference < -measureParam.differnceBinTh ? -1 : 0);
diffBinValue[i] = a_binValue;
if (1 == i) //<2F><>һ<EFBFBD><D2BB>
{
difference[0] = a_difference;
diffBinValue[0] = a_binValue;
}
}
//<2F><><EFBFBD><EFBFBD>+1<><31><EFBFBD>к<EFBFBD>-1<><31><EFBFBD><EFBFBD>
std::vector< SSG_RUN> runs;
SSG_RUN a_run;
memset(&a_run, 0, sizeof(SSG_RUN));
for (int i = 1, i_max = vldPts.size(); i < i_max; i++)
{
if (0 != diffBinValue[i])
{
if (0 == a_run.value)
{
a_run.start = i;
a_run.len = 1;
a_run.value = diffBinValue[i];
}
else
{
if (a_run.value != diffBinValue[i])
{
runs.push_back(a_run);
a_run.start = i;
a_run.len = 1;
a_run.value = diffBinValue[i];
}
else
{
a_run.len++;
}
}
}
else
{
if (0 != a_run.value)
{
runs.push_back(a_run);
memset(&a_run, 0, sizeof(SSG_RUN));
}
}
}
if (0 != a_run.value) //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
{
runs.push_back(a_run);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0, i_max = runs.size(); i < i_max; i++)
{
SSG_RUN a_run = runs[i];
if (0 == a_run.value)
continue;
if (i < i_max-1)
{
SSG_RUN* nxt_run = &runs[i + 1];
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (a_run.value != nxt_run->value)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double pos_end = vldPts[a_run.start + a_run.len - 1].pt3D.y;
double nxt_pos_start = vldPts[nxt_run->start].pt3D.y;
double dist = nxt_pos_start - pos_end;
if (dist < measureParam.extractPara.sameGapTh)
{
a_run.len = nxt_run->start + nxt_run->len - a_run.start;
nxt_run->value = 0; //invalid
}
}
}
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Gap<61><70><EFBFBD><EFBFBD>ȷȷ<C8B7><C8B7><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD><E3A3AC><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Gap
int start = a_run.start;
int end = a_run.start + a_run.len - 1;
bool hasGap = false;
for (int m = 0; m < measureParam.extractPara.gapChkWin; m++)
{
int ptIdx = a_run.start - m;
if (ptIdx > 0)
{
double gapLen = vldPts[ptIdx].pt3D.y - vldPts[ptIdx-1].pt3D.y;
if (gapLen > measureParam.scanYScale * 2) //<2F>ҵ<EFBFBD>Gap
{
start = ptIdx - 1;
hasGap = true;
if (vldPts[ptIdx].nPointIdx >= 0)
gaps[vldPts[ptIdx].nPointIdx].value = 1; //invalid
if(vldPts[ptIdx - 1].nPointIdx >= 0)
gaps[vldPts[ptIdx - 1].nPointIdx].value = 1; //invalid
break;
}
}
}
int vldPtSize = vldPts.size();
for (int m = 0; m < measureParam.extractPara.gapChkWin; m++)
{
int ptIdx = a_run.start + a_run.len - 1 + m;
if (ptIdx < vldPtSize-1)
{
double gapLen = vldPts[ptIdx+1].pt3D.y - vldPts[ptIdx ].pt3D.y;
if (gapLen > measureParam.scanYScale * 2) //<2F>ҵ<EFBFBD>Gap
{
end = ptIdx + 1;
hasGap = true;
if (vldPts[ptIdx].nPointIdx >= 0)
gaps[vldPts[ptIdx].nPointIdx].value = 1; //invalid
if (vldPts[ptIdx + 1].nPointIdx >= 0)
gaps[vldPts[ptIdx + 1].nPointIdx].value = 1; //invalid
break;
}
}
}
if (end > start) //gap<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SSG_basicFeatureGap a_feature;
memset(&a_feature, 0, sizeof(SSG_basicFeatureGap));
a_feature.lineIdx = lineIdx;
a_feature.gap_start = vldPts[start].pt3D.y;
a_feature.gap_width = vldPts[end].pt3D.y - vldPts[start].pt3D.y;
a_feature.gapPt_0 = vldPts[start];
a_feature.gapPt_1 = vldPts[end];
double x1, x2;
if (vldPts[end].pt3D.x > vldPts[start].pt3D.x)
{
x1 = vldPts[start].pt3D.x;
x2 = vldPts[end].pt3D.x;
}
else
{
x1 = vldPts[end].pt3D.x;
x2 = vldPts[start].pt3D.x;
}
a_feature.roi = { x1, x2, vldPts[start].pt3D.y, vldPts[end].pt3D.y };
if (true == hasGap)
a_feature.gap_depth = -1; //<2F><>͸<EFBFBD><CDB8>˺<EFBFBD><CBBA>
else
a_feature.gap_depth = _getGapDepth(vldPts, start, end);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰһ<C7B0><D2BB>feature<72>Ƿ񽻲<C7B7><F1BDBBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (vLineFeatures.size() > 0)
{
SSG_basicFeatureGap* pre_feature = &vLineFeatures[vLineFeatures.size() - 1];
if ((a_feature.roi.bottom > pre_feature->roi.top) && (pre_feature->roi.bottom > a_feature.roi.top)) //<2F>ϲ<EFBFBD>
{
//<2F>ϲ<EFBFBD>
pre_feature->gapPt_1 = a_feature.gapPt_1;
_combineROI(&pre_feature->roi, &a_feature.roi);
if ((a_feature.gap_depth < 0) || (pre_feature->gap_depth < 0))
pre_feature->gap_depth = -1;
else
pre_feature->gap_depth = pre_feature->gap_depth < a_feature.gap_depth ? a_feature.gap_depth : pre_feature->gap_depth;
pre_feature->gap_width = pre_feature->roi.bottom - pre_feature->roi.top;
}
else
{
double dist_y = a_feature.roi.top - pre_feature->roi.bottom;
if (dist_y < measureParam.scanYScale * 3)
{
//<2F>ϲ<EFBFBD>
pre_feature->gapPt_1 = a_feature.gapPt_1;
_combineROI(&pre_feature->roi, &a_feature.roi);
if ((a_feature.gap_depth < 0) || (pre_feature->gap_depth < 0))
pre_feature->gap_depth = -1;
else
pre_feature->gap_depth = pre_feature->gap_depth < a_feature.gap_depth ? a_feature.gap_depth : pre_feature->gap_depth;
pre_feature->gap_width = pre_feature->roi.bottom - pre_feature->roi.top;
}
else
vLineFeatures.push_back(a_feature);
}
}
else //if(a_gap.gap_width > minGapW) //С<><D0A1>minGapW<70><57><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
vLineFeatures.push_back(a_feature);
}
}
#if KEEP_GAP_AS_FEATURE
//<2F><>Gap<61><70><EFBFBD><EFBFBD>feature
int gapFeatureNum = 0;
for (int i = 0, i_max = gaps.size(); i < i_max; i++)
{
SSG_RUN* a_run = &gaps[i];
if (0 == a_run->value) //valid
{
int start = a_run->start;
int end = a_run->start + a_run->len - 1;
SSG_basicFeatureGap a_gap;
memset(&a_gap, 0, sizeof(SSG_basicFeatureGap));
a_gap.lineIdx = lineIdx;
a_gap.gap_start = vldPts[start].pt3D.y;
a_gap.gap_width = vldPts[end].pt3D.y - vldPts[start].pt3D.y;
a_gap.gapPt_0 = vldPts[start];
a_gap.gapPt_1 = vldPts[end];
double x1, x2;
if (vldPts[end].pt3D.x > vldPts[start].pt3D.x)
{
x1 = vldPts[start].pt3D.x;
x2 = vldPts[end].pt3D.x;
}
else
{
x1 = vldPts[end].pt3D.x;
x2 = vldPts[start].pt3D.x;
}
a_gap.roi = { x1, x2, vldPts[start].pt3D.y, vldPts[end].pt3D.y };
a_gap.gap_depth = -1; //<2F><>͸<EFBFBD><CDB8>˺<EFBFBD><CBBA>
vLineFeatures.push_back(a_gap);
gapFeatureNum++;
}
}
//<2F><><EFBFBD><EFBFBD>
if (gapFeatureNum > 0)
{
std::sort(vLineFeatures.begin(), vLineFeatures.end(), compareByStartY);
}
#endif
return;
}
//ˮƽɨ<C6BD><C9A8><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ˮƽɨ<C6BD><C9A8><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>1mm<6D><6D>ʹ<EFBFBD>ò<EFBFBD><C3B2>ֹ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ֱ֮<D6AE><D6B1>ʹ<EFBFBD><CAB9>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
void sg_bearTearing_hLineProc(
SSG_hLineProInfo* hLineProc,
int workerIdx,
int hLineIdx, //ˮƽɨ<C6BD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Ӧ<EFBFBD><D3A6>ֱɨ<D6B1><C9A8><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SVzNL3DLaserLine** buffLines,
const SSG_beltTearingParam measureParam,
std::vector<SSG_basicFeatureGap>& hLineFeatures )
{
//ע<><EFBFBD><E2A3BA><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ʱ<EFBFBD><CAB1>buffer<65>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>buffer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4A1A3><EFBFBD><EFBFBD><E5B4A6><EFBFBD>Ӻ<EFBFBD><D3BA><EFBFBD>SCAN_BUFF_SIZE / 2<><32><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>
int midPos = SCAN_BUFF_SIZE / 2;
SVzNL3DPosition* procData = &(buffLines[midPos]->p3DPosition[workerIdx]);
if (procData->pt3D.z < 1e-4)
return;
if (hLineProc->preVldData.pt3D.z < 1e-4)
{
hLineProc->preVldData = *procData;
return;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
double x_diff = procData->pt3D.x - hLineProc->preVldData.pt3D.x;
double a_difference;
int a_binValue;
if (x_diff > measureParam.tearingMinGap)
{
hLineProc->gapPos.nPointIdx = -1;
hLineProc->hLineSM = keSG_HLineProc_Init;
memset(&hLineProc->firstHalf, 0, sizeof(SSG_RUN));
memset(&hLineProc->firstHalf_startPt, 0, sizeof(SVzNL3DPosition));
memset(&hLineProc->firstHalf_endPt, 0, sizeof(SVzNL3DPosition));
a_difference = 0.0;
a_binValue = 0;
}
else
{
//<2F><><EFBFBD><EFBFBD>Gap
if (x_diff > measureParam.scanXScale * 2) //<2F>ҵ<EFBFBD>Gap
{
hLineProc->gapPos = hLineProc->preVldData;
}
a_difference = procData->pt3D.z - hLineProc->preVldData.pt3D.z;
if (measureParam.scanXScale < 1.0)
a_difference = a_difference / x_diff;
a_binValue = a_difference > measureParam.differnceBinTh ? 1 : (a_difference < -measureParam.differnceBinTh ? -1 : 0);
}
switch (hLineProc->hLineSM)
{
case keSG_HLineProc_Init:
if (a_binValue != 0)
{
hLineProc->gapMaxZ = procData->pt3D.z;
hLineProc->firstHalf.start = procData->nPointIdx;
hLineProc->firstHalf.len = 1;
hLineProc->firstHalf.value = a_binValue;
hLineProc->firstHalf_startPt = *procData;
hLineProc->firstHalf_endPt = *procData;
hLineProc->hLineSM = keSG_HLineProc_First_Half;
}
break;
case keSG_HLineProc_First_Half:
if(hLineProc->gapMaxZ < procData->pt3D.z)
hLineProc->gapMaxZ = procData->pt3D.z;
if (0 == a_binValue)
{
//<2F><><EFBFBD><EFBFBD>wait״̬
hLineProc->hLineSM = keSG_HLineProc_Wait_Second;
}
else if (hLineProc->firstHalf.value != a_binValue)
{
hLineProc->secondHalf.start = procData->nPointIdx;
hLineProc->secondHalf.len = 1;
hLineProc->secondHalf.value = a_binValue;
hLineProc->secondHalf_startPt = *procData;
hLineProc->secondHalf_endPt = *procData;
hLineProc->hLineSM = keSG_HLineProc_Second_Half;
}
else
{
hLineProc->firstHalf.len++;
hLineProc->firstHalf_endPt = *procData;
}
break;
case keSG_HLineProc_Wait_Second:
if (hLineProc->gapMaxZ < procData->pt3D.z)
hLineProc->gapMaxZ = procData->pt3D.z;
if (0 == a_binValue)
{
double x_diff = abs(procData->pt3D.x - hLineProc->firstHalf_endPt.pt3D.x);
if (x_diff > measureParam.extractPara.sameGapTh)
{
memset(&hLineProc->firstHalf, 0, sizeof(SSG_RUN));
memset(&hLineProc->firstHalf_startPt, 0, sizeof(SVzNL3DPosition));
memset(&hLineProc->firstHalf_endPt, 0, sizeof(SVzNL3DPosition));
hLineProc->hLineSM = keSG_HLineProc_Init;
}
}
else if (hLineProc->firstHalf.value != a_binValue)
{
hLineProc->secondHalf.start = procData->nPointIdx;
hLineProc->secondHalf.len = 1;
hLineProc->secondHalf.value = a_binValue;
hLineProc->secondHalf_startPt = *procData;
hLineProc->secondHalf_endPt = *procData;
hLineProc->hLineSM = keSG_HLineProc_Second_Half;
}
else
{
if (x_diff > measureParam.extractPara.sameGapTh)
{
//firstHalf<6C><66><EFBFBD>¿<EFBFBD>ʼ
hLineProc->firstHalf.start = procData->nPointIdx;
hLineProc->firstHalf.len = 1;
hLineProc->firstHalf.value = a_binValue;
hLineProc->firstHalf_startPt = *procData;
hLineProc->firstHalf_endPt = *procData;
}
else
{
//firstHalf<6C><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
hLineProc->firstHalf.len = procData->nPointIdx - hLineProc->firstHalf_startPt.nPointIdx + 1;
hLineProc->firstHalf_endPt = *procData;
}
hLineProc->hLineSM = keSG_HLineProc_First_Half;
}
break;
case keSG_HLineProc_Second_Half:
if (0 == a_binValue)
{
//ƥ<><C6A5>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SSG_basicFeatureGap a_gap;
memset(&a_gap, 0, sizeof(SSG_basicFeatureGap));
a_gap.lineIdx = hLineIdx;
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Gap
SVzNL3DPosition start;
int x_lineDiff = hLineProc->firstHalf_startPt.nPointIdx - hLineProc->gapPos.nPointIdx;
if ((x_lineDiff > 0) && (x_lineDiff < measureParam.extractPara.gapChkWin))
{
a_gap.gap_start = hLineProc->gapPos.pt3D.x;
start = hLineProc->gapPos;
}
else
{
a_gap.gap_start = hLineProc->firstHalf_startPt.pt3D.x;
start = hLineProc->firstHalf_startPt;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Gap
bool hasPostGap = false;
SVzNL3DPosition postGap;
memset(&postGap, 0, sizeof(SVzNL3DPosition));
int chkLen = measureParam.extractPara.gapChkWin;
if (chkLen > SCAN_BUFF_SIZE / 2)
chkLen = SCAN_BUFF_SIZE / 2;
SVzNL3DPosition preData = *procData;
for (int m = 1; m <= chkLen; m++)
{
int lineIdx = midPos + m;
if (buffLines[lineIdx]->p3DPosition[workerIdx].pt3D.z < 1e-4)
continue;
double x_dff_2 = buffLines[lineIdx]->p3DPosition[workerIdx].pt3D.x - preData.pt3D.x;
if (x_dff_2 > measureParam.scanXScale * 2) //<2F>ҵ<EFBFBD>Gap
{
hasPostGap = true;
postGap = buffLines[lineIdx]->p3DPosition[workerIdx];
break;
}
preData = buffLines[lineIdx]->p3DPosition[workerIdx];
}
SVzNL3DPosition end;
if (true == hasPostGap)
{
end = postGap;
a_gap.gap_width = postGap.pt3D.x - a_gap.gap_start;
a_gap.gap_depth = -1;//<2F><>͸<EFBFBD><CDB8>˺<EFBFBD><CBBA>
double y1, y2;
if (start.pt3D.y < end.pt3D.y)
{
y1 = start.pt3D.y;
y2 = end.pt3D.y;
}
else
{
y1 = end.pt3D.y;
y2 = start.pt3D.y;
}
a_gap.roi = { a_gap.gap_start, postGap.pt3D.x, y1, y2};
a_gap.gapPt_0 = start;
a_gap.gapPt_1 = end;
}
else
{
end = hLineProc->secondHalf_endPt;
a_gap.gap_width = hLineProc->secondHalf_endPt.pt3D.x - a_gap.gap_start;
a_gap.gap_depth = hLineProc->gapMaxZ - (start.pt3D.z + end.pt3D.z) / 2;
double y1, y2;
if (start.pt3D.y < end.pt3D.y)
{
y1 = start.pt3D.y;
y2 = end.pt3D.y;
}
else
{
y1 = end.pt3D.y;
y2 = start.pt3D.y;
}
a_gap.roi = { a_gap.gap_start, hLineProc->secondHalf_endPt.pt3D.x, y1, y2 };
a_gap.gapPt_0 = start;
a_gap.gapPt_1 = end;
}
hLineFeatures.push_back(a_gap);
memset(&hLineProc->firstHalf, 0, sizeof(SSG_RUN));
memset(&hLineProc->firstHalf_startPt, 0, sizeof(SVzNL3DPosition));
memset(&hLineProc->firstHalf_endPt, 0, sizeof(SVzNL3DPosition));
memset(&hLineProc->secondHalf, 0, sizeof(SSG_RUN));
memset(&hLineProc->secondHalf_startPt, 0, sizeof(SVzNL3DPosition));
memset(&hLineProc->secondHalf_endPt, 0, sizeof(SVzNL3DPosition));
hLineProc->hLineSM = keSG_HLineProc_Init;
}
else if (hLineProc->firstHalf.value != a_binValue)
{
//firstHalf<6C><66><EFBFBD><EFBFBD>
hLineProc->firstHalf.len = procData->nPointIdx - hLineProc->firstHalf_startPt.nPointIdx + 1;
hLineProc->firstHalf_endPt = *procData;
memset(&hLineProc->secondHalf, 0, sizeof(SSG_RUN));
memset(&hLineProc->secondHalf_startPt, 0, sizeof(SVzNL3DPosition));
memset(&hLineProc->secondHalf_endPt, 0, sizeof(SVzNL3DPosition));
hLineProc->hLineSM = keSG_HLineProc_First_Half;
}
else
{
//secondHalf<6C><66><EFBFBD><EFBFBD>
hLineProc->secondHalf.len++;
hLineProc->secondHalf_endPt = *procData;
}
break;
default:
break;
}
hLineProc->preVldData = *procData;
return;
}
void sg_beltTearingInit(
int linePtNum,
std::vector<SSG_hLineProInfo>& hLineWorkers )
{
hLineWorkers.resize(linePtNum);
for (int i = 0; i < linePtNum; i++)
memset(&hLineWorkers[i], 0, sizeof(SSG_hLineProInfo));
}
bool _chkTreeMatching(
SSG_basicFeatureGap* a_feature,
SSG_beltTearingInfo* a_tree,
const SSG_beltTearingParam measureParam,
double* dist_x,
double* dist_y
)
{
//<2F>˴<EFBFBD>ֻʹ<D6BB><CAB9>ROI<4F><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>
//<2F><><EFBFBD><EFBFBD>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double x_dist;
if ((a_feature->roi.right >= a_tree->roi.left) && (a_tree->roi.right >= a_feature->roi.left))
x_dist = 0; //<2F><><EFBFBD>غ<EFBFBD><D8BA><EFBFBD>
else if (a_tree->roi.left > a_feature->roi.right)
x_dist = a_tree->roi.left - a_feature->roi.right;
else
x_dist = a_feature->roi.left - a_tree->roi.right;
//<2F><><EFBFBD>㴹ֱ<E3B4B9><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double y_dist;
if ((a_feature->roi.bottom >= a_tree->roi.top) && (a_tree->roi.bottom >= a_feature->roi.top))
y_dist = 0; //<2F><><EFBFBD>غ<EFBFBD><D8BA><EFBFBD>
else if (a_tree->roi.top > a_feature->roi.bottom)
y_dist = a_tree->roi.top - a_feature->roi.bottom;
else
y_dist = a_feature->roi.top - a_tree->roi.bottom;
*dist_x = x_dist;
*dist_y = y_dist;
if (((y_dist < measureParam.scanYScale * 3) && (x_dist < measureParam.tearingMinGap)))
//||((x_dist < measureParam.scanXScale * 3) && (y_dist < measureParam.tearingMinGap)))
return true;
return false;
}
SSG_beltTearingInfo* _findMatchTre(
SSG_basicFeatureGap* a_feature,
std::vector<SSG_beltTearingInfo>& existTrees,
const SSG_beltTearingParam measureParam)
{
for (int i = 0, i_max = existTrees.size(); i < i_max; i++)
{
SSG_beltTearingInfo* a_tree = &existTrees[i];
double x_dist, y_dist;
bool isMatching = _chkTreeMatching(
a_feature,
a_tree,
measureParam,
&x_dist,
&y_dist);
if(true == isMatching)
return a_tree;
}
return NULL;
}
void _mergeTwoTree(
SSG_beltTearingInfo* mergeTree,
SSG_beltTearingInfo* subTree
)
{
mergeTree->endLineIdx = mergeTree->endLineIdx < subTree->endLineIdx ? subTree->endLineIdx : mergeTree->endLineIdx;
#if OUTPUT_TEARING_POINTS
mergeTree->pts.insert(mergeTree->pts.end(), subTree->pts.begin(), subTree->pts.end());
#endif
_combineROI(&mergeTree->roi, &subTree->roi);
mergeTree->statLineIdx = mergeTree->statLineIdx > subTree->statLineIdx ? subTree->statLineIdx : mergeTree->statLineIdx;
mergeTree->tearDepth = mergeTree->tearDepth < subTree->tearDepth ? subTree->tearDepth : mergeTree->tearDepth;
subTree->tearStatus = keSG_tearStatus_Invalid;
return;
}
SSG_tearProcessInfo* _getProcInfo(
int tearProcInfo_IdOffset,
int tearID,
std::vector<SSG_tearProcessInfo>& tearProcInfo)
{
int index = tearID;
if (tearProcInfo_IdOffset > index)
index = INT_MAX - tearProcInfo_IdOffset + index;
else
index = index - tearProcInfo_IdOffset;
SSG_tearProcessInfo* a_procInfo = &tearProcInfo[index];
if (a_procInfo->tearID >= 0)
{
try {
if (a_procInfo->tearID != tearID)
throw std::runtime_error("˺<EFBFBD>ѵ<EFBFBD>ID<EFBFBD><EFBFBD>˺<EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ID<EFBFBD><EFBFBD>ƥ<EFBFBD>");
}
catch (const std::runtime_error& e) {
std::cerr << "Caught an exception: " << e.what() << std::endl;
}
}
return a_procInfo;
}
///<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>grid<69><64>ʽ<EFBFBD><CABD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
//ÿ<><C3BF>ɨ<EFBFBD><C9A8><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD>һ<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ÿ<><C3BF>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>δ<EFBFBD>ֱɨ<D6B1><C9A8><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD><EFBFBD>ͬʱN<CAB1><4E>ˮƽ״̬<D7B4><CCAC>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ͨ<EFBFBD><CDA8>ROI<4F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮƽFeature<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ʼ<EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>ߺ<EFBFBD>
void sg_detectBeltTearing(
SVzNL3DLaserLine* laser3DPoints, //һ<><D2BB>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>
int inputLineIdx,
int nPointCount, //ÿ<><C3BF>ɨ<EFBFBD><C9A8><EFBFBD>ߵĵ<DFB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Grid<69><64><EFBFBD>ݸ<EFBFBD>ʽʱ<CABD><CAB1>ÿ<EFBFBD><C3BF>ɨ<EFBFBD><C9A8><EFBFBD>ߵĵ<DFB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>Grid<69><64>ʽ
int* errCode,
std::vector<SSG_hLineProInfo>& hLineWorkers,
std::vector<SSG_beltTearingInfo>& beltTearings_new,
std::vector<SSG_beltTearingInfo>& beltTearings_growing,
std::vector<SSG_beltTearingInfo>& beltTearings_ended,
std::vector<SSG_beltTearingInfo>& beltTearings_unknown, //δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B4A6><EFBFBD><EFBFBD>
const SSG_beltTearingParam measureParam)
{
//<2F><EFBFBD><E3B7A8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>Buff<66><66>ͬʱ<CDAC><CAB1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static SVzNL3DLaserLine** buffLines = NULL;
if(NULL == buffLines)
buffLines = (SVzNL3DLaserLine**)malloc(sizeof(SVzNL3DLaserLine*) * SCAN_BUFF_SIZE);
static int buffSize = 0;
static int tearID = 1; //<2F><>ΪƤ<CEAA><C6A4><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//˺<>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD><DDA1><EFBFBD>ΪƤ<CEAA><C6A4><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static int tearProcInfo_IdOffset = 1; //id<69><64>1<EFBFBD><31>ʼ
static std::vector<SSG_tearProcessInfo> tearProcInfo;
if (NULL == laser3DPoints) //<2F><>λ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
{
for (int i = 0; i < buffSize; i++)
{
if (buffLines[i])
{
free(buffLines[i]->p3DPosition);
free(buffLines[i]);
}
}
free(buffLines);
buffLines = NULL;
buffSize = 0;
tearID = 1;
tearProcInfo_IdOffset = 1;
tearProcInfo.resize(0);
return;
}
*errCode = 0;
if (0 == laser3DPoints->nPositionCnt)
return;
if (hLineWorkers.size() != laser3DPoints->nPositionCnt) //<2F><><EFBFBD><EFBFBD>
{
*errCode = SG_ERR_NOT_GRID_FORMAT;
return;
}
/* <20><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>FIFO<46><4F>ֻ<EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ž<EFBFBD><C5BD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD> */
if (buffSize < SCAN_BUFF_SIZE) //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>buff<66>ռ<EFBFBD>
{
SVzNL3DLaserLine* a_buffLine = (SVzNL3DLaserLine*)malloc(sizeof(SVzNL3DLaserLine));
a_buffLine->nPositionCnt = laser3DPoints->nPositionCnt;
a_buffLine->nTimeStamp = inputLineIdx;
a_buffLine->p3DPosition = (SVzNL3DPosition*)malloc(sizeof(SVzNL3DPosition) * laser3DPoints->nPositionCnt);
memcpy(a_buffLine->p3DPosition, laser3DPoints->p3DPosition, sizeof(SVzNL3DPosition) * laser3DPoints->nPositionCnt);
for (int i = 0; i < laser3DPoints->nPositionCnt; i++)
a_buffLine->p3DPosition[i].nPointIdx = inputLineIdx; //<2F><><EFBFBD><EFBFBD>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD>ʱ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>LineIdx
buffLines[buffSize] = a_buffLine;
buffSize++;
return; //bufferδ<72><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else //<2F><>Buffer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀռ<D5BC>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
{
SVzNL3DLaserLine* tmpLine = buffLines[0];
for (int i = 0; i < SCAN_BUFF_SIZE - 1; i++)
buffLines[i] = buffLines[i + 1];
tmpLine->nPositionCnt = laser3DPoints->nPositionCnt;
tmpLine->nTimeStamp = inputLineIdx;
memcpy(tmpLine->p3DPosition, laser3DPoints->p3DPosition, sizeof(SVzNL3DPosition) * laser3DPoints->nPositionCnt);
for (int i = 0; i < laser3DPoints->nPositionCnt; i++)
tmpLine->p3DPosition[i].nPointIdx = inputLineIdx; //<2F><><EFBFBD><EFBFBD>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD>ʱ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>LineIdx
buffLines[SCAN_BUFF_SIZE - 1] = tmpLine;
}
/* <20><><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ɵ<EFBFBD>beltTearings_new<65>ϲ<EFBFBD><CFB2><EFBFBD>beltTearings_growing<6E>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>beltTearings_new */
if (beltTearings_new.size() > 0)
{
for (int i = 0; i < beltTearings_new.size(); i++)
beltTearings_new[i].tearStatus = keSG_tearStatus_Growing;
beltTearings_growing.insert(beltTearings_growing.end(), beltTearings_new.begin(), beltTearings_new.end());
beltTearings_new.clear();
}
/* <20><>beltTearings_ended<65><64><EFBFBD><EFBFBD> */
if (beltTearings_ended.size() > 0)
{
for (int i = 0, i_max = beltTearings_ended.size(); i < i_max; i++)
{
SSG_tearProcessInfo* match_procInfo = _getProcInfo(
tearProcInfo_IdOffset,
beltTearings_ended[i].tearID,
tearProcInfo);
match_procInfo->tearID = -1;
}
beltTearings_ended.clear();
//<2F><><EFBFBD><EFBFBD>tearProcInfo
int vldStart = -1;
for (int i = 0, i_max = tearProcInfo.size(); i < i_max; i++)
{
if (tearProcInfo[i].tearID > 0)
{
vldStart = i;
break;
}
}
if (vldStart > 0)
{
tearProcInfo.erase(tearProcInfo.begin(), tearProcInfo.begin() + vldStart);
tearProcInfo_IdOffset = tearProcInfo[0].tearID;
}
}
/****************************************************************/
/**** <20><>BuffLines<65><73><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>BuffLines<65><73>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ****/
/****************************************************************/
int buffMidPos = SCAN_BUFF_SIZE / 2;
if ( (buffLines[buffMidPos]->nTimeStamp == 940) ||(buffLines[buffMidPos]->nTimeStamp == 182))
int kkk = 1;
int procLineIdx = buffLines[buffMidPos]->nTimeStamp;
//<2F>Ե<EFBFBD>ǰɨ<C7B0><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>д<EFBFBD><D0B4><EFBFBD>
std::vector<SSG_basicFeatureGap> vLineFeatures;
sg_bearTearing_vLineProc(
buffLines[buffMidPos], //<2F><>ǰɨ<C7B0><C9A8><EFBFBD><EFBFBD>
buffLines[buffMidPos]->nTimeStamp, //<2F><>ǰɨ<C7B0><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
measureParam,
vLineFeatures);
//<2F><><EFBFBD><EFBFBD>ƽ<CBAE><C6BD><EFBFBD><EFBFBD>
std::vector<SSG_basicFeatureGap> hLineFeatures;
//hLineFeatures.resize(hLineWorkers.size());
for (int i = 0; i < laser3DPoints->nPositionCnt; i++)
{
//if ((buffLines[buffMidPos]->nTimeStamp == 295) && (i == 725))
// int kkk = 1;
//ˮƽɨ<C6BD><C9A8><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::vector<SSG_basicFeatureGap> a_hLineFeatures;
sg_bearTearing_hLineProc(
&hLineWorkers[i],
i,
buffLines[buffMidPos]->nTimeStamp, //ˮƽɨ<C6BD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Ӧ<EFBFBD><D3A6>ֱɨ<D6B1><C9A8><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
buffLines,
measureParam,
a_hLineFeatures);
//if (0 == a_hLineFeatures.size())
// hLineFeatures[i].lineIdx = -1;
//else
if(a_hLineFeatures.size() > 0)
{
hLineFeatures.push_back(a_hLineFeatures[0]);
//hLineFeatures[i] = a_hLineFeatures[0];
//if ((a_hLineFeatures[0].gapPt_0.pt3D.x < 10871) &&(a_hLineFeatures[0].gapPt_0.pt3D.x > 10870))
// int kkk = 1;
}
}
//<2F><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD>ڴ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ϵ
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ϊ<EFBFBD>˼򻯴<CBBC><F2BBAFB4><EFBFBD><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺϲ<C4BA><CFB2><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (vLineFeatures.size() > 0)
{
std::vector<SSG_intPair> feature_tree_id_pair; //ע<>⣺vectorȡ<72><C8A1>ַʱ<D6B7><CAB1>push_back<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>ַ<EFBFBD><D6B7><EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD><E4BBAF>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
feature_tree_id_pair.resize(vLineFeatures.size()); //ÿ<><C3BF>featurec<65><63>Ӧһ<D3A6><D2BB>matchTree
std::vector<SVzNL2DPointD> feature_tree_pair_dist;
feature_tree_pair_dist.resize(vLineFeatures.size());
for (int i = 0, i_max = vLineFeatures.size(); i < i_max; i++)
{
feature_tree_id_pair[i].data_0 = -1; //ָʾtree_id
feature_tree_id_pair[i].data_1 = -1; //ָʾgroup_id
for (int j = 0, j_max = beltTearings_growing.size(); j < j_max; j++)
{
double dist_x = -1, dist_y = -1;
bool isMatching = _chkTreeMatching(
&vLineFeatures[i],
&beltTearings_growing[j],
measureParam,
&dist_x,
&dist_y);
if (true == isMatching)
{
if (feature_tree_id_pair[i].data_0 < 0)
{
feature_tree_id_pair[i].data_0 = j;
feature_tree_id_pair[i].data_1 = 0;
feature_tree_pair_dist[i].x = dist_x;
feature_tree_pair_dist[i].y = dist_y;
}
else //ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tree<65><65><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>dist_y<5F><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (dist_y < feature_tree_pair_dist[i].y)
{
feature_tree_id_pair[i].data_0 = j;
feature_tree_id_pair[i].data_1 = 0;
feature_tree_pair_dist[i].x = dist_x;
feature_tree_pair_dist[i].y = dist_y;
}
}
}
}
for (int j = 0, j_max = beltTearings_unknown.size(); j < j_max; j++)
{
if (keSG_tearStatus_Invalid == beltTearings_unknown[j].tearStatus)
continue;
double dist_x = -1, dist_y = -1;
bool isMatching = _chkTreeMatching(
&vLineFeatures[i],
&beltTearings_unknown[j],
measureParam,
&dist_x,
&dist_y);
if (true == isMatching)
{
if (feature_tree_id_pair[i].data_0 < 0)
{
feature_tree_id_pair[i].data_0 = j;
feature_tree_id_pair[i].data_1 = 1;
feature_tree_pair_dist[i].x = dist_x;
feature_tree_pair_dist[i].y = dist_y;
}
else //ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tree<65><65><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>dist_y<5F><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (dist_y < feature_tree_pair_dist[i].y)
{
feature_tree_id_pair[i].data_0 = j;
feature_tree_id_pair[i].data_1 = 1;
feature_tree_pair_dist[i].x = dist_x;
feature_tree_pair_dist[i].y = dist_y;
}
}
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬһ<CDAC><D2BB>feature<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0, i_max = vLineFeatures.size(); i < i_max; i++)
{
if (feature_tree_id_pair[i].data_0 < 0)
continue;
for (int j = i + 1; j < i_max; j++)
{
if ( (feature_tree_id_pair[i].data_0 == feature_tree_id_pair[j].data_0) &&
(feature_tree_id_pair[i].data_1 == feature_tree_id_pair[j].data_1))
{
//<2F>Ƚ<EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD>
if ( (feature_tree_pair_dist[i].y < feature_tree_pair_dist[j].y) &&
(feature_tree_pair_dist[j].y > 1e-4)) //<2F><>Ϊ0
feature_tree_id_pair[j].data_0 = -1;
else if ((feature_tree_pair_dist[j].y < feature_tree_pair_dist[i].y) &&
(feature_tree_pair_dist[i].y > 1e-4)) //<2F><>Ϊ0
feature_tree_id_pair[i].data_0 = -1;
break;
}
}
}
for (int i = 0, i_max = vLineFeatures.size(); i < i_max; i++)
{
//<2F><><EFBFBD>ڴ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ϵ
SSG_basicFeatureGap* a_vFeature = &vLineFeatures[i];
if (feature_tree_id_pair[i].data_0 < 0)
{
SSG_beltTearingInfo a_newTree;
memset(&a_newTree, 0, sizeof(SSG_beltTearingInfo));
a_newTree.tearID = tearID; //
tearID++;
if (tearID == 0) //ѭ<><D1AD>һȦ
tearID = 1;
a_newTree.statLineIdx = procLineIdx;
a_newTree.endLineIdx = procLineIdx;
a_newTree.roi = a_vFeature->roi;
a_newTree.tearDepth = a_vFeature->gap_depth;
a_newTree.tearType = keSG_tearType_MachineDir; //<2F><>˺
a_newTree.tearStatus = keSG_tearStatus_Uknown; //unknown
#if OUTPUT_TEARING_POINTS
a_vFeature->gapPt_0.nPointIdx = a_newTree.tearID;
a_vFeature->gapPt_1.nPointIdx = a_newTree.tearID;
a_newTree.pts.push_back(a_vFeature->gapPt_0);
a_newTree.pts.push_back(a_vFeature->gapPt_1);
#endif
beltTearings_unknown.push_back(a_newTree);
SSG_tearProcessInfo a_procInfo;
memset(&a_procInfo, 0, sizeof(SSG_tearProcessInfo));
a_procInfo.tearID = a_newTree.tearID;
a_procInfo.vGap_depth_max = a_vFeature->gap_depth;
a_procInfo.vGap_width_max = a_vFeature->gap_width;
a_procInfo.vGap_width_sum = a_vFeature->gap_width;
a_procInfo.vGap_num = 1;
tearProcInfo.push_back(a_procInfo);
}
else
{
SSG_beltTearingInfo* a_matchTree;
int tree_id = feature_tree_id_pair[i].data_0;
if(0 == feature_tree_id_pair[i].data_1)
a_matchTree = &beltTearings_growing[tree_id];
else
a_matchTree = &beltTearings_unknown[tree_id];
//ȡ<><C8A1>Ӧ<EFBFBD><D3A6>procInfo
SSG_tearProcessInfo* match_procInfo = _getProcInfo(
tearProcInfo_IdOffset,
a_matchTree->tearID,
tearProcInfo);
if ((a_vFeature->gap_depth < 0) || (match_procInfo->vGap_depth_max < 0))
match_procInfo->vGap_depth_max = -1; //<2F>ᴩ˺<E1B4A9><CBBA>
else
match_procInfo->vGap_depth_max = match_procInfo->vGap_depth_max < a_vFeature->gap_depth ? a_vFeature->gap_depth : match_procInfo->vGap_depth_max;
match_procInfo->vGap_width_max = match_procInfo->vGap_width_max < a_vFeature->gap_width ? a_vFeature->gap_width : match_procInfo->vGap_width_max;
match_procInfo->vGap_width_sum += a_vFeature->gap_width;
match_procInfo->vGap_num++;
#if OUTPUT_TEARING_POINTS
a_vFeature->gapPt_0.nPointIdx = a_matchTree->tearID;
a_vFeature->gapPt_1.nPointIdx = a_matchTree->tearID;
a_matchTree->pts.push_back(a_vFeature->gapPt_0);
a_matchTree->pts.push_back(a_vFeature->gapPt_1);
#endif
//
a_matchTree->endLineIdx = procLineIdx;
_combineROI(&a_matchTree->roi, &a_vFeature->roi);
if (keSG_tearType_MachineDir == a_matchTree->tearType)
{
a_matchTree->tearWidth = match_procInfo->vGap_width_max;
a_matchTree->tearDepth = match_procInfo->vGap_depth_max;
}
}
}
}
#if ENABLE_CROSS_WISE_TEAR
//ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (hLineFeatures.size() > 0)
{
std::vector<SSG_intPair> hFeature_tree_id_pair; //ע<>⣺vectorȡ<72><C8A1>ַʱ<D6B7><CAB1>push_back<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>ַ<EFBFBD><D6B7><EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD><E4BBAF>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
hFeature_tree_id_pair.resize(hLineFeatures.size()); //ÿ<><C3BF>featurec<65><63>Ӧһ<D3A6><D2BB>matchTree
std::vector<SVzNL2DPointD> hFeature_tree_pair_dist;
hFeature_tree_pair_dist.resize(hLineFeatures.size());
for(int i = 0, i_max = hLineFeatures.size(); i < i_max; i++)
{
hFeature_tree_id_pair[i].data_0 = -1; //ָʾtree_id
hFeature_tree_id_pair[i].data_1 = -1; //ָʾgroup_id
//<2F><><EFBFBD><EFBFBD>beltTearings_unknown<77><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Һϲ<D2BA>
for (int j = 0, j_max = beltTearings_unknown.size(); j < j_max; j++)
{
if (keSG_tearStatus_Invalid == beltTearings_unknown[j].tearStatus)
continue;
double dist_x = -1, dist_y = -1;
bool isMatching = _chkTreeMatching(
&hLineFeatures[i],
&beltTearings_unknown[j],
measureParam,
&dist_x,
&dist_y);
if (true == isMatching)
{
if (hFeature_tree_id_pair[i].data_0 < 0)
{
hFeature_tree_id_pair[i].data_0 = j;
hFeature_tree_id_pair[i].data_1 = 1; //1:beltTearings_unknown
hFeature_tree_pair_dist[i].x = dist_x;
hFeature_tree_pair_dist[i].y = dist_y;
}
else //<2F><><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>
{
int mergeTreeIdx = hFeature_tree_id_pair[i].data_0;
_mergeTwoTree(&beltTearings_unknown[mergeTreeIdx],&beltTearings_unknown[j]);
SSG_tearProcessInfo* match_procInfo = _getProcInfo(
tearProcInfo_IdOffset,
beltTearings_unknown[j].tearID,
tearProcInfo);
match_procInfo->tearID = -1; //<2F><><EFBFBD>ϲ<EFBFBD><CFB2>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
}
}
}
for (int j = 0, j_max = beltTearings_growing.size(); j < j_max; j++)
{
double dist_x = -1, dist_y = -1;
bool isMatching = _chkTreeMatching(
&hLineFeatures[i],
&beltTearings_growing[j],
measureParam,
&dist_x,
&dist_y);
if (true == isMatching)
{
if (hFeature_tree_id_pair[i].data_0 < 0)
{
hFeature_tree_id_pair[i].data_0 = j;
hFeature_tree_id_pair[i].data_1 = 0; //0 : beltTearings_growing
hFeature_tree_pair_dist[i].x = dist_x;
hFeature_tree_pair_dist[i].y = dist_y;
}
else
{
#if 0
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tree<65><65>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳʹ<D2B2><CAB9>dist_y<5F><79><EFBFBD><EFBFBD><EFBFBD>
if (dist_y < hFeature_tree_pair_dist[i].y)
{
hFeature_tree_id_pair[i].data_0 = j;
hFeature_tree_id_pair[i].data_1 = 0;
hFeature_tree_pair_dist[i].x = dist_x;
hFeature_tree_pair_dist[i].y = dist_y;
}
#else
//beltTearings_growingΪ<67><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>
hFeature_tree_id_pair[i].data_0 = j;
hFeature_tree_id_pair[i].data_1 = 0;
hFeature_tree_pair_dist[i].x = dist_x;
hFeature_tree_pair_dist[i].y = dist_y;
#endif
}
}
}
}
for (int i = 0, i_max = hLineFeatures.size(); i < i_max; i++)
{
SSG_basicFeatureGap* a_hFeature = &hLineFeatures[i];
if (a_hFeature->lineIdx < 0)
continue;
if (hFeature_tree_id_pair[i].data_0 < 0)
{
SSG_beltTearingInfo a_newTree;
memset(&a_newTree, 0, sizeof(SSG_beltTearingInfo));
a_newTree.tearID = tearID; //
tearID++;
if (tearID == 0) //ѭ<><D1AD>һȦ
tearID = 1;
a_newTree.statLineIdx = procLineIdx;
a_newTree.endLineIdx = procLineIdx;
a_newTree.roi = a_hFeature->roi;
a_newTree.tearDepth = a_hFeature->gap_depth;
a_newTree.tearType = keSG_tearType_CrossWise; //<2F><>˺
a_newTree.tearStatus = keSG_tearStatus_Uknown; //unknown
#if OUTPUT_TEARING_POINTS
a_hFeature->gapPt_0.nPointIdx = a_newTree.tearID;
a_hFeature->gapPt_1.nPointIdx = a_newTree.tearID;
a_newTree.pts.push_back(a_hFeature->gapPt_0);
a_newTree.pts.push_back(a_hFeature->gapPt_1);
#endif
beltTearings_unknown.push_back(a_newTree);
SSG_tearProcessInfo a_procInfo;
memset(&a_procInfo, 0, sizeof(SSG_tearProcessInfo));
a_procInfo.tearID = a_newTree.tearID;
a_procInfo.hGap_depth_max = a_hFeature->gap_depth;
a_procInfo.hGap_width_max = a_hFeature->gap_width;
a_procInfo.hGap_width_sum = a_hFeature->gap_width;
a_procInfo.hGap_num = 1;
tearProcInfo.push_back(a_procInfo);
}
else
{
SSG_beltTearingInfo* a_matchTree;
int tree_id = hFeature_tree_id_pair[i].data_0;
if (0 == hFeature_tree_id_pair[i].data_1)
a_matchTree = &beltTearings_growing[tree_id];
else
a_matchTree = &beltTearings_unknown[tree_id];
//ȡ<><C8A1>Ӧ<EFBFBD><D3A6>procInfo
SSG_tearProcessInfo* match_procInfo = _getProcInfo(
tearProcInfo_IdOffset,
a_matchTree->tearID,
tearProcInfo);
match_procInfo->hGap_depth_max = match_procInfo->hGap_depth_max < a_hFeature->gap_depth ? a_hFeature->gap_depth : match_procInfo->hGap_depth_max;
match_procInfo->hGap_width_max = match_procInfo->hGap_width_max < a_hFeature->gap_width ? a_hFeature->gap_width : match_procInfo->hGap_width_max;
match_procInfo->hGap_width_sum += a_hFeature->gap_width;
match_procInfo->hGap_num++;
#if OUTPUT_TEARING_POINTS
a_hFeature->gapPt_0.nPointIdx = a_matchTree->tearID;
a_hFeature->gapPt_1.nPointIdx = a_matchTree->tearID;
a_matchTree->pts.push_back(a_hFeature->gapPt_0);
a_matchTree->pts.push_back(a_hFeature->gapPt_1);
#endif
//
a_matchTree->endLineIdx = procLineIdx;
_combineROI(&a_matchTree->roi, &a_hFeature->roi);
if (keSG_tearType_CrossWise == a_matchTree->tearType)
{
a_matchTree->tearWidth = match_procInfo->hGap_width_max;
a_matchTree->tearDepth = match_procInfo->hGap_depth_max;
}
}
}
}
#endif
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>beltTearings_endedĿ<64><C4BF>
if (beltTearings_growing.size() > 0)
{
int i_max = beltTearings_growing.size();
for (int i = i_max-1; i >= 0; i--) //<2F>Ӻ<EFBFBD><D3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (beltTearings_growing[i].endLineIdx != procLineIdx)
{
int idx_diff;
if (procLineIdx > beltTearings_growing[i].endLineIdx)
idx_diff = procLineIdx - beltTearings_growing[i].endLineIdx;
else
idx_diff = INT_MAX - beltTearings_growing[i].endLineIdx + 1 + procLineIdx;
double dist = idx_diff * measureParam.scanXScale;
if (dist > measureParam.tearingMinGap)
{
beltTearings_growing[i].tearStatus = keSG_tearStatus_Ended; //<2F><><EFBFBD><EFBFBD>
beltTearings_ended.push_back(beltTearings_growing[i]);
beltTearings_growing.erase(beltTearings_growing.begin() + i);
}
}
}
}
//<2F><><EFBFBD><EFBFBD>unknown<77><6E>˺<EFBFBD>ѣ<EFBFBD><D1A3><EFBFBD><EFBFBD><EFBFBD>beltTearings_new
if (beltTearings_unknown.size() > 0)
{
int i_max = beltTearings_unknown.size();
for (int i = i_max - 1; i >= 0; i--)//<2F>Ӻ<EFBFBD><D3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (keSG_tearStatus_Invalid == beltTearings_unknown[i].tearStatus)
{
SSG_tearProcessInfo* match_procInfo = _getProcInfo(
tearProcInfo_IdOffset,
beltTearings_unknown[i].tearID,
tearProcInfo);
match_procInfo->tearID = -1;
beltTearings_unknown.erase(beltTearings_unknown.begin() + i);
}
else
{
if (beltTearings_unknown[i].endLineIdx == procLineIdx) //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
{
//<2F><><EFBFBD><EFBFBD>ROI<4F>ij<EFBFBD><C4B3><EFBFBD>
double w = beltTearings_unknown[i].roi.right - beltTearings_unknown[i].roi.left;
double h = beltTearings_unknown[i].roi.bottom - beltTearings_unknown[i].roi.top;
if ((w >= measureParam.tearingMinLen) || (h >= measureParam.tearingMinLen))
{
int lines = beltTearings_unknown[i].endLineIdx - beltTearings_unknown[i].statLineIdx + 1;
SSG_tearProcessInfo* match_procInfo = _getProcInfo(
tearProcInfo_IdOffset,
beltTearings_unknown[i].tearID,
tearProcInfo);
int vldLines = match_procInfo->hGap_num > match_procInfo->vGap_num ? match_procInfo->hGap_num : match_procInfo->vGap_num;
if (vldLines < lines / 2)
{
match_procInfo->tearID = -1;
beltTearings_unknown.erase(beltTearings_unknown.begin() + i);
}
else
{
bool isVTearing = true;
if ((match_procInfo->hGap_num > 0) && (match_procInfo->vGap_num == 0))
isVTearing = false;
else if (((match_procInfo->hGap_num > 0) && (match_procInfo->vGap_num > 0)) &&
(match_procInfo->hGap_width_max < match_procInfo->vGap_width_max))
isVTearing = false;
if (false == isVTearing)
{
beltTearings_unknown[i].tearType = keSG_tearType_CrossWise;
beltTearings_unknown[i].tearStatus = keSG_tearStatus_New;
beltTearings_unknown[i].tearDepth = match_procInfo->hGap_depth_max;
beltTearings_unknown[i].tearWidth = match_procInfo->hGap_width_max;
beltTearings_new.push_back(beltTearings_unknown[i]);
beltTearings_unknown.erase(beltTearings_unknown.begin() + i);
}
else
{
beltTearings_unknown[i].tearType = keSG_tearType_MachineDir;
beltTearings_unknown[i].tearStatus = keSG_tearStatus_New;
beltTearings_unknown[i].tearDepth = match_procInfo->vGap_depth_max;
beltTearings_unknown[i].tearWidth = match_procInfo->vGap_width_max;
beltTearings_new.push_back(beltTearings_unknown[i]);
beltTearings_unknown.erase(beltTearings_unknown.begin() + i);
}
}
}
}
else//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int idx_diff;
if (procLineIdx > beltTearings_unknown[i].endLineIdx)
idx_diff = procLineIdx - beltTearings_unknown[i].endLineIdx;
else
idx_diff = INT_MAX - beltTearings_unknown[i].endLineIdx + 1 + procLineIdx;
double dist = idx_diff * measureParam.scanXScale;
if (dist > measureParam.tearingMinGap)
{
SSG_tearProcessInfo* match_procInfo = _getProcInfo(
tearProcInfo_IdOffset,
beltTearings_unknown[i].tearID,
tearProcInfo);
match_procInfo->tearID = -1;
beltTearings_unknown.erase(beltTearings_unknown.begin() + i);
}
}
}
}
}
return;
}