Exemple #1
0
        protected void CheckRange(int xleft, int xright, int y, int z, ParentDirections ptype)
        {
            for (int i = xleft; i <= xright;)
            {
                if ((!flagsMap.GetFlagOn(i, y, z)) && IncludePredicate(i, y, z))
                {
                    int lb = i;
                    int rb = i + 1;
                    while (rb <= xright && (!flagsMap.GetFlagOn(rb, y, z)) && IncludePredicate(rb, y, z))
                    {
                        rb++;
                    }
                    rb--;

                    Span span = new Span();
                    span.XLeft  = lb;
                    span.XRight = rb;
                    span.Y      = y;
                    span.Z      = z;
                    if (lb == xleft && rb == xright)
                    {
                        span.Extended = ExtendTypes.UnRez;
                    }
                    else if (rb == xright)
                    {
                        span.Extended = ExtendTypes.RightRequired;
                    }
                    else if (lb == xleft)
                    {
                        span.Extended = ExtendTypes.LeftRequired;
                    }
                    else
                    {
                        span.Extended = ExtendTypes.AllRez;
                    }
                    span.ParentDirection = ptype;
                    for (int j = lb; j <= rb; j++)
                    {
                        flagsMap.SetFlagOn(j, y, z, true);
                        Process(new Int16Triple(j, y, z));
                    }
                    container.Push(span);

                    i = rb + 1;
                }
                else
                {
                    i++;
                }
            }
        }//区段法的CheckRange 注意与扫描线的CheckRange的不同
 protected virtual void ExcuteFloodFill(BitMap3d data, Int16Triple seed)
 {
     this.bmp = data;
     data.ResetVisitCount();
     flagsMap = new FlagMap3d(data.width, data.height, data.depth);
     Int16Triple[] adjPoints6 = new Int16Triple[6];
     flagsMap.SetFlagOn(seed.X, seed.Y, seed.Z, true);
     container.Push(seed);
     Process(seed);
     while (!container.Empty())
     {
         Int16Triple p = container.Pop();
         InitAdj6(ref adjPoints6, ref p);
         for (int adjIndex = 0; adjIndex < 6; adjIndex++)
         {
             Int16Triple t = adjPoints6[adjIndex];
             if (t.X < data.width && t.X >= 0 && t.Y < data.height && t.Y >= 0 && t.Z < data.depth && t.Z >= 0)
             {
                 if (!flagsMap.GetFlagOn(t.X, t.Y, t.Z) && IncludePredicate(t))
                 {
                     flagsMap.SetFlagOn(t.X, t.Y, t.Z, true);
                     container.Push(t);
                     Process(t);
                 }
             }
         }
     }
     return;
 }
        }//该函数为扫描线法主体

        protected void CheckRange(int xleft, int xright, int y, int z)
        {
            for (int i = xleft; i <= xright;)
            {
                if ((!flagsMap.GetFlagOn(i, y, z)) && IncludePredicate(i, y, z))
                {
                    int rb = i + 1;
                    while (rb <= xright && (!flagsMap.GetFlagOn(rb, y, z)) && IncludePredicate(rb, y, z))
                    {
                        rb++;
                    }
                    rb--;
                    Int16Triple t = new Int16Triple(rb, y, z);
                    flagsMap.SetFlagOn(rb, y, z, true);
                    container.Push(t);
                    Process(t);
                    i = rb + 1;
                }
                else
                {
                    i++;
                }
            }
        }//CheckRange操作
Exemple #4
0
 private void ProcessXSeeds(SpanFillInput input)
 {
     for (int k = 0; k < 2; k++)
     {
         List <Int16Triple> list = input.overstepPointList[k];
         for (int i = 0; i < list.Count; i++)
         {
             Int16Triple p = list[i];
             if (!flagsMap.GetFlagOn(p.X, p.Y, p.Z) && IncludeConditionMeets(p.X, p.Y, p.Z))
             {
                 Process(p);
                 flagsMap.SetFlagOn(p.X, p.Y, p.Z, true);
                 Span span = new Span();
                 span.XLeft           = p.X;
                 span.XRight          = p.X;
                 span.Y               = p.Y;
                 span.Z               = p.Z;
                 span.ParentDirection = ParentDirections.Non;
                 span.Extended        = ExtendTypes.UnRez;
                 container.Push(span);
             }
         }
     }
 }
