Esempio n. 1
0
        public static List <int> getIntersections(int x, int z, Bitmap3 bmp)
        {
            List <int> interList = new List <int>();
            bool       inShape   = false;

            for (int y = 0; y < bmp.Dimensions.y; y++)
            {
                //we were out of shape and now going in shape
                if (bmp.Get(createVector(x, y, z)) == true && inShape == false)
                {
                    inShape = true;
                    interList.Add(y);
                }
                //we were in shape and now going out of shape
                if (bmp.Get(createVector(x, y, z)) == false && inShape == true)
                {
                    inShape = false;
                    interList.Add(y);
                }
                //obj reaches the pick
                if (bmp.Get(createVector(x, y, z)) == true && y == bmp.Dimensions.y - 1)
                {
                    interList.Add(y + 1);
                }
            }
            return(interList);
        }
Esempio n. 2
0
 private bool IsBlockConnectedToAir(Bitmap3 bmp, Vector3i idx)
 {
     if (idx.x - 1 >= 0 && idx.x + 1 < bmp.Dimensions.x && idx.y - 1 >= 0 && idx.y + 1 < bmp.Dimensions.y && idx.z - 1 >= 0 && idx.z + 1 < bmp.Dimensions.z)
     {
         return(!bmp.Get(new Vector3i(idx.x - 1, idx.y, idx.z)) || !bmp.Get(new Vector3i(idx.x, idx.y + 1, idx.z)) || !bmp.Get(new Vector3i(idx.x + 1, idx.y, idx.z)) ||
                !bmp.Get(new Vector3i(idx.x, idx.y - 1, idx.z)) || !bmp.Get(new Vector3i(idx.x, idx.y, idx.z + 1)) || !bmp.Get(new Vector3i(idx.x, idx.y, idx.z - 1)));
     }
     return(false);
 }
Esempio n. 3
0
        /// <summary>
        /// Adds more cells and positives to the bitmap used for mold generation
        /// </summary>
        /// <param name="bmp"></param>
        /// <returns></returns>
        private Bitmap3 BitmapOffset(Bitmap3 bmp)
        {
            Bitmap3 mold_bmp = new Bitmap3(new Vector3i(bmp.Dimensions.x + 2, bmp.Dimensions.y + 2, bmp.Dimensions.z + 2)); //extra offsets to expand positive cells

            foreach (Vector3i idx in bmp.Indices())
            {
                //needs to be positive for use to be interested
                if (!bmp.Get(idx))
                {
                    continue;
                }

                //for x
                mold_bmp.Set(new Vector3i(idx.x - 1, idx.y, idx.z), true);
                mold_bmp.Set(new Vector3i(idx.x + 1, idx.y, idx.z), true);

                //for y
                mold_bmp.Set(new Vector3i(idx.x, idx.y - 1, idx.z), true);
                mold_bmp.Set(new Vector3i(idx.x, idx.y + 1, idx.z), true);

                //for z
                mold_bmp.Set(new Vector3i(idx.x, idx.y, idx.z - 1), true);
                mold_bmp.Set(new Vector3i(idx.x, idx.y, idx.z + 1), true);
            }

            return(mold_bmp);
        }
Esempio n. 4
0
        public static Bitmap3 createVoxelizedRepresentation(String objPath)
        {
            DMesh3 mesh = StandardMeshReader.ReadMesh(objPath);

            int    num_cells = 128;
            double cell_size = mesh.CachedBounds.MaxDim / num_cells;

            MeshSignedDistanceGrid sdf = new MeshSignedDistanceGrid(mesh, cell_size);

            sdf.Compute();

            //** voxels**//
            Bitmap3 bmp = new Bitmap3(sdf.Dimensions);

            Console.WriteLine(bmp.Dimensions.x + " " + bmp.Dimensions.y + " " + bmp.Dimensions.z);
            foreach (Vector3i idx in bmp.Indices())
            {
                float f = sdf[idx.x, idx.y, idx.z];
                bmp.Set(idx, (f < 0) ? true : false);
                //for bunny only removes bottom
                if (idx.y < 8)
                {
                    bmp.Set(idx, false);
                }

                if (test) //take only one line from top
                {
                    if (idx.z != 50 || idx.x != 60)
                    {
                        bmp.Set(idx, false);
                    }
                    else
                    {
                        bmp.Set(idx, true);
                        Console.WriteLine(bmp.Get(idx));
                    }
                }
            }
            return(bmp);
        }
