コード例 #1
0
        private List <StripDate[]> source; //for original datas

        /**The constructor
         * @param diameter the diameter of the pipeline, mm
         * .*/
        public StripDateService(double diameter)
        {
            double l = 3.1415926 * diameter;

            mergeUnit = (double)l * ConstParameter.AnglePreUnit / 360;  //distantce for 2°

            endRealPos = 0;
            maxPos     = l;

            lastIndex = 0;
            lastDate  = new StripDate(-1, -1);

            source = new List <StripDate[]>();

            int maxHeight = (int)(l / ConstParameter.DefaultPosInc * 1.2); //the max num of the array the stroge the datas

            maxNum = maxHeight / ConstParameter.BufferCapacity + 1;
            while (source.Count < maxNum)
            {
                StripDate[] arrays = new StripDate[ConstParameter.BufferCapacity];
                for (int i = 0; i < arrays.Length; i++)
                {
                    arrays[i] = new StripDate(-1, -1);
                }
                source.Add(arrays);
            }
        }
コード例 #2
0
        public void rebuildDates(ref List <StripDate> contain, ref int count, ref int listIndex, ref int arrayIndex, ref bool toEnd)
        {
            int maxNum = contain.Count;
            int index  = 0;

            while (index < maxNum)
            {
                listIndex += arrayIndex / ConstParameter.BufferCapacity;
                arrayIndex = arrayIndex % ConstParameter.BufferCapacity;

                StripDate[] curArray = source[listIndex];
                StripDate   date     = curArray[arrayIndex];
                if (date.isMaxInMerge && date.isAmpReceived && date.isTofReceived)
                {
                    StripDate tmp = contain[index++];
                    tmp.tof   = date.tof;
                    tmp.amp   = date.amp;
                    tmp.index = date.index;
                }
                arrayIndex++;

                if (endRealPos == date.realPos)
                {
                    toEnd = true;
                    break;
                }
            }
            count = index;
        }
コード例 #3
0
        public void clear()
        {
            lastIndex = 0;
            lastDate  = new StripDate(-1, -1);

            source = null;
            GC.Collect();

            source = new List <StripDate[]>();
            while (source.Count < maxNum)
            {
                StripDate[] arrays = new StripDate[ConstParameter.BufferCapacity];
                for (int i = 0; i < arrays.Length; i++)
                {
                    arrays[i] = new StripDate(-1, -1);
                }
                source.Add(arrays);
            }
        }
コード例 #4
0
        private void saveToTxt(String fileName)
        {
            StreamWriter writer  = new StreamWriter(fileName, false);
            bool         toEnd   = false;
            bool         isFirst = true;
            int          count   = 0;

            foreach (StripDate[] array in source)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    StripDate date = array[i];

                    if (date.isAmpReceived && date.isTofReceived)
                    {
                        if (isFirst)
                        {
                            writer.WriteLine(date.tof + " " + date.amp);
                            isFirst = false;
                        }
                        else
                        {
                            writer.WriteLine(" " + date.tof + " " + date.amp);
                        }
                        count++;
                    }

                    if (date.realPos == endRealPos)
                    {
                        toEnd = true;
                        break;
                    }
                }
                if (toEnd)
                {
                    break;
                }
            }
            writer.WriteLine(" " + count);
            writer.Flush();
            writer.Close();
        }
