Esempio n. 1
0
        /// <summary>
        /// Method to insert a feature at this node
        /// </summary>
        /// <param name="feature">The feature to add</param>
        public void Insert(SbnFeature feature)
        {
            // if this is leaf, just take the feature
            if (Nid >= _tree.FirstLeafNodeId)
            {
                AddFeature(feature);
                return;
            }

            // it takes 8 features to split a node
            // so we'll hold 8 features first
            if (Nid > 1)
            {
                if (!Full)
                {
                    if (FeatureCount < 8)
                    {
                        AddFeature(feature);
                        return;
                    }
                    if (FeatureCount == 8)
                    {
                        var bin = FirstBin;
                        FirstBin = new SbnBin();
                        Full     = true;
                        bin.AddFeature(feature);
                        for (var i = 0; i < 9; i++)
                        {
                            Insert(bin[i]);
                        }
                        return;
                    }
                }
            }

            // The node is split so we can sort features
            int min, max; //, smin, smax;
            var splitAxis = Level % 2;

            if (splitAxis == 1)
            {
                min = feature.MinX;
                max = feature.MaxX;
                //smin = feature.MinY;
                //smax = feature.MaxY;
            }
            else
            {
                min = feature.MinY;
                max = feature.MaxY;
                //smin = feature.MinX;
                //smax = feature.MaxX;
            }
            var seam = GetSplitOridnate(splitAxis);

            // Grab features on the seam we can't split
            if (min <= seam && max > seam)
            {
                AddFeature(feature);
            }

            else if (min < seam)
            {
                Child2.Insert(feature);
            }
            else
            {
                Child1.Insert(feature);
            }
        }