示例#1
0
        private C3DFile(Stream stream)
        {
            C3DReader reader = null;

            try
            {
                reader = new C3DReader(stream);

                this._processorType       = reader.CreateProcessorType;
                this._header              = reader.ReadHeader();
                this._parameterDictionary = reader.ReadParameters();
                this._frameCollection     = new C3DFrameCollection();

                try
                {
                    C3DParameterCache paramCache = C3DParameterCache.CreateCache(this);
                    C3DFrame          frame      = null;
                    while ((frame = reader.ReadNextFrame(paramCache)) != null)
                    {
                        this._frameCollection.Add(frame);
                    }
                }
                catch { }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
示例#2
0
 private C3DFile()
 {
     this._processorType       = C3DConstants.FILE_DEFAULT_PROCESSOR_TYPE;
     this._header              = new C3DHeader();
     this._parameterDictionary = C3DParameterDictionary.CreateNewParameterDictionary();
     this._frameCollection     = new C3DFrameCollection();
 }
示例#3
0
        /// <summary>
        /// 从已有参数组列表里创建C3D参数组字典
        /// </summary>
        /// <param name="groups">C3D参数组字典</param>
        /// <param name="parameters">C3D参数项字典</param>
        /// <returns>C3D参数组字典</returns>
        internal static C3DParameterDictionary CreateParameterDictionaryFromParameterList(IDictionary <Int32, C3DParameterGroup> groups, IDictionary <Int32, List <C3DParameter> > parameters)
        {
            C3DParameterDictionary dict = new C3DParameterDictionary();

            if (groups == null || groups.Count <= 0)
            {
                return(dict);
            }

            foreach (KeyValuePair <Int32, C3DParameterGroup> pair in groups)
            {
                C3DParameterGroup   group           = pair.Value;
                List <C3DParameter> groupParameters = null;

                if (group != null && group.ID < 0)
                {
                    if (parameters.TryGetValue(-group.ID, out groupParameters) && groupParameters != null)
                    {
                        for (Int32 i = 0; i < groupParameters.Count; i++)
                        {
                            group[groupParameters[i].Name] = groupParameters[i];
                        }
                    }

                    dict._paramGroups[-group.ID] = group;
                }
            }

            return(dict);
        }
示例#4
0
        private void WriteParameters(Byte firstParameterBlockIndex, C3DParameterDictionary dictionary)
        {
            Int32 startPosition = (firstParameterBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE;

            this._writer.Seek(startPosition, SeekOrigin.Begin);
            this._writer.Write(C3DConstants.FILEPARAMETER_FIRST_PARAM_BLOCK);
            this._writer.Write(C3DConstants.FILEPARAMETER_SIGNATURE);
            this._writer.Write((Byte)0);
            this._writer.Write((Byte)C3DConstants.FILE_DEFAULT_PROCESSOR_TYPE);

            foreach (C3DParameterGroup group in dictionary)
            {
                if (group.ID < 0)
                {
                    this.WriteParameter(null, group, false);

                    foreach (C3DParameter param in group)
                    {
                        this.WriteParameter(group, param, false);
                    }
                }
            }

            C3DParameterGroup lastGroup = new C3DParameterGroup(0, "", "");

            this.WriteParameter(null, lastGroup, true);

            this._newDataStartBlockIndex = (UInt16)((this._writer.BaseStream.Position + C3DConstants.FILE_SECTION_SIZE) / C3DConstants.FILE_SECTION_SIZE + 1);
            this._writer.Write(new Byte[(this._newDataStartBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE - this._writer.BaseStream.Position]);

            this._writer.Seek(startPosition + 2, SeekOrigin.Begin);
            this._writer.Write((Byte)(this._newDataStartBlockIndex - 2));
        }
示例#5
0
 private void LoadAnalogGeneralScale(C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("ANALOG", "GEN_SCALE"))
     {
         this._analogGeneralScale = Convert.ToSingle(dictionary["ANALOG", "GEN_SCALE"].GetData(0));
     }
     else
     {
         this._analogGeneralScale = C3DConstants.DEFAULT_ANALOG_GEN_SCALE;
     }
 }
示例#6
0
 private void LoadAnalogChannelScale(C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("ANALOG", "SCALE"))
     {
         this._analogChannelScale = this.LoadFromArray <Single>(dictionary["ANALOG", "SCALE"], this._analogChannelCount);
     }
     else
     {
         this._analogChannelScale = null;
     }
 }
示例#7
0
 private void LoadAnalogZeroOffset(C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("ANALOG", "OFFSET"))
     {
         this._analogZeroOffset = this.LoadFromArray <Int16>(dictionary["ANALOG", "OFFSET"], this._analogChannelCount);
     }
     else
     {
         this._analogZeroOffset = null;
     }
 }
示例#8
0
        public C3DParameterDictionary ReadParameters()
        {
            Dictionary <Int32, C3DParameterGroup>    groups     = new Dictionary <Int32, C3DParameterGroup>();
            Dictionary <Int32, List <C3DParameter> > parameters = new Dictionary <Int32, List <C3DParameter> >();

            Int32 startPosition = (this._firstParameterBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE;

            this._reader.BaseStream.Seek(startPosition + 2, SeekOrigin.Begin);

            Byte paramsBlocksCount = this._reader.ReadByte();
            Byte processorType     = this._reader.ReadByte();

            Int64 endPosition  = startPosition + paramsBlocksCount * C3DConstants.FILE_SECTION_SIZE;
            Int16 nextPosition = 0;

            do
            {
                SByte   nameLength = this._reader.ReadSByte();//Byte 1
                Boolean isLocked   = nameLength < 0;
                nameLength = Math.Abs(nameLength);

                SByte  id   = this._reader.ReadSByte();           //Byte 2
                Byte[] name = this._reader.ReadBytes(nameLength); //Byte 3

                nextPosition = this._reader.ReadInt16();          //Byte 3 + n
                Byte[] lastData = (nextPosition > 0 ? this._reader.ReadBytes(nextPosition - 2) : null);

                if (id > 0)//C3DParameter
                {
                    C3DParameter parameter = new C3DParameter(this._processorType, id, name, isLocked, lastData);

                    List <C3DParameter> list = null;
                    if (!parameters.TryGetValue(parameter.ID, out list))
                    {
                        list = new List <C3DParameter>();
                    }

                    list.Add(parameter);
                    parameters[parameter.ID] = list;
                }
                else//C3DParameterGroup
                {
                    C3DParameterGroup group = new C3DParameterGroup(id, name, isLocked, lastData);
                    groups[-group.ID] = group;
                }
            }while (nextPosition > 0 && this._reader.BaseStream.Position < endPosition);

            return(C3DParameterDictionary.CreateParameterDictionaryFromParameterList(groups, parameters));
        }
示例#9
0
 private void LoadPointCount(C3DHeader header, C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("POINT", "USED"))
     {
         this._pointCount = (UInt16)Convert.ToInt16(dictionary["POINT", "USED"].GetData(0));
     }
     else if (header != null)
     {
         this._pointCount = header.PointCount;
     }
     else
     {
         this._pointCount = C3DConstants.DEFAULT_POINT_USED;
     }
 }
示例#10
0
 private void LoadScaleFactor(C3DHeader header, C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("POINT", "SCALE"))
     {
         this._scaleFactor = Convert.ToSingle(dictionary["POINT", "SCALE"].GetData(0));
     }
     else if (header != null)
     {
         this._scaleFactor = header.ScaleFactor;
     }
     else
     {
         this._scaleFactor = C3DConstants.DEFAULT_POINT_SCALE;
     }
 }
