public void Face_VoronoiFortune() { List <VertexKDTree> listPointsFortune = new List <VertexKDTree>(); string fileNameLong = pathUnitTests + "\\KinectFace_1_15000.obj"; pointCloudSource = IOUtils.ReadObjFile_ToPointCloud(fileNameLong); for (int i = 0; i < pointCloudSource.Count; i++) { VertexKDTree v = new VertexKDTree(new Vector3(pointCloudSource[i].Vector.X, pointCloudSource[i].Vector.Y, pointCloudSource[i].Vector.Z), i); listPointsFortune.Add(v); } List <EdgeFortune> listEdges; Voronoi voronoi = new Voronoi(0.1f); listEdges = voronoi.GenerateVoronoi(listPointsFortune); List <LineD> myLines = new List <LineD>(); for (int i = 0; i < listEdges.Count; i++) { EdgeFortune edge = listEdges[i]; myLines.Add(new LineD(pointCloudSource[edge.PointIndex1].Vector, pointCloudSource[edge.PointIndex2].Vector)); } //------------------- ShowPointCloud(pointCloudSource); }
/// <summary> /// 获取Voronoi多边形的线 /// </summary> /// <param name="points"></param> /// <param name="envelope"></param> /// <param name="minDistanceTolerance"></param> /// <returns></returns> public static List <GraphEdge> BuildLine(List <TysonGeoPoint> points, double[] envelope = null, double minDistanceTolerance = 1e-8) { envelope ??= GetEnvelope(points); double[] xVal = new double[points.Count]; double[] yVal = new double[points.Count]; var i = 0; foreach (var point in points) { xVal[i] = point.X; yVal[i] = point.Y; i += 1; } var voronoiObject = new Voronoi(minDistanceTolerance); var graphEdgeList = voronoiObject.GenerateVoronoi(xVal, yVal, envelope[0], envelope[2], envelope[1], envelope[3]); var graphEdges = new HashSet <GraphEdge>(graphEdgeList).ToList(); var index = 0; var removeIndexs = new HashSet <int>(); foreach (var graphEdge in graphEdges) { var edgeLinePt1 = graphEdge.Start; var edgeLinePt2 = graphEdge.End; if (edgeLinePt1 == edgeLinePt2) { removeIndexs.Add(index); } index++; } removeIndexs.Reverse(); foreach (var i1 in removeIndexs) { graphEdges.RemoveAt(i1); } return(graphEdges); }
public void Face_VoronoiFortune_AsTriangles() { List <VertexKDTree> listPointsFortune = new List <VertexKDTree>(); string fileNameLong = pathUnitTests + "\\KinectFace_1_15000.obj"; pointCloudSource = IOUtils.ReadObjFile_ToPointCloud(fileNameLong); for (int i = 0; i < pointCloudSource.Count; i++) { VertexKDTree v = new VertexKDTree(new Vector3(pointCloudSource[i].Vector.X, pointCloudSource[i].Vector.Y, pointCloudSource[i].Vector.Z), i); listPointsFortune.Add(v); } List <EdgeFortune> listEdges; Voronoi voronoi = new Voronoi(0.1f); listEdges = voronoi.GenerateVoronoi(listPointsFortune); List <Triangle> listTriangle = new List <Triangle>(); for (int i = 0; i < listEdges.Count; i += 3) { EdgeFortune edge = listEdges[i]; Triangle t = new Triangle(); //t.IndVertices.Add(cell.Vertices[0].IndexInPointCloud); //t.IndVertices.Add(cell.Vertices[1].IndexInPointCloud); //t.IndVertices.Add(cell.Vertices[2].IndexInPointCloud); listTriangle.Add(t); //myLines.Add(pointCloud[edge.PointIndex1]); //myLinesTo.Add(pointCloud[edge.PointIndex2]); } //------------------- ShowPointCloud(pointCloudSource); }