private PlyElement ReadElement(PlyElementType elementType) { var propertyValues = new object[elementType.Properties.Count]; var tokens = new Queue <string>(CurrentLine.Split(' ')); foreach (var property in elementType.Properties.Values.OrderBy(p => p.Index)) { if (property.IsList) { var listElementCount = int.Parse(tokens.Dequeue()); var list = new object[listElementCount]; for (var i = 0; i < list.Length; i++) { list[i] = ParseValue(property.TypeName, tokens.Dequeue()); } propertyValues[property.Index] = list; } else { propertyValues[property.Index] = ParseValue(property.TypeName, tokens.Dequeue()); } } NextLine(); return(new PlyElement(elementType, propertyValues)); }
static void VerifySimplePropertiesExist(PlyElementType elementType, params string[] propertyNames) { foreach (var name in propertyNames) { if (!elementType.Properties.ContainsKey(name)) { throw new Exception( string.Format("The element type \"{0}\" does not contain a \"{1}\" property.", elementType.Name, name)); } if (elementType.Properties[name].IsList) { throw new Exception( string.Format("Property \"{1}\" of element type \"{0}\" was expected to be a simple property, not a list.", elementType.Name, name)); } } }
static void VerifyListPropertiesExist(PlyElementType elementType, params string[] propertyNames) { foreach (var name in propertyNames) { if (!elementType.Properties.ContainsKey(name)) { throw new Exception( string.Format("The element type \"{0}\" does not contain a \"{1}\" property.", elementType.Name, name)); } if (!elementType.Properties[name].IsList) { throw new Exception( string.Format("Property \"{1}\" of element type \"{0}\" was expected to be a list property.", elementType.Name, name)); } } }
private PlyElementType ReadElementType() { var tokens = CurrentLine.Split(' '); if (tokens.Length != 3) { throw new Exception( string.Format( "Incorrect number of tokens in element type line: \"{0}\". " + "Element types should be in the format: \"element <element_type> <element_count>\".", CurrentLine)); } if (tokens[0] != "element") { throw new Exception("Invalid element type line. Element types must start with the word \"element\"."); } int count; if (!int.TryParse(tokens[2], out count)) { throw new Exception( string.Format("Invalid element count: \"{0}\"", tokens[2])); } var elementType = new PlyElementType { Name = tokens[1], Count = count }; while (NextHeaderLine().StartsWith("property")) { elementType.AddProperty(ReadProperty()); } return(elementType); }
public void AddElementType(PlyElementType elementType) { ElementTypes.Add(elementType.Name, elementType); }
private PlyElement ReadElement(PlyElementType elementType) { var propertyValues = new object[elementType.Properties.Count]; var tokens = new Queue<string>(CurrentLine.Split(' ')); foreach(var property in elementType.Properties.Values.OrderBy(p => p.Index)) { if (property.IsList) { var listElementCount = int.Parse(tokens.Dequeue()); var list = new object[listElementCount]; for(var i = 0; i < list.Length; i++) { list[i] = ParseValue(property.TypeName, tokens.Dequeue()); } propertyValues[property.Index] = list; } else { propertyValues[property.Index] = ParseValue(property.TypeName, tokens.Dequeue()); } } NextLine(); return new PlyElement(elementType, propertyValues); }
private PlyElementType ReadElementType() { var tokens = CurrentLine.Split(' '); if (tokens.Length != 3) throw new Exception( string.Format( "Incorrect number of tokens in element type line: \"{0}\". " + "Element types should be in the format: \"element <element_type> <element_count>\".", CurrentLine)); if (tokens[0] != "element") throw new Exception("Invalid element type line. Element types must start with the word \"element\"."); int count; if (!int.TryParse(tokens[2], out count)) throw new Exception( string.Format("Invalid element count: \"{0}\"", tokens[2])); var elementType = new PlyElementType { Name = tokens[1], Count = count }; while(NextHeaderLine().StartsWith("property")) { elementType.AddProperty(ReadProperty()); } return elementType; }