Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

getEnclosingRegion() doesn't actually get the entire region
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=15&t=503
Page 1 of 1

Author:  Clonkex [ Wed Apr 24, 2013 1:10 am ]
Post subject:  getEnclosingRegion() doesn't actually get the entire region

When I first got the extracted mesh working in DBPro, it all appeared fine except the sides at -Z and -X were not capped (you could see inside the mesh). At first I assumed I was doing something wrong. I used this code:

Code:
volume[index].meshData.surfaceExtractor=new MarchingCubesSurfaceExtractor<LargeVolume<uint8_t>>(volume[index].volume,volume[index].volume->getEnclosingRegion(),volume[index].meshData.mesh);
volume[index].meshData.surfaceExtractor->execute();


But then I discovered that if I did this:

Code:
Vector3DInt32 lowerCorner=volume[index].volume->getEnclosingRegion().getLowerCorner();
Vector3DInt32 upperCorner=volume[index].volume->getEnclosingRegion().getUpperCorner();
lowerCorner.setX(lowerCorner.getX()-1);
lowerCorner.setY(lowerCorner.getY()-1);
lowerCorner.setZ(lowerCorner.getZ()-1);
volume[index].meshData.surfaceExtractor=new MarchingCubesSurfaceExtractor<LargeVolume<uint8_t>>(volume[index].volume,Region(lowerCorner,upperCorner),volume[index].meshData.mesh);
volume[index].meshData.surfaceExtractor->execute();


It worked perfectly, all sides enclosed properly. Obviously getEnclosingRegion() is failing to get the entire region. This should be corrected, but it's easy to work around for the time being.

I can be sure that it's not still my fault simply being disguised by the changed code, because the number of extracted vertices and indices goes up with the new code.

Clonkex

Author:  David Williams [ Thu Apr 25, 2013 8:00 am ]
Post subject:  Re: getEnclosingRegion() doesn't actually get the entire reg

Actually this is the expected behaviour, though it can be confusing and still catches me out sometimes.

So, the thing to remember is that the MC surface extractor operates on cells (groups of eight voxels) rather than individual voxels. Imagine we have a volume where the range of voxels is from (0,0,0) to (15, 15, 15) - these are the two values which will be returned as the lower and upper corners of the enclosing region. Now imagine that we set all voxels in the volume to be solid. If you now run the MC surface extractor on the enclosing region then no triangles will be generated.

The reason is that for every group of eight voxels in the volume, they are all solid so no surface passes between them. In this scenario the surface we were hoping to find wraps the volume and so actually lies slightly outside it. If we expand our extraction region to be bigger than our enclosing region then we will find this surface.

So, when working with the MC extractor you can pass a region which is bigger then the enclosing region. Alternatively you can just make sure that the never set the edge voxels to solid. Either of these approaches will let you generate meshes which are closed.

Author:  Clonkex [ Fri Apr 26, 2013 3:43 am ]
Post subject:  Re: getEnclosingRegion() doesn't actually get the entire reg

So....the MC extractor doesn't extract per-voxel, it extracts per-position? I assume that if I passed in a single voxel as the extraction region I would get all mesh data relating to that voxel... Actually now that I think about it, that would be bad. The way it really works kinda makes sense now. I guess I didn't think this through ;)

The reason I assumed that getEnclosingRegion() would get the mesh from the entire volume is because the tutorial says it does. If it's not true then you really need to fix that.

Thanks for clearing that up :)

Clonkex

Author:  David Williams [ Fri Apr 26, 2013 8:24 am ]
Post subject:  Re: getEnclosingRegion() doesn't actually get the entire reg

Clonkex wrote:
So....the MC extractor doesn't extract per-voxel, it extracts per-position?


It extracts per-cell, where a cell is a group of eight voxels. Passing in a single voxel region will generate no output as you say. I realise this is a bit counter-intuitive but it's basically a property of how marching cubes works.

Clonkex wrote:
The reason I assumed that getEnclosingRegion() would get the mesh from the entire volume is because the tutorial says it does. If it's not true then you really need to fix that.


The thing is, it is true for the CubicSurfaceExtractor, just not for the MarchingCubesSurfaceExtractor. The CubicSurfaceExtractor does operate on a per-voxel basis if a single voxel is solid then a cube should be generated.

I agree this is a bit messy, but it's not clear how it should be resolved. Well, probably by documentation. For the CubicSurfaceExtractor I added a description of the algorithm (complete with diagrams) but it's not finished and I have to do the same for the Marching Cubes version. It all takes so much time!

Author:  Clonkex [ Fri Apr 26, 2013 12:16 pm ]
Post subject:  Re: getEnclosingRegion() doesn't actually get the entire reg

Quote:
It extracts per-cell, where a cell is a group of eight voxels. Passing in a single voxel region will generate no output as you say. I realise this is a bit counter-intuitive but it's basically a property of how marching cubes works.


I understand that now. The diagrams as mentioned below helped a lot, thanks :)

Quote:
The thing is, it is true for the CubicSurfaceExtractor, just not for the MarchingCubesSurfaceExtractor. The CubicSurfaceExtractor does operate on a per-voxel basis if a single voxel is solid then a cube should be generated.


I suspected this to be the case but brought it up anyway because the tutorial states that the only thing that you simply need to comment out one line (ie. the cubic extractor) and uncomment another line (ie. the MC extractor). This isn't true if getEnclosingRegion() will create different results depending on which extractor is used.

Quote:
For the CubicSurfaceExtractor I added a description of the algorithm (complete with diagrams) but it's not finished and I have to do the same for the Marching Cubes version. It all takes so much time!


I like it. It's very helpful. The diagrams give me a way to visualise the way everything happens. Can't wait for the MC version :D

Clonkex

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/