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. 與輸入幾何的誤差分布在菱角及曲面處。

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

可使用Stl或NativeStl物件初始化,使用NativeStl的速度較快。輸入的三角網格必須是流形幾何(manifold geometry),即三角形的頂點對齊其他三角形的頂點,且為封閉幾何。

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

Parameters

stl Stl
expectedResolution double

設定裕度,實際裕度會小於等於設定裕度,大約以2的指數作為級距。 與輸入幾何的誤差分布在菱角及曲面處。

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

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()

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

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

public ConcurrentBag<DiffAttachment> Diff(NativeStl idealGeom, double diffRadius, RangeColorRule diffRangeColorRule, IProgress<IProgressReport> 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<IProgressReport>

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

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

設定裕度,實際裕度會小於等於設定裕度,大約以2的指數作為級距。與輸入幾何的誤差分布在菱角及曲面處。裕度越大,三角網格數量越少,運算也較迅速。

Returns

List<Tri3d>

三角網格

RebuildAttach(CbtrPickable)

Every node in CubeTree can contain one CbtrPickable object. This function put or replace the contained data of all nodes to src. 使用UpdateAttach(CbtrPickable)會將尚未儲存資料(CbtrPickable為null)的節點放入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)

使用BufferedTris效率比NativeStl好。 若差集區域的裕度與本體的裕度不同,則該部位採用較低的裕度。

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

Parameters

cutterBufferedTris CachedTris

差集幾何

preferredCubeWidth double

The preferred cube width for the operation.

isBuildContactContours bool

為真,則回傳的Substraction中含有差集幾何與工件幾何相交處的圍線群,該圍線群可做後續分析使用。

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)

與Substract(BufferedTris,...)同功能。效率較差,多了一個轉換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.