Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Polygonizing a grid after subtracting an irregular portion

Hybrid View

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162

    Polygonizing a grid after subtracting an irregular portion

    Click image for larger version. 

Name:	image.jpg 
Views:	268 
Size:	20.0 KB 
ID:	980
    I have a regular grid. I need to subtract someirregular part from it as shown in the figure. I know the coordinates of theportion to be subtracted. How can I polygonize the rest of the grid aftersubtracting that irregular portion? There may be a number of ways. Could any onegive me some suggestions?

  2. #2
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    1
    how about Marching Squares?

  3. #3
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362
    You can use the stencil buffer. Draw the shape of your irregular part in the stencil buffer. Use the algorithm described here for concave polygon (see the Drawing Filled, Concave Polygons Using the Stencil Buffer section). To draw your irregular shape, first choose a starting point on your irregular shape. Draw in triangle fan mode with the rest of the points in order to follow the path your irregular shape.


    Code :
     
    //all value in the stencil buffer is 0 if not
    // glClearStencil(0x0);
    //glClear(GL_STENCIL_BUFFER_BIT);
     
     glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
      glEnable(GL_STENCIL_TEST);
      glStencilFunc(GL_ALWAYS,0x1,0x1);
      glStencilOp(GL_KEEP,GL_INVERT,GL_INVERT);
      glDrawArrays(GL_TRIANGLE_FAN,0,m_Vertices.size()); 
    // Now the value of the stencil if 0x1 (one) inside your irregular shape
     
    glStencilFunc(GL_NOTEQUAL,0x1,0x1);
    glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
    glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
    draw_your_grid()
    glDisable(GL_STENCIL_TEST);
    Last edited by trinitrotoluene; 02-15-2013 at 04:40 PM. Reason: link seem to point to bottom of the web page

  4. #4
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    Thank you very much for taking time to reply. I can extract the irregular boundary outline using matlab. MATLAB also gives the color at different gtid points. My main question how to polygonize the remaining portion ( after subtracting the inside). This may resemble to constructing surface after extracting image boundaries. Any similar algorithm for constructing surface from image boundaries may be helpful. I am looking for some thing that suits it. If any body has any suggestion, please help me.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Jan 2011
    Location
    Paris, France
    Posts
    248
    Something like the "inverse" ?

    Code :
    // Set alls values in the stencil buffer to 1
    glClearStencil(0x1);
    glClear(GL_STENCIL_BUFFER_BIT);  
    glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); 
    glEnable(GL_STENCIL_TEST); 
     
    glStencilFunc(GL_ALWAYS,0x0,0x1);  
    glStencilOp(GL_KEEP,GL_INVERT,GL_INVERT);  
    glDrawArrays(GL_TRIANGLE_FAN,0,m_Vertices.size()); 
    // Now the value of the stencil if 0x0 (zero) inside your irregular shape
    // Now the value of the stencil if 0x1 (one) outside your irregular shape 
     
    glStencilFunc(GL_EQUAL,0x1,0x1);
    glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
    glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
    draw_your_grid();
     
    glDisable(GL_STENCIL_TEST);

    I have not tested but the idea is :

    1) set alls stencils values to 1
    2) set stencils values to 0 where they are into the interior of the shape
    3) draw the grid but only where the stencil value is set to 1 (cf. not in the shape where the stencil value is 0)
    Last edited by The Little Body; 02-21-2013 at 12:25 PM.
    @+
    Yannoo

  6. #6
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362
    Quote Originally Posted by The Little Body
    I have not tested but the idea is :

    1) set alls stencils values to 1
    2) set stencils values to 0 where they are into the interior of the shape
    3) draw the grid but only where the stencil value is set to 1 (cf. not in the shape where the stencil value is 0)
    The modification you wrote don't change anything , the result will be the same. My version was
    Code :
    1) set alls stencils values to 0 
    2) set stencils values to 1 in the interior of the irregular shape 
    3) draw the grid but only where the stencil value is not set to 1 i.e zero (cf. not in the irregular shape where the stencil value is 1)

    An improvement to the algorithm is to disable writing value also in the depth buffer when drawing the irregular shape. The stencil op become StencilOp(KEEP,KEEP,INVERT).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •