Esempio n. 1
0
        private List <Heatmap.Coord> TrimStaticHeatmap(SessionCollection sessions, double startTime, double stopTime, MediaClip video)
        {
            List <Heatmap.Coord> inputList = new List <Heatmap.Coord>();

            if (video != null)
            {
                foreach (Session x in sessions.sessions)
                {
                    int fps   = x.sample_rate;
                    int start = (int)Math.Floor(startTime / 1000 * fps);
                    int stop  = (int)Math.Floor(stopTime / 1000 * fps);

                    var deserial = Heatmap.CoordsDeserialize(x.history);

                    for (int i = start; i < stop; i++)
                    {
                        try
                        {
                            inputList.Add(deserial[i]);
                        }
                        catch
                        {
                            inputList.Add(new Heatmap.Coord {
                                fov = 0, pitch = 0, yaw = 0
                            });
                        }
                    }
                }
            }
            else
            {
                foreach (Session x in sessions.sessions)
                {
                    var deserial = Heatmap.CoordsDeserialize(x.history);
                    inputList.AddRange(deserial);
                }
            }

            return(inputList);
        }
Esempio n. 2
0
        private async Task <WriteableBitmap> GenerateHeatmap(List <Heatmap.Coord> inputList, bool forceFov, int forcedFov, bool scaleFovFlag, int scaleInPercentage)
        {
            //var deserializedData = Heatmap.CoordsDeserialize(session.history);

            if (forceFov)
            {
                foreach (Heatmap.Coord h in inputList)
                {
                    if (h.fov == 0)
                    {
                        continue;
                    }
                    h.fov = forcedFov;
                }
            }
            else if (scaleFovFlag)
            {
                foreach (Heatmap.Coord h in inputList)
                {
                    h.fov = ScaleFov(h.fov, scaleInPercentage);
                }
            }

            float[] heatmap = await Task.Factory.StartNew(() =>
                                                          Heatmap.Generate(inputList)
                                                          );

            var renderedHeatmap = Heatmap.RenderHeatmap(heatmap);

            WriteableBitmap wb = new WriteableBitmap(64, 64);


            using (Stream stream = wb.PixelBuffer.AsStream())
            {
                await stream.WriteAsync(renderedHeatmap, 0, renderedHeatmap.Length);
            }

            return(wb);
        }
Esempio n. 3
0
        private Heatmap.Coord[] InterpolateSession(Session session, uint videoFrameNumerator, uint videoFrameDenominator, TimeSpan videoDuration)
        {
            long framesCount = videoFrameNumerator * videoDuration.Ticks / TimeSpan.TicksPerSecond / videoFrameDenominator;

            Heatmap.Coord[] interpolated = new Heatmap.Coord[framesCount];

            int coordsLength;
            List <Heatmap.Coord> coords = Heatmap.CoordsDeserialize(session.history);


            float inOutProportion = (float)session.Length.Ticks / videoDuration.Ticks;

            if (inOutProportion > 1)
            {
                List <Heatmap.Coord> temp = coords.GetRange(0,
                                                            (int)(videoDuration.Ticks / TimeSpan.TicksPerSecond) * session.sample_rate);
                inOutProportion = 1;
                coords          = temp;
            }

            coordsLength = coords.Count;
            int lastFramePosition = (int)(inOutProportion * (framesCount - 1));           //represenst the value last position of last coord in new interpolated array

            float origTransformationStep = (float)lastFramePosition / (coordsLength - 1); //represents the value of the transformation step coords[x*k] -> inteprpolated[x + origTransformationStep*k] [-2 because first and last position are set manually below]


            //fill array with known values
            for (int i = 0; i < coordsLength; i++)
            {
                float temp        = i * origTransformationStep;
                int   newPosition = (int)Math.Round(temp, 0);

                interpolated[newPosition] = coords[i];

                if (_forceFovFlag)
                {
                    if (interpolated[newPosition].fov != 0)
                    {
                        interpolated[newPosition].fov = _forcedFov;
                    }
                }
            }

            //fill rest of time with empty heatmaps
            for (int i = lastFramePosition + 1; i < interpolated.Length; i++)
            {
                interpolated[i] = new Heatmap.Coord {
                    fov = 0, pitch = 0, yaw = 0
                };
            }

            int originalFrameCount = 1;

            for (int i = 0; i < lastFramePosition - 1; i++)
            {
                int           interpolationFromIndex = i;
                Heatmap.Coord valueFrom = interpolated[i];

                int           interpolationToIndex = (int)Math.Round((originalFrameCount) * origTransformationStep);
                Heatmap.Coord valueTo = interpolated[interpolationToIndex];

                int interpolationLength = interpolationToIndex - i - 1;

                if (interpolationLength == 0)
                {
                    continue;
                }

                float yawStepValue   = (valueTo.yaw - valueFrom.yaw) / (float)interpolationLength;
                float pitchStepValue = (valueTo.pitch - valueFrom.pitch) / (float)interpolationLength;

                int yawLength = valueTo.yaw - valueFrom.yaw;
                if (Math.Abs(yawLength) > 31)
                {
                    yawStepValue = (64 - Math.Abs(yawLength)) / (float)interpolationLength;
                }

                int internalCounter = 1;
                while (interpolationLength > 0)
                {
                    i++;
                    interpolated[i]       = new Heatmap.Coord();
                    interpolated[i].fov   = interpolated[interpolationFromIndex].fov;
                    interpolated[i].pitch = (int)Math.Round(interpolated[interpolationFromIndex].pitch + pitchStepValue * internalCounter, 0);
                    interpolated[i].yaw   = (int)Math.Round(interpolated[interpolationFromIndex].yaw + yawStepValue * internalCounter, 0) % 64;

                    if (Math.Abs(yawLength) > 31 && valueFrom.yaw < valueTo.yaw)
                    {
                        interpolated[i].yaw = ((int)Math.Round(interpolated[interpolationFromIndex].yaw - yawStepValue * internalCounter, 0) + 10 * 64) % 64;
                    }
                    interpolationLength--;
                    internalCounter++;
                }
                originalFrameCount++;
            }

            return(interpolated);
        }