コード例 #5
0
        public void mergeDates(ref List <StripDate> contain, ref int num, GatePacket gatePacket)
        {
            num = 0;
            int    curPosX  = (int)(gatePacket.tag.stampPos[0] / 1000);
            int    inc      = (int)(gatePacket.tag.stampInc[0] / 1000);
            int    bin      = (int)gatePacket.head.bin;
            int    cellNum  = (int)gatePacket.tag.cellNum;
            int    numIndex = 0;
            double value;

            if (inc < 0)            //暂时解决方案,由于PosInc一直为负,DSP需解决
            {
                inc = inc * (-1);
            }

            if (bin == (int)DAQ_MEAS_MODE.TOF_PEAK)
            {
                for (int i = 0; i < cellNum && curPosX < maxPos; i++)
                {
                    value = gatePacket.measureDate[i];
                    //int tofIndex = (int)(curPosX / ConstParameter.DefaultPosInc) / ConstParameter.BufferCapacity;
                    //int arrayIndex = (int)(curPosX / ConstParameter.DefaultPosInc) % ConstParameter.BufferCapacity;
                    int tofIndex   = (int)(curPosX / inc) / ConstParameter.BufferCapacity;  //把DefaultPosInc改为inc
                    int arrayIndex = (int)(curPosX / inc) % ConstParameter.BufferCapacity;
                    while (source.Count <= tofIndex)
                    {
                        StripDate[] arrays = new StripDate[ConstParameter.BufferCapacity];
                        for (int j = 0; j < arrays.Length; j++)
                        {
                            arrays[j] = new StripDate(-1, -1);
                        }
                        source.Add(arrays);
                    }

                    StripDate[] curArray = source[tofIndex];
                    curArray[arrayIndex].tof           = value;
                    curArray[arrayIndex].isTofReceived = true;

                    if (curArray[arrayIndex].isAmpReceived && curArray[arrayIndex].isMaxInMerge)
                    {
                        StripDate date = contain[num++];
                        date.tof   = curArray[arrayIndex].tof;
                        date.amp   = curArray[arrayIndex].amp;
                        date.index = curArray[arrayIndex].index;
                    }

                    curPosX += inc;
                }
                endRealPos = Math.Max(endRealPos, curPosX - inc);
            }
            else if (bin == (int)DAQ_MEAS_MODE.AMP_PERCENT)
            {
                for (int i = 0; i < cellNum && curPosX < maxPos; i++)
                {
                    //add to the source
                    value = gatePacket.measureDate[numIndex++];

                    //int ampIndex = (int)(curPosX / ConstParameter.DefaultPosInc) / ConstParameter.BufferCapacity;
                    //int arrayIndex = (int)(curPosX / ConstParameter.DefaultPosInc) % ConstParameter.BufferCapacity;
                    int ampIndex   = (int)(curPosX / inc) / ConstParameter.BufferCapacity;  //把DefaultPosInc改为inc
                    int arrayIndex = (int)(curPosX / inc) % ConstParameter.BufferCapacity;
                    while (source.Count <= ampIndex)
                    {
                        StripDate[] arrays = new StripDate[ConstParameter.BufferCapacity];
                        for (int j = 0; j < arrays.Length; j++)
                        {
                            arrays[j] = new StripDate(-1, -1);
                        }
                        source.Add(arrays);
                    }

                    StripDate[] curArray = source[ampIndex];
                    curArray[arrayIndex].realPos       = curPosX;
                    curArray[arrayIndex].amp           = value;
                    curArray[arrayIndex].isAmpReceived = true;

                    //merge
                    //int index = (int)(curPosX / mergeUnit);
                    int index = (int)(curPosX / inc);   //把mergeUnit改为inc
                    curArray[arrayIndex].index = index;
                    if (arrayIndex == 64)
                    {
                        int dd = index;
                    }
                    if (index == lastIndex)
                    {
                        if (value > lastDate.amp)
                        {
                            lastDate.isMaxInMerge = false;
                            lastDate = curArray[arrayIndex];
                            lastDate.isMaxInMerge = true;
                        }
                    }
                    else
                    {
                        //is tof not arrive, just make a note
                        if (!lastDate.isTofReceived)
                        {
                            lastDate.index = lastIndex;
                        }

                        //arrive, just update
                        else
                        {
                            StripDate date = contain[num++];
                            date.tof     = lastDate.tof;
                            date.amp     = lastDate.amp;
                            date.index   = lastIndex;
                            date.realPos = lastDate.realPos;
                        }

                        lastIndex             = index;
                        lastDate              = curArray[arrayIndex];
                        lastDate.isMaxInMerge = true;
                    }

                    curPosX += (int)inc;
                }
                endRealPos = Math.Max(endRealPos, curPosX - (int)inc);
            }
        }