/// <summary> /// Reads a TrimbleTINModel using the provided reader /// </summary> public void Read(BinaryReader reader, byte[] bytes) { var LoadErrMsg = ""; try { LoadErrMsg = "Error reading header"; Header.Read(reader); var identifier = System.Text.Encoding.ASCII.GetString(Header.FileSignature); if (identifier != Consts.TTM_FILE_IDENTIFIER) { throw new TTMFileReadException("File is not a Trimble TIN Model."); } // Check file version if (Header.FileMajorVersion != Consts.TTM_MAJOR_VERSION || Header.FileMinorVersion != Consts.TTM_MINOR_VERSION) { throw new TTMFileReadException($"TTM_Optimized.Read(): Unable to read this version {Header.FileMajorVersion}: {Header.FileMinorVersion} of Trimble TIN Model file. Expected version: { Consts.TTM_MAJOR_VERSION}: {Consts.TTM_MINOR_VERSION}"); } ModelName = ASCIIEncoding.ASCII.GetString(Header.DTMModelInternalName).TrimEnd(new[] { '\0' }); LoadErrMsg = "Error reading vertices"; reader.BaseStream.Position = Header.StartOffsetOfVertices; Vertices.Read(reader, Header); //Vertices.Read(bytes, Header.StartOffsetOfVertices, Header); LoadErrMsg = "Error reading triangles"; //reader.BaseStream.Position = Header.StartOffsetOfTriangles; //Triangles.Read(reader, Header); Triangles.Read(bytes, Header.StartOffsetOfTriangles, Header); LoadErrMsg = "Error reading edges"; reader.BaseStream.Position = Header.StartOffsetOfEdgeList; Edges.Read(reader, Header); LoadErrMsg = "Error reading start points"; reader.BaseStream.Position = Header.StartOffsetOfStartPoints; StartPoints.Read(reader, Header); } catch (TTMFileReadException) { throw; // pass it on } catch (Exception e) { throw new TTMFileReadException($"Exception at TTM loading phase {LoadErrMsg}", e); } }
public void Read(BinaryReader reader) { string LoadErrMsg = ""; Loading = true; try { try { LoadErrMsg = "Error reading header"; Header = TTMHeader.NewHeader(); Header.Read(reader); var identifier = Encoding.ASCII.GetString(Header.FileSignature); if (identifier != Consts.TTMFileIdentifier) { throw new TTMFileReadException("File is not a Trimble TIN Model."); } // Check file version if (Header.FileMajorVersion != Consts.TTMMajorVersion || Header.FileMinorVersion != Consts.TTMMinorVersion) { throw new TTMFileReadException($"TTM.Read(): Unable to read this version {Header.FileMajorVersion}: {Header.FileMinorVersion} of Trimble TIN Model file. Expected version: { Consts.TTMMajorVersion}: {Consts.TTMMinorVersion}"); } Clear(); ModelName = ASCIIEncoding.ASCII.GetString(Header.DTMModelInternalName).TrimEnd(new []{'\0'}); LoadErrMsg = "Error reading vertices"; reader.BaseStream.Position = Header.StartOffsetOfVertices; (Vertices as TTMVertices).Read(reader, Header); LoadErrMsg = "Error reading triangles"; reader.BaseStream.Position = Header.StartOffsetOfTriangles; (Triangles as TTMTriangles).Read(reader, Header, Vertices); LoadErrMsg = "Error reading edges"; reader.BaseStream.Position = Header.StartOffsetOfEdgeList; Edges.Read(reader, Header, Triangles as TTMTriangles); LoadErrMsg = "Error reading start points"; reader.BaseStream.Position = Header.StartOffsetOfStartPoints; StartPoints.Read(reader, Header, Triangles); } catch (TTMFileReadException) { Clear(); throw; // pass it on } catch (Exception E) { Clear(); throw new TTMFileReadException($"Exception at TTM loading phase {LoadErrMsg}", E); } } finally { Loading = false; } }