예제 #1
0
        /// <summary>
        /// Read the JSON data and convert into Lists of HeatPoint structs.
        /// </summary>
        /// <param name="text">The loaded data.</param>
        protected void ConsumeHeatmapData(string text)
        {
            var     heatData   = new Dictionary <string, HeatPoint[]>();
            var     keys       = new ArrayList();
            float   maxDensity = 0;
            float   maxTime    = 0;
            Vector3 lowSpace   = Vector3.zero;
            Vector3 highSpace  = Vector3.zero;

            Dictionary <string, object> data = Json.Deserialize(text) as Dictionary <string, object>;

            foreach (KeyValuePair <string, object> kv in data)
            {
                keys.Add(kv.Key);

                var pointList = kv.Value as List <object>;
                var array     = new HeatPoint[pointList.Count];
                for (int a = 0, aa = pointList.Count; a < aa; a++)
                {
                    array[a] = new HeatPoint();
                    float x = 0, y = 0, z = 0, t = 0, rx = 0, ry = 0, rz = 0, dx = 0, dy = 0, dz = 0;
                    float d  = 0;
                    var   pt = pointList[a] as Dictionary <string, object>;

                    foreach (KeyValuePair <string, object> pointKV in pt)
                    {
                        var value = (float)Convert.ToDouble(pointKV.Value);
                        switch (pointKV.Key)
                        {
                        case "x":
                            x = value;
                            break;

                        case "y":
                            y = value;
                            break;

                        case "z":
                            z = value;
                            break;

                        case "t":
                            t = value;
                            break;

                        case "d":
                            d = value;
                            break;

                        case "rx":
                            rx = value;
                            break;

                        case "ry":
                            ry = value;
                            break;

                        case "rz":
                            rz = value;
                            break;

                        case "dx":
                            dx = value;
                            break;

                        case "dy":
                            dy = value;
                            break;

                        case "dz":
                            dz = value;
                            break;
                        }
                    }
                    array[a].position    = new Vector3(x, y, z);
                    array[a].rotation    = new Vector3(rx, ry, rz);
                    array[a].destination = new Vector3(dx, dy, dz);
                    array[a].density     = d;
                    array[a].time        = t;
                    maxDensity           = Mathf.Max(d, maxDensity);
                    maxTime = Mathf.Max(array[a].time, maxTime);
                    if (a == 0)
                    {
                        lowSpace = highSpace = array[a].position;
                    }
                    else
                    {
                        lowSpace  = Vector3.Min(array[a].position, lowSpace);
                        highSpace = Vector3.Max(array[a].position, highSpace);
                    }
                }
                heatData[kv.Key] = array;
            }

            if (m_ParseHandler != null)
            {
                m_ParseHandler(heatData, keys.ToArray(typeof(string)) as string[]);
            }
        }
예제 #2
0
 void OnPointData(HeatPoint[] heatData, float maxDensity, float maxTime)
 {
     // Creating this data allows the renderer to use it on the next Update pass
     m_PointData = new Dictionary<string, object>();
     m_PointData["heatData"] = heatData;
     m_PointData["maxDensity"] = maxDensity;
     m_PointData["maxTime"] = maxTime;
 }
예제 #3
0
 public void UpdatePointData(HeatPoint[] newData, float newMaxDensity)
 {
     m_Data = newData;
     m_MaxDensity = newMaxDensity;
     m_RenderState = k_BeginRenderer;
 }
예제 #4
0
        /// <summary>
        /// Read the JSON data and convert into Lists of HeatPoint structs.
        /// </summary>
        /// <param name="text">The loaded data.</param>
        protected void ConsumeHeatmapData(string text)
        {
            var heatData = new Dictionary<string, HeatPoint[]>();
            var keys = new ArrayList();
            float maxDensity = 0;
            float maxTime = 0;

            Dictionary<string, object> data = Json.Deserialize(text) as Dictionary<string, object>;
            foreach (KeyValuePair<string, object> kv in data)
            {
                keys.Add(kv.Key);

                var pointList = kv.Value as List<object>;
                var array = new HeatPoint[pointList.Count];
                for (int a = 0, aa = pointList.Count; a < aa; a++)
                {
                    array[a] = new HeatPoint();
                    float x = 0, y = 0, z = 0, t = 0, rx = 0, ry = 0, rz = 0;
                    float d = 0;
                    var pt = pointList[a] as Dictionary<string, object>;

                    foreach (KeyValuePair<string,object> pointKV in pt)
                    {
                        var value = (float)Convert.ToDouble(pointKV.Value);
                        switch (pointKV.Key)
                        {
                            case "x":
                                x = value;
                                break;
                            case "y":
                                y = value;
                                break;
                            case "z":
                                z = value;
                                break;
                            case "t":
                                t = value;
                                break;
                            case "d":
                                d = value;
                                break;
                            case "rx":
                                rx = value;
                                break;
                            case "ry":
                                ry = value;
                                break;
                            case "rz":
                                rz = value;
                                break;
                        }
                    }
                    array[a].position = new Vector3(x, y, z);
                    array[a].rotation = new Vector3(rx, ry, rz);
                    array[a].density = d;
                    array[a].time = t;
                    maxDensity = Mathf.Max(d, maxDensity);
                    maxTime = Mathf.Max(array[a].time, maxTime);
                }
                heatData[kv.Key] = array;
            }

            if (m_ParseHandler != null)
            {
                m_ParseHandler(heatData, maxDensity, maxTime, keys.ToArray(typeof(string)) as string[]);
            }
        }