private AnnoList ConvertDiscreteAnnoListToContinuousList(AnnoList annolist, double chunksize, double end, string restclass = "Rest") { AnnoList result = new AnnoList(); result.Scheme = annolist.Scheme; result.Meta = annolist.Meta; double currentpos = 0; bool foundlabel = false; while (currentpos < end) { foundlabel = false; foreach (AnnoListItem orgitem in annolist) { if (orgitem.Start * 1000 < currentpos && orgitem.Stop * 1000 > currentpos) { AnnoListItem ali = new AnnoListItem(currentpos, chunksize, orgitem.Label); result.Add(ali); foundlabel = true; break; } } if (foundlabel == false) { AnnoListItem ali = new AnnoListItem(currentpos, chunksize, restclass); result.Add(ali); } currentpos = currentpos + chunksize; } return(result); }
void OnMediaMouseDown(IMedia media, double x, double y) { if (Mouse.LeftButton == MouseButtonState.Pressed) { if (AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.POINT && control.annoListControl.annoDataGrid.SelectedItem != null && control.geometricListControl.geometricDataGrid.SelectedItem != null) { AnnoListItem item = (AnnoListItem)control.annoListControl.annoDataGrid.SelectedItem; if (control.geometricListControl.geometricDataGrid.SelectedItems.Count > 1) { return; } PointListItem point = (PointListItem)control.geometricListControl.geometricDataGrid.SelectedItem; point.XCoord = x; point.YCoord = y; geometricTableUpdate(); int pos = control.annoListControl.annoDataGrid.SelectedIndex; geometricOverlayUpdate(item, AnnoScheme.TYPE.POINT, pos); } } if (Mouse.RightButton == MouseButtonState.Pressed) { RightHeldPos = new double[] { x, y }; RightHeld = true; } }
void OnMediaMouseMove(IMedia media, double x, double y) { if (RightHeld) { if (AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.POINT && control.annoListControl.annoDataGrid.SelectedItem != null && control.geometricListControl.geometricDataGrid.SelectedItem != null) { double deltaX = x - RightHeldPos[0]; double deltaY = y - RightHeldPos[1]; RightHeldPos = new double[] { x, y }; AnnoListItem item = (AnnoListItem)control.annoListControl.annoDataGrid.SelectedItem; foreach (PointListItem pli in control.geometricListControl.geometricDataGrid.SelectedItems) { pli.XCoord += deltaX; pli.YCoord += deltaY; } geometricTableUpdate(); int pos = control.annoListControl.annoDataGrid.SelectedIndex; geometricOverlayUpdate(item, AnnoScheme.TYPE.POINT, pos); } } }
private void geometricListCopy_Click(object sender, RoutedEventArgs e) { if (control.annoListControl.annoDataGrid.SelectedItems.Count == 1) { if (control.geometricListControl.geometricDataGrid.Items[0].GetType().Name == "PointListItem") { AnnoListItem item = (AnnoListItem)control.annoListControl.annoDataGrid.SelectedItems[0]; AnnoList list = (AnnoList)control.annoListControl.annoDataGrid.ItemsSource; for (int i = 0; i < list.Count; ++i) { if (Math.Round(list[i].Start, 2) == Math.Round(item.Stop, 2)) { for (int j = 0; j < list[i].Points.Count; ++j) { list[i].Points[j].Label = item.Points[j].Label; list[i].Points[j].XCoord = item.Points[j].XCoord; list[i].Points[j].YCoord = item.Points[j].YCoord; } break; } } } } else { MessageBoxResult mb = MessageBoxResult.OK; mb = MessageBox.Show("Select one frame to copy", "Confirm", MessageBoxButton.OK, MessageBoxImage.Information); } }
private void MenuItemDeleteClick(object sender, RoutedEventArgs e) { if (AnnoTierStatic.Selected.IsDiscreteOrFree) { if (annoDataGrid.SelectedItems.Count > 0) { AnnoListItem[] selected = new AnnoListItem[annoDataGrid.SelectedItems.Count]; annoDataGrid.SelectedItems.CopyTo(selected, 0); annoDataGrid.SelectedIndex = -1; AnnoTier track = AnnoTierStatic.Selected; foreach (AnnoListItem s in selected) { AnnoTierSegment segment = track.GetSegment(s); if (segment != null) { track.RemoveSegment(segment); } } } } else if (AnnoTierStatic.Selected.IsContinuous) { AnnoListItem[] selected = new AnnoListItem[annoDataGrid.SelectedItems.Count]; annoDataGrid.SelectedItems.CopyTo(selected, 0); annoDataGrid.SelectedIndex = -1; foreach (AnnoListItem s in selected) { s.Score = double.NaN; } AnnoTier.Selected.TimeRangeChanged(MainHandler.Time); } }
private void geometricSelectItem(AnnoListItem item, int pos) { if (item.Points != null && item.Points.Count > 0) { setPointList(item.Points); geometricOverlayUpdate(item, AnnoScheme.TYPE.POINT, pos); } }
private void PlayTimer_Tick(object sender, EventArgs e) { int elapsed = (int)((Environment.TickCount - playLastTick) * PlayerSpeed); Time.CurrentPlayPosition += elapsed / 1000.0; playLastTick = Environment.TickCount; if (Time.CurrentPlayPosition >= timeline.TotalDuration) { Stop(); } else { if (Time.CurrentPlayPosition >= Time.SelectionStop && control.navigator.autoScrollCheckBox.IsChecked == true) { double factor = (((Time.CurrentPlayPosition - Time.SelectionStart) / (Time.SelectionStop - Time.SelectionStart))); control.timeLineControl.rangeSlider.followmedia = true; control.timeLineControl.rangeSlider.MoveAndUpdate(true, factor); } else if (Time.CurrentPlayPosition >= Time.SelectionStop && control.navigator.autoScrollCheckBox.IsChecked == false) { control.timeLineControl.rangeSlider.followmedia = false; if (AnnoTierStatic.Label != null) { AnnoTierStatic.Label.select(true); } Stop(); } } foreach (IMedia media in mediaList) { if (media.GetMediaType() != MediaType.AUDIO && media.GetMediaType() != MediaType.VIDEO) { media.Move(Time.CurrentPlayPosition); } } updatePositionLabels(Time.CurrentPlayPosition); signalCursor.X = Time.PixelFromTime(Time.CurrentPlayPosition); if (AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.IsGeometric) { control.annoListControl.annoDataGrid.SelectedItems.Clear(); int position = (int)(Time.CurrentPlayPosition * AnnoTierStatic.Selected.AnnoList.Scheme.SampleRate); if (position < control.annoListControl.annoDataGrid.Items.Count) { AnnoListItem ali = (AnnoListItem)control.annoListControl.annoDataGrid.Items[position]; if (ali.Points.Count > 0) { geometricOverlayUpdate(ali, AnnoScheme.TYPE.POINT, position); } } } }
public void Redo(int level) { for (int i = 1; i <= level; i++) { if (_RedoActionsCollection.Count == 0) { return; } ChangeRepresentationObject Undostruct = _RedoActionsCollection.Pop(); if (Undostruct.Action == ActionType.Delete) { ((AnnoTier)Container).deleteSegment((AnnoTierLabel)Undostruct.UiElement); ChangeRepresentationObject ChangeRepresentationObjectForDelete = this.MakeChangeRepresentationObjectForDelete(Undostruct.UiElement); _UndoActionsCollection.Push(ChangeRepresentationObjectForDelete); } else if (Undostruct.Action == ActionType.Insert) { AnnoListItem ali = ((AnnoTierLabel)Undostruct.UiElement).Item; ((AnnoTier)Container).AnnoList.AddSorted(ali); AnnoTierLabel at = ((AnnoTier)Container).addSegment(ali); ChangeRepresentationObject ChangeRepresentationObjectForInsert = this.MakeChangeRepresentationObjectForInsert(at); _UndoActionsCollection.Push(ChangeRepresentationObjectForInsert); } else if (Undostruct.Action == ActionType.Resize) { Canvas.SetLeft(Undostruct.UiElement, Undostruct.Margin.X); Undostruct.UiElement.Width = Undostruct.Width; Undostruct.Start = ((AnnoTierLabel)Undostruct.UiElement).Item.Start; Undostruct.Stop = ((AnnoTierLabel)Undostruct.UiElement).Item.Stop; Undostruct.Duration = ((AnnoTierLabel)Undostruct.UiElement).Item.Duration; ChangeRepresentationObject ChangeRepresentationObjectForResize = this.MakeChangeRepresentationObjectForResize(Undostruct.Margin.X, Undostruct.UiElement); _UndoActionsCollection.Push(ChangeRepresentationObjectForResize); } else if (Undostruct.Action == ActionType.Move) { Canvas.SetLeft(Undostruct.UiElement, Undostruct.Margin.X); Undostruct.UiElement.Width = Undostruct.Width; Undostruct.Start = ((AnnoTierLabel)Undostruct.UiElement).Item.Start; Undostruct.Stop = ((AnnoTierLabel)Undostruct.UiElement).Item.Stop; Undostruct.Duration = ((AnnoTierLabel)Undostruct.UiElement).Item.Duration; ChangeRepresentationObject ChangeRepresentationObjectForMove = this.MakeChangeRepresentationObjectForMove(Undostruct.Margin.X, Undostruct.UiElement); _UndoActionsCollection.Push(ChangeRepresentationObjectForMove); } } if (EnableDisableUndoRedoFeature != null) { EnableDisableUndoRedoFeature(null, null); } }
private void ShowLabelBoxContinuous() { if (AnnoTierStatic.Selected != null) { double start = MainHandler.Time.TimeFromPixel(MainHandler.Time.CurrentSelectPosition); double stop = MainHandler.Time.CurrentPlayPosition; if (start > stop) { double temp = start; start = stop; stop = temp; } AnnoListItem newItem = new AnnoListItem(start, stop - start, double.NaN); AnnoTierNewLabelWindow dialog = new AnnoTierNewLabelWindow(AnnoTierStatic.Selected.AnnoList.Scheme, newItem); dialog.ShowDialog(); double value = dialog.Result.Score; double confidence = dialog.Result.Confidence; bool success = false; if (dialog.DialogResult == true) { if (value >= AnnoTierStatic.Selected.AnnoList.Scheme.MinScore && value <= AnnoTierStatic.Selected.AnnoList.Scheme.MaxScore || double.IsNaN(value)) { success = true; foreach (AnnoListItem ali in AnnoTierStatic.Selected.AnnoList) { if (ali.Start >= start && ali.Stop <= stop) { if (!double.IsNaN(value)) { ali.Score = value; } ali.Confidence = confidence; } } } } if (!success) { MessageBox.Show("Value must be a number in range [" + AnnoTierStatic.Selected.AnnoList.Scheme.MinScore + "..." + AnnoTierStatic.Selected.AnnoList.Scheme.MaxScore + "]"); } else { AnnoTierStatic.Selected.TimeRangeChanged(timeline); AnnoTierStatic.Selected.TimeRangeChanged(timeline); } } }
private AnnoList ResampleContinuousList(AnnoList annolist, double targetsr) { double sr = annolist.Scheme.SampleRate; if (sr == targetsr) { return(annolist); } AnnoList result = new AnnoList(); result.Scheme = annolist.Scheme; result.Meta = annolist.Meta; //upsample if (sr < targetsr) { double factor = targetsr / sr; double round = Math.Round(factor); if (factor - round == 0) { for (int i = 0; i < annolist.Count; i++) { for (int j = 0; j < round; j++) { AnnoListItem ali = new AnnoListItem(annolist[i].Start + j * (1.0 / round), (1.0 / round), annolist[i].Score); result.Add(ali); } } } else { return(null); } } //downsample else if (sr > targetsr) { double factor = sr / targetsr; double round = Math.Round(factor); for (int i = 0; i < annolist.Count; i = i + (int)round) { result.Add(annolist[i]); } } return(result); }
private void CopyLabelToTier(bool down = true) { if (down) { if (AnnoTierStatic.Label != null) { AnnoListItem temp = AnnoTierStatic.Label.Item; for (int i = 0; i < annoTiers.Count; i++) { if (annoTiers[i] == AnnoTierStatic.Selected && i + 1 < annoTiers.Count) { AnnoTierStatic.Select(annoTiers[i + 1]); if (AnnoTierStatic.Selected.IsDiscreteOrFree) { AnnoTier.SelectLabel(null); if (!AnnoTierStatic.Selected.AnnoList.Contains(temp)) { AnnoTierStatic.Selected.NewAnnoCopy(temp.Start, temp.Stop, temp.Label, temp.Color); break; } } } } } } else { if (AnnoTierStatic.Label != null) { AnnoListItem temp = AnnoTierStatic.Label.Item; for (int i = 0; i < annoTiers.Count; i++) { if (annoTiers[i] == AnnoTierStatic.Selected && i > 0) { AnnoTierStatic.Select(annoTiers[i - 1]); if (AnnoTierStatic.Selected.IsDiscreteOrFree) { AnnoTierStatic.SelectLabel(null); if (!AnnoTierStatic.Selected.AnnoList.Contains(temp)) { AnnoTierStatic.Selected.NewAnnoCopy(temp.Start, temp.Stop, temp.Label, temp.Color); break; } } } } } } }
private void geometricList_Selection(object sender, SelectionChangedEventArgs e) { if (control.annoListControl.annoDataGrid.SelectedItem != null) { AnnoListItem item = (AnnoListItem)control.annoListControl.annoDataGrid.SelectedItem; int pos = control.annoListControl.annoDataGrid.SelectedIndex; geometricOverlayUpdate(item, AnnoScheme.TYPE.POINT, pos); } if (control.geometricListControl.geometricDataGrid.SelectedItems.Count == 1) { PointListItem item = (PointListItem)control.geometricListControl.geometricDataGrid.SelectedItems[0]; control.geometricListControl.editTextBox.Text = item.Label; } }
private void geometricListDelete(object sender, RoutedEventArgs e) { if (control.geometricListControl.geometricDataGrid.SelectedItems.Count != 0 && control.annoListControl.annoDataGrid.SelectedItem != null) { AnnoListItem item = (AnnoListItem)control.annoListControl.annoDataGrid.SelectedItem; foreach (PointListItem point in control.geometricListControl.geometricDataGrid.SelectedItems) { point.XCoord = -1; point.YCoord = -1; } geometricTableUpdate(); int pos = control.annoListControl.annoDataGrid.SelectedIndex; geometricOverlayUpdate(item, AnnoScheme.TYPE.POINT, pos); } }
public AnnoTierNewLabelWindow(AnnoScheme scheme, AnnoListItem item) { InitializeComponent(); discreteSchemeGrid.Visibility = Visibility.Collapsed; continuousSchemeGrid.Visibility = Visibility.Collapsed; freeSchemeGrid.Visibility = Visibility.Collapsed; Result = item; this.scheme = scheme; confidenceSlider.Value = item.Confidence; colorPicker.SelectedColor = item.Color; switch (scheme.Type) { case AnnoScheme.TYPE.CONTINUOUS: if (!double.IsNaN(item.Score)) { scoreTextBox.Text = item.Score.ToString(); } else { scoreTextBox.Text = ""; } infoLabel.Text = "Edit continuous label"; continuousSchemeGrid.Visibility = Visibility.Visible; break; case AnnoScheme.TYPE.DISCRETE: infoLabel.Text = "Edit discrete label"; discreteSchemeGrid.Visibility = Visibility.Visible; foreach (AnnoScheme.Label label in scheme.Labels) { labelComboBox.Items.Add(label.Name); } labelComboBox.SelectedItem = item.Label; break; case AnnoScheme.TYPE.FREE: infoLabel.Text = "Edit free label"; freeSchemeGrid.Visibility = Visibility.Visible; labelTextBox.Text = item.Label; break; } }
public void play(AnnoListItem item, bool loop) { if (medias.Count > 0) { this.play_item = item; this.play_loop = loop; this.timer.Start(); foreach (IMedia v in medias) { //v.Position = TimeSpan.FromSeconds(item.Start); //v.MediaPosition = (long) (item.Start * 1000.0); v.Move(item.Start); v.Play(); } isPlaying = true; } }
public void geometricOverlayUpdate(AnnoListItem item, AnnoScheme.TYPE type, int pos = -1) { WriteableBitmap overlay = null; IMedia video = mediaList.GetFirstVideo(); if (video != null) { overlay = video.GetOverlay(); } else { return; } overlay.Lock(); overlay.Clear(); switch (type) { case AnnoScheme.TYPE.POINT: foreach (PointListItem p in item.Points) { if (p.XCoord != -1 && p.YCoord != -1) { Color color = item.Color; //color.A = 128; overlay.FillEllipseCentered((int)p.XCoord, (int)p.YCoord, 1, 1, color); } } break; case AnnoScheme.TYPE.POLYGON: break; case AnnoScheme.TYPE.GRAPH: break; case AnnoScheme.TYPE.SEGMENTATION: break; } overlay.Unlock(); }
private void annoList_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListView grid = (ListView)sender; if (grid.SelectedIndex >= 0 && grid.SelectedIndex < grid.Items.Count) { AnnoListItem item = (AnnoListItem)grid.SelectedItem; control.annoListControl.editComboBox.SelectedItem = item.Label; double samplerate = MainHandler.getMaxVideoSampleRate(); double offset = (1.0f / samplerate); Time.CurrentPlayPosition = item.Start; mediaList.Move(item.Start + offset); moveSignalCursor(item.Start); if (item.Start >= timeline.SelectionStop) { float factor = (float)(((item.Start - Time.SelectionStart) / (Time.SelectionStop - Time.SelectionStart))); control.timeLineControl.rangeSlider.MoveAndUpdate(true, factor); } else if (item.Stop <= timeline.SelectionStart) { float factor = (float)(((Time.SelectionStart - item.Start)) / (Time.SelectionStop - Time.SelectionStart)); control.timeLineControl.rangeSlider.MoveAndUpdate(false, factor); } foreach (AnnoListItem a in AnnoTierStatic.Selected.AnnoList) { if (a.Start == item.Start && a.Stop == item.Stop && item.Label == a.Label) { AnnoTierStatic.SelectLabel(AnnoTierStatic.Selected.GetSegment(a)); control.annoListControl.editComboBox.SelectedItem = item.Label; break; } } if (item.isGeometric) { int position = (int)(Time.CurrentPlayPosition * AnnoTierStatic.Selected.AnnoList.Scheme.SampleRate); geometricSelectItem(item, position); } } }
private void annoList_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListView grid = (ListView)sender; if (grid.SelectedIndex >= 0 && grid.SelectedIndex < grid.Items.Count) { AnnoListItem item = (AnnoListItem)grid.SelectedItem; control.annoListControl.editComboBox.SelectedItem = item.Label; movemedialock = true; Time.CurrentPlayPosition = item.Start; Time.CurrentPlayPositionPrecise = item.Start; mediaList.move(item.Start); moveSignalCursorToSecond(item.Start); if (item.Start >= timeline.SelectionStop) { float factor = (float)(((item.Start - Time.SelectionStart) / (Time.SelectionStop - Time.SelectionStart))); control.timeLineControl.rangeSlider.MoveAndUpdate(true, factor); } else if (item.Stop <= timeline.SelectionStart) { float factor = (float)(((Time.SelectionStart - item.Start)) / (Time.SelectionStop - Time.SelectionStart)); control.timeLineControl.rangeSlider.MoveAndUpdate(false, factor); } foreach (AnnoListItem a in AnnoTierStatic.Selected.AnnoList) { if (a.Start == item.Start && a.Stop == item.Stop && item.Label == a.Label) { AnnoTier.SelectLabel(AnnoTierStatic.Selected.getSegment(a)); control.annoListControl.editComboBox.SelectedItem = item.Label; control.annoListControl.editTextBox.Text = item.Label; break; } } movemedialock = false; } }
public AnnoTierSegment(AnnoListItem item, AnnoTier tier) { this.tier = tier; this.item = item; this.isSelected = false; this.isResizeableLeft = false; this.isResizeableRight = false; this.isMoveable = false; this.Inlines.Add(item.Label == null ? "" : item.Label); this.FontSize = 12; this.TextWrapping = TextWrapping.Wrap; if (item.Color != null) { Background = new SolidColorBrush(item.Color); } this.Foreground = Brushes.White; this.Opacity = 0.75; this.TextAlignment = TextAlignment.Center; this.TextTrimming = TextTrimming.WordEllipsis; ToolTip tt = new ToolTip(); tt.Background = Brushes.Black; tt.Foreground = Brushes.White; if (item.Meta == null || item.Meta.ToString() == "") { tt.Content = item.Label; } else { tt.Content = item.Label + "\n\n" + item.Meta.Replace(";", "\n"); } tt.StaysOpen = true; this.ToolTip = tt; item.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(item_PropertyChanged); update(); }
private void RemoveSegment(object sender, KeyEventArgs e) { if (AnnoTier.Selected != null && AnnoTier.Selected.IsDiscreteOrFree) { if (AnnoTierStatic.Label != null) { AnnoTierStatic.RemoveSegmentPressed(sender, e); } } else if (AnnoTier.Selected != null && AnnoTier.Selected.IsContinuous) { AnnoListItem[] selected = new AnnoListItem[control.annoListControl.annoDataGrid.SelectedItems.Count]; control.annoListControl.annoDataGrid.SelectedItems.CopyTo(selected, 0); control.annoListControl.annoDataGrid.SelectedIndex = -1; foreach (AnnoListItem s in selected) { s.Score = double.NaN; } AnnoTier.Selected.TimeRangeChanged(MainHandler.Time); } }
private void MenuItemDeleteClick(object sender, RoutedEventArgs e) { if (AnnoTierStatic.Selected.isDiscreteOrFree) { if (annoDataGrid.SelectedItems.Count > 0) { AnnoListItem[] selected = new AnnoListItem[annoDataGrid.SelectedItems.Count]; annoDataGrid.SelectedItems.CopyTo(selected, 0); annoDataGrid.SelectedIndex = -1; AnnoTier track = AnnoTierStatic.Selected; foreach (AnnoListItem s in selected) { AnnoTierLabel segment = track.getSegment(s); if (segment != null) { track.remSegment(segment); } } } } }
public AnnoList ExportToAnno() { AnnoList annoList = new AnnoList(); annoList.Scheme = new AnnoScheme(); annoList.Scheme.Type = AnnoScheme.TYPE.CONTINUOUS; annoList.Scheme.MinScore = min[ShowDim]; annoList.Scheme.MaxScore = max[ShowDim]; annoList.Scheme.SampleRate = rate; AnnoListItem annoListItem; double dur = 1 / rate; for (int i = 0; i < number; i++) { annoListItem = new AnnoListItem(i * dur, dur, data[i * dim + ShowDim].ToString(), "", annoList.Scheme.MaxOrForeColor); annoList.Add(annoListItem); annoList.Scheme.Name = Name; } return(annoList); }
public void Play() { Stop(); double pos = 0; AnnoListItem item = null; bool loop = false; AnnoTierLabel selected = AnnoTierStatic.Label; if (selected != null) { item = selected.Item; signalCursor.X = Time.PixelFromTime(item.Start); loop = true; } else { pos = signalCursor.X; double from = MainHandler.Time.TimeFromPixel(pos); double to = MainHandler.timeline.TotalDuration; item = new AnnoListItem(from, to, ""); signalCursor.X = pos; } try { mediaList.play(item, loop); control.navigator.playButton.Content = "II"; } catch (Exception e) { System.Console.WriteLine(e.ToString()); } // }
public static List <AnnoList> LoadFromDatabase(System.Collections.IList collections, string databaseName, string sessionName, string userName) { MongoClient mongo = new MongoClient(ServerConnectionString); IMongoDatabase database = mongo.GetDatabase(databaseName); var collection = database.GetCollection <BsonDocument>(DatabaseDefinitionCollections.Annotations); var roles = database.GetCollection <BsonDocument>(DatabaseDefinitionCollections.Roles); var annoSchemes = database.GetCollection <BsonDocument>(DatabaseDefinitionCollections.Schemes); List <AnnoList> annoLists = new List <AnnoList>(); foreach (DatabaseAnno anno in collections) { BsonElement value; AnnoList annoList = new AnnoList(); ObjectId roleid = GetObjectID(database, DatabaseDefinitionCollections.Roles, "name", anno.Role); string roledb = FetchDBRef(database, DatabaseDefinitionCollections.Roles, "name", roleid); ObjectId annoSchemeId = GetObjectID(database, DatabaseDefinitionCollections.Schemes, "name", anno.AnnoScheme); string annotdb = FetchDBRef(database, DatabaseDefinitionCollections.Schemes, "name", annoSchemeId); ObjectId annotatorId = GetObjectID(database, DatabaseDefinitionCollections.Annotators, "fullname", anno.AnnotatorFullname); string annotatdb = FetchDBRef(database, DatabaseDefinitionCollections.Annotators, "name", annotatorId); string annotatdbfn = FetchDBRef(database, DatabaseDefinitionCollections.Annotators, "fullname", annotatorId); annoList.Meta.Annotator = annotatdb; annoList.Meta.AnnotatorFullName = annotatdbfn; ObjectId sessionid = GetObjectID(database, DatabaseDefinitionCollections.Sessions, "name", sessionName); string sessiondb = FetchDBRef(database, DatabaseDefinitionCollections.Sessions, "name", sessionid); var builder = Builders <BsonDocument> .Filter; var filterscheme = builder.Eq("_id", annoSchemeId); var result = collection.Find(filterscheme); var annosch = annoSchemes.Find(filterscheme).Single(); var filter = builder.Eq("role_id", roleid) & builder.Eq("scheme_id", annoSchemeId) & builder.Eq("annotator_id", annotatorId) & builder.Eq("session_id", sessionid); var documents = collection.Find(filter).ToList(); annoList.Scheme = new AnnoScheme(); if (annosch.TryGetElement("type", out value) && annosch["type"].ToString() == AnnoScheme.TYPE.DISCRETE.ToString()) { annoList.Scheme.Type = AnnoScheme.TYPE.DISCRETE; } else if (annosch.TryGetElement("type", out value) && annosch["type"].ToString() == AnnoScheme.TYPE.FREE.ToString()) { annoList.Scheme.Type = AnnoScheme.TYPE.FREE; } else if (annosch.TryGetElement("type", out value) && annosch["type"].ToString() == AnnoScheme.TYPE.CONTINUOUS.ToString()) { annoList.Scheme.Type = AnnoScheme.TYPE.CONTINUOUS; } annoList.Meta.Role = roledb; annoList.Scheme.Name = annosch["name"].ToString(); var labels = documents[0]["labels"].AsBsonArray; if (annoList.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { if (annosch.TryGetElement("min", out value)) { annoList.Scheme.MinScore = double.Parse(annosch["min"].ToString()); } if (annosch.TryGetElement("max", out value)) { annoList.Scheme.MaxScore = double.Parse(annosch["max"].ToString()); } if (annosch.TryGetElement("sr", out value)) { annoList.Scheme.SampleRate = double.Parse(annosch["sr"].ToString()); } if (annosch.TryGetElement("min_color", out value)) { annoList.Scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(annosch["min_color"].ToString()); } if (annosch.TryGetElement("max_color", out value)) { annoList.Scheme.MaxOrForeColor = (Color)ColorConverter.ConvertFromString(annosch["max_color"].ToString()); } annoList.Scheme.MinScore = annoList.Scheme.MinScore; annoList.Scheme.MaxScore = annoList.Scheme.MaxScore; annoList.Scheme.SampleRate = annoList.Scheme.SampleRate; for (int i = 0; i < labels.Count; i++) { string label = labels[i]["score"].ToString(); string confidence = labels[i]["conf"].ToString(); double start = i * ((1000.0 / annoList.Scheme.SampleRate) / 1000.0); double dur = (1000.0 / annoList.Scheme.SampleRate) / 1000.0; AnnoListItem ali = new AnnoListItem(start, dur, label, "", Colors.Black, double.Parse(confidence)); annoList.Add(ali); } } else if (annoList.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { annoList.Scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(annosch["color"].ToString()); annoList.Scheme.Labels = new List <AnnoScheme.Label>(); BsonArray schemelabels = annosch["labels"].AsBsonArray; for (int j = 0; j < schemelabels.Count; j++) { //in case flag is set, if not ignore isValid try { if (schemelabels[j]["isValid"].AsBoolean == true) { annoList.Scheme.Labels.Add(new AnnoScheme.Label(schemelabels[j]["name"].ToString(), (Color)ColorConverter.ConvertFromString(schemelabels[j]["color"].ToString()))); } } catch { annoList.Scheme.Labels.Add(new AnnoScheme.Label(schemelabels[j]["name"].ToString(), (Color)ColorConverter.ConvertFromString(schemelabels[j]["color"].ToString()))); } } annoList.Scheme.Labels.Add(new AnnoScheme.Label(GARBAGELABEL, GARBAGECOLOR)); for (int i = 0; i < labels.Count; i++) { string SchemeLabel = ""; Color SchemeColor = Colors.Black; bool idfound = false; for (int j = 0; j < schemelabels.Count; j++) { if (labels[i]["id"].AsInt32 == schemelabels[j]["id"].AsInt32) { SchemeLabel = schemelabels[j]["name"].ToString(); SchemeColor = (Color)ColorConverter.ConvertFromString(schemelabels[j]["color"].ToString()); idfound = true; break; } } if (labels[i]["id"].AsInt32 == -1 || idfound == false) { SchemeLabel = GARBAGELABEL; SchemeColor = GARBAGECOLOR; } double start = double.Parse(labels[i]["from"].ToString()); double stop = double.Parse(labels[i]["to"].ToString()); double duration = stop - start; string label = SchemeLabel; string confidence = labels[i]["conf"].ToString(); AnnoListItem ali = new AnnoListItem(start, duration, label, "", SchemeColor, double.Parse(confidence)); annoList.AddSorted(ali); } } else if (annoList.Scheme.Type == AnnoScheme.TYPE.FREE) { annoList.Scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(annosch["color"].ToString()); for (int i = 0; i < labels.Count; i++) { double start = double.Parse(labels[i]["from"].ToString()); double stop = double.Parse(labels[i]["to"].ToString()); double duration = stop - start; string label = labels[i]["name"].ToString(); string confidence = labels[i]["conf"].ToString(); AnnoListItem ali = new AnnoListItem(start, duration, label, "", Colors.Black, double.Parse(confidence)); annoList.AddSorted(ali); } } annoList.Source.Database.OID = anno.Id; annoLists.Add(annoList); annoList = null; } return(annoLists); }
private void ExportAnnoContinuousToDiscrete() { if (AnnoTierStatic.Selected != null && !AnnoTierStatic.Selected.IsDiscreteOrFree) { Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>(); input["labels"] = new UserInputWindow.Input() { Label = "Class labels (separated by ;)", DefaultValue = Properties.Settings.Default.ConvertToDiscreteClasses }; input["thresholds"] = new UserInputWindow.Input() { Label = "Upper thresholds (separated by ;)", DefaultValue = Properties.Settings.Default.ConvertToDiscreteThreshs }; input["offset"] = new UserInputWindow.Input() { Label = "Optional offset (s)", DefaultValue = Properties.Settings.Default.ConvertToDiscreteDelays }; UserInputWindow dialog = new UserInputWindow("Convert to discrete annotation", input); dialog.ShowDialog(); List <string> classes = new List <string>(); List <double> upperThresholds = new List <double>(); double offset = 0.0; if (dialog.DialogResult == true) { Properties.Settings.Default.ConvertToDiscreteClasses = dialog.Result("labels"); Properties.Settings.Default.ConvertToDiscreteThreshs = dialog.Result("thresholds"); Properties.Settings.Default.ConvertToDiscreteDelays = dialog.Result("offset"); Properties.Settings.Default.Save(); string[] labels = dialog.Result("labels").Split(';'); for (int i = 0; i < labels.Length; i++) { classes.Add(labels[i]); } string[] thresholds = dialog.Result("thresholds").Split(';'); for (int i = 0; i < thresholds.Length; i++) { double thresh = -1; double.TryParse(thresholds[i], out thresh); if (thresh > -1) { upperThresholds.Add(thresh); } else { MessageTools.Warning("Could not parse input"); } } if (thresholds.Length == labels.Length - 1) { upperThresholds.Add(1.0); } else if (thresholds.Length == labels.Length + 1) { classes.Add("REST"); } else if (thresholds.Length != labels.Length) { MessageBox.Show("Number of labels does not match number of threshholds"); } double.TryParse(dialog.Result("offset"), out offset); } Mouse.SetCursor(Cursors.No); AnnoList discretevalues = new AnnoList(); discretevalues.Scheme = new AnnoScheme(); discretevalues.Scheme.Type = AnnoScheme.TYPE.DISCRETE; discretevalues.Meta.Role = AnnoTier.Selected.AnnoList.Meta.Role; discretevalues.Meta.Annotator = AnnoTier.Selected.AnnoList.Meta.Annotator; discretevalues.Scheme.Name = AnnoTier.Selected.AnnoList.Scheme.Name; foreach (string label in classes) { AnnoScheme.Label item = new AnnoScheme.Label(label, System.Windows.Media.Colors.Black); discretevalues.Scheme.Labels.Add(item); } AnnoScheme.Label garbage = new AnnoScheme.Label("GARBAGE", Colors.Black); discretevalues.Scheme.Labels.Add(garbage); double lowThres = -Double.MaxValue; double highThres = 1.0; foreach (AnnoListItem ali in AnnoTierStatic.Selected.AnnoList) { double val = ali.Score; for (int i = 0; i < classes.Count; i++) { highThres = upperThresholds[i]; if (i > 0) { lowThres = upperThresholds[i - 1]; } else { lowThres = -Double.MaxValue; } if (val > lowThres && val <= highThres) { if (!(discretevalues.Count > 0 && discretevalues[discretevalues.Count - 1].Label == classes[i])) { AnnoListItem newItem = new AnnoListItem(ali.Start + offset, ali.Duration, classes[i], "", discretevalues.Scheme.GetColorForLabel(classes[i])); if (newItem.Start < 0.0) { newItem.Duration = ali.Duration + offset + newItem.Start; newItem.Start = 0.0; newItem.Stop = newItem.Duration; } if (newItem.Duration > 0.0) { discretevalues.Add(newItem); } } else { discretevalues[discretevalues.Count - 1].Stop = discretevalues[discretevalues.Count - 1].Stop + ali.Duration; } break; } } } AnnoTier.Unselect(); addAnnoTierFromList(discretevalues); Mouse.SetCursor(System.Windows.Input.Cursors.Arrow); } else { MessageBox.Show("Tier is already discrete"); } }
public static AnnoList LoadfromFile(string filepath) { AnnoList list = new AnnoList(); list.Source.File.Path = filepath; list.Scheme = new AnnoScheme(); list.Scheme.Labels = new List <AnnoScheme.Label>(); try { XmlDocument doc = new XmlDocument(); doc.Load(filepath); XmlNode annotation = doc.SelectSingleNode("annotation"); XmlNode info = annotation.SelectSingleNode("info"); list.Source.File.Type = info.Attributes["ftype"].Value == AnnoSource.FileSource.TYPE.ASCII.ToString() ? AnnoSource.FileSource.TYPE.ASCII : AnnoSource.FileSource.TYPE.BINARY; int size = int.Parse(info.Attributes["size"].Value); XmlNode meta = annotation.SelectSingleNode("meta"); if (meta != null) { if (meta.Attributes["role"] != null) { list.Meta.Role = meta.Attributes["role"].Value; } if (meta.Attributes["annotator"] != null) { list.Meta.Annotator = meta.Attributes["annotator"].Value; } } XmlNode scheme = annotation.SelectSingleNode("scheme"); if (scheme.Attributes["name"] != null) { list.Scheme.Name = scheme.Attributes["name"].Value; } string type = "FREE"; if (scheme.Attributes["type"] != null) { type = scheme.Attributes["type"].Value; } if (type == AnnoScheme.TYPE.DISCRETE.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.DISCRETE; } else if (type == AnnoScheme.TYPE.CONTINUOUS.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.CONTINUOUS; } else { list.Scheme.Type = AnnoScheme.TYPE.FREE; } if (scheme.Attributes["color"] != null) { list.Scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(scheme.Attributes["color"].Value); } else if (scheme.Attributes["mincolor"] != null) { list.Scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(scheme.Attributes["mincolor"].Value); } else if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { list.Scheme.MinOrBackColor = Colors.Orange; } if (scheme.Attributes["maxcolor"] != null) { list.Scheme.MaxOrForeColor = (Color)ColorConverter.ConvertFromString(scheme.Attributes["maxcolor"].Value); } else if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { list.Scheme.MaxOrForeColor = Colors.LightBlue; } Dictionary <string, string> LabelIds = new Dictionary <string, string>(); if (list.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { foreach (XmlNode item in scheme) { LabelIds.Add(item.Attributes["id"].Value, item.Attributes["name"].Value); Color color = Colors.Black; if (item.Attributes["color"] != null) { color = (Color)ColorConverter.ConvertFromString(item.Attributes["color"].Value); } AnnoScheme.Label lcp = new AnnoScheme.Label(item.Attributes["name"].Value, color); list.Scheme.Labels.Add(lcp); } AnnoScheme.Label garbage = new AnnoScheme.Label("GARBAGE", Colors.Black); list.Scheme.Labels.Add(garbage); } else if (list.Scheme.Type == AnnoScheme.TYPE.FREE) { } else if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { list.Scheme.SampleRate = double.Parse(scheme.Attributes["sr"].Value); list.Scheme.MinScore = double.Parse(scheme.Attributes["min"].Value); list.Scheme.MaxScore = double.Parse(scheme.Attributes["max"].Value); } if (File.Exists(filepath + "~")) { if (list.Source.File.Type == AnnoSource.FileSource.TYPE.ASCII) { StreamReader sr = new StreamReader(filepath + "~", System.Text.Encoding.Default); string line = null; double start = 0.0; while ((line = sr.ReadLine()) != null) { string[] data = line.Split(';'); if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { string value = data[0]; double confidence = Convert.ToDouble(data[1], CultureInfo.InvariantCulture); AnnoListItem e = new AnnoListItem(start, (1000.0 / list.Scheme.SampleRate) / 1000.0, value, "", Colors.Black, confidence); list.Add(e); start = start + (1000.0 / list.Scheme.SampleRate) / 1000.0; } else if (list.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture); double stop = Convert.ToDouble(data[1], CultureInfo.InvariantCulture); double dur = stop - start; string label = ""; if (int.Parse(data[2]) < 0) { label = "GARBAGE"; } else { LabelIds.TryGetValue(data[2], out label); } Color color = Colors.Black; if (list.Scheme.Labels.Find(x => x.Name == label) != null) { color = list.Scheme.Labels.Find(x => x.Name == label).Color; } double confidence = Convert.ToDouble(data[3], CultureInfo.InvariantCulture); AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } else if (list.Scheme.Type == AnnoScheme.TYPE.FREE) { start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture); double stop = Convert.ToDouble(data[1], CultureInfo.InvariantCulture); double dur = stop - start; string label = data[2]; double confidence = Convert.ToDouble(data[3], CultureInfo.InvariantCulture); Color color = Colors.Black; if (data.Length > 4) { string[] metapairs = data[4].Split('='); for (int i = 0; i < metapairs.Length; i++) { if (metapairs[i].Contains("color")) { color = (Color)ColorConverter.ConvertFromString(metapairs[i + 1]); break; } } } AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } } sr.Close(); } else if (list.Source.File.Type == AnnoSource.FileSource.TYPE.BINARY) { BinaryReader binaryReader = new BinaryReader(File.Open(filepath + "~", FileMode.Open)); long length = (binaryReader.BaseStream.Length); double start = 0.0; while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { string value = binaryReader.ReadSingle().ToString(); double confidence = (double)binaryReader.ReadSingle(); AnnoListItem e = new AnnoListItem(start, (1000.0 / list.Scheme.SampleRate) / 1000.0, value, "", Colors.Black, confidence); list.Add(e); start = start + (1000.0 / list.Scheme.SampleRate) / 1000.0; } else if (list.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { start = binaryReader.ReadDouble(); double stop = binaryReader.ReadDouble(); double dur = stop - start; string label = ""; int index = binaryReader.ReadInt32(); if (index < 0) { label = "GARBAGE"; } else { LabelIds.TryGetValue(index.ToString(), out label); } Color color = Colors.Black; if (list.Scheme.Labels.Find(x => x.Name == label) != null) { color = list.Scheme.Labels.Find(x => x.Name == label).Color; } double confidence = Math.Round(binaryReader.ReadSingle(), 3, MidpointRounding.AwayFromZero); AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } else if (list.Scheme.Type == AnnoScheme.TYPE.FREE) { start = binaryReader.ReadDouble(); double stop = binaryReader.ReadDouble(); double dur = stop - start; int stringlength = (int)binaryReader.ReadUInt32(); byte[] labelasbytes = (binaryReader.ReadBytes(stringlength)); string label = System.Text.Encoding.Default.GetString(labelasbytes); Color color = Colors.Black; double confidence = Math.Round(binaryReader.ReadSingle(), 3, MidpointRounding.AwayFromZero); AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } } binaryReader.Close(); } } else { MessageBox.Show("Annotation data was not found, load scheme only from '" + filepath + "'"); } list.HasChanged = false; } catch (Exception e) { MessageBox.Show("An exception occured while reading annotation from '" + filepath + "'"); } return(list); }
public void OnPreviewKeyDown(object sender, KeyEventArgs e) { if (!this.control.annoListControl.editTextBox.IsFocused) { if (e.KeyboardDevice.IsKeyDown(Key.Space)) { handlePlay(); e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && e.KeyboardDevice.IsKeyDown(Key.L)) { if (AnnoTierStatic.Selected != null && Properties.Settings.Default.CMLDefaultStream != null) { DatabaseHandler.StoreToDatabase(AnnoTierStatic.Selected.AnnoList, loadedDBmedia, false); CompleteTier(Properties.Settings.Default.CMLContext, AnnoTierStatic.Selected, Properties.Settings.Default.CMLDefaultStream, Properties.Settings.Default.CMLDefaultConf, Properties.Settings.Default.CMLDefaultGap, Properties.Settings.Default.CMLDefaultMinDur); } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.D0) || e.KeyboardDevice.IsKeyDown(Key.NumPad0)) { if (AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.DISCRETE || AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.FREE) { string label = "GARBAGE"; if (AnnoTierStatic.Label != null) { AnnoTierStatic.Label.Item.Label = label; AnnoTierStatic.Label.Item.Color = Colors.Black; AnnoTierStatic.Label.Item.Confidence = 1.0; } } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.D1) || e.KeyboardDevice.IsKeyDown(Key.D2) || e.KeyboardDevice.IsKeyDown(Key.D3) || e.KeyboardDevice.IsKeyDown(Key.D4) || e.KeyboardDevice.IsKeyDown(Key.D5) || e.KeyboardDevice.IsKeyDown(Key.D6) || e.KeyboardDevice.IsKeyDown(Key.D7) || e.KeyboardDevice.IsKeyDown(Key.D8) || e.KeyboardDevice.IsKeyDown(Key.D9) || e.KeyboardDevice.IsKeyDown(Key.NumPad1) || e.KeyboardDevice.IsKeyDown(Key.NumPad2) || e.KeyboardDevice.IsKeyDown(Key.NumPad3) || e.KeyboardDevice.IsKeyDown(Key.NumPad4) || e.KeyboardDevice.IsKeyDown(Key.NumPad5) || e.KeyboardDevice.IsKeyDown(Key.NumPad6) || e.KeyboardDevice.IsKeyDown(Key.NumPad7) || e.KeyboardDevice.IsKeyDown(Key.NumPad8) || e.KeyboardDevice.IsKeyDown(Key.NumPad9)) { int index = 0; if (e.Key - Key.D1 < 10 && AnnoTierStatic.Selected.AnnoList.Scheme.Labels != null && AnnoTierStatic.Selected.AnnoList.Scheme.Labels.Count > 0) { index = Math.Min(AnnoTierStatic.Selected.AnnoList.Scheme.Labels.Count - 1, e.Key - Key.D1); } else if (AnnoTierStatic.Selected.AnnoList.Scheme.Labels != null) { index = Math.Min(AnnoTierStatic.Selected.AnnoList.Scheme.Labels.Count - 1, e.Key - Key.NumPad1); } if (index >= 0 && AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { string label = AnnoTierStatic.Selected.AnnoList.Scheme.Labels.ElementAt(index).Name; if (AnnoTierStatic.Label != null) { AnnoTierStatic.Label.Item.Label = label; AnnoTierStatic.Selected.DefaultLabel = label; foreach (AnnoScheme.Label lp in AnnoTierStatic.Selected.AnnoList.Scheme.Labels) { if (label == lp.Name) { AnnoTierStatic.Label.Item.Color = lp.Color; AnnoTierStatic.Label.Item.Confidence = 1.0; AnnoTierStatic.Selected.DefaultColor = lp.Color; break; } } } } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.Right) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl)) { if (AnnoTierStatic.Label != null && AnnoTierStatic.Selected.isDiscreteOrFree && isKeyDown == false /*&& AnnoTierStatic.Label == null*/) { UIElement container = VisualTreeHelper.GetParent(AnnoTierStatic.Label) as UIElement; Point relativeLocation = AnnoTierStatic.Label.TranslatePoint(new Point(0, 0), container); mediaList.move(MainHandler.Time.TimeFromPixel(relativeLocation.X + AnnoTierStatic.Label.Width)); if (e.KeyboardDevice.IsKeyDown(Key.LeftShift)) { annoCursor.X = relativeLocation.X + AnnoTierStatic.Label.Width; } else { signalCursor.X = relativeLocation.X + AnnoTierStatic.Label.Width; } timeline.CurrentSelectPosition = annoCursor.X; timeline.CurrentPlayPosition = MainHandler.Time.TimeFromPixel(signalCursor.X); timeline.CurrentPlayPositionPrecise = MainHandler.Time.TimeFromPixel(signalCursor.X); AnnoTierStatic.Label.select(true); isKeyDown = true; } e.Handled = true; } else if (e.KeyboardDevice.IsKeyDown(Key.Right) && !e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && !e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && !isKeyDown) { isKeyDown = true; if (AnnoTier.Selected != null) { AnnoTier.Selected.Focus(); } int i = 0; double fps = 1.0 / 25.0; foreach (IMedia im in mediaList.Medias) { if (im.IsVideo()) { break; } i++; } if (i < mediaList.Medias.Count) { fps = 1.0 / mediaList.Medias[i].GetSampleRate(); } mediaList.move(MainHandler.Time.TimeFromPixel(signalCursor.X) + fps); timeline.CurrentPlayPosition = MainHandler.Time.TimeFromPixel(signalCursor.X) + fps; timeline.CurrentPlayPositionPrecise = MainHandler.Time.TimeFromPixel(signalCursor.X) + fps; double pos = MainHandler.Time.PixelFromTime(timeline.CurrentPlayPosition); signalCursor.X = pos; if (Time.CurrentPlayPosition >= Time.SelectionStop && control.navigator.followplaybox.IsChecked == true) { double factor = (((timeline.CurrentPlayPosition - timeline.SelectionStart) / (timeline.SelectionStop - timeline.SelectionStart))); control.timeLineControl.rangeSlider.followmedia = true; control.timeLineControl.rangeSlider.MoveAndUpdate(true, factor); if (timeline.SelectionStop - timeline.SelectionStart < 1) { timeline.SelectionStart = timeline.SelectionStop - 1; } signalCursor.X = 1; } else if (control.navigator.followplaybox.IsChecked == false) { control.timeLineControl.rangeSlider.followmedia = false; } double time = Time.TimeFromPixel(pos); control.signalPositionLabel.Text = FileTools.FormatSeconds(time); control.annoTrackControl.currenttime = Time.TimeFromPixel(pos); e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.Left) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl)) { if (AnnoTierStatic.Label != null && AnnoTierStatic.Selected.isDiscreteOrFree && isKeyDown == false /*&& AnnoTierStatic.Label == null*/) { UIElement container = VisualTreeHelper.GetParent(AnnoTierStatic.Label) as UIElement; Point relativeLocation = AnnoTierStatic.Label.TranslatePoint(new Point(0, 0), container); mediaList.move(MainHandler.Time.TimeFromPixel(relativeLocation.X)); if (e.KeyboardDevice.IsKeyDown(Key.LeftShift)) { annoCursor.X = relativeLocation.X; } else { signalCursor.X = relativeLocation.X; } timeline.CurrentSelectPosition = annoCursor.X; timeline.CurrentPlayPosition = MainHandler.Time.TimeFromPixel(signalCursor.X); timeline.CurrentPlayPositionPrecise = MainHandler.Time.TimeFromPixel(signalCursor.X); AnnoTierStatic.Label.select(true); isKeyDown = true; } e.Handled = true; } else if (e.KeyboardDevice.IsKeyDown(Key.Left) && !e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && !e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && !isKeyDown) { isKeyDown = true; if (AnnoTier.Selected != null) { AnnoTier.Selected.Focus(); } int i = 0; double fps = 1.0 / 25.0; foreach (IMedia im in mediaList.Medias) { if (im.IsVideo()) { break; } i++; } if (i < mediaList.Medias.Count) { fps = 1.0 / mediaList.Medias[i].GetSampleRate(); } mediaList.move(MainHandler.Time.TimeFromPixel(signalCursor.X) - fps); timeline.CurrentPlayPosition = MainHandler.Time.TimeFromPixel(signalCursor.X) - fps; timeline.CurrentPlayPositionPrecise = timeline.CurrentPlayPosition; double pos = MainHandler.Time.PixelFromTime(timeline.CurrentPlayPosition); signalCursor.X = pos; if (Time.CurrentPlayPosition < Time.SelectionStart && Time.SelectionStart > 0 && control.navigator.followplaybox.IsChecked == true) { double factor = (((timeline.SelectionStop - timeline.CurrentPlayPosition) / (timeline.SelectionStop - timeline.SelectionStart))); control.timeLineControl.rangeSlider.followmedia = true; control.timeLineControl.rangeSlider.MoveAndUpdate(false, factor); if (timeline.SelectionStop - timeline.SelectionStart < 1) { timeline.SelectionStart = timeline.SelectionStop - 1; } signalCursor.X = MainHandler.Time.PixelFromTime(MainHandler.Time.SelectionStop); } else if (control.navigator.followplaybox.IsChecked == false) { control.timeLineControl.rangeSlider.followmedia = false; } double time = Time.TimeFromPixel(pos); if (time != 0) { control.signalPositionLabel.Text = FileTools.FormatSeconds(time); control.annoTrackControl.currenttime = Time.TimeFromPixel(pos); } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && !isKeyDown) { if (AnnoTierStatic.Selected != null && !AnnoTierStatic.Selected.isDiscreteOrFree) { AnnoTierStatic.Selected.ContinuousAnnoMode(); } isKeyDown = true; e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.T) && e.KeyboardDevice.IsKeyDown(Key.Down)) { for (int i = 0; i < annoTiers.Count; i++) { if (annoTiers[i] == AnnoTierStatic.Selected && i + 1 < annoTiers.Count) { AnnoTier.SelectTier(annoTiers[i + 1]); AnnoTier.SelectLabel(null); break; } } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.T) && e.KeyboardDevice.IsKeyDown(Key.Up)) { for (int i = 0; i < annoTiers.Count; i++) { if (annoTiers[i] == AnnoTierStatic.Selected && i > 0) { AnnoTier.SelectTier(annoTiers[i - 1]); AnnoTier.SelectLabel(null); break; } } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.C) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.isDiscreteOrFree) { if (AnnoTierStatic.Label != null) { temp_segment = AnnoTierStatic.Label; AnnoTierStatic.Label.select(false); } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.X) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.isDiscreteOrFree) { if (AnnoTierStatic.Label != null) { temp_segment = AnnoTierStatic.Label; AnnoTier.OnKeyDownHandler(sender, e); } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.V) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.isDiscreteOrFree) { if (AnnoTierStatic.Selected != null) { double start = Time.TimeFromPixel(annoCursor.X); if (temp_segment != null) { AnnoTierStatic.Selected.NewAnnoCopy(start, start + temp_segment.Item.Duration, temp_segment.Item.Label, temp_segment.Item.Color, temp_segment.Item.Confidence); } } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && e.KeyboardDevice.IsKeyDown(Key.Z)) { if (AnnoTierStatic.Selected != null) { AnnoTierStatic.Selected.UnDoObject.Undo(1); } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && e.KeyboardDevice.IsKeyDown(Key.Y)) { if (AnnoTierStatic.Selected != null) { AnnoTierStatic.Selected.UnDoObject.Redo(1); } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && e.KeyboardDevice.IsKeyDown(Key.Down)) { if (AnnoTierStatic.Label != null) { AnnoListItem temp = AnnoTierStatic.Label.Item; for (int i = 0; i < annoTiers.Count; i++) { if (annoTiers[i] == AnnoTierStatic.Selected && i + 1 < annoTiers.Count) { AnnoTier.SelectTier(annoTiers[i + 1]); AnnoTier.SelectLabel(null); if (!AnnoTierStatic.Selected.AnnoList.Contains(temp)) { AnnoTierStatic.Selected.NewAnnoCopy(temp.Start, temp.Stop, temp.Label, temp.Color); } break; } } } e.Handled = true; } if (e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && e.KeyboardDevice.IsKeyDown(Key.Up)) { if (AnnoTierStatic.Label != null) { AnnoListItem temp = AnnoTierStatic.Label.Item; for (int i = 0; i < annoTiers.Count; i++) { if (annoTiers[i] == AnnoTierStatic.Selected && i > 0) { AnnoTier.SelectTier(annoTiers[i - 1]); AnnoTier.SelectLabel(null); if (!AnnoTierStatic.Selected.AnnoList.Contains(temp)) { AnnoTierStatic.Selected.NewAnnoCopy(temp.Start, temp.Stop, temp.Label, temp.Color); } break; } } } e.Handled = true; } } }
public static AnnoList LoadFromCSVFile(String filepath, double samplerate = 1, string type = "legacy", string filter = null) { AnnoList list = new AnnoList(); list.Source.File.Path = filepath; list.Scheme = new AnnoScheme(); try { StreamReader sr = new StreamReader(filepath, System.Text.Encoding.Default); string line = null; while ((line = sr.ReadLine()) != null) { if (type == "semicolon") { list.Scheme.Type = AnnoScheme.TYPE.FREE; string[] data = line.Split(';'); double start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture); double duration = Convert.ToDouble(data[1]) - Convert.ToDouble(data[0], CultureInfo.InvariantCulture); string label = ""; string tier = ""; string meta = ""; double confidence = 1.0; if (data.Length > 2) { label = data[2]; } if (data.Length > 3) { if (data[3].Contains("#")) { tier = data[3]; tier = tier.Remove(0, 1); } else { bool isconfidence = double.TryParse(data[3], out confidence); } } if (data.Length > 4) { for (int i = 4; i < data.Length; i++) { meta += data[i] + ";"; } } AnnoListItem e = new AnnoListItem(start, duration, label, meta, Colors.Black, confidence); if (filter == null || tier == filter) { list.AddSorted(e); } } else if (type == "continuous") { list.Scheme.Type = AnnoScheme.TYPE.CONTINUOUS; list.Scheme.SampleRate = samplerate; string[] data = line.Split(';'); double start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture); double score = double.NaN; string tier = ""; double confidence = 1.0; if (data.Length > 1) { double.TryParse(data[1], out score); } if (data.Length > 2) { bool isconfidence = double.TryParse(data[2], out confidence); } if (data.Length > 3) { list.Scheme.MinScore = double.Parse(data[3]); if (data.Length > 4) { list.Scheme.MaxScore = double.Parse(data[4]); } AnnoListItem e = new AnnoListItem(start, samplerate == 0 ? 0 : 1 / samplerate, score, "Range: " + list.Scheme.MinScore + "-" + list.Scheme.MaxScore, Colors.Black); list.AddSorted(e); } else { AnnoListItem e = new AnnoListItem(start, samplerate == 0 ? 0 : 1 / samplerate, score, "", Colors.Black, 1); if (filter == null || tier == filter) { list.AddSorted(e); } } } else if (type == "legacy") { list.Scheme.Type = AnnoScheme.TYPE.FREE; string[] data; data = line.Split(' '); if (data.Length < 2) { data = line.Split('\t'); } if (data.Length < 2) { data = line.Split(';'); } double start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture); double duration = Convert.ToDouble(data[1], CultureInfo.InvariantCulture) - Convert.ToDouble(data[0], CultureInfo.InvariantCulture); string label = ""; string tier = ""; if (data.Length > 2) { label = data[2]; } if (data.Length > 3) { tier = data[3]; } for (int i = 4; i < data.Length; i++) { label += " " + data[i]; } AnnoListItem e = new AnnoListItem(start, duration, label, "", Colors.Black, 1); if (filter == null || tier == filter) { list.AddSorted(e); } } } sr.Close();; list.HasChanged = false; } catch { MessageBox.Show("An exception occured while reading annotation from '" + filepath + "'"); } return(list); }
public static AnnoList LoadfromFile(string filepath) { AnnoList list = new AnnoList(); list.Source.File.Path = filepath; list.Scheme = new AnnoScheme(); list.Scheme.Labels = new List <AnnoScheme.Label>(); //try { XmlDocument doc = new XmlDocument(); doc.Load(filepath); XmlNode annotation = doc.SelectSingleNode("annotation"); XmlNode info = annotation.SelectSingleNode("info"); list.Source.File.Type = info.Attributes["ftype"].Value == AnnoSource.FileSource.TYPE.ASCII.ToString() ? AnnoSource.FileSource.TYPE.ASCII : AnnoSource.FileSource.TYPE.BINARY; int size = int.Parse(info.Attributes["size"].Value); XmlNode meta = annotation.SelectSingleNode("meta"); if (meta != null) { if (meta.Attributes["role"] != null) { list.Meta.Role = meta.Attributes["role"].Value; } if (meta.Attributes["annotator"] != null) { list.Meta.Annotator = meta.Attributes["annotator"].Value; } } XmlNode scheme = annotation.SelectSingleNode("scheme"); if (scheme.Attributes["name"] != null) { list.Scheme.Name = scheme.Attributes["name"].Value; } string type = "FREE"; if (scheme.Attributes["type"] != null) { type = scheme.Attributes["type"].Value; } if (type == AnnoScheme.TYPE.DISCRETE.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.DISCRETE; } else if (type == AnnoScheme.TYPE.CONTINUOUS.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.CONTINUOUS; } else if (type == AnnoScheme.TYPE.FREE.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.FREE; } else if (type == AnnoScheme.TYPE.POINT.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.POINT; } else if (type == AnnoScheme.TYPE.POLYGON.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.POLYGON; } else if (type == AnnoScheme.TYPE.GRAPH.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.GRAPH; } else if (type == AnnoScheme.TYPE.SEGMENTATION.ToString()) { list.Scheme.Type = AnnoScheme.TYPE.SEGMENTATION; } if (scheme.Attributes["color"] != null) { list.Scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(scheme.Attributes["color"].Value); } else if (scheme.Attributes["mincolor"] != null) { list.Scheme.MinOrBackColor = (Color)ColorConverter.ConvertFromString(scheme.Attributes["mincolor"].Value); } else if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { list.Scheme.MinOrBackColor = Defaults.Colors.GradientMin; } if (scheme.Attributes["maxcolor"] != null) { list.Scheme.MaxOrForeColor = (Color)ColorConverter.ConvertFromString(scheme.Attributes["maxcolor"].Value); } else if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { list.Scheme.MaxOrForeColor = Defaults.Colors.GradientMax; } Dictionary <string, string> LabelIds = new Dictionary <string, string>(); if (list.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { foreach (XmlNode item in scheme) { LabelIds.Add(item.Attributes["id"].Value, item.Attributes["name"].Value); Color color = Defaults.Colors.Foreground; if (item.Attributes["color"] != null) { color = (Color)ColorConverter.ConvertFromString(item.Attributes["color"].Value); } AnnoScheme.Label lcp = new AnnoScheme.Label(item.Attributes["name"].Value, color); list.Scheme.Labels.Add(lcp); } AnnoScheme.Label garbage = new AnnoScheme.Label("GARBAGE", Defaults.Colors.Foreground); list.Scheme.Labels.Add(garbage); } else if (list.Scheme.Type == AnnoScheme.TYPE.FREE) { } else if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { list.Scheme.MinScore = double.Parse(scheme.Attributes["min"].Value); list.Scheme.MaxScore = double.Parse(scheme.Attributes["max"].Value); list.Scheme.SampleRate = double.Parse(scheme.Attributes["sr"].Value); } else if (list.Scheme.Type == AnnoScheme.TYPE.POINT || list.Scheme.Type == AnnoScheme.TYPE.POLYGON || list.Scheme.Type == AnnoScheme.TYPE.GRAPH || list.Scheme.Type == AnnoScheme.TYPE.SEGMENTATION) { list.Scheme.SampleRate = double.Parse(scheme.Attributes["sr"].Value); list.Scheme.NumberOfPoints = int.Parse(scheme.Attributes["num"].Value); } if (File.Exists(filepath + "~")) { if (list.Source.File.Type == AnnoSource.FileSource.TYPE.ASCII) { StreamReader sr = new StreamReader(filepath + "~", System.Text.Encoding.UTF8); string line = null; double start = 0.0; while ((line = sr.ReadLine()) != null) { string[] data = line.Split(';'); if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { double value = double.NaN; double.TryParse(data[0], out value); double confidence = Convert.ToDouble(data[1], CultureInfo.InvariantCulture); AnnoListItem e = new AnnoListItem(start, 1 / list.Scheme.SampleRate, value, "", Defaults.Colors.Foreground, confidence); list.Add(e); start = start + 1 / list.Scheme.SampleRate; } else if (list.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture); double stop = Convert.ToDouble(data[1], CultureInfo.InvariantCulture); double dur = stop - start; string label = ""; if (int.Parse(data[2]) < 0) { label = "GARBAGE"; } else { LabelIds.TryGetValue(data[2], out label); } Color color = Colors.Black; if (list.Scheme.Labels.Find(x => x.Name == label) != null) { color = list.Scheme.Labels.Find(x => x.Name == label).Color; } double confidence = Convert.ToDouble(data[3], CultureInfo.InvariantCulture); AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } else if (list.Scheme.Type == AnnoScheme.TYPE.FREE) { start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture); double stop = Convert.ToDouble(data[1], CultureInfo.InvariantCulture); double dur = stop - start; string label = data[2]; double confidence = Convert.ToDouble(data[3], CultureInfo.InvariantCulture); Color color = Colors.Black; if (data.Length > 4) { string[] metapairs = data[4].Split('='); for (int i = 0; i < metapairs.Length; i++) { if (metapairs[i].Contains("color")) { color = (Color)ColorConverter.ConvertFromString(metapairs[i + 1]); break; } } } AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } else if (list.Scheme.Type == AnnoScheme.TYPE.POINT) { string frameLabel = data[0]; double frameConfidence = Convert.ToDouble(data[data.Count() - 1], CultureInfo.InvariantCulture); PointList points = new PointList(); for (int i = 1; i < data.Count() - 1; ++i) { string pd = data[i].Replace("(", ""); pd = pd.Replace(")", ""); string[] pointData = pd.Split(':'); points.Add(new PointListItem(double.Parse(pointData[1]), double.Parse(pointData[2]), pointData[0], double.Parse(pointData[3]))); } AnnoListItem ali = new AnnoListItem(start, 1 / list.Scheme.SampleRate, frameLabel, "", list.Scheme.MinOrBackColor, frameConfidence, true, points); list.Add(ali); start = start + 1 / list.Scheme.SampleRate; } } sr.Close(); } else if (list.Source.File.Type == AnnoSource.FileSource.TYPE.BINARY) { BinaryReader binaryReader = new BinaryReader(File.Open(filepath + "~", FileMode.Open)); long length = (binaryReader.BaseStream.Length); double start = 0.0; while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { if (list.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { double value = (double)binaryReader.ReadSingle(); double confidence = (double)binaryReader.ReadSingle(); AnnoListItem e = new AnnoListItem(start, 1 / list.Scheme.SampleRate, value, "", Defaults.Colors.Foreground, confidence); list.Add(e); start = start + 1 / list.Scheme.SampleRate; } else if (list.Scheme.Type == AnnoScheme.TYPE.DISCRETE) { start = binaryReader.ReadDouble(); double stop = binaryReader.ReadDouble(); double dur = stop - start; string label = ""; int index = binaryReader.ReadInt32(); if (index < 0) { label = "GARBAGE"; } else { LabelIds.TryGetValue(index.ToString(), out label); } Color color = Colors.Black; if (list.Scheme.Labels.Find(x => x.Name == label) != null) { color = list.Scheme.Labels.Find(x => x.Name == label).Color; } double confidence = Math.Round(binaryReader.ReadSingle(), 3, MidpointRounding.AwayFromZero); AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } else if (list.Scheme.Type == AnnoScheme.TYPE.FREE) { start = binaryReader.ReadDouble(); double stop = binaryReader.ReadDouble(); double dur = stop - start; int stringlength = (int)binaryReader.ReadUInt32(); byte[] labelasbytes = (binaryReader.ReadBytes(stringlength)); string label = System.Text.Encoding.Default.GetString(labelasbytes); Color color = Colors.Black; double confidence = Math.Round(binaryReader.ReadSingle(), 3, MidpointRounding.AwayFromZero); AnnoListItem e = new AnnoListItem(start, dur, label, "", color, confidence); list.AddSorted(e); } } binaryReader.Close(); } } //Plugin logic should be called after parsing if (meta != null && meta.Attributes["trigger"] != null) { string[] triggers = meta.Attributes["trigger"].Value.Split(';'); foreach (string trigger in triggers) { try { Match match = Regex.Match(trigger, @"([^{]+)\{([^}]*)\}"); if (match.Success && match.Groups.Count == 3) { string dllName = match.Groups[1].Value; string arguments = match.Groups[2].Value; Dictionary <string, object> args = arguments.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(part => part.Split('=')) .ToDictionary(split => split[0], split => (object)split[1]); PluginCaller pluginCaller = new PluginCaller(dllName + ".dll", dllName); AnnoTrigger annoTrigger = new AnnoTrigger(list, pluginCaller, args); list.Meta.Trigger.Add(annoTrigger); } else { MessageTools.Warning("could not parse trigger '" + trigger + "'"); } } catch (Exception) { MessageTools.Warning("could not parse trigger '" + trigger + "'"); } } } if (meta != null && meta.Attributes["pipeline"] != null) { string[] pipelines = meta.Attributes["pipeline"].Value.Split(';'); foreach (string pipeline in pipelines) { try { Pipeline pipe = new Pipeline(list, pipeline); list.Meta.Pipeline.Add(pipe); } catch (Exception) { MessageTools.Warning("could not parse pipeline '" + pipeline + "'"); } } } } //catch(Exception e) //{ // MessageBox.Show("An exception occured while reading annotation from '" + filepath + "'"); //} return(list); }
public void Undo(int level) { for (int i = 1; i <= level; i++) { if (_UndoActionsCollection.Count == 0) { return; } ChangeRepresentationObject Undostruct = _UndoActionsCollection.Pop(); if (Undostruct.Action == ActionType.Delete) { AnnoListItem ali = ((AnnoTierSegment)Undostruct.UiElement).Item; ((AnnoTier)Container).AnnoList.AddSorted(ali); AnnoTierSegment at = ((AnnoTier)Container).AddSegment(ali); this.RedoPushInUnDoForDelete(at); } else if (Undostruct.Action == ActionType.Insert) { ((AnnoTier)Container).DeleteSegment((AnnoTierSegment)Undostruct.UiElement); this.RedoPushInUnDoForInsert(Undostruct.UiElement); } else if (Undostruct.Action == ActionType.Resize) { this.RedoPushInUnDoForResize(Canvas.GetLeft(Undostruct.UiElement), Undostruct.UiElement); Canvas.SetLeft(Undostruct.UiElement, Undostruct.Margin.X); Undostruct.UiElement.Width = Undostruct.Width; ((AnnoTierSegment)Undostruct.UiElement).Item.Duration = Undostruct.Duration; ((AnnoTierSegment)Undostruct.UiElement).Item.Start = Undostruct.Start; ((AnnoTierSegment)Undostruct.UiElement).Item.Stop = Undostruct.Stop; } else if (Undostruct.Action == ActionType.Move) { this.RedoPushInUnDoForMove(Canvas.GetLeft(Undostruct.UiElement), Undostruct.UiElement); Canvas.SetLeft(Undostruct.UiElement, Undostruct.Margin.X); Undostruct.UiElement.Width = Undostruct.Width; ((AnnoTierSegment)Undostruct.UiElement).Item.Duration = Undostruct.Duration; ((AnnoTierSegment)Undostruct.UiElement).Item.Start = Undostruct.Start; ((AnnoTierSegment)Undostruct.UiElement).Item.Stop = Undostruct.Stop; } else if (Undostruct.Action == ActionType.Split) { //resize element this.RedoPushInUnDoForSplit(Canvas.GetLeft(Undostruct.UiElement), Undostruct.UiElement, Undostruct.NextUiElement); Canvas.SetLeft(Undostruct.UiElement, Undostruct.Margin.X); Undostruct.UiElement.Width = Undostruct.Width; ((AnnoTierSegment)Undostruct.UiElement).Item.Duration = Undostruct.Duration; ((AnnoTierSegment)Undostruct.UiElement).Item.Start = Undostruct.Start; ((AnnoTierSegment)Undostruct.UiElement).Item.Stop = Undostruct.Stop; //delete added element ((AnnoTier)Container).DeleteSegment((AnnoTierSegment)Undostruct.NextUiElement); } } if (EnableDisableUndoRedoFeature != null) { EnableDisableUndoRedoFeature(null, null); } }