Skip to content

Commit

Permalink
make improvements of the 3d spatial lookup helper
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Jan 19, 2024
1 parent 91f0fb3 commit ee01e98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Data_science/Graph/Model/GridGraph/Grid2D.vb
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,27 @@ Namespace GridGraph
End Get
End Property

''' <summary>
''' get the max value of x axis
''' </summary>
''' <returns></returns>
''' <remarks>
''' this assuming that all x axis value is positive
''' </remarks>
Public ReadOnly Property width As Integer
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Get
Return matrix2D.Keys.Max
End Get
End Property

''' <summary>
''' get the max value of y axis
''' </summary>
''' <returns></returns>
''' <remarks>
''' this assuming that all y axis value is positive
''' </remarks>
Public ReadOnly Property height As Integer
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Get
Expand Down
23 changes: 23 additions & 0 deletions Data_science/Graph/Model/GridGraph/Spatial3D.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Namespace GridGraph
''' </summary>
''' <returns></returns>
Public ReadOnly Property size As Integer
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Get
Return Aggregate layer As Grid(Of T)
In matrix2D.Values.AsParallel
Expand All @@ -40,6 +41,14 @@ Namespace GridGraph
Me.toPoint = toPoint
End Sub

Public Function GetDimensions() As (xdims As Integer, ydims As Integer, zdims As Integer)
Dim z As Integer = matrix2D.Keys.Max
Dim x As Integer = Aggregate layer As Grid(Of T) In matrix2D.Values Into Max(layer.width)
Dim y As Integer = Aggregate layer As Grid(Of T) In matrix2D.Values Into Max(layer.height)

Return (x, y, z)
End Function

''' <summary>
''' implements the 3d spatial data lookup helper
''' </summary>
Expand All @@ -59,6 +68,20 @@ Namespace GridGraph
End If
End Function

''' <summary>
''' get the grid index for each layer on z axis
''' </summary>
''' <returns></returns>
''' <remarks>
''' the populate out layer has already been re-ordered by the z-axis order.
''' </remarks>
Public Iterator Function ZLayers() As IEnumerable(Of Grid(Of T))
For Each item In matrix2D.OrderBy(Function(lz) lz.Key)
Yield item.Value
Next
End Function

<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Shared Function CreateSpatial3D(Of E As {T, IPoint3D})(data As IEnumerable(Of T)) As Spatial3D(Of E)
Return Spatial3D(Of E).CreateSpatial3D(data, Function(a) a.X, Function(a) a.Y, Function(a) a.Z)
End Function
Expand Down

0 comments on commit ee01e98

Please sign in to comment.