Show / Hide Table of Contents

    Class AdaptiveGrid

    A graph like edge-vertex structure with planar spaces connected by vertical edges. The grid doesn't do any intersections when new sections are added, they are stitched only by common vertices. Make sure that regions that are added into the graph are aligned with respect to boundaries and split points.

    Examples
    
    var adaptiveGrid = new AdaptiveGrid();
    var points = new List<Vector3>()
    {
        new Vector3(-6, -4),
        new Vector3(-2, -4),
        new Vector3(3, -4),
        new Vector3(1, 4.5),
        new Vector3(6, 3),
    };
    adaptiveGrid.AddFromPolygon(Polygon.Rectangle(15, 10).TransformedPolygon(
        new Transform(new Vector3(), new Vector3(10, 0, 10))), points);
    
    
    Inheritance
    System.Object
    AdaptiveGrid
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Elements.Spatial.AdaptiveGrid
    Assembly: Hypar.Elements.dll
    Syntax
    public class AdaptiveGrid

    Constructors

    AdaptiveGrid()

    Create default AdaptiveGrid

    Declaration
    public AdaptiveGrid()

    AdaptiveGrid(Transform)

    Create an AdaptiveGrid with custom transformation.

    Declaration
    public AdaptiveGrid(Transform transform)
    Parameters
    Type Name Description
    Transform transform

    Transformation, grid is aligned with.

    Properties

    Boundaries

    Grid boundary used in obstacle perimeter clipping. Can be null.

    Declaration
    public Polygon Boundaries { get; set; }
    Property Value
    Type Description
    Polygon

    HintExtendDistance

    Maximum distance for line segments of hints lines to extend to other existing edges.

    Declaration
    public double HintExtendDistance { get; set; }
    Property Value
    Type Description
    System.Double

    Tolerance

    Distance tolerance for points being considered the same. Tolerance is twice the epsilon because grid uses single tolerance for individual coordinates snapping.

    Declaration
    public double Tolerance { get; }
    Property Value
    Type Description
    System.Double

    Transform

    Transformation with which planar spaces are aligned

    Declaration
    public Transform Transform { get; set; }
    Property Value
    Type Description
    Transform

    Methods

    AddEdge(Vector3, Vector3, Boolean)

    Add an edge between two vertices represented by their position. Positions that are not yet present in the grid are created as new vertices.

    Declaration
    public List<Edge> AddEdge(Vector3 a, Vector3 b, bool cut = true)
    Parameters
    Type Name Description
    Vector3 a
    Vector3 b
    System.Boolean cut

    Intersect new edge with existing edges.

    Returns
    Type Description
    System.Collections.Generic.List<Edge>

    Edges between two vertices. Single if cut is false.

    AddEdge(Vertex, Vertex, Boolean)

    Add an edge between two vertices.

    Declaration
    public List<Edge> AddEdge(Vertex a, Vertex b, bool cut = true)
    Parameters
    Type Name Description
    Vertex a

    First vertex.

    Vertex b

    Second vertex.

    System.Boolean cut

    Intersect new edge with existing edges.

    Returns
    Type Description
    System.Collections.Generic.List<Edge>

    Edges between two vertices. Single if cut is false.

    AddEdge(UInt64, UInt64, Boolean)

    Add an edge between two vertices represented by their ids.

    Declaration
    public List<Edge> AddEdge(ulong vertexId1, ulong vertexId2, bool cut = true)
    Parameters
    Type Name Description
    System.UInt64 vertexId1

    Id of the first vertex.

    System.UInt64 vertexId2

    Id of the second vertex.

    System.Boolean cut

    Intersect new edge with existing edges.

    Returns
    Type Description
    System.Collections.Generic.List<Edge>

    Edges between two vertices. Single if cut is false.

    AddFromBbox(BBox3, List<Vector3>)

    Add graph section using bounding box, divided by a set of key points. Key points don't respect "MinimumResolution" at the moment. Any vertices that already exist are not created but reused. This way new region is connected with the rest of the graph.

    Declaration
    public void AddFromBbox(BBox3 bBox, List<Vector3> keyPoints)
    Parameters
    Type Name Description
    BBox3 bBox

    Box which region is populated with graph.

    System.Collections.Generic.List<Vector3> keyPoints

    Set of 3D points, region is split with.

    Examples
    
    var adaptiveGrid = new AdaptiveGrid();
    var points = new List<Vector3>()
    {
        new Vector3(-6, -4),
        new Vector3(-2, -4),
        new Vector3(3, -4),
        new Vector3(1, 4.5, 3),
        new Vector3(6, 3, -2),
    };
    adaptiveGrid.AddFromBbox(new BBox3(new Vector3(-7.5, -5, -3), new Vector3(10, 10, 3)), points);
    
    points = new List<Vector3>()
    {
        new Vector3(-6, -4, 3),
        new Vector3(-2, 0, 3),
        new Vector3(0, 4, 3),
        new Vector3(2, 6, 3)
    };
    var rectangle = Polygon.Rectangle(new Vector3(-10, -5), new Vector3(15, 10));
    adaptiveGrid.AddFromPolygon(rectangle.TransformedPolygon(new Transform(new Vector3(0, 0, 3))), points);
    points = new List<Vector3>()
    {
        new Vector3(-6, -4, 2),
        new Vector3(-2, 0, 2),
        new Vector3(0, 4, 2),
        new Vector3(2, 6, 2)
    };
    adaptiveGrid.AddFromPolygon(rectangle.TransformedPolygon(new Transform(new Vector3(0, 0, 2))), points);
    
    

    AddFromExtrude(Polygon, Vector3, Double, List<Vector3>)

    Add graph section using polygon, extruded in given direction. Any vertices that already exist are not created but reused. This way new region is connected with the rest of the graph.

    Declaration
    public void AddFromExtrude(Polygon boundingPolygon, Vector3 extrusionAxis, double distance, List<Vector3> keyPoints)
    Parameters
    Type Name Description
    Polygon boundingPolygon

    Base polygon

    Vector3 extrusionAxis

    Extrusion direction

    System.Double distance

    Height of polygon extrusion

    System.Collections.Generic.List<Vector3> keyPoints

    Set of 3D points, region is split with.

    AddFromPolygon(Polygon, IEnumerable<Vector3>)

    Add single planar region to the graph section using polygon. Any vertices that already exist are not created but reused. This way new region is connected with the rest of the graph.

    Declaration
    public HashSet<Edge> AddFromPolygon(Polygon boundingPolygon, IEnumerable<Vector3> keyPoints)
    Parameters
    Type Name Description
    Polygon boundingPolygon

    Base polygon

    System.Collections.Generic.IEnumerable<Vector3> keyPoints

    Set of 3D points, region is split with.

    Returns
    Type Description
    System.Collections.Generic.HashSet<Edge>

    AddVertex(Vector3)

    Add a Vertex or return existing one if it's withing grid tolerance. Doesn't connect new Vertex to the grid with edges.

    Declaration
    public Vertex AddVertex(Vector3 point)
    Parameters
    Type Name Description
    Vector3 point

    Position of required vertex

    Returns
    Type Description
    Vertex

    New or existing Vertex.

    AddVertex(Vector3, IAddVertexStrategy, Boolean)

    Add a Vertex and connect in to one or more other vertices.

    Declaration
    public Vertex AddVertex(Vector3 point, IAddVertexStrategy strategy, bool cut = true)
    Parameters
    Type Name Description
    Vector3 point

    Position of required Vertex.

    IAddVertexStrategy strategy

    Vertex insertion strategy.

    System.Boolean cut

    Should new edges be intersected with existing edges.

    Returns
    Type Description
    Vertex

    New Vertex or existing one if it's within grid tolerance.

    AddVertices(IList<Vector3>, AdaptiveGrid.VerticesInsertionMethod)

    Create a chain of vertices. Exact behavior depends on the method used.

    Declaration
    public List<Vertex> AddVertices(IList<Vector3> points, AdaptiveGrid.VerticesInsertionMethod method)
    Parameters
    Type Name Description
    System.Collections.Generic.IList<Vector3> points

    List of points to insert. Must have at least two points.

    AdaptiveGrid.VerticesInsertionMethod method

    Insertion method.

    Returns
    Type Description
    System.Collections.Generic.List<Vertex>

    Vertices in order between provided points. Depends on used method.

    AddVerticesWithCustomExtension(IList<Vector3>, Double)

    Intersect points into grid and connect them into edges. New edges are intersected along intersection points. End points of each segment are extended up to given distance until the next hit on both sides. If not extended, point is connected to the grid at its position.

    Declaration
    public List<Vertex> AddVerticesWithCustomExtension(IList<Vector3> points, double extendDistance)
    Parameters
    Type Name Description
    System.Collections.Generic.IList<Vector3> points

    Points to add and connect to the grid.

    System.Double extendDistance

    Distance at which lines are extended to existing edges.

    Returns
    Type Description
    System.Collections.Generic.List<Vertex>

    Vertices in order they are inserted, including already existing. Can contain duplicates.

    ClosestEdge(Vector3, out Vector3)

    Find closest Edge on the grid to given location. If several edges are no the same closest distance - first found is returned.

    Declaration
    public Edge ClosestEdge(Vector3 location, out Vector3 point)
    Parameters
    Type Name Description
    Vector3 location

    Position to which closest Vertex is searched.

    Vector3 point

    Closest point of the found edge line.

    Returns
    Type Description
    Edge

    Closest Edge

    ClosestVertex(Vector3)

    Find closest Vertex on the grid to given location. If several vertices are no the same closest distance - first found is returned.

    Declaration
    public Vertex ClosestVertex(Vector3 location)
    Parameters
    Type Name Description
    Vector3 location

    Position to which closest Vertex is searched.

    Returns
    Type Description
    Vertex

    Closest Vertex

    CutEdge(Edge, Vector3)

    Split provided edge by given point. Edge is removed and replaced by two new edges. New vertex position is not required to be in the edge line.

    Declaration
    public Vertex CutEdge(Edge edge, Vector3 position)
    Parameters
    Type Name Description
    Edge edge

    Edge to cut.

    Vector3 position

    Cut position where new Vertex is created.

    Returns
    Type Description
    Vertex

    New Vertex at cut position.

    GetEdges()

    Get all Edges.

    Declaration
    public List<Edge> GetEdges()
    Returns
    Type Description
    System.Collections.Generic.List<Edge>

    GetLine(Edge)

    Get the geometry that represents this Edge or DirectedEdge.

    Declaration
    public Line GetLine(Edge edge)
    Parameters
    Type Name Description
    Edge edge
    Returns
    Type Description
    Line

    GetVertex(UInt64)

    Get a Vertex by its ID.

    Declaration
    public Vertex GetVertex(ulong vertexId)
    Parameters
    Type Name Description
    System.UInt64 vertexId
    Returns
    Type Description
    Vertex

    GetVertices()

    Get all Vertices.

    Declaration
    public List<Vertex> GetVertices()
    Returns
    Type Description
    System.Collections.Generic.List<Vertex>

    GetVertices(Edge)

    Get associated Vertices.

    Declaration
    public List<Vertex> GetVertices(Edge edge)
    Parameters
    Type Name Description
    Edge edge
    Returns
    Type Description
    System.Collections.Generic.List<Vertex>

    InsertSnapshot(List<(Vector3 Start, Vector3 End)>, Transform, Boolean)

    Duplicate stored edges with transformation applied. Use with InsertSnapshot to move a list of existing or previously existed edges to the new location, for example, copy edges from one elevation to another.

    Declaration
    public void InsertSnapshot(List<(Vector3 Start, Vector3 End)> storedEdges, Transform transform, bool connect = true)
    Parameters
    Type Name Description
    System.Collections.Generic.List<System.ValueTuple<Vector3, Vector3>> storedEdges

    Edge positions to duplicate.

    Transform transform

    Transformation to apply to all of the new edges.

    System.Boolean connect

    Optional. Connect each new vertex with it's original vertex if it still exist.

    RemoveEdge(Edge)

    Remove the Edge from the grid.

    Declaration
    public void RemoveEdge(Edge edge)
    Parameters
    Type Name Description
    Edge edge

    Edge to delete

    RemoveVertex(Vertex)

    Remove the Vertex from the grid. All it's edges are removed as well, including any neighbor vertices that are left without edges.

    Declaration
    public void RemoveVertex(Vertex v)
    Parameters
    Type Name Description
    Vertex v

    Vertex to delete.

    SnapshotEdgesOnPlane(Plane, IEnumerable<Edge>)

    Store points of edges both vertices of which are located at the given plane. Use with InsertSnapshot to duplicate vertices to a new elevation, while allowing modification of the original edges before duplication takes place.

    Declaration
    public List<(Vector3 Start, Vector3 End)> SnapshotEdgesOnPlane(Plane plane, IEnumerable<Edge> edgesToCheck = null)
    Parameters
    Type Name Description
    Plane plane

    Plane to retrieve edges from.

    System.Collections.Generic.IEnumerable<Edge> edgesToCheck

    Optional. Edges to check, all by default .

    Returns
    Type Description
    System.Collections.Generic.List<System.ValueTuple<Vector3, Vector3>>

    Position pair for each edge stored.

    SubtractObstacle(Obstacle)

    Intersect the grid with an obstacle, defined from a set of points with offset.

    Declaration
    public bool SubtractObstacle(Obstacle obstacle)
    Parameters
    Type Name Description
    Obstacle obstacle

    Obstacle object.

    Returns
    Type Description
    System.Boolean

    True if obstacle intersects with any edge on the grid.

    SubtractObstacles(IEnumerable<Obstacle>)

    Intersect the grid with a list of obstacles.

    Declaration
    public bool SubtractObstacles(IEnumerable<Obstacle> obstacles)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<Obstacle> obstacles

    List of obstacles.

    Returns
    Type Description
    System.Boolean

    True if any obstacle intersects with any edge on the grid.

    TryGetVertexIndex(Vector3, out UInt64)

    Whether a vertex location already exists in the AdaptiveGrid. A vertex with each coordinate less than AdaptiveGrid.Tolerance away is considered suitable.

    Declaration
    public bool TryGetVertexIndex(Vector3 point, out ulong id)
    Parameters
    Type Name Description
    Vector3 point
    System.UInt64 id

    The ID of the Vertex, if a match is found.

    Returns
    Type Description
    System.Boolean

    True if any Vertex is close enough.