public override Centroid GetCentroid() { Centroid cent = default; Centroid ct = default; for (int i = 0; i < mHeModel.FaceStore.Count; i++) { HeFace f = mHeModel.FaceStore[i]; HalfEdge head = f.Head; HalfEdge he = head; int i0 = he.Vertex; int i1 = he.Next.Vertex; int i2 = he.Next.Next.Vertex; ct.set( mHeModel.VertexStore[i0].vector, mHeModel.VertexStore[i1].vector, mHeModel.VertexStore[i2].vector ); cent = cent.Merge(ct); } return(cent); }
/// <summary> /// /// </summary> /// <typeparam name="V"></typeparam> /// <typeparam name="E"></typeparam> /// <typeparam name="F"></typeparam> /// <param name="face"></param> /// <param name="getPosition"></param> /// <returns></returns> public static Polyline ToPolyline <V, E, F>(this HeFace <V, E, F> face) where V : HeVertex <V, E, F>, IPosition3d where E : Halfedge <V, E, F> where F : HeFace <V, E, F> { return(ToPolyline(face, IPosition3d <V> .Get)); }
/// <summary> /// Returns the incircle of a triangular face. /// Assumes face is triangular. /// http://mathworld.wolfram.com/Incenter.html /// </summary> /// <returns></returns> public static Circle GetIncircle <V, E, F>(this HeFace <V, E, F> face) where V : HeVertex <V, E, F>, IPosition3d where E : Halfedge <V, E, F> where F : HeFace <V, E, F> { return(GetIncircle(face, IPosition3d <V> .Get)); }
private void UpdateSegList() { SegList.Clear(); for (int i = 0; i < mHeModel.FaceStore.Count; i++) { HeFace f = mHeModel.FaceStore[i]; HalfEdge head = f.Head; HalfEdge c = head; for (; ;) { HalfEdge next = c.Next; SegList.Add(new IndexPair(c.Vertex, next.Vertex)); c = next; if (c == head) { break; } } } }
public static MpHeFace_v1001 Create(HeFace face) { MpHeFace_v1001 ret = new MpHeFace_v1001(); ret.ID = face.ID; ret.HeadID = face.Head.ID; ret.Normal = face.Normal; return(ret); }
public HeFace Restore(Dictionary <uint, HalfEdge> dic) { HalfEdge he = dic[HeadID]; HeFace ret = new HeFace(he); ret.ID = ID; ret.Normal = Normal; return(ret); }
/// <summary> /// Returns the circumcircle of a triangular face. /// Assumes the face is triangular. /// http://mathworld.wolfram.com/Incenter.html /// </summary> /// <typeparam name="V"></typeparam> /// <typeparam name="E"></typeparam> /// <typeparam name="F"></typeparam> /// <param name="face"></param> /// <param name="getPosition"></param> /// <returns></returns> public static Circle GetCircumcircle <V, E, F>(this HeFace <V, E, F> face, Func <V, Vec3d> getPosition) where V : HeVertex <V, E, F> where E : Halfedge <V, E, F> where F : HeFace <V, E, F> { var he = face.First; Point3d p0 = getPosition(he.Previous.Start); Point3d p1 = getPosition(he.Previous.Start); Point3d p2 = getPosition(he.Next.Start); return(new Circle(p0, p1, p2)); }
public void DrawHarfEdgeModel( DrawBrush brush, DrawPen pen, DrawPen edgePen, double edgeThreshold, HeModel model) { for (int i = 0; i < model.FaceStore.Count; i++) { HeFace f = model.FaceStore[i]; HalfEdge head = f.Head; HalfEdge c = head; HalfEdge pair; for (; ;) { bool edge = false; pair = c.Pair; if (pair == null) { edge = true; } else { double s = CadMath.InnerProduct(model.NormalStore[c.Normal], model.NormalStore[pair.Normal]); if (Math.Abs(s) < edgeThreshold) { edge = true; } } HalfEdge next = c.Next; DrawPen dpen = edge ? edgePen : pen; DrawLine(dpen, model.VertexStore.Ref(c.Vertex).vector, model.VertexStore.Ref(next.Vertex).vector ); c = next; if (c == head) { break; } } } }
/// <summary> /// /// </summary> /// <typeparam name="V"></typeparam> /// <typeparam name="E"></typeparam> /// <typeparam name="F"></typeparam> /// <param name="face"></param> /// <param name="getPosition"></param> /// <returns></returns> public static Polyline ToPolyline <V, E, F>(this HeFace <V, E, F> face, Func <V, Vec3d> getPosition) where V : HeVertex <V, E, F> where E : Halfedge <V, E, F> where F : HeFace <V, E, F> { Polyline result = new Polyline(); foreach (var v in face.Vertices) { var p = getPosition(v); result.Add(p.X, p.Y, p.Z); } result.Add(result.First); return(result); }
private void DrawHeFaces(DrawBrush brush, HeModel model) { if (brush.IsNullBrush) { return; } EnableLight(); for (int i = 0; i < model.FaceStore.Count; i++) { HeFace f = model.FaceStore[i]; HalfEdge head = f.Head; HalfEdge c = head; GL.Begin(PrimitiveType.Polygon); GL.Color4(brush.Color4()); if (f.Normal != HeModel.INVALID_INDEX) { Vector3d nv = model.NormalStore[f.Normal]; GL.Normal3(nv); } for (; ;) { GL.Vertex3((model.VertexStore.Ref(c.Vertex).vector *DC.WorldScale)); c = c.Next; if (c == head) { break; } } GL.End(); } DisableLight(); }
private void DrawHeFacesNormal(HeModel model) { DisableLight(); for (int i = 0; i < model.FaceStore.Count; i++) { HeFace f = model.FaceStore[i]; HalfEdge head = f.Head; HalfEdge c = head; for (; ;) { HalfEdge next = c.Next; Vector3d p = model.VertexStore.Ref(c.Vertex).vector; if (c.Normal != HeModel.INVALID_INDEX) { Vector3d nv = model.NormalStore[c.Normal]; Vector3d np0 = p; Vector3d np1 = p + (nv * 10); DrawArrow(DC.GetPen(DrawTools.PEN_NORMAL), np0, np1, ArrowTypes.CROSS, ArrowPos.END, 3, 3); } c = next; if (c == head) { break; } } } EnableLight(); }
/// <summary> /// Returns the incircle of a triangular face. /// Assumes face is triangular. /// http://mathworld.wolfram.com/Incenter.html /// </summary> /// <returns></returns> public static Circle GetIncircle <V, E, F>(this HeFace <V, E, F> face, Func <V, Vec3d> getPosition) where V : HeVertex <V, E, F> where E : Halfedge <V, E, F> where F : HeFace <V, E, F> { var he = face.First; Vec3d p0 = getPosition(he.Previous.Start); Vec3d p1 = getPosition(he.Start); Vec3d p2 = getPosition(he.Next.Start); double d01 = p0.DistanceTo(p1); double d12 = p1.DistanceTo(p2); double d20 = p2.DistanceTo(p0); var p = (d01 + d12 + d20) * 0.5; // semiperimeter var pInv = 1.0 / p; // inverse semiperimeter var radius = Math.Sqrt(p * (p - d01) * (p - d12) * (p - d20)) * pInv; // triangle area (Heron's formula) / semiperimeter pInv *= 0.5; // inverse perimeter var center = p0 * (d12 * pInv) + p1 * (d20 * pInv) + p2 * (d01 * pInv); return(new Circle(new Plane(p0, p1, (Point3d)p2), center, radius)); }
private void DrawHeEdges(DrawPen borderPen, DrawPen edgePen, double edgeThreshold, HeModel model) { bool drawBorder = !borderPen.IsNullPen; bool drawEdge = !edgePen.IsNullPen; if (!drawBorder && !drawEdge) { return; } DisableLight(); GL.LineWidth(1.0f); Color4 color = borderPen.Color4(); Color4 edgeColor = edgePen.Color4(); Vector3d shift = GetShiftForOutLine(); Vector3d p0; Vector3d p1; for (int i = 0; i < model.FaceStore.Count; i++) { HeFace f = model.FaceStore[i]; HalfEdge head = f.Head; HalfEdge c = head; HalfEdge pair; p0 = model.VertexStore.Ref(c.Vertex).vector *DC.WorldScale + shift; for (; ;) { bool drawAsEdge = false; pair = c.Pair; if (drawEdge) { if (pair == null) { drawAsEdge = true; } else { if (edgeThreshold != 0) { double s = CadMath.InnerProduct(model.NormalStore[c.Normal], model.NormalStore[pair.Normal]); if (Math.Abs(s) <= edgeThreshold) { drawAsEdge = true; } } } } p1 = model.VertexStore.Ref(c.Next.Vertex).vector *DC.WorldScale + shift; if (drawAsEdge) { GL.Color4(edgeColor); GL.Begin(PrimitiveType.Lines); GL.Vertex3(p0); GL.Vertex3(p1); GL.End(); } else { if (drawBorder) { GL.Color4(color); GL.Begin(PrimitiveType.Lines); GL.Vertex3(p0); GL.Vertex3(p1); GL.End(); } } p0 = p1; c = c.Next; if (c == head) { break; } } } }