public void Octree_getpointsInboxfromSearchBox_pointsOK()
        {
            List <Vector3> vectorList = new List <Vector3>();

            for (int i = 0; i <= 100; i++)
            {
                for (int j = 0; j <= 100; j++)
                {
                    vectorList.Add(new Vector3(i * .1, j * .1, 1.0));
                }
            }
            Octree <SurfacePoint> Octree = OctreeBuilder <SurfacePoint> .Build(vectorList, .1);

            Vector3             searchPoint  = new Vector3(5, 6, 3);
            Vector3             direction    = new Vector3(0, 0, 1);
            Ray                 ray          = new Ray(searchPoint, direction);
            double              searchRadius = Octree.MeshSize * 3;
            var                 searchBox    = BoundingBoxBuilder.GetSearchCylinder(Octree.BoundingBox, searchPoint, direction, searchRadius);
            List <SurfacePoint> points       = Octree.GetPointsInsideBox(searchBox);

            Assert.AreNotEqual(0, points.Count);
        }
Ejemplo n.º 2
0
        //public List<T> GetKNearestPoints(Vector3 searchPoint, int searchQty)
        //{
        //    try
        //    {
        //        int resultCount = 0;
        //        var results = new List<T>();

        //        if (searchQty == 0)
        //        {
        //            return results;
        //        }

        //        double initSearchWidth = minSeparation * Math.Min(searchQty, 3);

        //        double searchSize = 1;
        //        double maxSearchDim = 2 * Math.Max((searchPoint - _boundingBox.Min).Length, (_boundingBox.Max - searchPoint).Length);
        //        Vector3 searchHalfDimension = new Vector3(initSearchWidth, initSearchWidth, initSearchWidth);
        //        // search and expand search box until point count is >= k
        //        do
        //        {
        //            var box = new BoundingBox(searchPoint - searchHalfDimension, searchPoint + searchHalfDimension);

        //            results = new List<T>();
        //            getPointsInBox(box, ref results);

        //            resultCount = results.Count;
        //            if (resultCount == 0)
        //            {
        //                searchSize *= 2;
        //            }
        //            else
        //            {
        //                searchSize *= ((double)searchQty / (double)resultCount);
        //            }

        //            searchHalfDimension = new Vector3(searchSize * initSearchWidth, searchSize * initSearchWidth, searchSize * initSearchWidth);
        //        } while (resultCount < searchQty && searchHalfDimension.Length < maxSearchDim);

        //        double[] distances = new double[resultCount];
        //        T[] resultArray = results.ToArray();

        //        // find closest k points to search point and add to output
        //        if (resultCount > searchQty)
        //        {
        //            for (int i = 0; i < resultCount; i++)
        //            {
        //                distances[i] = searchPoint.Distance2To(resultArray[i].Position);
        //            }
        //            Array.Sort(distances, resultArray);

        //            return resultArray.ToList();

        //        }
        //        else
        //        {
        //            return results;
        //        }
        //    }
        //    catch (Exception)
        //    {

        //        throw;
        //    }


        //}
        public IntersectionRecord GetIntersection(Ray ray)
        {
            try
            {
                var searchBox = BoundingBoxBuilder.GetSearchCylinder(_boundingBox, ray.Origin, ray.Direction, minSeparation * 3);

                List <T> points = GetPointsInsideBox(searchBox);
                Vector3  intPt  = new Vector3();

                double  denom  = (ray.Direction - ray.Origin).Length;
                Vector3 rayEnd = ray.Direction - ray.Origin;
                if (denom > 0 && points.Count == 1)
                {
                    return(new IntersectionRecord(points[0].Position, true));
                }
                if (denom > 0 && points.Count > 1)
                {
                    double[]  distArr = new double[points.Count];
                    Vector3[] ptArr   = new Vector3[points.Count];
                    int       i       = 0;
                    foreach (T pt in points)
                    {
                        distArr[i] = GeomUtilities.RayPointDistance(ray, pt.Position);
                        ptArr[i]   = pt.Position;
                        i++;
                    }
                    Array.Sort(distArr, ptArr);
                    return(new IntersectionRecord(ptArr[0], true));
                }
                return(new IntersectionRecord());
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public void Run(CancellationToken ct, IProgress <int> progress)
        {
            try
            {
                double searchRadius = jetRadius + surface.MeshSize;

                int           pcount    = path.Count * runInfo.Runs * runInfo.Iterations;
                int           count     = 0;
                List <string> pointlist = new List <string>();
                pointlist.Add("run,Nx,Ny,Nz,x,z,pointradius,jetfactor,incidentangle,slopefactor");

                double spFactor      = spacingFactor();
                double testJetRadius = jetRadius + surface.MeshSize;
                for (int iteration = 1; iteration <= runInfo.Iterations; iteration++)
                {
                    runInfo.CurrentIteration = iteration;


                    for (int run = 1; run <= runInfo.Runs; run++)
                    {
                        runInfo.CurrentRun = run;
                        int pathCount = 0;
                        foreach (ModelPathEntity mpe in path)
                        {
                            if (!ct.IsCancellationRequested)
                            {
                                double feedFactor = currentRemovalRate.DepthPerPass * spFactor * feedrateFactor(mpe.Feedrate.Value, currentRemovalRate);
                                pathCount++;
                                if (mpe.JetOn && feedFactor != 0)
                                {
                                    BoundingBox        searchBox        = BoundingBoxBuilder.GetSearchCylinder(surface.BoundingBox, mpe.PositionAsVector3, mpe.JetVector, searchRadius);
                                    List <AbmachPoint> jetIntersectList = surface.GetPointsInsideBox(searchBox);

                                    Octree <AbmachPoint> localSurface = OctreeBuilder <AbmachPoint> .Build(jetIntersectList, surface.MeshSize);// OctreeBuilder<AbmachPoint>.Build(jetIntersectList, searchBox, surface.MeshSize);

                                    var newPts = new List <AbmachPoint>();
                                    var mpeV   = new Vector3(mpe.Position.X, mpe.Position.Y, 0);
                                    var jetRay = new Ray(mpe.PositionAsVector3, mpe.JetVector);

                                    foreach (AbmachPoint jetPt in localSurface.GetAllPoints())
                                    {
                                        if (jetPt != null)
                                        {
                                            //var jetV = new Vector3(jetPt.Position.X, jetPt.Position.Y, 0);

                                            //double pointRadius = jetV.DistanceTo(mpeV);
                                            double pointRadius = GeomUtilities.RayPointDistance(jetRay, jetPt.Position);
                                            if (pointRadius <= testJetRadius)
                                            {
                                                double jFactor = jetFactor(pointRadius);
                                                if (jFactor > 0)
                                                {
                                                    Vector3 localNormal = new Vector3(0, 0, 1); // localSurface.GetNormalAt(jetPt.Position);
                                                    if (localNormal.Length == 0)
                                                    {
                                                        localNormal = new Vector3(mpe.JetVector);
                                                    }
                                                    double angle    = incidentAngle(mpe.JetVector, localNormal);
                                                    double slFactor = slopeFactor(angle);
                                                    //debug


                                                    if (jetPt.Position.X > 0.006 && jetPt.Position.X < .1 && jetPt.Position.Y > .072 && jetPt.Position.Y < .102)
                                                    {
                                                        pointlist.Add(run.ToString() + "," + jetPt.Position.X.ToString("f5") + "," + jetPt.Position.Y.ToString("f5") + "," + jetPt.Position.Z.ToString("f5") + "," + pointRadius.ToString("f5") + "," + jFactor.ToString("F5") + "," + angle.ToString("F5") + "," + slFactor.ToString("F5"));
                                                    }
                                                    //debug

                                                    Vector3 materialRemoved = (feedFactor * slFactor * jFactor) * mpe.JetVector;

                                                    Vector3 newPosition = jetPt.Position - materialRemoved;

                                                    jetPt.Position         = newPosition;
                                                    jetPt.Normal           = localNormal;
                                                    jetPt.OriginalPosition = jetPt.OriginalPosition;
                                                    jetPt.JetHit           = true;
                                                    newPts.Add(jetPt);
                                                }
                                            }
                                            else
                                            {
                                                newPts.Add(jetPt);
                                            }
                                        }    //end foreach jetPt
                                    }
                                    surface.Insert(newPts);
                                }//endif jeton
                            }
                            progress.Report(100 * ++count / pcount);
                        }//next path entity
                        if (runInfo.RunType == ModelRunType.NewMRR)
                        {
                            currentRemovalRate = newRemovalRate(path, runInfo, currentRemovalRate, depthInfo);
                        }
                    } //next run

                    if (runInfo.RunType == ModelRunType.NewFeedrates && runInfo.CurrentIteration < runInfo.Iterations)
                    {
                        path = newFeedrates(path, depthInfo);
                        resetSurface();
                    }
                }//next iteration
                FileIOLib.FileIO.Save(pointlist, "slopefactor.csv");
            }
            catch (Exception)
            {
                throw;
            }
        }