Click or drag to resize
AB4D logo

OptimizedPointMeshT Class

OptimizedPointMesh class is used to show point cloud and can dynamically reduce the number of rendered positions to improver rendering performance. It creates one Vertex buffer and multiple Index buffers that are used to provide different level of optimized sub-sets of all the vertices.
Inheritance Hierarchy
SystemObject
  Ab3d.DirectXDXResourceBase
    Ab3d.DirectXSharedDXResource
      Ab3d.DirectXSharedDXDeviceResource
        Ab3d.DirectXMeshBase
          Ab3d.DirectXOptimizedPointMeshT

Namespace: Ab3d.DirectX
Assembly: Ab3d.DXEngine (in Ab3d.DXEngine.dll) Version: 7.0.8865.1045
Syntax
C#
public class OptimizedPointMesh<T> : MeshBase
where T : struct, new()

Type Parameters

T
struct that holds data for one vertex - for example Ab3d.DirectX.PositionNormal

The OptimizedPointMeshT type exposes the following members.

Constructors
Properties
 NameDescription
Public propertyOptimizePositions Gets or sets a Boolean that specifies if smart point reduction algorithm is used to skip rendering positions that are close together.
Public propertyPositionsArray Gets the array of Vector3 elements that define the positions for this OptimizedPointMesh.
Public propertyRenderOnlyVisibleSegments Gets or sets a Boolean that specifies if only visible segments are rendered. When RenderOnlyVisibleSegments is true, the UpdateVisibleSegments(Matrix) method must be called before rendering.
Public propertyVertexBufferArray Gets or sets an array of T structs that define the vertex buffer
Top
Methods
 NameDescription
Public methodGetClosestPositionIndex(Ray) Returns an index of the position that is the closest to the specified ray. The method is highly optimized and checks only the segments that ray goes through (ray intersects segment's bounding box) and this significantly reduces the number of checked positions. When no segment is hit by the ray, then -1 is returned. To also get the distance to the ray use the GetClosestPositionIndex(Ray, Single).
Public methodGetClosestPositionIndex(Ray, Single) Returns an index of the position that is the closest to the specified ray. The method also sets the distance to the out parameter. The method is highly optimized and checks only the segments that ray goes through (ray intersects segment's bounding box) and this significantly reduces the number of checked positions. When no segment is hit by the ray, then -1 is returned and distance is set to NaN.
Public methodStatic memberGetPixel3DSize GetPixel3DSize returns size of one pixel at specified position on screen based on the specified camera and view width. For example, value 5 means a box at the specified position and with size set to 5 will be rendered to 1 pixel on screen.
Public methodGetPositionIndexesAroundRay(Ray, Single, Boolean, Int32) GetPositionIndexesAroundRay method returns a list of position indexes that are closer to the ray then the specified maxDistance. By default (when orderByDistanceToRayPosition is true) the position are ordered by the distance to the ray's Position. When maxResultsCount is set to a bigger number then 0, then it is possible to limit the number of returned indexes. To prevent creating List object on each call to this method, call the overload that takes the List object as ref.
Public methodGetPositionIndexesAroundRay(Ray, Single, ListInt32, Boolean, Int32) GetPositionIndexesAroundRay method returns a list of position indexes that are closer to the ray then the specified maxDistance. By default (when orderByDistanceToRayPosition is true) the position are ordered by the distance to the ray's Position. When maxResultsCount is set to a bigger number then 0, then it is possible to limit the number of returned indexes.
Public methodOptimize Optimize method optimizes the positions with preparing the segments and data views that will be used for different camera positions. This method should be call after a bigger change of the Viewport3D's size.
Public methodRenderGeometry RenderGeometry renders the geometry (executes draw calls but does not apply material settings)
Public methodUpdateVisibleSegments UpdateVisibleSegments method gets camera's worldViewProjectionMatrix as parameter and updates which segments are visible and will be rendered in the next rendering pass. When worldViewProjectionMatrix parameter is Identity then all segments are shown.
Top
Fields
 NameDescription
Public fieldMaxOptimizationViewsCount MaxOptimizationViewsCount specifies maximum number of views (Index buffers) for each segment. Default value is 10.
Public fieldOptimizationIndicesNumberThreshold OptimizationIndicesNumberThreshold specifies at which number of indices user is satisfied with performance and no more views (Index buffers) will be created. When number of indices defined in all segments is less then the number specified in this field, then no more views are created. Smaller value can create more optimization views and can take longer to initialize. Default value is 100000.
Public fieldUseMultiThreadedAnalysis UseMultiThreadedAnalysis specifies if generation of optimization views is run on multiple threads. Default value is true.
Top
Remarks

OptimizedPointMesh class is used to show point cloud with optimized number of shown points.

It creates one Vertex buffer and multiple Index buffers that are used to provide different level of optimized sub-sets of all the vertices.

OptimizedPointMesh also support hit testing. To get the position index of the closest position, call the GetClosestPositionIndex(Ray, Single) or GetClosestPositionIndex(Ray) method. To get all position indexes that are close to the specified ray use the GetPositionIndexesAroundRay(Ray, Single, ListInt32, Boolean, Int32) or GetPositionIndexesAroundRay(Ray, Single, Boolean, Int32) method. All those methods are highly optimized and check only the segments that ray goes through (ray intersects segment's bounding box) and this significantly reduces the number of checked positions.

OptimizedPointMesh uses two techniques to do the optimization:
1)
Divide all the positions into multiple segments and when rendering it checks bounding box of each segment to determine if it is visible on the screen on not. Number of segments is defined in the OptimizedPointMesh constructor.

2)
For each segment multiple optimization views (Index Buffers) are created where the number of positions is defined by the pixel size on the screen and how close together the positions are (positions that are closer then size of one pixel are rendered as one pixel). Number of views is defined by MaxOptimizationViewsCount and OptimizationIndicesNumberThreshold properties.

Before OptimizedPointMesh can be rendered for the first time, the Optimize(Size2, Double) method must be called. It generates the Index Buffers for the segments based on the size of Viewport and size of pixel. This method can take a while to execute so call it only when the size of Viewport or pixel is changed.

To determine which segments are visible and which are hidden, the UpdateVisibleSegments(Matrix) method needs to be called before rendering.

Then you can call RenderGeometry(RenderingContext) method.

IMPORTANT:
It is very important that the positions are organized in such a way that the positions that are close together in 3D space are also close together in positions array. This way the OptimizedPointMesh will be able to efficiently group positions into segments and render only one position instead of multiple positions that are close together.

Please contact support@ab4d.com to get more information about the OptimizedPointMesh.

See Also