示例#11
0
 private void LoadAnalogSamplesPerFrame(C3DHeader header, C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("ANALOG", "RATE"))
     {
         this._analogSamplesPerFrame = (UInt16)(Convert.ToSingle(dictionary["ANALOG", "RATE"].GetData(0)) / this._frameRate);
     }
     else if (header != null)
     {
         this._analogSamplesPerFrame = header.AnalogSamplesPerFrame;
     }
     else
     {
         this._analogSamplesPerFrame = (UInt16)(C3DConstants.DEFAULT_ANALOG_RATE / C3DConstants.DEFAULT_POINT_RATE);
     }
 }
示例#12
0
 private void LoadAnalogChannelCount(C3DHeader header, C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("ANALOG", "USED"))
     {
         this._analogChannelCount = (UInt16)Convert.ToInt16(dictionary["ANALOG", "USED"].GetData(0));
     }
     else if (header != null)
     {
         this._analogChannelCount = (UInt16)(header.AnalogSamplesPerFrame != 0 ? header.AnalogMeasurementCount / header.AnalogSamplesPerFrame : 0);
     }
     else
     {
         this._analogChannelCount = C3DConstants.DEFAULT_ANALOG_USED;
     }
 }
示例#13
0
 private void LoadFrameRate(C3DHeader header, C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("POINT", "RATE"))
     {
         this._frameRate = Convert.ToSingle(dictionary["POINT", "RATE"].GetData(0));
     }
     else if (header != null)
     {
         this._frameRate = header.FrameRate;
     }
     else
     {
         this._frameRate = C3DConstants.DEFAULT_POINT_RATE;
     }
 }
