public PlyType(PlyPropertyType plyPropertyType, Type netType, int byteCount, Func <byte[], int, object> byteConverter) { PlyPropertyType = plyPropertyType; NetType = netType; ByteCount = byteCount; ByteConverter = byteConverter; }
public PlyProperty(string name, int index, PlyPropertyType type) { Name = name; Index = index; Type = TypeMapper.GetPlyType(type); IsList = false; }
private PlyProperty ReadProperty(string line) { string[] tokens = line.Split(splitter, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length != 3 && tokens.Length != 5) { throw new Exception(string.Format("Invalid number of tokens in property line: \"{0}\".", CurrentLine)); } if (tokens[0] != "property") { throw new Exception(string.Format("Invalid property line: \"{0}\".", CurrentLine)); } var property = new PlyProperty { Name = tokens.Last(), IsList = tokens[1] == "list", }; if (property.IsList) { property.ListCountTypeName = tokens[2]; property.TypeName = tokens[3]; property.Name = tokens[4]; if (tokens[4] == PlyPropertyType.vertex_indices.ToString()) { property.Name = PlyPropertyType.vertex_index.ToString(); } } else { property.TypeName = tokens[1]; property.Name = tokens[2]; } property.Type = PlyPropertyType.other; PlyPropertyType tempType = PlyPropertyType.other; if (Enum.TryParse <PlyPropertyType>(property.Name, out tempType)) { property.Type = tempType; } return(property); }
public static PlyType GetPlyType(PlyPropertyType propertyType) { switch (propertyType) { case PlyPropertyType.Char: return(new PlyType(propertyType, typeof(char), 2, (b, i) => BitConverter.ToChar(b, i))); case PlyPropertyType.Short: return(new PlyType(propertyType, typeof(short), 2, (b, i) => BitConverter.ToInt16(b, i))); case PlyPropertyType.Int: return(new PlyType(propertyType, typeof(int), 4, (b, i) => BitConverter.ToInt32(b, i))); case PlyPropertyType.UChar: return(new PlyType(propertyType, typeof(byte), 1, (b, i) => { return b[0]; })); case PlyPropertyType.UShort: return(new PlyType(propertyType, typeof(ushort), 2, (b, i) => BitConverter.ToUInt16(b, i))); case PlyPropertyType.UInt: return(new PlyType(propertyType, typeof(uint), 4, (b, i) => BitConverter.ToUInt32(b, i))); case PlyPropertyType.Float: return(new PlyType(propertyType, typeof(float), 4, (b, i) => BitConverter.ToSingle(b, i))); case PlyPropertyType.Double: return(new PlyType(propertyType, typeof(double), 8, (b, i) => BitConverter.ToDouble(b, i))); case PlyPropertyType.Invalid: return(null); default: break; } return(null); }
private static object GetAsciiItem(string word, PlyPropertyType type, out int intVal, out uint uintVal, out double doubleVal) { switch (type) { case PlyPropertyType.Char: case PlyPropertyType.UChar: case PlyPropertyType.Short: case PlyPropertyType.UShort: case PlyPropertyType.Int: intVal = Convert.ToInt32(word); uintVal = (uint)intVal; doubleVal = intVal; break; case PlyPropertyType.UInt: uintVal = Convert.ToUInt32(word); intVal = (int)uintVal; doubleVal = uintVal; break; case PlyPropertyType.Float: case PlyPropertyType.Double: doubleVal = Convert.ToDouble(word); intVal = (int)doubleVal; uintVal = (uint)doubleVal; break; default: throw new ArgumentException("Unknown type: " + type); } switch (type) { case PlyPropertyType.Char: return Convert.ToByte(word); case PlyPropertyType.Double: return Convert.ToDouble(word); case PlyPropertyType.Float: return Convert.ToSingle(word); case PlyPropertyType.Int: return Convert.ToInt32(word); case PlyPropertyType.Short: return Convert.ToInt16(word); case PlyPropertyType.UChar: return Convert.ToByte(word); case PlyPropertyType.UInt: return Convert.ToUInt32(word); case PlyPropertyType.UShort: return Convert.ToUInt16(word); default: throw new ArgumentException("Unknown type: " + type); } }
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++) { } } } }
private static object GetAsciiItem(string word, PlyPropertyType type, out int intVal, out uint uintVal, out double doubleVal) { switch (type) { case PlyPropertyType.Char: case PlyPropertyType.UChar: case PlyPropertyType.Short: case PlyPropertyType.UShort: case PlyPropertyType.Int: intVal = Convert.ToInt32(word); uintVal = (uint)intVal; doubleVal = intVal; break; case PlyPropertyType.UInt: uintVal = Convert.ToUInt32(word); intVal = (int)uintVal; doubleVal = uintVal; break; case PlyPropertyType.Float: case PlyPropertyType.Double: doubleVal = Convert.ToDouble(word); intVal = (int)doubleVal; uintVal = (uint)doubleVal; break; default: throw new ArgumentException("Unknown type: " + type); } switch (type) { case PlyPropertyType.Char: return(Convert.ToByte(word)); case PlyPropertyType.Double: return(Convert.ToDouble(word)); case PlyPropertyType.Float: return(Convert.ToSingle(word)); case PlyPropertyType.Int: return(Convert.ToInt32(word)); case PlyPropertyType.Short: return(Convert.ToInt16(word)); case PlyPropertyType.UChar: return(Convert.ToByte(word)); case PlyPropertyType.UInt: return(Convert.ToUInt32(word)); case PlyPropertyType.UShort: return(Convert.ToUInt16(word)); default: throw new ArgumentException("Unknown type: " + type); } }