It is currently Sat Aug 22, 2020 12:26 pm


All times are UTC




Post new topic Reply to topic  [ 67 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next
Author Message
 Post subject: 3D surface reconstruction for volumetric voxel data
PostPosted: Sun Feb 01, 2009 3:36 pm 

Joined: Sun Feb 01, 2009 3:18 pm
Posts: 34
Hi,

I was looking for a library that can extract surface from volumetric voxel data. I just found polyvox. I am not sure still it will work in my case.
My Problem:
I have an array of voxel data which I represent as a 3d grid points. Those points represents the density data from CT scan data. This volumetric data represents a static object , though could be rotated (camera). Currently I render the points (900000) using just glVertex3f.
I have another object which is made of a point cloud (5000) and I try to find the collision between objects and I can exactly find which objects are collided. Currently,in the case of collision I inactivate the voxels (not to render the points).
I would like to improve the rendering part by extracting surface from voxel data of the static object and should be able to modify the voxel and the surface.

My major concern are:
- I should be able to render it in real time (30 fps)
- I should also be able to modify the voxel data hence the surface (30fps)

Could you please advice me I could use PolyVox for my work?

My Platform:
Windows XP(SP3)
OpenGl
C++

I am looking forward to some reply from someone .

Thanking you.

Sincerely
Gajananan


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Sun Feb 01, 2009 10:34 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Hi,

Well, there is a good chance PolyVox can be useful for you. The library will indeed take volume data and convert it to triangles using the marching cubes algorithm. However, the format of the volumes is different to that produced by CT scanners. In CT data the voxel value corresponds to the material density, where as in PolyVox volumes the voxel value is simply an identifier for a particular material. 0 is always empty spce, and the other values you can define yourself.

Given a CT scan of the human body, you will basically divide the voxels into different materials using one or more thresholds. Anything below -800HU is air in a CT scan, so in the corresponding PolyVox volume you would set this to zero. You could then set all other voxels to '1', or you might want to use more thesholds to seperate bone, fat, etc. You can have up to 255 of these different materials. However, I would start by just dividing into 'air' and 'body'.

PolyVox will then split the volume into a number of cubes (regions), and when you run the surface extraction you will get a mesh for each region. The mesh is basically just a index/vertex list which you can the render using OpenGL or whatever else you like.

So what are the catches? Well, I would imagine your volumes are bigger then the 'castle' which you probably saw in the demo. That castle volume was 256^3, whereas I expect your volumes are at least 512^3. This means more polygons, and I don't know whether this will be a problem. I think it will still work, as most graphics cards are actually limited by the number of 'batches' they can render, rather than the number of polygons.

As for modifying the volume, again it is fine on the smaller volume but I can't be certain about your larger one. There are plenty of optimisations to be done here though...

I should point out that PolyVox does not do any kind of collision detection - it just generates the meshes. In the castle demo the physics is implemented using the 'Bullet' physics engine, but I wouldn't recommend that for you. If you just want collision (rather than full physics) then it's easier and faster to just directly check each of the 5000 points in your cloud against the voxels. Actually, the Bullet physics is one of the slowest parts of my demo, especially when modifying the volume.

Also, there is an extreamly basic OpenGL demo in the PolyVox source code folder. It just generates a volume and then a mesh (no modification or nice materials) but maybe it's a start. You wil need GLUT to run it.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Mon Feb 02, 2009 6:32 am 

Joined: Sun Feb 01, 2009 3:18 pm
Posts: 34
Hi,

Thanking you for your prompt reply!

Quote:
However, the format of the volumes is different to that produced by CT scanners. In CT data the voxel value corresponds to the material density, where as in PolyVox volumes the voxel value is simply an identifier for a particular material. 0 is always empty space, and the other values you can define yourself.


In my CT scan data, currently I have 85 * 109 * 98 resolution and values of 0, 50,100 ,255 only.

Quote:
Given a CT scan of the human body, you will basically divide the voxels into different materials using one or more thresholds. Anything below -800HU is air in a CT scan, so in the corresponding PolyVox volume you would set this to zero. You could then set all other voxels to '1', or you might want to use more thesholds to seperate bone, fat, etc. You can have up to 255 of these different materials. However, I would start by just dividing into 'air' and 'body'.


I have a CT scan data of a human tooth. According to your explanation, first I can set
- 0 for Voxel value 0
- 1 for Voxel value 50,100, 255
I am not sure about setting more thresholds.

Quote:
So what are the catches? Well, I would imagine your volumes are bigger then the 'castle' which you probably saw in the demo. That castle volume was 256^3, whereas I expect your volumes are at least 512^3.


As I said, currently I have 85 * 109 * 98, which I cut from a high resolution data. I will switch to at least 256 ^ 3. In that case, PolyVox would not have any issue.

Quote:
I should point out that PolyVox does not do any kind of collision detection - it just generates the meshes.................just directly check each of the 5000 points in your cloud against the voxels.


Sorry I was not clear in my previous post. Actually I have done the collision detection part using the technique called 3d Occupancy Grid. This is an integer based operation and much faster.

Quote:
Also, there is an extreamly basic OpenGL demo in the PolyVox source code folder. It just generates a volume and then a mesh (no modification or nice materials) but maybe it's a start. You wil need GLUT to run it.


Yes , I have already built PolyVox and the example and run it. Currently I am trying to understand how it is implemented. I am already using glut , no problem then.

Later , I tried to load 64 ^ 3 (croped from my original data) in OpenGl example, but I am confused with how we should set the "volIter.setVoxel"
Does this mean the Iso Value used in MC ?

/Gajananan


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Mon Feb 02, 2009 9:52 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Gajananan wrote:
In my CT scan data, currently I have 85 * 109 * 98 resolution and values of 0, 50,100 ,255 only.


Great, well PolyVox requires the volumes to be cubic and to have side lengths which are a power of two. The OpenGL demo uses a 128^3 volume so I guess that will be fine for your purposes.

Gajananan wrote:
I have a CT scan data of a human tooth. According to your explanation, first I can set
- 0 for Voxel value 0
- 1 for Voxel value 50,100, 255
I am not sure about setting more thresholds.


Yep, that is correct. Latar, you can try setting 1=50, 2=100, and 3=255 if you want to. But start simple :-)

