Пример #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <DMesh3_goo> goo = new List <DMesh3_goo>();
            int numCells          = 64;

            DA.GetDataList(0, goo);
            DA.GetData(1, ref numCells);

            ImplicitNaryUnion3d diff2 = new ImplicitNaryUnion3d();

            diff2.Children = goo.Select(x => g3ghUtil.MeshToImplicit(x.Value, numCells, 0.2f)).ToList();

            g3.MarchingCubes c = new g3.MarchingCubes();
            c.Implicit      = diff2;
            c.RootMode      = g3.MarchingCubes.RootfindingModes.Bisection;
            c.RootModeSteps = 5;
            c.Bounds        = diff2.Bounds();
            c.CubeSize      = c.Bounds.MaxDim / numCells;
            c.Bounds.Expand(3 * c.CubeSize);
            c.Generate();

            MeshNormals.QuickCompute(c.Mesh);

            DA.SetData(0, c.Mesh);
        }
Пример #2
0
        protected virtual DMesh3 compute_wrap()
        {
            cache_input_sdfs();
            if (is_invalidated())
            {
                return(null);
            }

            BoundedImplicitFunction3d iso = null;

            if (op_type == OpTypes.Union)
            {
                iso = new ImplicitNaryUnion3d()
                {
                    Children = new List <BoundedImplicitFunction3d>(cached_isos)
                };
            }
            else if (op_type == OpTypes.Intersection)
            {
                iso = new ImplicitNaryIntersection3d()
                {
                    Children = new List <BoundedImplicitFunction3d>(cached_isos)
                };
            }
            else if (op_type == OpTypes.Difference)
            {
                iso = new ImplicitNaryDifference3d()
                {
                    A    = cached_isos[0],
                    BSet = new List <BoundedImplicitFunction3d>(cached_isos.Skip(1))
                };
            }

            MarchingCubes c = new MarchingCubes();

            c.Implicit = iso;
            c.IsoValue = 0;
            c.Bounds   = iso.Bounds();
            c.CubeSize = mesh_cell_size;
            c.Bounds.Expand(3 * c.CubeSize);
            c.RootMode      = MarchingCubes.RootfindingModes.Bisection;
            c.RootModeSteps = 5;

            c.CancelF = is_invalidated;
            c.Generate();
            if (is_invalidated())
            {
                return(null);
            }

            Reducer r = new Reducer(c.Mesh);

            r.FastCollapsePass(c.CubeSize / 2, 3, true);
            if (is_invalidated())
            {
                return(null);
            }

            if (min_component_volume > 0)
            {
                MeshEditor.RemoveSmallComponents(c.Mesh, min_component_volume, min_component_volume);
            }
            if (is_invalidated())
            {
                return(null);
            }

            return(c.Mesh);
        }
Пример #3
0
        public static void test_marching_cubes_implicits()
        {
            DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj");

            MeshTransforms.Translate(mesh, -mesh.CachedBounds.Center);
            double meshCellsize             = mesh.CachedBounds.MaxDim / 32;
            MeshSignedDistanceGrid levelSet = new MeshSignedDistanceGrid(mesh, meshCellsize);

            levelSet.ExactBandWidth = 3;
            levelSet.UseParallel    = true;
            levelSet.ComputeMode    = MeshSignedDistanceGrid.ComputeModes.NarrowBandOnly;
            levelSet.Compute();
            var meshIso = new DenseGridTrilinearImplicit(levelSet.Grid, levelSet.GridOrigin, levelSet.CellSize);


            ImplicitOffset3d offsetMeshIso = new ImplicitOffset3d()
            {
                A = meshIso, Offset = 2.0
            };

            double           r       = 15.0;
            ImplicitSphere3d sphere1 = new ImplicitSphere3d()
            {
                Origin = Vector3d.Zero,
                Radius = r
            };
            ImplicitSphere3d sphere2 = new ImplicitSphere3d()
            {
                Origin = r * Vector3d.AxisX,
                Radius = r
            };
            ImplicitAxisAlignedBox3d aabox1 = new ImplicitAxisAlignedBox3d()
            {
                AABox = new AxisAlignedBox3d(r * 0.5 * Vector3d.One, r, r * 0.75, r * 0.5)
            };
            ImplicitBox3d box1 = new ImplicitBox3d()
            {
                Box = new Box3d(new Frame3f(r * 0.5 * Vector3d.One, Vector3d.One.Normalized),
                                new Vector3d(r, r * 0.75, r * 0.5))
            };
            ImplicitLine3d line1 = new ImplicitLine3d()
            {
                Segment = new Segment3d(Vector3d.Zero, r * Vector3d.One),
                Radius  = 3.0
            };
            ImplicitHalfSpace3d half1 = new ImplicitHalfSpace3d()
            {
                Origin = Vector3d.Zero, Normal = Vector3d.One.Normalized
            };

            ImplicitUnion3d union = new ImplicitUnion3d()
            {
                A = sphere1, B = line1
            };
            ImplicitDifference3d difference = new ImplicitDifference3d()
            {
                A = meshIso, B = aabox1
            };
            ImplicitIntersection3d intersect = new ImplicitIntersection3d()
            {
                A = meshIso, B = half1
            };
            ImplicitNaryUnion3d nunion = new ImplicitNaryUnion3d()
            {
                Children = new List <BoundedImplicitFunction3d>()
                {
                    offsetMeshIso, sphere1, sphere2
                }
            };
            ImplicitNaryDifference3d ndifference = new ImplicitNaryDifference3d()
            {
                A    = offsetMeshIso,
                BSet = new List <BoundedImplicitFunction3d>()
                {
                    sphere1, sphere2
                }
            };
            ImplicitBlend3d blend = new ImplicitBlend3d()
            {
                A = sphere1, B = sphere2
            };

            BoundedImplicitFunction3d root = intersect;

            AxisAlignedBox3d bounds = root.Bounds();
            int           numcells  = 64;
            MarchingCubes c         = new MarchingCubes();

            c.RootMode      = MarchingCubes.RootfindingModes.LerpSteps;
            c.RootModeSteps = 5;
            c.Implicit      = root;
            c.Bounds        = bounds;
            c.CubeSize      = bounds.MaxDim / numcells;
            c.Bounds.Expand(3 * c.CubeSize);

            c.Generate();

            MeshNormals.QuickCompute(c.Mesh);
            TestUtil.WriteTestOutputMesh(c.Mesh, "marching_cubes_implicit.obj");
        }
