Ejemplo n.º 1
0
        public static PlacementTree GetPlacementTree(Mesh mesh)
        {
            if (!mesh.IsInitialized)
            {
                throw new ArgumentException($"Mesh not initialized in {nameof(GetPlacementTree)}");
            }
            if (mesh.Dimension != 2)
            {
                throw new ArgumentException($"Mesh not 2D in {nameof(GetPlacementTree)}");
            }

            if (mesh.Faces.Any(f => !f.IsSimple))
            {
                throw new ArgumentException($"Mesh contains non-simple polygons in {nameof(GetPlacementTree)}");
            }

            var placementTree = new PlacementTree();

            IEnumerable <HalfEdge> edges = _seed == -1 ? mesh.Edges() : GetShuffledEdges(mesh);

            // TODO: We need to pass Rayed Faces so that placement may be extended to them.
            foreach (var edge in edges)
            {
                placementTree.AddEdge(edge);
            }

            placementTree.Finish();
            return(placementTree);
        }
Ejemplo n.º 2
0
        public static void Serialize(PlacementTree tree, Func <Face, string> serializeFaceToString, TextWriter stm)
        {
            var serializer = new JsonSerializer
            {
                Context           = new StreamingContext(StreamingContextStates.Other, (serializeFaceToString, new Dictionary <Face, string>())),
                NullValueHandling = NullValueHandling.Ignore,
                TypeNameHandling  = TypeNameHandling.Objects
            };

            using (JsonWriter writer = new JsonTextWriter(stm))
            {
                serializer.Serialize(writer, tree.Root);
            }
        }
Ejemplo n.º 3
0
        public static PlacementTree Deserialize(Func <string, object> serializeStringToObject, TextReader stm)
        {
            var serializer = new JsonSerializer
            {
                Context           = new StreamingContext(StreamingContextStates.Other, (serializeStringToObject, new Dictionary <string, object>())),
                NullValueHandling = NullValueHandling.Ignore,
                TypeNameHandling  = TypeNameHandling.Objects
            };
            var ret = new PlacementTree();

            using (JsonReader reader = new JsonTextReader(stm))
            {
                ret.Root = serializer.Deserialize <PlacementNode>(reader);
            }

            ret.FromDeserialized = true;
            return(ret);
        }