protected void ProcessPendingExtensionImplementation(ImplicitNaryDifference3d processedSide, List <BoundedImplicitFunction3d> pendingTools, AxisAlignedBox3d filterBox, Action <DMesh3> setProcessedMesh)
        {
            var bounds    = processedSide.Bounds();
            var indexList = new List <int>();

            for (int i = 0; i < pendingTools.Count; i++)
            {
                if (bounds.Intersects(pendingTools[i].Bounds()))
                {
                    indexList.Add(i);
                }
            }

            if (indexList.Count > 0)
            {
                foreach (var idx in indexList)
                {
                    processedSide.BSet.Add(pendingTools[idx]);
                }

                DMesh3 mesh = GenerateMeshBase(processedSide, filterBox);

                MeshPlaneCut cut = new MeshPlaneCut(mesh, Center.ToVector3d() + (Vector3d.AxisZ * SizeZ / 2.0), Vector3d.AxisZ);
                bool         bc  = cut.Cut();

                if (!mesh.IsCompact)
                {
                    mesh.CompactInPlace();
                }

                setProcessedMesh(mesh);
            }
        }
Пример #2
0
        private MeshGeometry3D ToMeshGeometry3D(DMesh3 src)
        {
            MeshGeometry3D dest = new MeshGeometry3D();

            if (!src.IsCompact)
            {
                src.CompactInPlace();
            }

            var vertices = src.VerticesBuffer;

            foreach (int vId in src.VerticesRefCounts)
            {
                int i = vId * 3;
                dest.Positions.Add(new Point3D(vertices[i], vertices[i + 1], vertices[i + 2]));
            }

            var triangles = src.TrianglesBuffer;

            foreach (int tId in src.TrianglesRefCounts)
            {
                int i = tId * 3;
                dest.TriangleIndices.Add(triangles[i]);
                dest.TriangleIndices.Add(triangles[i + 1]);
                dest.TriangleIndices.Add(triangles[i + 2]);
            }

            return(dest);
        }
Пример #3
0
        public static IGeometry ToIGeometry(this DMesh3 self)
        {
            self.CompactInPlace();
            var verts   = self.Vertices().Select(ToNumerics).ToIArray();
            var indices = self.TrianglesBuffer.ToIArray();

            return(verts.TriMesh(indices));
        }
Пример #4
0
        protected void ProcessPendingRoutImplementation(ImplicitNaryDifference3d processedSide, AxisAlignedBox3d filterBox, Action <DMesh3> setProcessedMesh)
        {
            DMesh3 mesh = GenerateMeshBase(processedSide, filterBox);

            MeshPlaneCut cut = new MeshPlaneCut(mesh, Center.ToVector3d() + (Vector3d.AxisZ * SizeZ / 2.0), Vector3d.AxisZ);
            bool         bc  = cut.Cut();

            if (!mesh.IsCompact)
            {
                mesh.CompactInPlace();
            }

            setProcessedMesh(mesh);
        }
Пример #5
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);
            }
        }
Пример #6
0
        List <Polygon2d> decompose_cluster_up(DMesh3 mesh)
        {
            optimize_mesh(mesh);
            mesh.CompactInPlace();
            mesh.DiscardTriangleGroups(); mesh.EnableTriangleGroups(0);

            double minLength = Settings.MaxBridgeWidthMM * 0.75;
            double minArea   = minLength * minLength;

            Dictionary <int, double>         areas   = new Dictionary <int, double>();
            Dictionary <int, HashSet <int> > trisets = new Dictionary <int, HashSet <int> >();
            HashSet <int> active_groups = new HashSet <int>();

            Action <int, int> add_tri_to_group = (tid, gid) => {
                mesh.SetTriangleGroup(tid, gid);
                areas[gid] = areas[gid] + mesh.GetTriArea(tid);
                trisets[gid].Add(tid);
            };
            Action <int, int> add_group_to_group = (gid, togid) => {
                var set = trisets[togid];
                foreach (int tid in trisets[gid])
                {
                    mesh.SetTriangleGroup(tid, togid);
                    set.Add(tid);
                }
                areas[togid] += areas[gid];
                active_groups.Remove(gid);
            };
            Func <IEnumerable <int>, int> find_min_area_group = (tri_itr) => {
                int min_gid = -1; double min_area = double.MaxValue;
                foreach (int tid in tri_itr)
                {
                    int    gid = mesh.GetTriangleGroup(tid);
                    double a   = areas[gid];
                    if (a < min_area)
                    {
                        min_area = a;
                        min_gid  = gid;
                    }
                }
                return(min_gid);
            };


            foreach (int eid in MeshIterators.InteriorEdges(mesh))
            {
                Index2i et = mesh.GetEdgeT(eid);
                if (mesh.GetTriangleGroup(et.a) != 0 || mesh.GetTriangleGroup(et.b) != 0)
                {
                    continue;
                }
                int gid = mesh.AllocateTriangleGroup();
                areas[gid]   = 0;
                trisets[gid] = new HashSet <int>();
                active_groups.Add(gid);
                add_tri_to_group(et.a, gid);
                add_tri_to_group(et.b, gid);
            }
            foreach (int tid in mesh.TriangleIndices())
            {
                if (mesh.GetTriangleGroup(tid) != 0)
                {
                    continue;
                }
                int gid = find_min_area_group(mesh.TriTrianglesItr(tid));
                add_tri_to_group(tid, gid);
            }


            IndexPriorityQueue pq = new IndexPriorityQueue(mesh.MaxGroupID);

            foreach (var pair in areas)
            {
                pq.Insert(pair.Key, (float)pair.Value);
            }
            while (pq.Count > 0)
            {
                int gid = pq.First;
                pq.Remove(gid);
                if (areas[gid] > minArea)                    // ??
                {
                    break;
                }

                List <int> nbr_groups = find_neighbour_groups(mesh, gid, trisets[gid]);
                int        min_gid = -1; double min_area = double.MaxValue;
                foreach (int ngid in nbr_groups)
                {
                    double a = areas[ngid];
                    if (a < min_area)
                    {
                        min_area = a;
                        min_gid  = ngid;
                    }
                }
                if (min_gid != -1)
                {
                    add_group_to_group(gid, min_gid);
                    pq.Remove(min_gid);
                    pq.Insert(min_gid, (float)areas[min_gid]);
                }
            }



            List <Polygon2d> result = new List <Polygon2d>();

            int[][] sets = FaceGroupUtil.FindTriangleSetsByGroup(mesh);
            foreach (var set in sets)
            {
                result.Add(make_poly(mesh, set));
            }
            return(result);
        }
Пример #7
0
        private Triangulation SaveTriangulation(DMesh3 mesh)
        {
            mesh.CompactInPlace();

            return(new Triangulation(GetMeshPositions(mesh), GetMeshIndices(mesh)));
        }