private double[] GetVolumeBox(double[] actualTilesetBox, double[] actualTransform)
        {
            var transform       = new double[] { actualTransform[12], actualTransform[13], actualTransform[14] };
            var bb              = new BoundingBox3D(actualTilesetBox);
            var transformback   = bb.TransformZToY();
            var from            = BoundingBoxCalculator.RotateXTranslate(transformback.FromPoint(), transform, Math.PI * -1 / 2);
            var to              = BoundingBoxCalculator.RotateXTranslate(transformback.ToPoint(), transform, Math.PI * -1 / 2);
            var bbox3d          = new BoundingBox3D((double)from.X, (double)from.Y, (double)from.Z, (double)to.X, (double)to.Y, (double)to.Z);
            var center          = bbox3d.GetCenter();
            var actualVolumeBox = new double[] { (double)center.X, (double)center.Y, (double)center.Z, (bbox3d.ExtentX() / 2), 0, 0, 0, bbox3d.ExtentY() / 2, 0, 0, 0, bbox3d.ExtentZ() / 2 };

            return(actualVolumeBox);
        }
        public static void CalculateBoundingVolume()
        {
            // values for table delaware_buildings_4978
            var translation            = new double[] { 1238070.0029833354 * -1, -4795867.9075041208 * -1, 4006102.3617460253 * -1 };
            var bbox3d                 = new BoundingBox3D(1231256.4091099831, -4800453.896456448, 4000024.663498499, 1244883.5968566877, -4791281.918551793, 4012180.059993551);
            var boundingboxAllFeatures = BoundingBoxCalculator.TranslateRotateX(bbox3d, translation, Math.PI / 2);
            var box         = boundingboxAllFeatures.GetBox();
            var expectedBox = new double[] { 0.0, 0.0, 0.0, 6813.593873352278, 0.0, 0.0, 0.0, 4585.98895, 0.0, 0.0, 0.0, 6077.69825 };

            for (var i = 0; i < box.Length; i++)
            {
                Assert.IsTrue(box[i].Equals(expectedBox[i]));
            }
        }
