Computing volume

What I mean by the title is that I have a set of voxels that are arrayed so that they encompass a 3d space. The question is, can I compute the volume of this space in an efficient way?

I thought of starting inside of the space and checking the 6 directions from the beginning, and then checking the spaces beyond those, and so on until they hit a voxel, but that seems very inefficient to me.

In any case, any pointers are greatly appreciated.

Can this voxels be converted into simpler shapes like cubes or polyhedrons? If yes, calculating volume should be rather easy and based on simple formulas.

I honestly wouldn’t know how to figure that out. How would I check to see if a voxel is an exterior corner, or an interior corner? Like, if I had an L-shaped container?

Each Voxel is assigned to a group called a Component, and the type of Component determines what those voxels do. For example, a Chamber component can contain liquids, while Containers can hold solid cargo, and Pipes, which can hold and transport liquids.

The volume calculation is important only to Chambers and Containers at present, and the player places the walls of the chamber or container; once the player saves the current set of voxels, a class builds a new in-game Component based on what the voxels would do. That’s why I need to be able to calculate irregular spaces, since odds are that players will be making irregular shapes.

Try using the trapezoid rule or a reiman sums? you could choose how accurate you got from the subintervals with the tradeoff being performance.