Esempio n. 1
0
        private SphereModel GetSkeletone(int recursionLevel, CancellationToken token)
        {
            var res = GetBaseSkeleton();

            var bp = res.Item2;
            var triengles = res.Item1;

            var model = new SphereModel(bp);

            for (int i = 0; i < recursionLevel; i++)
            {
                var newTriengles = new List<RefTriengle>();

                foreach (var t in triengles)
                {
                    if (token.IsCancellationRequested)
                        return null;

                    var a = model.MiddlePoint(t.Points[0], t.Points[1]);
                    var b = model.MiddlePoint(t.Points[1], t.Points[2]);
                    var c = model.MiddlePoint(t.Points[2], t.Points[0]);

                    newTriengles.Add(new RefTriengle(t.Points[0], a, c));
                    newTriengles.Add(new RefTriengle(t.Points[1], b, a));
                    newTriengles.Add(new RefTriengle(t.Points[2], c, b));
                    newTriengles.Add(new RefTriengle(a, b, c));
                }

                triengles = newTriengles;
            }

            model.Normalize();
            model.Triengles = triengles;

            return model;
        }
Esempio n. 2
0
        private Tuple<SphereModel, Dictionary<int, List<RefTriengleOptimize>>> GetOptimizeSkeleton(int recursionLevel, CancellationToken token)
        {
            var res = GetBaseSkeleton();

            var bp = res.Item2;
            var triengles = res.Item1;
            var resultDic = new Dictionary<int, List<RefTriengleOptimize>>();

            resultDic[0] = triengles.Select(e => new RefTriengleOptimize(e, 0)).ToList();

            var model = new SphereModel(bp);

            for (int i = 0; i < recursionLevel; i++)
            {
                var parents = resultDic[i];
                var childs = new List<RefTriengleOptimize>();

                foreach (var t in parents)
                {
                    if (token.IsCancellationRequested)
                        return null;

                    var a = model.MiddlePoint(t.Points[0], t.Points[1]);
                    var b = model.MiddlePoint(t.Points[1], t.Points[2]);
                    var c = model.MiddlePoint(t.Points[2], t.Points[0]);

                    var refs = new List<RefTriengleOptimize>
                    {
                        new RefTriengleOptimize(new RefTriengle(t.Points[0], a, c),i+1),
                        new RefTriengleOptimize(new RefTriengle(t.Points[1], b, a),i+1),
                        new RefTriengleOptimize(new RefTriengle(t.Points[2], c, b),i+1),
                        new RefTriengleOptimize(new RefTriengle(a, b, c),i+1)
                    };

                    foreach (var refT in refs)
                        refT.Parent = t;

                    t.Childs = refs.ToArray();
                    childs.AddRange(refs);
                }

                resultDic[i + 1] = childs;
            }

            model.Normalize();
            model.Triengles = triengles;

            return new Tuple<SphereModel, Dictionary<int, List<RefTriengleOptimize>>>(model, resultDic);
        }