protected int FindXLeft(int x, int y, int z) { int xleft = x - 1; while (true) { if (xleft == -1 || flagsMap.GetFlagOn(xleft, y, z)) { if (xleft == -1) { OnOverstepX0PointFound(xleft, y, z); } break; } else { if (IncludeConditionMeets(xleft, y, z)) { Int16Triple t = new Int16Triple(xleft, y, z); flagsMap.SetFlagOn(xleft, y, z, true); Process(t); xleft--; } else { break; } } } return(xleft + 1); }
private Block GetFirstBlock(Int16Triple seed) { if (seed.X < 0 || seed.X > image.GetWidth() || seed.Y < 0 || seed.Y > image.GetHeight() || seed.Z < 0 || seed.Z > image.GetDepth()) throw new Exception(); Int16Triple index = image.GetBlockIndex(seed); return image.GetBlock(index.X, index.Y, index.Z); }
protected void InitAdj6(Int16Triple[] adjPoints6, Int16Triple p) { adjPoints6[0].X = p.X - 1; adjPoints6[0].Y = p.Y; adjPoints6[0].Z = p.Z; adjPoints6[1].X = p.X + 1; adjPoints6[1].Y = p.Y; adjPoints6[1].Z = p.Z; adjPoints6[2].X = p.X; adjPoints6[2].Y = p.Y - 1; adjPoints6[2].Z = p.Z; adjPoints6[3].X = p.X; adjPoints6[3].Y = p.Y + 1; adjPoints6[3].Z = p.Z; adjPoints6[4].X = p.X; adjPoints6[4].Y = p.Y; adjPoints6[4].Z = p.Z - 1; adjPoints6[5].X = p.X; adjPoints6[5].Y = p.Y; adjPoints6[5].Z = p.Z + 1; }
public Mesh GenerateSurface() { d = bmp.depth; h = bmp.height; w = bmp.width; wh = w * h; Int16Triple[] temp = new Int16Triple[8]; Mesh m = new Mesh(); OriginalTriangle[] tempTriangles = new OriginalTriangle[4]; SMCTriangleNetHashTable hash = new SMCTriangleNetHashTable(0, 0, w, h); for (int k = 0; k <= d - 1; k++) { for (int j = 0; j <= h - 1; j++) { for (int i = 0; i <= w - 1; i++) { byte value = GetConfig(temp, bmp, i, j, k); if (value == 0 || value == 255) { continue; } int tcount = ExtractTriangles(temp, value, i, j, k, tempTriangles); for (int tindex = 0; tindex < tcount; tindex++) { MergeTriangleIntoMesh(m, hash, tempTriangles[tindex]); } } } hash.IncreaseIndex(); } return(m); }
}//get copnfig private void ExtractTriangles(ref Cube cube, byte value, MeshBuilder_FloatVertex builder) { if (MCTable.TriTable[value, 0] != -1) { int index = 0; while (MCTable.TriTable[value, index] != -1) { int e0index = MCTable.TriTable[value, index]; int e1index = MCTable.TriTable[value, index + 1]; int e2index = MCTable.TriTable[value, index + 2]; Int16Triple e0p0 = cube.cubeImageIndices[Cube.EdgeIndexToEdgeVertexIndex[e0index, 0]]; Int16Triple e0p1 = cube.cubeImageIndices[Cube.EdgeIndexToEdgeVertexIndex[e0index, 1]]; Int16Triple e1p0 = cube.cubeImageIndices[Cube.EdgeIndexToEdgeVertexIndex[e1index, 0]]; Int16Triple e1p1 = cube.cubeImageIndices[Cube.EdgeIndexToEdgeVertexIndex[e1index, 1]]; Int16Triple e2p0 = cube.cubeImageIndices[Cube.EdgeIndexToEdgeVertexIndex[e2index, 0]]; Int16Triple e2p1 = cube.cubeImageIndices[Cube.EdgeIndexToEdgeVertexIndex[e2index, 1]]; Point3d e0pm = GetIntersetedPoint(e0p0, e0p1); Point3d e1pm = GetIntersetedPoint(e1p0, e1p1); Point3d e2pm = GetIntersetedPoint(e2p0, e2p1); builder.AddTriangle(e0pm, e1pm, e2pm); index += 3; } } }//extract triangles and put them into mesh builder
protected int FindXLeft(int x, int y, int z) { int xleft = x - 1; while (true) { if (xleft == -1 || flagsMap.GetFlagOn(xleft, y, z)) { break; } else { if (IncludePredicate(xleft, y, z)) { Int16Triple t = new Int16Triple(xleft, y, z); flagsMap.SetFlagOn(xleft, y, z, true); Process(t); xleft--; } else { break; } } } return(xleft + 1); }
}//区段法的CheckRange 注意与扫描线的CheckRange的不同 protected int FindXRight(int x, int y, int z) { int xright = x + 1; while (true) { if (xright == data.width || flagsMap.GetFlagOn(xright, y, z)) { if (xright == data.width) { OnOverstepX2PointFound(xright, y, z); } break; } else { if (IncludeConditionMeets(xright, y, z)) { Int16Triple t = new Int16Triple(xright, y, z); flagsMap.SetFlagOn(xright, y, z, true); Process(t); xright++; } else { break; } } } return(xright - 1); }
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; }
}//区段法的CheckRange 注意与扫描线的CheckRange的不同 protected int FindXRight(int x, int y, int z) { int xright = x + 1; while (true) { if (xright == bmp.width || flagsMap.GetFlagOn(xright, y, z)) { break; } else { if (IncludePredicate(xright, y, z)) { Int16Triple t = new Int16Triple(xright, y, z); flagsMap.SetFlagOn(xright, y, z, true); Process(t); xright++; } else { break; } } } return(xright - 1); }
}//CheckRange操作 protected int FindXLeft(Int16Triple p) { int xleft = p.X - 1; while (true) { if (xleft == -1 || flagsMap.GetFlagOn(xleft, p.Y, p.Z)) { break; } else { byte value = bmp.GetPixel(xleft, p.Y, p.Z); if (IncludePredicate(xleft, p.Y, p.Z)) { Int16Triple t = new Int16Triple(xleft, p.Y, p.Z); flagsMap.SetFlagOn(xleft, p.Y, p.Z, true); Process(t); xleft--; } else { break; } } } return(xleft + 1); }//FindXLeft操作
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); } } }//该函数为扫描线法主体
}//FindXLeft操作 protected int FindXRight(Int16Triple p) { int xright = p.X + 1; while (true) { if (xright == bmp.width || flagsMap.GetFlagOn(xright, p.Y, p.Z)) { break; } else { byte value = bmp.GetPixel(xright, p.Y, p.Z); if (IncludePredicate(xright, p.Y, p.Z)) { Int16Triple t = new Int16Triple(xright, p.Y, p.Z); flagsMap.SetFlagOn(xright, p.Y, p.Z, true); Process(t); xright++; } else { break; } } } return(xright - 1); }//FindXRight操作
public void ClearAll() { data = null; width = -1; height = -1; depth = -1; data = null; seed = new Int16Triple(-1, -1, -1); mask = null; if (overstepPointList != null) { for (int i = 0; i < 2; i++) { if (overstepPointList[i] != null) { overstepPointList[i].Clear(); } } } if (overstepRangeList != null) { for (int i = 0; i < 4; i++) { if (overstepRangeList[i] != null) { overstepRangeList[i].Clear(); } } } overstepPointList = null; overstepRangeList = null; }
public void ExecuteSeededGrow(Int16Triple firstseed) { if (buffer == null || seedGrowExecutor == null || dataProvider == null) { throw new Exception(); } queue = new Container_Stack <LayerDataAndInput>(); Layer firstLayer = GetFirstLayer(firstseed); FloodFillInput firstInput = new FloodFillInput (buffer, firstLayer.AllWidth, firstLayer.AllHeight, firstLayer.actualDepth, firstLayer.GetAndInitFlag(), new List <Int16Triple>() { ConvertGlobalCoodToLayerCoold(firstLayer, firstseed) }, firstLayer.HasUpperLayer(), firstLayer.HasLowerLayer(), true); queue.Push(new LayerDataAndInput(firstLayer, firstInput)); while (!queue.Empty()) { LayerDataAndInput sgi = queue.Pop(); Layer layer = sgi.layer; layer.visitcount++; FloodFillInput input = sgi.input; FillLayerData(layer); FloodFillResult ret1 = seedGrowExecutor.ExecuteSeededGrow(input); input.overstepList.Clear(); //ConvertLayerCoordsToGlobalCoords(layer,ret1.resultPointSet); //resultSet.AddRange(ret1.resultPointSet); resultCount += ret1.resultCount; if (ret1.GetNeedsSeekLower()) { Layer lowerlayer = image.GetLayer(layer.indexZ - 1); if (lowerlayer == null) { ret1.boundaryRequestPoints[0].Clear(); continue; } ConvertOtherLayerCoordsToThisLayerCoords(layer, lowerlayer, ret1.boundaryRequestPoints[0]); FloodFillInput newinput = new FloodFillInput (buffer, lowerlayer.AllWidth, lowerlayer.AllHeight, lowerlayer.actualDepth, lowerlayer.GetAndInitFlag(), ret1.boundaryRequestPoints[0], lowerlayer.HasUpperLayer(), lowerlayer.HasLowerLayer(), false); queue.Push(new LayerDataAndInput(lowerlayer, newinput)); } if (ret1.GetNeedsSeekUpper()) { Layer upperlayer = image.GetLayer(layer.indexZ + 1); if (upperlayer == null) { ret1.boundaryRequestPoints[1].Clear(); continue; } ConvertOtherLayerCoordsToThisLayerCoords(layer, upperlayer, ret1.boundaryRequestPoints[1]); FloodFillInput newinput = new FloodFillInput (buffer, upperlayer.AllWidth, upperlayer.AllHeight, upperlayer.actualDepth, upperlayer.GetAndInitFlag(), ret1.boundaryRequestPoints[1], upperlayer.HasUpperLayer(), upperlayer.HasLowerLayer(), false); queue.Push(new LayerDataAndInput(upperlayer, newinput)); } } }
private void ConvertLayerCoordsToGlobalCoords(Layer thislayer, List <Int16Triple> adjSeedList) { for (int i = 0; i < adjSeedList.Count; i++) { Int16Triple old = adjSeedList[i]; old.Z += thislayer.stz; adjSeedList[i] = old; } }
private void ConvertOtherLayerCoordsToThisLayerCoords(Layer thislayer, Layer other, List <Int16Triple> adjSeedList) { for (int i = 0; i < adjSeedList.Count; i++) { Int16Triple old = adjSeedList[i]; old.Z += (thislayer.stz - other.stz); adjSeedList[i] = old; } }
private Layer GetFirstLayer(Int16Triple seed) { if (seed.X < 0 || seed.X > image.GetWidth() || seed.Y < 0 || seed.Y > image.GetHeight() || seed.Z < 0 || seed.Z > image.GetDepth()) { throw new Exception(); } int index = image.GetLayerIndex(seed); return(image.GetLayer(index)); }
public SpanFillInput() { this.data = null; this.width = -1; this.height = -1; this.depth = -1; this.overstepPointList = null; this.overstepRangeList = null; this.seed = new Int16Triple(-1, -1, -1); this.mask = null; }
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; }
private void ConvertThisBlockCoordsToOtherBlockCoords(Block thisblock, Block other, List <Int16Triple> pList) { for (int i = 0; i < pList.Count; i++) { Int16Triple old = pList[i]; old.X += (thisblock.stx - other.stx); old.Y += (thisblock.sty - other.sty); old.Z += (thisblock.stz - other.stz); pList[i] = old; } }
private void ConvertBlockCoordsToGlobalCoords(Block thisblock, List <Int16Triple> pList) { for (int i = 0; i < pList.Count; i++) { Int16Triple old = pList[i]; old.X += thisblock.stx; old.Y += thisblock.sty; old.Z += thisblock.stz; pList[i] = old; } }
//public List<Int16Triple>[] boundaryOverstepOutside; public BlockIR_FF() { boundarySeedsInside = new List <Int16Triple> [6]; //boundaryOverstepOutside = new List<Int16Triple>[6]; for (int i = 0; i < 6; i++) { boundarySeedsInside[i] = new List <Int16Triple>(); //boundaryOverstepOutside[i] = new List<Int16Triple>(); } singleSeed = new Int16Triple(-1, -1, -1); }
public int GetLayerIndex(Int16Triple innerPoint) { for (int k = 0; k < layerCount; k++) { Layer b = this.GetLayer(k); if (b.HasPoint(innerPoint)) { return(k); } } throw new Exception(); }
public BlockIR_SP() { boundarySeedXsInside = new List<Int16Triple>[2]; boundaryRangesYZInside = new List<Range>[4]; for (int i = 0; i < 2; i++) { boundarySeedXsInside[i] = new List<Int16Triple>(); } for (int i = 0; i < 4; i++) { boundaryRangesYZInside[i] = new List<Range>(); } singleSeed = new Int16Triple(-1, -1, -1); }
private void ProcessFirstSeed(SpanFillInput input) { 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); }
}//get copnfig private void ExtractTriangles(ref Cube cube, byte value, MeshBuilder_IntegerVertex builder) { if (SMCTable.TableFat[value, 0] != -1) { int index = 0; while (SMCTable.TableFat[value, index] != -1) { Int16Triple t0 = cube.cubeImageIndices[SMCTable.TableFat[value, index]]; Int16Triple t1 = cube.cubeImageIndices[SMCTable.TableFat[value, index + 1]]; Int16Triple t2 = cube.cubeImageIndices[SMCTable.TableFat[value, index + 2]]; builder.AddTriangle(t0, t1, t2); //builder.AddTriangle(new Point3d(t0.X,t0.Y,t0.Z), new Point3d(t1.X,t1.Y,t1.Z), new Point3d(t2.X,t2.Y,t2.Z )); index += 3; } } }//extract triangles and put them into meshbuilder
public Int16Triple GetBlockIndex(Int16Triple seed) { for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { for (int k = 0; k < layerCount; k++) { if (blocksMap[i, j, k].HasPoint(seed)) { return(new Int16Triple(i, j, k)); } } } } throw new Exception(); }
public void ExcuteSpanFill_Stack(BitMap3d data, Int16Triple seed) { watch.Start(); container = new Container_Stack <Span>(); base.ExcuteSpanFill(data, seed); watch.Stop(); report.time = watch.ElapsedMilliseconds; report.result_point_count = count; report.bmp_get_count = data.action_get_count; report.bmp_set_count = data.action_set_count; report.container_pop_count = container.action_pop_count; report.container_push_count = container.action_push_count; report.container_max_size = container.max_contain_count; report.flag_get_count = flagsMap.action_get_count; report.flag_set_count = flagsMap.action_set_count; return; }
private int ExtractTriangles(Int16Triple[] temp, byte value, int indexInWidth, int indexInHeight, int indexInDepth, OriginalTriangle[] result) { int tcount = 0; if (SMCTable.TableFat[value, 0] != -1) { int index = 0; while (SMCTable.TableFat[value, index] != -1) { Int16Triple t0 = temp[SMCTable.TableFat[value, index]]; Int16Triple t1 = temp[SMCTable.TableFat[value, index + 1]]; Int16Triple t2 = temp[SMCTable.TableFat[value, index + 2]]; result[tcount] = new OriginalTriangle(t0.X, t0.Y, t0.Z, t1.X, t1.Y, t1.Z, t2.X, t2.Y, t2.Z); tcount++; index += 3; } } return(tcount); }
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; }