예제 #1
0
    // 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;
    }
예제 #2
0
 public void Write(BinaryWriter writer, TTMHeader header)
 {
     for (int i = 0; i < Count; i++)
     {
         this[i].Write(writer, header);
     }
 }
예제 #3
0
        public void Read(BinaryReader reader, TTMHeader header,
                         TriVertices vertices, TTMTriangles triangles, int TriNumber)
        {
            for (int i = 0; i < 3; i++)
            {
                int VertIndex = Utilities.ReadInteger(reader, header.VertexNumberSize);

                Vertices[i] = (VertIndex <1 || VertIndex> vertices.Count) ? null : vertices[VertIndex - 1];

                //{$ifdef LoadTTMIndices}
                //VertexIndices[i] := VertexIndex;
                //{$endif}
            }

            for (int i = 0; i < 3; i++)
            {
                int NeighbourIndex = Utilities.ReadInteger(reader, header.TriangleNumberSize);

                Neighbours[i] = (NeighbourIndex <1 || NeighbourIndex> triangles.Count) ? null : triangles[NeighbourIndex - 1];

                //{$ifdef LoadTTMIndices}
                //NeighbourIndices[i] := NeighbourIndex;
                //{$endif}
            }
        }
예제 #4
0
 public void Write(BinaryWriter writer, TTMHeader header)
 {
     foreach (TTMVertex vertex in this)
     {
         vertex.Write(writer, header);
     }
 }
예제 #5
0
        //    {$ifdef LoadTTMIndices}
        //    TriangleIndices: array of Integer;
        //    {$endif

        public void Write(BinaryWriter writer, TTMHeader header)
        {
            // Assume triangles have been numbered
            for (int i = 0; i < Count; i++)
            {
                Utilities.WriteInteger(writer, this[i].Tag, header.TriangleNumberSize);
            }
        }
예제 #6
0
        public void Write(BinaryWriter writer, TTMHeader header)
        {
            NumberTriangles();

            foreach (TTMTriangle triangle in this)
            {
                triangle.Write(writer, header);
            }
        }
예제 #7
0
        public void Read(BinaryReader reader, TTMHeader header, Triangles triangles)
        {
            Capacity = header.NumberOfStartPoints;

            for (int i = 0; i < header.NumberOfStartPoints; i++)
            {
                long          RecPos = reader.BaseStream.Position;
                TTMStartPoint Pt     = new TTMStartPoint(0, 0, null);
                Add(Pt);
                Pt.Read(reader, header, triangles);
                reader.BaseStream.Position = RecPos + header.StartPointRecordSize;
            }
        }
예제 #8
0
        public void Read(BinaryReader reader, TTMHeader header, Triangles triangles)
        {
            FY = Utilities.ReadFloat(reader, header.VertexCoordinateSize) + header.NorthingOffsetValue;
            FX = Utilities.ReadFloat(reader, header.VertexCoordinateSize) + header.EastingOffsetValue;

            int TriIndex = Utilities.ReadInteger(reader, header.TriangleNumberSize);

            FTriangle = (TriIndex > 0) && (TriIndex <= triangles.Count) ? triangles[TriIndex - 1] : null;

            //{$ifdef LoadTTMIndices}
            //TriangleIndex:= TriIndex;
            //{$endif}
        }
예제 #9
0
        //    {$ifdef LoadTTMIndices}
        //    VertexIndices,
        //      NeighbourIndices: array[TTriangleSide] of Integer;
        //    {$endif}

        public void Write(BinaryWriter writer, TTMHeader header)
        {
            for (int i = 0; i < 3; i++)
            {
                Utilities.WriteInteger(writer, Vertices[i].Tag, header.VertexNumberSize);
            }

            for (int i = 0; i < 3; i++)
            {
                int NeighbourIndex = Neighbours[i] == null ? Consts.NoNeighbour : Neighbours[i].Tag;

                Utilities.WriteInteger(writer, NeighbourIndex, header.TriangleNumberSize);
            }
        }
예제 #10
0
        public void Read(BinaryReader reader, TTMHeader header)
        {
            Capacity = header.NumberOfVertices;

            for (int i = 0; i < header.NumberOfVertices; i++)
            {
                long      RecPos = reader.BaseStream.Position;
                TTMVertex Vertex = new TTMVertex(0, 0, 0);
                Add(Vertex);
                Vertex.Read(reader, header);
                reader.BaseStream.Position = RecPos + header.VertexRecordSize;
            }

            NumberVertices();
        }
예제 #11
0
        public void Read(BinaryReader reader, TTMHeader header, TriVertices vertices)
        {
            Capacity = header.NumberOfTriangles;

            // Create objects first as we need neighbour triangles to exist
            for (int i = 0; i < header.NumberOfTriangles; i++)
            {
                Add(new TTMTriangle(null, null, null));
            }

            NumberTriangles();

            for (int i = 0; i < Count; i++)
            {
                long RecPos = reader.BaseStream.Position;
                (this[i] as TTMTriangle).Read(reader, header, vertices, this, i + 1);
                reader.BaseStream.Position = RecPos + header.TriangleRecordSize;
            }
        }
예제 #12
0
        public void Read(BinaryReader reader, TTMHeader header, Triangles triangles)
        {
            //{$ifdef LoadTTMIndices}
            //SetLength(TriangleIndices, Header.NumberOfEdgeRecords);
            //{$endif}

            Capacity = header.NumberOfEdgeRecords;

            for (int i = 0; i < header.NumberOfEdgeRecords; i++)
            {
                long RecPos        = reader.BaseStream.Position;
                int  TriangleIndex = Utilities.ReadInteger(reader, header.TriangleNumberSize);

                Add(TriangleIndex <1 || TriangleIndex> triangles.Count ? null : triangles[TriangleIndex - 1] as TTMTriangle);

                //{$ifdef LoadTTMIndices}
                //TriangleIndices[i] = TriangleIndex;
                //{$endif}
                reader.BaseStream.Position = RecPos + header.EdgeRecordSize;
            }
        }
예제 #13
0
    // 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;
      }
    }
예제 #14
0
 public void Read(BinaryReader reader, TTMHeader header)
 {
     Y = Utilities.ReadFloat(reader, header.VertexCoordinateSize) + header.NorthingOffsetValue;
     X = Utilities.ReadFloat(reader, header.VertexCoordinateSize) + header.EastingOffsetValue;
     Z = Utilities.ReadFloat(reader, header.VertexValueSize);
 }
예제 #15
0
 public void Write(BinaryWriter writer, TTMHeader header)
 {
     Utilities.WriteFloat(writer, Y - header.NorthingOffsetValue, header.VertexCoordinateSize);
     Utilities.WriteFloat(writer, X - header.EastingOffsetValue, header.VertexCoordinateSize);
     Utilities.WriteFloat(writer, Z, header.VertexValueSize);
 }
예제 #16
0
    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;
      }
    }
예제 #17
0
 public void Write(BinaryWriter writer, TTMHeader header)
 {
     Utilities.WriteFloat(writer, Y - header.NorthingOffsetValue, header.VertexCoordinateSize);
     Utilities.WriteFloat(writer, X - header.EastingOffsetValue, header.VertexCoordinateSize);
     Utilities.WriteInteger(writer, Triangle.Tag, header.TriangleNumberSize);
 }