Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 protected virtual void ExcuteScanlineFill(BitMap3d data, Int16Triple seed)
 {
     this.bmp = data;
     data.ResetVisitCount();
     flagsMap = new FlagMap3d(data.width, data.height, data.depth);
     flagsMap.SetFlagOn(seed.X, seed.Y, seed.Z, true);
     container.Push(seed);
     Process(seed);
     while (!container.Empty())
     {
         Int16Triple p      = container.Pop();
         int         xleft  = FindXLeft(p);
         int         xright = FindXRight(p);
         if (p.Y - 1 >= 0)
         {
             CheckRange(xleft, xright, p.Y - 1, p.Z);
         }
         if (p.Y + 1 < data.height)
         {
             CheckRange(xleft, xright, p.Y + 1, p.Z);
         }
         if (p.Z - 1 >= 0)
         {
             CheckRange(xleft, xright, p.Y, p.Z - 1);
         }
         if (p.Z + 1 < data.depth)
         {
             CheckRange(xleft, xright, p.Y, p.Z + 1);
         }
     }
 }//该函数为扫描线法主体
Exemplo n.º 3
0
 public FlagMap3d GetFlagMap3d()
 {
     if (flagMap == null)
     {
         flagMap = new FlagMap3d(actualWidth, actualHeight, actualDepth);
     }
     return(flagMap);
     //return null;
 }
Exemplo n.º 4
0
 public FloodFillInput()
 {
     this.data         = null;
     this.flagsMap     = null;
     this.width        = -1;
     this.height       = -1;
     this.depth        = -1;
     this.overstepList = null;
     this.seed         = new Int16Triple(-1, -1, -1);
     this.mask         = null;
 }
Exemplo n.º 5
0
 public FlagMap3d GetAndInitFlag()
 {
     if (Flag != null)
     {
         return(Flag);
     }
     else
     {
         Flag = new FlagMap3d(AllWidth, AllHeight, actualDepth);
         return(Flag);
     }
 }//第一次访问时初始化
Exemplo n.º 6
0
 public Layer(int allwidth, int allheight, int alldepth, int subDepth, int stz, int edz)
 {
     this.AllWidth  = allwidth;
     this.AllHeight = allheight;
     this.AllDepth  = alldepth;
     this.stz       = stz;
     this.subDepth  = subDepth;
     this.edz       = edz;
     Flag           = null;
     indexZ         = -1;
     visitcount     = 0;
 }
Exemplo n.º 7
0
 public FloodFillInput(byte[] data, int width, int height, int depth, FlagMap3d flag, List <Int16Triple> overstepList, bool recordUpper, bool recordLower, bool isfirst)
 {
     this.data         = data;
     this.width        = width;
     this.height       = height;
     this.depth        = depth;
     this.flag         = flag;
     this.overstepList = overstepList;
     for (int i = 0; i < overstepList.Count; i++)
     {
         if (!(overstepList[i].X >= 0 && overstepList[i].X < width && overstepList[i].Y >= 0 && overstepList[i].Y < height && overstepList[i].Z >= 0 && overstepList[i].Z < depth))
         {
             throw new Exception();
         }
     }//确保越界点都确实在这层里
     this.recordLower = recordLower;
     this.recordUpper = recordUpper;
     this.IsFirst     = isfirst;
 }
Exemplo n.º 8
0
 public void ClearAll()
 {
     data     = null;
     width    = -1;
     height   = -1;
     depth    = -1;
     data     = null;
     seed     = new Int16Triple(-1, -1, -1);
     mask     = null;
     flagsMap = null;
     if (overstepList != null)
     {
         for (int i = 0; i < 6; i++)
         {
             overstepList[i].Clear();
         }
     }
     overstepList = null;
 }
Exemplo n.º 9
0
 public SpanFillInput(byte[] data, int width, int height, int depth, FlagMap3d flag, List <Range> spanList, Int16Triple seed, bool recordUpper, bool recordLower, bool isfirst)
 {
     this.data     = data;
     this.width    = width;
     this.height   = height;
     this.depth    = depth;
     this.flag     = flag;
     this.spanlist = spanList;
     this.seed     = seed;
     if (spanlist != null)
     {
         for (int i = 0; i < spanlist.Count; i++)
         {
             if (!(spanlist[i].Y >= 0 && spanlist[i].Y < height && spanlist[i].Z >= 0 && spanlist[i].Z < depth))
             {
                 throw new Exception();
             }
         }
     }
     this.recordLower = recordLower;
     this.recordUpper = recordUpper;
     this.IsFirst     = isfirst;
 }
