# Voxel

Let’s assume there is a 3D grid of voxels like below. Filled voxels represent a 3D model and empty voxels represent space.

# Loop over voxels

Shown by this pseudocode, the iteration over voxels is done by their `x, y, z` index:

``````for x := 1, Nx;
for y := 1, Ny;
for z := 1, Nz;
if voxelIsEmpty continue;
// 3D coordinates of 8 voxel corners are floating-point values.
voxelCornersX = [x1, x2, x3, x4, x5, x6, x7, x8];
voxelCornersY = [y1, y2, y3, y4, y5, y6, y7, y8];
voxelCornersZ = [z1, z2, z3, z4, z5, z6, z7, z8];
// TODO: create a hexahedral element by the 8 corners.
endfor
endfor
endfor
``````

# Question

How can I create a single hex element for a filled voxel, if the voxel corner coordinates are known?

As far as I study the documentation, the CGX should be used by creating a geometry (line, surface, volume) and then creating finite elements through the geometry. The problem is that I don’t create a geometry in advance. I’m a bit confused. I appreciate any hints. Thanks.

I’m studying examples like this, to figure out how to:

Currently, I’m generating finite elements by a data structure in Golang. While iterating over the voxels, the data structure stores elements by their corner coordinates and has functions to write nodes, elements, restraints, and loads as an `INP` file.

But I’m thinking of replacing the Golang data structure. I can imagine writing CGX commands to an `FBD` file line by line while I’m iterating over the voxels. I can imagine writing any other needed command to the `FBD` file. Then I will generate the final `INP` file by calling CGX with the `FBD` file as a parameter. These are all imaginations. I’m not sure

The objective is leveraging the CGX to generate higher quality finite elements and also a cleaner and maintainable code

I guess I have to create volume before creating finite elements. Maybe I can make a volume for each voxel

One requirement is that I have to be able to separate sets of elements in layers along the Z-axis. I mean, the elements on the 1st layer, 2nd layer, and so on, should be separatable.

You don’t have to use `cgx`.

Since you already have the voxel coordinates, you could basically use those to create nodes and convert each voxel into a HE8 or HE20R element.

1 Like

Right. I guess I would stick with my current Golang data structure.

# Darker lines

Another thing that motivated me to try CGX for element generation, is the fact that I’m observing darker lines on the surface of my models:

It’s suggested that the darker lines are a warning sign. So far, I couldn’t fix those darker lines.

C3D4
C3D8
C3D10
C3D20R

Those darker lines are probably disconnected midside nodes

1 Like

Right, probably that’s the case I move forward Maybe down the road, I’ll figure out a definite answer as to why.

hi there, we have a python package for CalculiX that can help you… you might want ti check it out:

documentation and manual here: