Exemplo n.º 1
0
        public static KdIntersectionTree LoadAndPutIntoCache(KdTreePlaceHolder ph)
        {
            var element = Load.As <KdIntersectionTree>(ph.Path);

            s_cache[s_cachePointer] = new KdTreeCacheElement(ph.Path, element);
            s_cachePointer          = (s_cachePointer + 1) % s_cache.Length;

            return(element);
        }
Exemplo n.º 2
0
        public static PatchHierarchyInfo FromCacheFile(string filePath)
        {
            var patchHierarchyInfo = Load.As <PatchHierarchyInfo>(filePath);

            if (patchHierarchyInfo == null)
            {
                Report.Warn("PatchHierarchyInfo: Wrong format cache file at " + filePath);
            }

            return(patchHierarchyInfo);
        }
Exemplo n.º 3
0
        public bool ObjectIsInsideBox(
            int objectIndex,
            Box3d box
            )
        {
            var ph     = KdTreePlaceholders[objectIndex];
            var kdTree = Load.As <KdIntersectionTree>(ph.Path);

            return(kdTree.IsInsideBox(box));

            //var x = ConcreteKdTreeList[objectIndex];
            //return x.KdIntersectionTree.IsInsideBox(box.Transformed(x.Trafo.Backward));
        }
Exemplo n.º 4
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.º 5
0
        public bool ClosestPoint(
            int[] objectIndexArray, int firstIndex, int indexCount,
            V3d query,
            Func <IIntersectableObjectSet, int, bool> ios_index_objectFilter,
            Func <IIntersectableObjectSet, int, int, ObjectClosestPoint, bool> ios_index_part_ocp_pointFilter,
            ref ObjectClosestPoint closest
            )
        {
            //throw new NotImplementedException("ClosestPoint not implement for lazykdtree set");

            int kdTreeIndex = -1;

            for (int i = firstIndex, e = firstIndex + indexCount; i < e; i++)
            {
                int index  = objectIndexArray[i];
                var ph     = KdTreePlaceholders[index];
                var kdTree = Load.As <KdIntersectionTree>(ph.Path);
                //  var trafo = x.Trafo;
                //kdTree.KdIntersectionTree.ClosestPoint(trafo.Backward.TransformPos(query), ref closest)

                if (kdTree.ClosestPoint(query, ref closest))
                {
                    kdTreeIndex = index;
                    //closest.Point = trafo.Forward.TransformPos(closest.Point);
                }
            }
            if (kdTreeIndex < 0)
            {
                return(false);
            }

            if (closest.ObjectStack == null)
            {
                closest.ObjectStack = new List <SetObject>();
            }

            closest.ObjectStack.Add(new SetObject(this, kdTreeIndex));
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns OpcPaths with all paths created from a given OPC folder.
        /// This involves Loading of a PatchHierarchyInfo cache from disk. If the cache does not
        /// exist RootPatchName is read from xml.
        /// </summary>
        public static OpcPaths FullPathsFrom(string baseDirectory)
        {
            var paths         = new OpcPaths(baseDirectory);
            var rootPatchName = string.Empty;

            //get RootPatchName from cache file or read from xml
            if (StorageConfig.FileExists(paths.CachedPatchHierarchyPath))
            {
                var info = Load.As <PatchHierarchyInfo>(paths.CachedPatchHierarchyPath);
                rootPatchName = info.RootPatch;
            }
            else
            {
                rootPatchName = PatchHierarchyXML.From(baseDirectory).RootPatchName;
            }

            Requires.NotEmpty(rootPatchName, "RootPatchName could not be retrieved");

            paths.SetRootPatchName(rootPatchName);

            return(paths);
        }
Exemplo n.º 7
0
        /// <summary>
        /// NOT TESTED
        /// </summary>
        private static KdTreeSet BuildConcreteKdTreeSet(IEnumerable <PatchTree> patches, OpcPaths opcPaths,
                                                        int level, PositionsType posType, bool overrideExisting, IObserver <float> progressObserver, CancellationToken cancelToken = default(CancellationToken),
                                                        float maxTriangleSize = float.PositiveInfinity)
        {
            var kdTrees     = new List <ConcreteKdIntersectionTree>();
            var progressInc = 1f / patches.Count();

            foreach (var p in patches)
            {
                cancelToken.ThrowIfCancellationRequested();

                KdIntersectionTree tree;
                var kdtreePath = opcPaths.GetKdTreePath(p.Id, level, posType);
                if (overrideExisting || !StorageConfig.FileExists(kdtreePath))
                {
                    tree = BuildKdTreeForPatch(p.Id, level, p.Info, opcPaths, posType, saveTriangles: true, saveKdTree: false, maxTriangleSize: maxTriangleSize);
                }
                else
                {
                    tree = Load.As <KdIntersectionTree>(kdtreePath);
                }

                kdTrees.Add(tree.ToConcreteKdIntersectionTree());

                if (progressObserver != null)
                {
                    progressObserver.OnNext(progressInc);
                }
            }

            if (progressObserver != null)
            {
                progressObserver.OnCompleted();
            }

            return(new KdTreeSet(kdTrees));
        }