Table of Contents

Class CubeTree

Namespace
Hi.Cbtr
Assembly
HiCbtr.dll

Cube-based data structure. CubeTree has high performance for free-form geometry manipulation include volume removal and addition.

public class CubeTree : IDisposable, IDisplayee, ICollidee, ICollidable, IExpandToBox3d, IGetCollidable
Inheritance
CubeTree
Implements
Inherited Members
Extension Methods

Constructors

CubeTree(NativeStl, double, CancellationToken, IProgress<IProgressReport>)

public CubeTree(NativeStl stl, double preferredGridWidth, CancellationToken token, IProgress<IProgressReport> progress)

Parameters

stl NativeStl

Triangle Grid. The triangles must be manifold geometry.

preferredGridWidth double

The expected resolution.

token CancellationToken

Cancellation token for the operation

progress IProgress<IProgressReport>

Progress reporter for the operation

Remarks

The applied resolution is equal or smaller than the expected resolution. The applied resolution is c*(2^i). Where c is a constant; i is a integer to make the closest value of the formula. Errors relative to the input geometry are distributed at sharp edges and curved surfaces.

CubeTree(Stl, double, CancellationToken, IProgress<IProgressReport>)

Can be initialized with Stl or NativeStl objects; using NativeStl is faster. The input triangle mesh must be manifold geometry, i.e., triangle vertices are aligned with other triangles' vertices, and the geometry must be closed.

public CubeTree(Stl stl, double expectedResolution, CancellationToken token, IProgress<IProgressReport> progress)

Parameters

stl Stl
expectedResolution double

Sets the preferred resolution. The actual resolution will be equal to or smaller than the specified value, approximately spaced by powers of 2. Errors relative to the input geometry are distributed at sharp edges and curved surfaces.

token CancellationToken

Cancellation token for the operation

progress IProgress<IProgressReport>

Progress reporter for the operation

CubeTree(string)

Initializes a new instance of the CubeTree class from a file.

public CubeTree(string file)

Parameters

file string

The path to the cube tree file.

Fields

KeyDll

Key dll path.

public const string KeyDll = "hi-key.dll"

Field Value

string

defaultPreferredGridWidth

The default grid_width for the constructor.

public const double defaultPreferredGridWidth = 0.0625

Field Value

double

Properties

CollisionFlag

Gets or sets the collision flag.

public CollisionFlag CollisionFlag { get; set; }

Property Value

CollisionFlag

CubetreePtr

Private element.

public nint CubetreePtr { get; }

Property Value

nint

DispCacheMb

Display cache size in Mb. The cahce cost from graphic card and RAM.

public static long DispCacheMb { get; set; }

Property Value

long

Resolution

Get initialized resolution.

public double Resolution { get; }

Property Value

double

TotalCacheMb

Cache size used by CubeTree. Sum of TrisCacheMb and DispCacheMb. TotalCacheMb Setter distributes (2/5 of the setting value) for DispCacheMb.

public static long TotalCacheMb { get; set; }

Property Value

long

TrisCacheMb

Triangles cache size in Mb. The cache costs from RAM.

public static long TrisCacheMb { get; set; }

Property Value

long

Methods

CleanCache()

Call Hi.Cbtr.CubeTree.CleanTrisCache() and Hi.Cbtr.CubeTree.CleanDispCache_().

public static void CleanCache()

CleanDispCachee()

Clean display cache of this.

public void CleanDispCachee()

ContainsInfEdgeCuts()

Checks if any existing node in the cube tree contains inf or -inf in its edge_cuts array.

public bool ContainsInfEdgeCuts()

Returns

bool

true if any node contains inf or -inf in edge_cuts, false otherwise.

Diff(NativeStl, double, RangeColorRule, IProgress<object>)

Compares the cube tree with an ideal geometry and returns difference attachments.

public ConcurrentBag<DiffAttachment> Diff(NativeStl idealGeom, double diffRadius, RangeColorRule diffRangeColorRule, IProgress<object> progress = null)

