1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System.IO;
- using UnityEngine;
- public class Heatmap : MonoBehaviour
- {
- [Header("Read and Save Settings:")]
- public int readIndex;
- public int saveIndex = 2019;
- [Header("Grid Settings:")]
- public Vector2 gridSize = new Vector2(70, 35);
- public int scaleHeatmap = 8;
- [Header("Set Scene Obstacles:")]
- public GameObject[] obstacles;
- private void Start()
- {
- GridArray grid = new GridArray((int)gridSize.x, (int)gridSize.y) ;
- // Read from CSV file and save time, position, rotation in matrix
- string dir = Directory.GetCurrentDirectory();
- string reference = @"\Assets\Data_position\Walk" + readIndex + ".csv";
- var timePosRotList = gameObject.GetComponent<ReadFromCSVNew>().ReadFromCSVFile(dir + reference);
- // increment grid at the positions where the people are located
- for(int i = 0; i < timePosRotList.Length; ++i) // groups
- {
- for(int j = 0; j < timePosRotList[i].Length; ++j) // humans
- {
- int currentIndex = 0;
- // increment grid for one Human completly
- while(currentIndex < timePosRotList[i][j].Item2.Count)
- {
- int width = (int)timePosRotList[i][j].Item2[currentIndex].x;
- int height = (int)timePosRotList[i][j].Item2[currentIndex].z;
- grid.IncrementGridArray(width, height);
- currentIndex++;
- }
- }
- }
-
- var normalizedHeatmap = grid.NormalizeArray();
- //add obstacles into heatmap
- foreach(var obstacle in obstacles)
- normalizedHeatmap = grid.SetObstacles(normalizedHeatmap, obstacle);
- string fileName = @"\Assets\Data_image\Heatmap" + saveIndex + ".png";
- float[,] scaledHeatmap = grid.ScaleArray(normalizedHeatmap, scaleHeatmap);
- scaledHeatmap = grid.SetBorder(scaledHeatmap, obstacles[1], scaleHeatmap);
- grid.SaveGrid(scaledHeatmap, dir + fileName);
- }
- }
|