예제 #1
0
 private bool RemoveAnonymousItem(Queue <string> nameParts, U item, bool failQuiet)
 {
     if (nameParts.Count == 0)
     {
         var removed = AnonymousItems.Remove(item);
         if (OnItemRemoved != null)
         {
             OnItemRemoved(null, item);
         }
         return(removed);
     }
     else
     {
         var first = nameParts.Dequeue();
         if (!Subnodes.ContainsKey(first))
         {
             if (failQuiet)
             {
                 return(false);
             }
             throw new UriTreeException(
                       String.Format(
                           "Could not remove item '{0}' from group with full name '{1}'; " +
                           "missing intermediate node with name '{2}'.",
                           item, FullName, first
                           )
                       );
         }
         return(Subnodes[first].RemoveAnonymousItem(nameParts, item, failQuiet));
     }
 }
예제 #2
0
        private void RemoveItem(Queue <string> nameParts, bool failQuiet)
        {
            var first = nameParts.Dequeue();

            if (nameParts.Count == 0)
            {
                if (!Items.ContainsKey(first))
                {
                    if (failQuiet)
                    {
                        return;
                    }
                    throw CouldNotRemoveItem(nameParts);
                }
                var item = Items[first];
                Items.Remove(first);
                if (OnItemRemoved != null)
                {
                    OnItemRemoved(first, item);
                }
            }
            else
            {
                if (!Subnodes.ContainsKey(first))
                {
                    if (failQuiet)
                    {
                        return;
                    }
                    throw CouldNotRemoveItem(nameParts);
                }
                Subnodes[first].RemoveItem(nameParts, failQuiet);
            }
        }
예제 #3
0
 private void AddAnonymousItem(Queue <string> nameParts, U item)
 {
     if (nameParts.Count == 0)
     {
         AnonymousItems.Add(item);
         if (OnItemAdded != null)
         {
             OnItemAdded(null, item);
         }
     }
     else
     {
         var first = nameParts.Dequeue();
         if (!Subnodes.ContainsKey(first))
         {
             throw new UriTreeException(
                       String.Format(
                           "Could not add item '{0}' to group with full name '{1}'; " +
                           "missing intermediate node with name '{2}'. Consider using InsertItem instead.",
                           item, FullName, first
                           )
                       );
         }
         Subnodes[first].AddAnonymousItem(nameParts, item);
     }
 }
예제 #4
0
        internal U GetItem(Queue <string> nameParts, bool useDefault, U defaultVal)
        {
            var first = nameParts.Dequeue();

            if (nameParts.Count > 0 && !Subnodes.ContainsKey(first))
            {
                if (useDefault)
                {
                    return(defaultVal);
                }
                throw CouldNotRetrieveItem(first);
            }
            else if (nameParts.Count == 0)
            {
                if (!Items.ContainsKey(first))
                {
                    if (useDefault)
                    {
                        return(defaultVal);
                    }
                    throw CouldNotRetrieveItem(first);
                }
                return(Items[first]);
            }
            return(Subnodes[first].GetItem(nameParts, useDefault, defaultVal));
        }
예제 #5
0
 /// <summary>
 /// Remove an anonymous item from this group.
 /// </summary>
 /// <param name="item"></param>
 public bool RemoveAnonymousItem(U item, bool searchRecursive = true)
 {
     if (!AnonymousItems.Remove(item) && searchRecursive)
     {
         if (IsLeaf)
         {
             return(false);
         }
         return(Subnodes.Any(kvp => kvp.Value.RemoveAnonymousItem(item, searchRecursive)));
     }
     if (OnItemRemoved != null)
     {
         OnItemRemoved(null, item);
     }
     return(true);
 }
예제 #6
0
        internal AssetGroup(string pathName
                            , SearchOption option
                            , string fileSearchQuery   = "*"
                            , string folderSearchQuery = "*"
                            , bool pruneEmptySubgroups = true)
            : base(Path.GetFileName(pathName))
        {
            // Search for directories to turn into subgroups.
            if (option == SearchOption.AllDirectories)
            {
                var directories = Directory.EnumerateDirectories(
                    pathName, folderSearchQuery, SearchOption.TopDirectoryOnly);

                foreach (var folderName in directories)
                {
                    var subgroup = new AssetGroup(folderName, option, fileSearchQuery, folderSearchQuery);

                    if (subgroup.IsEmpty)
                    {
                        continue;
                    }

                    subgroup.SetParent(this);
                    Subnodes.Add(subgroup.Name, subgroup);
                }
            }
            // Otherwise, option == SearchOption.TopDirectoryOnly, and we only have to look for
            // asset files in the given directory rather than subdirectories as well.

            var files = Directory.EnumerateFiles(
                pathName, fileSearchQuery, SearchOption.TopDirectoryOnly);

            foreach (var fileName in files)
            {
                var assetName = Path.GetFileNameWithoutExtension(
                    DirectoryUtils.MakeRelativePath(
                        AssetLoader.ContentFolderName, fileName));

                Items.Add(assetName, AssetLoader.LoadUsingExtension(fileName));
            }

            if (pruneEmptySubgroups)
            {
                Subnodes = Subnodes.Where(kvp => !kvp.Value.IsEmpty)
                           .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }
        }