Parameters

idealGeom NativeStl

The ideal geometry to compare with.

diffRadius double

The radius for difference detection.

diffRangeColorRule RangeColorRule

The color rule for visualizing differences.

progress IProgress<object>

Progress reporter for the operation.

Returns

ConcurrentBag<DiffAttachment>

A collection of difference attachments.

Display(Bind)

Display function called in DispEngine rendering loop.

public void Display(Bind bind)

Parameters

bind Bind

Bind with DispEngine. See Bind.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

ExpandToBox3d(Box3d)

Expands the destination box. This function is usually used to compute the bounding box of elements.

public void ExpandToBox3d(Box3d dst)

Parameters

dst Box3d

Destination box

~CubeTree()

dtor

protected ~CubeTree()

GetCollidable()

Gets the collidable object.

public ICollidable GetCollidable()

Returns

ICollidable

The collidable object (this instance).

GetCollidee()

Get ICollidee.

public ICollidee GetCollidee()

Returns

ICollidee

ICollidee

GetInfEdgeCutsInfo()

Gets info for all nodes that contain inf or -inf in their edge_cuts array. Each node's box is grouped with its corresponding inf edge indices. This is useful for identifying and visualizing non-manifold geometry issues in the cube tree.

public List<CubeTree.InfNodeInfo> GetInfEdgeCutsInfo()

Returns

List<CubeTree.InfNodeInfo>

A list of node info, each containing a box and its inf edge indices.

GetRgbTrisNativeArray(double)

Get triangles in type of double array. The returned triangles is non-manifold. It may not be closed model and the apexes of triangle grid may not be overlapped.

public double[] GetRgbTrisNativeArray(double resolution = 0)

Parameters

resolution double

The preferred resolution. The real resolution may be smaller or equal the prefered resolution. The real resolution is discrete. The resolution value is at 2^i. The geometric error mainly locate at corner.

Returns

double[]

rgb traingle grid. In sequence of r,g,b,n.x,n.y,n.z,p0.x,p0.y,p0.z,p1.x,p1.y,p1.z,p2.x,p2.y,p2.z, repetitively. A triangle take 15 double.

GetTris(double)

Get triangles. The returned triangles is non-manifold. It may not be closed model and the apexes of triangle grid may not be overlapped.

public List<Tri3d> GetTris(double resolution = 0)

Parameters

resolution double

Sets the preferred resolution. The actual resolution will be equal to or smaller than the specified value, approximately spaced by powers of 2. Errors relative to the input geometry are distributed at sharp edges and curved surfaces. A larger resolution results in fewer triangles and faster computation.

Returns

List<Tri3d>

Triangle mesh

NewWithDefectInfos(NativeStl, double, CancellationToken, IProgress<object>)

Creates a new CubeTree and collects defect node infos during construction.

public static (CubeTree cubeTree, List<CubeTree.DefectNodeInfo> defectInfos) NewWithDefectInfos(NativeStl stl, double preferredGridWidth, CancellationToken token, IProgress<object> progress)

Parameters

stl NativeStl
preferredGridWidth double
token CancellationToken
progress IProgress<object>

Returns

(CubeTree cubeTree, List<CubeTree.DefectNodeInfo> defectInfos)

NewWithDefectInfos(Stl, double, CancellationToken, IProgress<object>)

Creates a new CubeTree and collects defect node infos during construction.

public static (CubeTree cubeTree, List<CubeTree.DefectNodeInfo> defectInfos) NewWithDefectInfos(Stl stl, double preferredGridWidth, CancellationToken token, IProgress<object> progress)

Parameters

stl Stl
preferredGridWidth double
token CancellationToken
progress IProgress<object>

Returns

(CubeTree cubeTree, List<CubeTree.DefectNodeInfo> defectInfos)

RebuildAttach(CbtrPickable)

Every node in CubeTree can contain one CbtrPickable object. This function put or replace the contained data of all nodes to src. Using UpdateAttach(CbtrPickable) will place nodes that have not yet stored data (CbtrPickable is null) into src.

