private ByteMatrix FillMesh() { int stx = (int)(range.Min3[0] - 2); int sty = (int)(range.Min3[1] - 2); int stz = (int)(range.Min3[2] - 2); int width = (int)(range.GetXLength() + 4); int height = (int)(range.GetYLength() + 4); int depth = (int)(range.GetZLength() + 4); ByteMatrix bmp = new ByteMatrix(stx, sty, stz, width, height, depth, 0); FillTriangles(bmp, 255); BitMap3d cmp = new BitMap3d(bmp.data, bmp.width, bmp.height, bmp.depth); //cmp.SaveRaw("ret1T " + bmp.width + "_" + bmp.height + "_" + bmp.depth + ".raw"); SpanFill3d rg = new SpanFill3d(); rg.ExcuteSpanFill(bmp, new Int16Triple(0, 0, 0), 0, 128); ReverseValue(bmp); return(bmp); }
public List <Int16Triple> GetVoxels() { List <Int16Triple> list = new List <Int16Triple>(); ByteMatrix mat = FillMesh(); for (int k = 0; k < mat.depth; k++) { for (int j = 0; j < mat.height; j++) { for (int i = 0; i < mat.width; i++) { if (mat.GetValue(i, j, k) == 255) { Int16Triple t = new Int16Triple(i + mat.stx, j + mat.sty, k + mat.stz); list.Add(t); } } } } return(list); }
public virtual void ExcuteSpanFill(ByteMatrix data, Int16Triple seed, byte includeColor, byte replaceColor) { this.includeColor = includeColor; this.replaceColor = replaceColor; this.container = new Stack <Span>(); this.bmp = data; Process(seed.X, seed.Y, seed.Z); 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.Count != 0) { 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 } }
public FillTriangle(ByteMatrix bmp, byte value) { bmpMap = bmp; Color = value; }