Ejemplo n.º 1
0
        void SaveEdgeLayer(FileStream fs, EdgeLayer edgeLayer)
        {
            writer.Write("Edge Layer");

            writer.Write(edgeLayer.Count);

            foreach (EdgeTree tree in edgeLayer.EdgeTreeList)
            {
                List<Edge> list = new List<Edge>();
                //TravelEdge(tree.Root, list);

                list.Add(tree.Root);

                // 宽度搜索
                while (list.Count != 0)
                {
                    Edge edge = list[0];
                    list.RemoveAt(0);

                    SaveEdge(edge);

                    if (edge.LeftChild != null && edge.RightChild != null)
                    {
                        list.Add(edge.LeftChild);
                        list.Add(edge.RightChild);
                    }
                    else
                    {
                        writer.Write(-1);
                        writer.Write(-1);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        VertexLayer vertexLayer; /// 点层

        #endregion Fields

        #region Constructors

        public CloverController()
        {
            faceLayer = new FaceLayer(this);
            edgeLayer = new EdgeLayer(this);
            vertexLayer = new VertexLayer(this);

            //paper = new Paper("paper");
        }
Ejemplo n.º 3
0
        public int SaveFile(string filename, FaceLayer faceLayer, EdgeLayer edgeLayer, VertexLayer vertexLayer, ShadowSystem shadowSystem)
        {
            FileStream fs = new FileStream(filename, FileMode.Create);
            writer = new BinaryWriter(fs);

            // 魔数,用于表示这个文件是一个Clover文件
            writer.Write(201203100);

            ReAllocateVertexID(vertexLayer);

            SaveVertexLayer(fs, vertexLayer);

            SaveEdgeLayer(fs, edgeLayer);

            SaveFaceLayer(fs, faceLayer);

            SaveShadowSystem(fs, shadowSystem);

            fs.Close();

            return 0;
        }
Ejemplo n.º 4
0
        public void LoadFile(string filename)
        {
            fs = new FileStream(filename, FileMode.Open);

            reader = new BinaryReader(fs);

            int magicNumber = reader.ReadInt32();

            vertexIDDict = new Dictionary<int, Vertex>();
            edgeIDDict = new Dictionary<int, Edge>();
            faceIDDict = new Dictionary<int, Face>();

            vertexLayer = new VertexLayer();
            edgeLayer = new EdgeLayer();
            faceLayer = new FaceLayer();
            shadowSystem = new ShadowSystem();

            Clover();

            faceLayer.UpdateLeaves();

            fs.Close();
        }
Ejemplo n.º 5
0
        public void LoadFile(string filename)
        {
            fileLoader.LoadFromFile(filename);

            // 重置所有的数据结构
            faceLayer = fileLoader.FaceLayer;
            edgeLayer = fileLoader.EdgeLayer;
            vertexLayer = fileLoader.VertexLayer;
            shadowSystem = fileLoader.ShadowSystem;

            renderController.DeleteAll();
            //renderController.RedrawFoldLine();
            foreach (Face face in faceLayer.Leaves)
            {
                renderController.New(face);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据给定的长和宽初始化纸张
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void Initialize(float width, float height)
        {
            Vertex.Vertex_count = 0;
            Face.Face_count = 0;
            Edge.Edge_count = 0;

            faceLayer = new FaceLayer();
            edgeLayer = new EdgeLayer();
            vertexLayer = new VertexLayer();

            // Create 4 original vertices
            Vertex[] vertices = new Vertex[4];
            vertices[0] = new Vertex(-width / 2, height / 2, 0);
            vertices[1] = new Vertex(-width / 2, -height / 2, 0);
            vertices[2] = new Vertex(width / 2, -height / 2, 0);
            vertices[3] = new Vertex(width / 2, height / 2, 0);
            // 初始化纹理坐标
            vertices[0].u = 0; vertices[0].v = 0;
            vertices[1].u = 0; vertices[1].v = 1;
            vertices[2].u = 1; vertices[2].v = 1;
            vertices[3].u = 1; vertices[3].v = 0;

            // add to vertex layer
            foreach (Vertex v in vertices)
            {
                vertexLayer.InsertVertex(v);

                renderController.AddVisualInfoToVertex(v);
            }

            // create a face
            Face face = new Face(0);

            // creates 4 edges
            Edge[] edges = new Edge[4];

            // create one face and four edges
            for (int i = 0; i < 4; i++)
            {
                edges[i] = new Edge(vertices[i], vertices[i + 1 < 4 ? i + 1 : 0]);
                EdgeTree tree = new EdgeTree(edges[i]);
                edgeLayer.AddTree(tree);

                face.AddEdge(edges[i]);
                edges[i].Face1 = face;
            }

            // use root to initialize facecell tree and lookuptable
            faceLayer.Initliaze(face);

            face.UpdateVertices();
            faceLayer.UpdateLeaves();

            faceGroupLookupTable = new FaceGroupLookupTable(face);

            // 此处也应该拍一张快照
            SnapshotNode node = new SnapshotNode(faceLayer.Leaves);
            // 为了方便revert设计,详情联系 ET
            node.Type = SnapshotNodeKind.CutKind;
            node.OriginVertexListCount = vertexLayer.VertexCellTable.Count;
            node.OriginEdgeListCount = edgeLayer.Count;
            shadowSystem.Snapshot(node);

            // 调用渲染层,更新纸张
            CreatePaper(face);
        }