Beispiel #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;
            }
        }
Beispiel #2
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);
        }