Browse Source

improve overlap measure flow algorithm

gsp 1 year ago
parent
commit
f74b2a1ffe

+ 2 - 2
Bin/x64/Debug/Config/ProData/HardwareConfig.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <XMLData PathName="HardwareConfig.xml" ID="1">
-  <Member RegName="SemControllerName" Value="Oxford" ImageInputSources="SE" />
-  <Member RegName="EDSName" Value="Oxford" DelayQuantify="true" />
+  <Member RegName="SemControllerName" Value="OffLine" ImageInputSources="SE" />
+  <Member RegName="EDSName" Value="OffLine" DelayQuantify="true" />
   <Member RegName="BrukerDllVersion" Version="Bruker.API.Esprit64.dll" />
   <Member RegName="FEIIP" Value="192.168.0.1" />
   <Member RegName="FEIPORT" Value="7520" />

+ 13 - 52
OTSCPP/OTSClrInterface/ImageProClr/FieldMgrClr.cpp

@@ -53,7 +53,7 @@ namespace OTSCLRINTERFACE {
 	}
 
 	bool CFieldMgrClr::Init(CDomainClr^ a_pMeasureArea,
-		Size^ a_ResolutionSize,int a_scanfieldsize, int a_FieldStartMode
+		 int a_FieldStartMode
 		)
 	{
 		
@@ -70,66 +70,27 @@ namespace OTSCLRINTERFACE {
 			LogErrorTrace(__FILE__, __LINE__, _T("Init: invalid pointer."));
 			return false;
 		}
-		CSize resolu;
-		resolu.cx = a_ResolutionSize->Width;
-		resolu.cy = a_ResolutionSize->Height;
-		bool bRet = pFieldMgr->Init(pDomain, resolu,a_scanfieldsize,a_FieldStartMode);
+		
+		bool bRet = pFieldMgr->Init(pDomain,a_FieldStartMode);
 
 		return bRet;
 
 	}
 
-	// calculate estimate total fields
-	long CFieldMgrClr::CalculateTotalFields(CDomainClr^ a_poMeasureArea, double a_dScanFieldSizeX, Size^ a_sizeResolution)
+	int CFieldMgrClr::GetEffectiveFieldWidth()
 	{
-		if (this == nullptr)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("CalculateTotalFields:invalid pointer."));
-			return -1;
-		}
-
-		ASSERT(a_poMeasureArea);
-		if (!a_poMeasureArea)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("CalculateTotalFields:invalid mesaure area pointer."));
-			return -1;
-		}
-
-		CDomainPtr pDomain = a_poMeasureArea->GetDomainPtr();
-
-		ASSERT(pDomain);
-		if (!pDomain)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("CalculateTotalFields:invalid mesaure area pointer."));
-			return -1;
-		}
-
-		ASSERT(a_sizeResolution);
-		if (a_sizeResolution)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("CalculateTotalFields:invalid mesaure area pointer."));
-			return -1;
-		}
-
-		CSize sz;
-		sz.cx = a_sizeResolution->Width;
-		sz.cy = a_sizeResolution->Height;
-
 		CFieldMgrPtr pFieldMgr = GetCFiledMgrPtr();
+		return pFieldMgr->GetEffectiveFieldWidth();
+	}
 
-		ASSERT(pFieldMgr);
-		if (!pFieldMgr)
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("Reset: invalid pointer."));
-			return -1;
-		}
-
-		long lRet = pFieldMgr->CalculateTotalFields(pDomain, a_dScanFieldSizeX, sz);
-
-		return lRet;
-
+	int CFieldMgrClr::GetEffectiveFieldHeight()
+	{
+		CFieldMgrPtr pFieldMgr = GetCFiledMgrPtr();
+		return pFieldMgr->GetEffectiveFieldHeight();
 	}
 
