コード例 #1
0
ファイル: Bitmap3d.cs プロジェクト: quantumdot/geometry3Sharp
        /// <summary>
        /// count 6-nbrs of each voxel, discard if count <= minNbrs
        /// </summary>
        public void Filter(int nMinNbrs)
        {
            AxisAlignedBox3i bounds = GridBounds;

            bounds.Max -= Vector3i.One;

            for (int i = 0; i < Bits.Length; ++i)
            {
                if (Bits[i] == false)
                {
                    continue;
                }
                Vector3i idx = ToIndex(i);
                int      nc  = 0;
                for (int k = 0; k < 6 && nc <= nMinNbrs; ++k)
                {
                    Vector3i nbr = idx + gIndices.GridOffsets6[k];
                    if (bounds.Contains(nbr) == false)
                    {
                        continue;
                    }
                    if (Get(nbr))
                    {
                        nc++;
                    }
                }
                if (nc <= nMinNbrs)
                {
                    Bits[i] = false;
                }
            }
        }
コード例 #2
0
        public void Generate()
        {
            append_mesh();

            AxisAlignedBox3i bounds = Voxels.GridBounds;

            bounds.Max -= Vector3i.One;

            int[] vertices = new int[4];

            foreach (Vector3i nz in Voxels.NonZeros())
            {
                check_counts_or_append(6, 2);

                Box3d cube = Box3d.UnitZeroCentered;
                cube.Center = (Vector3d)nz;

                for (int fi = 0; fi < 6; ++fi)
                {
                    // checks dependent on neighbours
                    Index3i nbr = nz + gIndices.GridOffsets6[fi];
                    if (bounds.Contains(nbr))
                    {
                        if (SkipInteriorFaces && Voxels.Get(nbr))
                        {
                            continue;
                        }
                    }
                    else if (CapAtBoundary == false)
                    {
                        continue;
                    }


                    int           ni = gIndices.BoxFaceNormals[fi];
                    Vector3f      n  = (Vector3f)(Math.Sign(ni) * cube.Axis(Math.Abs(ni) - 1));
                    NewVertexInfo vi = new NewVertexInfo(Vector3d.Zero, n);
                    if (ColorSourceF != null)
                    {
                        vi.c      = ColorSourceF(nz);
                        vi.bHaveC = true;
                    }
                    for (int j = 0; j < 4; ++j)
                    {
                        vi.v        = cube.Corner(gIndices.BoxFaces[fi, j]);
                        vertices[j] = cur_mesh.AppendVertex(vi);
                    }

                    Index3i t0 = new Index3i(vertices[0], vertices[1], vertices[2], Clockwise);
                    Index3i t1 = new Index3i(vertices[0], vertices[2], vertices[3], Clockwise);
                    cur_mesh.AppendTriangle(t0);
                    cur_mesh.AppendTriangle(t1);
                }
            }
        }
コード例 #3
0
        public ImplicitFieldSampler3d(AxisAlignedBox3d fieldBounds, double cellSize)
        {
            CellSize   = cellSize;
            GridOrigin = fieldBounds.Min;
            Indexer    = new ShiftGridIndexer3(GridOrigin, CellSize);

            Vector3d max = fieldBounds.Max; max += cellSize;
            int      ni  = (int)((max.x - GridOrigin.x) / CellSize) + 1;
            int      nj  = (int)((max.y - GridOrigin.y) / CellSize) + 1;
            int      nk  = (int)((max.z - GridOrigin.z) / CellSize) + 1;

            GridBounds = new AxisAlignedBox3i(0, 0, 0, ni, nj, nk);

            BackgroundValue = (float)((ni + nj + nk) * CellSize);
            Grid            = new DenseGrid3f(ni, nj, nk, BackgroundValue);
        }
コード例 #4
0
        public void Sample(BoundedImplicitFunction3d f, double expandRadius = 0)
        {
            AxisAlignedBox3d bounds = f.Bounds();

            Vector3d expand  = expandRadius * Vector3d.One;
            Vector3i gridMin = Indexer.ToGrid(bounds.Min - expand),
                     gridMax = Indexer.ToGrid(bounds.Max + expand) + Vector3i.One;

            gridMin = GridBounds.ClampExclusive(gridMin);
            gridMax = GridBounds.ClampExclusive(gridMax);

            AxisAlignedBox3i gridbox = new AxisAlignedBox3i(gridMin, gridMax);

            switch (CombineMode)
            {
            case CombineModes.DistanceMinUnion:
                sample_min(f, gridbox.IndicesInclusive());
                break;
            }
        }
コード例 #5
0
 /// <summary>
 /// Must provide a sample instance of the element type that we can Duplicate()
 /// to make additional copies. Should be no data in here
 /// </summary>
 public DSparseGrid3(ElemType toDuplicate)
 {
     this.exemplar = toDuplicate;
     elements      = new Dictionary <Vector3i, ElemType>();
     bounds        = AxisAlignedBox3i.Empty;
 }