Exemple #3
0
        private static void CalculateBoundingBoxes(double[] translation, List <Tile> tiles, double minZ, double maxZ)
        {
            foreach (var t in tiles)
            {
                var bb          = t.BoundingBox;
                var bvol        = new BoundingBox3D(bb.XMin, bb.YMin, minZ, bb.XMax, bb.YMax, maxZ);
                var bvolRotated = BoundingBoxCalculator.TranslateRotateX(bvol, Reverse(translation), Math.PI / 2);

                if (t.Children != null)
                {
                    CalculateBoundingBoxes(translation, t.Children, minZ, maxZ);
                }
                t.Boundingvolume = TileCutter.GetBoundingvolume(bvolRotated);
            }
        }
        public void BoundingBoxCalculatorTest()
        {
            // arrange
            var bboxes = new List <BoundingBox3D>();
            var bbox1  = new BoundingBox3D(0, 0, 0, 1, 1, 1);

            bboxes.Add(bbox1);

            // act
            var box = BoundingBoxCalculator.GetBoundingBox(bboxes);

            // assert
            Assert.IsTrue(box.XMin == 0);
            Assert.IsTrue(box.YMin == 0);
            Assert.IsTrue(box.XMax == 1);
            Assert.IsTrue(box.YMax == 1);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var version = Assembly.GetEntryAssembly().GetName().Version;

            Console.WriteLine($"tool: pg2b3dm {version}");

            Parser.Default.ParseArguments <Options>(args).WithParsed(o => {
                o.User     = string.IsNullOrEmpty(o.User) ? Environment.UserName : o.User;
                o.Database = string.IsNullOrEmpty(o.Database) ? Environment.UserName : o.Database;

                var connectionString = $"Host={o.Host};Username={o.User};Database={o.Database};Port={o.Port}";
                var istrusted        = TrustedConnectionChecker.HasTrustedConnection(connectionString);

                if (!istrusted)
                {
                    Console.Write($"password for user {o.User}: ");
                    password          = PasswordAsker.GetPassword();
                    connectionString += $";password={password}";
                    Console.WriteLine();
                }

                Console.WriteLine($"start processing....");

                var stopWatch = new Stopwatch();
                stopWatch.Start();

                var output      = o.Output;
                var outputTiles = $"{output}{Path.DirectorySeparatorChar}tiles";
                if (!Directory.Exists(output))
                {
                    Directory.CreateDirectory(output);
                }
                if (!Directory.Exists(outputTiles))
                {
                    Directory.CreateDirectory(outputTiles);
                }

                Console.WriteLine($"input table:  {o.GeometryTable}");
                if (o.Query != String.Empty)
                {
                    Console.WriteLine($"query:  {o.Query}");
                }
                Console.WriteLine($"input geometry column:  {o.GeometryColumn}");

                Console.WriteLine($"output directory:  {outputTiles}");

                var geometryTable   = o.GeometryTable;
                var geometryColumn  = o.GeometryColumn;
                var idcolumn        = o.IdColumn;
                var lodcolumn       = o.LodColumn;
                var query           = o.Query;
                var geometricErrors = Array.ConvertAll(o.GeometricErrors.Split(','), double.Parse);;

                var conn = new NpgsqlConnection(connectionString);

                var lods = (lodcolumn != string.Empty ? LodsRepository.GetLods(conn, geometryTable, lodcolumn, query) : new List <int> {
                    0
                });
                if ((geometricErrors.Length != lods.Count + 1) && lodcolumn == string.Empty)
                {
                    Console.WriteLine($"lod levels: [{ String.Join(',', lods)}]");
                    Console.WriteLine($"geometric errors: {o.GeometricErrors}");

                    Console.WriteLine("error: parameter -g --geometricerrors is wrongly specified...");
                    Console.WriteLine("end of program...");
                    Environment.Exit(0);
                }
                if (lodcolumn != String.Empty)
                {
                    Console.WriteLine($"lod levels: {String.Join(',', lods)}");

                    if (lods.Count >= geometricErrors.Length)
                    {
                        Console.WriteLine($"calculating geometric errors starting from {geometricErrors[0]}");
                        geometricErrors = GeometricErrorCalculator.GetGeometricErrors(geometricErrors[0], lods);
                    }
                }
                ;
                Console.WriteLine("geometric errors: " + String.Join(',', geometricErrors));

                var bbox3d = BoundingBoxRepository.GetBoundingBox3DForTable(conn, geometryTable, geometryColumn, query);
                // Console.WriteLine($"3D Boundingbox {geometryTable}.{geometryColumn}: [{bbox3d.XMin}, {bbox3d.YMin}, {bbox3d.ZMin},{bbox3d.XMax},{bbox3d.YMax}, {bbox3d.ZMax}]");
                var translation = bbox3d.GetCenter().ToVector();
                //  Console.WriteLine($"translation {geometryTable}.{geometryColumn}: [{string.Join(',', translation) }]");
                var boundingboxAllFeatures = BoundingBoxCalculator.TranslateRotateX(bbox3d, Reverse(translation), Math.PI / 2);
                var box = boundingboxAllFeatures.GetBox();
                var sr  = SpatialReferenceRepository.GetSpatialReference(conn, geometryTable, geometryColumn, query);
                Console.WriteLine($"spatial reference: {sr}");
                var tiles = TileCutter.GetTiles(0, conn, o.ExtentTile, geometryTable, geometryColumn, bbox3d, sr, 0, lods, geometricErrors.Skip(1).ToArray(), lodcolumn, query);
                Console.WriteLine();
                var nrOfTiles = RecursiveTileCounter.CountTiles(tiles.tiles, 0);
                Console.WriteLine($"tiles with features: {nrOfTiles} ");
                CalculateBoundingBoxes(translation, tiles.tiles, bbox3d.ZMin, bbox3d.ZMax);
                Console.WriteLine("writing tileset.json...");
                var json = TreeSerializer.ToJson(tiles.tiles, translation, box, geometricErrors[0], o.Refinement);
                File.WriteAllText($"{o.Output}/tileset.json", json);

                WriteTiles(conn, geometryTable, geometryColumn, idcolumn, translation, tiles.tiles, sr, o.Output, 0, nrOfTiles, o.RoofColorColumn, o.AttributesColumn, o.LodColumn, query);

                stopWatch.Stop();
                Console.WriteLine();
                Console.WriteLine($"elapsed: {stopWatch.ElapsedMilliseconds / 1000} seconds");
                Console.WriteLine("program finished.");
            });
        }