Sign in to follow this  
luckyyyyyy

OpenGL marching cube in opengl

Recommended Posts

hi guys... i have a big problem...i spent a lot of time on this topic...but i didn't get the right path... i want to draw triangular marching cube...(a famous marching cube algorithm) but i don't know how...which type of data is used in marching cube algorithm... i know...first of all we need to convert my model into slices...then draw voxels... but how to convert slices...and what type of data should be exported from slices for draw the voxels...means slices should be PNG(image formate) or ASCII data...???? or what kind of data should be exported for march the cube... i have a triangular model and i want to convert that model into voxel model... how can i convert my model into slices..??? i would appreciate you kind help... much thanks in advance...

Share this post


Link to post
Share on other sites
yes...i already read that article and got a good concept...

please only tell me what kind of data is used in that article for marching cube...

is that ASCII data...means (XYZ vertices and indices) or other type...


i found a one file is there name(cell.gz) when i extract this file (9mb file size) exported. what type of that file...there is no extension of that file...

and also brother i couldn't compile this (http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/source/) opengl program...


it needs another files...

please if you have this compilable complete marching cube program...please give me or some references...


UncleRemus, you were working on marching cube...please sir i want to contact you...you can help me...if you have some time...please tell me your Email...




much thanks...

Share this post


Link to post
Share on other sites
Lucky,

Marching Cubes uses a scalar field to denote the relative density across a 3D space.

Converting a mesh to a scalar field (aka voxel field) is not straight-forward. The most basic way would be to establish a regular grid, then step through it cell by cell. If the cell is "inside" of the mesh, you can mark it as being dense (a scalar value of 1). If the cell is "outside" of the mesh, you can mark it as being sparse (a scalar value of 0). The key thing with Marching Cubes is that the scalar field can have any value within the range of 0 to 1. So when you are converting your mesh to a grid, you will eventually also have to take into consideration that certain cells will be both "inside" and "outside" of the mesh, and that you will have to calculate the percentage that the cell is inside of the mesh, so that you can come up with a value that is appropriately in-between 0 and 1.

The main function of Marching Cubes is then to take this scalar field and convert it to a mesh.

My page has an example program:
http://cpp.criticaldamage.com/index.php/Marching_Cubes_Field_Tesselation

I am also wondering why you would want to take a mesh, convert it to a scalar field, then convert it back to a mesh using Marching Cubes. It seems like a lot of work, where the result is simply a mesh that looks bad compared to the original. The main purpose of Marching Cubes it to convert density data to a mesh, ex: information gained from sonography, tomography, seismology, implicit functions, etc.

Share this post


Link to post
Share on other sites
much Thanks taby..

yes i can get a lot of concept from your example code...

my problem is this...

I have a triangular surface model data...(triangular vertices + indices)

i imported this data and draw in OpenGL...

now i want to draw that model with marching cube algorithm...

i read your volume text file...but i couldn't understand...from where did you get that file...and what is that data...i just understand header of that data file...(size of grids, resolution, data type etc)..

but what is lower data...from where did you export that data...


Please tell me ...how can i convert my triangular surface model into volume data...

means if i use your example program with my model data...how can i convert my model data as same as your (input.txt)...grid data..


please help me...

Thanks...

Share this post


Link to post
Share on other sites
Hi Lucky,

The data beyond the header is the density information for the cells. I believe the header says that the grid is 10x10x10, so there should be 1000 density numbers after the header (one per cell). So the first density number should represent cell {0, 0, 0}, the second one should represent cell {0, 0, 1}, and the last one should represent cell {9, 9, 9}.

I exported this density data from a fluid simulation. Basically you are seeing a portion of the top of a cloud.

The first step to converting your model to a scalar field is finding out how to detect whether a point {x, y, z} is "inside" the model, or "outside". I'm not an expert at this, so I recommend that you create a new topic called something like "detecting whether a point is inside/outside a mesh". Once you have figured this out, come back to this thread and we can continue.

Share this post


Link to post
Share on other sites
thanks you very much sir...

now i am clear...

actually sometime i thought about this kind of thing...and i studied some papers related to detection of points inside or outside of mesh...

i believe, i will do this in some coming days...then again...i will come back...

please sir guide me...otherwise it would be very difficult for me...

thanks a lot...

Share this post


Link to post
Share on other sites
Sounds good. If you make a reply and I don't respond within a day or two, just send me a private message to remind me. :)

Share this post


Link to post
Share on other sites
thanks taby...

yes... i will remind you...

