예제 #1
0
        long QueryInterval()
        {
            stopwatch.Reset();
            stopwatch.Start();

            float3 randOffset = RandomInsideUnitSphere() * 0.25f;

            float3 min = new float3(1, 1, 1) * 0.25f + RandomInsideUnitSphere() * 0.25f + randOffset;
            float3 max = new float3(1, 1, 1) * 0.75f + RandomInsideUnitSphere() * 0.25f + randOffset;

            results.Clear();
            query.Interval(tree, min, max, results);

            stopwatch.Stop();

            return(stopwatch.ElapsedMilliseconds);
        }
예제 #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();
            }
        }
예제 #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;
            }
        }