Exemplo n.º 1
0
        long QueryKNearest()
        {
            stopwatch.Reset();
            stopwatch.Start();

            float3 position = float3One() * 0.5f + RandomInsideUnitSphere();
            int    k        = 13;

            results.Clear();
            query.KNearest(tree, position, k, results);

            stopwatch.Stop();

            return(stopwatch.ElapsedMilliseconds);
        }
Exemplo n.º 2
0
        private void OnDrawGizmos()
        {
            if (query == null)
            {
                return;
            }

            Vector3 size = 0.2f * Vector3.one;

            for (int i = 0; i < pointCloud.Length; i++)
            {
                Gizmos.DrawCube(pointCloud[i], size);
            }

            var resultIndices = new List <int>();

            Color markColor = Color.red;

            markColor.a  = 0.5f;
            Gizmos.color = markColor;

            switch (QueryType)
            {
            case QType.ClosestPoint: {
                query.ClosestPoint(tree, transform.position, resultIndices);
            }
            break;

            case QType.KNearest: {
                query.KNearest(tree, transform.position, K, resultIndices);
            }
            break;

            case QType.Radius: {
                query.Radius(tree, transform.position, Radius, resultIndices);

                Gizmos.DrawWireSphere(transform.position, Radius);
            }
            break;

            case QType.Interval: {
                query.Interval(tree, transform.position - IntervalSize / 2f, transform.position + IntervalSize / 2f, resultIndices);

                Gizmos.DrawWireCube(transform.position, IntervalSize);
            }
            break;

            default:
                break;
            }

            for (int i = 0; i < resultIndices.Count; i++)
            {
                Gizmos.DrawCube(pointCloud[resultIndices[i]], 2f * size);
            }

            Gizmos.color = Color.green;
            Gizmos.DrawCube(transform.position, 4f * size);

            if (DrawQueryNodes)
            {
                query.DrawLastQuery();
            }
        }
Exemplo n.º 3
0
        void Update()
        {
            Debug.Log(checkObject.transform.position);
            for (int i = 0; i < tree.Count; i++)
            {
                tree.Points[i].Position += LorenzStep(tree.Points[i].Position) * Time.deltaTime * 0.01f;
                var gobj = (GameObject)tree.Points[i].UserObject;
                gobj.GetComponent <Renderer>().material.color = Color.white;
            }


            tree.Rebuild();

            if (query == null)
            {
                return;
            }



            Vector3 size = 0.2f * Vector3.one;

            var resultIndices = new List <int>();

            Color markColor = Color.red;

            markColor.a  = 0.5f;
            Gizmos.color = markColor;

            switch (QueryType)
            {
            case QType.ClosestPoint: {
                query.ClosestPoint(tree, checkObject.transform.position, resultIndices);
            }
            break;

            case QType.KNearest: {
                query.KNearest(tree, checkObject.transform.position, K, resultIndices);
            }
            break;

            case QType.Radius: {
                query.Radius(tree, checkObject.transform.position, Radius, resultIndices);
            }
            break;

            case QType.Interval: {
                query.Interval(tree, checkObject.transform.position - IntervalSize / 2f, checkObject.transform.position + IntervalSize / 2f, resultIndices);
            }
            break;

            default:
                break;
            }

            for (int i = 0; i < resultIndices.Count; i++)
            {
                var gobj = (GameObject)tree.Points[resultIndices[i]].UserObject;
                gobj.GetComponent <Renderer>().material.color = Color.red;
            }
        }