Polygonizing a grid after subtracting an irregular portion

[ATTACH=CONFIG]378[/ATTACH]
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?

how about Marching Squares?

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.



//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);

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.

Something like the “inverse” ?


// 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)

The modification you wrote don’t change anything , the result will be the same. My version was


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).