예제 #7
0
        private void AddItem(Queue <string> nameParts, U item, bool disallowDuplicates)
        {
            var first = nameParts.Dequeue();

            if (nameParts.Count == 0)
            {
                if (Items.ContainsKey(first))
                {
                    if (disallowDuplicates)
                    {
                        throw new UriTreeException(
                                  String.Format(
                                      "Could not add item '{0}' with name '{1}' to group with full name '{2}', " +
                                      "an item with that name already exists.", item, first, FullName
                                      )
                                  );
                    }
                    Items[first] = item;
                }
                else
                {
                    Items.Add(first, item);
                }
                if (OnItemAdded != null)
                {
                    OnItemAdded(first, item);
                }
            }
            else
            {
                if (!Subnodes.ContainsKey(first))
                {
                    throw new UriTreeException(
                              String.Format(
                                  "Could not add item '{0}' with name '{1}' to group with full name '{2}; " +
                                  "missing intermediate node with name '{3}'. Consider using InsertItem instead.",
                                  item, nameParts, FullName, first
                                  )
                              );
                }
                Subnodes[first].AddItem(nameParts, item, disallowDuplicates);
            }
        }
예제 #8
0
 private void InsertAnonymousItem <NodeType>(Queue <string> nameParts, U item)
     where NodeType : UriTreeMutableGroup <T, U>
 {
     if (nameParts.Count == 0)
     {
         AnonymousItems.Add(item);
         if (OnItemAdded != null)
         {
             OnItemAdded(null, item);
         }
     }
     else
     {
         var first = nameParts.Dequeue();
         if (!Subnodes.ContainsKey(first))
         {
             var newNode = (T)Activator.CreateInstance(typeof(NodeType), first);
             newNode.SetParent((T)this);
         }
         Subnodes[first].InsertAnonymousItem <NodeType>(nameParts, item);
     }
 }
예제 #9
0
        private void InsertItem <NodeType>(Queue <string> nameParts, U item, bool disallowDuplicates)
            where NodeType : UriTreeMutableGroup <T, U>
        {
            var first = nameParts.Dequeue();

            if (nameParts.Count == 1)
            {
                if (Items.ContainsKey(first))
                {
                    if (disallowDuplicates)
                    {
                        throw new UriTreeException(
                                  String.Format(
                                      "Cannot insert item '{0}' with name '{1}' to group with full name '{2}', " +
                                      "an item with that name already exists.", item, first, FullName
                                      )
                                  );
                    }
                    Items[first] = item;
                }
                else
                {
                    Items.Add(first, item);
                }
                if (OnItemAdded != null)
                {
                    OnItemAdded(first, item);
                }
            }
            else
            {
                if (!Subnodes.ContainsKey(first))
                {
                    var newNode = (T)Activator.CreateInstance(typeof(NodeType), first);
                    newNode.SetParent((T)this); // will add to Subnodes automatically.
                }
                Subnodes[first].InsertItem <NodeType>(nameParts, item, disallowDuplicates);
            }
        }
예제 #10
0
        /// <summary></summary>
        public IPointCloudNode Materialize()
        {
            var newId = Guid.NewGuid();
            var data  = ImmutableDictionary <Def, object> .Empty
                        .Add(Octree.NodeId, newId)
                        .Add(Octree.Cell, Cell)
                        .Add(Octree.BoundingBoxExactLocal, BoundingBoxExactLocal)
            ;

            if (IsLeaf)
            {
                data = data.Add(Octree.BoundingBoxExactGlobal, BoundingBoxExactGlobal);
            }
            else
            {
                var subnodes      = Subnodes.Map(x => x?.Value.Materialize());
                var subnodeIds    = subnodes.Map(x => x?.Id ?? Guid.Empty);
                var bbExactGlobal = new Box3d(subnodes.Where(x => x != null).Select(x => x.BoundingBoxExactGlobal));
                data = data
                       .Add(Octree.SubnodesGuids, subnodeIds)
                       .Add(Octree.BoundingBoxExactGlobal, bbExactGlobal)
                ;
            }

            if (HasPositions)
            {
                var id = Guid.NewGuid();
                Storage.Add(id, Positions.Value);
                data = data.Add(Octree.PositionsLocal3fReference, id);
            }

            if (HasKdTree)
            {
                var id = Guid.NewGuid();
                Storage.Add(id, KdTree.Value.Data);
                data = data.Add(Octree.PointRkdTreeFDataReference, id);
            }

            if (HasColors)
            {
                var id = Guid.NewGuid();
                Storage.Add(id, Colors.Value);
                data = data.Add(Octree.Colors4bReference, id);
            }

            if (HasNormals)
            {
                var id = Guid.NewGuid();
                Storage.Add(id, Normals.Value);
                data = data.Add(Octree.Normals3fReference, id);
            }

            if (HasClassifications)
            {
                var id = Guid.NewGuid();
                Storage.Add(id, Classifications.Value);
                data = data.Add(Octree.Classifications1bReference, id);
            }

            if (HasIntensities)
            {
                var id = Guid.NewGuid();
                Storage.Add(id, Intensities.Value);
                data = data.Add(Octree.Intensities1iReference, id);
            }

            var result = new PointSetNode(data, Storage, writeToStore: true);

            return(result);
        }
예제 #11
0
 /// <summary>
 /// Check if this group contains the given item.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool ContainsItem(U item, bool searchRecursive = true)
 {
     return(Items.ContainsValue(item) || (
                searchRecursive ? Subnodes.Any(kvp => kvp.Value.ContainsItem(item)) : false
                ));
 }