Class CubeTree
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>)
Ctor. This ctor is faster than CubeTree(NativeStl, double, CancellationToken, IProgress<IProgressReport>).
public CubeTree(NativeStl stl, double preferredGridWidth, CancellationToken token, IProgress<IProgressReport> progress)
Parameters
stlNativeStlTriangle Grid. The triangles must be manifold geometry.
preferredGridWidthdoubleThe expected resolution.
tokenCancellationTokenCancellation token for the operation
progressIProgress<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
stlStlexpectedResolutiondoubleSets 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.
tokenCancellationTokenCancellation token for the operation
progressIProgress<IProgressReport>Progress reporter for the operation
CubeTree(string)
Initializes a new instance of the CubeTree class from a file.
public CubeTree(string file)
Parameters
filestringThe path to the cube tree file.
Fields
KeyDll
Key dll path.
public const string KeyDll = "hi-key.dll"
Field Value
defaultPreferredGridWidth
The default grid_width for the constructor.
public const double defaultPreferredGridWidth = 0.0625
Field Value
Properties
CollisionFlag
Gets or sets the collision flag.
public CollisionFlag CollisionFlag { get; set; }
Property Value
CubetreePtr
Private element.
public nint CubetreePtr { get; }
Property Value
DispCacheMb
Display cache size in Mb. The cahce cost from graphic card and RAM.
public static long DispCacheMb { get; set; }
Property Value
Resolution
Get initialized resolution.
public double Resolution { get; }
Property Value
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
TrisCacheMb
Triangles cache size in Mb. The cache costs from RAM.
public static long TrisCacheMb { get; set; }
Property Value
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
idealGeomNativeStlThe ideal geometry to compare with.
diffRadiusdoubleThe radius for difference detection.
diffRangeColorRuleRangeColorRuleThe color rule for visualizing differences.
progressIProgress<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
bindBindBind 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
disposingbool
ExpandToBox3d(Box3d)
Expands the destination box. This function is usually used to compute the bounding box of elements.
public void ExpandToBox3d(Box3d dst)
Parameters
dstBox3dDestination 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
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
resolutiondoubleThe 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
resolutiondoubleSets 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
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
stlNativeStlpreferredGridWidthdoubletokenCancellationTokenprogressIProgress<object>
Returns
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
stlStlpreferredGridWidthdoubletokenCancellationTokenprogressIProgress<object>
Returns
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
srcCbtrPickable
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
cutterBufferedTrisCachedTrisSubtraction geometry
preferredCubeWidthdoubleThe preferred cube width for the operation.
isBuildContactContoursboolIf 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.
isAggressiveCutboolIf true, uses aggressive cutting mode.
Returns
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
geomBoolCacheGeomBoolCacheThe geometry boolean cache containing the geometry to subtract.
isBuildContactContoursboolIf true, the returned Substraction will contain contact contours.
isAggressiveCutboolIf 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
initStickConvexInitStickConvexThe stick convex geometry to subtract.
matMat4dThe transformation matrix to apply to the stick convex.
preferredCubeWidthdoubleThe preferred cube width for the operation.
isBuildContactContoursboolIf true, the returned Substraction will contain contact contours.
isAggressiveCutboolIf 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
Returns
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_CubeTreeThe resulting cube tree.
idealGeom_NativeStlThe 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_CubeTreeThe 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
srcCbtrPickable
WriteFile(string)
Writes the cube tree to a file.
public void WriteFile(string file)
Parameters
filestringThe path where the cube tree will be written.