Exemplo n.º 1
0
        private void AddSplineCurve()
        {
            var selectedPoints = Points.Where(x => x.Selected).ToList();
            var curve          = new BSplineCurve();

            selectedPoints.ForEach(x => curve.AddPoint(x));
            _listBox.Items.Add(curve);
        }
Exemplo n.º 2
0
        private void Deserialize()
        {
            string filename = string.Empty;

            using (var ofd = new OpenFileDialog())
            {
                var res = ofd.ShowDialog();
                if (res != DialogResult.OK)
                {
                    return;
                }
                else
                {
                    filename = ofd.FileName;
                }
            }

            var f = _listBox.Items[0];

            _listBox.Items.Clear();
            _listBox.Items.Add(f);
            var lines = File.ReadAllLines(filename);

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];

                var spl      = line.Split(' ');
                var expected = int.Parse(spl[1].Trim());
                i++;
                var type = spl[0].Trim();
                switch (type)
                {
                case "curveC0":
                    for (int j = 0; j < expected; j++, i++)
                    {
                        var curve = new BezierCurve(lines[i]);
                        _listBox.Items.Add(curve);
                        curve.Points.ForEach(p => _listBox.Items.Add(p));
                    }
                    break;

                case "curveC2":
                    for (int j = 0; j < expected; j++, i++)
                    {
                        var curve = new BSplineCurve(lines[i]);
                        _listBox.Items.Add(curve);
                        curve.Points.ForEach(p => _listBox.Items.Add(p));
                    }
                    break;

                case "curveInt":
                    for (int j = 0; j < expected; j++, i++)
                    {
                        var curve = new InterpolatingBSpline(lines[i]);
                        _listBox.Items.Add(curve);
                        curve.Points.ForEach(p => _listBox.Items.Add(p));
                    }
                    break;

                case "surfaceC0":
                    for (int j = 0; j < expected; j++, i++)
                    {
                        var surf = new BasicSurface(lines[i], false);
                        //if (surf.Name == "ucho")
                        //{
                        //    var surf2 = new BasicSurface(lines[i], false);
                        //    surf2.Points.ToList().ForEach(x => x.X = -x.X);
                        //    surf2.Name = "ucho2";
                        //    _listBox.Items.Add(surf2);
                        //}
                        _listBox.Items.Add(surf);
                    }
                    break;

                case "tubeC0":
                    for (int j = 0; j < expected; j++, i++)
                    {
                        _listBox.Items.Add(new BasicSurface(lines[i], true));
                    }
                    break;

                case "surfaceC2":
                    for (int j = 0; j < expected; j++, i++)
                    {
                        var surf = new BSplineSurface(lines[i], false);
                        _listBox.Items.Add(surf);
                    }
                    break;

                case "tubeC2":
                    for (int j = 0; j < expected; j++, i++)
                    {
                        var surf = new BSplineSurface(lines[i], true);
                        if (surf.Name == "noga1")
                        {
                            //var surf2 = new BSplineSurface(lines[i], true);
                            //surf2.Points.ToList().ForEach(x => x.X = -x.X);
                            //surf2.Name = "noga3";
                            //_listBox.Items.Add(surf2);
                        }
                        else if (surf.Name == "noga2")
                        {
                            //var surf2 = new BSplineSurface(lines[i], true);
                            //surf2.Points.ToList().ForEach(x => x.X = -x.X);
                            //surf2.Name = "noga4";
                            //_listBox.Items.Add(surf2);
                        }
                        else
                        {
                            // var points = surf.Points.ToList();

                            // //for(int k=0;k<points.Count;k++)
                            // //{
                            // //    var p = points[k];
                            // //    var p2 = points[k+2];
                            // //    points[k + 2].Point = new Vector4(-p.X, p2.Y, p.Z, 1);
                            // //    if (k % 4 == 1)
                            // //        k += 2;
                            // //}

                            // var bigX = points.Where(x => x.X  >0).ToList();
                            // foreach(var p in bigX)
                            // {
                            //     var mirror = new Vector4(-p.X, p.Y, p.Z, 1);
                            //     var matched = points.OrderBy(x => Vector4.DistanceSquared(x.Point, mirror)).ToList();
                            //     var best = matched.First();
                            //     best.Point = mirror;
                            //     if (best == p)
                            //         p.X = 0;
                            // }
                        }
                        _listBox.Items.Add(surf);
                    }
                    break;

                default:
                    break;
                }
                i--;
            }
        }
