private SetVersion GetLargeDataSet()
        {
            SetVersion setVersion = new SetVersion();

            setVersion.Name    = "Test";
            setVersion.Version = "v1";

            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(new BoundingBox(Vector3.Zero, Vector3.Zero), new CubeBounds[] { }, 2);

            using (Stream metadataStream = new FileStream(".\\data\\validdataset2\\v1\\metadata.json", FileMode.Open, FileAccess.Read))
            {
                ocTree = MetadataLoader.Load(metadataStream, ocTree, "L1", new Vector3(1, 1, 1));
            }

            ocTree.UpdateTree();
            Assert.AreEqual(2, ocTree.MinimumSize);
            Assert.IsNotNull(ocTree);
            Assert.IsTrue(ocTree.HasChildren);

            SetVersionLevelOfDetail lod = new SetVersionLevelOfDetail
            {
                Name        = "L1",
                Cubes       = ocTree,
                SetSize     = ocTree.Region.Max - ocTree.Region.Min,
                WorldBounds = new BoundingBox(Vector3.Zero, new Vector3(40, 40, 40))
            };

            setVersion.DetailLevels =
                new SortedDictionary <string, SetVersionLevelOfDetail>(new[] { lod }.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase));
            return(setVersion);
        }
        private async Task <List <SetVersionLevelOfDetail> > ExtractDetailLevels(SetMetadataContract setMetadata, Uri baseUrl)
        {
            List <SetVersionLevelOfDetail> detailLevels = new List <SetVersionLevelOfDetail>();

            foreach (int detailLevel in Enumerable.Range(setMetadata.MinimumLod, setMetadata.MaximumLod - setMetadata.MinimumLod + 1))
            {
                string detailLevelName = "L" + detailLevel;

                Uri lodMetadataUri = new Uri(baseUrl, "L" + detailLevel + "/metadata.json");
                CubeMetadataContract cubeMetadata = await this.Deserialize <CubeMetadataContract>(lodMetadataUri);

                OcTree <CubeBounds> octree = MetadataLoader.Load(cubeMetadata, detailLevelName, new Vector3(1, 1, 1));
                octree.UpdateTree();

                Vector3 cubeBounds = cubeMetadata.SetSize;

                ExtentsContract worldBounds        = cubeMetadata.WorldBounds;
                ExtentsContract virtualWorldBounds = cubeMetadata.VirtualWorldBounds;

                SetVersionLevelOfDetail currentSetLevelOfDetail = new SetVersionLevelOfDetail();
                currentSetLevelOfDetail.Metadata    = lodMetadataUri;
                currentSetLevelOfDetail.Number      = detailLevel;
                currentSetLevelOfDetail.Cubes       = octree;
                currentSetLevelOfDetail.ModelBounds = new BoundingBox(
                    new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                    new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));

                if (virtualWorldBounds != null)
                {
                    currentSetLevelOfDetail.WorldBounds =
                        new BoundingBox(
                            new Vector3(virtualWorldBounds.XMin, virtualWorldBounds.YMin, virtualWorldBounds.ZMin),
                            new Vector3(virtualWorldBounds.XMax, virtualWorldBounds.YMax, virtualWorldBounds.ZMax));
                }
                else
                {
                    currentSetLevelOfDetail.WorldBounds = new BoundingBox(
                        new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                        new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));
                }

                currentSetLevelOfDetail.SetSize     = new Vector3(cubeBounds.X, cubeBounds.Y, cubeBounds.Z);
                currentSetLevelOfDetail.Name        = "L" + detailLevel.ToString(CultureInfo.InvariantCulture);
                currentSetLevelOfDetail.VertexCount = cubeMetadata.VertexCount;

                currentSetLevelOfDetail.TextureTemplate = new Uri(lodMetadataUri, "texture/{x}_{y}.jpg");
                currentSetLevelOfDetail.ModelTemplate   = new Uri(lodMetadataUri, "{x}_{y}_{z}.{format}");

                currentSetLevelOfDetail.TextureSetSize = cubeMetadata.TextureSetSize;

                detailLevels.Add(currentSetLevelOfDetail);
            }
            return(detailLevels);
        }
