public override bool Run(FeatureContext context) { LineStyle lineStyle = new LineStyle(); lineStyle.SetLineWidth(0.5f); lineStyle.SetColor(ColorValue.RED); var points = new List <Vector3>(); points.Add(new Vector3(0, 0, 0)); points.Add(new Vector3(50, 0, 0)); points.Add(new Vector3(100, 0, 0)); points.Add(new Vector3(0, 50, 0)); points.Add(new Vector3(50, 50, 5)); points.Add(new Vector3(100, 50, -5)); points.Add(new Vector3(0, 150, 5)); points.Add(new Vector3(50, 150, -5)); points.Add(new Vector3(100, 150, 0)); TopoShape face = GlobalInstance.BrepTools.MakeSurfaceFromPoints(points, 3, 3); context.ShowGeometry(face); GeomSurface surface = new GeomSurface(); surface.Initialize(face); double ufirst = surface.FirstUParameter(); double uLarst = surface.LastUParameter(); double vfirst = surface.FirstVParameter(); double vLast = surface.LastVParameter(); double ustep = (uLarst - ufirst) * 0.1; double vstep = (vLast - vfirst) * 0.1; for (double ii = ufirst; ii <= uLarst; ii += ustep) { for (double jj = vfirst; jj <= vLast; jj += vstep) { var data = surface.D1(ii, jj); Vector3 pos = data[0]; Vector3 dirU = data[1]; Vector3 dirV = data[2]; Vector3 dir = dirV.CrossProduct(dirU); //dir.Normalize(); { TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir * 0.01f); SceneNode node = context.ShowGeometry(line); node.SetLineStyle(lineStyle); } } } return(true); }
private void queryToolStripMenuItem_Click(object sender, EventArgs e) { SelectedShapeQuery context = new SelectedShapeQuery(); renderView.QuerySelection(context); TopoShape subShape = context.GetSubGeometry(); SceneNode topoNode = context.GetSubNode(); if (subShape != null) { Console.WriteLine(subShape.GetShapeType()); } Matrix4 shapeTransform = topoNode.GetTransform(); //surface GeomSurface surface = new GeomSurface(); if (surface.Initialize(subShape)) { List <Vector3> ptVecList = new List <Vector3>(); List <Vector3> norVecList = new List <Vector3>(); Console.Write("surface"); //double firstU = surface.FirstUParameter(); //double lastU = surface.LastUParameter(); //double firstV = surface.FirstVParameter(); //double lastV = surface.LastVParameter(); double firstU = surface.FirstUParameter(); double lastU = surface.LastUParameter(); double firstV = surface.FirstVParameter(); double lastV = surface.LastVParameter(); double offSetU = lastU - firstU; double offSetV = lastV - firstV; double stepU = 0.10; double stepV = 10; int stepNoU = (int)(offSetU / stepU); int stepNoV = (int)(offSetV / stepV); for (int v_i = 3; v_i < stepNoV - 5; v_i++) { for (int u_i = 0; u_i < stepNoU; u_i++) { double tempV = firstV + stepV * v_i; double tempU = firstU + stepU * (v_i % 2 == 0 ? u_i : stepNoU - u_i); //double tempV = firstV + stepV * (u_i % 2 == 0 ? v_i : stepNoV - v_i); Vector3 ptVec_1 = surface.Value(tempU, tempV); Vector3 ptVec = shapeTransform.Transform(ptVec_1); Vector3 normalVec_1 = surface.GetNormal(tempU, tempV); //Vector3 normalVec =shapeTransform.Transform(normalVec_1);//matrix3 3*3 Vector3 normalVec = RotateDirVector(shapeTransform, normalVec_1); ptVecList.Add(ptVec); norVecList.Add(normalVec); pathPqList.Add(QuaternionFromTo(new Vector3(-1, 0, 0), normalVec, ptVec)); ShowStatusMessage("path pts No: " + pathPqList.Count); //LineNode tempLineNode = new LineNode(); //LineStyle lineStyle = new LineStyle(); //lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DashedLine); //lineStyle.SetColor(100, 0, 100); //tempLineNode.SetLineStyle(lineStyle); //tempLineNode.Set(ptVec, ptVec + normalVec); //tempLineNode.SetVisible(true); //renderView.SceneManager.AddNode(tempLineNode); //renderView.RequestDraw(); } } //for (int u_i = 0; u_i < stepNoU; u_i++) //{ // for (int v_i = 0; v_i < stepNoV-0; v_i++) // { // double tempU = firstU + stepU * u_i; // double tempV = firstV + stepV * (u_i % 2 == 0 ? v_i : stepNoV - v_i); // Vector3 ptVec =shapeTransform.Transform(surface.Value(tempU,tempV )); // Vector3 normalVec = surface.GetNormal(tempU,tempV); // ptVecList.Add(ptVec); // norVecList.Add(normalVec); // pathPqList.Add(QuaternionFromTo(new Vector3(-1, 0, 0), normalVec, ptVec)); // } //} int a = 0; } //curve GeomCurve curve = new GeomCurve(); if (curve.Initialize(subShape)) { Vector3 startPt = shapeTransform.Transform(curve.D0(curve.FirstParameter())); //Vector3 startPt_ = shapeTransform.Transform(startPt); Vector3 pt1 = curve.GetStartPoint(); Vector3 endPt = shapeTransform.Transform(curve.D0(curve.LastParameter())); Vector3 pt2 = curve.GetEndPoint(); switch ((EnumCurveType)curve.GetCurveType()) { case EnumCurveType.CurveType_OtherCurve: Console.Write("other"); break; case EnumCurveType.CurveType_BSplineCurve: break; case EnumCurveType.CurveType_BezierCurve: break; case EnumCurveType.CurveType_Parabola: break; case EnumCurveType.CurveType_Hyperbola: break; case EnumCurveType.CurveType_Ellipse: break; case EnumCurveType.CurveType_Circle: Console.Write("Circle"); break; case EnumCurveType.CurveType_Line: Console.Write("Line"); //path double[] startPt_ = new double[3] { startPt.X, startPt.Y, startPt.Z }; double[] endPt_ = new double[3] { endPt.X, endPt.Y, endPt.Z }; Path_U.Interpolation(startPt_, endPt_, 0.01, ref pathPtList); //show pick result LineNode tempLineNode = new LineNode(); LineStyle lineStyle = new LineStyle(); lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DashedLine); lineStyle.SetColor(100, 0, 100); tempLineNode.SetLineStyle(lineStyle); tempLineNode.Set(new Vector3(startPt.X + 0.1, startPt.Y + 10, startPt.Z + 0.1), endPt); tempLineNode.SetVisible(true); renderView.SceneManager.AddNode(tempLineNode); renderView.RequestDraw(); break; default: break; } ElementId id = context.GetNodeId(); MessageBox.Show(id.AsInt().ToString()); //... } }
private void surfaceToolStripMenuItem_Click(object sender, EventArgs e) { Platform.LineStyle lineStyle = new Platform.LineStyle(); lineStyle.SetLineWidth(0.5f); lineStyle.SetColor(ColorValue.RED); var points = new System.Collections.Generic.List<Vector3>(); points.Add(new Vector3(0, 0, 0)); points.Add(new Vector3(50, 0, 0)); points.Add(new Vector3(100, 0, 0)); points.Add(new Vector3(0, 50, 0)); points.Add(new Vector3(50, 50, 5)); points.Add(new Vector3(100, 50, -5)); points.Add(new Vector3(0, 150, 5)); points.Add(new Vector3(50, 150, -5)); points.Add(new Vector3(100, 150, 0)); TopoShape face = GlobalInstance.BrepTools.MakeSurfaceFromPoints(points, 3, 3); renderView.ShowGeometry(face, 101); GeomSurface surface = new GeomSurface(); surface.Initialize(face); float ufirst = surface.FirstUParameter(); float uLarst = surface.LastUParameter(); float vfirst = surface.FirstVParameter(); float vLast = surface.LastVParameter(); float ustep = (uLarst - ufirst) * 0.1f; float vstep = (vLast - vfirst) * 0.1f; for(float ii=ufirst; ii<=uLarst; ii+= ustep) for (float jj = vfirst; jj <= vLast; jj += vstep) { var data = surface.D1(ii, jj); Vector3 pos = data[0]; Vector3 dirU = data[1]; Vector3 dirV = data[2]; Vector3 dir = dirV.CrossProduct(dirU); dir.Normalize(); { Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir*10.0f); Platform.SceneNode node = renderView.ShowGeometry(line, 101); node.SetLineStyle(lineStyle); } } TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(face); float area = property.SurfaceArea(); TextNode text = new TextNode(); text.SetText(String.Format("Surface Area: {0}", area)); text.SetPosition(new Vector3(100, 100, 0)); renderView.SceneManager.ClearNodes2d(); renderView.SceneManager.AddNode2d(text); renderView.RequestDraw(); }
private BendHelper BendDown(TopoShape face, TopoShape line, Bending bending) { #region 计算平面法向量 GeomSurface surface = new GeomSurface(); surface.Initialize(face); //参数域UV范围 double uFirst = surface.FirstUParameter(); double uLast = surface.LastUParameter(); double vFirst = surface.FirstVParameter(); double vLast = surface.LastVParameter(); //取中点 double umid = uFirst + (uLast - uFirst) * 0.5f; double vmid = vFirst + (vLast - vFirst) * 0.5f; //计算法向量 var data = surface.D1(umid, vmid); Vector3 dirU = data[1]; Vector3 dirV = data[2]; Vector3 dirF = dirV.CrossProduct(dirU); dirF.Normalize(); #endregion #region 计算边线参数 GeomCurve curve = new GeomCurve(); curve.Initialize(line); Vector3 dirL = curve.DN(curve.FirstParameter(), 1); Vector3 stPt = curve.Value(curve.FirstParameter()); //起点 Vector3 edPt = curve.Value(curve.LastParameter()); //终点 #endregion #region 绘制草图 TopoShapeGroup lineGroup = new TopoShapeGroup(); Vector3 center = stPt + dirF * bending.Radius; //圆心 Vector3 radius = stPt - center; //半径 double theta = bending.Angle * (Math.PI / 180.0); Vector3 radius2 = radius * Math.Cos(theta) + dirL.CrossProduct(radius) * Math.Sin(theta); Vector3 edArc = center + radius2; //圆弧终点 TopoShape arc = GlobalInstance.BrepTools.MakeArc(stPt, edArc, center, dirL); //绘制圆弧 if (arc != null) { lineGroup.Add(arc); } Vector3 edLine = dirL.CrossProduct(radius2) * (bending.Length / bending.Radius) + edArc; arc = GlobalInstance.BrepTools.MakeLine(edArc, edLine); lineGroup.Add(arc); //扫描生成折弯 TopoShape wireSketch = GlobalInstance.BrepTools.MakeWire(lineGroup); TopoShape sweep; if (wireSketch != null) { sweep = GlobalInstance.BrepTools.Sweep(wireSketch, line, true); } else { sweep = GlobalInstance.BrepTools.Sweep(arc, line, true); } TopoShape oFace = GlobalInstance.BrepTools.Sweep(arc, line, true).GetSubShape(0, 1); TopoShape oEdge = GlobalInstance.BrepTools.MakeLine(edLine, edLine + edPt - stPt); #endregion BendHelper bend = new BendHelper() { Sweep = sweep, EdFace = oFace, EdLine = oEdge }; return(bend); }
private void TransOnSelectBtn_Click(object sender, EventArgs e) { //Get selected shape SelectedShapeQuery context = new SelectedShapeQuery(); renderView.QuerySelection(context); var shape = context.GetGeometry(); var face = context.GetSubGeometry(); if (shape == null) { return; } var center = shape.GetBBox().GetCenter(); #region 计算法向量 GeomSurface surface = new GeomSurface(); surface.Initialize(face); //参数域UV范围 double uFirst = surface.FirstUParameter(); double uLast = surface.LastUParameter(); double vFirst = surface.FirstVParameter(); double vLast = surface.LastVParameter(); //取中点 double umid = uFirst + (uLast - uFirst) * 0.5f; double vmid = vFirst + (vLast - vFirst) * 0.5f; //计算法向量 var data = surface.D1(umid, vmid); Vector3 dirU = data[1]; Vector3 dirV = data[2]; Vector3 dir = dirV.CrossProduct(dirU); dir.Normalize(); Console.WriteLine("\tDir {0}", dir); #endregion #region 坐标变换 Vector3 dirN = new Vector3(); if (face.GetOrientation() == EnumShapeOrientation.ShapeOrientation_REVERSED) { dirN = dir * -1; } else { dirN = dir; } //Translation shape = GlobalInstance.BrepTools.Translate(shape, -center); //Rotation Vector3 dirZ = new Vector3(0, 0, -1); shape = GlobalInstance.BrepTools.Rotation(shape, dirN.CrossProduct(dirZ), dirN.AngleBetween(dirZ)); #endregion #region Render if (shape != null) { topoShape = shape; renderView.ClearScene(); renderView.ShowGeometry(shape, shapeId); } renderView.FitAll(); renderView.RequestDraw(EnumRenderHint.RH_LoadScene); #endregion }
private void TransOnMax(TopoShape shape) { double areaM = 0; Vector3 dirN = new Vector3(); Vector3 pos = new Vector3(); TopoExplor topo = new TopoExplor(); TopoShapeGroup group2 = topo.ExplorFaces(shape); for (int i = 0; i < group2.Size(); i++) { TopoShape face = group2.GetTopoShape(i); #region 计算面积 TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(face); Console.WriteLine("Face {0}:\n\tArea {1}\n\tOrientation {2}", i, property.SurfaceArea(), face.GetOrientation()); #endregion #region 计算法向量 GeomSurface surface = new GeomSurface(); surface.Initialize(face); //参数域UV范围 double uFirst = surface.FirstUParameter(); double uLast = surface.LastUParameter(); double vFirst = surface.FirstVParameter(); double vLast = surface.LastVParameter(); //取中点 double umid = uFirst + (uLast - uFirst) * 0.5f; double vmid = vFirst + (vLast - vFirst) * 0.5f; //计算法向量 var data = surface.D1(umid, vmid); Vector3 dirU = data[1]; Vector3 dirV = data[2]; Vector3 dir = dirV.CrossProduct(dirU); dir.Normalize(); Console.WriteLine("\tDir {0}", dir); #endregion #region 取最大的面 if (property.SurfaceArea() > areaM) { areaM = property.SurfaceArea(); pos = data[0]; Console.WriteLine(data[0]); if (face.GetOrientation() == EnumShapeOrientation.ShapeOrientation_REVERSED) { dirN = dir * -1; } else { dirN = dir; } } #endregion } #region 坐标变换 //Translation shape = GlobalInstance.BrepTools.Translate(shape, -pos); //Rotation Vector3 dirZ = new Vector3(0, 0, -1); shape = GlobalInstance.BrepTools.Rotation(shape, dirN.CrossProduct(dirZ), dirN.AngleBetween(dirZ)); #endregion if (shape != null) { topoShape = shape; renderView.ClearScene(); renderView.ShowGeometry(shape, shapeId); } renderView.FitAll(); renderView.RequestDraw(EnumRenderHint.RH_LoadScene); }