Ejemplo n.º 1
0
        public static void AssertLabelsGoodStartingLocationAndOrientation <K, T>(List <PlanarUnfolder.UnfoldableFaceLabel
                                                                                       <K, T> > labels)
            where K : IUnfoldableEdge
            where T : IUnfoldablePlanarFace <K>
        {
            // get aligned geometry
            var alignedGeo = labels.Select(x => x.AlignedLabelGeometry).ToList();

            // assert that the bounding box of the label at least intersects the face it represents
            for (int i = 0; i < alignedGeo.Count; i++)
            {
                var curveList = alignedGeo[i];

                var curvePoints = curveList.Select(x => x.StartPoint);
                var labelPlane  = Plane.ByBestFitThroughPoints(curvePoints);
                var testsurf    = Surface.ByPatch(Rectangle.ByWidthLength(1, 1).
                                                  Transform(CoordinateSystem.ByPlane(labelPlane)) as Curve);

                //check that the aligned curves intersect the surface they are aligned to
                Assert.IsTrue(curveList.SelectMany(x => labels[i].UnfoldableFace.SurfaceEntities.Select(x.DoesIntersect)).Any());
                Console.WriteLine("This label was in the right spot at the start of the unfold");
                //also assert that the face normal is parallel with the normal of the boundingbox plane

                var face = labels[i].UnfoldableFace.SurfaceEntities;

                UnfoldTestUtils.AssertSurfacesAreCoplanar(testsurf, face.First());
                Console.WriteLine("This label was in the right orientation at the start of the unfold");

                testsurf.Dispose();
                labelPlane.Dispose();
            }
        }
Ejemplo n.º 2
0
        public static void AssertEachFacePairUnfoldsCorrectly(List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> > graph)
        {
            //perform BFS on the graph and get back the tree
            var    nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);
            object tree       = nodereturn;

            var casttree = tree as List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> >;
            //perform Tarjans algo and make sure that the tree is acylic before unfold
            var sccs = GraphUtilities.TarjansAlgo <EdgeLikeEntity, FaceLikeEntity> .CycleDetect(casttree, GraphUtilities.EdgeType.Tree);

            UnfoldTestUtils.IsAcylic <EdgeLikeEntity, FaceLikeEntity>(sccs, casttree);

            // iterate through each vertex in the tree
            // make sure that the parent/child is not null (depends which direction we're traversing)
            // if not null, grab the next node and the tree edge
            // pass these to check normal consistencey and align.
            // be careful about the order of passed faces

            foreach (var parent in casttree)
            {
                if (parent.GraphEdges.Count > 0)
                {
                    foreach (var edge in parent.GraphEdges)
                    {
                        var child = edge.Head;

                        double nc          = AlignPlanarFaces.CheckNormalConsistency(child.Face, parent.Face, edge.GeometryEdge);
                        var    rotatedFace = AlignPlanarFaces.MakeGeometryCoPlanarAroundEdge(nc, child.Face, parent.Face, edge.GeometryEdge);

                        UnfoldTestUtils.AssertSurfacesAreCoplanar(rotatedFace.First(), parent.Face.SurfaceEntities.First());

                        UnfoldTestUtils.AssertRotatedSurfacesDoNotShareSameCenter(rotatedFace.First(), parent.Face.SurfaceEntities.First());

                        foreach (IDisposable item in rotatedFace)
                        {
                            item.Dispose();
                        }
                    }
                }
            }
            foreach (IDisposable item in graph)
            {
                Console.WriteLine("disposing a graphnode");
                item.Dispose();
            }

            foreach (IDisposable item in casttree)
            {
                Console.WriteLine("disposing a face");
                item.Dispose();
            }
        }