Jelajahi Sumber

add xray spectrum matching program in the report app.

gsp 3 minggu lalu
induk
melakukan
202e72f52b

+ 5 - 0
OTSCPP/OTSClrInterface/CommonClr/PosXrayClr.cpp

@@ -67,6 +67,11 @@ namespace OTSCLRINTERFACE {
 	}
 	
 
+	double CPosXrayClr::GetXrayDataVectorNorm()
+	{
+		return	m_PosXray->get()->GetXrayDataVectorNorm();
+	}
+
 	array<DWORD>^ CPosXrayClr::GetXrayData()
 	{
 		array<DWORD>^ XrayData;

+ 1 - 1
OTSCPP/OTSClrInterface/CommonClr/PosXrayClr.h

@@ -27,7 +27,7 @@ namespace OTSCLRINTERFACE {
 
 		// channels
 		long GetChannelsNum() { return m_PosXray->get()->GetChannelsNum (); }
-
+		double GetXrayDataVectorNorm();
 		// x-ray data
 		cli::array<DWORD>^ GetXrayData();
 	

+ 31 - 0
OTSIncAReportApp/1-UI/Control_Grids/ParticlesGridDevidePage/ParticlesGridDevidePage.cs

@@ -2,6 +2,7 @@
 using NPOI.SS.UserModel.Charts;
 using NPOI.SS.Util;
 using NPOI.XSSF.UserModel;
+using OTSCLRINTERFACE;
 using OTSCommon.DBOperate.Model;
 
 using OTSIncAReportApp;
@@ -2847,6 +2848,36 @@ namespace OTSIncAReportGrids
                 }
             }
         }
+         private  double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1)
+        {
+            if (posXray == null) return 0;
+            if (posXray1 == null) return 0;
+            if (posXray.GetChannelsNum() != posXray1.GetChannelsNum())
+            {
+                return 0;
+            }
+
+            var pXrayData = posXray.GetXrayData();
+            var pXrayData1 = posXray1.GetXrayData();
+
+
+            // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2))
+            double dotProduct = 0;
+            double d1 = 0;
+            double d2 = 0;
+            for (int i = 0; i < posXray.GetChannelsNum(); i++)
+            {
+                double r1 = pXrayData[i];
+                double r2 = pXrayData1[i];
+                r1 *= r2;
+                dotProduct = dotProduct + r1;
+
+            }
+            d1 = posXray.GetXrayDataVectorNorm();
+            d2 = posXray1.GetXrayDataVectorNorm();
+            return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2);
+
+        }
     }
 }