Пример #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo goo             = null;
            double     lattice_radius  = 0.05;
            double     lattice_spacing = 0.4;
            double     shell_thickness = 0.05;
            int        mesh_resolution = 64;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref lattice_radius);
            DA.GetData(2, ref lattice_spacing);
            DA.GetData(3, ref shell_thickness);
            DA.GetData(4, ref mesh_resolution);

            DMesh3 mesh = new DMesh3(goo.Value);

            var              shellMeshImplicit = g3ghUtil.MeshToImplicit(mesh, 128, shell_thickness);
            double           max_dim           = mesh.CachedBounds.MaxDim;
            AxisAlignedBox3d bounds            = new AxisAlignedBox3d(mesh.CachedBounds.Center, max_dim / 2);

            bounds.Expand(2 * lattice_spacing);
            AxisAlignedBox2d element   = new AxisAlignedBox2d(lattice_spacing);
            AxisAlignedBox2d bounds_xy = new AxisAlignedBox2d(bounds.Min.xy, bounds.Max.xy);
            AxisAlignedBox2d bounds_xz = new AxisAlignedBox2d(bounds.Min.xz, bounds.Max.xz);
            AxisAlignedBox2d bounds_yz = new AxisAlignedBox2d(bounds.Min.yz, bounds.Max.yz);

            List <BoundedImplicitFunction3d> Tiling = new List <BoundedImplicitFunction3d>();

            foreach (g3.Vector2d uv in TilingUtil.BoundedRegularTiling2(element, bounds_xy, 0))
            {
                Segment3d seg = new Segment3d(new g3.Vector3d(uv.x, uv.y, bounds.Min.z), new g3.Vector3d(uv.x, uv.y, bounds.Max.z));
                Tiling.Add(new ImplicitLine3d()
                {
                    Segment = seg, Radius = lattice_radius
                });
            }
            foreach (g3.Vector2d uv in TilingUtil.BoundedRegularTiling2(element, bounds_xz, 0))
            {
                Segment3d seg = new Segment3d(new g3.Vector3d(uv.x, bounds.Min.y, uv.y), new g3.Vector3d(uv.x, bounds.Max.y, uv.y));
                Tiling.Add(new ImplicitLine3d()
                {
                    Segment = seg, Radius = lattice_radius
                });
            }
            foreach (g3.Vector2d uv in TilingUtil.BoundedRegularTiling2(element, bounds_yz, 0))
            {
                Segment3d seg = new Segment3d(new g3.Vector3d(bounds.Min.x, uv.x, uv.y), new g3.Vector3d(bounds.Max.x, uv.x, uv.y));
                Tiling.Add(new ImplicitLine3d()
                {
                    Segment = seg, Radius = lattice_radius
                });
            }

            ImplicitNaryUnion3d lattice = new ImplicitNaryUnion3d()
            {
                Children = Tiling
            };
            ImplicitIntersection3d lattice_clipped = new ImplicitIntersection3d()
            {
                A = lattice, B = shellMeshImplicit
            };

            g3.MarchingCubes c = new g3.MarchingCubes();
            c.Implicit      = lattice_clipped;
            c.RootMode      = g3.MarchingCubes.RootfindingModes.LerpSteps;
            c.RootModeSteps = 5;
            c.Bounds        = lattice_clipped.Bounds();
            c.CubeSize      = c.Bounds.MaxDim / mesh_resolution;
            c.Bounds.Expand(3 * c.CubeSize);
            c.Generate();
            MeshNormals.QuickCompute(c.Mesh);


            DA.SetData(0, c.Mesh);
        }