Esempio n. 1
0
        /// <summary>
        /// Generate grid line
        /// </summary>
        /// <returns> [x0,y0,z0,x1,y1,z1][]</returns>
        public static double[][] GenerateGridSegment(ParametricSurface srf, int uDiv, int vDiv)
        {
            double[][]      result = null;
            List <double[]> ls     = new List <double[]>();

            double[][][] gridPoints = GeneratePointGrid(srf, uDiv, vDiv);

            // add vertical segments
            for (int i = 0; i <= uDiv; i++)
            {
                for (int j = 0; j < vDiv; j++)
                {
                    var pt1 = gridPoints[i][j];
                    var pt2 = gridPoints[i][j + 1];
                    ls.Add(pt1.Concat(pt2).ToArray());
                }
            }

            // add horizontal segments
            for (int j = 0; j <= vDiv; j++)
            {
                for (int i = 0; i < uDiv; i++)
                {
                    var pt1 = gridPoints[i][j];
                    var pt2 = gridPoints[i + 1][j];
                    ls.Add(pt1.Concat(pt2).ToArray());
                }
            }

            result = ls.ToArray();

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Generate grid points
        /// </summary>
        public static double[][][] GeneratePointGrid(ParametricSurface srf, int uDiv, int vDiv)
        {
            double[][][] uvMat = GenerateUVGridParameters(uDiv, vDiv);

            var gridPoints = uvMat
                             .Select(n => n.Select(m => srf.ParameterAt(m[0], m[1])).ToArray())
                             .ToArray();

            return(gridPoints);
        }
        public override void Run(RenderControl renderer)
        {
            string fileName = GetResourcePath("Holes.stp");
            var    shape    = StepIO.Open(fileName);

            if (shape == null)
            {
                return;
            }


            var face    = shape.FindChild(EnumTopoShapeType.Topo_FACE, 148);
            var surface = new ParametricSurface(face);

            var wireExp = new WireExplor(face);
            var wires   = wireExp.GetInnerWires();

            foreach (var wire in wires)
            {
                // Show wire
                renderer.ShowShape(wire, Vector3.Red);

                var curve     = new ParametricCurve(wire);
                var paramList = curve.SplitByUniformLength(1, 0.01);

                var  lines = new SegmentsSceneNode((uint)paramList.Count, Vector3.Green, 2);
                uint idx   = 0;
                foreach (var p in paramList)
                {
                    var pt       = curve.Value(p);
                    var pointSur = new ExtremaPointSurface();
                    if (pointSur.Initialize(surface, pt, GP.Resolution(), GP.Resolution()))
                    {
                        var uv     = pointSur.GetParameter(0);
                        var normal = surface.GetNormal(uv.X(), uv.Y());

                        lines.SetPositions(idx++, Vector3.From(pt), Vector3.From(pt.XYZ().Added(normal.XYZ())));
                    }
                }
                lines.UpdateBoundingBox();
                renderer.ShowSceneNode(lines);
            }

            // Show face
            var faceMaterial = MeshStandardMaterial.Create("pbr.face");

            faceMaterial.SetColor(Vector3.LightGray);
            faceMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
            var faceNode = BrepSceneNode.Create(face, faceMaterial, null);

            faceNode.SetDisplayFilter(EnumShapeFilter.Face);
            renderer.ShowSceneNode(faceNode);
        }
Esempio n. 4
0
        public override void OnSelectionChanged(RenderControl render, PickedResult result)
        {
            var item = result.GetItem();

            if (item.GetNode() == null)
            {
                return;
            }
            var ssn = BrepSceneNode.Cast(item.GetNode());

            if (ssn == null)
            {
                return;
            }

            if (item.GetShapeType() == EnumShapeFilter.Face)
            {
                var face = ssn.GetShape().GetShape().FindChild(EnumTopoShapeType.Topo_FACE, (int)item.GetShapeIndex());
                if (face != null)
                {
                    var surface = new ParametricSurface(face);
                    var pt      = item.GetPoint().GetPosition();
                    var param   = surface.ComputeClosestPoint(pt.ToPnt(), GP.Resolution(), GP.Resolution());

                    var values  = surface.D1(param.X(), param.Y());
                    var postion = Vector3.From(values.GetPoint());
                    var vecs    = values.GetVectors();

                    var dir = Vector3.From(vecs[0].Crossed(vecs[1]));
                    dir.normalize();
                    mArrow.SetLocation(postion, dir);
                    mArrow.RequstUpdate();
                    mArrow.Update();

                    render.GetContext().GetSelection().Clear();

                    render.RequestDraw(EnumUpdateFlags.Scene);
                }
            }
        }
        protected override void InitFunction()
        {
            if (this.SourceType == SourceType.Equation)
            {
                _function = new ParametricSurface(_formula, _formulaY, _formulaZ);
            }
            else
            {
//				Parametric3DEvalutor evalutor = new Parametric3DEvalutor();
//				evalutor.Text = this.CodeBody;
//				switch(this.CodeLanguage)
//				{
//					case CodeLanguage.CSharp:
//						evalutor.language= CodeLanguage.CSharp;
//						break;
//					case CodeLanguage.VBNET:
//						evalutor.language = CodeLanguage.VBNET;
//						break;
//				}
//				_function = new Parameter3DFunction(new Parameter3DFunctionDelegate(evalutor.Invoke));
                FunctionEvalutor evalutor = new FunctionEvalutor(this.CodeBody, new string[] { "u", "v" }, this.CodeLanguage);
                _function = new ParametricSurface((ParametricSurfaceDelegate)evalutor.CreateDelegate(typeof(ParametricSurfaceDelegate)));
            }
        }
 public ParametricSurfacePlotter(ParametricSurface function)
 {
     _function = function.ValueAt;
 }