Exemplo n.º 1
0
        public static EdgeSpan find_edge_path(DMesh3 mesh, int v0, int v1)
        {
            if (v0 == v1)
            {
                throw new Exception("same vertices!");
            }

            int eid = mesh.FindEdge(v0, v1);

            if (eid >= 0)
            {
                return(EdgeSpan.FromEdges(mesh, new List <int>()
                {
                    eid
                }));
            }

            DijkstraGraphDistance dist = DijkstraGraphDistance.MeshVertices(mesh);

            //DijkstraGraphDistance dist = DijkstraGraphDistance.MeshVerticesSparse(mesh);
            dist.AddSeed(v0, 0);
            dist.ComputeToNode(v1);
            List <int> vpath = new List <int>();
            bool       bOK   = dist.GetPathToSeed(v1, vpath);

            Util.gDevAssert(bOK);
            vpath.Reverse();
            return(EdgeSpan.FromVertices(mesh, vpath));
        }
Exemplo n.º 2
0
        // NO DOES NOT WORK. DOES NOT FIND EDGE SPANS THAT ARE IN PLANE BUT HAVE DIFFERENT NORMAL!
        // NEED TO COLLECT UP SPANS USING NORMAL HISTOGRAM NORMALS!
        // ALSO NEED TO ACTUALLY CHECK FOR COPLANARITY, NOT JUST SAME NORMAL!!

        Dictionary <Vector3d, List <EdgeSpan> > find_coplanar_span_sets(DMesh3 mesh, EdgeLoop loop)
        {
            double dot_thresh = 0.999;

            var span_sets = new Dictionary <Vector3d, List <EdgeSpan> >();

            int NV = loop.Vertices.Length;
            int NE = loop.Edges.Length;

            var edge_normals = new Vector3d[NE];

            for (int k = 0; k < NE; ++k)
            {
                edge_normals[k] = mesh.GetTriNormal(mesh.GetEdgeT(loop.Edges[k]).a);
            }

            // find coplanar verts
            // [RMS] this is wrong, if normals vary smoothly enough we will mark non-coplanar spans as coplanar
            bool[] vert_coplanar = new bool[NV];
            int    nc            = 0;

            for (int k = 0; k < NV; ++k)
            {
                int prev = (k == 0) ? NV - 1 : k - 1;
                if (edge_normals[k].Dot(ref edge_normals[prev]) > dot_thresh)
                {
                    vert_coplanar[k] = true;
                    nc++;
                }
            }
            if (nc < 2)
            {
                return(null);
            }

            int iStart = 0;

            while (vert_coplanar[iStart])
            {
                iStart++;
            }

            int iPrev = iStart;
            int iCur  = iStart + 1;

            while (iCur != iStart)
            {
                if (vert_coplanar[iCur] == false)
                {
                    iPrev = iCur;
                    iCur  = (iCur + 1) % NV;
                    continue;
                }

                var edges = new List <int>()
                {
                    loop.Edges[iPrev]
                };
                int span_start_idx = iCur;
                while (vert_coplanar[iCur])
                {
                    edges.Add(loop.Edges[iCur]);
                    iCur = (iCur + 1) % NV;
                }

                if (edges.Count > 1)
                {
                    Vector3d span_n = edge_normals[span_start_idx];
                    var      span   = EdgeSpan.FromEdges(mesh, edges);
                    span.CheckValidity();
                    foreach (var pair in span_sets)
                    {
                        if (pair.Key.Dot(ref span_n) > dot_thresh)
                        {
                            span_n = pair.Key;
                            break;
                        }
                    }
                    List <EdgeSpan> found;
                    if (span_sets.TryGetValue(span_n, out found) == false)
                    {
                        span_sets[span_n] = new List <EdgeSpan>()
                        {
                            span
                        };
                    }
                    else
                    {
                        found.Add(span);
                    }
                }
            }



            return(span_sets);
        }
Exemplo n.º 3
0
        void extract_topology()
        {
            var graph = new DGraph3();

            // add vertices to graph, and store mappings
            int[] mapV     = new int[Mesh.MaxVertexID];
            int[] mapVFrom = new int[AllVertices.Count];
            foreach (int vid in AllVertices)
            {
                int new_vid = graph.AppendVertex(Mesh.GetVertex(vid));
                mapV[vid]         = new_vid;
                mapVFrom[new_vid] = vid;
            }

            // add edges to graph. graph-to-mesh eid mapping is stored via graph edge-group-id
            int[] mapE = new int[Mesh.MaxEdgeID];
            foreach (int eid in AllEdges)
            {
                Index2i ev      = Mesh.GetEdgeV(eid);
                int     new_a   = mapV[ev.a];
                int     new_b   = mapV[ev.b];
                int     new_eid = graph.AppendEdge(new_a, new_b, eid);
                mapE[eid] = new_eid;
            }

            // extract the graph topology
            DGraph3Util.Curves curves = DGraph3Util.ExtractCurves(graph, true);

            // reconstruct mesh spans / curves / junctions from graph topology

            int NP = curves.PathEdges.Count;

            Spans = new EdgeSpan[NP];
            for (int pi = 0; pi < NP; ++pi)
            {
                List <int> pathE = curves.PathEdges[pi];
                for (int k = 0; k < pathE.Count; ++k)
                {
                    pathE[k] = graph.GetEdgeGroup(pathE[k]);
                }
                Spans[pi] = EdgeSpan.FromEdges(Mesh, pathE);
            }

            int NL = curves.LoopEdges.Count;

            Loops = new EdgeLoop[NL];
            for (int li = 0; li < NL; ++li)
            {
                List <int> loopE = curves.LoopEdges[li];
                for (int k = 0; k < loopE.Count; ++k)
                {
                    loopE[k] = graph.GetEdgeGroup(loopE[k]);
                }
                Loops[li] = EdgeLoop.FromEdges(Mesh, loopE);
            }

            JunctionVertices = new HashSet <int>();
            foreach (int gvid in curves.JunctionV)
            {
                JunctionVertices.Add(mapVFrom[gvid]);
            }
        }