Exemplo n.º 10
0
        protected Container <Span> container;//以Span为单位的Queue或Stack容器
        protected virtual void ExcuteSpanFill(BitMap3d data, Int16Triple seed)
        {
            this.bmp = data;
            data.ResetVisitCount();
            flagsMap = new FlagMap3d(data.width, data.height, data.depth);
            Process(seed);
            flagsMap.SetFlagOn(seed.X, seed.Y, seed.Z, true);
            Span seedspan = new Span();

            seedspan.XLeft           = seed.X;
            seedspan.XRight          = seed.X;
            seedspan.Y               = seed.Y;
            seedspan.Z               = seed.Z;
            seedspan.ParentDirection = ParentDirections.Non;
            seedspan.Extended        = ExtendTypes.UnRez;
            container.Push(seedspan);

            while (!container.Empty())
            {
                Span span = container.Pop();
                #region AllRez
                if (span.Extended == ExtendTypes.AllRez)
                {
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)//[spx-spy,y-1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < data.depth)//[spx-spy,y,z+1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < bmp.height)//[spx-spy,y+1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < data.depth)//[spx-spy,y,z+1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)//[spx-spy,y-1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)//[spx-spy,y+1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region UnRez
                if (span.Extended == ExtendTypes.UnRez)
                {
                    int xl = FindXLeft(span.XLeft, span.Y, span.Z);
                    int xr = FindXRight(span.XRight, span.Y, span.Z);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y + 1, span.Z, ParentDirections.Y0);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                            }
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Y - 1 >= 0)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y - 1, span.Z, ParentDirections.Y2);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                            }
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                            }
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                            }
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Non)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region LeftRequired
                if (span.Extended == ExtendTypes.LeftRequired)
                {
                    int xl = FindXLeft(span.XLeft, span.Y, span.Z);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y - 1 >= 0 && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0 && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region RightRequired
                if (span.Extended == ExtendTypes.RightRequired)
                {
                    int xr = FindXRight(span.XRight, span.Y, span.Z);

                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }

                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Y - 1 >= 0 && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        if (span.Z - 1 >= 0 && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        if (span.Z + 1 < bmp.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 public void Clear()
 {
     data         = null;
     flag         = null;
     overstepList = null;
 }
Exemplo n.º 13
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public virtual void ExecuteSeededGrow(SpanFillInput input, SpanFillResult ret)
        {
            this.data = new BitMap3d(input.data, input.width, input.height, input.depth);
            if (input.flagsMap == null)
            {
                this.flagsMap = new FlagMap3d(input.width, input.height, input.depth);
            }
            else
            {
                this.flagsMap = input.flagsMap;
            }
            this.result = ret;
            this.mask   = input.mask;

            if (input.GetIsFirst())
            {
                ProcessFirstSeed(input);
            }
            else
            {
                ProcessYZSeedRanges(input);
                ProcessXSeeds(input);
            }

            while (!container.Empty())
            {
                Span span = container.Pop();
                #region AllRez
                if (span.Extended == ExtendTypes.AllRez)
                {
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)//[spx-spy,y-1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(span.XLeft, span.XRight, span.Y - 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(span.XLeft, span.XRight, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)//[spx-spy,y,z+1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(span.XLeft, span.XRight, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < data.height)//[spx-spy,y+1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(span.XLeft, span.XRight, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(span.XLeft, span.XRight, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)//[spx-spy,y,z+1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(span.XLeft, span.XRight, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)//[spx-spy,y-1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(span.XLeft, span.XRight, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)//[spx-spy,y+1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(span.XLeft, span.XRight, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(span.XLeft, span.XRight, span.Y, span.Z - 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(span.XLeft, span.XRight, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(span.XLeft, span.XRight, span.Y + 1, span.Z);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(span.XLeft, span.XRight, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region UnRez
                if (span.Extended == ExtendTypes.UnRez)
                {
                    int xl = FindXLeft(span.XLeft, span.Y, span.Z);
                    int xr = FindXRight(span.XRight, span.Y, span.Z);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(xl, xr, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y + 1, span.Z, ParentDirections.Y0);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                            }
                        }
                        else
                        {
                            if (xl != span.XLeft)
                            {
                                OnOverstepY2RangeFound(xl, span.XLeft, span.Y + 1, span.Z);
                            }
                            if (span.XRight != xr)
                            {
                                OnOverstepY2RangeFound(span.XRight, xr, span.Y + 1, span.Z);
                            }
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(xl, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(xl, xr, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(xl, xr, span.Y + 1, span.Z);
                        }

                        if (span.Y - 1 >= 0)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y - 1, span.Z, ParentDirections.Y2);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                            }
                        }
                        else
                        {
                            if (xl != span.XLeft)
                            {
                                OnOverstepY0RangeFound(xl, span.XLeft, span.Y - 1, span.Z);
                            }
                            if (span.XRight != xr)
                            {
                                OnOverstepY0RangeFound(span.XRight, xr, span.Y - 1, span.Z);
                            }
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(xl, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(xl, xr, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(xl, xr, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(xl, xr, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(xl, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                            }
                        }
                        else
                        {
                            if (xl != span.XLeft)
                            {
                                OnOverstepZ2RangeFound(xl, span.XLeft, span.Y, span.Z + 1);
                            }
                            if (span.XRight != xr)
                            {
                                OnOverstepZ2RangeFound(span.XRight, xr, span.Y, span.Z + 1);
                            }
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(xl, xr, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(xl, xr, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                            }
                        }
                        else
                        {
                            if (xl != span.XLeft)
                            {
                                OnOverstepZ0RangeFound(xl, span.XLeft, span.Y, span.Z - 1);
                            }
                            if (span.XRight != xr)
                            {
                                OnOverstepZ0RangeFound(span.XRight, xr, span.Y, span.Z - 1);
                            }
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(xl, xr, span.Y, span.Z + 1);
                        }

                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Non)
                    {
                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(xl, xr, span.Y + 1, span.Z);
                        }

                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(xl, xr, span.Y - 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(xl, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(xl, xr, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region LeftRequired
                if (span.Extended == ExtendTypes.LeftRequired)
                {
                    int xl = FindXLeft(span.XLeft, span.Y, span.Z);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(xl, span.XRight, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else if (xl != span.XLeft)
                        {
                            OnOverstepY2RangeFound(xl, span.XLeft, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(xl, span.XRight, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(xl, span.XRight, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y - 1 >= 0 && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else if (xl != span.XLeft)
                        {
                            OnOverstepY0RangeFound(xl, span.XLeft, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(xl, span.XRight, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(xl, span.XRight, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(xl, span.XRight, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(xl, span.XRight, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(xl, span.XRight, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(xl, span.XRight, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else if (xl != span.XLeft)
                        {
                            OnOverstepZ2RangeFound(xl, span.XLeft, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(xl, span.XRight, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(xl, span.XRight, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0 && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else if (xl != span.XLeft)
                        {
                            OnOverstepZ0RangeFound(xl, span.XLeft, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(xl, span.XRight, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region RightRequired
                if (span.Extended == ExtendTypes.RightRequired)
                {
                    int xr = FindXRight(span.XRight, span.Y, span.Z);

                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(span.XLeft, xr, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else if (span.XRight != xr)
                        {
                            OnOverstepY2RangeFound(span.XRight, xr, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(span.XLeft, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(span.XLeft, xr, span.Y, span.Z + 1);
                        }
                        continue;
                    }

                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(span.XLeft, xr, span.Y + 1, span.Z);
                        }

                        if (span.Y - 1 >= 0 && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else if (span.XRight != xr)
                        {
                            OnOverstepY0RangeFound(span.XRight, xr, span.Y - 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(span.XLeft, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(span.XLeft, xr, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(span.XLeft, xr, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(span.XLeft, xr, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepZ0RangeFound(span.XLeft, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else if (span.XRight != xr)
                        {
                            OnOverstepZ2RangeFound(span.XRight, xr, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        else
                        {
                            OnOverstepY0RangeFound(span.XLeft, xr, span.Y - 1, span.Z);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }
                        else
                        {
                            OnOverstepY2RangeFound(span.XLeft, xr, span.Y + 1, span.Z);
                        }

                        if (span.Z - 1 >= 0 && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else if (span.XRight != xr)
                        {
                            OnOverstepZ0RangeFound(span.XRight, xr, span.Y, span.Z - 1);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepZ2RangeFound(span.XLeft, xr, span.Y, span.Z + 1);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
            }
        }
Exemplo n.º 15
0
        public virtual SpanFillResult ExecuteSeededGrow(SpanFillInput input)
        {
            this.data = new BitMap3d(input.data, input.width, input.height, input.depth);
            flagsMap  = input.flag;
            //result.Clear()
            resultCount = 0;
            container.Clear();
            SpanFillResult ret = new SpanFillResult();

            ret.Init();
            if (input.IsFirst)
            {
                Int16Triple seed = input.seed;
                Process(seed);
                flagsMap.SetFlagOn(seed.X, seed.Y, seed.Z, true);
                Span seedspan = new Span();
                seedspan.XLeft           = seed.X;
                seedspan.XRight          = seed.X;
                seedspan.Y               = seed.Y;
                seedspan.Z               = seed.Z;
                seedspan.ParentDirection = ParentDirections.Non;
                seedspan.Extended        = ExtendTypes.UnRez;
                container.Push(seedspan);
            }
            else
            {
                ParentDirections p = (input.spanlist[0].Z == 0) ? ParentDirections.Z0 : ParentDirections.Z2;
                for (int i = 0; i < input.spanlist.Count; i++)
                {
                    Range r = input.spanlist[i];
                    CheckRange(r.XLeft, r.XRight, r.Y, r.Z, p);
                }
            }

            while (!container.Empty())
            {
                Span span = container.Pop();
                #region AllRez
                if (span.Extended == ExtendTypes.AllRez)
                {
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)//[spx-spy,y-1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)//[spx-spy,y,z+1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < data.height)//[spx-spy,y+1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)//[spx-spy,y,z+1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)//[spx-spy,y-1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)//[spx-spy,y+1,z]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)//[spx-spy,y,z-1]
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region UnRez
                if (span.Extended == ExtendTypes.UnRez)
                {
                    int xl = FindXLeft(span.XLeft, span.Y, span.Z);
                    int xr = FindXRight(span.XRight, span.Y, span.Z);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < data.height)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y + 1, span.Z, ParentDirections.Y0);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                            }
                        }
                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Y - 1 >= 0)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y - 1, span.Z, ParentDirections.Y2);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                            }
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                            }
                        }
                        else
                        {
                            if (xl != span.XLeft)
                            {
                                OnOverstepSpanFound(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                            }
                            if (span.XRight != xr)
                            {
                                OnOverstepSpanFound(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                            }
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                            }
                        }
                        else
                        {
                            if (xl != span.XLeft)
                            {
                                OnOverstepSpanFound(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                            }
                            if (span.XRight != xr)
                            {
                                OnOverstepSpanFound(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                            }
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }

                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Non)
                    {
                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region LeftRequired
                if (span.Extended == ExtendTypes.LeftRequired)
                {
                    int xl = FindXLeft(span.XLeft, span.Y, span.Z);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y - 1 >= 0 && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, span.XRight, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else if (xl != span.XLeft)
                        {
                            OnOverstepSpanFound(xl, span.XLeft, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0 && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else if (xl != span.XLeft)
                        {
                            OnOverstepSpanFound(xl, span.XLeft, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(xl, span.XRight, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region RightRequired
                if (span.Extended == ExtendTypes.RightRequired)
                {
                    int xr = FindXRight(span.XRight, span.Y, span.Z);

                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }

                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Y - 1 >= 0 && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else if (span.XRight != xr)
                        {
                            OnOverstepSpanFound(span.XRight, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Z0)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, span.Z, ParentDirections.Y2);
                        }

                        if (span.Y + 1 < data.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, span.Z, ParentDirections.Y0);
                        }

                        if (span.Z - 1 >= 0 && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2);
                        }
                        else if (span.XRight != xr)
                        {
                            OnOverstepSpanFound(span.XRight, xr, span.Y, span.Z - 1, ParentDirections.Z2, ref ret);
                        }

                        if (span.Z + 1 < data.depth)
                        {
                            CheckRange(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0);
                        }
                        else
                        {
                            OnOverstepSpanFound(span.XLeft, xr, span.Y, span.Z + 1, ParentDirections.Z0, ref ret);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
            }
            //ret.resultPointSet = this.result;
            ret.resultCount = this.resultCount;
            return(ret);
        }
Exemplo n.º 16
0
 public void Clear()
 {
     data     = null;
     flag     = null;
     spanlist = null;
 }