+	
+
 	List<Point>^ CFieldMgrClr::GetFieldCentrePoints()
 	{
 		List<Point>^ NameClr = gcnew List<Point>();
@@ -263,7 +224,7 @@ namespace OTSCLRINTERFACE {
 		return true;
 	}
 
-	bool CFieldMgrClr::FindNeighborField( List<Point>^ a_flds, Point centerField,Point a_neighbor, int a_direction)
+	bool CFieldMgrClr::FindNeighborField( List<Point>^ a_flds, Point centerField,Point% a_neighbor, int a_direction)
 	{
 		std::vector<CPoint> allfieldPos;
 		CPoint curFld;

+ 4 - 5
OTSCPP/OTSClrInterface/ImageProClr/FieldMgrClr.h

@@ -26,12 +26,11 @@ namespace OTSCLRINTERFACE {
 
 								// initialization
 		bool Init(CDomainClr^ a_pMeasureArea,
-			Size^ a_ResolutionSize,int a_scanfieldsize, int a_FieldStartMode
+			 int a_FieldStartMode
 			);
 
-	
-		// calculate estimate total fields
-		long CalculateTotalFields(CDomainClr^ a_poMeasureArea, double a_dScanFieldSizeX, Size^ a_sizeResolution);
+		int GetEffectiveFieldWidth();
+		int GetEffectiveFieldHeight();
 
 		// field centre points list
 		List<Point>^ GetFieldCentrePoints();
@@ -48,7 +47,7 @@ namespace OTSCLRINTERFACE {
 
 		int GetOverlap();
 		bool SetOverlap(int a_overlap);
-		bool FindNeighborField( List<Point>^ a_flds, Point centerField, Point a_neighbor, int a_direction);
+		bool FindNeighborField( List<Point>^ a_flds, Point centerField, Point% a_neighbor, int a_direction);
 
 
 	protected:

+ 48 - 140
OTSCPP/OTSImagePro/FieldMgr.cpp

@@ -126,7 +126,7 @@ namespace OTSIMGPROC {
 
 
 	// initialization
-	BOOL CFieldMgr::Init(CDomainPtr a_pMeasureArea, CSize a_ResolutionSize,int a_scanfieldsize,int a_FieldStartMode)
+	BOOL CFieldMgr::Init(CDomainPtr a_pMeasureArea, int a_FieldStartMode)
 	{
 		// input check
 		ASSERT(a_pMeasureArea);
@@ -137,18 +137,13 @@ namespace OTSIMGPROC {
 		m_pMeasureArea = CDomainPtr(new CDomain(a_pMeasureArea.get()));
 		
 	
-		m_ResolutionSize = a_ResolutionSize;
 		m_fieldStartMode = a_FieldStartMode;
-		m_ScanFieldSize = a_scanfieldsize;
-		// calculate field centre points list
-	
 
-		// ok, return TRUE;
 		return TRUE;
 	}
 	std::vector<CPoint> CFieldMgr::GetUnmeasuredFieldCentrePoints(std::vector<CPoint> a_listMeasuredFieldCentrePoints)
 	{
-		std::vector<CPoint> allPoints = CalculateFieldCentrePoints1();
+		std::vector<CPoint> allPoints = CalculateFieldCentrePoints();
 		std::vector<CPoint> unmeasuredPoints;
 		for(auto p:allPoints)
 		if (!IsInMeasuredFieldList(p,a_listMeasuredFieldCentrePoints))
@@ -159,99 +154,16 @@ namespace OTSIMGPROC {
 		return unmeasuredPoints;
 	}
 
-	// calculate total fields
-	long CFieldMgr::CalculateTotalFields(CDomainPtr a_poMeasureArea, double a_dScanFieldSizeX, CSize a_sizePixelImage)
-	{
-		// total fields
-		long nTotalFields = -1;
-
-		// input check
-		ASSERT(a_poMeasureArea);
-		if (!a_poMeasureArea || a_poMeasureArea->IsInvalid())
-		{
-			LogErrorTrace(__FILE__, __LINE__, _T("CalculateTotalFields: invalid mesure area point."));
-			return nTotalFields;
-		}
-
-		// calculate scan field size--Y
-		double dScanFieldSizeY = a_dScanFieldSizeX * (double)a_sizePixelImage.cy / (double)a_sizePixelImage.cx;
-
-		// calculate total columns
-		long nTotalCols = (long)ceil((double)a_poMeasureArea->GetDomainRect().Width() / a_dScanFieldSizeX);
-
-		// calculate total rows
-		long nTotalRows = (long)ceil((double)a_poMeasureArea->GetDomainRect().Height() / dScanFieldSizeY);
-
-		// calculate column on the right of the center column
-		long nRightColumns = nTotalCols / 2;
-
-		// calculate rows above the center row
-		long nTopRows = nTotalRows / 2;
-
-		// re-calculate total columns, total rows make sure they are odd numbers
-		nTotalCols = nRightColumns * 2 + 1;
-		nTotalRows = nTopRows * 2 + 1;
-
-		// measure are is a rectangle?
-		if (a_poMeasureArea->IsRect() || nTotalCols == 1 || nTopRows == 1)
-		{
-			// easy 
-			nTotalFields = nTotalCols * nTopRows;
-		}
-		else
-		{
-			// we need to do more calculation
-
-			// centre row, centre column and centre field
-			nTotalFields = nRightColumns * 2 + nTotalRows * 2 + 1;
-
-			// calculate top right part 
-			int nTopRightPartFileds = 0;
-			CPoint poi; 
-			// row by row
-			for (int i = 1; i <= nTopRows; ++i)
-			{
-				// calculate row y position (field bottom)
-				poi.y = a_poMeasureArea->GetDomainCenter().y + (int)dScanFieldSizeY * i - (int)dScanFieldSizeY / 2;
-
-				// column by column
-				for (int j = 1; j <= nRightColumns; ++j)
-				{
-					// calculate column x position (field left)
-					poi.x = a_poMeasureArea->GetDomainCenter().x + (int)a_dScanFieldSizeX * i - (int)a_dScanFieldSizeX / 2;
-
-					// test if this field is in the measure domain
-					if (a_poMeasureArea->PtInDomain(poi))
-					{
-						// in the measure domain, count it.
-						++nTopRightPartFileds;
-					}
-					else
-					{
-						// not in the measure domain, get out row test
-						break;
-					}
-				}
-			}
-
-			// add other fields (top right part fields times 4)
-			nTotalFields += nTopRightPartFileds * 4;
-		}
-
-		// return total fields
-		return nTotalFields;
-	}
-
 	std::vector<CPoint> CFieldMgr::GetFieldCentrePoints()
 	{
-		 auto m_listFieldCentrePoints = CalculateFieldCentrePoints1();
+		 auto m_listFieldCentrePoints = CalculateFieldCentrePoints();
 		 return m_listFieldCentrePoints; 
 	}
 
 	// field centre points list
 	BOOL CFieldMgr::GetFieldRectByIndex(int a_nIndex, CRect& a_rectField)
 	{
-		auto m_listFieldCentrePoints = CalculateFieldCentrePoints1();
+		auto m_listFieldCentrePoints = CalculateFieldCentrePoints();
 		// check input
 		if (a_nIndex < 0 || a_nIndex >(int)m_listFieldCentrePoints.size())
 		{
@@ -263,11 +175,9 @@ namespace OTSIMGPROC {
 
 		// get image size
 	
-		CSize sizePixelImage = m_ResolutionSize;
-		// scan field size (x, y)
 		CSize sizeImage;
-		sizeImage.cx = m_ScanFieldSize;
-		sizeImage.cy = sizeImage.cx * sizePixelImage.cy / sizePixelImage.cx;
+		sizeImage.cx = GetEffectiveFieldWidth();
+		sizeImage.cy = GetEffectiveFieldHeight();
 		// get left top
 		CPoint ptLeftTop = m_listFieldCentrePoints[a_nIndex] - CPoint(sizeImage.cx / 2, sizeImage.cy / 2);
 		// get field rectangle
@@ -277,7 +187,7 @@ namespace OTSIMGPROC {
 
 	int CFieldMgr::GetTotalFields()
 	{
-		auto m_listFieldCentrePoints = CalculateFieldCentrePoints1();
+		auto m_listFieldCentrePoints = CalculateFieldCentrePoints();
 		return (int)m_listFieldCentrePoints.size();
 	}
 
@@ -301,16 +211,39 @@ namespace OTSIMGPROC {
 
 
 
+	int CFieldMgr::GetEffectiveFieldWidth()
+	{
+			auto width= m_ScanFieldSize - 2*m_overlap;
+			return width;
+	}
+
+	int CFieldMgr::GetEffectiveFieldHeight()
+	{
+		
+			CSize ImageSizeByPixel = m_ResolutionSize;
+
+			// scan field size (x, y)
+
+			double pixelx = ImageSizeByPixel.cx;
+			double pixely = ImageSizeByPixel.cy;
+
+			double dScanFiledSizeX = m_ScanFieldSize;
+			double dScanFiledSizeY = dScanFiledSizeX * pixely / pixelx;
+
+			auto height= dScanFiledSizeY - 2*m_overlap;
+			return height;
+	}
+
 	COTSFieldDataPtr CFieldMgr::FindNeighborField(const COTSFieldDataList a_flds, COTSFieldDataPtr a_centerField, SORTING_DIRECTION a_direction)
 	{
 		COTSFieldDataPtr fld;
 		double pixelsize;
-		double mScanfieldsize_y = m_ScanFieldSize * m_ResolutionSize.cy / m_ResolutionSize.cx;
+		
 
 		for (auto f : a_flds)
 		{
 			SORTING_DIRECTION di;
-			IsNeighborFieldCentre(f->GetPosition(), a_centerField->GetPosition(), m_ScanFieldSize, mScanfieldsize_y, di);
+			IsNeighborFieldCentre(f->GetPosition(), a_centerField->GetPosition(), GetEffectiveFieldWidth(), GetEffectiveFieldHeight(), di);
 			if (di == a_direction)
 			{
 				return f;
@@ -323,13 +256,12 @@ namespace OTSIMGPROC {
 	bool CFieldMgr::FindNeighborField(const std::vector<CPoint> a_flds, CPoint a_centerField,CPoint& neighbor, SORTING_DIRECTION a_direction)
 	{
 		
-		double pixelsize;
-		double mScanfieldsize_y = m_ScanFieldSize * m_ResolutionSize.cy / m_ResolutionSize.cx;
+		
 
 		for (auto f : a_flds)
 		{
 			SORTING_DIRECTION di;
-			IsNeighborFieldCentre(f, a_centerField, m_ScanFieldSize, mScanfieldsize_y, di);
+			IsNeighborFieldCentre(f, a_centerField, GetEffectiveFieldWidth(), GetEffectiveFieldHeight(), di);
 			if (di == a_direction)
 			{
 				neighbor=f;
@@ -345,7 +277,7 @@ namespace OTSIMGPROC {
 
 	
 	// calculate field centre points list
-	std::vector<CPoint>  CFieldMgr::CalculateFieldCentrePoints1()
+	std::vector<CPoint>  CFieldMgr::CalculateFieldCentrePoints()
 	{
 		// field centre points list
 		std::vector<CPoint> m_listFieldCentrePoints;
@@ -354,25 +286,7 @@ namespace OTSIMGPROC {
 		// clean up 
 		m_listFieldCentrePoints.clear();
 
-		CSize ImageSizeByPixel = m_ResolutionSize;
-
-		// scan field size (x, y)
-		
-		double pixelx = ImageSizeByPixel.cx ;
-		double pixely = ImageSizeByPixel.cy;
 		
-		double dScanFiledSizeX = m_ScanFieldSize ;
-		double dScanFiledSizeY = dScanFiledSizeX * pixely / pixelx;
-		CSize sizeImage;
-		sizeImage.cx = dScanFiledSizeX;
-		sizeImage.cy = dScanFiledSizeY;
-	
-
-		/*double dOverLapSizeX = m_Overlap * dScanFiledSizeX / pixelx;
-		double dOverLapSizeY = m_Overlap * dScanFiledSizeY / pixely;*/
-
-		double dOverLapSizeX = m_Overlap;// the overlap is indicated by micron(um)
-		double dOverLapSizeY = m_Overlap;
 
 		// the measure domain rectangle 
 		CRect rectMeasureDomain = m_pMeasureArea->GetDomainRect();
@@ -380,13 +294,18 @@ namespace OTSIMGPROC {
 		// the measure domain centre 
 		CPoint poiDomainCentre = rectMeasureDomain.CenterPoint();
 
-		
+		double effectiveWidth = GetEffectiveFieldWidth();
+		double effectiveHeight = GetEffectiveFieldHeight();
+
+		CSize sizeImage;
+		sizeImage.cx = effectiveWidth;
+		sizeImage.cy = effectiveHeight;
 		// start mode
 		OTS_GET_IMAGE_MODE nStartMode = (OTS_GET_IMAGE_MODE)m_fieldStartMode;
 			
 			// calculate total columns, rows and make sure the domain area be covered
-			int nTotalCols = (int)(ceil((double)rectMeasureDomain.Width() / (dScanFiledSizeX - 2 * dOverLapSizeX)));
-			int nTotalRows = (int)(ceil((double)rectMeasureDomain.Height() / (dScanFiledSizeY - 2 * dOverLapSizeY)));
+			int nTotalCols = (int)(ceil((double)rectMeasureDomain.Width() / effectiveWidth));
+			int nTotalRows = (int)(ceil((double)rectMeasureDomain.Height() / effectiveHeight));
 
 			// calculate column on the left of the centre point
 			int nLeftCols = nTotalCols / 2;
@@ -399,16 +318,16 @@ namespace OTSIMGPROC {
 			nTotalRows = nRowsOnTop * 2 + 1;
 
 			// calculate left, right field column position (x only
-			int nLeftMostColX = poiDomainCentre.x - nLeftCols * ((int)dScanFiledSizeX - 2 * (int)dOverLapSizeX);
-			int nUpMostRowY = poiDomainCentre.y - nRowsOnTop * ((int)dScanFiledSizeY - 2* (int)dOverLapSizeY);
+			int nLeftMostColX = poiDomainCentre.x - nLeftCols * (effectiveWidth);
+			int nUpMostRowY = poiDomainCentre.y - nRowsOnTop * (effectiveHeight);
 				
 				std::vector <std::vector <CPoint>> pointMatrics(nTotalRows, std::vector<CPoint>(nTotalCols));
 				for (int i = 0; i < nTotalRows; i++)
 				{
 					for (int j = 0; j < nTotalCols; j++)
 					{
-						pointMatrics[i][j].x = nLeftMostColX + j * ((int)dScanFiledSizeX - 2 * (int)dOverLapSizeX);
-						pointMatrics[i][j].y = nUpMostRowY + i * ((int)dScanFiledSizeY - 2 * (int)dOverLapSizeY);
+						pointMatrics[i][j].x = nLeftMostColX + j * (effectiveWidth);
+						pointMatrics[i][j].y = nUpMostRowY + i * (effectiveHeight);
 					}
 				}
 				std::vector <std::vector <int>> sequenceMat; //construct an matrics map to the pointMatrics,but the content is the sequence number.
@@ -951,17 +870,6 @@ namespace OTSIMGPROC {
 	}
 
 
-	// get a random number in a given range
-	int CFieldMgr::GetRangedRandNumber(int a_nRange_min, int a_nRange_max)
-	{
-		// return a random number
-		int nRet;
-
-		// get a random number in the given range
-		nRet = long((double)rand() / (RAND_MAX + 1) * (a_nRange_max - a_nRange_min) + a_nRange_min);
-
-		// return the random number
-		return nRet;
-	}
+	
 
 }

+ 9 - 11
OTSCPP/OTSImagePro/FieldMgr.h

@@ -25,12 +25,9 @@ namespace OTSIMGPROC {
 		virtual ~CFieldMgr();	// destructor
 
 		// initialization
-		BOOL Init(CDomainPtr a_pMeasureArea,CSize a_ResolutionSize,int a_scanfieldsize, int a_FieldStartMode);
+		BOOL Init(CDomainPtr a_pMeasureArea, int a_FieldStartMode);
 		// unmeasured field centre points list
 		std::vector<CPoint> GetUnmeasuredFieldCentrePoints(std::vector<CPoint> a_listHaveMeasuredFieldCentrePoints);
-		
-		// calculate estimate total fields
-		static long CalculateTotalFields(CDomainPtr a_poMeasureArea, double a_dScanFieldSizeX, CSize a_sizeResolution);
 
 		// field centre points list
 		std::vector<CPoint> GetFieldCentrePoints();
@@ -39,10 +36,10 @@ namespace OTSIMGPROC {
 		int GetTotalFields();
 		
 		//overlap
-		int GetOverlap() { return m_Overlap; }
+		int GetOverlap() { return m_overlap; }
 		void SetOverlap(int a_Overlap)
 		{
-			m_Overlap = a_Overlap;
+			m_overlap = a_Overlap;
 		}
 
 		// measure area
@@ -57,6 +54,9 @@ namespace OTSIMGPROC {
 		{
 			m_ScanFieldSize = a_FieldSize;
 		}
+		int GetEffectiveFieldWidth();
+		int GetEffectiveFieldHeight();
+		
 		COTSFieldDataPtr FindNeighborField(const COTSFieldDataList a_flds, COTSFieldDataPtr centerField, SORTING_DIRECTION a_direction);
 		bool FindNeighborField(const std::vector<CPoint> a_flds, CPoint a_centerField, CPoint& neighbor,SORTING_DIRECTION a_direction);
 	protected:
@@ -67,12 +67,12 @@ namespace OTSIMGPROC {
 		CDomainPtr m_pMeasureArea;
 
 		
-		int m_Overlap;
+		int m_overlap=0;
 		int m_ScanFieldSize;
 		CSize m_ResolutionSize;
 		int m_fieldStartMode;
 		// calculate field centre points list
-		std::vector<CPoint> CalculateFieldCentrePoints1();
+		std::vector<CPoint> CalculateFieldCentrePoints();
 
 		// test if field is in or partly in the measure domain area
 		BOOL IsInMeasureArea(CPoint a_poiField, CSize a_sizeImageSize);
@@ -110,9 +110,7 @@ namespace OTSIMGPROC {
 			double a_dScanFieldSizeY, 
 			SORTING_DIRECTION& a_nDirection);
 
-		// get a random number in a given range
-		int GetRangedRandNumber(int a_nRange_min, int a_nRange_max);
-
+	
 		// test if field is in or partly in the measure domain area
 		BOOL IsInPolygonMeasureArea(CPoint a_poiField, CSize a_sizeImageSize, std::vector<CPoint> ptPolygon);
 		BOOL PtInPolygon(CPoint p, const std::vector<CPoint> ptPolygon);

+ 2 - 5
OTSCPP/OTSImagePro/OTSImageProcess.cpp

@@ -96,8 +96,7 @@ namespace OTSIMGPROC
 			// get the area image	
 
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
-			//Mat blurImg;
-			//medianBlur(cvcopyImg, blurImg, 5);//get rid of the noise point.
+		
 			Mat labels = Mat::zeros(cvcopyImg.size(), CV_32S);
 			Mat  stats, centroids;
 			int number = connectedComponentsWithStats(cvcopyImg, labels, stats, centroids, 8, CV_32S);
@@ -125,7 +124,6 @@ namespace OTSIMGPROC
 				  if (actualArea >= partAreaMin && actualArea < partAreaMax)
 				  {
 				 
-				
 					Rect rectMax = Rect(x, y, w, h);
 					
 				
@@ -1082,8 +1080,7 @@ namespace OTSIMGPROC
 			line(particleImage, Point(nStart, nHeight), Point(nEnd, nHeight), Scalar(nBlackColor), nThickness, nLineType);
 		}		
 	//--------abstract the contour of the particle.
-		//Mat cvcopyImg;
-		//medianBlur(particleImage, cvcopyImg, 5);//smooth the edge
+
 	
 		vector<vector<Point>>contours;
 	

+ 6 - 499
OTSIncAMeasureApp/1-OTSMeasure/Measure/3-MeasureFlow/CSmplMsrResult.cs

@@ -14,12 +14,10 @@ namespace OTSModelSharp
 
         //----------------定义----------------------
         protected static NLog.Logger logger = null;
-        // working folder string
-        string m_strWorkingFolder;
+      
         string m_strSampleWorkingFolder;
         string m_strFieldFileSubFolder;
-        private string m_strBSEImageFileFolder;
-        private string m_strDBFileFolder;
+      
 
         // pathname
         string m_strRstFileName;
@@ -55,7 +53,7 @@ namespace OTSModelSharp
         CSEMStageData m_pSEMStageData;
         // sample stage
         CStage m_pStage;
-        //CSEMStageDataPtr m_pSEMData;
+      
         CSEMDataGnr m_pSEMData;
         // sample setting
         COTSSample m_pSample;
@@ -67,13 +65,6 @@ namespace OTSModelSharp
         public CIncAFileMgr DBFileMgr { get => m_DBFileMgr; set => m_DBFileMgr = value; }
 
 
-        //----------------public-----------------
-        public CSmplMsrResult()
-        {
-            Init();
-            m_pSample = new COTSSample();
-           
-        }
        
      
         public CSmplMsrResult(string measureWorkingFolder,COTSSample a_pSample)
@@ -85,11 +76,10 @@ namespace OTSModelSharp
 
            
 
-             m_strWorkingFolder = measureWorkingFolder;
+           
             m_strSampleWorkingFolder = measureWorkingFolder + "\\" + a_pSample.GetName();
             m_strFieldFileSubFolder = m_strSampleWorkingFolder + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
-            m_strBSEImageFileFolder = m_strFieldFileSubFolder;
-            m_strDBFileFolder = m_strFieldFileSubFolder;
+          
             m_strRstFileName = m_strSampleWorkingFolder + "\\" + a_pSample.GetName() + SMPL_MSR_RESULT_FILE_EXT;
             m_strdbPathName = m_strFieldFileSubFolder + "\\" + DBFILE_NAME;
 
@@ -172,15 +162,7 @@ namespace OTSModelSharp
             m_pSEMData = a_pSEMData;
         }
 
-        public bool GetSwitch()
-        {
-            return m_bSwitch;
-        }
-        public void SetSwitch(bool a_bSwitch)
-        {
-            m_bSwitch = a_bSwitch;
-        }
-
+ 
 
 
         public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
@@ -283,420 +265,7 @@ namespace OTSModelSharp
         }
        
 
-        // Load 
-        public bool Load(String a_strPathname /*= _T("")*/)
-        {
-
-            a_strPathname.Trim();
-            if (a_strPathname == "")
-            {
-  
-
-                FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框
-                if (FileDialog.ShowDialog() != DialogResult.OK)
-                {
-                    // user canceled loading
-                    logger.Info("Load: user canceled loading.");
-                    return false;
-                }
-                a_strPathname = FileDialog.SelectedPath;
-            }
-
-            // get path of the pathname
-            String strFilePath =a_strPathname;
-         
-
-            // field file sub folder string
-            m_strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
-            
-            // check if the field file sub folder exists
-            if (!Exists(m_strFieldFileSubFolder))
-            {
-                // field files folder doesn't exist
-
-                return false;
-            }
-
-
-            // file version
-            String strFileVersion = m_strFileVersion;
-            uint nFileVersion = GetVersionFromString(strFileVersion);
-            if (nFileVersion == 0)
-            {// invalid file
-
-                return false;
-            }
-            // sample measure result file
-          
-            SetPathFileName(a_strPathname);
-            this.LoadFieldDataFromDB(a_strPathname);
-            // ok, return TRUE
-            return true;
-        }
-
-        // Get file versio
-        // File Version should be format <Major version>.<Minor version>.<Build version>, like 1.2.3
-        public uint GetVersionFromString(string a_sVersion)
-        {
-            int nMajorVersion = 0;
-            int nMinorVersion = 0;
-            int nBuildVersion = 0;
-
-            uint nVersion = 0;
-            if (GetMajorVersionFromString(a_sVersion, nMajorVersion) &&
-                GetMinorVersionFromString(a_sVersion, nMinorVersion) &&
-                GetBuildVersionFromString(a_sVersion, nBuildVersion))
-            {
-                nVersion = (uint)nMajorVersion * 10000 + (uint)nMinorVersion * 100 + (uint)nBuildVersion;
-            }
-
-            return nVersion;
-        }
-
-        public bool GetMinorVersionFromString(string a_sVersion, int a_nVersion)
-        {
-            // version string
-            String strVersion = a_sVersion;
-
-            // get major file version string position first
-            int nPosFirst = strVersion.IndexOf('.');
-            if (nPosFirst < 0)
-            {
-                // failed to find major file version string
-
-                return false;
-            }
-
-            // get minor file version string position           
-            int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
-            int nStrLength = nPosSecond - nPosFirst - 1;
-            if (nStrLength <= 0)
-            {
-                // failed to find minor file version string
-
-                return false;
-            }
-
-            // get minor file version string
-            String strMinorVersion = strVersion.Remove(nPosFirst + 1, nStrLength);
-
-
-            // the minor file version string can't be empty
-            strMinorVersion.Trim();
-            if (strMinorVersion == "")
-            {
-                // failed to find minor file version string
-
-                return false;
-            }
-
-            // convert the minor version string to minor version number
-            if (!StringToInt(strMinorVersion, a_nVersion))
-            {
-                // failed to convert the major file version string to number
-
-                return false;
-            }
-
-            // ok, return TRUE
-            return true;
-        }
-
-        public bool GetMajorVersionFromString(string a_sVersion, int a_nVersion)
-        {
-            // version string
-            String strVersion = a_sVersion;
-
-            // get major file version string position
-            int nPosFirst = strVersion.IndexOf('.');
-            if (nPosFirst <= 0)
-            {
-                // failed to find major file version
-
-                return false;
-            }
-
-            // get major file version string
-            String strMajorVersion = strVersion.PadLeft(nPosFirst);
-
-            // the major file version string can't be empty
-            strMajorVersion.Trim();
-            if (strMajorVersion == "")
-            {
-                // failed to find major file version
-
-                return false;
-            }
-
-            // convert the major version string to major version number
-            if (!StringToInt(strMajorVersion, a_nVersion))
-            {
-                // failed to convert the major file version string to number
-
-                return false;
-            }
-
-            // ok, return TRUE
-            return true;
-        }
-
-        public bool GetBuildVersionFromString(string a_sVersion, int a_nBuild)
-        {
-            // version string
-            String strVersion = a_sVersion;
-
-            // get major file version string position first          
-            int nPosFirst = strVersion.IndexOf('.');
-            if (nPosFirst < 0)
-            {
-                // failed to find major file version string
-
-                return false;
-            }
-
-            // get minor file version string position          
-            int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
-
-            if (nPosSecond < 0)
-            {
-                // failed to find minor file version string
-
-                return false;
-            }
-
-            // get build string position
-            int nStrLength = strVersion.Length - nPosSecond - 1;
-            if (nStrLength <= 0)
-            {
-                // failed to find build string
-
-                return false;
-            }
-
-            // get build string
-            String strBuild = strVersion.PadRight(nStrLength);
-
-            // build string can't be empty
-            strBuild.Trim();
-            if (strBuild == "")
-            {
-                // failed to convert the build string to number
-
-                return false;
-            }
-
-            // convert the build string to build number
-            if (!StringToInt(strBuild, a_nBuild))
-            {
-                // failed to convert the build string to number
-
-                return false;
-            }
-
-            // ok, return TRUE
-            return true;
-        }
-
-        // Strings to int.
-        public bool StringToInt(string a_sValue, int a_nValue)
-        {
-            if (!IsDigitString(a_sValue))
-            {
-
-                return false;
-            }
-
-            a_nValue = Convert.ToInt32(a_sValue);
-
-            return true;
-        }
-
-        // Determines whether is digit string.
-        public bool IsDigitString(string a_sValue)
-        {
-            String strInt = a_sValue;
-            strInt.Trim();
-
-            if (strInt == "")
-            {
-
-                return false;
-            }
-
-            int nStart = 0;
-
-            if (strInt[nStart] == '-')
-            {
-                ++nStart;
-            }
-
-            // cycle through string and check each character if it is a digit
-            for (; nStart < strInt.Length; ++nStart)
-            {
-                if (strInt[nStart] != '-')
-                {
-
-                    return false;
-                }
-            }
-
-            return true;
-        }
-
-
-
-        // gets the name of the folder
-        static String GetFolderName(String a_strPathName)
-        {
-        
-       string str=   FileHelper.GetFolderName(a_strPathName);
-            return str.ToString();
-        }
-
-        private bool LoadFieldDataFromDB(string a_strPathname)
-        {
-            // check the pathname string
-            a_strPathname.Trim();
-            if (a_strPathname == null)
-            {
-                // open
-                FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框
-                if (FileDialog.ShowDialog() != DialogResult.OK)
-                {
-                    // user canceled loading
-                    logger.Info("Load: user canceled loading.");
-                    return false;
-                }
-                a_strPathname = FileDialog.SelectedPath;
-            }
-            // get path of the pathname
-      
-            string strFilePath = GetFolderName(a_strPathname);
-            if (strFilePath == null)
-            {
-                // file path string is an empty string 
-                logger.Info("Load: file path string is an empty string.");
-                return false;
-            }
-            // field file sub folder string
-          
-            string strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
-            // check if the field file sub folder exists
        
-            if (!Exists(strFieldFileSubFolder))
-            {// field files folder doesn't exist
-                logger.Info("Load: field files folder doesn't exist (%s).");
-                return false;
-            }
-
-            string strIncAFilename = strFieldFileSubFolder + "\\" +DBFILE_NAME;
-            CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
-            List<COTSField> allFlds;
-            allFlds = null;
-            CMsrSampleStatus poMsrStatus = m_pSample.GetMsrStatus();
-            CMsrResultItems poMsrResults = m_pSample.GetMsrResults();
-            double aFldArea = m_pSample.CalculateAFieldArea();
-            if (GetAllFieldsFromDB(allFlds, poMsrStatus, poMsrResults, aFldArea))
-            {
-                SetFieldData(allFlds);
-              
-                return true;
-            }
-            else
-            {
-                return false;
-            }
-        }
-
-        public bool GetAllFieldsFromDB(List<COTSField> allFlds, CMsrSampleStatus status, CMsrResultItems rst, double aFieldArea)
-        {
-            
-            List<System.Drawing.PointF> completedfld = new List<System.Drawing.PointF>();
-         
-
-           m_DBFileMgr.GetIncADB().GetAllFieldsRecord(ref allFlds);
-            var SegmentDB = m_DBFileMgr.GetSegmentDB();
-            double msrFldsArea = 0;
-
-        
-            Dictionary<int, List<COTSParticleClr>> mapTypeParticles = new Dictionary<int, List<COTSParticleClr>>();
-            
-            Dictionary<string, List<COTSSegmentClr>> AllSegments = new Dictionary<string, List<COTSSegmentClr>>();
-            if (SegmentDB.GetAllSegmentsRecord(AllSegments))
-            {
-                //int nCol;
-                foreach (var fld in allFlds)
-
-                {
-                    int fldId = fld.GetId();
-                    List<COTSParticleClr> parts = fld.GetListAnalysisParticles();
-                    List<COTSSegmentClr> cOTSSegment = new List<COTSSegmentClr>();
-                    foreach (var part in parts)
-
-                    {
-                      
-
-                        var itr = AllSegments.Values;
-
-                        if (itr != AllSegments.Values)
-                        {
-                            COTSFeatureClr f = new COTSFeatureClr();
-                            f.SetSegmentsList(cOTSSegment, true);
-                            part.SetFeature(f);
-                        }
-                        mapTypeParticles[part.GetClassifyId()].Add(part);
-                    }
-                    completedfld.Add(fld.GetOTSPosition());
-                    msrFldsArea += aFieldArea;
-                }
-            }
-            // get MsrStatus info from DB.
-           
-            String strTimeStart = "";
-            String strTimeEnd = "";
-            String strRstStatus = "";
-            var m_GenInfoDB = m_DBFileMgr.GetGeneralInfoDB();
-            m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeStart(), ref strTimeStart);
-            m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeEnd(),ref strTimeEnd);
-            m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameResultStatus(),ref strRstStatus);
-            status.SetCompletedFieldsCenter(completedfld);
-          
-            DateTime timeStart, timeEnd;
-          
-            timeStart = Convert.ToDateTime(strTimeStart);
-            timeEnd = Convert.ToDateTime(strTimeEnd);
-            status.SetStartTime(timeStart);
-            status.SetEndTime(timeEnd);
-            status.SetUsedTime(timeEnd - timeStart);
-            status.SetStatus((OTS_MSR_SAMPLE_STATUS)Convert.ToInt32(strRstStatus));
-            //get MsrResults data from map.
-            List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
-            double allPartArea = 0;
-            foreach (var typeParticles in mapTypeParticles)
-            {
-                CMsrResultItem rstItm = new CMsrResultItem();
-                int typeNum = 0;
-                double typeArea = 0;
-                foreach (var p in mapTypeParticles)
-                {
-                    typeNum += 1;
-                    typeArea += Convert.ToInt32(p);
-                }
-                rstItm.SetTypeId(Convert.ToInt32(typeParticles));
-                rstItm.SetNumber((uint)typeNum);
-                rstItm.SetArea((uint)typeArea);
-                rstItms.Add(rstItm);
-                allPartArea += typeArea;
-            }
-            rst.SetResultItems(rstItms);
-            rst.SetMeasuredArea((uint)msrFldsArea * 1000000);
-            rst.SetRatio(allPartArea / (msrFldsArea * 1000000));
-            return true;
-
-        }
-
-
-
 
         // Save 
         public bool CreateResultFiles()
@@ -741,69 +310,7 @@ namespace OTSModelSharp
             // return field file sub folder string
             return m_strFieldFileSubFolder;
         }
-        // sample measure result file
-  
-        // save a BSE file for a field
-        public bool SaveBSEFileForAField(COTSField a_pField)
-        {
-            if (a_pField == null)
-            {
-                logger.Info("SaveBSEFileForAField: invalid field data pointer.");
-                return false;
-            }
-         
-            string strBSEFilePathname = m_strSampleWorkingFolder + "\\" +SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
-            // save BSE file for the field
-            CBSEImgClr pBSEImage = a_pField.GetBSEImage();
-            CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
-            pBSEImgFileMgr.SetBSEImg(pBSEImage);
-            pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname);
-            // ok, return TRUE
-            return true;
-        }
-        // save a x-ray file for a field
-        public bool SaveXRayFileForAField(List<CPosXrayClr>  a_pFieldXray)
-        {
-    
-
-            string strIncAFilename = m_strDBFileFolder + "\\" + DBFILE_NAME;
-            // save x-ray file for the field
-            CPosXrayDBMgr pPosXrayDBMgr = new CIncAFileMgr(strIncAFilename).GetPosXrayDBMgr();
-
-   
-
-            List<CPosXrayClr> listAnalysisXray = a_pFieldXray;
-           
-            if (!pPosXrayDBMgr.SaveXray(listAnalysisXray,true))
-            {
-                logger.Info("SaveXRayFileForAField: save analysis x-ray failed.");
-                return false;
-            }
-            // ok, return TRUE
-            return true;
-        }
-  
-
-        public void SetFieldData(List<COTSField> a_listFieldData)
-        {
-
-            m_pSample.SetFieldsData(a_listFieldData);
-
-        }
        
-  
-        public string GetPathFileName()
-        {
-            return m_strRstFileName;
-        }
-        public string GetDBPathName()
-        {
-            return m_strdbPathName;
-        }
-        public void SetPathFileName(string PathName)
-        {
-            m_strRstFileName = PathName;
-        }
        
         public void SetSEMGnr(CSEMDataGnr a_pSEMGnr)
         {

+ 2 - 6
OTSIncAMeasureApp/1-OTSMeasure/Measure/BSEPicData/COTSField.cs

@@ -140,11 +140,7 @@ namespace OTSModelSharp
         {
             m_pixelSize = size;
         }
-        public COTSField()
-        {
-            log = NLog.LogManager.GetCurrentClassLogger();
-            Init();
-        }
+       
         // initialization
         void Init()
         {
@@ -198,7 +194,7 @@ namespace OTSModelSharp
                 return;
             CImageHandler imghandler = new CImageHandler();
             List<COTSParticleClr> xrayParts = new List<COTSParticleClr>();
-            imghandler.RemoveBGAndGetParts(this,m_pBSEImg, a_pImageProcessParam,a_pixelSize, ref xrayParts);
+            imghandler.RemoveBGAndGetParts(this, a_pImageProcessParam, ref xrayParts);
             foreach (var p in xrayParts)
             {
                 p.SetIsXrayParticle(ifXray);

+ 7 - 5
OTSIncAMeasureApp/1-OTSMeasure/Measure/DBDataTransition/IncADataDB.cs

@@ -101,7 +101,7 @@ namespace OTSModelSharp
             return new KeyValuePair<string, SQLiteParameter[]>(sInsertCmd.Key,paras);
         }
 
-        public bool GetAllFieldsRecord(ref List<COTSField> allFlds)
+        public bool GetAllFieldsRecord(Size fldsize, double pixelsize,ref List<COTSField> allFlds)
         {
             var allRecords = this.GetQueryOfAllRecord();
             
@@ -111,12 +111,14 @@ namespace OTSModelSharp
                 int curFldId = Convert.ToInt32(allRecords.Rows[i][(int)CIncADataTable.ColumnID.N_FIELD_ID]);  //GetColIntValue((int)CIncADataTable.ColumnID.N_FIELD_ID);
                 if (!mapFld.Keys.Contains(curFldId))
                 {
-                    COTSField fld = new COTSField();
-
-                    fld.SetId(Convert.ToInt32(allRecords.Rows[i][(int)CIncADataTable.ColumnID.N_FIELD_ID]));
-                    System.Drawing.Point fldPos =new System.Drawing.Point();
+                    System.Drawing.Point fldPos = new System.Drawing.Point();
                     fldPos.X = Convert.ToInt32(allRecords.Rows[i][(int)CIncADataTable.ColumnID.N_FldPosX]);
                     fldPos.Y = Convert.ToInt32(allRecords.Rows[i][(int)CIncADataTable.ColumnID.N_FldPosY]);
+
+                    COTSField fld = new COTSField(new PointF(fldPos.X,fldPos.Y),pixelsize);
+                    fld.Width = fldsize.Width;
+                    fld.Height = fldsize.Height;
+                    fld.SetId(Convert.ToInt32(allRecords.Rows[i][(int)CIncADataTable.ColumnID.N_FIELD_ID]));
                     fld.SetOTSPosition(fldPos);
                     List<COTSParticleClr> ps = fld.GetListAnalysisParticles();
                     COTSParticleClr p = new COTSParticleClr();

+ 78 - 78
OTSIncAMeasureApp/1-OTSMeasure/Measure/DBDataTransition/MergedParticles/MergeParticleDB.cs

@@ -90,91 +90,91 @@ namespace OTSModelSharp
 		return true;
 	}
 
-     public   bool GetAllFieldsRecord(ref List<COTSField> allFlds)
-        {
-            var allRecords = this.GetQueryOfAllRecord();
-            Dictionary<int,COTSField> mapFld = new Dictionary<int,COTSField>();
-            for (int i = 0; i < allRecords.Rows.Count; i++)
-            {
-                int curFldId = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FIELD_ID][0];             
+     //public   bool GetAllFieldsRecord(ref List<COTSField> allFlds)
+     //   {
+     //       var allRecords = this.GetQueryOfAllRecord();
+     //       Dictionary<int,COTSField> mapFld = new Dictionary<int,COTSField>();
+     //       for (int i = 0; i < allRecords.Rows.Count; i++)
+     //       {
+     //           int curFldId = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FIELD_ID][0];             
                 
-                if (!mapFld.Keys.Contains(curFldId))
-                {
-                   COTSField fld = new COTSField();
+     //           if (!mapFld.Keys.Contains(curFldId))
+     //           {
+     //              COTSField fld = new COTSField();
 
                    
-                    fld.SetId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FIELD_ID][0]);
-                    System.Drawing.Point fldPos = new System.Drawing.Point();
+     //               fld.SetId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FIELD_ID][0]);
+     //               System.Drawing.Point fldPos = new System.Drawing.Point();
                     
-                    fldPos.X = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FldPosX][0];
-                    fldPos.Y = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FldPosY][0];
-                    fld.SetOTSPosition(fldPos);
-                    List< COTSParticleClr> ps = fld.GetListAnalysisParticles();
-                    COTSParticleClr p = new COTSParticleClr();
+     //               fldPos.X = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FldPosX][0];
+     //               fldPos.Y = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FldPosY][0];
+     //               fld.SetOTSPosition(fldPos);
+     //               List< COTSParticleClr> ps = fld.GetListAnalysisParticles();
+     //               COTSParticleClr p = new COTSParticleClr();
                    
-                    p.SetParticleId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_PARTICLE_ID][0]);
-                    p.SetClassifyId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_INCA_ID][0]);
-                    int top = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_TOP][0];
-                    int left = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_LEFT][0];
-                    int width = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_WIDTH][0];
-                    int height = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_HEIGHT][0];
-
-                    Rectangle r = new Rectangle(left, top, width,  height);
-                    p.SetParticleRect(r);
+     //               p.SetParticleId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_PARTICLE_ID][0]);
+     //               p.SetClassifyId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_INCA_ID][0]);
+     //               int top = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_TOP][0];
+     //               int left = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_LEFT][0];
+     //               int width = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_WIDTH][0];
+     //               int height = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_HEIGHT][0];
+
+     //               Rectangle r = new Rectangle(left, top, width,  height);
+     //               p.SetParticleRect(r);
                    
-                    p.SetAveGray(Convert.ToByte(allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_AVE_GRAY][0]));
-                    p.SetActualArea((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_AREA][0]);
-                    p.SetAnalysisId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_XRAY_ID][0]);
-                    //p.SetDMax((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMAX][0]);
-                    //p.SetDMin((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMIN][0]);
-                    //p.SetDPerp((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DPERP][0]);
-                    //p.SetDInscr((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DINSCR][0]);
-                    //p.SetDMean((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMEAN][0]);
-                    //p.SetDElong((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DELONG][0]);
-                    //p.SetPerimeter((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_PERIMETER][0]);
-                    //p.SetOrientation((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_ORIENTATION][0]);
-                    //p.TypeName(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_NAME][0].ToString());
-                    //p.TypeColor(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_COLOR][0].ToString());
-                    ps.Add(p);
-                    allFlds.Add(fld);
-                    mapFld[curFldId] = fld;
-                }
-                else
-                {
-                   COTSField  fld = mapFld[curFldId];
-                    List< COTSParticleClr>  ps = fld.GetListAnalysisParticles();
-                    COTSParticleClr p = new COTSParticleClr();
-                    p.SetFieldId(fld.GetId());
-
-                    p.SetParticleId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_PARTICLE_ID][0]);
-                    p.SetClassifyId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_INCA_ID][0]);
-                    int top = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_TOP][0];
-                    int left = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_LEFT][0];
-                    int width = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_WIDTH][0];
-                    int height = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_HEIGHT][0];
-                    Rectangle r = new Rectangle(left, top,  width,  height);
-                    p.SetParticleRect(r);
+     //               p.SetAveGray(Convert.ToByte(allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_AVE_GRAY][0]));
+     //               p.SetActualArea((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_AREA][0]);
+     //               p.SetAnalysisId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_XRAY_ID][0]);
+     //               //p.SetDMax((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMAX][0]);
+     //               //p.SetDMin((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMIN][0]);
+     //               //p.SetDPerp((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DPERP][0]);
+     //               //p.SetDInscr((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DINSCR][0]);
+     //               //p.SetDMean((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMEAN][0]);
+     //               //p.SetDElong((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DELONG][0]);
+     //               //p.SetPerimeter((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_PERIMETER][0]);
+     //               //p.SetOrientation((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_ORIENTATION][0]);
+     //               //p.TypeName(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_NAME][0].ToString());
+     //               //p.TypeColor(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_COLOR][0].ToString());
+     //               ps.Add(p);
+     //               allFlds.Add(fld);
+     //               mapFld[curFldId] = fld;
+     //           }
+     //           else
+     //           {
+     //              COTSField  fld = mapFld[curFldId];
+     //               List< COTSParticleClr>  ps = fld.GetListAnalysisParticles();
+     //               COTSParticleClr p = new COTSParticleClr();
+     //               p.SetFieldId(fld.GetId());
+
+     //               p.SetParticleId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_PARTICLE_ID][0]);
+     //               p.SetClassifyId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_INCA_ID][0]);
+     //               int top = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_TOP][0];
+     //               int left = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_LEFT][0];
+     //               int width = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_WIDTH][0];
+     //               int height = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_HEIGHT][0];
+     //               Rectangle r = new Rectangle(left, top,  width,  height);
+     //               p.SetParticleRect(r);
                    
-                    p.SetAveGray(Convert.ToByte(allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_AVE_GRAY][0]));
-                    p.SetActualArea((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_AREA][0]);
-                    p.SetAnalysisId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_XRAY_ID][0]);
-                    //p.SetDMax((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMAX][0]);
-                    //p.SetDMin((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMIN][0]);
-                    //p.SetDPerp((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DPERP][0]);
-                    //p.SetDInscr((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DINSCR][0]);
-                    //p.SetDMean((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMEAN][0]);
-                    //p.SetDElong((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DELONG][0]);
-                    //p.SetPerimeter((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_PERIMETER][0]);
-                    //p.SetOrientation((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_ORIENTATION][0]);
-                    //p.TypeName(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_NAME][0].ToString());
-                    //p.TypeColor(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_COLOR][0].ToString());
-                    ps.Add(p);
-                }
-                allRecords.NewRow();
-            };
-            allRecords.Clear();
-            return true;
-        }
+     //               p.SetAveGray(Convert.ToByte(allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_AVE_GRAY][0]));
+     //               p.SetActualArea((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_AREA][0]);
+     //               p.SetAnalysisId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_XRAY_ID][0]);
+     //               //p.SetDMax((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMAX][0]);
+     //               //p.SetDMin((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMIN][0]);
+     //               //p.SetDPerp((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DPERP][0]);
+     //               //p.SetDInscr((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DINSCR][0]);
+     //               //p.SetDMean((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMEAN][0]);
+     //               //p.SetDElong((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DELONG][0]);
+     //               //p.SetPerimeter((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_PERIMETER][0]);
+     //               //p.SetOrientation((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_ORIENTATION][0]);
+     //               //p.TypeName(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_NAME][0].ToString());
+     //               //p.TypeColor(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_COLOR][0].ToString());
+     //               ps.Add(p);
+     //           }
+     //           allRecords.NewRow();
+     //       };
+     //       allRecords.Clear();
+     //       return true;
+     //   }
 
       public   DataTable GetQueryOfAllRecord()
         {

+ 9 - 10
OTSIncAMeasureApp/1-OTSMeasure/Measure/ParamData/COTSMsrPrjResultData.cs

@@ -1,7 +1,6 @@
 using OTSDataType;
 using OTSModelSharp.ServiceCenter;
-using OTSModelSharp.DTLBase;
-using OTSModelSharp.ImageProcess;
+
 using System;
 using System.Collections.Generic;
 using System.Drawing;
@@ -289,16 +288,16 @@ namespace OTSModelSharp
             CIncAFileMgr incAFileMgr = new CIncAFileMgr(sDatabaseName);
             var m_IncADataDB = incAFileMgr.GetIncADB();
             List<COTSField> allFldsWithdata=new List<COTSField>();
-            m_IncADataDB.GetAllFieldsRecord(ref allFldsWithdata);
+            m_IncADataDB.GetAllFieldsRecord(new Size(picSize.Width,picSize.Height),pixelSize,ref allFldsWithdata);
 
 
-            foreach (var f in allFldsWithdata)
-            {
-                f.Width = picSize.Width;
-                f.Height = picSize.Height;
-                f.SetPixelSize(pixelSize);
+            //foreach (var f in allFldsWithdata)
+            //{
+            //    f.Width = picSize.Width;
+            //    f.Height = picSize.Height;
+            //    f.SetPixelSize(pixelSize);
             
-            }
+            //}
 
             var eleChemistryDB = incAFileMgr.GetPosXrayDBMgr().GetElementChemistryDB();
              Dictionary<string, CPosXrayClr> mapXrayInfo=new Dictionary<string, CPosXrayClr>();
@@ -419,7 +418,7 @@ namespace OTSModelSharp
             foreach (var p in completedFldPositions)
             {
                 bool haveData=false;
-                var emptyFld = new COTSField();
+                var emptyFld = new COTSField(p,pixelSize);
                 emptyFld.SetOTSPosition(p);
                 foreach (var fld in allFldsWithdata)
                 {

+ 11 - 11
OTSIncAMeasureApp/4-OTSSamplespaceGraphicsPanel/CFieldPositionMgr.cs

@@ -23,7 +23,7 @@ namespace OTSModelSharp
         CDomain m_pMeasureArea;
 
         // measured field centre points list
-        List<System.Drawing.Point> m_listMeasuredFieldCentrePoints;
+        //List<System.Drawing.Point> m_listMeasuredFieldCentrePoints;
 
         // image scan parameter
         COTSImgScanPrm  m_poImageScanParam;
@@ -67,9 +67,9 @@ namespace OTSModelSharp
             CDomain domainclr = new CDomain(a_pMeasureArea.GetShape(),a_pMeasureArea.GetRectDomain());
             domainclr.SetPolygonPoint(a_pMeasureArea.GetPolygonPoint());
             
-            System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
            
-            fieldmgrclr.Init(domainclr.GetClrDomainObj(), sizePixelImage,scanfieldsize, (int)m_poImageScanParam.GetFieldStartMode());
+           
+            fieldmgrclr.Init(domainclr.GetClrDomainObj(),  (int)m_poImageScanParam.GetFieldStartMode());
             fieldmgrclr.SetOverlap(overlap);
  
             List<System.Drawing.Point> fieldpoints = new List<System.Drawing.Point>();
@@ -118,10 +118,10 @@ namespace OTSModelSharp
             System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
             // scan field size (x, y)
             System.Drawing.Size sizeImage = new System.Drawing.Size();
-            
-            sizeImage.Width = m_poSEMDataMsr.GetScanFieldSize() - overLap;
-             
-            sizeImage.Height = m_poSEMDataMsr.GetScanFieldSize() * sizePixelImage.Height/ sizePixelImage.Width-overLap;
+
+            sizeImage.Width = fieldmgrclr.GetEffectiveFieldWidth();
+
+            sizeImage.Height = fieldmgrclr.GetEffectiveFieldHeight();
             // get left top
             System.Drawing.Point ptcenter = m_listFieldCentrePoints[a_nIndex];
             Point ptLt = new Point(ptcenter.X - sizeImage.Width / 2, ptcenter.Y + sizeImage.Height / 2);
@@ -153,7 +153,7 @@ namespace OTSModelSharp
             PointF curPos = currentfld.GetOTSPosition();
             Point curFld = new Point((int)curPos.X, (int)curPos.Y);
             Point neighbor = new Point();
-            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld, neighbor, (int)SORTING_DIRECTION.LEFT))
+            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld, ref neighbor, (int)SORTING_DIRECTION.LEFT))
             {
                 if (allflds[neighbor].GetMeasureSequence() < currentfld.GetMeasureSequence())
                 {
@@ -161,21 +161,21 @@ namespace OTSModelSharp
                 }
                 
             }
