1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System.Collections.Generic;
- namespace AIPractice.Shared.Labels
- {
- public enum GroupType
- {
- Image = 0,
- Roi =1,
- All = 2,
- }
- public abstract class LabelGroup : LabelObject
- {
- private RootLabel _root;
- /// <summary>
- /// Gets the group type.
- /// </summary>
- public GroupType Type { get; set; }
- /// <summary>
- /// Gets the labels belongs to this group.
- /// </summary>
- public IReadOnlyList<ImageLabel> Labels { get; }
- /// <summary>
- /// Gets or sets the root of this group
- /// </summary>
- public RootLabel Root
- {
- get => _root;
- set
- {
- if (_root != value)
- {
- _root = value;
- foreach(var label in Labels)
- {
- label.Root = _root;
- }
- }
- }
- }
- protected LabelGroup(string id, string title, GroupType type, IEnumerable<ImageLabel> labels) : base(id, title)
- {
- Type = type;
- var list = new List<ImageLabel>(labels);
- Labels = list;
- }
- /// <summary>
- /// Add one label into the group.
- /// </summary>
- /// <param name="label">The label to be added. and the root label will be assigned to the label.</param>
- public void AddLabel(ImageLabel label)
- {
- var labelList = (List<ImageLabel>)Labels;
- if(!labelList.Contains(label))
- {
- labelList.Add(label);
- label.Root = _root;
- }
- }
- /// <summary>
- /// Remove the lable from the group.
- /// </summary>
- /// <param name="label">The label to be removed.</param>
- public void RemoveLabel(ImageLabel label)
- {
- var labelList = (List<ImageLabel>)Labels;
- if(labelList.Contains(label))
- {
- labelList.Remove(label);
- }
- }
- /// <summary>
- /// Insert one label into the group on given index.
- /// </summary>
- /// <param name="index">The index to be insert.</param>
- /// <param name="label">The label to be added. and the root label will be assigned to the label.</param>
- public void InsertLabel(int index, ImageLabel label)
- {
- var labelList = (List<ImageLabel>)Labels;
- if (!labelList.Contains(label))
- {
- labelList.Insert(index,label);
- label.Root = _root;
- }
- }
- }
- }
|