Gajananan wrote:
As I said, currently I have 85 * 109 * 98, which I cut from a high resolution data. I will switch to at least 256 ^ 3. In that case, PolyVox would not have any issue.


Yep, should be fine.

Gajananan wrote:
Yes , I have already built PolyVox and the example and run it. Currently I am trying to understand how it is implemented.


Ok, well it was originally based on this article by Paul Bourke. I have since created more complex (but hopefully faster) implementation of the algorithm, but the original one is still in there as a reference. Look in sources/PolyVoxImpl/ReferenceSurfaceExtractor.cpp and the main function is called 'extractReferenceSurfaceImpl()'.

This function takes a single region of the volume and generates the corresponding mesh (a mesh is actually called an IndexedSurfacePatch as I recall). So you call that function for each region of your volume, and you can call it again later if the data changes.

The main() function in main.cpp contains a nested loop which calls extractReferenceSurface() for each region in the volume. The meshes are stored, and then rendered later in the display() function.

Gajananan wrote:
Later , I tried to load 64 ^ 3 (croped from my original data) in OpenGl example, but I am confused with how we should set the "volIter.setVoxel"
Does this mean the Iso Value used in MC ?


Yeah... I haven't quite finalised the way the iterators should work. It currently uses a function called 'moveForwardInRegionXYZ()' which is supposed to be fast but is also a little bit confusing. The easiest way is just to use the functions volIter.setPosition() to point the iterator at a particulr voxel, and volIter.setVoxel() to set it's value. Put these in a nested loop which goes from 0-63 in x, y, and z. Does that make sense?

And let me know if you have any problems - it's very likely there are bugs. But it's great that someone else is using the library :-)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Tue Feb 03, 2009 7:19 am 

Joined: Sun Feb 01, 2009 3:18 pm
Posts: 34
I tested it by writing my own OpenGl example then I compared the rendered surface with the image from another surface rendering tool . Results seems fine as I can see the shape of the tooth. Since my example too basic with out light model I am yet to get the desired output.
Meantime I also tested with the following code.I think it works fine.

if(vector.dv > 50)
{
volIter.setVoxel(1);

}
else if(vector.dv == 100)
{
volIter.setVoxel(2);
}
else if(vector.dv == 255)
{
volIter.setVoxel(3);
}
else
{
volIter.setVoxel(0);
}

I still not understood with the idea how Iso value is implemented for MC. Usually we should be able to set different Iso values and see different Iso surfaces. I am not sure Polyvox does this.

/Gajananan


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Tue Feb 03, 2009 8:30 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Gajananan wrote:
I tested it by writing my own OpenGl example then I compared the rendered surface with the image from another surface rendering tool . Results seems fine as I can see the shape of the tooth. Since my example too basic with out light model I am yet to get the desired output.


Great, if you look at the SurfaceVertex class you will see that the vertices already contain normals, so it should be easy to add lighting.

Gajananan wrote:
Meantime I also tested with the following code.I think it works fine.

if(vector.dv > 50)
{
volIter.setVoxel(1);

}
else if(vector.dv == 100)
{
volIter.setVoxel(2);
}
else if(vector.dv == 255)
{
volIter.setVoxel(3);
}
else
{
volIter.setVoxel(0);
}