Esempio n. 5
0
        public static bool isCoulumnInObj(Bitmap3 bmp, int zi, int zj, int x, int z)
        {
            bool visitedInObject = false;

            for (int y = zi; y < zj; y++)
            {
                if (y < 0)
                {
                    continue;
                }
                if (y >= bmp.Dimensions.y)
                {
                    if (visitedInObject)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (!bmp.Get(createVector(x, y, z)))
                {
                    return(false);
                }
                else
                {
                    visitedInObject = true;
                }
            }
            if (visitedInObject)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        public override Schematic WriteSchematic()
        {
            DMesh3           mesh   = StandardMeshReader.ReadMesh(_path);
            AxisAlignedBox3d bounds = mesh.CachedBounds;

            DMeshAABBTree3    spatial  = new DMeshAABBTree3(mesh, autoBuild: true);
            double            cellsize = mesh.CachedBounds.MaxDim / _gridSize;
            ShiftGridIndexer3 indexer  = new ShiftGridIndexer3(bounds.Min, cellsize);

            MeshSignedDistanceGrid sdf = new MeshSignedDistanceGrid(mesh, cellsize);

            sdf.Compute();

            Bitmap3 bmp = new Bitmap3(sdf.Dimensions);

            Schematic schematic = new Schematic()
            {
                Blocks = new HashSet <Block>(),
                Width  = (ushort)bmp.Dimensions.x,
                Height = (ushort)bmp.Dimensions.y,
                Length = (ushort)bmp.Dimensions.z
            };

            LoadedSchematic.WidthSchematic  = schematic.Width;
            LoadedSchematic.HeightSchematic = schematic.Height;
            LoadedSchematic.LengthSchematic = schematic.Length;

            if (_winding_number != 0)
            {
                spatial.WindingNumber(Vector3d.Zero);  // seed cache outside of parallel eval

                using (ProgressBar progressbar = new ProgressBar())
                {
                    List <Vector3i> list  = bmp.Indices().ToList();
                    int             count = 0;
                    gParallel.ForEach(bmp.Indices(), (idx) =>
                    {
                        Vector3d v = indexer.FromGrid(idx);
                        bmp.SafeSet(idx, spatial.WindingNumber(v) > _winding_number);
                        count++;
                        progressbar.Report(count / (float)list.Count);
                    });
                }
                if (!_excavate)
                {
                    foreach (Vector3i idx in bmp.Indices())
                    {
                        if (bmp.Get(idx))
                        {
                            schematic.Blocks.Add(new Block((ushort)idx.x, (ushort)idx.y, (ushort)idx.z, Color.White.ColorToUInt()));
                        }
                    }
                }
            }
            else
            {
                using (ProgressBar progressbar = new ProgressBar())
                {
                    int             count = bmp.Indices().Count();
                    List <Vector3i> list  = bmp.Indices().ToList();
                    for (int i = 0; i < count; i++)
                    {
                        Vector3i idx      = list[i];
                        float    f        = sdf[idx.x, idx.y, idx.z];
                        bool     isInside = f < 0;
                        bmp.Set(idx, (f < 0));

                        if (!_excavate && isInside)
                        {
                            schematic.Blocks.Add(new Block((ushort)idx.x, (ushort)idx.y, (ushort)idx.z, Color.White.ColorToUInt()));
                        }
                        progressbar.Report((i / (float)count));
                    }
                }
            }



            if (_excavate)
            {
                foreach (Vector3i idx in bmp.Indices())
                {
                    if (bmp.Get(idx) && IsBlockConnectedToAir(bmp, idx))
                    {
                        schematic.Blocks.Add(new Block((ushort)idx.x, (ushort)idx.y, (ushort)idx.z, Color.White.ColorToUInt()));
                    }
                }
            }

            return(schematic);
        }