Ejemplo n.º 1
0
        public void BuildFromGrid2(CartGridData pointStripList)
        {
            int minStripLen = GetMinStripLength(pointStripList);
            int id          = 0;
            var vertexGrid  = new PlyVertex[pointStripList.Count, minStripLen];

            for (int i = 0; i < pointStripList.Count; i++)
            {
                for (int j = 0; j < minStripLen; j++)
                {
                    vertexGrid[i, j] = new PlyVertex(pointStripList[i][j], id++);
                    _vertices.Add(vertexGrid[i, j]);
                }
            }
            for (int i = 0; i < pointStripList.Count - 1; i++)
            {
                for (int j = 0; j < minStripLen - 1; j++)
                {
                    var indices1 = new List <int>()
                    {
                        vertexGrid[i, j].ID, vertexGrid[i, j + 1].ID, vertexGrid[i + 1, j].ID
                    };
                    _faces.Add(new PlyFace(indices1));
                    var indices2 = new List <int>()
                    {
                        vertexGrid[i, j + 1].ID, vertexGrid[i + 1, j + 1].ID, vertexGrid[i + 1, j].ID
                    };
                    _faces.Add(new PlyFace(indices2));
                }
            }
        }
Ejemplo n.º 2
0
        public void BuildFromGrid(CartGridData pointStripList)
        {
            Debug.WriteLine("building ply file");

            //find minimum strip length


            int minStripLen = GetMinStripLength(pointStripList);
            //add triangles to list of faces

            var triList = new List <Triangle>();

            for (int i = 0; i < pointStripList.Count - 1; i++)
            {
                for (int j = 0; j < minStripLen - 1; j++)
                {
                    Triangle t1 = new Triangle(pointStripList[i][j], pointStripList[i][j + 1], pointStripList[i + 1][j]);
                    Triangle t2 = new Triangle(pointStripList[i][j + 1], pointStripList[i + 1][j + 1], pointStripList[i + 1][j]);

                    triList.Add(t1);
                    triList.Add(t2);
                }
            }
            int vertCount = 0;

            foreach (var tri in triList)
            {
                var indexList = new List <int>();
                foreach (var vt in tri.Vertices)
                {
                    var plyvert = new PlyVertex(vt, tri.Normal);
                    plyvert.ID = vertCount++;
                    indexList.Add(plyvert.ID);
                    _vertices.Add(plyvert);
                }
                var face = new PlyFace(indexList);
                _faces.Add(face);
            }


            Debug.WriteLine("triangles:{0} ", _faces.Count);
            Debug.WriteLine("Vertices:{0} ", _vertices.Count);
        }
Ejemplo n.º 3
0
        private void ReadBody(List <string> section, PlyElement element)
        {
            foreach (string line in section)
            {
                string[] tokens = line.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                if (element.Type == PlyElementType.vertex)
                {
                    float[]   floatTokens = new float[tokens.Length];
                    PlyVertex Vertex      = new PlyVertex();
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        string          typeName = element.Properties[i].TypeName;
                        string          name     = element.Properties[i].Name;
                        PlyPropertyType propType = element.Properties[i].Type;
                        byte            r        = 0;
                        byte            g        = 0;
                        byte            b        = 0;
                        if (propType == PlyPropertyType.x)
                        {
                            Vertex.X = float.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.y)
                        {
                            Vertex.Y = float.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.z)
                        {
                            Vertex.Z = float.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.nx)
                        {
                            Vertex.Normal.X = double.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.ny)
                        {
                            Vertex.Normal.Y = double.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.nz)
                        {
                            Vertex.Normal.Z = double.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.red)
                        {
                            r = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.green)
                        {
                            g = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.blue)
                        {
                            b = byte.Parse(tokens[i]);
                        }
                        Vertex.Col = System.Drawing.Color.FromArgb(r, g, b);
                    }

                    Vertices.Add(Vertex);
                }
                if (element.Type == PlyElementType.face)
                {
                    var indexList = new List <int>();
                    for (int i = 1; i < tokens.Length; i++)
                    {
                        int temp = int.Parse(tokens[i]);
                        indexList.Add(temp);
                    }
                    Faces.Add(new PlyFace(indexList));
                }
                if (element.Type == PlyElementType.edge)
                {
                    PlyEdge edge = new PlyEdge(element.containsColor);
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        string          typeName = element.Properties[i].TypeName;
                        string          name     = element.Properties[i].Name;
                        PlyPropertyType propType = element.Properties[i].Type;
                        byte            r        = 0;
                        byte            b        = 0;
                        byte            g        = 0;

                        if (propType == PlyPropertyType.red)
                        {
                            r = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.green)
                        {
                            g = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.blue)
                        {
                            b = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.vertex1)
                        {
                            edge.Vertex1 = int.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.vertex2)
                        {
                            edge.Vertex2 = int.Parse(tokens[i]);
                        }
                        edge.Color = System.Drawing.Color.FromArgb(r, g, b);
                    }
                    Edges.Add(edge);
                }
                if (element.Type == PlyElementType.material)
                {
                    for (int i = 0; i < tokens.Length; i++)
                    {
                    }
                }
                if (element.Type == PlyElementType.other)
                {
                    for (int i = 0; i < tokens.Length; i++)
                    {
                    }
                }
            }
        }