public bool AddElement(PLYElement elementItem) { bool result = false; try { elements.Add(elementItem); result = true; } catch (Exception ex) { } return(result); }
/// <summary> /// Reads the model in ASCII format from the specified stream. /// </summary> /// <param name="stream"> /// The stream. /// </param> /// <returns> /// True if the model was loaded successfully. /// </returns> private bool TryReadAscii(StreamReader reader) { bool result = false; bool endHeader = false; int elementIndex = 0; long elementCount = 0; this.vertex = new List <Point3D>(); PLYElement currentElement = null; while (!reader.EndOfStream) { var line = reader.ReadLine(); if (line != null) { line = line.Trim(); if (line.Length == 0 || line.StartsWith("\0") || line.StartsWith("#") || line.StartsWith("!") || line.StartsWith("$")) { continue; } string id, values; if (!endHeader) { SplitLine(line, out id, out values); string[] fields = null; if (values != null) { fields = values.SplitOnWhitespace(); } switch (id.ToLowerInvariant()) { case "ply": this.header.isValid = true; break; case "format": this.header.Format = fields[0]; break; case "element": if (currentElement != null) { this.header.AddElement(currentElement); currentElement = null; } currentElement = new PLYElement(); currentElement.Name = fields[0]; currentElement.Count = long.Parse(fields[1]); break; case "property": PLYProperty currentProperty = new PLYProperty(); currentProperty.Name = fields[fields.Length - 1]; currentProperty.DataType = fields[fields.Length - 2]; if (currentElement != null) { currentElement.AddProperty(currentProperty); } break; case "end_header": if (currentElement != null) { this.header.AddElement(currentElement); currentElement = null; } endHeader = true; break; } } else { if (header.Elements.Count > elementIndex) { if (header.Elements[elementIndex].Count > elementCount) { switch (header.Elements[elementIndex].Name.ToLower()) { case "vertex": this.AddVertex(line); break; case "face": if (faces == null) { faces = new List <int> [header.Elements[elementIndex].Count]; } this.AddFace(line, elementCount); break; } elementCount++; } else { elementIndex++; elementCount = 0; } } } } } return(result); }
/// <summary> /// Reads the model in ASCII format from the specified stream. /// </summary> /// <param name="stream"> /// The stream. /// </param> /// <returns> /// True if the model was loaded successfully. /// </returns> private bool TryReadAscii(StreamReader reader) { bool result = false; bool endHeader = false; int elementIndex = 0; long elementCount = 0; this.vertex = new List<Point3D>(); PLYElement currentElement = null; while (!reader.EndOfStream) { var line = reader.ReadLine(); if (line != null) { line = line.Trim(); if (line.Length == 0 || line.StartsWith("\0") || line.StartsWith("#") || line.StartsWith("!") || line.StartsWith("$")) { continue; } string id, values; if (!endHeader) { SplitLine(line, out id, out values); string[] fields=null; if (values != null) { fields = values.SplitOnWhitespace(); } switch (id.ToLowerInvariant()) { case "ply": this.header.isValid = true; break; case "format": this.header.Format = fields[0]; break; case "element": if (currentElement != null) { this.header.AddElement(currentElement); currentElement = null; } currentElement = new PLYElement(); currentElement.Name = fields[0]; currentElement.Count = long.Parse(fields[1]); break; case "property": PLYProperty currentProperty = new PLYProperty(); currentProperty.Name = fields[fields.Length - 1]; currentProperty.DataType = fields[fields.Length - 2]; if (currentElement != null) { currentElement.AddProperty(currentProperty); } break; case "end_header": if (currentElement != null) { this.header.AddElement(currentElement); currentElement = null; } endHeader = true; break; } } else { if (header.Elements.Count > elementIndex) { if (header.Elements[elementIndex].Count > elementCount) { switch (header.Elements[elementIndex].Name.ToLower()) { case "vertex": this.AddVertex(line); break; case "face": if(faces==null) { faces = new List<int>[header.Elements[elementIndex].Count]; } this.AddFace(line, elementCount); break; } elementCount++; } else { elementIndex++; elementCount = 0; } } } } } return result; }
public bool AddElement(PLYElement elementItem) { bool result = false; try { elements.Add(elementItem); result = true; } catch(Exception ex) { } return result; }