Exemplo n.º 1
0
        public static void flip_tests(bool bTestBoundary, int N = 100)
        {
            System.Console.WriteLine("DMesh3:flip_tests() starting");

            DMesh3 mesh = TestUtil.MakeCappedCylinder(bTestBoundary);

            mesh.CheckValidity();

            Random r = new Random(31377);

            for (int k = 0; k < N; ++k)
            {
                int eid = r.Next() % mesh.EdgeCount;
                if (!mesh.IsEdge(eid))
                {
                    continue;
                }
                bool bBoundary = mesh.IsBoundaryEdge(eid);

                DMesh3.EdgeFlipInfo flipInfo;
                MeshResult          result = mesh.FlipEdge(eid, out flipInfo);
                if (bBoundary)
                {
                    Debug.Assert(result == MeshResult.Failed_IsBoundaryEdge);
                }
                else
                {
                    Debug.Assert(result == MeshResult.Ok || result == MeshResult.Failed_FlippedEdgeExists);
                }
                mesh.CheckValidity();
            }

            System.Console.WriteLine("flips ok");
        }
Exemplo n.º 2
0
        public static void poke_test()
        {
            DMesh3 mesh = TestUtil.LoadTestInputMesh("plane_250v.obj");

            //DMesh3 mesh = TestUtil.LoadTestInputMesh("sphere_bowtie_groups.obj");
            mesh.CheckValidity();


            int NT = mesh.TriangleCount;

            for (int i = 0; i < NT; i += 5)
            {
                Vector3d n = mesh.GetTriNormal(i);
                DMesh3.PokeTriangleInfo pokeinfo;
                MeshResult result = mesh.PokeTriangle(i, out pokeinfo);

                Vector3d v = mesh.GetVertex(pokeinfo.new_vid);
                v += 0.25f * n;
                mesh.SetVertex(pokeinfo.new_vid, v);

                mesh.CheckValidity();
            }

            //TestUtil.WriteTestOutputMesh(mesh, "poke_test_result.obj");
        }
