Ejemplo n.º 1
0
        protected override void RebuildVisualization()
        {
            if (_presenter == null || _presenter.NumberOfDimensions < 3)
            {
                Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization");
                return;
            }
            if (_dataItemMesh == null)
            {
                _dataItemMesh = buildCircleMesh();
                Debug.Log("No DataMesh was set for this visualization. Using default");
            }
            var iMesh = new IntermediateMesh();
            // temporary save the mesh data from the template for faster access
            var tVertices = _dataItemMesh.vertices;
            var tNromals  = _dataItemMesh.normals;
            var tUVs      = _dataItemMesh.uv;
            var tIndices  = _dataItemMesh.triangles;

            //int offset = _presenter.SelectedMinItem;
            float divisor = 0;

            MultiDimDataPresenter presenter = (MultiDimDataPresenter)_presenter;

            //TODO find better way to determine divisor (what 100% is)
            for (int valueIndex = 0; valueIndex < presenter[1].Count; valueIndex++)
            {
                float sum = 0;
                for (int dimIndex = 0; dimIndex < presenter.NumberOfDimensions; dimIndex++)
                {
                    sum += VisViewHelper.GetItemValueAbsolute(presenter, dimIndex, valueIndex);
                }
                divisor = Mathf.Max(divisor, sum);
                //Debug.Log("Div " + divisor);
            }
            float startHeight = 0;

            _divisor = divisor;
            //Debug.Log(presenter.CaptionDimension.GetStringValue(ValueIndex));

            for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++)
            {
                float dim;
                if (_useMinIndex)
                {
                    dim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _presenter.SelectedMinItem);
                }
                else
                {
                    dim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex);
                }
                float height = dim / divisor;
                //Debug.Log(presenter[dimIndex].Name + " height " + height+ " dim " + dim +" div " + divisor);
                //var pos = new Vector3(0, startHeight * _size.y, 0);
                var scale      = new Vector3(_size.x, height * _size.y, _size.z);
                var startIndex = iMesh.Vertices.Count;
                foreach (var v in tVertices)
                {
                    var vPos = new Vector3(v.x * scale.x, startHeight * _size.y + v.y * scale.y, v.z * scale.z);
                    iMesh.Vertices.Add(vPos);
                    iMesh.Colors.Add(_style.GetColorCategorical(dimIndex, height));
                }
                iMesh.Normals.AddRange(tNromals);
                iMesh.TexCoords.AddRange(tUVs);
                foreach (var index in tIndices)
                {
                    iMesh.Indices.Add(startIndex + index);
                }
                startHeight += height;
            }

            var mesh       = iMesh.GenerateMesh("StackedBarMesh", MeshTopology.Triangles);
            var meshFilter = GetComponent <MeshFilter>();

            meshFilter.sharedMesh = mesh;
            var meshCollider = GetComponent <MeshCollider>();

            if (meshCollider != null)
            {
                meshCollider.sharedMesh = mesh;
            }
        }