Exemplo n.º 3
0
        public List <Vector4> GetPoints(int count)
        {
            var list = new List <Vector4>();

            count /= 8;

            for (int patchU = 3; patchU < _countU; patchU++)
            {
                var startV = _isTube ? 0 : 3;
                for (int patchV = startV; patchV < _countV; patchV++)
                {
                    var p = GetDeBoorPoints(patchU, patchV);

                    for (float curveU = 0; curveU <= 1.0; curveU += 1.0f / (DivisionsU - 1))
                    {
                        var u1 = BSplineCurve.GetFirstPart(curveU);
                        var u2 = BSplineCurve.GetSecondPart(curveU);
                        var u3 = BSplineCurve.GetThirdPart(curveU);
                        var u4 = BSplineCurve.GetFourthPart(curveU);

                        var paramU = (int)((patchU - 3 + curveU) * ParameterRangePrecision / (_countU - 3));

                        for (float t = 0; t < 1.0f; t += 1.0f / count)
                        {
                            if (Trimmed)
                            {
                                var paramV = (int)((patchV - startV + t) * ParameterRangePrecision / (_countV - startV));
                                if (!ParameterRange[paramU, paramV])
                                {
                                    continue;
                                }
                            }

                            var t1    = t * t * t / 6;
                            var t2    = (1 + 3 * t + 3 * t * t - 3 * t * t * t) / 6;
                            var t3    = (4 - 6 * t * t + 3 * t * t * t) / 6;
                            var t4    = (1 - t) * (1 - t) * (1 - t) / 6;
                            var point =
                                u1 * t1 * p[0] + u1 * t2 * p[1] + u1 * t3 * p[2] + u1 * t4 * p[3] +
                                u2 * t1 * p[4] + u2 * t2 * p[5] + u2 * t3 * p[6] + u2 * t4 * p[7] +
                                u3 * t1 * p[8] + u3 * t2 * p[9] + u3 * t3 * p[10] + u3 * t4 * p[11] +
                                u4 * t1 * p[12] + u4 * t2 * p[13] + u4 * t3 * p[14] + u4 * t4 * p[15];

                            list.Add(point);
                        }
                    }

                    for (float curveV = 0; curveV <= 1.0; curveV += 1.0f / (DivisionsV - 1))
                    {
                        var u1 = BSplineCurve.GetFirstPart(curveV);
                        var u2 = BSplineCurve.GetSecondPart(curveV);
                        var u3 = BSplineCurve.GetThirdPart(curveV);
                        var u4 = BSplineCurve.GetFourthPart(curveV);

                        var paramV = (int)((patchV - startV + curveV) * ParameterRangePrecision / (_countV - startV));

                        for (float t = 0; t < 1.0f; t += 1.0f / count)
                        {
                            if (Trimmed)
                            {
                                var paramU = (int)((patchU - 3 + t) * ParameterRangePrecision / (_countU - 3));
                                if (!ParameterRange[paramU, paramV])
                                {
                                    continue;
                                }
                            }

                            var t1    = t * t * t / 6;
                            var t2    = (1 + 3 * t + 3 * t * t - 3 * t * t * t) / 6;
                            var t3    = (4 - 6 * t * t + 3 * t * t * t) / 6;
                            var t4    = (1 - t) * (1 - t) * (1 - t) / 6;
                            var point =
                                t1 * u1 * p[0] + t1 * u2 * p[1] + t1 * u3 * p[2] + t1 * u4 * p[3] +
                                t2 * u1 * p[4] + t2 * u2 * p[5] + t2 * u3 * p[6] + t2 * u4 * p[7] +
                                t3 * u1 * p[8] + t3 * u2 * p[9] + t3 * u3 * p[10] + t3 * u4 * p[11] +
                                t4 * u1 * p[12] + t4 * u2 * p[13] + t4 * u3 * p[14] + t4 * u4 * p[15];

                            list.Add(point);
                        }
                    }
                }
            }

            return(list);
        }