Added an AsyncStarted event to the progression class, currently disabled for further consideration; set up the outline of a new spatial partitioning framework with an R*-Tree implementation; new AbortedException for indicating that a process was forcefully aborted

git-svn-id: file:///srv/devel/repo-conversion/nusu@31 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2007-07-01 19:27:40 +00:00
parent 6d79fe3ebc
commit 1ae0c7de63
13 changed files with 511 additions and 30 deletions

View file

@ -0,0 +1,78 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace Nuclex.Support.SpatialPartitioning {
/// <summary>Two-dimensional bounding rectangle</summary>
internal struct BoundingRectangle {
/// <summary>Initializes a new two-dimensional bounding rectangle</summary>
/// <param name="min">Lesser coordinates of the bounding rectangle</param>
/// <param name="max">Greater coordinates of the bounding rectangle</param>
public BoundingRectangle(Vector2 min, Vector2 max) {
this.Min = min;
this.Max = max;
}
/// <summary>
/// Builds the smallest bounding rectangle that contains the two
/// specified bounding rectangle.
/// </summary>
/// <param name="original">One of the bounding rectangles to contain</param>
/// <param name="additional">One of the bounding rectangles to contain</param>
/// <returns>The resulting merged bounding rectangle</returns>
public static BoundingRectangle CreateMerged(
BoundingRectangle original, BoundingRectangle additional
) {
BoundingRectangle result;
CreateMerged(ref original, ref additional, out result);
return result;
}
/// <summary>
/// Builds the smallest bounding rectangle that contains the two
/// specified bounding rectangle.
/// </summary>
/// <param name="original">One of the bounding rectangles to contain</param>
/// <param name="additional">One of the bounding rectangles to contain</param>
/// <param name="result">The resulting merged bounding rectangle</param>
public static void CreateMerged(
ref BoundingRectangle original, ref BoundingRectangle additional,
out BoundingRectangle result
) {
result = new BoundingRectangle();
result.Min = Vector2.Min(original.Min, additional.Min);
result.Max = Vector2.Max(original.Max, additional.Max);
}
/// <summary>Coordinates of the lesser side of the bounding rectangle</summary>
public Vector2 Min;
/// <summary>Coordinates of the greater side of the bounding rectangle</summary>
public Vector2 Max;
}
} // namespace Nuclex.Support.SpatialPartitioning

View file

@ -0,0 +1,95 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace Nuclex.Support.SpatialPartitioning {
/// <summary>R-Tree for two-dimensional data</summary>
/// <remarks>
/// R-Trees essentially fullfill the same role that is traditionally
/// assigned to quadtrees in games. But unlike a quadtree, an R-Tree does not
/// require knowledge of the total area that is to be covered by the objects
/// that will populate the tree.
/// </remarks>
public partial class RTree2<ItemType> : SpatialIndex2 {
/// <summary>Variants of R-Tree behaviors this implementation can assume</summary>
public enum Variants {
/// <summary>
/// Insertions and deletions take linear time at the cost of degrading the
/// tree's overall performance.
/// </summary>
/// <remarks>
/// Finds the two bounding boxes with the greatest normalized separation
/// along both axes, and split along this axis. The remaining bounding boxes
/// in the node are assigned to the nodes whose covering bounding box is
/// increased the least by the addition [Gutt84]. This method takes linear time.
/// </remarks>
Linear,
/// <summary>
/// Insertions and deletions take quadratic time while keeping the tree's
/// overall performance at a reasonable level.
/// </summary>
/// <remarks>
/// Examines all the children of the overflowing node and find the pair of
/// bounding boxes that would waste the most area were they to be inserted
/// in the same node. This is determined by subtracting the sum of the areas
/// of the two bounding boxes from the area of the covering bounding box.
/// These two bounding boxes are placed in separate nodes, say j and k.
/// The set of remaining bounding boxes are examined and the bounding box i
/// whose addition maximizes the difference in coverage between the bounding
/// boxes associated with j and k is added to the node whose coverage
/// is minimized by the addition. This process is reapplied to the
/// remaining bounding boxes [Gutt84]. This method takes quadratic time.
/// </remarks>
Quadratic,
/// <summary>
/// Insertions and deletions vary in performance but the tree's overall
/// performance is kept high.
/// </summary>
/// <remarks>
/// The R*-tree [Beck90c] is a name given to a variant of the R-tree which
/// makes use of the most complex of the node splitting algorithms. The
/// algorithm differs from the other algorithms as it attempts to reduce
/// both overlap and coverage. In particular, the primary focus is on
/// reducing overlap with ties broken by favoring the splits that reduce
/// the coverage by using the splits that minimize the perimeter of the
/// bounding boxes of the resulting nodes. In addition, when a node 'a'
/// overflows, instead of immediately splitting 'a', an attempt is made
/// first to see if some of the objects in 'a' could possibly be more suited
/// to being in another node. This is achieved by reinserting a fraction
/// (30% has been found to yield good performance [Beck90c]) of these
/// objects in the tree (termed 'forced reinsertion'). The node is only split
/// if it has been found to overflow after reinsertion has taken place.
/// This method is quite complex.
/// </remarks>
RStar
}
}
} // namespace Nuclex.Geometry.SpatialPartitioning

View file

@ -0,0 +1,35 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace Nuclex.Support.SpatialPartitioning {
/// <summary>Leaf of an R-Tree</summary>
internal class RTreeLeaf2<ItemType> {
public BoundingRectangle BoundingRectangle;
public ItemType Item;
}
} // namespace Nuclex.Support.SpatialPartitioning

View file

@ -0,0 +1,65 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Nuclex.Support.SpatialPartitioning {
/// <summary>Node in a two-dimensional R-Tree</summary>
/// <typeparam name="ItemType">Type of items that the R-Tree manages</typeparam>
internal class RTreeNode2<ItemType> {
/// <summary>Initializes a new R-Tree node</summary>
/// <param name="capacity">Number of items that can fit in the node</param>
public RTreeNode2(int capacity) {
this.leafs = new RTreeLeaf2<ItemType>[capacity];
}
/// <summary>Inserts an item into this node</summary>
/// <param name="item">Item to be inserted</param>
/// <param name="boundingRectangle">Bounding rectangle of the item</param>
private void insertEntry(ItemType item, BoundingRectangle boundingRectangle) {
Debug.Assert(leafCount < this.leafs.Length);
this.leafs[this.leafCount].Item = item;
this.leafs[this.leafCount].BoundingRectangle = boundingRectangle;
BoundingRectangle.CreateMerged(
ref this.boundingRectangle, ref boundingRectangle,
out this.boundingRectangle
);
}
/// <summary>The node's minimum bounding rectangle</summary>
/// <remarks>
/// This bounding rectangle is just large enough to contain all the items
/// belonging to this node and recursively all of its child nodes.
/// </remarks>
private BoundingRectangle boundingRectangle;
/// <summary>Leafs of this node</summary>
private RTreeLeaf2<ItemType>[] leafs;
/// <summary>Number of leafes in use</summary>
private int leafCount;
}
} // namespace Nuclex.Support.SpatialPartitioning

View file

@ -0,0 +1,30 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
namespace Nuclex.Support.SpatialPartitioning {
/// <summary>Interface for a 2D geometrical database</summary>
public abstract class SpatialIndex2 {
}
} // namespace Nuclex.Support.SpatialPartitioning