private BenchmarkSample AverageMarkerSet(PSMarker[] markerSet)
    {
        var result       = new BenchmarkSample();
        var subSampleSet = new List <Vector4>();

        float avgCondition = 0f;         // bad, no cam sees the marker

        Vector3 avgVector = Vector3.zero;

        float n = markerSet.Length;

        foreach (var marker in markerSet)
        {
            avgCondition += marker.cond;
            avgVector    += marker.position;
            subSampleSet.Add(new Vector4(marker.position.x, marker.position.y, marker.position.z, marker.cond));
        }

        if (n < expectedMarkerCount)
        {
            result.condition = 0;             // If a marker is missing mark the whole sample as dirty
        }
        result.subsamples = subSampleSet.ToArray();

        avgVector    = avgVector / n;
        avgCondition = avgCondition / n;

        result.position  = avgVector;
        result.condition = avgCondition;

        return(result);
    }
    public BenchmarkSample AveragePosition(ICollection <PSMarker[]> markerSets)
    {
        var result     = new BenchmarkSample();
        var subsamples = new List <Vector4>();

        float condition = 0f;

        Vector3 sumVector = Vector3.zero;

        float n = markerSets.Count;

        foreach (var set in markerSets)
        {
            var setAvg = AverageMarkerSet(set);

            condition += setAvg.condition;

            sumVector += setAvg.position;

            subsamples.Add(new Vector4(setAvg.position.x, setAvg.position.y, setAvg.position.z, setAvg.condition));
        }


        result.subsamples = subsamples.ToArray();

        Vector3 avgVector = sumVector / n;

        float avgError = condition / n;

        result.position  = avgVector;
        result.condition = avgError;

        return(result);
    }
    void AppendToBenchmark(GameObject preview, BenchmarkSample sample)
    {
        var obj = GameObject.Instantiate(preview);

        obj.transform.parent = activeBenchmarkPresenter.transform;

        activeBenchmarkPresenter.model.Samples.Add(sample);
    }
    void Render(BenchmarkSample avgPosition)
    {
        var obj = GameObject.Instantiate(prototypSample);

        obj.transform.position   = avgPosition.position;
        obj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        obj.GetComponent <Renderer>().material.color = GetFrom(avgPosition.condition);
    }
    GameObject UpdatePreviewSample(BenchmarkSample sample)
    {
        samplePrototype.transform.position = sample.position;
        var benchmarkColor = activeBenchmarkPresenter.model.color;

        samplePrototype.GetComponent <Renderer>().material.color = new Color(benchmarkColor.r, benchmarkColor.g, benchmarkColor.b, sample.condition / availableCameras);

        return(samplePrototype);
    }
    // Update is called once per frame
    void Update()
    {
        if (markerQueue.Count >= minAveraginCount)
        {
            var avgPosition = AveragePosition(markerQueue.ToList());

            markerQueue.Clear();

            latestAvgResult = avgPosition;

            var currentSample = UpdatePreviewSample(avgPosition);

            if (recording)
            {
                AppendToBenchmark(currentSample, avgPosition);
            }
        }
    }