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); } } } } }