www.pudn.com > DataCollectionSystem.rar > modProcess.bas, change:2003-08-12,size:6530b


Attribute VB_Name = "modProcess" 
 
'PtNumber一测回的点数, MeasTime取几次的平均, x(),y(),z()输出的处理过MeasTime的平均值, XImport,YImport,ZImport 输入的MeasTime次PtNumber点的坐标值 
Public Function DataCheck(ByVal PtNumber As Integer, ByVal MeasTime As Integer, x() As Double, y() As Double, z() As Double, XImport() As Double, YImport() As Double, ZImport() As Double, Explain() As Integer) As Boolean 
Dim Xaverage(100) As Double, Yaverage(100) As Double, Zaverage(100) As Double 
Dim i As Integer, j As Integer, TrueNumber As Integer, TrueNumberMin As Integer 
Dim sumx As Double, sumy As Double, sumz As Double 
Dim RoX(100) As Double, RoY(100) As Double, RoZ(100) As Double 
Dim MeasTimeReal As Integer 
TrueNumber = 0 
TrueNumberMin = 10000 
MeasTimeReal = MeasTime 
 
 
For i = 1 To PtNumber 
    MeasTimeReal = MeasTime 
    For j = 1 To MeasTime 
        If Explain(i + (j - 1) * PtNumber) = 4 Then 
            MeasTimeReal = MeasTimeReal - 1 
            If MeasTimeReal = 0 Then 
                Xaverage(i) = 0 
                Yaverage(i) = 0 
                Zaverage(i) = 0 
                GoTo tang3 
            End If 
            GoTo tang 
        End If 
        Xaverage(i) = Xaverage(i) + XImport(i + (j - 1) * PtNumber) 
        Yaverage(i) = Yaverage(i) + YImport(i + (j - 1) * PtNumber) 
        Zaverage(i) = Zaverage(i) + ZImport(i + (j - 1) * PtNumber) 
tang: 
    Next j 
    Xaverage(i) = Xaverage(i) / MeasTimeReal 
    Yaverage(i) = Yaverage(i) / MeasTimeReal 
    Zaverage(i) = Zaverage(i) / MeasTimeReal 
tang3: 
Next i 
 
 
For i = 1 To PtNumber 
    MeasTimeReal = MeasTime 
    For j = 1 To MeasTime 
        If Explain(i + (j - 1) * PtNumber) = 4 Then 
            MeasTimeReal = MeasTimeReal - 1 
            If MeasTimeReal = 0 Then 
                RoX(i) = 0: RoY(i) = 0: RoZ(i) = 0 
                GoTo tang4 
            End If 
            GoTo tang1 
        End If 
        sumx = sumx + (XImport(i + (j - 1) * PtNumber) - Xaverage(i)) ^ 2 
        sumy = sumy + (YImport(i + (j - 1) * PtNumber) - Yaverage(i)) ^ 2 
        sumz = sumz + (ZImport(i + (j - 1) * PtNumber) - Zaverage(i)) ^ 2 
tang1: 
    Next j 
    RoX(i) = Sqr(sumx / MeasTimeReal) 
    RoY(i) = Sqr(sumy / MeasTimeReal) 
    RoZ(i) = Sqr(sumz / MeasTimeReal) 
    sumx = 0: sumy = 0: sumz = 0 
tang4: 
Next i 
 
 
 
For i = 1 To PtNumber 
    TrueNumber = 0 
    MeasTimeReal = MeasTime 
    For j = 1 To MeasTime 
        If Explain(i + (j - 1) * PtNumber) = 4 Then 
            MeasTimeReal = MeasTimeReal - 1 
            If MeasTimeReal = 0 Then 
                x(i) = 0: y(i) = 0: z(i) = 0 
                GoTo tang5 
            End If 
            GoTo tang2 
        End If 
        If Abs((XImport(i + (j - 1) * PtNumber) - Xaverage(i))) < 2 * RoX(i) And Abs((YImport(i + (j - 1) * PtNumber) - Yaverage(i))) < 2 * RoY(i) And Abs((ZImport(i + (j - 1) * PtNumber) - Zaverage(i))) < 2 * RoZ(i) Then 
            TrueNumber = TrueNumber + 1 
            x(i) = x(i) + XImport(i + (j - 1) * PtNumber) 
            y(i) = y(i) + YImport(i + (j - 1) * PtNumber) 
            z(i) = z(i) + ZImport(i + (j - 1) * PtNumber) 
        End If 
tang2: 
    Next j 
    If (TrueNumber <> 0) Then 
        x(i) = x(i) / TrueNumber 
        y(i) = y(i) / TrueNumber 
        z(i) = z(i) / TrueNumber 
    Else 
        x(i) = 0 
        y(i) = 0 
        z(i) = 0 
    End If 
     
    If TrueNumber < TrueNumberMin Then 
        TrueNumberMin = TrueNumber 
    End If 
