It is currently Sat Aug 22, 2020 3:39 am


All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: getEnclosingRegion() doesn't actually get the entire region
PostPosted: Wed Apr 24, 2013 1:10 am 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: getEnclosingRegion() doesn't actually get the entire reg
PostPosted: Thu Apr 25, 2013 8:00 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: getEnclosingRegion() doesn't actually get the entire reg
PostPosted: Fri Apr 26, 2013 3:43 am 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: getEnclosingRegion() doesn't actually get the entire reg
PostPosted: Fri Apr 26, 2013 8:24 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: getEnclosingRegion() doesn't actually get the entire reg
PostPosted: Fri Apr 26, 2013 12:16 pm 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
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


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net