Пример #1
0
        /*!
         * @fn ParseChannels(XmlNodeList channels)
         * @param channels	node list with channel information
         * helper method to extract channel information
         */
        protected void ParseChannels(XmlNodeList channels)
        {
            foreach (XmlNode channel in channels)
            {
                if (channel.Name.Contains("channel"))
                {
                    string       channelName   = "";
                    string       channelType   = "";
                    string       channelInterp = "";
                    string       sampleType    = "";
                    float        sampleRate    = 0;
                    float        startTime     = 0;
                    float        endTime       = 0;
                    CacheChannel channelObj    = null;

                    for (int index = 0; index < channel.Attributes.Count; ++index)
                    {
                        string attrName = channel.Attributes[index].Name;
                        string attrVal  = channel.Attributes[index].Value;
                        if (attrName == "ChannelName")
                        {
                            channelName = attrVal;
                        }
                        if (attrName == "ChannelInterpretation")
                        {
                            channelInterp = attrVal;
                        }
                        if (attrName == "EndTime")
                        {
                            endTime = (float)Double.Parse(attrVal) / 6000.0f;
                        }
                        if (attrName == "StartTime")
                        {
                            startTime = (float)Double.Parse(attrVal) / 6000.0f;
                        }
                        if (attrName == "SamplingRate")
                        {
                            sampleRate = (float)Double.Parse(attrVal) / 6000.0f;
                        }
                        if (attrName == "SamplingType")
                        {
                            sampleType = attrVal;
                        }
                        if (attrName == "ChannelType")
                        {
                            channelType = attrVal;
                        }
                    }
                    channelObj            = new CacheChannel(channelName, channelType, channelInterp, sampleType, sampleRate, startTime, endTime);
                    Channels[channelName] = channelObj;
                }
            }
        }
Пример #2
0
 public void ParseData()
 {
     BaseName  = Path.GetFileNameWithoutExtension(FileName);
     Directory = Path.GetDirectoryName(FileName) + '/';
     if (Version > 2.0)
     {
         throw new FileLoadException("This function can only parse cache files of version 2 or lower");
     }
     Log(BaseName + " Maya Cache version " + Version);
     Log(String.Format("Cache has {0} channels, starting at time {1} seconds and ending at {2} seconds",
                       new object[] { Channels.Count, StartTime, EndTime }));
     if (_root.Name == null)
     {
         _root.Name = BaseName + ".meshanim";
     }
     _root.TimeInc = TimePerFrame;
     _root.Active  = false;
     foreach (KeyValuePair <string, CacheChannel> p in Channels)
     {
         CacheChannel channel = p.Value as CacheChannel;
         Log(String.Format("Channel Name {0}, Type {1}, interpretation {2}, sampling Type {3}",
                           new object[] { channel.Name, channel.Type, channel.Interp, channel.SampleType }));
         Log("sample rate " + (1.0 / channel.SampleRate) + " FPS " + channel.SampleRate + " sec / frame");
         Log(String.Format("startTime {0} seconds, endTime {1} seconds for {2} frames",
                           new object[] { channel.StartTime, channel.EndTime, (channel.EndTime - channel.StartTime) / channel.SampleRate }));
     }
     if (Type == "OneFilePerFrame")
     {
         ParseDataFilePerFrame();
     }
     else if (Type == "OneFile")
     {
         ParseDataOneFile();
     }
     else
     {
         throw new FileLoadException("Invalid cache file type " + Type);
     }
     if (_event != null)
     {
         _event.Log();
         _event = null;
     }
 }
Пример #3
0
        protected Int32 ParseChannel(BinaryReader fd, float time)
        {
            //
            // channel name is next. the tag for this must be CHNM
            //
            String       chnmTag = new String(fd.ReadChars(4));
            String       channelName;
            String       sizeTag;
            String       dataFormatTag;
            Int32        chnmSize;
            Int32        arrayLength;
            Int32        bufferLength;
            Int32        bytesRead = 0;
            Int32        mask;
            Int32        chnmSizeToRead;
            Int32        paddingSize;
            Int32        index;
            CacheChannel channel = null;

            if (chnmTag != "CHNM")
            {
                return(0);
            }
            bytesRead += 4;
            //
            // Next comes a 32 bit int that tells us how long the channel name is
            //
            chnmSize   = ReadInt(fd);
            bytesRead += 4;
            //
            // The string is padded out to 32 bit boundaries,
            // so we may need to read more than chnmSize
            //
            mask           = 3;
            chnmSizeToRead = (chnmSize + mask) & (~mask);
            --chnmSize;
            channelName = new String(fd.ReadChars(chnmSize));
            channel     = Channels[channelName];
            paddingSize = chnmSizeToRead - chnmSize;
            if (paddingSize > 0)
            {
                fd.ReadChars(paddingSize);
            }
            bytesRead += chnmSizeToRead;
            //
            // Next is the SIZE field, which tells us the length of the data array
            //
            sizeTag = new String(fd.ReadChars(4));
            if (sizeTag != "SIZE")
            {
                throw new FileLoadException("SIZE section missing in cache file " + FileName);
            }
            bytesRead += 4;
            //
            // Next 32 bit int is the size of the array size variable,
            // this is always 4, so we'll ignore it for now
            // though we could use it as a sanity check.
            //
            fd.ReadChars(4);
            bytesRead += 4;
            //
            //finally the actual size of the array
            //
            arrayLength = ReadInt(fd);
            bytesRead  += 4;
            //
            // data format tag
            //
            dataFormatTag = new String(fd.ReadChars(4));
            //
            // buffer length - how many bytes is the actual data
            //
            bufferLength = ReadInt(fd);
            bytesRead   += 8;
            Vixen.VertexArray verts      = new Vixen.VertexArray("position float 3", arrayLength);
            float[]           floatArray = new float[arrayLength * verts.VertexSize];

            if (dataFormatTag == "FVCA")                        // FVCA == Float Vector Array
            {
                if (bufferLength != arrayLength * 3 * 4)
                {
                    throw new FileLoadException("size inconsistency in cache file " + FileName);
                }
                for (int i = 0; i < arrayLength; i++)
                {
                    int   j = i * verts.VertexSize;
                    float x = ReadFloat(fd);
                    float y = ReadFloat(fd);
                    float z = ReadFloat(fd);
                    floatArray[j]     = x;
                    floatArray[j + 1] = y;
                    floatArray[j + 2] = z;
                }
            }
            else if (dataFormatTag == "DVCA")                   // DVCA == Double Vector Array
            {
                if (bufferLength != arrayLength * 3 * 8)
                {
                    throw new FileLoadException("size inconsistency in cache file " + FileName);
                }
                for (int i = 0; i < arrayLength; i++)
                {
                    int   j = i * verts.VertexSize;
                    float x = ReadDouble(fd);
                    float y = ReadDouble(fd);
                    float z = ReadDouble(fd);
                    floatArray[j]     = x;
                    floatArray[j + 1] = y;
                    floatArray[j + 2] = z;
                }
            }
            else
            {
                throw new FileLoadException("Unknown data tag " + dataFormatTag + " in cache file " + FileName);
            }
            bytesRead += bufferLength;
            verts.AddVertices(floatArray, arrayLength);
            float t = time + TimePerFrame / 2.0f - channel.StartTime;

            index = (Int32)(t / TimePerFrame);
            _root.SetSource(index, verts);
            Log("\ti = " + index + " t = " + t);
            return(bytesRead);
        }