Exemplo n.º 1
0
        /// <param name="level">Selects hierarchy Level the kdtree is built of (-1 shouldn't be used, use BuildKdtreeN instead).</param>
        /// <param name="progressObserver">Reports progress in increments which sum up to 1.</param>
        public static void BuildKdTreeForLevel(
            OpcPaths opcPaths, int level, PositionsType posType,
            bool lazy = true, bool overrideExisting = false, IObserver <float> progressObserver = null,
            CancellationToken cancelToken = default(CancellationToken), PatchHierarchyInfo hierarchyInfo = null,
            float maxTriangleSize         = float.PositiveInfinity)
        {
            #region Preconditions

            if (hierarchyInfo == null)
            {
                hierarchyInfo = PatchHierarchyInfo.BuildOrLoadCache(opcPaths);
            }

            if (posType == PositionsType.V2dPositions && !hierarchyInfo.PatchTree.Info.Has2dData)
            {
                Report.Warn("KdTreeUtils: 2d KdTree needs 2d data to be able to get built.");
                progressObserver.OnNext(1f);
                progressObserver.OnCompleted();
                return;
            }

            opcPaths.SetRootPatchName(hierarchyInfo.RootPatch);

            var kdTreeSetPath = opcPaths.GetAggKdTreePath(level, posType);
            if (!overrideExisting && StorageConfig.FileExists(kdTreeSetPath))
            {
                progressObserver.OnNext(1f);
                progressObserver.OnCompleted();
                return;
            }

            #endregion

            hierarchyInfo.PatchTree.CreatePatchPaths(opcPaths.PatchesSubDir);

            // Get geometry patchinformations for certain level with a valid boundingbox
            var patchTrees = hierarchyInfo.RetrievePatchTreesOfLevel(level)
                             .Where(x => !x.Info.GlobalBoundingBox.IsInvalid);

            IIntersectableObjectSet kdTree;
            var buildFlags =
                KdIntersectionTree.BuildFlags.Hierarchical |
                KdIntersectionTree.BuildFlags.EmptySpaceOptimization;

            // Decide lazy or eager
            if (lazy)
            {
                kdTree      = BuildLazyKdTreeSet(patchTrees, opcPaths, level, posType, overrideExisting, progressObserver, cancelToken, maxTriangleSize);
                buildFlags |= KdIntersectionTree.BuildFlags.OptimalRaytracing;
            }
            else
            {
                kdTree      = BuildConcreteKdTreeSet(patchTrees, opcPaths, level, posType, overrideExisting, progressObserver, cancelToken, maxTriangleSize);
                buildFlags |= KdIntersectionTree.BuildFlags.MediumIntersection;
            }

            // Save Kd-Tree
            var aggrTree = new KdIntersectionTree(kdTree, buildFlags);
            aggrTree.Save(kdTreeSetPath, waitMode: WaitMode.WaitUntilFinished);
        }
Exemplo n.º 2
0
 public ConcreteKdIntersectionTree(
     KdIntersectionTree kdIntersectionTree,
     Trafo3d trafo)
 {
     KdIntersectionTree = kdIntersectionTree;
     Trafo = trafo;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Loads level N kdtree. If level N kdtree does not exist it is built from rootpatch.
        /// </summary>
        public static KdIntersectionTree BuildOrLoadKdTreeN(OpcPaths opcPaths, PositionsType posType, PatchFileInfo patchFileInfo)
        {
            KdIntersectionTree kdiTree = null;
            var kdTreeNPatch           = opcPaths.GetKdTreeNPath(posType);

            if (!StorageConfig.FileExists(kdTreeNPatch))
            {
                kdiTree = KdTreeUtils.BuildKdTreeForPatch(opcPaths.RootPatchName, -1, patchFileInfo, opcPaths, posType, saveTriangles: true);
                kdiTree.Save(opcPaths.RootPatchName);
            }
            else
            {
                kdiTree = Load.As <KdIntersectionTree>(opcPaths.GetKdTreeNPath(posType));
            }

            return(kdiTree);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Builds kdtree for specific patch.
        /// Kdtree is built according to specified positions type and hierarchy level.
        /// </summary>
        private static KdIntersectionTree BuildKdTreeForPatch(
            string patchName, int level, PatchFileInfo info, OpcPaths paths,
            PositionsType posType, bool saveTriangles = false, bool saveKdTree = true,
            float maxTriangleSize = float.PositiveInfinity)
        {
            var path = Path.Combine(paths.PatchesSubDir, patchName);

            var patchGeometry = new TriangleSet();

            //var patchGeometryTest = new TriangleSet();
            if ((maxTriangleSize < float.PositiveInfinity) && (maxTriangleSize > 0.000001f))
            {
                patchGeometry = PatchLoadingStrategy.LoadPatchTriangleSetWithoutOversizedTriangles(info, path, posType, maxTriangleSize);
                //patchGeometryTest = PatchLoadingStrategy.LoadPatchTriangleSet(info, path, posType);
            }
            else
            {
                patchGeometry = PatchLoadingStrategy.LoadPatchTriangleSet(info, path, posType);
            }

            KdIntersectionTree kdIntTree =
                new KdIntersectionTree(patchGeometry,
                                       KdIntersectionTree.BuildFlags.MediumIntersection |
                                       KdIntersectionTree.BuildFlags.Hierarchical);

            if (!saveTriangles)
            {
                kdIntTree.ObjectSet = null;
            }

            if (saveKdTree)
            {
                var kdTreePath = paths.GetKdTreePath(patchName, level, posType);
                kdIntTree.Save(kdTreePath);
            }

            return(kdIntTree);
        }
Exemplo n.º 5
0
 public KdTreeCacheElement(string path, KdIntersectionTree tree)
 {
     Path = path;
     Tree = tree;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Returns a concrete kd intersection tree using the provided
 /// kd tree and an identity trafo.
 /// </summary>
 public static ConcreteKdIntersectionTree ToConcreteKdIntersectionTree(
     this KdIntersectionTree kdTree)
 {
     return(new ConcreteKdIntersectionTree(kdTree, Trafo3d.Identity));
 }
Exemplo n.º 7
0
 public ConcreteKdIntersectionTree()
 {
     KdIntersectionTree = new KdIntersectionTree();
     Trafo = Trafo3d.Identity;
 }