Exemplo n.º 3
0
        public DMesh3 remesh_region(int iterations, DMesh3 mesh, double min, double max, double angle)
        {
            int[] tris = GetTrisOnPositiveSide(mesh, new Frame3f(Vector3F.Zero, Vector3F.AxisY));

            RegionRemesher r = new RegionRemesher(mesh, tris);

            r.Region.SubMesh.CheckValidity(true);

            r.Precompute();
            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = true;
            r.MinEdgeLength   = min;
            r.MaxEdgeLength   = max;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 1.0f;

            for (int k = 0; k < iterations; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }


            r.BackPropropagate();

            for (int k = 0; k < iterations; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            r.BackPropropagate();

            return(mesh);
        }
Exemplo n.º 4
0
        public static void split_tests(bool bTestBoundary, int N = 100)
        {
            System.Console.WriteLine("DMesh3:split_tests() starting");

            DMesh3 mesh = TestUtil.MakeCappedCylinder(bTestBoundary);

            mesh.CheckValidity();

            Random r = new Random(31377);

            for (int k = 0; k < N; ++k)
            {
                int eid = r.Next() % mesh.EdgeCount;
                if (!mesh.IsEdge(eid))
                {
                    continue;
                }

                DMesh3.EdgeSplitInfo splitInfo;
                MeshResult           result = mesh.SplitEdge(eid, out splitInfo);
                Debug.Assert(result == MeshResult.Ok);
                mesh.CheckValidity();
            }

            System.Console.WriteLine("splits ok");
        }
Exemplo n.º 5
0
        public static DMesh3 make_good_cylinder(float fResScale = 1.0f)
        {
            DMesh3 mesh = TestUtil.MakeCappedCylinder(false);

            MeshUtil.ScaleMesh(mesh, Frame3f.Identity, new Vector3f(1, 2, 1));
            mesh.CheckValidity();

            Remesher r = new Remesher(mesh);

            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = true;
            r.MinEdgeLength   = 0.1f * fResScale;
            r.MaxEdgeLength   = 0.2f * fResScale;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 0.1f;

            r.EnableFlips   = r.EnableSmoothing = false;
            r.MinEdgeLength = 0.05f * fResScale;
            for (int k = 0; k < 10; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            r.MinEdgeLength = 0.1f * fResScale;
            r.MaxEdgeLength = 0.2f * fResScale;
            r.EnableFlips   = r.EnableCollapses = r.EnableSmoothing = true;

            for (int k = 0; k < 10; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            return(mesh);
        }
Exemplo n.º 6
0
        public static void collapse_tests(bool bTestBoundary, int N = 100)
        {
            bool write_debug_meshes = false;

            DMesh3 mesh = TestUtil.MakeCappedCylinder(bTestBoundary);

            mesh.CheckValidity();

            System.Console.WriteLine(string.Format("DMesh3:collapse_tests() starting - test bdry {2}, verts {0} tris {1}",
                                                   mesh.VertexCount, mesh.TriangleCount, bTestBoundary));

            if (write_debug_meshes)
            {
                TestUtil.WriteDebugMesh(mesh, string.Format("before_collapse_{0}.obj", ((bTestBoundary)?"boundary":"noboundary")));
            }


            Random r = new Random(31377);

            for (int k = 0; k < N; ++k)
            {
                int eid = r.Next() % mesh.EdgeCount;
                if (!mesh.IsEdge(eid))
                {
                    continue;
                }
                //bool bBoundary = mesh.IsBoundaryEdge(eid);
                //if (bTestBoundary && bBoundary == false)
                //	 continue;
                Index2i ev = mesh.GetEdgeV(eid);

                DMesh3.EdgeCollapseInfo collapseInfo;
                MeshResult result = mesh.CollapseEdge(ev[0], ev[1], out collapseInfo);
                Debug.Assert(
                    result != MeshResult.Failed_NotAnEdge &&
                    result != MeshResult.Failed_FoundDuplicateTriangle);

                mesh.CheckValidity();
            }

            System.Console.WriteLine(string.Format("random collapses ok - verts {0} tris {1}",
                                                   mesh.VertexCount, mesh.TriangleCount));


            collapse_to_convergence(mesh);

            System.Console.WriteLine(string.Format("all possible collapses ok - verts {0} tris {1}",
                                                   mesh.VertexCount, mesh.TriangleCount));

            if (write_debug_meshes)
            {
                TestUtil.WriteDebugMesh(mesh, string.Format("after_collapse_{0}.obj", ((bTestBoundary)?"boundary":"noboundary")));
            }
        }
Exemplo n.º 7
0
        public static void test_basic_closed_remesh()
        {
            DMesh3 mesh = TestUtil.MakeCappedCylinder(false);

            MeshUtil.ScaleMesh(mesh, Frame3f.Identity, new Vector3f(1, 2, 1));
            //DMesh3 mesh = TestUtil.MakeOpenCylinder(false);
            mesh.CheckValidity();

            if (WriteDebugMeshes)
            {
                TestUtil.WriteDebugMesh(mesh, "basic_closed_remesh_before.obj");
            }

            Remesher r = new Remesher(mesh);

            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = true;
            r.MinEdgeLength   = 0.1f;
            r.MaxEdgeLength   = 0.2f;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 0.1f;

            r.EnableFlips   = r.EnableSmoothing = false;
            r.MinEdgeLength = 0.05f;
            for (int k = 0; k < 10; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            r.MinEdgeLength = 0.1f;
            r.MaxEdgeLength = 0.2f;
            r.EnableFlips   = r.EnableCollapses = r.EnableSmoothing = true;

            for (int k = 0; k < 10; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            r.EnableSplits = r.EnableCollapses = false;

            for (int k = 0; k < 10; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            if (WriteDebugMeshes)
            {
                TestUtil.WriteDebugMesh(mesh, "basic_closed_remesh_after.obj");
            }
        }
Exemplo n.º 8
0
        // closed mesh should collapse to a tetrahedron
        public static void collapse_test_closed_mesh()
        {
            DMesh3 mesh = TestUtil.MakeCappedCylinder(false);

            mesh.CheckValidity();
            collapse_to_convergence(mesh);
            mesh.CheckValidity();
            Util.gDevAssert(mesh.TriangleCount == 4);
            Util.gDevAssert(mesh.VertexCount == 4);
            foreach (int eid in mesh.EdgeIndices())
            {
                Util.gDevAssert(mesh.IsBoundaryEdge(eid) == false);
            }
        }
Exemplo n.º 9
0
        public static void hard_test()
        {
            //DMesh3 mesh = TestUtil.LoadTestInputMesh("three_edge_crack.obj");
            DMesh3 mesh = TestUtil.LoadTestMesh("c:\\scratch\\VTX_Scan_removeocc.obj");

            //MeshEditor editor = new MeshEditor(mesh);
            //editor.DisconnectAllBowties(100);

            mesh.CheckValidity(true, FailMode.DebugAssert);
            MergeCoincidentEdges merge = new MergeCoincidentEdges(mesh);

            merge.Apply();
            mesh.CheckValidity(true, FailMode.DebugAssert);
            TestUtil.WriteTestOutputMesh(mesh, "vtx_scan_merged.obj");
        }
Exemplo n.º 10
0
        public static void test_remesh_region()
        {
            int    Slices = 16;
            DMesh3 mesh   = TestUtil.MakeCappedCylinder(false, Slices);

            MeshUtil.ScaleMesh(mesh, Frame3f.Identity, new Vector3f(1, 2, 1));
            mesh.CheckValidity();

            int[] tris = TestUtil.GetTrisOnPositiveSide(mesh, new Frame3f(Vector3f.Zero, Vector3f.AxisY));

            RegionRemesher r = new RegionRemesher(mesh, tris);

            r.Region.SubMesh.CheckValidity(true);

            TestUtil.WriteTestOutputMesh(r.Region.SubMesh, "remesh_region_submesh.obj");

            r.Precompute();
            double fResScale = 0.5f;

            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = true;
            r.MinEdgeLength   = 0.1f * fResScale;
            r.MaxEdgeLength   = 0.2f * fResScale;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 1.0f;

            for (int k = 0; k < 5; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            TestUtil.WriteTestOutputMesh(r.Region.SubMesh, "remesh_region_submesh_refined.obj");

            r.BackPropropagate();

            TestUtil.WriteTestOutputMesh(mesh, "remesh_region_submesh_merged_1.obj");


            for (int k = 0; k < 5; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            r.BackPropropagate();

            TestUtil.WriteTestOutputMesh(mesh, "remesh_region_submesh_merged_2.obj");
        }
Exemplo n.º 11
0
        public static void basic_tests()
        {
            DMesh3 mesh = TestUtil.LoadTestInputMesh("three_edge_crack.obj");
            MergeCoincidentEdges merge = new MergeCoincidentEdges(mesh);

            merge.Apply();
            Util.gDevAssert(mesh.BoundaryEdgeIndices().Count() == 0);
            mesh.CheckValidity(true, FailMode.DebugAssert);
            TestUtil.WriteTestOutputMesh(mesh, "three_edge_crack_merged.obj");

            DMesh3 mesh2 = TestUtil.LoadTestInputMesh("crack_loop.obj");
            MergeCoincidentEdges merge2 = new MergeCoincidentEdges(mesh2);

            merge2.Apply();
            Util.gDevAssert(mesh2.BoundaryEdgeIndices().Count() == 0);
            mesh2.CheckValidity(true, FailMode.DebugAssert);
            TestUtil.WriteTestOutputMesh(mesh2, "crack_loop_merged.obj");

            DMesh3 mesh3 = TestUtil.LoadTestInputMesh("cracks_many.obj");
            MergeCoincidentEdges merge3 = new MergeCoincidentEdges(mesh3);

            merge3.Apply();
            Util.gDevAssert(mesh3.BoundaryEdgeIndices().Count() == 0);
            mesh3.CheckValidity(true, FailMode.DebugAssert);
            TestUtil.WriteTestOutputMesh(mesh3, "cracks_many_merged.obj");

            DMesh3 mesh4 = TestUtil.LoadTestInputMesh("cracks_duplicate_edge.obj");
            MergeCoincidentEdges merge4 = new MergeCoincidentEdges(mesh4);

            merge4.Apply();
            Util.gDevAssert(mesh4.BoundaryEdgeIndices().Count() == 0);
            mesh4.CheckValidity(true, FailMode.DebugAssert);
            TestUtil.WriteTestOutputMesh(mesh4, "cracks_duplicate_edge_merged.obj");
        }
Exemplo n.º 12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Message = modes.ToString() + " : " + steps.ToString() + " Steps";

            Grid3f_goo goo = null;
            double     val = 0;
            double     exp = 0;

            DA.GetData(0, ref goo);
            DA.GetData(1, ref val);
            DA.GetData(2, ref exp);

            var iso = goo.Value;

            g3.MarchingCubes c = new g3.MarchingCubes();
            c.Implicit      = iso;
            c.Bounds        = iso.Bounds();
            c.RootMode      = modes;
            c.RootModeSteps = steps;
            c.CubeSize      = iso.CellSize;
            c.Bounds.Expand(3 * c.CubeSize);
            c.IsoValue = val;
            c.Generate();


            DMesh3 outputMesh = c.Mesh;
            bool   isValid    = outputMesh.CheckValidity();

            if (!isValid)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh seems to be corrupted. Please check...");
            }

            DA.SetData(0, outputMesh);
        }
Exemplo n.º 13
0
        // open cylinder (ie a tube) should collapse down to having two boundary loops with 3 verts/edges each
        public static void collapse_test_convergence_opencyl()
        {
            DMesh3 mesh = TestUtil.MakeOpenCylinder(false);

            mesh.CheckValidity();

            collapse_to_convergence(mesh);
            int bdry_v = 0, bdry_t = 0, bdry_e = 0;

            foreach (int eid in mesh.EdgeIndices())
            {
                if (mesh.IsBoundaryEdge(eid))
                {
                    bdry_e++;
                }
            }
            Util.gDevAssert(bdry_e == 6);
            foreach (int tid in mesh.TriangleIndices())
            {
                if (mesh.tri_is_boundary(tid))
                {
                    bdry_t++;
                }
            }
            Util.gDevAssert(bdry_t == 6);
            foreach (int vid in mesh.VertexIndices())
            {
                if (mesh.IsBoundaryVertex(vid))
                {
                    bdry_v++;
                }
            }
            Util.gDevAssert(bdry_v == 6);
        }
Exemplo n.º 14
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            double     w        = 1;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref w);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value, true);

            LaplacianMeshDeformer deformer = new LaplacianMeshDeformer(dMsh_copy);

            foreach (int vid in dMsh_copy.VertexIndices())
            {
                if (deformer.IsConstrained(vid) == false)
                {
                    deformer.SetConstraint(vid, dMsh_copy.GetVertex(vid), w);
                }
            }

            bool success = deformer.SolveAndUpdateMesh();
            bool isValid = dMsh_copy.CheckValidity();

            if (!success)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Laplacian deform seems to have failed. Please check...");
            }

            if (!isValid)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh seems to have been corrupted during smoothing. Please check...");
            }

            DA.SetData(0, dMsh_copy);
        }
Exemplo n.º 15
0
        public static DMesh3 Reduce(this DMesh3 mesh, float percent, bool project = true)
        {
            if (!mesh.CheckValidity(eFailMode: FailMode.ReturnOnly))
            {
                return(mesh);
            }
            var r = new Reducer(mesh);

            if (project)
            {
                var tree = mesh.AABBTree();
                r.SetProjectionTarget(new MeshProjectionTarget(tree.Mesh, tree));

                // http://www.gradientspace.com/tutorials/2017/8/30/mesh-simplification
                // r.ProjectionMode = Reducer.TargetProjectionMode.Inline;
            }

            var target = mesh.VertexCount * percent / 100.0f;

            r.ReduceToVertexCount((int)target);
            var newMesh = r.Mesh.Compact();
            var g       = newMesh.ToIGeometry();

            Debug.Assert(g.AreAllIndicesValid());
            //Debug.Assert(g.AreAllVerticesUsed());
            return(newMesh);
        }
Exemplo n.º 16
0
        public static void test_basic_closed_reduce()
        {
            //DMesh3 mesh = TestUtil.MakeCappedCylinder(false);
            //DMesh3 mesh = TestUtil.LoadTestInputMesh("sphere_bowtie_groups.obj");
            DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj");

            //MeshUtil.ScaleMesh(mesh, Frame3f.Identity, new Vector3f(1,2,1));
            //DMesh3 mesh = TestUtil.MakeOpenCylinder(false);
            mesh.CheckValidity();

            if (WriteDebugMeshes)
            {
                TestUtil.WriteTestOutputMesh(mesh, "basic_closed_reduce_before.obj");
            }

            Reducer r = new Reducer(mesh);

            DMeshAABBTree3 tree = new DMeshAABBTree3(new DMesh3(mesh));

            tree.Build();
            //r.SetProjectionTarget(new MeshProjectionTarget() { Mesh = tree.Mesh, Spatial = tree });

            r.ReduceToTriangleCount(3000);
            //r.ReduceToEdgeLength(2.0);

            double mine, maxe, avge;

            MeshQueries.EdgeLengthStats(mesh, out mine, out maxe, out avge);
            System.Console.WriteLine("Edge length stats: {0} {1} {2}", mine, maxe, avge);

            if (WriteDebugMeshes)
            {
                TestUtil.WriteTestOutputMesh(mesh, "basic_closed_reduce_after.obj");
            }
        }
Exemplo n.º 17
0
        public static void set_triangle_tests()
        {
            DMesh3 mesh = TestUtil.LoadTestInputMesh("plane_250v.obj");

            mesh.CheckValidity();

            // ok todo
        }
Exemplo n.º 18
0
        public DMesh3 remesh_constraints_fixedverts(int iterations, DMesh3 mesh, double min, double max, double angle)
        {
            AxisAlignedBox3d bounds = mesh.CachedBounds;

            // construct mesh projection target
            DMesh3 meshCopy = new DMesh3(mesh);

            meshCopy.CheckValidity();
            DMeshAABBTree3 tree = new DMeshAABBTree3(meshCopy);

            tree.Build();
            MeshProjectionTarget target = new MeshProjectionTarget()
            {
                Mesh = meshCopy, Spatial = tree
            };

            // construct constraint set
            MeshConstraints cons = new MeshConstraints();

            //EdgeRefineFlags useFlags = EdgeRefineFlags.NoFlip | EdgeRefineFlags.NoCollapse;
            EdgeRefineFlags useFlags = EdgeRefineFlags.NoFlip;

            foreach (int eid in mesh.EdgeIndices())
            {
                double fAngle = MeshUtil.OpeningAngleD(mesh, eid);
                if (fAngle > angle)
                {
                    cons.SetOrUpdateEdgeConstraint(eid, new EdgeConstraint(useFlags));
                    Index2i ev      = mesh.GetEdgeV(eid);
                    int     nSetID0 = (mesh.GetVertex(ev[0]).y > bounds.Center.y) ? 1 : 2;
                    int     nSetID1 = (mesh.GetVertex(ev[1]).y > bounds.Center.y) ? 1 : 2;
                    cons.SetOrUpdateVertexConstraint(ev[0], new VertexConstraint(true, nSetID0));
                    cons.SetOrUpdateVertexConstraint(ev[1], new VertexConstraint(true, nSetID1));
                }
            }

            Remesher r = new Remesher(mesh);

            r.Precompute();
            r.SetExternalConstraints(cons);
            r.SetProjectionTarget(target);
            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = true;
            r.MinEdgeLength   = min;
            r.MaxEdgeLength   = max;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 1;


            for (int k = 0; k < iterations; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }


            return(mesh);
        }
Exemplo n.º 19
0
        public static DMesh3 MakeTrivialRect()
        {
            DMesh3 rectMesh           = new DMesh3();
            TrivialRectGenerator rgen = new TrivialRectGenerator();

            rgen.Generate();
            rgen.MakeMesh(rectMesh);
            rectMesh.CheckValidity();
            return(rectMesh);
        }
Exemplo n.º 20
0
        DMesh3 BuildPlanarMesh(bool bPreservePolygon)
        {
            DMesh3 planarMesh = new DMesh3();

            Vector2d center    = CurveUtils2.CentroidVtx(Loop.Vertices);
            int      center_id = planarMesh.AppendVertex(new Vector3d(center.x, center.y, 0));

            int prev_id  = -1;
            int first_id = -1;

            foreach (Vector2d v in Loop.Vertices)
            {
                int next_id = planarMesh.AppendVertex(new Vector3d(v.x, v.y, Thickness));
                if (prev_id > 0)
                {
                    planarMesh.AppendTriangle(center_id, prev_id, next_id);
                    prev_id = next_id;
                }
                else
                {
                    first_id = next_id;
                    prev_id  = next_id;
                }
            }
            planarMesh.AppendTriangle(center_id, prev_id, first_id);

            if (ReverseOrientation)
            {
                planarMesh.ReverseOrientation();
            }

            Debug.Assert(planarMesh.CheckValidity());


            double   edge_len = (TargetEdgeLength == 0) ? Loop.AverageEdgeLength : TargetEdgeLength;
            Remesher r        = new Remesher(planarMesh);

            r.SetTargetEdgeLength(edge_len);
            r.SmoothSpeedT = 1.0f;
            if (bPreservePolygon)
            {
                MeshConstraintUtil.FixAllBoundaryEdges(r);
            }
            else
            {
                MeshConstraintUtil.PreserveBoundaryLoops(r);
            }

            for (int k = 0; k < 20; ++k)
            {
                r.BasicRemeshPass();
            }

            return(planarMesh);
        }
Exemplo n.º 21
0
        public static void test_remove_change_apply()
        {
            DMesh3   testMesh = TestUtil.LoadTestInputMesh("bunny_solid.obj");
            DMesh3   copy     = new DMesh3(testMesh);
            Vector3d c        = testMesh.CachedBounds.Center;

            MeshFaceSelection selection = new MeshFaceSelection(testMesh);

            foreach (int tid in testMesh.TriangleIndices())
            {
                if (testMesh.GetTriCentroid(tid).x > c.x)
                {
                    selection.Select(tid);
                }
            }

            RemoveTrianglesMeshChange change = new RemoveTrianglesMeshChange();

            change.InitializeFromApply(testMesh, selection);

            testMesh.CheckValidity(true);
            change.Apply(copy);
            copy.CheckValidity(true);

            if (!copy.IsSameMesh(testMesh, true))
            {
                System.Console.WriteLine("FAILED copy.IsSameMesh() 1");
            }

            change.Revert(testMesh);
            testMesh.CheckValidity(false);
            change.Revert(copy);
            copy.CheckValidity(false);

            if (!copy.IsSameMesh(testMesh, true))
            {
                System.Console.WriteLine("FAILED copy.IsSameMesh() 1");
            }

            System.Console.WriteLine("test_remove_change_apply ok");
        }
Exemplo n.º 22
0
        public static void test_remove_change_construct()
        {
            DMesh3 testMesh = TestUtil.LoadTestInputMesh("bunny_open_base.obj");

            Random r = new Random(31337);
            //int N = 100;
            int N = 10;

            int[] indices = TestUtil.RandomIndices(N, r, testMesh.MaxVertexID);
            for (int ii = 0; ii < N; ++ii)
            {
                MeshFaceSelection selection = new MeshFaceSelection(testMesh);
                selection.SelectVertexOneRing(indices[ii]);
                selection.ExpandToOneRingNeighbours(8);

                RemoveTrianglesMeshChange change = new RemoveTrianglesMeshChange();
                change.InitializeFromExisting(testMesh, selection);

                DMesh3 removed = new DMesh3(testMesh);
                MeshEditor.RemoveTriangles(removed, selection);

                DMesh3 changeCopy = new DMesh3(testMesh);
                change.Apply(changeCopy);
                changeCopy.CheckValidity(true);

                if (!changeCopy.IsSameMesh(removed, true))
                {
                    System.Console.WriteLine("FAILED copy.IsSameMesh() 1");
                }

                change.Revert(changeCopy);
                changeCopy.CheckValidity(false);

                if (!changeCopy.IsSameMesh(testMesh, true))
                {
                    System.Console.WriteLine("FAILED copy.IsSameMesh() 1");
                }
            }

            System.Console.WriteLine("test_remove_change_construct ok");
        }
Exemplo n.º 23
0
        public static void test_add_change()
        {
            DMesh3 testMesh = TestUtil.LoadTestInputMesh("bunny_open_base.obj");
            DMesh3 copy     = new DMesh3(testMesh);

            MeshBoundaryLoops loops = new MeshBoundaryLoops(copy);

            foreach (var loop in loops)
            {
                SimpleHoleFiller filler = new SimpleHoleFiller(copy, loop);
                bool             ok     = filler.Fill();
                Util.gDevAssert(ok);

                AddTrianglesMeshChange change = new AddTrianglesMeshChange();
                change.InitializeFromExisting(copy,
                                              new List <int>()
                {
                    filler.NewVertex
                }, filler.NewTriangles);

                DMesh3 tmp = new DMesh3(copy);
                change.Revert(copy);
                copy.CheckValidity(true);

                if (!copy.IsSameMesh(testMesh, true))
                {
                    System.Console.WriteLine("FAILED copy.IsSameMesh() 1");
                }

                change.Apply(copy);
                copy.CheckValidity(true);
                if (!copy.IsSameMesh(tmp, true))
                {
                    System.Console.WriteLine("FAILED copy.IsSameMesh() 1");
                }
            }

            System.Console.WriteLine("test_add_change ok");
        }
Exemplo n.º 24
0
        // cyl with no shared verts should collapse down to two triangles
        public static void collapse_test_convergence_cyl_noshared()
        {
            DMesh3 mesh = TestUtil.MakeCappedCylinder(true);

            mesh.CheckValidity();
            collapse_to_convergence(mesh);
            Util.gDevAssert(mesh.TriangleCount == 3);
            Util.gDevAssert(mesh.VertexCount == 9);
            foreach (int tid in mesh.TriangleIndices())
            {
                Util.gDevAssert(mesh.tri_is_boundary(tid));
            }
        }
Exemplo n.º 25
0
        public static void basic_tests()
        {
            System.Console.WriteLine("DMesh3:basic_tests() starting");

            DMesh3 tmp = new DMesh3();
            CappedCylinderGenerator cylgen = new CappedCylinderGenerator();

            cylgen.Generate();
            cylgen.MakeMesh(tmp);
            tmp.CheckValidity();

            System.Console.WriteLine("cylinder ok");
        }
Exemplo n.º 26
0
        public DMesh3 remesh_basic_closed(int iterations, DMesh3 mesh, double min, double max, double angle)
        {
            Remesher r = new Remesher(mesh);

            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = true;
            r.MinEdgeLength   = min;
            r.MaxEdgeLength   = max;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 0.1f;

            r.EnableFlips   = r.EnableSmoothing = false;
            r.MinEdgeLength = min;
            for (int k = 0; k < iterations; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            r.MinEdgeLength = min;
            r.MaxEdgeLength = max;
            r.EnableFlips   = r.EnableCollapses = r.EnableSmoothing = true;

            for (int k = 0; k < iterations; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            r.EnableSplits = r.EnableCollapses = false;

            for (int k = 0; k < iterations; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            return(mesh);
        }
Exemplo n.º 27
0
        public static void test_compact_in_place()
        {
            DMesh3 testMesh = TestUtil.LoadTestInputMesh("bunny_solid.obj");

            testMesh.CheckValidity();
            int[] test_counts = new int[] { 16, 256, 1023, 1024, 1025, 2047, 2048, 2049, testMesh.TriangleCount - 1, testMesh.TriangleCount };
            foreach (int count in test_counts)
            {
                DMesh3  mesh = new DMesh3(testMesh);
                Reducer r    = new Reducer(mesh); r.ReduceToTriangleCount(count);
                mesh.CompactInPlace();
                mesh.CheckValidity(false, FailMode.DebugAssert);
                Util.gDevAssert(mesh.IsCompact);
            }
        }
Exemplo n.º 28
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            double     targetL  = 0;
            int        numI     = 0;
            bool       fixB     = false;
            bool       projBack = false;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref targetL);
            DA.GetData(2, ref numI);
            DA.GetData(3, ref fixB);
            DA.GetData(4, ref projBack);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            Remesher r = new Remesher(dMsh_copy);

            r.PreventNormalFlips = true;
            r.SetTargetEdgeLength(targetL);
            r.SmoothSpeedT = 0.5;

            if (fixB)
            {
                MeshConstraintUtil.FixAllBoundaryEdges(r);
            }

            if (projBack)
            {
                r.SetProjectionTarget(MeshProjectionTarget.Auto(dMsh_goo.Value));
            }

            for (int k = 0; k < numI; ++k)
            {
                r.BasicRemeshPass();
            }

            bool isValid = dMsh_copy.CheckValidity();

            if (!isValid)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh seems to have been corrupted during remeshing. Please check...");
            }

            DA.SetData(0, dMsh_copy);
        }
Exemplo n.º 29
0
        public DMesh3 remesh_smoothing(int iterations, DMesh3 mesh)
        {
            Remesher r = new Remesher(mesh);

            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = false;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 0.5f;
            r.SmoothType      = Remesher.SmoothTypes.MeanValue;

            for (int k = 0; k < iterations; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            return(mesh);
        }
Exemplo n.º 30
0
        public static void test_remesh_smoothing()
        {
            DMesh3 mesh = make_good_cylinder(1.0f);

            Remesher r = new Remesher(mesh);

            r.EnableFlips     = r.EnableSplits = r.EnableCollapses = false;
            r.EnableSmoothing = true;
            r.SmoothSpeedT    = 0.5f;
            r.SmoothType      = Remesher.SmoothTypes.MeanValue;

            for (int k = 0; k < 100; ++k)
            {
                r.BasicRemeshPass();
                mesh.CheckValidity();
            }

            if (WriteDebugMeshes)
            {
                TestUtil.WriteDebugMesh(mesh, "remesh_smoothing_test_after.obj");
            }
        }