Example #1
0
        /// <summary>
        /// Adds a PointCloudItem from OtherCloud to the end of MyCloud
        /// and Adds Dictionary Values from OtherCloud to Dictionary Lists.
        /// </summary>
        /// <param name="MyCloud"> Cloud to Add to.</param>
        /// <param name="OtherCloud"> Cloud to Add from.</param>
        /// <param name="index"> Index of CloudItem in OtherCloud to Add to end end of MyCloud. </param>
        public static void AddItem_FromOtherCloud(ref PointCloud MyCloud, PointCloud OtherCloud, int index)
        {
            PointCloudItem OtherCloudItem = OtherCloud[index];

            MyCloud.AppendNew();
            PointCloudItem MyCloudItem = MyCloud[MyCloud.Count - 1];

            MyCloudItem.Location = OtherCloudItem.Location;
            if (OtherCloud.ContainsColors)
            {
                MyCloudItem.Color = OtherCloudItem.Color;
            }
            if (OtherCloud.ContainsNormals)
            {
                MyCloudItem.Normal = OtherCloudItem.Normal;
            }
        }
Example #2
0
        /// <summary>
        /// Parallel Computing Setup for Code to Execute.
        /// </summary>
        /// <param name="pointCloud">ByRef PointCloud to Execute Code on.</param>
        /// <returns></returns>
        public override bool Execute(ref PointCloud pointCloud)
        {
            //Set Global Variables
            LastPercentReported = 0;
            PointCounter        = 0;
            NewCloud            = new PointCloud();
            CloudPieces         = null;
            CloudPieces         = new PointCloud[ProcCount];
            DictPieces          = new object[ProcCount];
            GlobalCloud         = pointCloud;

            // Setup the cancellation mechanism.
            po.CancellationToken = cts.Token;

            //Create Partitions for multithreading.
            var rangePartitioner = System.Collections.Concurrent.Partitioner.Create(0, GlobalCloud.Count, (int)Math.Ceiling((double)GlobalCloud.Count / ProcCount));

            Dict_Utils.CastDictionary_ToArrayDouble(ref GlobalCloud);

            //Run MultiThreaded Loop.
            Parallel.ForEach(rangePartitioner, po, (rng, loopState) =>
            {
                //Initialize Local Variables.
                /// Get Index for Processor to be able to merge clouds in ProcesserIndex order in the end.
                int MyIndex = (int)(rng.Item1 / Math.Ceiling(((double)GlobalCloud.Count / ProcCount)));
                /// Initialize Partial PointCloud
                PointCloud MyCloud = new PointCloud();
                /// Get Total Count Fraction to calculate Operation Percentage.
                double totc = (double)1 / GlobalCloud.Count;

                /// Initialize Partial Dictionary Lists
                List <double>[] MyDict = new List <double> [GlobalCloud.UserDictionary.Count];
                //Get Dictionary Values from PointCloud
                List <double[]> GlobalDict = new List <double[]>();
                GlobalDict.Clear();

                if (GlobalCloud.UserDictionary.Count > 0)
                {
                    Dict_Utils.Initialize_Dictionary(ref GlobalDict, ref MyDict, GlobalCloud);
                    //Loop over individual RangePartitions per processor.
                    for (int i = rng.Item1; i < rng.Item2; i++)
                    {
                        //Operation Percentage Report
                        ///Safe Counter Increment.
                        Interlocked.Increment(ref PointCounter);
                        ///Calculate and Report Percentage.
                        if (LastPercentReported < ((PointCounter * totc) * 100))
                        {
                            LastPercentReported = (int)(5 * Math.Ceiling((double)(PointCounter * totc) * 20));
                            this.ReportPercent  = LastPercentReported;
                        }

                        //
                        if (insV_InsideBool)
                        {
                            for (int j = 0; j <= insV_Box.Count - 1; j += 1)
                            {
                                PointCloudItem GlobalCloudItem = GlobalCloud[i];
                                if (Math_Utils.IsInBox(GlobalCloudItem.Location, insV_Box[j]))
                                {
                                    Cloud_Utils.AddItem_FromOtherCloud(ref MyCloud, GlobalCloud, i);
                                    Dict_Utils.AddItem_FromGlobalDict(ref MyDict, GlobalDict, i);
                                    break; // TODO: might not be correct. Was : Exit For
                                }
                            }
                        }
                        else
                        {
                            List <Boolean> CropBools       = new List <Boolean>();
                            PointCloudItem GlobalCloudItem = GlobalCloud[i];
                            for (int j = 0; j <= insV_Box.Count - 1; j += 1)
                            {
                                CropBools.Add(Math_Utils.IsInBox(GlobalCloudItem.Location, insV_Box[j]));
                            }
                            bool Crop = !CropBools.Any(x => x == true);

                            if (Crop)
                            {
                                Cloud_Utils.AddItem_FromOtherCloud(ref MyCloud, GlobalCloud, i);
                                Dict_Utils.AddItem_FromGlobalDict(ref MyDict, GlobalDict, i);
                            }
                        }
                    }
                }
                else
                {
                    //Loop over individual RangePartitions per processor.
                    for (int i = rng.Item1; i < rng.Item2; i++)
                    {
                        //Operation Percentage Report
                        ///Safe Counter Increment.
                        Interlocked.Increment(ref PointCounter);
                        ///Calculate and Report Percentage.
                        if (LastPercentReported < ((PointCounter * totc) * 100))
                        {
                            LastPercentReported = (int)(5 * Math.Ceiling((double)(PointCounter * totc) * 20));
                            this.ReportPercent  = LastPercentReported;
                        }

                        //
                        if (insV_InsideBool)
                        {
                            for (int j = 0; j <= insV_Box.Count - 1; j += 1)
                            {
                                PointCloudItem GlobalCloudItem = GlobalCloud[i];
                                if (Math_Utils.IsInBox(GlobalCloudItem.Location, insV_Box[j]))
                                {
                                    Cloud_Utils.AddItem_FromOtherCloud(ref MyCloud, GlobalCloud, i);
                                    break; // TODO: might not be correct. Was : Exit For
                                }
                            }
                        }
                        else
                        {
                            List <Boolean> CropBools       = new List <Boolean>();
                            PointCloudItem GlobalCloudItem = GlobalCloud[i];
                            for (int j = 0; j <= insV_Box.Count - 1; j += 1)
                            {
                                CropBools.Add(Math_Utils.IsInBox(GlobalCloudItem.Location, insV_Box[j]));
                            }
                            bool Crop = !CropBools.Any(x => x == true);

                            if (Crop)
                            {
                                Cloud_Utils.AddItem_FromOtherCloud(ref MyCloud, GlobalCloud, i);
                            }
                        }
                    }
                }
                //Set DictPieces.
                if (GlobalCloud.UserDictionary.Count > 0)
                {
                    DictPieces[(int)MyIndex] = MyDict;
                }

                //Add MyCloud to CloudPieces at ProcesserIndex.
                CloudPieces[(int)MyIndex] = MyCloud;

                //Enable Parrallel Computing Cancellation
                po.CancellationToken.ThrowIfCancellationRequested();
            }
                             );



            //Merge PointCloud Pieces into One PointCloud.
            Cloud_Utils.MergeClouds(ref NewCloud, CloudPieces);

            if (GlobalCloud.UserDictionary.Count > 0)
            {
                List <double>[] NewDict = new List <double> [GlobalCloud.UserDictionary.Count];
                Dict_Utils.Merge_DictPieces(ref NewDict, DictPieces);
                Dict_Utils.SetUserDict_FromDictLists(ref NewCloud, NewDict, GlobalCloud.UserDictionary.Keys);
            }

            //Dispose of Global Clouds.
            GlobalCloud.Dispose();
            pointCloud.Dispose();

            //Set OutputCloud
            pointCloud = (PointCloud)NewCloud.Duplicate();

            //Dispose of PointCloud Pieces and NewCloud.
            CloudPieces = null;
            DictPieces  = null;
            NewCloud.Dispose();


            //Return True on Finish
            return(true);
        }
