コード例 #1
0
        static void Main(string[] args)
        {
            string infile = "testfixtures/1-0-1-1.pnts";
            var    stream = File.OpenRead(infile);

            Console.WriteLine("Pnts tile sample application");
            Console.WriteLine($"Start parsing {infile}...");
            var pnts = PntsParser.ParsePnts(stream);

            var rtc              = pnts.FeatureTableMetadata.Rtc_Center;
            var rtc_cartesian    = GetCartesianPoint(rtc[0], rtc[1], rtc[2]);
            var cartesian_points = GetCartesianPoints(pnts);
            var wgs84Points      = GetWgs84Points(cartesian_points, rtc_cartesian);

            WritePositions3DToCsv("positions.csv", wgs84Points);

            var first_point = wgs84Points[0];

            Console.WriteLine($"Number of points: {pnts.FeatureTableMetadata.points_length} ");
            Console.WriteLine($"RTC_CENTER (relative to center x,y,z): {rtc[0]},{rtc[1]},{rtc[2]}");
            Console.WriteLine($"First point (x,y,z): {pnts.Points[0].X}, {pnts.Points[0].Y}, {pnts.Points[0].Z} ");
            Console.WriteLine($"First point (longitude, latitude, altitude): {first_point.Longitude.DecimalDegrees}, {first_point.Latitude.DecimalDegrees}, {first_point.Altitude} ");
            Console.WriteLine($"First point color (r,g,b): {pnts.Colors[0].R}, {pnts.Colors[0].G}, {pnts.Colors[0].B} ");
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
コード例 #2
0
        public void ParsePntsTest()
        {
            // arrange

            // act
            var pnts = PntsParser.ParsePnts(pntsfile);

            // assert
            Assert.IsTrue(expectedMagicHeader == pnts.Magic);
            Assert.IsTrue(expectedVersionHeader == pnts.Version);
            Assert.IsTrue(pnts.Points != null);
            Assert.IsTrue(pnts.Points.Count > 0);
            Assert.IsTrue(pnts.Points[0].X == (float)144.78);
            Assert.IsTrue(pnts.Points[0].Y == (float)-64.85);
            Assert.IsTrue(pnts.Points[0].Z == (float)-174.68);
            Assert.IsTrue(pnts.Colors != null);
            Assert.IsTrue(pnts.Colors.Count > 0);
            Assert.IsTrue(pnts.Colors[0].R == 75);
            Assert.IsTrue(pnts.Colors[0].G == 91);
            Assert.IsTrue(pnts.Colors[0].B == 88);
            Assert.IsTrue(pnts.FeatureTableMetadata.points_length == 164);
            var rtc = pnts.FeatureTableMetadata.Rtc_Center;

            Assert.IsTrue(rtc[0] == 3830004.5);
            Assert.IsTrue(rtc[1] == 323597.5);
            Assert.IsTrue(rtc[2] == 5072948.5);
        }
コード例 #3
0
        public void TestPointsFile()
        {
            // source file: https://github.com/CesiumGS/3d-tiles-samples/blob/master/tilesets/TilesetWithRequestVolume/points.pnts
            var pntsFile = File.OpenRead(@"testfixtures/points.pnts");
            var pnts     = PntsParser.ParsePnts(pntsFile);

            Assert.IsTrue(expectedMagicHeader == pnts.Magic);
            Assert.IsTrue(expectedVersionHeader == pnts.Version);
            Assert.IsTrue(pnts.Points.Count == 125000);
            Assert.IsTrue(pnts.Colors.Count == 125000);
            Assert.IsTrue(pnts.Points[0].X == (float)-1.1413337);
            Assert.IsTrue(pnts.Points[0].Y == (float)0.359452039);
            Assert.IsTrue(pnts.Points[0].Z == (float)-0.361457467);
            Assert.IsTrue(pnts.Colors[0].R == 182);
            Assert.IsTrue(pnts.Colors[0].G == 215);
            Assert.IsTrue(pnts.Colors[0].B == 153);
        }
コード例 #4
0
ファイル: MapViewer.cs プロジェクト: Geodan/UnityViewer
        private IEnumerator RequestTreeTile(string url)
        {
            DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
            var www = new UnityWebRequest(url)
            {
                downloadHandler = handler
            };

            yield return(www.SendWebRequest());

            if (!www.isNetworkError && !www.isHttpError)
            {
                //get data
                var stream = new MemoryStream(www.downloadHandler.data);

                var pnts      = PntsParser.ParsePnts(stream);
                var pointData = pnts.Points;
                var colorData = pnts.Colors;

                Vector3[] verts = new Vector3[pointData.Count];
                for (int i = 0; i < pointData.Count; i++)
                {
                    var dist_x = new Distance(pnts.FeatureTableMetadata.Rtc_Center[0] + pointData[i].X, DistanceUnit.Meters); //lon
                    var dist_y = new Distance(pnts.FeatureTableMetadata.Rtc_Center[1] + pointData[i].Y, DistanceUnit.Meters); //lat
                    var dist_z = new Distance(pnts.FeatureTableMetadata.Rtc_Center[2] + pointData[i].Z, DistanceUnit.Meters); //alt

                    var WGS84Coor = new CartesianPoint(dist_x, dist_y, dist_z).ToPosition3D();

                    double x      = WGS84Coor.Longitude.DecimalDegrees;
                    double height = WGS84Coor.Altitude.Value;
                    double z      = WGS84Coor.Latitude.DecimalDegrees;

                    //conversion to view
                    var xv = (x - floatingOrigin.x) * UnityUnitsPerGraadX;
                    var zv = (z - floatingOrigin.y) * UnityUnitsPerGraadY;

                    verts[i] = new Vector3((float)xv, (float)height, (float)zv);
                }


                Color[] colors = new Color[colorData.Count];
                for (int i = 0; i < colorData.Count; i++)
                {
                    colors[i] = new Color(colorData[i].R / (float)255f, colorData[i].G / (float)255f, colorData[i].B / (float)255f, colorData[i].A / (float)255f);
                }

                int[] tris = new int[pointData.Count];

                for (int i = 0; i < tris.Length; i++)
                {
                    tris[i] = i;
                }

                Mesh m = new Mesh();
                m.vertices = verts;
                m.colors   = colors;
                m.SetIndices(tris, MeshTopology.Points, 0);
                m.RecalculateBounds();

                GameObject trees = new GameObject("trees: " + url);// { hideFlags = HideFlags.HideInHierarchy };
                trees.AddComponent <MeshRenderer>().material = new Material(Shader.Find("Point Cloud/Point"));
                trees.AddComponent <MeshFilter>().mesh       = m;
            }
            else
            {
                Debug.Log("Tile: [" + url + "] Error loading b3dm data");
            }

            pendingQueue.Remove(url);
        }