i am trying to do your approach...( triangular surface mesh data(IDs, x,y,z) into 3D scalar volume data(density, dimensions, type of data, 0-1 array, etc)

but can you clear me one thing..???

i spent a lot of time for searching this kind of program or paper..in which anybody draw voxel with surface data(ID, x,y,z)...
but i did not find any material about this...

i saw, many author used marching cube for displaying 3D model...i saw a lot of images on the net...my question is this...what kind of data they use in marching cube algorithm...if they use scalar data as you described...from where they get that data...i think they must would have exported from somewhere/from some kind of software/or algorithm as you did in your program file...

like this... below link...
http://aycu19.webshots.com/image/46258/2004591242660400304_rs.jpg

in above link three model you can see...these model drawn with marching cube algorithm...how they draw these model...???from where they did get scalar data...if they use some kind of scanner then which scanner.???..if they produce scalar data themself..then which method they choose for displaying voxels...???
are they use your method as you explained above...detect inside or outside points...or anyother...


here is a one example... if you want draw a tooth model for some kind of simulation, not you anybody...and you have triangular surface data of that tooth, scanned from some kind of 3D scanner...

now you want to convert that model into voxel model(volume model)...

what will you do.??...means in your case...which method you choose for display your model as voxels...

now i think you can fully understand my problem...means we don't want to use any machine for exporting scalar data of tooth model...

in case of MetaBalls...its easy to create scalar field of sphere...many author did this...

but in my case ...i have a triangular surface(face) data of tooth...
please firstly you suggest me which method i need to choose for display surface model into voxel model...which method is suitable for tooth model...every tooth model have millions of vertices...

one is another method in which we convert surface model into slices and then draw into voxel model...

please suggest me...which method is suitable for me...

thanks...

[Edited by - luckyyyyyy on March 10, 2008 7:21:52 AM]

Share this post


Link to post
Share on other sites
Lucky,

A common source of density data is tomography and imaging:
http://en.wikipedia.org/wiki/Magnetic_resonance_imaging

Rendering volumetric information (density data) is a fairly common topic these days, especially with fluid dynamics becoming so popular. Jos Stam and so many others have written good papers about raytracing semi-opaque materials.

Marching Cubes is used if you want to go one step further and compute the triangulated shell of the density. This can be used for things like collision detection, volume calculation, etc. Most importantly, having a set of triangles allows you to render the object using standard GLSL shaders (or even the fixed-function pipeline if you really must).

If a particular type of scanner generates a triangular mesh by default, then Marching Cubes is no longer necessary.

Share this post


Link to post
Share on other sites
If you are going to use the "inside"/"outside" voxels only to construct an obstacle (boundary) field, then Marching Cubes is not required.

In this instance, the boundary field is analagous to "density data", where "inside" = "1.0f", and "outside" = "0.0f". Surface normals assist in the reflection of fluids (and absorption of momentum, if the boundary is mobile).

The tesselated mesh representing the obstacles is already available -- it's what was used to create the voxel version of obstacle field.

If the fluid has a free surface (ex: water-air boundary), then Marching Cubes could be used to construct the surface from fluid density data (tesselation). There are other methods for surface tesselation, and they might be good to explore.

Share this post


Link to post
Share on other sites
sorry for delay taby...

actually i was trying to understand your posts...

i think now its full understandable...

but please tell me...for marching cube algorithm and for extracting density data ...firstly i need to draw contours of my triangulated surface model(means trace the outside surface: for example if we want to draw contour of sphere then every contour would must be a circle, and its our choice how many slices we want to create)...am i right???...do you agree with my statement....

if yes...then do you have any idea how to draw contour of this complicated model...you can see in below picture link...
Free Image Hosting at allyoucanupload.com
http://aycu32.webshots.com/image/48271/2002968009362320966_rs.jpg

this is a surface model...means it has only surface not volume...it has only triangles on surfaces..not voxels...
you can see this model as wire frame...

Free Image Hosting at allyoucanupload.com
http://aycu32.webshots.com/image/48071/2002999871490735174_rs.jpg

please tell me...is it possible that we can transform this surface model into volume(voxel) model...?????


if yes,,,then how...please guide me...i spent a lot of time on this topic...first i spent my time on learning OpenGL volumizer, VTK, and a lot of papers...then marching cube...if we want to use marching cube algorithm ...we mist have slices(contours) of that model...do you agree...??


i thing this is a very complex model...because it has two layers...means sphere has only one boundary layer...but this model has two inside and outside layer...thats why i thing its very difficult to guess which vertices are inside or outside...

please tell some idea...how can i solve my problem...actually i want to do cutting simulation...i did complete cutting process on this surface model...but facing some problem when push vertices from my spherical tool...then i decide to move on marching cube algorithm...


now i think you fully understand what i want ...and what i am facing problems...

please guide me...

very very thank you...
Stay happy always...

[Edited by - luckyyyyyy on March 12, 2008 11:07:42 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627783
    • Total Posts
      2979035
  • Similar Content

    • By JFT
      Hi,

      I am trying to optimize shadow mapping for an rts-view (nearly top down) with directional light.

      My approach so far is to intersect the camera view frustum with the plane of the terrain on which all the units are moving and
      fit a box around the four intersection points:

      Then I use the center of the box and the light direction to construct a view matrix.
      To construct the orthographic projection matrix I use the corners of my box. 

      With that I somehow do not get the wanted results (no shadows) /shadow map is not correctly created for the view of the camera.
      I think I am maybe missing some translation/rotation?

      Is there a better way for rts-views with a single shadow map ?

      Thanks for your help beforehand!
    • By lonewolff
      Hi guys,
      With OpenGL not having a dedicated SDK, how were libraries like GLUT and the likes ever written?
      Could someone these days write an OpenGL library from scratch? How would you even go about this?
      Obviously this question stems from the fact that there is no OpenGL SDK.
      DirectX is a bit different as MS has the advantage of having the relationship with the vendors and having full access to OS source code and the entire works.
      If I were to attempt to write the most absolute basic lib to access OpenGL on the GPU, how would I go about this?
    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
  • Popular Now