示例#1
0
 public BehaviourHolderXml(BoundaryBaseXml boundary, InteractionBehaviour interaction, int frameNumber)
 {
     Boundary    = boundary;
     Interaction = interaction;
     FrameNumber = frameNumber;
 }
示例#2
0
        public void SaveFile(string fileLocation, string videoFileName, SingleFileResult result, Dictionary <int, ISingleFrameResult> headPoints, PointF[] motionTrack, PointF[] smoothedMotionTrack, Vector[] orientationTrack, IEnumerable <IBehaviourHolder> events, IEnumerable <IBoundaryBase> boundaries, Dictionary <IBoundaryBase, IBehaviourHolder[]> interactions, double minInteractionDistance, double gapDistance, int thresholdValue, int thresholdValue2, int startFrame, int endFrame, double frameRate, bool smoothMotion, double smoothingFactor, double centroidSize, double pelvicArea1, double pelvicArea2, double pelvicArea3, double pelvicArea4, double unitsToMilimeters, Rectangle roi, string message = "")
        {
            if (string.IsNullOrWhiteSpace(fileLocation))
            {
                return;
            }

            TrackedVideoXml fileXml;
            XmlSerializer   serializer;
            RectangleXml    roiXml = new RectangleXml(roi);

            if (result != SingleFileResult.Ok)
            {
                fileXml    = new TrackedVideoXml(videoFileName, result, null, null, null, null, null, null, null, minInteractionDistance, gapDistance, thresholdValue, thresholdValue2, startFrame, endFrame, frameRate, smoothMotion, smoothingFactor, centroidSize, pelvicArea1, pelvicArea2, pelvicArea3, pelvicArea4, unitsToMilimeters, roiXml, message);
                serializer = new XmlSerializer(typeof(TrackedVideoXml));

                using (StreamWriter writer = new StreamWriter(fileLocation))
                {
                    serializer.Serialize(writer, fileXml);
                }

                return;
            }

            int headCount = headPoints.Count;

            SingleFrameResultXml[] allPoints = new SingleFrameResultXml[headCount];
            for (int i = 0; i < headCount; i++)
            {
                allPoints[i] = new SingleFrameResultXml(headPoints[i]);
            }

            DictionaryXml <int, SingleFrameResultXml> headPointsXml = new DictionaryXml <int, SingleFrameResultXml>(headPoints.Keys.ToArray(), allPoints);

            PointFXml[] motionTrackXml         = motionTrack.Select(point => new PointFXml(point.X, point.Y)).ToArray();
            PointFXml[] smoothedMotionTrackXml = smoothedMotionTrack.Select(point => new PointFXml(point)).ToArray();
            VectorXml[] orientationTrackXml    = orientationTrack.Select(vector => new VectorXml(vector)).ToArray();

            List <BoundaryBaseXml> boundariesXml = boundaries.Select(boundary => boundary.GetData()).ToList();

            List <BehaviourHolderXml> eventsXml = new List <BehaviourHolderXml>();

            foreach (IBehaviourHolder behaviour in events)
            {
                BoundaryBaseXml      boundary    = null;
                InteractionBehaviour interaction = behaviour.Interaction;
                int frameNumber = behaviour.FrameNumber;
                boundary = behaviour.Boundary.GetData();

                eventsXml.Add(new BehaviourHolderXml(boundary, interaction, frameNumber));
            }

            BoundaryBaseXml[]      keys   = interactions.Keys.Select(key => key.GetData()).ToArray();
            BehaviourHolderXml[][] values = interactions.Values.Select(value => value.Select(behavHolder => new BehaviourHolderXml(behavHolder.Boundary.GetData(), behavHolder.Interaction, behavHolder.FrameNumber)).ToArray()).ToArray();
            DictionaryXml <BoundaryBaseXml, BehaviourHolderXml[]> interactionBoundries = new DictionaryXml <BoundaryBaseXml, BehaviourHolderXml[]>(keys, values);

            fileXml    = new TrackedVideoXml(videoFileName, result, headPointsXml, motionTrackXml, smoothedMotionTrackXml, orientationTrackXml, boundariesXml.ToArray(), eventsXml.ToArray(), interactionBoundries, minInteractionDistance, gapDistance, thresholdValue, thresholdValue2, startFrame, endFrame, frameRate, smoothMotion, smoothingFactor, centroidSize, pelvicArea1, pelvicArea2, pelvicArea3, pelvicArea4, unitsToMilimeters, roiXml, message);
            serializer = new XmlSerializer(typeof(TrackedVideoXml));

            using (StreamWriter writer = new StreamWriter(fileLocation))
            {
                serializer.Serialize(writer, fileXml);
            }
        }