/// <summary> /// Row-wise: text-blocks are read in rows from left-to-right, top- to-bottom. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="T">The tolerance parameter T.</param> /// <returns></returns> private bool GetBeforeInReadingHorizontal(TextBlock a, TextBlock b, double T) { IntervalRelations xRelation = GetIntervalRelationX(a, b, T); IntervalRelations yRelation = GetIntervalRelationY(a, b, T); if (yRelation == IntervalRelations.Precedes || yRelation == IntervalRelations.Meets || (yRelation == IntervalRelations.Overlaps && (xRelation == IntervalRelations.Precedes || xRelation == IntervalRelations.Meets || xRelation == IntervalRelations.Overlaps)) || ((xRelation == IntervalRelations.Precedes || xRelation == IntervalRelations.Meets || xRelation == IntervalRelations.Overlaps) && (yRelation == IntervalRelations.Precedes || yRelation == IntervalRelations.Meets || yRelation == IntervalRelations.Overlaps || yRelation == IntervalRelations.Starts || yRelation == IntervalRelations.FinishesI || yRelation == IntervalRelations.Equals || yRelation == IntervalRelations.During || yRelation == IntervalRelations.DuringI || yRelation == IntervalRelations.Finishes || yRelation == IntervalRelations.StartsI || yRelation == IntervalRelations.OverlapsI))) { return(true); } return(false); }
private bool GetBeforeInReading(TextBlock a, TextBlock b, double T) { IntervalRelations xRelation = GetIntervalRelationX(a, b, T); IntervalRelations yRelation = GetIntervalRelationY(a, b, T); return(xRelation == IntervalRelations.Precedes || yRelation == IntervalRelations.Precedes || xRelation == IntervalRelations.Meets || yRelation == IntervalRelations.Meets || xRelation == IntervalRelations.Overlaps || yRelation == IntervalRelations.Overlaps); }
/// <summary> /// Column-wise: text-blocks are read in columns, from top-to-bottom and from left-to-right. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="T">The tolerance parameter T.</param> private static bool GetBeforeInReadingVertical(TextBlock a, TextBlock b, double T) { IntervalRelations xRelation = GetIntervalRelationX(a, b, T); IntervalRelations yRelation = GetIntervalRelationY(a, b, T); return(xRelation == IntervalRelations.Precedes || xRelation == IntervalRelations.Meets || (xRelation == IntervalRelations.Overlaps && (yRelation == IntervalRelations.Precedes || yRelation == IntervalRelations.Meets || yRelation == IntervalRelations.Overlaps)) || ((yRelation == IntervalRelations.Precedes || yRelation == IntervalRelations.Meets || yRelation == IntervalRelations.Overlaps) && (xRelation == IntervalRelations.Precedes || xRelation == IntervalRelations.Meets || xRelation == IntervalRelations.Overlaps || xRelation == IntervalRelations.Starts || xRelation == IntervalRelations.FinishesI || xRelation == IntervalRelations.Equals || xRelation == IntervalRelations.During || xRelation == IntervalRelations.DuringI || xRelation == IntervalRelations.Finishes || xRelation == IntervalRelations.StartsI || xRelation == IntervalRelations.OverlapsI))); }
/// <summary> /// Gets the Thick Boundary Rectangle Relations (TBRR) for the Y coordinate. /// <para>The Thick Boundary Rectangle Relations (TBRR) is a set of qualitative relations representing the spatial relations of the document objects on the page. /// For every pair of document objects a and b, one X and one Y interval relation hold. If one considers the pair in reversed /// order, the inverse interval relation holds. Therefore the directed graph g_i representing these relations is complete.</para> /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="T">The tolerance parameter T. If two coordinates are closer than T they are considered equal.</param> private IntervalRelations GetIntervalRelationY(TextBlock a, TextBlock b, double T) { IntervalRelations yRelation = IntervalRelations.Unknown; if (a.BoundingBox.Bottom < b.BoundingBox.Top - T) { yRelation = IntervalRelations.PrecedesI; } else if (a.BoundingBox.Bottom >= b.BoundingBox.Top - T) { yRelation = IntervalRelations.Precedes; } else if (b.BoundingBox.Top - T <= a.BoundingBox.Bottom && a.BoundingBox.Bottom <= b.BoundingBox.Top + T) { yRelation = IntervalRelations.MeetsI; } else if (b.BoundingBox.Top - T > a.BoundingBox.Bottom && a.BoundingBox.Bottom > b.BoundingBox.Top + T) { yRelation = IntervalRelations.Meets; } else if (a.BoundingBox.Top < b.BoundingBox.Top - T && (b.BoundingBox.Top + T < a.BoundingBox.Bottom && a.BoundingBox.Bottom < b.BoundingBox.Bottom - T)) { yRelation = IntervalRelations.OverlapsI; } else if (a.BoundingBox.Top >= b.BoundingBox.Top - T && (b.BoundingBox.Top + T >= a.BoundingBox.Bottom && a.BoundingBox.Bottom >= b.BoundingBox.Bottom - T)) { yRelation = IntervalRelations.Overlaps; } else if ((b.BoundingBox.Top - T <= a.BoundingBox.Top && a.BoundingBox.Top <= b.BoundingBox.Top + T) && a.BoundingBox.Bottom < b.BoundingBox.Bottom - T) { yRelation = IntervalRelations.StartsI; } else if ((b.BoundingBox.Top - T > a.BoundingBox.Top && a.BoundingBox.Top > b.BoundingBox.Top + T) && a.BoundingBox.Bottom >= b.BoundingBox.Bottom - T) { yRelation = IntervalRelations.Starts; } else if (a.BoundingBox.Top > b.BoundingBox.Top + T && a.BoundingBox.Bottom < b.BoundingBox.Bottom - T) { yRelation = IntervalRelations.DuringI; } else if (a.BoundingBox.Top <= b.BoundingBox.Top + T && a.BoundingBox.Bottom >= b.BoundingBox.Bottom - T) { yRelation = IntervalRelations.During; } else if (a.BoundingBox.Top > b.BoundingBox.Top + T && (b.BoundingBox.Bottom - T <= a.BoundingBox.Bottom && a.BoundingBox.Bottom <= b.BoundingBox.Bottom + T)) { yRelation = IntervalRelations.FinishesI; } else if (a.BoundingBox.Top <= b.BoundingBox.Top + T && (b.BoundingBox.Bottom - T > a.BoundingBox.Bottom && a.BoundingBox.Bottom > b.BoundingBox.Bottom + T)) { yRelation = IntervalRelations.Finishes; } else if ((b.BoundingBox.Top - T <= a.BoundingBox.Top && a.BoundingBox.Top <= b.BoundingBox.Top + T) && (b.BoundingBox.Bottom - T <= a.BoundingBox.Bottom && a.BoundingBox.Bottom <= b.BoundingBox.Bottom + T)) { yRelation = IntervalRelations.Equals; } return(yRelation); }
/// <summary> /// Gets the Thick Boundary Rectangle Relations (TBRR) for the X coordinate. /// <para>The Thick Boundary Rectangle Relations (TBRR) is a set of qualitative relations representing the spatial relations of the document objects on the page. /// For every pair of document objects a and b, one X and one Y interval relation hold. If one considers the pair in reversed /// order, the inverse interval relation holds. Therefore the directed graph g_i representing these relations is complete.</para> /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="T">The tolerance parameter T. If two coordinates are closer than T they are considered equal.</param> private IntervalRelations GetIntervalRelationX(TextBlock a, TextBlock b, double T) { IntervalRelations xRelation = IntervalRelations.Unknown; if (a.BoundingBox.Right < b.BoundingBox.Left - T) { xRelation = IntervalRelations.Precedes; } else if (a.BoundingBox.Right >= b.BoundingBox.Left - T) { xRelation = IntervalRelations.PrecedesI; } else if (b.BoundingBox.Left - T <= a.BoundingBox.Right && a.BoundingBox.Right <= b.BoundingBox.Left + T) { xRelation = IntervalRelations.Meets; } else if (b.BoundingBox.Left - T > a.BoundingBox.Right && a.BoundingBox.Right > b.BoundingBox.Left + T) { xRelation = IntervalRelations.MeetsI; } else if (a.BoundingBox.Left < b.BoundingBox.Left - T && (b.BoundingBox.Left + T < a.BoundingBox.Right && a.BoundingBox.Right < b.BoundingBox.Right - T)) { xRelation = IntervalRelations.Overlaps; } else if (a.BoundingBox.Left >= b.BoundingBox.Left - T && (b.BoundingBox.Left + T >= a.BoundingBox.Right && a.BoundingBox.Right >= b.BoundingBox.Right - T)) { xRelation = IntervalRelations.OverlapsI; } else if ((b.BoundingBox.Left - T <= a.BoundingBox.Left && a.BoundingBox.Left <= b.BoundingBox.Left + T) && a.BoundingBox.Right < b.BoundingBox.Right - T) { xRelation = IntervalRelations.Starts; } else if ((b.BoundingBox.Left - T > a.BoundingBox.Left && a.BoundingBox.Left > b.BoundingBox.Left + T) && a.BoundingBox.Right >= b.BoundingBox.Right - T) { xRelation = IntervalRelations.StartsI; } else if (a.BoundingBox.Left > b.BoundingBox.Left + T && a.BoundingBox.Right < b.BoundingBox.Right - T) { xRelation = IntervalRelations.During; } else if (a.BoundingBox.Left <= b.BoundingBox.Left + T && a.BoundingBox.Right >= b.BoundingBox.Right - T) { xRelation = IntervalRelations.DuringI; } else if (a.BoundingBox.Left > b.BoundingBox.Left + T && (b.BoundingBox.Right - T <= a.BoundingBox.Right && a.BoundingBox.Right <= b.BoundingBox.Right + T)) { xRelation = IntervalRelations.Finishes; } else if (a.BoundingBox.Left <= b.BoundingBox.Left + T && (b.BoundingBox.Right - T > a.BoundingBox.Right && a.BoundingBox.Right > b.BoundingBox.Right + T)) { xRelation = IntervalRelations.FinishesI; } else if ((b.BoundingBox.Left - T <= a.BoundingBox.Left && a.BoundingBox.Left <= b.BoundingBox.Left + T) && (b.BoundingBox.Right - T <= a.BoundingBox.Right && a.BoundingBox.Right <= b.BoundingBox.Right + T)) { xRelation = IntervalRelations.Equals; } return(xRelation); }