Exemple #5
0
        public FloodFillResult ExecuteSeededGrow(FloodFillInput input)
        {
            queue.Clear();
            //result.Clear();
            resultCount   = 0;
            this.width    = input.width;
            this.height   = input.height;
            this.depth    = input.depth;
            this.flagsMap = input.flag;
            this.data     = input.data;
            List <Int16Triple> oversteps = input.overstepList;
            FloodFillResult    ret       = new FloodFillResult();

            ret.Init();
            Int16Triple[] adjPoints6 = new Int16Triple[6];
            if (!input.IsFirst)
            {
                for (int i = 0; i < oversteps.Count; i++)
                {
                    if (!flagsMap.GetFlagOn(oversteps[i].X, oversteps[i].Y, oversteps[i].Z) && IncludeConditionMeets(oversteps[i]))
                    {
                        flagsMap.SetFlagOn(oversteps[i].X, oversteps[i].Y, oversteps[i].Z, true);
                        Process(oversteps[i]);
                        InitAdj6(adjPoints6, oversteps[i]);
                        for (int adjIndex = 0; adjIndex < 6; adjIndex++)
                        {
                            Int16Triple t = adjPoints6[adjIndex];
                            if (t.X < width && t.X >= 0 && t.Y < height && t.Y >= 0 && t.Z < depth && t.Z >= 0)
                            {
                                int indext = t.X + width * t.Y + width * height * t.Z;
                                if (!flagsMap.GetFlagOn(t.X, t.Y, t.Z) && IncludeConditionMeets(t))
                                {
                                    flagsMap.SetFlagOn(t.X, t.Y, t.Z, true);
                                    queue.Push(t);
                                    Process(t);
                                }
                            }
                        }
                    }//首次生长需要避免让越界种子点又重新回溯到原先的层
                }
            }
            else
            {
                //以下是第一次生长的时候种子点不需要担心回溯
                if (oversteps.Count != 1)
                {
                    throw new Exception();
                }
                for (int i = 0; i < oversteps.Count; i++)
                {
                    if (!flagsMap.GetFlagOn(oversteps[i].X, oversteps[i].Y, oversteps[i].Z) && IncludeConditionMeets(oversteps[i]))
                    {
                        flagsMap.SetFlagOn(oversteps[i].X, oversteps[i].Y, oversteps[i].Z, true);
                        queue.Push(oversteps[i]);
                        Process(oversteps[i]);
                    }
                }
            }
            while (!queue.Empty())
            {
                Int16Triple p = queue.Pop();
                InitAdj6(adjPoints6, p);
                for (int adjIndex = 0; adjIndex < 6; adjIndex++)
                {
                    Int16Triple t = adjPoints6[adjIndex];
                    if (t.X < width && t.X >= 0 && t.Y < height && t.Y >= 0 && t.Z < depth && t.Z >= 0)
                    {
                        int indext = t.X + width * t.Y + width * height * t.Z;
                        if (!flagsMap.GetFlagOn(t.X, t.Y, t.Z) && IncludeConditionMeets(t))
                        {
                            flagsMap.SetFlagOn(t.X, t.Y, t.Z, true);
                            queue.Push(t);
                            Process(t);
                        }
                    }
                    else
                    {
                        if (input.recordLower && t.Z < 0)
                        {
                            if (t.Z != -1)
                            {
                                throw new Exception();
                            }
                            ret.boundaryRequestPoints[0].Add(t);
                            continue;
                        }
                        if (input.recordUpper && t.Z >= depth)
                        {
                            if (t.Z > depth)
                            {
                                throw new Exception();
                            }
                            ret.boundaryRequestPoints[1].Add(t);
                            continue;
                        }
                    }
                }
            }
            //ret.resultPointSet = this.result;
            ret.resultCount = this.resultCount;
            return(ret);
        }
        public void ExecuteSeededGrow(FloodFillInput input, FloodFillResult ret)
        {
            queue.Clear();
            result      = ret;
            this.width  = input.width;
            this.height = input.height;
            this.depth  = input.depth;
            this.data   = input.data;
            if (input.flagsMap != null)
            {
                this.flagsMap = input.flagsMap;
            }
            else
            {
                this.flagsMap = new FlagMap3d(input.width, input.height, input.depth);
            }

            Int16Triple[] adjPoints6 = new Int16Triple[6];
            if (!input.GetIsFirst())
            {
                List <Int16Triple>[] oversteps = input.overstepList;
                for (int j = 0; j < 6; j++)
                {
                    for (int i = 0; i < oversteps[j].Count; i++)
                    {
                        Int16Triple p = oversteps[j][i];
                        if (!flagsMap.GetFlagOn(p.X, p.Y, p.Z) && IncludeConditionMeets(p))
                        {
                            flagsMap.SetFlagOn(p.X, p.Y, p.Z, true);
                            Process(p);
                            queue.Push(new Int16TripleWithDirection(p, j));
                        }
                    }
                }
            }
            else
            {
                Int16Triple seed = input.seed;
                flagsMap.SetFlagOn(seed.X, seed.Y, seed.Z, true);
                queue.Push(new Int16TripleWithDirection(seed, 6));
                Process(seed);
            }
            while (!queue.Empty())
            {
                Int16TripleWithDirection p = queue.Pop();
                InitAdj6(adjPoints6, p.Poistion);
                for (int adjIndex = 0; adjIndex < 6; adjIndex++)
                {
                    if (adjIndex == p.PDirection)
                    {
                        continue;
                    }
                    Int16Triple t = adjPoints6[adjIndex];
                    if (t.X < width && t.X >= 0 && t.Y < height && t.Y >= 0 && t.Z < depth && t.Z >= 0)
                    {
                        int indext = t.X + width * t.Y + width * height * t.Z;
                        if (!flagsMap.GetFlagOn(t.X, t.Y, t.Z) && IncludeConditionMeets(t))
                        {
                            flagsMap.SetFlagOn(t.X, t.Y, t.Z, true);
                            queue.Push(new Int16TripleWithDirection(t, OppositePos[adjIndex]));
                            Process(t);
                        }
                    }
                    else
                    {
                        if (input.GetCanSeekAdj(adjIndex))
                        {
                            result.boundaryRequestPoints[adjIndex].Add(t);
                        }
                    }
                }
            }
        }