예제 #1
0
 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);
 }
예제 #2
0
        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);
        }
예제 #3
0
        public void Write_NonEmpty()
        {
            TrimbleTINModel TTM = new TrimbleTINModel();

            TTM.LoadFromFile(Path.Combine("TestData", "Bug36372.ttm"));
            Test_TTMWriteAndReadBack(TTM);
        }
예제 #4
0
        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);
        }
예제 #5
0
 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);
 }
예제 #6
0
        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);
        }
예제 #7
0
        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();
        }
예제 #8
0
        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);
        }
예제 #9
0
        public void BuildStartPoint_Empty()
        {
            TrimbleTINModel TTM = new TrimbleTINModel();

            TTM.BuildStartPointList();

            TTM.StartPoints.Count.Should().Be(0);
        }
예제 #10
0
 /// <summary>
 /// Creates an empty profiler context
 /// </summary>
 public OptimisedTTMProfiler(TrimbleTINModel ttm,
                             IOptimisedSpatialIndexSubGridTree index,
                             int [] indices)
 {
     TTM     = ttm;
     Index   = index;
     Indices = indices;
 }
예제 #11
0
        /// <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;
        }
예제 #12
0
        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");
        }
예제 #13
0
        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];
        }
예제 #14
0
        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();
        }
예제 #15
0
        public void SaveToFile_Empty()
        {
            TrimbleTINModel TTM = new TrimbleTINModel();

            var fileName = Path.GetTempFileName() + ".ttm";

            TTM.SaveToFile(fileName);

            File.Delete(fileName);
        }
예제 #16
0
        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();
        }
예제 #17
0
        public void ReadHeaderFromFile_InvalidFile()
        {
            var fileName = Path.GetTempFileName() + ".ttm";

            File.WriteAllBytes(fileName, new byte[100]);

            TrimbleTINModel.ReadHeaderFromFile(fileName, out _).Should().BeFalse();

            File.Delete(fileName);
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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);
        }
예제 #21
0
        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);
        }
예제 #22
0
        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);
        }
예제 #23
0
        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);
        }
예제 #24
0
        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);
        }
예제 #25
0
        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);
        }
예제 #26
0
        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);
        }
예제 #27
0
        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);
        }
예제 #28
0
        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);
        }
예제 #29
0
        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);
            }
        }
예제 #30
0
        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);
            }
        }