Ejemplo n.º 2
0
        protected override void RebuildVisualization()
        {
            if (_presenter == null || _presenter.NumberOfDimensions < 1)
            {
                Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization");
                return;
            }
            var vertices = new List <Vector3>();
            var colors   = new List <Color>();
            var indices  = new List <int>();

            int   offset   = (int)_presenter.SelectedMinItem;
            int   length   = (int)_presenter.SelectedMaxItem - offset;
            float maxValue = VisViewHelper.GetGlobalMaximum(_presenter);
            float radius   = 0.5f * _size.x;
            float divisor  = 0;

            //TODO find better way to determine divisor (what 100% is)
            for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++)
            {
                divisor += VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue;
            }
            MultiDimDataPresenter presenter = (MultiDimDataPresenter)_presenter;

            Debug.Log(presenter.CaptionDimension.GetStringValue(ValueIndex));

            float startAngle = 0;

            for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++)
            {
                float height = -(VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _3DIndex + offset) / maxValue) * _size.z;

                vertices.Add(new Vector3(0, 0, height));
                int   zeroTop  = vertices.Count - 1;
                float sumOfDim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue;
                float part     = sumOfDim / divisor;
                colors.Add(_style.GetColorCategorical(dimIndex, part));
                float angle    = part * Mathf.PI * 2;
                float endAngle = startAngle + angle;

                List <Vector3> partMeshTop = Circles.CreatePartMesh(startAngle, endAngle, radius, _segments);
                for (int i = 0; i < partMeshTop.Count; i++)
                {
                    partMeshTop[i] = new Vector3(partMeshTop[i].x, partMeshTop[i].y, height);
                }
                for (int vertex = 1; vertex < partMeshTop.Count; vertex++)
                {
                    colors.Add(_style.GetColorCategorical(dimIndex, part));
                    indices.Add(vertices.Count - 1);
                    indices.Add(vertices.Count + vertex);
                    indices.Add(vertices.Count - 1 + vertex);
                }
                colors.Add(_style.GetColorCategorical(dimIndex, part));
                vertices.AddRange(partMeshTop);

                vertices.Add(Vector3.zero);
                int zeroBottom = vertices.Count - 1;
                colors.Add(_style.GetColorCategorical(dimIndex, part));
                List <Vector3> partMeshBottom = Circles.CreatePartMesh(startAngle, endAngle, radius, _segments);
                for (int vertex = 1; vertex < partMeshBottom.Count; vertex++)
                {
                    colors.Add(_style.GetColorCategorical(dimIndex, part));
                    indices.Add(vertices.Count - 1);
                    indices.Add(vertices.Count - 1 + vertex);
                    indices.Add(vertices.Count + vertex);
                }
                colors.Add(_style.GetColorCategorical(dimIndex, part));
                vertices.AddRange(partMeshBottom);

                //adding side quads
                int[] tris = new int[] { zeroTop, zeroTop + 1, zeroBottom + 1, zeroTop, zeroBottom + 1, zeroBottom, zeroTop, vertices.Count - 1, zeroBottom - 1, zeroTop, zeroBottom, vertices.Count - 1 };
                indices.AddRange(tris);

                //adding rounds
                List <int> round = Circles.CreateRound(vertices.Count - partMeshBottom.Count - partMeshTop.Count - 1, partMeshTop.Count - 1, 1);
                indices.AddRange(round);
                startAngle = endAngle;
            }
            var mesh = new Mesh();

            mesh.name     = "PieChart3DMesh";
            mesh.vertices = vertices.ToArray();
            mesh.colors   = colors.ToArray();
            mesh.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0);
            mesh.RecalculateNormals();
            var meshFilter = GetComponent <MeshFilter>();

            meshFilter.sharedMesh = mesh;
        }
Ejemplo n.º 3
0
        protected override void RebuildVisualization()
        {
            if (_presenter == null || _presenter.NumberOfDimensions < 1)
            {
                Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization");
                return;
            }
            var vertices = new List <Vector3>();
            var normals  = new List <Vector3>();
            var colors   = new List <Color>();
            var indices  = new List <int>();

            int   offset   = (int)_presenter.SelectedMinItem;
            int   length   = (int)_presenter.SelectedMaxItem - offset;
            float maxValue = VisViewHelper.GetGlobalMaximum(_presenter);
            float radius   = 0.5f * _size.x;
            float divisor  = 0;

            //TODO find better way to determine divisor (what 100% is)
            for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++)
            {
                divisor += VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue;
            }
            MultiDimDataPresenter presenter = (MultiDimDataPresenter)_presenter;

            float startAngle = 0;

            for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++)
            {
                vertices.Add(Vector3.zero);
                normals.Add(-Vector3.forward);
                float sumOfDim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue;
                float part     = sumOfDim / divisor;
                colors.Add(_style.GetColorCategorical(dimIndex, part));
                float          angle    = part * Mathf.PI * 2;
                float          endAngle = startAngle + angle;
                List <Vector3> partMesh = Circles.CreatePartMesh(startAngle, endAngle, radius, _segments);
                for (int vertex = 1; vertex < partMesh.Count; vertex++)
                {
                    colors.Add(_style.GetColorCategorical(dimIndex, part));
                    normals.Add(-Vector3.forward);
                    indices.Add(vertices.Count - 1);
                    indices.Add(vertices.Count + vertex);
                    indices.Add(vertices.Count - 1 + vertex);
                }
                colors.Add(_style.GetColorCategorical(dimIndex, part));
                normals.Add(-Vector3.forward);
                startAngle = endAngle;
                vertices.AddRange(partMesh);
            }
            var mesh = new Mesh();

            mesh.name     = "PieChart2DMesh";
            mesh.vertices = vertices.ToArray();
            mesh.normals  = normals.ToArray();
            mesh.colors   = colors.ToArray();
            mesh.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0);

            var meshFilter = GetComponent <MeshFilter>();

            meshFilter.sharedMesh = mesh;
        }