public void RebuildAttach(CbtrPickable src)

Parameters

src CbtrPickable

RemoveFlyPiece()

Removes disconnected pieces (fly pieces) from the cube tree.

public void RemoveFlyPiece()

Substract(CachedTris, double, bool, bool)

Using BufferedTris is more efficient than NativeStl. If the resolution of the subtraction region differs from the body's resolution, the lower resolution is applied to that region.

public UnmanagedSubstraction Substract(CachedTris cutterBufferedTris, double preferredCubeWidth, bool isBuildContactContours = false, bool isAggressiveCut = false)

Parameters

cutterBufferedTris CachedTris

Subtraction geometry

preferredCubeWidth double

The preferred cube width for the operation.

isBuildContactContours bool

If true, the returned Substraction contains contour groups at the intersection of the subtraction geometry and the workpiece geometry, which can be used for further analysis.

isAggressiveCut bool

If true, uses aggressive cutting mode.

Returns

UnmanagedSubstraction

Substract(GeomBoolCache, bool, bool)

Subtracts a geometry from the cube tree using a geometry boolean cache.

public UnmanagedSubstraction Substract(GeomBoolCache geomBoolCache, bool isBuildContactContours = false, bool isAggressiveCut = false)

Parameters

geomBoolCache GeomBoolCache

The geometry boolean cache containing the geometry to subtract.

isBuildContactContours bool

If true, the returned Substraction will contain contact contours.

isAggressiveCut bool

If true, uses aggressive cutting mode.

Returns

UnmanagedSubstraction

The result of the subtraction operation.

Substract(InitStickConvex, Mat4d, double, bool, bool)

Subtracts a stick convex geometry from the cube tree.

public UnmanagedSubstraction Substract(InitStickConvex initStickConvex, Mat4d mat, double preferredCubeWidth, bool isBuildContactContours = false, bool isAggressiveCut = false)

Parameters

initStickConvex InitStickConvex

The stick convex geometry to subtract.

mat Mat4d

The transformation matrix to apply to the stick convex.

preferredCubeWidth double

The preferred cube width for the operation.

isBuildContactContours bool

If true, the returned Substraction will contain contact contours.

isAggressiveCut bool

If true, uses aggressive cutting mode.

Returns

UnmanagedSubstraction

The result of the subtraction operation.

Substract(NativeStl, double, bool, bool)

Same functionality as Substract(BufferedTris,...). Less efficient due to the additional step of converting to CachedTris.

public UnmanagedSubstraction Substract(NativeStl cutterStl, double preferredCubeWidth = 0, bool isBuildContactContours = false, bool isAggressiveCut = false)

Parameters

cutterStl NativeStl
preferredCubeWidth double
isBuildContactContours bool
isAggressiveCut bool

Returns

UnmanagedSubstraction

TestDiff(out CubeTree, out NativeStl)

Tests the difference calculation between a cube tree and an ideal geometry.

public static void TestDiff(out CubeTree cubeTree_, out NativeStl idealGeom_)

Parameters

cubeTree_ CubeTree

The resulting cube tree.

idealGeom_ NativeStl

The ideal geometry used for comparison.

TestIO()

Tests the input/output operations for a cube tree.

public static CubeTree TestIO()

Returns

CubeTree

The cube tree created or loaded during the test.

TestSimpleRemove(out CubeTree)

Tests the simple removal operation on a cube tree.

public static void TestSimpleRemove(out CubeTree cubeTree_)

Parameters

cubeTree_ CubeTree

The resulting cube tree after the removal operation.

UpdateAttach(CbtrPickable)

Every node in CubeTree can contain one CbtrPickable object. This function put src to the nodes that contain null.

public void UpdateAttach(CbtrPickable src)

Parameters

src CbtrPickable

WriteFile(string)

Writes the cube tree to a file.

public void WriteFile(string file)

Parameters

file string

The path where the cube tree will be written.