|
|
@@ -6,6 +6,7 @@
|
|
|
#include "OTSHelper.h"
|
|
|
#include "OTSImageProcess.h"
|
|
|
#include "CGBLevel.h"
|
|
|
+#include <GBFieldData.h>
|
|
|
namespace OTSGBCalculate
|
|
|
{
|
|
|
using namespace OTSDATA;
|
|
|
@@ -829,14 +830,22 @@ namespace OTSGBCalculate
|
|
|
CGridRowsList listRows;
|
|
|
CGridRowPtr pRow;
|
|
|
CString strWidthName1, strWidthName2, strWidthName3;
|
|
|
+ CString idstr;
|
|
|
+ int fldid;
|
|
|
+ int partId;
|
|
|
switch (i)
|
|
|
{
|
|
|
case 0:
|
|
|
pColumn = listCol.at(0);
|
|
|
pRow = CGridRowPtr(new CGridRow());
|
|
|
- pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
|
|
|
- pRow->SetIntValue(part->GetTagId());
|
|
|
- pColumn->GetRowList().push_back(pRow);
|
|
|
+ pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
|
|
|
+ fldid = part->GetFieldId();
|
|
|
+ partId = part->GetTagId();
|
|
|
+
|
|
|
+ idstr.Format("%d_%d", fldid,partId);
|
|
|
+
|
|
|
+ pRow->SetStringValue(idstr);
|
|
|
+ pColumn->AddGridRow(pRow);
|
|
|
|
|
|
break;
|
|
|
case 1:
|
|
|
@@ -844,35 +853,35 @@ namespace OTSGBCalculate
|
|
|
pRow = CGridRowPtr(new CGridRow());
|
|
|
pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
|
|
|
pRow->SetIntValue(part->GetActualArea());
|
|
|
- pColumn->GetRowList().push_back(pRow);
|
|
|
+ pColumn->AddGridRow(pRow);
|
|
|
break;
|
|
|
case 2:
|
|
|
pColumn = listCol.at(2);
|
|
|
pRow = CGridRowPtr(new CGridRow());
|
|
|
pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
|
|
|
- pRow->SetIntValue(part->GetFeretDiameter());
|
|
|
- pColumn->GetRowList().push_back(pRow);
|
|
|
+ pRow->SetDoubleValue(part->GetFeretDiameter());
|
|
|
+ pColumn->AddGridRow(pRow);
|
|
|
break;
|
|
|
case 3:
|
|
|
pColumn = listCol.at(3);
|
|
|
pRow = CGridRowPtr(new CGridRow());
|
|
|
pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
|
|
|
pRow->SetIntValue(part->GetAbsolutPos().x);
|
|
|
- pColumn->GetRowList().push_back(pRow);
|
|
|
+ pColumn->AddGridRow(pRow);
|
|
|
break;
|
|
|
case 4:
|
|
|
pColumn = listCol.at(4);
|
|
|
pRow = CGridRowPtr(new CGridRow());
|
|
|
pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
|
|
|
pRow->SetIntValue(part->GetAbsolutPos().y);
|
|
|
- pColumn->GetRowList().push_back(pRow);
|
|
|
+ pColumn->AddGridRow(pRow);
|
|
|
break;
|
|
|
case 5:
|
|
|
pColumn = listCol.at(5);
|
|
|
pRow = CGridRowPtr(new CGridRow());
|
|
|
pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
|
|
|
pRow->SetIntValue((int)OTSGBCalculate::GetDSGrade(part->GetFeretDiameter()));
|
|
|
- pColumn->GetRowList().push_back(pRow);
|
|
|
+ pColumn->AddGridRow(pRow);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -1130,30 +1139,20 @@ namespace OTSGBCalculate
|
|
|
// get field width
|
|
|
int nOTSFieldWidth = pEMDataMsrPtr->GetScanFieldSize();
|
|
|
int nOTSFieldHeight = pEMDataMsrPtr->GetScanFieldHeight();
|
|
|
- if (nOTSFieldWidth == 0)
|
|
|
+ if (nOTSFieldWidth == 0 || nOTSFieldHeight==0)
|
|
|
{
|
|
|
LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: field width is zero ."));
|
|
|
return m_listGBFields;
|
|
|
}
|
|
|
|
|
|
- // cal a gb field need how many ots fields rows and columns
|
|
|
- int nOTSRowsForGBFld, nOTSColumnsForGBFld;
|
|
|
- CalOTSFieldsNo(nOTSRowsForGBFld, nOTSColumnsForGBFld, nOTSFieldWidth,nOTSFieldHeight);
|
|
|
-
|
|
|
- if (nOTSRowsForGBFld == 0 || nOTSColumnsForGBFld == 0)
|
|
|
- {
|
|
|
- LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: nOTSRow|nOTSColumn is zero ."));
|
|
|
- return m_listGBFields;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// scan parameters
|
|
|
CMsrParamsPtr pMsrParam = pOTSSample->GetMsrParams();
|
|
|
//CMsrParamsPtr pMsrParam = pOTSSample->get
|
|
|
COTSImageScanParamPtr pImgScanParam = pMsrParam->GetImageScanParam();
|
|
|
|
|
|
- // get image size
|
|
|
- /*OTS_ImageResolution_OPTIONS nImageSizeId = pImgScanParam->GetImageResolutionEnumNo();
|
|
|
- int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;*/
|
|
|
+
|
|
|
CSize sizePixelImage = pImgScanParam->GetImageResolution();
|
|
|
//use OTSField width cal the OTSField height
|
|
|
|
|
|
@@ -1162,7 +1161,7 @@ namespace OTSGBCalculate
|
|
|
COTSFieldDataList allOTSFields;
|
|
|
allOTSFields = pSmplMsrResultFile->GetFieldData();
|
|
|
// convert ots fields to gb fields
|
|
|
- if (!OTSFieldToGBField( allOTSFields, &m_listGBFields, nOTSRowsForGBFld, nOTSColumnsForGBFld,sizePixelImage, nOTSFieldWidth, nOTSFieldHeight))
|
|
|
+ if (!OTSFieldToGBField( allOTSFields, &m_listGBFields, sizePixelImage, nOTSFieldWidth, nOTSFieldHeight))
|
|
|
{
|
|
|
LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: call OTSFieldToGBField failed."));
|
|
|
return m_listGBFields;
|
|
|
@@ -1170,28 +1169,12 @@ namespace OTSGBCalculate
|
|
|
return m_listGBFields;
|
|
|
}
|
|
|
|
|
|
- // protected
|
|
|
|
|
|
- // cal a gb field need how many ots fields rows and columns
|
|
|
- void CGBCalculate::CalOTSFieldsNo(int& a_nRow, int& a_nColumn, int a_nFieldWidth,int a_nFieldHeight)
|
|
|
- {
|
|
|
- a_nRow = 0;
|
|
|
- a_nColumn = 0;
|
|
|
- if (a_nFieldWidth > 0)
|
|
|
- {
|
|
|
- a_nColumn = (int)ceil((double)GB_FIELD_WIDTH / (double)a_nFieldWidth);
|
|
|
- //OTSField Height always equal to 3 / 4 OTSField Width
|
|
|
- double dFieldHeight = a_nFieldHeight;//(double)a_nFieldWidth * 3 / 4;
|
|
|
- a_nRow = (int)ceil((double)GB_FIELD_WIDTH / dFieldHeight);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
// Turn OTSField to GBField
|
|
|
- BOOL CGBCalculate::OTSFieldToGBField(COTSFieldDataList allOTSFields, CGBFieldList* m_listGBFields,int nOTSRowsPerGBfld, int nOTSColumnsPerGBFld,CSize sizePixelImage,int nOTSFieldWidth,int nOTSFieldHeight)
|
|
|
+ BOOL CGBCalculate::OTSFieldToGBField(COTSFieldDataList allOTSFields, CGBFieldList* m_listGBFields,CSize sizePixelImage,int nOTSFieldWidth,int nOTSFieldHeight)
|
|
|
{
|
|
|
- /*int nFieldHeight = nOTSFieldHeight;*/
|
|
|
-
|
|
|
- // doing nothing if no field at all
|
|
|
+
|
|
|
if (allOTSFields.empty())
|
|
|
{
|
|
|
LogTrace(__FILE__, __LINE__, _T("CalGBFields: listOTSFields is empty ."));
|
|
|
@@ -1209,60 +1192,27 @@ namespace OTSGBCalculate
|
|
|
CPoint poiOTSFieldPosition = allOTSFields[i]->GetPosition();
|
|
|
|
|
|
pointTopleft.x = min(poiOTSFieldPosition.x, pointTopleft.x);
|
|
|
- pointTopleft.y = min(poiOTSFieldPosition.y, pointTopleft.y);
|
|
|
+ pointTopleft.y = max(poiOTSFieldPosition.y, pointTopleft.y);
|
|
|
pointBottomright.x = max(poiOTSFieldPosition.x, pointBottomright.x);
|
|
|
- pointBottomright.y = max(poiOTSFieldPosition.y, pointBottomright.y);
|
|
|
- }
|
|
|
-
|
|
|
- // cal ots columns 有效区域内所有的OTScolumn数
|
|
|
- int nOTSColumnNum = ((pointBottomright.x - pointTopleft.x) / nOTSFieldWidth) + 1;
|
|
|
-
|
|
|
- // cal ots rows有效区域内所有的OTSRow数
|
|
|
- int nOTSRowNum = ((pointBottomright.y - pointTopleft.y) / nOTSFieldHeight) + 1;
|
|
|
-
|
|
|
- int nPossibleGBFieldRowNum = nOTSRowNum /nOTSRowsPerGBfld;//可能有的国标field行数
|
|
|
- int nPossibleGBFieldColNum = nOTSColumnNum / nOTSColumnsPerGBFld;//列数
|
|
|
-
|
|
|
- // cal possible GBFields area
|
|
|
- CPoint pointPosibleAreaTopLeft = pointTopleft;
|
|
|
- //CPoint poiPosAreaBottomRight = poiBottomright;
|
|
|
- CPoint pointPossibleAreaBottomRight = pointTopleft;
|
|
|
-
|
|
|
- pointPosibleAreaTopLeft.x -= nOTSFieldWidth / 2;
|
|
|
- pointPosibleAreaTopLeft.y -= nOTSFieldHeight / 2;
|
|
|
-
|
|
|
- //pointPossibleAreaBottomRight.x += (nPossibleGBFieldColNum * nOTSColumnsPerGBFld * nOTSFieldWidth - nOTSFieldWidth / 2);
|
|
|
- pointPossibleAreaBottomRight.x += (nPossibleGBFieldColNum * nOTSColumnsPerGBFld * nOTSFieldWidth );
|
|
|
- //pointPossibleAreaBottomRight.y += (nPossibleGBFieldRowNum * nOTSRowsPerGBfld * nFieldHeight - nFieldHeight / 2);
|
|
|
- pointPossibleAreaBottomRight.y += (nPossibleGBFieldRowNum * nOTSRowsPerGBfld * nOTSFieldHeight);
|
|
|
- // form rectangle of GBFields area
|
|
|
- CRect rectOTSFieldsCuted(pointPosibleAreaTopLeft, pointPossibleAreaBottomRight);
|
|
|
- rectOTSFieldsCuted.NormalizeRect();
|
|
|
- if (rectOTSFieldsCuted.IsRectEmpty())
|
|
|
- {
|
|
|
- LogTrace(__FILE__, __LINE__, _T("CalGBFields: GBFields area is empty ."));
|
|
|
- return TRUE;
|
|
|
+ pointBottomright.y = min(poiOTSFieldPosition.y, pointBottomright.y);
|
|
|
}
|
|
|
|
|
|
- // find all OTSFields inside GBFields area
|
|
|
- COTSFieldDataList OTSFieldsInGBFieldsArea;
|
|
|
- OTSFieldsInGBFieldsArea.clear();
|
|
|
- CPoint poiOTSFieldPosition;
|
|
|
+ pointTopleft.x -= nOTSFieldWidth / 2;
|
|
|
+ pointTopleft.y += nOTSFieldHeight / 2;
|
|
|
+ pointBottomright.x+= nOTSFieldWidth / 2;
|
|
|
+ pointBottomright.y-= nOTSFieldHeight / 2;
|
|
|
+
|
|
|
+ double totalWidth = pointBottomright.x - pointTopleft.x;
|
|
|
+ double totalHeight = pointTopleft.y - pointBottomright.y;
|
|
|
+
|
|
|
+
|
|
|
+ int nPossibleGBFieldRowNum = totalHeight /GB_FIELD_WIDTH+0.5;//可能有的国标field行数
|
|
|
+ int nPossibleGBFieldColNum = totalWidth / GB_FIELD_WIDTH+0.5;//列数
|
|
|
|
|
|
- for (auto OTSField : allOTSFields)
|
|
|
- {
|
|
|
- poiOTSFieldPosition = OTSField->GetPosition();
|
|
|
- //if over the edge
|
|
|
- if (rectOTSFieldsCuted.PtInRect(poiOTSFieldPosition))
|
|
|
- {
|
|
|
- OTSFieldsInGBFieldsArea.push_back(OTSField);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
//get possible OTSFields
|
|
|
m_listGBFields->clear();
|
|
|
CPoint pointGBFieldPosition;
|
|
|
- int nOTSFieldsPerGBField = nOTSRowsPerGBfld * nOTSColumnsPerGBFld;
|
|
|
for (int i = 0; i < nPossibleGBFieldRowNum; i++)
|
|
|
{
|
|
|
for (int j = 0; j < nPossibleGBFieldColNum; j++)
|
|
|
@@ -1271,31 +1221,29 @@ namespace OTSGBCalculate
|
|
|
// cal GB field rectangle
|
|
|
CPoint poiCurGBFieldTopLeft, poiCurGBFieldBottomRight;
|
|
|
|
|
|
- poiCurGBFieldTopLeft = pointPosibleAreaTopLeft;
|
|
|
+ poiCurGBFieldTopLeft = pointTopleft;
|
|
|
//获得左上角的坐标
|
|
|
- poiCurGBFieldTopLeft.x += nOTSColumnsPerGBFld * j * nOTSFieldWidth;
|
|
|
- poiCurGBFieldTopLeft.y += nOTSRowsPerGBfld * i * nOTSFieldHeight;
|
|
|
+ poiCurGBFieldTopLeft.x += j * GB_FIELD_WIDTH;
|
|
|
+ poiCurGBFieldTopLeft.y -= i * GB_FIELD_WIDTH;
|
|
|
//获得右下角的坐标
|
|
|
- poiCurGBFieldBottomRight.x = poiCurGBFieldTopLeft.x + nOTSColumnsPerGBFld * nOTSFieldWidth;
|
|
|
- poiCurGBFieldBottomRight.y = poiCurGBFieldTopLeft.y + nOTSRowsPerGBfld * nOTSFieldHeight;
|
|
|
- CRect rectGBField(poiCurGBFieldTopLeft, poiCurGBFieldBottomRight);
|
|
|
- rectGBField.NormalizeRect();
|
|
|
+ poiCurGBFieldBottomRight.x = poiCurGBFieldTopLeft.x + GB_FIELD_WIDTH;
|
|
|
+ poiCurGBFieldBottomRight.y = poiCurGBFieldTopLeft.y - GB_FIELD_WIDTH;
|
|
|
+ COTSRect rectGBField(poiCurGBFieldTopLeft, poiCurGBFieldBottomRight);
|
|
|
+
|
|
|
|
|
|
CGBFieldDataPtr pGBFieldData;
|
|
|
- //切割组合的矩形成为GBfield,
|
|
|
+
|
|
|
|
|
|
- pGBFieldData = GetOneGBField(rectGBField, OTSFieldsInGBFieldsArea, nOTSRowsPerGBfld, nOTSColumnsPerGBFld, sizePixelImage, nOTSFieldWidth, nOTSFieldHeight);
|
|
|
+ pGBFieldData = GetOneGBField(rectGBField, allOTSFields, sizePixelImage, nOTSFieldWidth, nOTSFieldHeight);
|
|
|
if (!pGBFieldData)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
- rectGBField.bottom = rectGBField.top + GB_FIELD_WIDTH;
|
|
|
- rectGBField.right = rectGBField.left + GB_FIELD_WIDTH;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
+ CPoint poiNewPosition=rectGBField.GetCenterPoint();
|
|
|
|
|
|
- CPoint poiNewPosition;
|
|
|
- poiNewPosition.x = rectGBField.left + GB_FIELD_WIDTH / 2;
|
|
|
- poiNewPosition.y = rectGBField.top + GB_FIELD_WIDTH / 2;
|
|
|
|
|
|
pGBFieldData->SetPosition(poiNewPosition);
|
|
|
|
|
|
@@ -1328,12 +1276,10 @@ namespace OTSGBCalculate
|
|
|
}
|
|
|
|
|
|
// get the GB field within a rectangle
|
|
|
- CGBFieldDataPtr CGBCalculate::GetOneGBField( CRect a_rectGBField,
|
|
|
- COTSFieldDataList& allOTSFields,
|
|
|
- int nOTSRowsPerGBFld,
|
|
|
- int nOTSColumnsPerGBFld,
|
|
|
- CSize a_sizePixelImage,
|
|
|
- int nOTSFieldWidth,int nOTSFieldHeight)
|
|
|
+ CGBFieldDataPtr CGBCalculate::GetOneGBField(COTSRect a_rectGBField,
|
|
|
+ COTSFieldDataList& allOTSFields,
|
|
|
+ CSize a_sizePixelImage,
|
|
|
+ int nOTSFieldWidth, int nOTSFieldHeight)
|
|
|
{
|
|
|
// GB Field handle
|
|
|
CGBFieldDataPtr pGBFieldData = nullptr;
|
|
|
@@ -1346,73 +1292,52 @@ namespace OTSGBCalculate
|
|
|
{
|
|
|
// get an OTS field
|
|
|
CPoint poiOTSField = (*itr)->GetPosition();
|
|
|
-
|
|
|
- //check if the field is within the rectangle
|
|
|
- if(a_rectGBField.PtInRect(poiOTSField))
|
|
|
+
|
|
|
+ COTSRect fldRec = COTSRect(poiOTSField.x - nOTSFieldWidth / 2, poiOTSField.y + nOTSFieldHeight / 2, poiOTSField.x + nOTSFieldWidth / 2, poiOTSField.y - nOTSFieldHeight / 2);
|
|
|
+
|
|
|
+ if (a_rectGBField.IntersectOtherRect( fldRec))
|
|
|
{
|
|
|
- // found a field
|
|
|
+
|
|
|
|
|
|
- // add into the list
|
|
|
+
|
|
|
+ (*itr)->SetRect(fldRec);
|
|
|
myOTSFields.push_back(*itr);
|
|
|
|
|
|
- // remove the field from the measurement field list
|
|
|
- // move to the next item
|
|
|
- //itr = allOTSFields.erase(itr);//There's no need to delete the field. gsp
|
|
|
+
|
|
|
itr++;
|
|
|
- // jump over
|
|
|
+
|
|
|
continue;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- // move to the next item
|
|
|
+
|
|
|
itr++;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- // make sure GBFields list has enough OTSFields
|
|
|
- int nOTSFieldsOfAGBField = nOTSRowsPerGBFld * nOTSColumnsPerGBFld;
|
|
|
- if (myOTSFields.size() == nOTSFieldsOfAGBField)
|
|
|
- {
|
|
|
- // sort the GBFields list
|
|
|
- sort(myOTSFields.begin(), myOTSFields.end(), comp);
|
|
|
-
|
|
|
- // normalize particles for the GBFields
|
|
|
+
|
|
|
pGBFieldData = NormalizeParticles(a_rectGBField, myOTSFields, a_sizePixelImage, nOTSFieldWidth, nOTSFieldHeight);
|
|
|
pGBFieldData->myReleventOTSFlds = myOTSFields;
|
|
|
- }
|
|
|
-
|
|
|
- // return GB Field handle
|
|
|
+
|
|
|
return pGBFieldData;
|
|
|
}
|
|
|
|
|
|
- // Custom collation rules
|
|
|
- BOOL compSegment(const COTSSegmentPtr &a, const COTSSegmentPtr &b)
|
|
|
- {
|
|
|
- if (a->GetHeight() <= b->GetHeight())
|
|
|
- {
|
|
|
- if (a->GetHeight() == b->GetHeight())
|
|
|
- {
|
|
|
- if (a->GetStart() < b->GetStart())
|
|
|
- {
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
- }
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// normalize particles for the GBFields
|
|
|
- CGBFieldDataPtr CGBCalculate::NormalizeParticles(CRect a_rectGBField, COTSFieldDataList myOTSFields, CSize a_sizePixelImage, int nFieldWidth,int nFieldHeight)
|
|
|
+ CGBFieldDataPtr CGBCalculate::NormalizeParticles(COTSRect a_rectGBField, COTSFieldDataList myOTSFields, CSize a_sizePixelImage, int nFieldWidth,int nFieldHeight)
|
|
|
{
|
|
|
// inits
|
|
|
CGBFieldDataPtr pGBFieldData(new CGBFieldData);
|
|
|
-
|
|
|
+
|
|
|
+ pGBFieldData->SetMyRect(a_rectGBField);
|
|
|
+
|
|
|
COTSParticleList listNormalizedParticles;
|
|
|
|
|
|
- CPoint pointGBFieldRectTopLeft = a_rectGBField.TopLeft();
|
|
|
- //a_rectGBField.Width = 707;
|
|
|
- CRect GBRect = CRect(a_rectGBField.left, a_rectGBField.top, a_rectGBField.left+GB_FIELD_WIDTH, a_rectGBField.top+ GB_FIELD_WIDTH);
|
|
|
+ CPoint pointGBFieldRectTopLeft = a_rectGBField.GetTopLeft();
|
|
|
+
|
|
|
+ COTSRect GBRect = a_rectGBField;
|
|
|
+
|
|
|
int nBeforeCalNo = 0;
|
|
|
int nAfterCalNo = 0;
|
|
|
for (auto OTSField : myOTSFields)
|
|
|
@@ -1420,15 +1345,28 @@ namespace OTSGBCalculate
|
|
|
for (auto part : OTSField->GetParticleList())
|
|
|
{
|
|
|
CPoint fieldPos = OTSField->GetPosition();
|
|
|
- CPoint fieldTopLeft = CPoint(fieldPos.x - nFieldWidth / 2, fieldPos.y + nFieldHeight);
|
|
|
+ //CPoint fieldTopLeft = CPoint(fieldPos.x - nFieldWidth / 2, fieldPos.y + nFieldHeight/2);
|
|
|
+ CPoint fieldTopLeft = OTSField->GetRect().GetTopLeft();
|
|
|
double fwidth = nFieldWidth;
|
|
|
double pixelsize = fwidth / a_sizePixelImage.cx;
|
|
|
CPoint xrayPosInFieldByPixel= part->GetXRayPos();
|
|
|
|
|
|
CPoint partPos = CPoint(fieldTopLeft.x + xrayPosInFieldByPixel.x * pixelsize, fieldTopLeft.y - xrayPosInFieldByPixel.y * pixelsize);
|
|
|
|
|
|
- if (GBRect.PtInRect(partPos))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (GBRect.PointInRect(partPos))
|
|
|
{
|
|
|
+ CRect rectInSinglefld = part->GetParticleRect();
|
|
|
+ CPoint OTSLeftTop = CPoint(fieldTopLeft.x + rectInSinglefld.left * pixelsize, fieldTopLeft.y - rectInSinglefld.top * pixelsize);
|
|
|
+ CPoint OTSRightBottom = CPoint(fieldTopLeft.x + rectInSinglefld.right * pixelsize, fieldTopLeft.y - rectInSinglefld.bottom * pixelsize);
|
|
|
+
|
|
|
+ COTSRect recInOTSCord = COTSRect(OTSLeftTop, OTSRightBottom);
|
|
|
+ part->SetOTSRect(recInOTSCord);
|
|
|
+
|
|
|
+
|
|
|
+ pGBFieldData->IdentifyPartChemicalType(part);
|
|
|
listNormalizedParticles.push_back(part);
|
|
|
}
|
|
|
|
|
|
@@ -1444,248 +1382,13 @@ namespace OTSGBCalculate
|
|
|
return pGBFieldData;
|
|
|
}
|
|
|
|
|
|
- //function Get GBField's FieldSegments List
|
|
|
- BOOL CGBCalculate::GetGBFieldSegmentsList(int a_nColum, int a_nRow, COTSParticleList a_listOTSFieldParticles, int a_nCalNo, COTSSegmentsList &a_listGBFieldSegments, CSize a_sizePixelImage, int a_nFieldWidth)
|
|
|
- {
|
|
|
- CRect rectParticle;
|
|
|
- CPoint poiParticleTopLeft;
|
|
|
- COTSSegmentsList listOTSFieldSegments;
|
|
|
- long nNewStart = 0, nNewLength = 0, nNewHeight;
|
|
|
- long nOffsetX = a_nColum * a_sizePixelImage.cx;
|
|
|
- long nOffsetY = a_nRow * a_sizePixelImage.cy;
|
|
|
- // get one pixel width
|
|
|
- //double dPixelsize = (double)a_nFieldWidth / a_sizePixelImage.cx;
|
|
|
- double dPixelsize = (double)a_sizePixelImage.cx/a_nFieldWidth ;
|
|
|
- double dGBwidth = sqrt(0.5) * 1000;
|
|
|
- long nGBpixcel = (long)(dGBwidth * dPixelsize);
|
|
|
-
|
|
|
- //cal the new segment coordinate
|
|
|
- for (auto Particle : a_listOTSFieldParticles)
|
|
|
- {
|
|
|
- //get the Particle rect
|
|
|
- rectParticle = Particle->GetParticleRect();
|
|
|
- poiParticleTopLeft = rectParticle.TopLeft();
|
|
|
- listOTSFieldSegments = Particle->GetFeature()->GetSegmentsList();
|
|
|
- for (auto Segment : listOTSFieldSegments)
|
|
|
- {
|
|
|
- BOOL bMerge = (a_nColum > 0) && (Segment->GetStart() == 0);
|
|
|
-
|
|
|
- // off set the segment
|
|
|
- nNewStart = Segment->GetStart() + nOffsetX;
|
|
|
- nNewHeight= Segment->GetHeight() + nOffsetY;
|
|
|
-
|
|
|
- // check should we need to keep the segment
|
|
|
- // cal if the Segment in the GB 0.5/m2
|
|
|
- if (nNewStart > nGBpixcel)
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (nNewHeight > nGBpixcel)
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // do we need to cut the segment
|
|
|
- //if over 0.5m2 cut it
|
|
|
- //get GBField's a_nHeight, long a_nStart, long a_nLength
|
|
|
- nNewLength = Segment->GetLength();
|
|
|
- if (nNewStart + Segment->GetLength() > nGBpixcel)
|
|
|
- {
|
|
|
- nNewLength = (long)(nGBpixcel - nNewStart);
|
|
|
- }
|
|
|
-
|
|
|
- COTSSegmentPtr pGBFieldSegment(new COTSSegment(nNewHeight, nNewStart, nNewLength));
|
|
|
-
|
|
|
- //merge the segment
|
|
|
- if (bMerge && MergSegment(a_listGBFieldSegments, pGBFieldSegment, a_nCalNo))
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- a_listGBFieldSegments.push_back(pGBFieldSegment);
|
|
|
- }
|
|
|
- }
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
-
|
|
|
- // merge the segment
|
|
|
- BOOL CGBCalculate::MergSegment(COTSSegmentsList &a_listGBFieldSegments, COTSSegmentPtr a_pGBFieldSegment, int a_nCalNo)
|
|
|
- {
|
|
|
- //search merge segments only on last field
|
|
|
- COTSSegmentsList::iterator itr = a_listGBFieldSegments.begin()+ a_nCalNo;
|
|
|
- while (itr != a_listGBFieldSegments.end())
|
|
|
- {
|
|
|
- COTSSegmentPtr pSegmentHead = *itr;
|
|
|
- long nNextX = pSegmentHead->GetStart() + pSegmentHead->GetLength();
|
|
|
- //merge only when height are the same
|
|
|
- if (pSegmentHead->GetHeight() == a_pGBFieldSegment->GetHeight())
|
|
|
- {
|
|
|
- //end to start
|
|
|
- if ((nNextX + 1) == a_pGBFieldSegment->GetStart())
|
|
|
- {
|
|
|
- //merge and return true
|
|
|
- pSegmentHead->SetLength(pSegmentHead->GetLength() + a_pGBFieldSegment->GetLength());
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
- }
|
|
|
- itr++;
|
|
|
- }
|
|
|
-
|
|
|
- //didn't merge return false
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- // merge the segment,get new particles
|
|
|
- BOOL CGBCalculate::GetGBParticles(COTSSegmentsList a_listGBFieldSegments, COTSParticleList &a_listNormalizedParticles)
|
|
|
- {
|
|
|
- //change segments to Particles
|
|
|
- COTSFeatureList listFeatures;
|
|
|
-
|
|
|
- if (a_listGBFieldSegments.size() == 0)
|
|
|
- {
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- GetFeatureList1(a_listGBFieldSegments, listFeatures);
|
|
|
- ChangeFeaturelist(listFeatures, a_listNormalizedParticles);
|
|
|
- for (auto p : a_listNormalizedParticles)
|
|
|
- {
|
|
|
- COTSImageProcess::CalcuParticleImagePropertes(p, PixSize);
|
|
|
-
|
|
|
- }
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- BOOL CGBCalculate::GetFeatureList1(COTSSegmentsList& a_listSegments, COTSFeatureList& a_listFeatures)
|
|
|
- {
|
|
|
- COTSSegmentsList listSegmentNew;
|
|
|
- std::map<long, COTSSegmentsList > mapOneLineSegments;
|
|
|
- for (auto s : a_listSegments)
|
|
|
- {
|
|
|
- mapOneLineSegments[s->GetHeight()].push_back(s);
|
|
|
- }
|
|
|
- std::map<long, COTSSegmentsList >::iterator lineItr = mapOneLineSegments.begin();//find the highest line
|
|
|
- while (lineItr!=mapOneLineSegments.end ())
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- for (auto s = lineItr->second.begin(); s < lineItr->second.end(); )//find one segment of this line.
|
|
|
- {
|
|
|
-
|
|
|
- COTSSegmentPtr bottomSeg= *s;
|
|
|
- listSegmentNew.clear();
|
|
|
- listSegmentNew.push_back(*s);
|
|
|
- s=lineItr->second.erase(s);
|
|
|
- std::map<long, COTSSegmentsList >::iterator tempItr = lineItr;
|
|
|
- tempItr++;
|
|
|
- for (; tempItr !=mapOneLineSegments.end(); tempItr++)//find all other lines of segments
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- for (auto nextLineSegment = tempItr->second.begin(); nextLineSegment < tempItr->second.end();)//find next line's all segments
|
|
|
- {
|
|
|
- if (bottomSeg->UpDownConection(**nextLineSegment))
|
|
|
- {
|
|
|
- listSegmentNew.push_back(*nextLineSegment);
|
|
|
- bottomSeg = *nextLineSegment;
|
|
|
- nextLineSegment=tempItr->second.erase(nextLineSegment);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (tempItr->second.size() > 0)
|
|
|
- {
|
|
|
- nextLineSegment++;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- COTSFeaturePtr pFeature = COTSFeaturePtr(new COTSFeature());
|
|
|
- pFeature->SetSegmentsList(listSegmentNew);
|
|
|
- //check if this new feature is connected with other found feature.
|
|
|
- COTSSegmentPtr topSeg = listSegmentNew[0];//find the toppest segment of this new feature.
|
|
|
- COTSSegmentPtr bottomSegment= listSegmentNew[listSegmentNew.size()-1];//find the lowest segment of this new feature.
|
|
|
-
|
|
|
- bool haveMerged=false;
|
|
|
- for (auto f : a_listFeatures)
|
|
|
- {
|
|
|
- for (auto seg : f->GetSegmentsList())
|
|
|
- {
|
|
|
- if (bottomSegment->UpDownConection(*seg)|| topSeg->UpDownConection (*seg))
|
|
|
- {
|
|
|
- COTSSegmentsList segs = f->GetSegmentsList();
|
|
|
- for (auto s : listSegmentNew)
|
|
|
- {
|
|
|
- segs.push_back(s);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- f->SetSegmentsList(segs);
|
|
|
- haveMerged = true;
|
|
|
- break ;
|
|
|
- }
|
|
|
- }
|
|
|
- if (haveMerged)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (!haveMerged)
|
|
|
- {
|
|
|
- a_listFeatures.push_back(pFeature);
|
|
|
- }
|
|
|
-
|
|
|
- if (lineItr->second.size()==0)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- lineItr++;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- // change feature into particle
|
|
|
- BOOL CGBCalculate::ChangeFeaturelist(COTSFeatureList& a_listFeatures, COTSParticleList& a_listParticle)
|
|
|
- {
|
|
|
- if (a_listFeatures.size() == 0)
|
|
|
- {
|
|
|
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeFeaturelist: there is no feature in the list."));
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- // compute Rect
|
|
|
- for (auto pFeature : a_listFeatures)
|
|
|
- {
|
|
|
- COTSParticlePtr pParticle = COTSParticlePtr(new COTSParticle());
|
|
|
- COTSFeaturePtr pFeatureNew = COTSFeaturePtr(new COTSFeature(*pFeature.get()));
|
|
|
- pParticle->SetFeature(pFeatureNew);
|
|
|
- if (!pParticle->CalCoverRect())
|
|
|
- {
|
|
|
- LogErrorTrace(__FILE__, __LINE__, _T("ChangeFeaturelist: failed to get particle rect."));
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- a_listParticle.push_back(pParticle);
|
|
|
- }
|
|
|
-
|
|
|
- if ((int)a_listParticle.size() == 0)
|
|
|
- {
|
|
|
- LogErrorTrace(__FILE__, __LINE__, _T("Can't get particle."));
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
void CGBCalculate::SetPixSize(double p)
|
|
|
{
|
|
|
PixSize = p;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|