Hello dear community and fellow developers!
I hope you are all having a nice day.
I am currently working in converting 3D models exported from IGES file into an HDF5 geometry file. I am using Paraview as the 3D Viewer for HDF5.
The purpose is to build a 3D integer (boolean 0-1) matrix which is a dataset in HDF5, out of the geometric parameters of the Data Entry (DE) and Parameter Data.
I want to know how can I build from this Entities geometric figures.
The HDF5 3D integer dataset works with a boolean mask of 0 and 1, where 1 is the background (free space) of the model and 0 is for the pixel where the 3D model is built.
@df.osorio11
Sorry for the delayed response.
Aspose.3D does not support IGES format now and HDF5 is not a 3D file. But we can provide a workaround/code snippet for this task.
This code snippet shows how to create a 3D byte array matrix from a Mesh(or Scene/Node, check the comment). Then you can use 3rd party HDF5 library to create a H5 file with 3D matrix.
private static void PointMatrix()
{
//Get your own Mesh from elsewhere, here we create a mesh from Sphere for demonstration
//You can also use PolygonModifier.MergeMesh() to create a merged mesh from a Scene or Node object
var geom = (new Sphere()).ToMesh();
//Convert mesh to point cloud first
var pointCloud = PointCloud.FromGeometry(geom);
var bbox = pointCloud.GetBoundingBox();
var size = bbox.Size;
var invSize = new Vector3(1.0 / size.x, 1.0 / size.y, 1.0 / size.z);
//the final matrix would be 512 * 512 * 512
var matrixZSize = 512;
var matrixYSize = 512;
var matrixXSize = 512;
var matrix = new byte[matrixXSize, matrixYSize, matrixZSize];
var matrixSize = new Vector3(matrixXSize - 1, matrixYSize - 1, matrixZSize - 1);
//map each point from the point cloud to the 3d matrix
for (int i = 0; i < pointCloud.ControlPoints.Count; i++)
{
var point = new Vector3(pointCloud.ControlPoints[i]);
//convert point to [0, 1]
var normalized = (point - bbox.Minimum) * invSize;
//convert point from to [0, size)
var pt = normalized * matrixSize;
//tag specified location in the matrix to 1
matrix[(int)pt.x, (int)pt.y, (int)pt.z] = 1;
}
//done, save the 3d matrix into file
unsafe
{
fixed(byte* p = matrix)
{
int bytes = matrixXSize * matrixYSize * matrixZSize;
var span = new ReadOnlySpan<byte>(p, bytes);
using var stream = new FileStream("matrix.bin", FileMode.Create);
stream.Write(span);
}
}
}