-            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld, neighbor, (int)SORTING_DIRECTION.RIGHT))
+            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld,ref neighbor, (int)SORTING_DIRECTION.RIGHT))
             {
                 if (allflds[neighbor].GetMeasureSequence() < currentfld.GetMeasureSequence())
                 {
                     currentfld.SetRightBorderParticlesBiasDefine(false);
                 }
             }
-            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld, neighbor, (int)SORTING_DIRECTION.UP))
+            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld, ref neighbor, (int)SORTING_DIRECTION.UP))
             {
                 if (allflds[neighbor].GetMeasureSequence() < currentfld.GetMeasureSequence())
                 {
                     currentfld.SetUpBorderParticlesBiasDefine(false);
                 }
             }
-            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld, neighbor, (int)SORTING_DIRECTION.DOWN))
+            if (fieldmgrclr.FindNeighborField(allFldPoints, curFld,ref neighbor, (int)SORTING_DIRECTION.DOWN))
             {
                 if (allflds[neighbor].GetMeasureSequence() < currentfld.GetMeasureSequence())
                 {

+ 1 - 7
OTSIncAMeasureApp/5-OTSMeasureStatuImageFun/OTSMeasureStatusWindow.cs

@@ -446,10 +446,7 @@ namespace OTSMeasureApp
         }
         #endregion
 
-        //更新当前的图
-        #region 更新当前的图
       
-        #endregion
         //显示去背景图 = AUTO
         #region 显示去背景图
         private void ShowRemoveBGImage_Click(object sender, EventArgs e)
@@ -539,9 +536,6 @@ namespace OTSMeasureApp
               
                 removeBGBseData = pImgNoBG.GetImageDataPtr();
 
-      
-
-
             //获取去背景灰度图数据
             dGrayAbandonLevelData = new double[(int)GrayLevel.Max];
             dGrayAbandonLevelData = GetGrayAbandonData(removeBGBseData, dGrayAbandonLevelData);
@@ -1918,7 +1912,7 @@ namespace OTSMeasureApp
                 grayStart = toolWindow.BseGrayMinValue;
                 grayEnd = toolWindow.BseGrayMaxValue;
                 //设置去背景参数
-                COTSImageProcParam cOTSImgProc = new COTSImageProcParam();
+                COTSImageProcParam cOTSImgProc ;
                 cOTSImgProc = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().GetImageProcessParam();
                 CIntRange cIntRange = new CIntRange();
                 cIntRange.SetStart(grayStart);

+ 21 - 9
OTSIncAMeasureApp/ServiceCenter/CImageHandler.cs

@@ -221,8 +221,9 @@ namespace OTSModelSharp.ServiceCenter
             List<COTSParticleClr> parts = new List<COTSParticleClr>();
             List<COTSParticleClr> specialGreyparts = new List<COTSParticleClr>();
             var ecdrange = a_pImgProcessParam.GetIncAreaRange();
-            var tempFld = new COTSField();
-            if (!RemoveBGAndGetParts(tempFld,a_pImgIn, a_pImgProcessParam, a_pixelSize, ref parts))
+            var tempFld = new COTSField(new PointF(0,0),a_pixelSize);
+            tempFld.SetBSEImage(a_pImgIn);
+            if (!RemoveBGAndGetParts(tempFld, a_pImgProcessParam, ref parts))
             {
                 return;
             }
@@ -301,8 +302,9 @@ namespace OTSModelSharp.ServiceCenter
             List<COTSParticleClr> parts = new List<COTSParticleClr>();
             List<COTSParticleClr> specialGreyparts = new List<COTSParticleClr>();
             var ecdrange = a_pImgProcessParam.GetIncAreaRange();
-            var tempFld = new COTSField();
-            if (!RemoveBGAndGetParts(tempFld,a_pImgIn, a_pImgProcessParam, a_pixelSize, ref parts))
+            var tempFld = new COTSField(new PointF(0,0),a_pixelSize);
+            tempFld.SetBSEImage(a_pImgIn);
+            if (!RemoveBGAndGetParts(tempFld, a_pImgProcessParam,  ref parts))
             {
                 return;
             }
@@ -335,6 +337,7 @@ namespace OTSModelSharp.ServiceCenter
                 {
                     a_pBmpOut.SetPixel(i, j, Color.White);
                 }
+               
             }
             Random c = new Random();
             if (specialGreyparts.Count > 0)
