public List <Line> ComputeVoronoi3d(List <Line> x, List <Point3d> y)
        {
            box hu = new box(x);

            hull[] hulls = new hull[y.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){
             *          Point3d cen = new Point3d(y[ii]);cen += y[i];cen /= 2;
             *          Vector3d v = y[ii] - y[i];
             *          Plane plane = new Plane(cen, v);
             *          h.intersect(plane);}
             *      }
             *      hulls.Add(h);
             *    }
             */
            ///*
            //  System.Threading.Tasks.Parallel.ForEach(y, pt =>
            // {
            System.Threading.Tasks.Parallel.For(0, y.Count, (iii) =>
            {
                Point3d pt = y[iii];
                hull h     = new hull(hu, pt);
                for (int i = 0; i < y.Count; i++)
                {
                    double t = y[i].DistanceTo(pt);
                    if (t > 0.001 && t < h.R * 2)
                    {
                        Point3d cen = new Point3d(pt); cen += y[i]; cen /= 2;
                        Vector3d v  = pt - y[i];
                        Plane plane = new Plane(cen, v);
                        h.intersect(plane);
                    }
                }
                hulls[iii] = h;
            });
            //  */
            List <Line> tree = new List <Line>();

            for (int k = 0; k < hulls.Length; k++)
            {
                hull h = hulls[k];
                for (int i = 0; i < h.edges.Count; i++)
                {
                    tree.Add(new Line(h.edges[i].p1.pos, h.edges[i].p2.pos));
                }
            }
            return(tree);
        }
示例#2
0
 public List<Line> ComputeVoronoi3d(List<Line> x, List<Point3d> y)
 {
     box hu = new box(x);
     hull[] hulls = new hull[y.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){
                 Point3d cen = new Point3d(y[ii]);cen += y[i];cen /= 2;
                 Vector3d v = y[ii] - y[i];
                 Plane plane = new Plane(cen, v);
                 h.intersect(plane);}
             }
             hulls.Add(h);
           }
     */
     ///*
     //  System.Threading.Tasks.Parallel.ForEach(y, pt =>
     // {
     System.Threading.Tasks.Parallel.For(0, y.Count, (iii) =>
          {
              Point3d pt = y[iii];
              hull h = new hull(hu, pt);
              for (int i = 0; i < y.Count; i++)
              {
                  double t = y[i].DistanceTo(pt);
                  if (t > 0.001 && t < h.R * 2)
                  {
                      Point3d cen = new Point3d(pt); cen += y[i]; cen /= 2;
                      Vector3d v = pt - y[i];
                      Plane plane = new Plane(cen, v);
                      h.intersect(plane);
                  }
              }
              hulls[iii] = h;
          });
     //  */
     List<Line> tree = new List<Line>();
     for (int k = 0; k < hulls.Length; k++)
     {
         hull h = hulls[k];
         for (int i = 0; i < h.edges.Count; i++)
         {
             tree.Add(new Line(h.edges[i].p1.pos, h.edges[i].p2.pos));
         }
     }
     return tree;
 }