I still not understood with the idea how Iso value is implemented for MC. Usually we should be able to set different Iso values and see different Iso surfaces. I am not sure Polyvox does this.

/Gajananan


The code above is what I had in mind but, thinking about it more carefully, PolyVox won't give quite the right behaviour for your situation. I have to go to work now, but I'll come back tonight and give you more details about how it decides when to generate a surface.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Wed Feb 04, 2009 11:16 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Ok, sorry for the delay...

Right, PolyVox was originally designed for a game environment - the idea was that voxels with a value of 0 would represent empty space where other values would represent various solid materials such as wood, stone, etc. Crucially, it was anticipated that the camera would only ever be in areas of empty space. Consider the diagram below for a voxel world:

Image

As you can see, PolyVox generates a mesh for the white-yellow boundary, and for the white-green boundary, but not for the yellow-green boundary. Even if a mesh was generated for the yellow-green boundary, the user would never be able to see it because it was hidden behing the other one.

In your case you want something slightly different. Because your data came from a density field, you probably never have the case where material 0 (in white) is directly adjacent to material 2 (in green). Your data will probably look more like the following:

Image

It seems that, in your case, you don't want to find the boundaries for 0-1, 0-2, etc. Instead you wan 0-1, 1-2, etc. Do you see what I mean?

Unfortunatly this is slightly beyond what I designed PolyVox to do. However, it shouldn't be too difficult to modify the source code to do what you need. ReferenceSurfaceExtractor.cpp contains the following code:
Code:
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8 iCubeIndex = 0;

if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
if (v110 == 0) iCubeIndex |= 4;
if (v010 == 0) iCubeIndex |= 8;
if (v001 == 0) iCubeIndex |= 16;
if (v101 == 0) iCubeIndex |= 32;
if (v111 == 0) iCubeIndex |= 64;
if (v011 == 0) iCubeIndex |= 128;

This basically checks each vertex to determine whether they are empty space (value == 0) or not.If I were you, I would start by playing with the logic in this section.

Hope that helps!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Thu Feb 05, 2009 3:48 am 

Joined: Sun Feb 01, 2009 3:18 pm
Posts: 34
Hi,

Thanking you for your detailed reply. I could not work for last two days due to an illness. I just read your reply.

Quote:
It seems that, in your case, you don't want to find the boundaries for 0-1, 0-2, etc. Instead you want 0-1, 1-2, etc. Do you see what I mean?

I understand your point. You picture about my data is correct. But I am not sure If it is enough to have 0-1 boundary only, I need to think about 1-2 when I cut the model and try to go inside.In my model , 0,50,100,255 is the order of density from outside to inside.

Quote:
This basically checks each vertex to determine whether they are empty space (value == 0) or not.If I were you, I would start by playing with the logic in this section.

I would try this!

/Gajananan


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Sun Feb 15, 2009 3:49 pm 

Joined: Sun Feb 01, 2009 3:18 pm
Posts: 34
Hi

I tried to load the tooth model [128 * 3]in PolyVox example! this is the rotated view of the second image.
Attachment:
File comment: Tooth model loaded in PolyVox example
Polyvox-tooth.JPG
Polyvox-tooth.JPG [ 24.08 KiB | Viewed 6152 times ]




You can compare this with an image that I got after volume rendering of it.
Attachment:
File comment: Volume rendered tooth model
Tooth- VolumeRend.JPG
Tooth- VolumeRend.JPG [ 15.76 KiB | Viewed 6151 times ]


You can also see what I get when I render the sphere:
Attachment:
sphere.JPG
sphere.JPG [ 16.32 KiB | Viewed 6150 times ]


My question is : why it is showing like flat, I mean no 3D effect in tooth and sphere cases ?

/gajananan


Top
Offline Profile  
Reply with quote  
 Post subject: Re: 3D surface reconstruction for volumetric voxel data
PostPosted: Mon Feb 16, 2009 1:07 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Gajananan wrote:
My question is : why it is showing like flat, I mean no 3D effect in tooth and sphere cases ?


Because the OpenGL demo is very basic, and doesn't apply any lighting or materials to the mesh. If lighting was applied, then parts of the surface which are directly facing the light would be brighter than those which were at an angle, and the result would be a more 3D image.

I forget exactly how you set up lighting in OpenGL but I'm sure there will be articles about it online (you only need a basic approach). As well as setting up the light you will also need to provide OpenGL with the surface normals of the mesh so it can perform the lighting calculations. PolyVox does generate these normals for you, but I'll have to let you know later how to access them as I don't have the code in foront of me right now...

Hope that helps!


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 67 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 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