コード例 #1
0
        public static void test_tiling()
        {
            Vector2d         origin     = Vector2d.Zero;
            double           radius     = 22;
            Circle2d         circ       = new Circle2d(origin, radius);
            AxisAlignedBox2d elemBounds = circ.Bounds;
            //elemBounds.Max.x += radius / 2;

            AxisAlignedBox2d packBounds = new AxisAlignedBox2d(0, 0, 800, 400);
            double           spacing    = 5;
            Polygon2d        boundsPoly = new Polygon2d();

            for (int i = 0; i < 4; ++i)
            {
                boundsPoly.AppendVertex(packBounds.GetCorner(i));
            }

            //List<Vector2d> packed = TilingUtil.BoundedRegularTiling2(elemBounds, packBounds, spacing);
            List <Vector2d> packed = TilingUtil.BoundedCircleTiling2(elemBounds, packBounds, spacing);

            System.Console.WriteLine("packed {0}", packed.Count);

            SVGWriter writer = new SVGWriter();

            foreach (Vector2d t in packed)
            {
                writer.AddCircle(new Circle2d(origin + t, radius), SVGWriter.Style.Outline("black", 1.0f));
            }
            writer.AddPolygon(boundsPoly, SVGWriter.Style.Outline("red", 2.0f));
            writer.Write(TestUtil.GetTestOutputPath("test.svg"));
        }
コード例 #2
0
ファイル: VolumetricLattice.cs プロジェクト: joelhi/g3-gh
        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);
        }