@@ -405,6 +408,15 @@ namespace OTSModelSharp.ServiceCenter
 
 
             }
+            Graphics graphics = Graphics.FromImage(a_pBmpOut);
+
+            // 绘制一个红色矩形
+            Pen pen = new Pen(Color.Red, 1);
+            var overlap=a_pImgProcessParam.GetOverlapParam();
+            int overlapPixels =(int) (overlap / a_pixelSize);
+            graphics.DrawRectangle(pen, overlapPixels, overlapPixels, a_pBmpOut.Width-2*overlapPixels, a_pBmpOut.Height - 2 * overlapPixels);
+
+
 
             return;
         }
@@ -530,9 +542,9 @@ namespace OTSModelSharp.ServiceCenter
       
 
 
-        public bool RemoveBGAndGetParts(COTSField currentField,CBSEImgClr img, COTSImageProcParam a_pImgProcessParam,double a_pixelSize,ref List<COTSParticleClr> parts)
+        public bool RemoveBGAndGetParts(COTSField currentField, COTSImageProcParam a_pImgProcessParam,ref List<COTSParticleClr> parts)
         {
-
+           var a_pixelSize = currentField.GetPixelSize();
             COTSImgProcPrmClr prm = GetImageProcPrmClr(a_pImgProcessParam);
             COTSFieldDataClr flddataclr = new COTSFieldDataClr();
             PointF fldpos = currentField.GetOTSPosition();
@@ -540,15 +552,15 @@ namespace OTSModelSharp.ServiceCenter
             flddataclr.SetImageWidth(currentField.Width);
             flddataclr.SetImageHeight(currentField.Height);
             double left = fldpos.X - currentField.Width * a_pixelSize / 2;
-            double top = fldpos.Y - currentField.Height * a_pixelSize / 2;
+            double top = fldpos.Y + currentField.Height * a_pixelSize / 2;
             double right = fldpos.X + currentField.Width * a_pixelSize / 2;
-            double bottom = fldpos.Y + currentField.Height * a_pixelSize / 2;
+            double bottom = fldpos.Y - currentField.Height * a_pixelSize / 2;
             flddataclr.SetOTSRect(left, top, right, bottom);
             flddataclr.SetLeftBorderParticlesBiasDefine(currentField.GetLeftBorderParticlesBiasDefine());
             flddataclr.SetRightBorderParticlesBiasDefine(currentField.GetRightBorderParticlesBiasDefine());
             flddataclr.SetUpBorderParticlesBiasDefine(currentField.GetUpBorderParticlesBiasDefine());
             flddataclr.SetDownBorderParticlesBiasDefine(currentField.GetDownBorderParticlesBiasDefine());
-            if (!imgProEngine.GetFieldDataFromImage(img, prm, a_pixelSize, flddataclr))
+            if (!imgProEngine.GetFieldDataFromImage(currentField.GetBSEImage(), prm, a_pixelSize, flddataclr))
             {
                 return false;
             }