Exemplo n.º 1
0
    // Update the text that displays the statistics of the selected points
    // This function shouldn't be in this class, but I don't give a shit
    public void UpdateGUI()
    {
        string text = "";

        if (selection.Count == 1)   // If there is only one point
        {
            text = "1 object selected:";
            PlottedBalls uniqueObject = selection[0].GetComponent <PlottedBalls>(); // Properties are stored in PlottedBalls component
            Dictionary <string, object> .KeyCollection keys = uniqueObject.Data.Keys;
            foreach (string key in keys)
            {
                text += "\n" + key + ": " + uniqueObject.Data[key]; // Display each property
            }
        }
        else if (selection.Count > 1)     // If there are multiple points selected
        {
            text  = selection.Count + " objects selected:";
            text += Plotter.getDataFromBallsAsText(selection); // Use the static function of the plotting class (we should change the name...)
        }
        else
        {
            text = "No object selected"; // If there is nothing selected, we will hide this
        }

        GUI_Text.text = text;     // Set the displayed text

        if (selection.Count == 0) // Remove the text completely if there is nothing to display
        {
            GUI_Text_Container.gameObject.GetComponent <Hideable>().Hide();
        }
        else
        {
            GUI_Text_Container.gameObject.GetComponent <Hideable>().Show();
        }
    }
Exemplo n.º 2
0
    // Get statistics of multiple points as a dictionary <key, list_of_values>
    // If the column is numerical, list_of_values is a array with [mean_value, min_value, max_value]
    // Otherwise it is the list of all different values
    static public Dictionary <string, List <object> > getDataFromBalls(List <GameObject> balls)
    {
        if (balls.Count == 0)
        {
            return(null);
        }
        Dictionary <string, List <object> > allData = new Dictionary <string, List <object> >();

        Dictionary <string, object> .KeyCollection keys = balls[0].GetComponent <PlottedBalls>().Data.Keys;
        foreach (string key in keys)
        {
            if (key == "")
            {
                continue;
            }
            allData[key] = new List <object>();
            foreach (GameObject obj in balls)
            {
                PlottedBalls pb    = obj.GetComponent <PlottedBalls>();
                string       s_val = pb.Data[key].ToString().Replace(".", ",");
                float        val;
                if (float.TryParse(s_val, out val))
                {
                    if (allData[key].Count == 0)
                    {
                        allData[key].Add(val); // Mean
                        allData[key].Add(val); // Min
                        allData[key].Add(val); // Max
                    }
                    else
                    {
                        allData[key][0] = (float)allData[key][0] + val;           // Mean
                        allData[key][1] = Mathf.Min((float)allData[key][1], val); // Min
                        allData[key][2] = Mathf.Max((float)allData[key][2], val); // Max
                    }
                }
                else
                {
                    if (!allData[key].Contains(s_val))
                    {
                        allData[key].Add(s_val);
                    }
                }
            }
            if (allData[key].Count > 0 && float.TryParse(allData[key][0].ToString(), out _))
            {
                allData[key][0] = (float)allData[key][0] / (float)balls.Count; // Calculate real mean
            }
        }

        return(allData);
    }
Exemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        pointList = CSVReader.Read(inputfile);

        // Declare list of strings, fill with keys (column names)
        List <string> columnList = new List <string>(pointList[1].Keys);

        // Assign column name from columnList to Name variables
        xName = columnList[columnX];
        yName = columnList[columnY];
        zName = columnList[columnZ];

        // Get maxes of each axis
        float xMax = FindMaxValue(pointList, xName);
        float yMax = FindMaxValue(pointList, yName);
        float zMax = FindMaxValue(pointList, zName);

        // Get minimums of each axis
        float xMin = FindMinValue(pointList, xName);
        float yMin = FindMinValue(pointList, yName);
        float zMin = FindMinValue(pointList, zName);

        float x = 0.0f;
        float y = 0.0f;
        float z = 0.0f;

        // Loop through Pointlist
        for (var i = 0; i < pointList.Count; i++)
        {
            string v1 = pointList[i][xName].ToString().Replace(".", ",");
            string v2 = pointList[i][yName].ToString().Replace(".", ",");
            string v3 = pointList[i][zName].ToString().Replace(".", ",");

            // Get value in poinList at ith "row", in "column" Name, normalize
            x = (System.Convert.ToSingle(v1) - xMin) / (xMax - xMin);
            y = (System.Convert.ToSingle(v2) - yMin) / (yMax - yMin);
            z = (System.Convert.ToSingle(v3) - zMin) / (zMax - zMin);

            // Instantiate as gameobject variable so that it can be manipulated within loop
            GameObject dataPoint = Instantiate(PointPrefab, new Vector3(x, y, z) * plotScale, Quaternion.identity, this.transform);
            dataPoint.transform.localScale = new Vector3(1.0f * ballScale * plotScale, 1.0f * ballScale * plotScale, 1.0f * ballScale * plotScale);

            // Assigns original values to dataPointName
            string dataPointName = pointList[i][xName].ToString() + " " + pointList[i][yName].ToString() + " " + pointList[i][zName].ToString();

            // Assigns name to the prefab
            dataPoint.transform.name = dataPointName;

            // Gets material color and sets it to a new RGBA color we define
            // dataPoint.GetComponent<Renderer>().material.color = new Color(x,y,z, 1.0f); // We will use selected/deselected colors instead

            PlottedBalls pointData = dataPoint.GetComponent <PlottedBalls>(); // The prefab contains the PlottedBalls component
            for (int data_id = 0; data_id < columnList.Count; data_id++)      // Store all the data about this point in it
            {
                pointData.setData(columnList[data_id], pointList[i][columnList[data_id]]);
            }
        }

        if (axis != null)
        {
            axis.changeAxisLabels(xName, yName, zName);
        }
    }