Exemple #3
0
        public void WorldToCubeTransform()
        {
            BoundingBox             worldBounds = new BoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10));
            SetVersionLevelOfDetail detail      = new SetVersionLevelOfDetail();

            detail.WorldBounds = worldBounds;
            detail.SetSize     = new Vector3(4, 4, 4);

            Vector3 result = detail.ToCubeCoordinates(new Vector3(-5, 5, 0));

            Assert.AreEqual(1, result.X);
            Assert.AreEqual(3, result.Y);
            Assert.AreEqual(2, result.Z);
        }
        public void LargeDataSetQueryPerformanceCube()
        {
            SetVersion setVersion = this.GetLargeDataSet();

            SetVersionLevelOfDetail lod0 = setVersion.DetailLevels.Values.FirstOrDefault();

            Stopwatch timer = new Stopwatch();

            timer.Start();
            int[][] results = setVersion.Query("L1", lod0.WorldBounds).ToArray();
            Trace.WriteLine(results.Count(), "Elements");
            timer.Stop();
            Trace.WriteLine(timer.ElapsedMilliseconds, "Query Performance (ms)");
        }
        private SetVersionLevelOfDetail GenerateRubikLevelOfDetail(string name, int scale, Vector3 worldBounds)
        {
            int offset = scale / 3;
            int min    = offset;
            int max    = (2 * offset);
            List <CubeBounds>       testBounds = new List <CubeBounds>();
            SetVersionLevelOfDetail lod;

            for (int x = 0; x < scale; x++)
            {
                for (int y = 0; y < scale; y++)
                {
                    for (int z = 0; z < scale; z++)
                    {
                        if (offset != 1)
                        {
                            if ((min <= x && x < max) && (min <= y && y < max) && (min <= z && z < max))
                            {
                                testBounds.Add(new ValidCube {
                                    BoundingBox = this.MakeCube(new Vector3(x, y, z), 1)
                                });
                            }
                            else
                            {
                                testBounds.Add(new InvalidCube {
                                    BoundingBox = this.MakeCube(new Vector3(x, y, z), 1)
                                });
                            }
                        }
                        else
                        {
                            testBounds.Add(new ValidCube {
                                BoundingBox = this.MakeCube(new Vector3(x, y, z), 1)
                            });
                        }
                    }
                }
            }
            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            ocTree.UpdateTree();
            lod = new SetVersionLevelOfDetail
            {
                Name        = name,
                Cubes       = ocTree,
                SetSize     = new Vector3(scale, scale, scale),
                WorldBounds = new BoundingBox(Vector3.Zero, worldBounds)
            };
            return(lod);
        }
        private SetVersion GenerateRubiksCubeLOD(IEnumerable <int> scales, Vector3 worldBounds)
        {
            SetVersion setVersion = new SetVersion();

            setVersion.Name    = "RubiksCubeData";
            setVersion.Version = "v1";

            List <SetVersionLevelOfDetail> lods = new List <SetVersionLevelOfDetail>();

            int index = 1;

            foreach (int scale in scales)
            {
                SetVersionLevelOfDetail lod = this.GenerateRubikLevelOfDetail("L" + index++, scale, worldBounds);
                lods.Add(lod);
            }

            setVersion.DetailLevels =
                new SortedDictionary <string, SetVersionLevelOfDetail>(lods.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase));

            return(setVersion);
        }
        private SetVersion Get4x4x4DataSet1()
        {
            SetVersion setVersion = new SetVersion();

            setVersion.Name    = "Test";
            setVersion.Version = "v1";

            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            ocTree.UpdateTree();

            SetVersionLevelOfDetail lod = new SetVersionLevelOfDetail
            {
                Name        = "L1",
                Cubes       = ocTree,
                SetSize     = ocTree.Region.Max - ocTree.Region.Min,
                WorldBounds = new BoundingBox(Vector3.Zero, new Vector3(40, 40, 40))
            };

            setVersion.DetailLevels =
                new SortedDictionary <string, SetVersionLevelOfDetail>(new[] { lod }.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase));
            return(setVersion);
        }
        private async Task <List <SetVersionLevelOfDetail> > ExtractDetailLevels2(SetMetadataContract setMetadata, Uri baseUrl)
        {
            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>();

            List <LoaderSet> lods = new List <LoaderSet>();

            foreach (int detailLevel in Enumerable.Range(setMetadata.MinimumLod, setMetadata.MaximumLod - setMetadata.MinimumLod + 1))
            {
                // Allow exceptions to propagate here for logging in ELMAH
                string detailLevelName            = "L" + detailLevel;
                Uri    lodMetadataUri             = new Uri(baseUrl, detailLevelName + "/metadata.json");
                CubeMetadataContract cubeMetadata = await this.Deserialize <CubeMetadataContract>(lodMetadataUri);

                lods.Add(new LoaderSet {
                    CubeMetadataContract = cubeMetadata, Name = detailLevelName, DetailLevel = detailLevel, MetadataUrl = lodMetadataUri
                });
            }

            Vector3 maxSetSize = new Vector3(0, 0, 0);

            foreach (var loaderSet in lods)
            {
                if (loaderSet.CubeMetadataContract.SetSize.X > maxSetSize.X)
                {
                    maxSetSize.X = loaderSet.CubeMetadataContract.SetSize.X;
                }

                if (loaderSet.CubeMetadataContract.SetSize.Y > maxSetSize.Y)
                {
                    maxSetSize.Y = loaderSet.CubeMetadataContract.SetSize.Y;
                }

                if (loaderSet.CubeMetadataContract.SetSize.Z > maxSetSize.Z)
                {
                    maxSetSize.Z = loaderSet.CubeMetadataContract.SetSize.Z;
                }
            }

            List <SetVersionLevelOfDetail> detailLevels = new List <SetVersionLevelOfDetail>();

            foreach (LoaderSet loaderSet in lods)
            {
                var cubeMetadata = loaderSet.CubeMetadataContract;

                Vector3 cubeSize = maxSetSize / loaderSet.CubeMetadataContract.SetSize;

                ocTree.Add(MetadataLoader.LoadCubeBounds(loaderSet.CubeMetadataContract, loaderSet.Name, cubeSize));

                Vector3 cubeBounds = cubeMetadata.SetSize;

                ExtentsContract worldBounds        = cubeMetadata.WorldBounds;
                ExtentsContract virtualWorldBounds = cubeMetadata.VirtualWorldBounds;

                SetVersionLevelOfDetail currentSetLevelOfDetail = new SetVersionLevelOfDetail();
                currentSetLevelOfDetail.Metadata    = loaderSet.MetadataUrl;
                currentSetLevelOfDetail.Number      = loaderSet.DetailLevel;
                currentSetLevelOfDetail.Cubes       = ocTree;
                currentSetLevelOfDetail.ModelBounds = new BoundingBox(
                    new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                    new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));

                if (virtualWorldBounds != null)
                {
                    currentSetLevelOfDetail.WorldBounds =
                        new BoundingBox(
                            new Vector3(virtualWorldBounds.XMin, virtualWorldBounds.YMin, virtualWorldBounds.ZMin),
                            new Vector3(virtualWorldBounds.XMax, virtualWorldBounds.YMax, virtualWorldBounds.ZMax));
                }
                else
                {
                    currentSetLevelOfDetail.WorldBounds = new BoundingBox(
                        new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                        new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));
                }

                currentSetLevelOfDetail.SetSize     = new Vector3(cubeBounds.X, cubeBounds.Y, cubeBounds.Z);
                currentSetLevelOfDetail.Name        = "L" + loaderSet.DetailLevel.ToString(CultureInfo.InvariantCulture);
                currentSetLevelOfDetail.VertexCount = cubeMetadata.VertexCount;

                currentSetLevelOfDetail.TextureTemplate = new Uri(loaderSet.MetadataUrl, "texture/{x}_{y}.jpg");
                currentSetLevelOfDetail.ModelTemplate   = new Uri(loaderSet.MetadataUrl, "{x}_{y}_{z}.{format}");

                currentSetLevelOfDetail.TextureSetSize = cubeMetadata.TextureSetSize;

                detailLevels.Add(currentSetLevelOfDetail);
            }

            ocTree.UpdateTree();

            return(detailLevels);
        }