Example #3
0
        public override bool Execute(ref PointCloud pointCloud)
        {
            LastPercentReported = 0;
            PointCounter        = 0;
            NewCloud            = new PointCloud();
            CloudPieces         = null;

            CloudPieces = new PointCloud[ProcCount];

            GlobalCloud = pointCloud;

            // Setup the cancellation mechanism.
            po.CancellationToken = cts.Token;

            //Create Partitions for multithreading.
            var rangePartitioner = System.Collections.Concurrent.Partitioner.Create(0, GlobalCloud.Count, (int)Math.Ceiling((double)GlobalCloud.Count / ProcCount));

            //Run MultiThreaded Loop.
            Parallel.ForEach(rangePartitioner, po, (rng, loopState) =>

            {
                //Initialize Partial PointCloud
                PointCloud MyCloud = new PointCloud();

                //Initialize Partial Dictionary Lists
                List <double>[] myDict = new List <double> [GlobalCloud.UserDictionary.Count];
                for (int L = 0; L < myDict.Length; L++)
                {
                    myDict[L] = new List <double>();
                }


                double totc = (double)1 / GlobalCloud.Count;
                int MyIndex = (int)(rng.Item1 / Math.Ceiling(((double)GlobalCloud.Count / ProcCount)));

                for (int i = rng.Item1; i < rng.Item2; i++)
                {
                    Interlocked.Increment(ref PointCounter);
                    double tmp = PointCounter * totc * 100;


                    if (LastPercentReported < ((PointCounter * totc) * 100))
                    {
                        LastPercentReported = (int)(5 * Math.Ceiling((double)(PointCounter * totc) * 20));
                        this.ReportPercent  = LastPercentReported;
                    }

                    if (InsideBool)
                    {
                        for (int j = 0; j <= BoxCrop.Count - 1; j += 1)
                        {
                            PointCloudItem GlobalCloudItem = GlobalCloud[i];
                            if (Math_Utils.IsInBox(GlobalCloudItem.Location, BoxCrop[j]))
                            {
                                //AddPointCloudItem(ref MyCloud, GlobalCloudItem);

                                MyCloud.AppendNew();
                                PointCloudItem MyCloudItem = MyCloud[MyCloud.Count - 1];
                                MyCloudItem.Location       = GlobalCloudItem.Location;
                                if (GlobalCloud.ContainsColors)
                                {
                                    MyCloudItem.Color = GlobalCloudItem.Color;
                                }
                                if (GlobalCloud.ContainsNormals)
                                {
                                    MyCloudItem.Normal = GlobalCloudItem.Normal;
                                }
                                if (GlobalCloud.HasUserData)
                                {
                                    for (int k = 0; k < GlobalCloud.UserDictionary.Count; k++)
                                    {
                                        string key   = GlobalCloud.UserDictionary.Keys[k];
                                        double value = ((Double[])GlobalCloud.UserDictionary[key])[i];
                                        myDict[k].Add(value);
                                    }
                                }

                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                    }


                    else
                    {
                        List <Boolean> CropBools       = new List <Boolean>();
                        PointCloudItem GlobalCloudItem = GlobalCloud[i];
                        for (int j = 0; j <= BoxCrop.Count - 1; j += 1)
                        {
                            CropBools.Add(Math_Utils.IsInBox(GlobalCloudItem.Location, BoxCrop[j]));
                        }
                        bool Crop = !CropBools.Any(x => x == true);

                        if (Crop)
                        {
                            MyCloud.AppendNew();
                            PointCloudItem MyCloudItem = MyCloud[MyCloud.Count - 1];
                            MyCloudItem.Location       = GlobalCloudItem.Location;
                            if (GlobalCloud.ContainsColors)
                            {
                                MyCloudItem.Color = GlobalCloudItem.Color;
                            }
                            if (GlobalCloud.ContainsNormals)
                            {
                                MyCloudItem.Normal = GlobalCloudItem.Normal;
                            }
                            if (GlobalCloud.HasUserData)
                            {
                                for (int k = 0; k < GlobalCloud.UserDictionary.Count; k++)
                                {
                                    string key   = GlobalCloud.UserDictionary.Keys[k];
                                    double value = ((Double[])GlobalCloud.UserDictionary[key])[i];
                                    myDict[k].Add(value);
                                }
                            }

                            //break; // TODO: might not be correct. Was : Exit For
                        }
                    }
                }

                for (int k = 0; k < myDict.Length; k++)
                {
                    string key         = GlobalCloud.UserDictionary.Keys[k];
                    double[] MyDictArr = myDict[k].ToArray();
                    MyCloud.UserDictionary.Set(key, MyDictArr);
                }


                CloudPieces[(int)MyIndex] = MyCloud;

                po.CancellationToken.ThrowIfCancellationRequested();
            }
                             );


            GlobalCloud.Dispose();
            pointCloud.Dispose();
            foreach (PointCloud pc in CloudPieces)
            {
                if (pc != null)
                {
                    NewCloud.Merge(pc);
                }


                if (pc.HasUserData)
                {
                    foreach (string key in pc.UserDictionary.Keys)
                    {
                        double[] newDict = null;

                        if (NewCloud.UserDictionary.ContainsKey(key))
                        {
                            double[]      Dict        = (double[])NewCloud.UserDictionary[key];
                            double[]      MyDict      = (double[])pc.UserDictionary[key];
                            List <Double> listNewDict = new List <double>(Dict);
                            listNewDict.AddRange(MyDict);
                            newDict = listNewDict.ToArray();
                        }
                        else
                        {
                            newDict = (double[])pc.UserDictionary[key];
                        }

                        NewCloud.UserDictionary.Set(key, newDict);

                        newDict = null;
                    }
                }
            }

            pointCloud  = (PointCloud)NewCloud.Duplicate();
            CloudPieces = null;
            NewCloud.Dispose();


            return(true);
        }
Example #4
0
        /// <summary>
        /// Parallel Computing Setup for Code to Execute.
        /// </summary>
        /// <param name="pointCloud">ByRef PointCloud to Execute Code on.</param>
        /// <returns></returns>
        public override bool Execute(ref PointCloud pointCloud)
        {
            //Set Global Variables
            LastPercentReported = 0;
            PointCounter        = 0;

            Dict_Utils.CastDictionary_ToArrayDouble(ref pointCloud);
            GlobalCloud = pointCloud;
            NewCloud    = (PointCloud)pointCloud.Duplicate();

            Array.Resize(ref Distances, pointCloud.Count);
            Array.Resize(ref ApproachAngle, pointCloud.Count);

            double halfpi = Math.PI / 2;

            // Setup the cancellation mechanism.
            po.CancellationToken = cts.Token;

            //Create Partitions for multithreading.
            var rangePartitioner = System.Collections.Concurrent.Partitioner.Create(0, GlobalCloud.Count, (int)Math.Ceiling((double)GlobalCloud.Count / ProcCount));



            //Run MultiThreaded Loop.
            Parallel.ForEach(rangePartitioner, po, (rng, loopState) =>
            {
                //Initialize Local Variables.
                /// Get Index for Processor to be able to merge clouds in ProcesserIndex order in the end.
                int MyIndex = (int)(rng.Item1 / Math.Ceiling(((double)GlobalCloud.Count / ProcCount)));
                /// Initialize Partial PointCloud
                PointCloud MyCloud = new PointCloud();
                /// Get Total Count Fraction to calculate Operation Percentage.
                double totc = (double)1 / GlobalCloud.Count;


                //Loop over individual RangePartitions per processor.
                for (int i = rng.Item1; i < rng.Item2; i++)
                {
                    //Operation Percentage Report
                    ///Safe Counter Increment.
                    Interlocked.Increment(ref PointCounter);
                    ///Calculate and Report Percentage.
                    if (LastPercentReported < ((PointCounter * totc) * 100))
                    {
                        LastPercentReported = (int)(5 * Math.Ceiling((double)(PointCounter * totc) * 20));
                        this.ReportPercent  = LastPercentReported;
                    }

                    //
                    PointCloudItem GlobalCloudItem = GlobalCloud[i];
                    Point3d p3  = GlobalCloudItem.Location;
                    Point3d pm  = new Point3d();
                    Vector3d pv = new Vector3d();

                    insV_Mesh.ClosestPoint(p3, out pm, out pv, 0);
                    double d = p3.DistanceTo(pm);

                    if (Vector3d.VectorAngle(pv, new Vector3d(pm - p3)) < halfpi)
                    {
                        d = -d;
                    }
                    Distances[i] = d;


                    if (insV_ApproachAngle)
                    {
                        Point3d pos      = (Point3d)insV_PositionPt;
                        Vector3d scanVec = new Vector3d(p3 - pos);
                        double appA      = Math.Abs(halfpi - Vector3d.VectorAngle(pv, scanVec));


                        ApproachAngle[i] = appA;
                    }
                }



                //Enable Parrallel Computing Cancellation
                po.CancellationToken.ThrowIfCancellationRequested();
            }
                             );



            //Dispose of Global Clouds.
            GlobalCloud.Dispose();
            pointCloud.Dispose();

            //Set OutputCloud
            NewCloud.UserDictionary.Set(insV_Key, Distances);
            NewCloud.UserDictionary.Set(insV_AngleKey, ApproachAngle);
            //Colorize
            if (insV_Colorize)
            {
                List <double> colorValues = Color_Utils.ColorValues_Std_negpos(NewCloud, insV_Key);
                List <Color>  Colors      = Color_Utils.ColorGradient_Std_BtoR();

                Instruction.Instr_Dict_Color col = new Instruction.Instr_Dict_Color(insV_Key, colorValues, Colors, -1, 0.00);
                Boolean ColResult = col.Execute(ref NewCloud);

                //Set ColorGradient UserData
                Color_Utils.Set_ColorGradient_Dict(ref NewCloud, Colors, colorValues);
            }


            pointCloud = (PointCloud)NewCloud.Duplicate();

            //Dispose of PointCloud Pieces and NewCloud.
            GlobalCloud.Dispose();
            NewCloud.Dispose();

            //Return True on Finish
            return(true);
        }