public virtual void Initialize(GenericDataPresenter presenter, GenericAxisView axisViewPrefab = null, GenericVisualizationStyle style = null)
        {
            if (presenter == null)
            {
                throw new ArgumentNullException("Presenter can't be null");
            }
            if (_presenter != null)
            {
                _presenter.DataUpdated -= Presenter_DataUpdated;
            }

            _initialized            = true;
            _fromEditor             = false;
            _presenter              = presenter;
            _presenter.DataUpdated += Presenter_DataUpdated;
            _axisViewPrefab         = axisViewPrefab;
            // if there is no axis prefab, there can be no axis views
            if (_axisViewPrefab == null)
            {
                _showAxes = false;
            }
            // Destroy initial axis views because references to axis presenters somehow gets lost
            // when started from the editor, so we just rebuild them completely
            DestroyAxisViews();
            _style = style;

            Rebuild_Internal();
        }
示例#2
0
 public virtual void Initialize(GenericDataPresenter presenter, GenericAxisView axisViewPrefab = null, GenericVisualizationStyle style = null, Mesh dataItemMesh = null)
 {
     _dataItemMesh = dataItemMesh;
     base.Initialize(presenter, axisViewPrefab, style);
 }
示例#3
0
        private static Mesh CreateGeometry(Vector3[] points, int sides, bool smooth, bool outside, GenericVisualizationStyle style = null, bool isCateg = false, int dimIndex = 0, Mesh sharedMesh = null) //taken from DesginAR
        {
            if (points.Length < 2)
            {
                return(null);
            }
            // smooth meshes have exactly the same points per side as the 2d contour,
            // while for non-smooth every point besides the first and last one is added
            // twice to the list of vertices
            int numPoints = smooth ? points.Length : (points.Length - 1) * 2;

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector2> texcoords = new List <Vector2>();
            List <Color>   colors    = new List <Color>();
            // algorithm runs from zero to one for the angles, steps are determined by the number of sides
            float angleStep = 1.0f / sides;
            float pi2       = Mathf.PI * 2;
            int   length    = smooth ? points.Length : points.Length - 1;

            for (float angle = 0; angle <= 1.0f; angle += angleStep)
            {
                for (int i = 0; i < length; i++)
                {
                    float x, z;
                    CoordinateHelper.ToCartesianCoordinates(points[i].x, angle * pi2, out x, out z);
                    vertices.Add(new Vector3(x, points[i].y, z));
                    if (style != null && !isCateg)
                    {
                        colors.Add(style.GetColorContinous((float)i / (float)length));
                    }
                    if (style != null && isCateg)
                    {
                        colors.Add(style.GetColorCategorical(dimIndex, (float)i / (float)length));
                    }
                    texcoords.Add(new Vector2(angle, (float)i / (float)length));

                    // for non smooth points also add the next point to the list of vertices to create sharp edges
                    if (!smooth)
                    {
                        CoordinateHelper.ToCartesianCoordinates(points[i + 1].x, angle * pi2, out x, out z);
                        vertices.Add(new Vector3(x, points[i + 1].y, z));
                        if (style != null)
                        {
                            colors.Add(style.GetColorContinous((float)i / (float)length));
                        }
                        texcoords.Add(new Vector2(angle, (float)(i + 1) / (float)length));
                    }
                }
            }

            List <int> indices = new List <int>();

            length = smooth ? numPoints - 1 : numPoints;
            int step = smooth ? 1 : 2;

            for (int i = 0; i < sides; i++)
            {
                for (int j = 0; j < length; j += step)
                {
                    int s0 = numPoints * i;
                    int s1 = numPoints * (i + 1);
                    //if (i == _sides - 1)
                    //    s1 = 0;
                    if (outside)
                    {
                        indices.Add(s0 + j);
                        indices.Add(s0 + j + 1);
                        indices.Add(s1 + j);

                        indices.Add(s0 + j + 1);
                        indices.Add(s1 + j + 1);
                        indices.Add(s1 + j);
                    }
                    else
                    {
                        indices.Add(s0 + j);
                        indices.Add(s1 + j);
                        indices.Add(s0 + j + 1);

                        indices.Add(s0 + j + 1);
                        indices.Add(s1 + j);
                        indices.Add(s1 + j + 1);
                    }
                }
            }

            if (sharedMesh == null)
            {
                sharedMesh = new Mesh();
            }
            sharedMesh.Clear();
            sharedMesh.vertices  = vertices.ToArray();
            sharedMesh.uv        = texcoords.ToArray();
            sharedMesh.triangles = indices.ToArray();
            if (style != null)
            {
                sharedMesh.colors = colors.ToArray();
            }
            sharedMesh.RecalculateNormals();
            return(sharedMesh);
        }