public override bool Run(FeatureContext context) { 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); TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(face); MessageBox.Show(String.Format("Area: {0}", property.SurfaceArea())); return(true); }
private void OnSelectElement(SelectionChangeArgs args) { if (!args.IsHighlightMode()) { SelectedShapeQuery query = new SelectedShapeQuery(); renderView.QuerySelection(query); var ids = query.GetIds(); if (ids.Length > 0) { var shape = query.GetGeometry(); if (shape != null) { GeomCurve curve = new GeomCurve(); if (curve.Initialize(shape)) { TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(shape); var str = String.Format("Length:{0}", property.EdgeLength()); toolStripStatusLabel2.Text = str; return; } } } else { toolStripStatusLabel2.Text = ""; } } }
public override bool Run(FeatureContext context) { TopoShape box = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(100, 100, 100)); context.ShowGeometry(box); TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(box); MessageBox.Show(String.Format("Area: {0}", property.SolidVolume())); return(true); }
public override bool Run(FeatureContext context) { TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z); context.ShowGeometry(arc); TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(arc); double length = property.EdgeLength(); MessageBox.Show(String.Format("Length: {0}", length)); return(true); }
private void OnSelectElement(SelectionChangeArgs args) { if (!args.IsHighlightMode()) { SelectedShapeQuery query = new SelectedShapeQuery(); renderView.QuerySelection(query); var shape = query.GetGeometry(); if (shape != null) { GeomCurve curve = new GeomCurve(); if (curve.Initialize(shape)) { TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(shape); Console.WriteLine("Edge Length {0}", property.EdgeLength()); } } } }
public Solid(TopoShape solid) { BoundingBox = solid.GetBBox(); var faces = GlobalInstance.TopoExplor.ExplorFaces(solid); TopoShapeProperty prop = new TopoShapeProperty(); List <FaceInfo> dictFaceByArea = new List <FaceInfo>(); for (int ii = 0; ii < faces.Size(); ++ii) { var face = faces.GetAt(ii); prop.SetShape(face); double area = prop.SurfaceArea(); var faceInfo = new FaceInfo(face, ii, area); dictFaceByArea.Add(faceInfo); Faces.Add(ii, faceInfo); } dictFaceByArea.Sort((a, b) => { return((int)((b.Area - a.Area) * 1000)); }); var baseFace = dictFaceByArea[0]; foreach (var item in baseFace.Edges) { EdgeGroup eg = new EdgeGroup(item.Value); EdgeGroups.Add(eg); } for (int ii = 2; ii < dictFaceByArea.Count; ++ii) { var faceInfo = dictFaceByArea[ii]; if (AddLongFace(faceInfo)) { continue; } AddSideFace(faceInfo); } }
public FaceInfo(TopoShape face, int idx, double area) { Surface = new GeomSurface(); Surface.Initialize(face); Index = idx; Area = area; Direction = Surface.GetNormal(Surface.FirstUParameter(), Surface.FirstVParameter()); TopoShapeProperty prop = new TopoShapeProperty(); var edges = GlobalInstance.TopoExplor.ExplorEdges(face); for (int jj = 0; jj < edges.Size(); ++jj) { var edge = edges.GetAt(jj); prop.SetShape(edge); var edgeInfo = new EdgeInfo(edge, jj, idx, prop.EdgeLength()); // 只加直线? Edges.Add(jj, edgeInfo); } }
private void surfaceToolStripMenuItem_Click(object sender, EventArgs e) { LineStyle lineStyle = new LineStyle(); lineStyle.SetLineWidth(0.5f); lineStyle.SetColor(ColorValue.RED); Vector3List points = new Vector3List(); 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, ++shapeId); GeomeSurface surface = new GeomeSurface(); 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) { Vector3List data = surface.D1(ii, jj); Vector3 pos = data.Get(0); Vector3 dirU = data.Get(1); Vector3 dirV = data.Get(2); Vector3 dir = dirV.CrossProduct(dirU); dir.Normalize(); { TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir * 10.0f); SceneNode node = renderView.ShowGeometry(line, ++shapeId); 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 void curveToolStripMenuItem_Click(object sender, EventArgs e) { renderView.View3d.SetStandardView(3); LineStyle lineStyle = new LineStyle(); lineStyle.SetLineWidth(0.5f); lineStyle.SetColor(ColorValue.BLUE); LineStyle lineStyle2 = new LineStyle(); lineStyle2.SetLineWidth(0.5f); lineStyle2.SetColor(ColorValue.GREEN); TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z); renderView.ShowGeometry(arc, ++shapeId); { GeomeCurve curve = new GeomeCurve(); curve.Initialize(arc); float paramStart = curve.FirstParameter(); float paramEnd = curve.LastParameter(); float step = (paramEnd - paramStart) * 0.1f; for (float uu = paramStart; uu <= paramEnd; uu += step) { Vector3 dir = curve.DN(uu, 1); Vector3 pos = curve.Value(uu); // 切线 { TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir); SceneNode node = renderView.ShowGeometry(line, ++shapeId); node.SetLineStyle(lineStyle); } // 法线 { Vector3 dirN = dir.CrossProduct(Vector3.UNIT_Z); TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dirN); SceneNode node = renderView.ShowGeometry(line, ++shapeId); node.SetLineStyle(lineStyle2); } } } TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(arc); float len = property.EdgeLength(); TextNode text = new TextNode(); text.SetText(String.Format("Arc Length: {0}", len)); text.SetPosition(new Vector3(100, 100, 0)); renderView.SceneManager.ClearNodes2d(); renderView.SceneManager.AddNode2d(text); renderView.RequestDraw(); }
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 void curveToolStripMenuItem_Click(object sender, EventArgs e) { renderView.SetStandardView(EnumStandardView.SV_Top); Platform.LineStyle lineStyle = new Platform.LineStyle(); lineStyle.SetLineWidth(0.5f); lineStyle.SetColor(ColorValue.BLUE); Platform.LineStyle lineStyle2 = new Platform.LineStyle(); lineStyle2.SetLineWidth(0.5f); lineStyle2.SetColor(ColorValue.GREEN); Platform.TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z); renderView.ShowGeometry(arc, 100); { GeomCurve curve = new GeomCurve(); curve.Initialize(arc); float paramStart = curve.FirstParameter(); float paramEnd = curve.LastParameter(); float step = (paramEnd - paramStart) * 0.1f; for (float uu = paramStart; uu <= paramEnd; uu += step) { Vector3 dir = curve.DN(uu, 1); Vector3 pos = curve.Value(uu); // 切线 { Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir); Platform.SceneNode node = renderView.ShowGeometry(line, 101); node.SetLineStyle(lineStyle); } // 法线 { Vector3 dirN = dir.CrossProduct(Vector3.UNIT_Z); Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dirN); Platform.SceneNode node = renderView.ShowGeometry(line, 101); node.SetLineStyle(lineStyle2); } } } TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(arc); float len = property.EdgeLength(); TextNode text = new TextNode(); text.SetText(String.Format("Arc Length: {0}", len)); text.SetPosition(new Vector3(100, 100, 0)); renderView.SceneManager.ClearNodes2d(); renderView.SceneManager.AddNode2d(text); renderView.RequestDraw(); }
private void solidToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "STL (*.stl)|*.stl|IGES (*.igs;*.iges)|*.igs;*.iges|STEP (*.stp;*.step)|*.stp;*.step|BREP (*.brep)|*.brep|All Files(*.*)|*.*"; if (DialogResult.OK != dlg.ShowDialog()) return; TopoShape shape = GlobalInstance.BrepTools.LoadFile(new AnyCAD.Platform.Path(dlg.FileName)); renderView.ShowGeometry(shape, 100); //TopoExplor explor = new TopoExplor(); //TopoShapeGroup solids = explor.ExplorSolids(shape); //float vol = 0; //for(int ii=0; ii<solids.Size(); ++ii) //{ // TopoShapeProperty property = new TopoShapeProperty(); // property.SetShape(solids.GetAt(ii)); // vol += property.SolidVolume(); //} TopoExplor explor = new TopoExplor(); TopoShapeGroup faces = explor.ExplorFaces(shape); TopoShape solid = GlobalInstance.BrepTools.MakeSolid(faces); TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(solid); float vol = property.SolidVolume(); MessageBox.Show(String.Format("{0}", vol)); }
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); }