tang5: 
Next i 
 
If TrueNumberMin <= MeasTime / 3 Then 
    DataCheck = False 
Else 
 
    DataCheck = True 
End If 
 
End Function 
 
Public Function Process(pNumber As Integer, pCycle As Integer, xOut() As Double, yOut() As Double, zOut() As Double, xIn() As Double, yIn() As Double, zIn() As Double, pSm() As Integer) 
Dim yitax(100) As Double, yitay(100) As Double, yitaz(100) As Double 
Dim M As Integer, N As Integer 
Dim times(100) As Integer, pAverage(100) As Integer 
Dim x(600) As Double, y(600) As Double, z(600) As Double 
Dim sumx(100) As Double, sumy(100) As Double, sumz(100) As Double 
Dim avgx(100) As Double, avgy(100) As Double, avgz(100) As Double 
Dim sumDeltax(100) As Double, sumDeltay(100) As Double, sumDeltaz(100) As Double 
Dim deltax(600) As Double, deltay(600) As Double, deltaz(600) As Double 
 
For M = 1 To pNumber * pCycle 
    x(M) = xIn(M) 
    y(M) = yIn(M) 
    z(M) = zIn(M) 
Next M 
 
For M = 0 To (pNumber - 1) 
    pAverage(M) = pCycle 
Next M 
 
For M = 0 To (pCycle - 1) 
   For N = 1 To pNumber 
      If pSm(M) <> 4 Then 
         sumx(N - 1) = sumx(N - 1) + x(M * pNumber + N) 
         sumy(N - 1) = sumy(N - 1) + y(M * pNumber + N) 
         sumz(N - 1) = sumz(N - 1) + z(M * pNumber + N) 
      Else 
'         sumx(N - 1) = sumx(N - 1) 
'         sumy(N - 1) = sumy(N - 1) 
'         sumz(N - 1) = sumz(N - 1) 
         pAverage(M) = pAverage(M) - 1 
      End If 
  Next N 
Next M 
 
For M = 0 To (pNumber - 1) 
    avgx(M) = sumx(M) / pAverage(M) 
    avgy(M) = sumy(M) / pAverage(M) 
    avgz(M) = sumz(M) / pAverage(M) 
Next M 
 
For M = 1 To pNumber * pCycle 
    deltax(M - 1) = Abs(x(M) - avgx((M - 1) Mod pNumber)) 
    deltay(M - 1) = Abs(y(M) - avgy((M - 1) Mod pNumber)) 
    deltaz(M - 1) = Abs(z(M) - avgz((M - 1) Mod pNumber)) 
Next M 
 
For N = 0 To (pCycle - 1) 
For M = 0 To (pNumber - 1) 
    sumDeltax(M) = sumDeltax(M) + (deltax(N * pNumber + M) ^ 2) 
    sumDeltay(M) = sumDeltay(M) + (deltay(N * pNumber + M) ^ 2) 
    sumDeltaz(M) = sumDeltaz(M) + (deltaz(N * pNumber + M) ^ 2) 
Next M 
Next N 
 
For M = 0 To (pNumber - 1) 
    yitax(M) = Sqr(sumDeltax(M) / pCycle) 
    yitay(M) = Sqr(sumDeltay(M) / pCycle) 
    yitaz(M) = Sqr(sumDeltaz(M) / pCycle) 
Next M 
 
For M = 0 To (pNumber - 1) 
    times(M) = pCycle 
Next M 
 
For N = 0 To (pCycle - 1) 
   For M = 1 To (pNumber) 
      If deltax(N * pNumber + M - 1) > 2 * yitax(M - 1) Or deltay(N * pNumber + M - 1) > 2 * yitay(M - 1) Or deltaz(N * pNumber + M - 1) > 2 * yitaz(M - 1) Then 
         times(M - 1) = times(M - 1) - 1 
         sumx(M - 1) = sumx(M - 1) - xIn(N * pNumber + M) 
         sumy(M - 1) = sumy(M - 1) - yIn(N * pNumber + M) 
         sumz(M - 1) = sumz(M - 1) - zIn(N * pNumber + M) 
      End If 
   Next M 
Next N 
 
For M = 0 To (pNumber - 1) 
    If times(M) > 0 Then 
        xOut(M) = sumx(M) / times(M) 
        yOut(M) = sumy(M) / times(M) 
        zOut(M) = sumz(M) / times(M) 
    Else 
        xOut(M) = 0 
        yOut(M) = 0 
        zOut(M) = 0 
    End If 
Next M 
End Function