public void IntersectVoronoi(Plane3 <double> myPlane) { SetVertexConditions(myPlane); SetHullVoronoiFromEdges(myPlane); ClearPointsWithNegativeDistanceToPlaneFromHull(); ////////////////////////////////// //TODO AddEdges(myPlane); }
private void SetHullVoronoiFromEdges(Plane3 <double> myPlane) { /////////////////////// int ii = 0; while (ii < Edges.Count) { if (Edges[ii].p1.Condition == 0 && Edges[ii].p2.Condition == 0) { Edges.RemoveAt(ii); } else if (Edges[ii].p1.Condition == 1 && Edges[ii].p2.Condition == 0) { Edges.RemoveAt(ii); } else if (Edges[ii].p1.Condition == 1 && Edges[ii].p2.Condition == 1) { Edges.RemoveAt(ii); } else if (Edges[ii].p1.Condition == 0 && Edges[ii].p2.Condition == 1) { Edges.RemoveAt(ii); } else if (Edges[ii].p1.Condition == 0 && Edges[ii].p2.Condition == 2) { //double u; Line3 <double> line = new Line3 <double>(Edges[ii].p1.Vector, Edges[ii].p2.Vector); Vector3 <double> vIntersect = myPlane.Intersect(line); //Rhino.Geometry.Intersect.Intersection.Line3<double>Plane(line, p, out u); //pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u)))); Vertices.Add(new VertexHull(vIntersect, this.Center.DistanceTo(vIntersect, 1))); VertexHull vert = new VertexHull(vIntersect, this.Center.DistanceTo(vIntersect, 1)); Vertices.Add(vert); Edges[ii].p1 = Vertices[Vertices.Count - 1]; ii++; } else if (Edges[ii].p1.Condition == 2 && Edges[ii].p2.Condition == 0) { //double u; Line3 <double> line = new Line3 <double>(Edges[ii].p1.Vector, Edges[ii].p2.Vector); Vector3 <double> vIntersect = myPlane.Intersect(line); //TODO Rhino.Geometry.Intersect.Intersection.Line3<double>Plane(line, p, out u); //pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u)))); Vertices.Add(new VertexHull(vIntersect, this.Center.DistanceTo(vIntersect, 1))); Edges[ii].p2 = Vertices[Vertices.Count - 1]; ii++; } else { ii++; } } }
public List <Line3 <float> > ComputeVoronoi3d(List <Line3 <float> > myLines, List <Vector3 <float> > myPCL) { Box hu = new Box(myLines); Hull[] hulls = new Hull[myPCL.Count]; /* * for (int ii = 0;ii < y.Count;ii++){ * hull h = new hull(hu, y[ii]); * for(int i = 0;i < y.Count;i++){ * if( i != ii && y[i].DistanceTo(y[ii]) < h.R * 2){ * Line3<float> cen = new Line3<float>(y[ii]);cen += y[i];cen /= 2; * Vector3<float> v = y[ii] - y[i]; * Plane3<float> plane = new Plane3<float>(cen, v); * h.IntersectVoronoi(plane);} * } * hulls.Add(h); * } */ ///* // System.Threading.Tasks.Parallel.ForEach(y, pt => // { System.Threading.Tasks.Parallel.For(0, myPCL.Count, (iii) => { Vector3 <float> pt = myPCL[iii]; Hull h = new Hull(hu, pt); for (int i = 0; i < myPCL.Count; i++) { float t = myPCL[i].DistanceTo(pt, 1); if (t > 0.001 && t < h.R * 2) { Vector3 <float> cen = new Vector3 <float>(pt); cen += myPCL[i]; cen /= 2; Vector3 <float> v = pt - myPCL[i]; Plane3 <float> plane = new Plane3 <float>(cen, v, 1); h.IntersectVoronoi(plane); } } hulls[iii] = h; }); // */ List <Line3 <float> > tree = new List <Line3 <float> >(); for (int k = 0; k < hulls.Length; k++) { Hull h = hulls[k]; for (int i = 0; i < h.Edges.Count; i++) { tree.Add(new Line3 <float>(h.Edges[i].p1.Vector, h.Edges[i].p2.Vector)); } } return(tree); }
/// <summary> /// according to distance to plane /// </summary> /// <param name="myPlane"></param> private void SetVertexConditions(Plane3 <double> myPlane) { for (int i = 0; i < Vertices.Count; i++) { double db = myPlane.DistanceTo(Vertices[i].Vector); if (Math.Abs(db) < GeneralSettings.AbsoluteTolerance) { Vertices[i].Condition = 1; } else if (db > 0) { Vertices[i].Condition = 2; } else if (db < 0) { Vertices[i].Condition = 0; } } }
/// <summary> /// according to distance to plane /// </summary> /// <param name="myPlane"></param> private void SetVertexConditions(Plane3 <float> myPlane) { for (int i = 0; i < Vertices.Count; i++) { float db = myPlane.DistanceTo(Vertices[i].Vector); if (Math.Abs(db) < GlobalVariables.AbsoluteTolerance) { Vertices[i].Condition = 1; } else if (db > 0) { Vertices[i].Condition = 2; } else if (db < 0) { Vertices[i].Condition = 0; } } }
private static bool Equals(ref Plane3 <T> v1, ref Plane3 <T> v2) { return(EqualityComparer <Vector3d <T> > .Default.Equals(v1.normal, v2.normal) && EqualityComparer <Numeric <T> > .Default.Equals(v1.distance, v2.distance)); }
public bool Equals(Plane3 <T> other) { return(Equals(this, other)); }