private void CheckTTMAttributes(TrimbleTINModel TTM1, TrimbleTINModel TTM2) { TTM1.Triangles.Count.Should().Be(TTM2.Triangles.Count); TTM1.Vertices.Count.Should().Be(TTM2.Vertices.Count); TTM1.Edges.Count.Should().Be(TTM2.Edges.Count); TTM1.StartPoints.Count.Should().Be(TTM2.StartPoints.Count); }
public void IsTTMFile_ErrorVerifyingVersion(byte majorVersion, byte minorVersion) { var TTM = new TrimbleTINModel(); TTM.Header.FileMajorVersion = majorVersion; TTM.Header.FileMinorVersion = minorVersion; var fileName = Path.GetTempFileName() + ".ttm"; TTM.SaveToFile(fileName); // Pervert the version in the file. Byte 1 = major version, byte 2 = minor version var bytes = File.ReadAllBytes(fileName); bytes[0] = majorVersion; bytes[1] = minorVersion; File.WriteAllBytes(fileName, bytes); TrimbleTINModel.IsTTMFile(fileName, out var message).Should().BeFalse(); message.Should().StartWith("TTM.IsTTMFile(): Unable to read this version"); File.Delete(fileName); }
public void Write_NonEmpty() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); Test_TTMWriteAndReadBack(TTM); }
public void ReadInvalidTTMFile_ErrorVerifyingVersion(byte majorVersion, byte minorVersion) { var ttm = new TTM.TrimbleTINModel(); ttm.Header.FileMajorVersion = majorVersion; ttm.Header.FileMinorVersion = minorVersion; var fileName = Path.GetTempFileName() + ".ttm"; ttm.SaveToFile(fileName); // Pervert the version in the file. Byte 1 = major version, byte 2 = minor version var bytes = File.ReadAllBytes(fileName); bytes[0] = majorVersion; bytes[1] = minorVersion; File.WriteAllBytes(fileName, bytes); var TTM2 = new TrimbleTINModel(); Action act = () => TTM2.LoadFromFile(fileName); act.Should().Throw <TTMFileReadException>().WithMessage("*Unable to read this version*"); File.Delete(fileName); }
private void CheckTTMAttributes(TrimbleTINModel ttm1, TrimbleTINModel ttm2) { ttm1.Triangles.Items.Length.Should().Be(ttm2.Triangles.Items.Length); ttm1.Vertices.Items.Length.Should().Be(ttm2.Vertices.Items.Length); ttm1.Edges.Items.Length.Should().Be(ttm2.Edges.Items.Length); ttm1.StartPoints.Items.Length.Should().Be(ttm2.StartPoints.Items.Length); }
public void LoadFromFile_SmallTTM(double eastSize, double northSize, double elevation) { var ttm = new TTM.TrimbleTINModel(); ttm.Vertices.InitPointSearch(-1, -1, eastSize + 1, northSize + 1, 100); ttm.Triangles.AddTriangle(ttm.Vertices.AddPoint(0, 0, elevation), ttm.Vertices.AddPoint(0, northSize, elevation), ttm.Vertices.AddPoint(eastSize, 0, elevation)); ttm.Triangles.AddTriangle(ttm.Vertices.AddPoint(eastSize, 0, elevation), ttm.Vertices.AddPoint(eastSize, northSize, elevation), ttm.Vertices.AddPoint(0, northSize, elevation)); var fileName = Path.GetTempFileName() + ".ttm"; ttm.SaveToFile(fileName, 0.001, 0.001); var ttm2 = new TrimbleTINModel(); ttm2.LoadFromFile(fileName); CheckTTMAttributes(ttm, ttm2); File.Delete(fileName); }
private void RemoveCornerAndNullTriangles() { TrimbleTINModel TIN = Engine.TIN; double NullHeightLimit = DecimationExtents.MinZ - 0.001; // Remove all triangles that have a null height vertex as a corner for (int I = 0; I < TIN.Triangles.Count; I++) { if (TIN.Triangles[I].Vertices[0].Z < NullHeightLimit || TIN.Triangles[I].Vertices[1].Z < NullHeightLimit || TIN.Triangles[I].Vertices[2].Z < NullHeightLimit) { //Debug.Assert(TIN.Triangles[I].Tag - 1 == I, "Tag and triangle index inconsistent"); TIN.Triangles.RemoveTriangle(TIN.Triangles[I]); } } TIN.Triangles.Pack(); TIN.Triangles.NumberTriangles(); // Remove all vertices with null heights for (int I = 0; I < TIN.Vertices.Count; I++) { if (TIN.Vertices[I].Z < NullHeightLimit) { TIN.Vertices[I] = null; } } TIN.Vertices.Pack(); TIN.Vertices.NumberVertices(); }
public void Initialise(TrimbleTINModel ATTM, bool AWantSearchStamps) { TTM = ATTM; /* * if (AWantSearchStamps) * { * if (FSearchStamps != null) * { * FreeMem(FSearchStamps); * FSearchStamps = null; * } * * int Num = 0; * if (TTM.Triangles.Count > 0) * Num = (TTM.Triangles.Count + 1); * else * if (TTM.Vertices.Count > 0) * Num = 3 * (TTM.Vertices.Count + 1); * * if (Num > 0) * { * // GetMem(FSearchStamps, Num* sizeof(word)); * //FillChar(FSearchStamps^, num* sizeof(Word), 0); * } * } */ resize_quadtree(TTM.Header.MinimumEasting - 100, TTM.Header.MinimumNorthing - 100, TTM.Header.MaximumEasting + 100, TTM.Header.MaximumNorthing + 100); }
public void BuildStartPoint_Empty() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.BuildStartPointList(); TTM.StartPoints.Count.Should().Be(0); }
/// <summary> /// Creates an empty profiler context /// </summary> public OptimisedTTMProfiler(TrimbleTINModel ttm, IOptimisedSpatialIndexSubGridTree index, int [] indices) { TTM = ttm; Index = index; Indices = indices; }
/// <summary> /// Constructs a builder from a given TTM model in the optimized format and other information /// </summary> /// <param name="ttm"></param> /// <param name="cellSize"></param> public OptimisedTTMSpatialIndexBuilder(TrimbleTINModel ttm, double cellSize) { TTM = ttm; CellSize = cellSize; TriangleItems = ttm.Triangles.Items; VertexItems = ttm.Vertices.Items; }
public void LoadFromFile() { var ttm = new TrimbleTINModel(); ttm.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); Assert.True(ttm.Vertices.Items.Length > 0, "No vertices loaded from TTM file"); Assert.True(ttm.Triangles.Items.Length > 0, "No triangles loaded from TTM file"); }
public TinningEngine() { TIN = new TrimbleTINModel(); // Set sizes of all lists to be 1 to force list lengthening logic to be exercised as a matter of course. affSideList = new AffSideNode[1]; candidateList = new TriListNode[1]; affectedList = new TriListNode[1]; }
public void LoadFromFile() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); Assert.True(TTM.Vertices.Count > 0, "No vertices loaded from TTM file"); Assert.True(TTM.Triangles.Count > 0, "No triangles loaded from TTM file"); TTM.Loading.Should().BeFalse(); }
public void SaveToFile_Empty() { TrimbleTINModel TTM = new TrimbleTINModel(); var fileName = Path.GetTempFileName() + ".ttm"; TTM.SaveToFile(fileName); File.Delete(fileName); }
public void Triangles_RemoveTriangle() { var ttm = new TrimbleTINModel(); ttm.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); ttm.Triangles.RemoveTriangle(ttm.Triangles[0]); ttm.Triangles[0].Should().BeNull(); }
public void ReadHeaderFromFile_InvalidFile() { var fileName = Path.GetTempFileName() + ".ttm"; File.WriteAllBytes(fileName, new byte[100]); TrimbleTINModel.ReadHeaderFromFile(fileName, out _).Should().BeFalse(); File.Delete(fileName); }
public void SaveToFile_WithEdgeBuilding(bool state) { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); var fileName = Path.GetTempFileName() + ".ttm"; TTM.SaveToFile(fileName, state); File.Delete(fileName); }
public void IsTTMFile_ErrorVerifyingTTMIdentifier_Null() { var fileName = Path.GetTempFileName() + ".ttm"; File.WriteAllBytes(fileName, new byte[500]); TrimbleTINModel.IsTTMFile(fileName, out var message).Should().BeFalse(); message.Should().StartWith("File is not a Trimble TIN Model"); File.Delete(fileName); }
public void GetElevationRange() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); TTM.GetElevationRange(out var MinElev, out var MaxElev); MinElev.Should().BeApproximately(22.5, 0.001); MaxElev.Should().BeApproximately(37.33, 0.001); }
public void IsTTMFile_ErrorReadingHeader() { var fileName = Path.GetTempFileName() + ".ttm"; File.WriteAllBytes(fileName, new byte[100]); TrimbleTINModel.IsTTMFile(fileName, out var message).Should().BeFalse(); message.Should().StartWith("Error reading header"); File.Delete(fileName); }
public void ReadHeaderFromFile() { TrimbleTINModel.ReadHeaderFromFile(Path.Combine("TestData", "Bug36372.ttm"), out var header).Should().BeTrue(); header.NumberOfTriangles.Should().Be(67251); header.NumberOfVertices.Should().Be(34405); header.MaximumEasting.Should().BeApproximately(248539.6337, 001); header.MaximumNorthing.Should().BeApproximately(194587.6191, 001); header.MinimumEasting.Should().BeApproximately(246852.3283, 001); header.MinimumNorthing.Should().BeApproximately(191674.8496, 001); }
public void SaveToFile_NonEmpty() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); var fileName = Path.GetTempFileName() + ".ttm"; TTM.SaveToFile(fileName); File.Delete(fileName); }
public void ReadInvalidTTMFile_ErrorReadingHeader() { var fileName = Path.GetTempFileName() + ".ttm"; File.WriteAllBytes(fileName, new byte[100]); var ttm = new TrimbleTINModel(); Action act = () => ttm.LoadFromFile(fileName); act.Should().Throw <TTMFileReadException>().WithMessage("Exception at TTM loading phase Error reading header"); File.Delete(fileName); }
public void Read_NonEmpty() { var ttm = new TrimbleTINModel(); byte[] bytes = File.ReadAllBytes(Path.Combine("TestData", "Bug36372.ttm")); using (BinaryReader br = new BinaryReader(new MemoryStream(bytes))) { ttm.Read(br, bytes); } ttm.Header.NumberOfTriangles.Should().Be(67251); ttm.Header.NumberOfVertices.Should().Be(34405); }
public void BuildEdgeList() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); TTM.Edges.Count.Should().Be(1525); TTM.Edges.Clear(); TTM.Edges.Count.Should().Be(0); TTM.BuildEdgeList(); TTM.Edges.Count.Should().Be(1525); }
public void ReadInvalidTTMFile_ErrorVerifyingTTMIdentifier() { var ttm = new TrimbleTINModel(); var fileName = Path.GetTempFileName() + ".ttm"; File.WriteAllBytes(fileName, new byte[500]); Action act = () => ttm.LoadFromFile(fileName); act.Should().Throw <TTMFileReadException>().WithMessage("File is not a Trimble TIN Model."); File.Delete(fileName); }
public void BuildStartPointList() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); TTM.StartPoints.Count.Should().Be(16); TTM.StartPoints.Clear(); TTM.StartPoints.Count.Should().Be(0); TTM.BuildStartPointList(); TTM.StartPoints.Count.Should().Be(50); }
private void Test_TTMWriteAndReadBack(TrimbleTINModel TTM) { using (var bw = new BinaryWriter(new MemoryStream(Common.Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION))) { TTM.Write(bw); TrimbleTINModel TTM2 = new TrimbleTINModel(); MemoryStream ms = bw.BaseStream as MemoryStream; ms.Position = 0; TTM2.Read(new BinaryReader(ms)); CheckTTMAttributes(TTM, TTM2); } }
public void Read_NonEmpty() { TrimbleTINModel TTM = new TrimbleTINModel(); TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm")); byte[] bytes = File.ReadAllBytes(Path.Combine("TestData", "Bug36372.ttm")); using (var br = new BinaryReader(new MemoryStream(bytes))) { TrimbleTINModel TTM2 = new TrimbleTINModel(); TTM2.Read(br); CheckTTMAttributes(TTM, TTM2); } }