// The combine methods take a list of TTM files/surfaces and merge them all into a // single coherent surface // procedure Combine(const TTMSurfaces : TOwnedObjectList); overload; // procedure Combine(const TTMFiles : TStringList); overload; public static bool ReadHeaderFromFile(string FileName, out TTMHeader Header) { Header = TTMHeader.NewHeader(); bool result = false; try { using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(fs)) { Header.Read(reader); // Check signature string signature = ASCIIEncoding.ASCII.GetString(Header.FileSignature).Substring(0, Consts.TTMFileIdentifier.Length); if (Consts.TTMFileIdentifier.Equals(signature)) { // Check file version if (Header.FileMajorVersion == Consts.TTMMajorVersion && Header.FileMinorVersion == Consts.TTMMinorVersion) result = true; } } } } catch { result = false; } return result; }
// procedure RemoveDuplicateTriangles; public static bool IsTTMFile(string FileName, out string ErrorMsg) { ErrorMsg = "Error reading header"; try { TTMHeader Header = TTMHeader.NewHeader(); using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(fs)) { Header.Read(reader); // Check signature string signature = ASCIIEncoding.ASCII.GetString(Header.FileSignature).Substring(0, Consts.TTMFileIdentifier.Length); if (!Consts.TTMFileIdentifier.Equals(signature)) { ErrorMsg = "File is not a Trimble TIN Model."; return false; } // Check file version if (Header.FileMajorVersion != Consts.TTMMajorVersion || Header.FileMinorVersion != Consts.TTMMinorVersion) { ErrorMsg = $"TTM.IsTTMFile(): Unable to read this version {Header.FileMajorVersion}: {Header.FileMinorVersion} of Trimble TIN Model file. Expected version: { Consts.TTMMajorVersion}: {Consts.TTMMinorVersion}"; return false; } return true; } } } catch (Exception E) { ErrorMsg = ErrorMsg + "\n" + E.Message; return false; } }
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; } }