示例#14
0
 private void LoadFrameCount(C3DHeader header, C3DParameterDictionary dictionary)
 {
     if (dictionary != null && dictionary.ContainsParameter("POINT", "FRAMES"))
     {
         this._frameCount = (UInt16)Convert.ToInt16(dictionary["POINT", "FRAMES"].GetData(0));
     }
     else if (header != null)
     {
         this._frameCount = (UInt16)(header.LastFrameIndex - header.FirstFrameIndex + 1);
     }
     else
     {
         this._frameCount = C3DConstants.DEFAULT_POINT_LAST_FRAME - C3DConstants.DEFAULT_POINT_FIRST_FRAME + 1;
     }
 }
示例#15
0
        /// <summary>
        /// 初始化取参数缓存信息
        /// </summary>
        /// <param name="header">C3D文件头</param>
        /// <param name="dictionary">C3D参数字典</param>
        private C3DParameterCache(C3DHeader header, C3DParameterDictionary dictionary)
        {
            this.LoadFirstDataBlockPosition(header, dictionary);

            this.LoadPointCount(header, dictionary);
            this.LoadScaleFactor(header, dictionary);
            this.LoadFrameCount(header, dictionary);
            this.LoadFrameRate(header, dictionary);

            this.LoadAnalogChannelCount(header, dictionary);
            this.LoadAnalogSamplesPerFrame(header, dictionary);

            this.LoadAnalogGeneralScale(dictionary);
            this.LoadAnalogChannelScale(dictionary);
            this.LoadAnalogZeroOffset(dictionary);
        }
示例#16
0
        private void LoadFirstDataBlockPosition(C3DHeader header, C3DParameterDictionary dictionary)
        {
            this._firstDataBlockPosition = 0;

            if (dictionary != null && dictionary.ContainsParameter("POINT", "DATA_START"))
            {
                this._firstDataBlockPosition = ((UInt16)Convert.ToInt16(dictionary["POINT", "DATA_START"].GetData(0)) - 1) * C3DConstants.FILE_SECTION_SIZE;
            }

            if (header != null && this._firstDataBlockPosition <= 0)
            {
                this._firstDataBlockPosition = (header.FirstDataSectionID - 1) * C3DConstants.FILE_SECTION_SIZE;
            }

            if (this._firstDataBlockPosition <= 0)
            {
                this._firstDataBlockPosition = (C3DConstants.FILE_DEFAULT_FIRST_PARAM_SECTION - 1) * C3DConstants.FILE_SECTION_SIZE;
            }
        }
示例#17
0
        /// <summary>
        /// 创建新的C3D参数组字典
        /// </summary>
        /// <returns>C3D参数组字典</returns>
        public static C3DParameterDictionary CreateNewParameterDictionary()
        {
            C3DParameterDictionary dict = new C3DParameterDictionary();

            C3DParameterGroup groupPoint = dict.SetGroup(1, "POINT", "");

            groupPoint.Add <UInt16>("USED", "", C3DConstants.DEFAULT_POINT_USED);
            groupPoint.Add <Single>("SCALE", "", C3DConstants.DEFAULT_POINT_SCALE);
            groupPoint.Add <Single>("RATE", "", C3DConstants.DEFAULT_POINT_RATE);
            groupPoint.Add <UInt16>("DATA_START", "", C3DConstants.FILE_DEFAULT_FIRST_PARAM_SECTION);
            groupPoint.Add <UInt16>("FRAMES", "", C3DConstants.DEFAULT_POINT_LAST_FRAME - C3DConstants.DEFAULT_POINT_FIRST_FRAME + 1);

            C3DParameterGroup groupAnalog = dict.SetGroup(2, "ANALOG", "");

            groupAnalog.Add <UInt16>("USED", "", C3DConstants.DEFAULT_ANALOG_USED);
            groupAnalog.Add <Single>("RATE", "", C3DConstants.DEFAULT_ANALOG_RATE);

            C3DParameterGroup groupForcePlatform = dict.SetGroup(3, "FORCE_PLATFORM", "");

            return(dict);
        }
示例#18
0
 /// <summary>
 /// 从C3D文件头和参数字典中创建参数缓存
 /// </summary>
 /// <param name="header">C3D文件头</param>
 /// <param name="dictionary">C3D参数字典</param>
 public static C3DParameterCache CreateCache(C3DHeader header, C3DParameterDictionary dictionary)
 {
     return(new C3DParameterCache(header, dictionary));
 }
示例#19
0
 /// <summary>
 /// 从C3D参数字典中创建参数缓存
 /// </summary>
 /// <param name="dictionary">C3D参数字典</param>
 public static C3DParameterCache CreateCache(C3DParameterDictionary dictionary)
 {
     return(new C3DParameterCache(null, dictionary));
 }
示例#20
0
 public C3DFrame ReadNextFrame(C3DParameterDictionary dictionary)
 {
     return(this.ReadNextFrame(C3DParameterCache.CreateCache(dictionary)));
 }