Sign in to follow this  
StoneDevil

Fast Duplicate Edge Detection

Recommended Posts

Hi, Im working on some stencil shadow rendering in managed directx with c#. When create my list of contour edges i am trying to check if i have already added the current edge to my list before i add it again. What is the best way to do this. I have an Edge struct with just two integers in it that reference the indices of the edge. and i have an array of Edges that i am adding to. Whats the best way to avoid duplicates? Thanks

Share this post


Link to post
Share on other sites
To be able to search relatively quickly for dups, be sure you order the indices for each edge - Edge.idx1 is always < Edge.idx2.

Then you can search to see if a newEdge is a duplicate (or something similar):

int i;
bool dup;

i = 0;
dup = false;
while( i < currentArraySize && newEdge.idx1 >= edgeArray[i] ) {
if( newEdge.idx1==edgeArray[i].idx1 && newEdge.idx2==edgeArray[i].idx2 ) {
dup = true;
break;
}
i++;
}
if( !dup ) edgeArray.Add( newEdge );

Share this post


Link to post
Share on other sites
Fastest would be to mark the edge as used, if you have a spare bit in your edge structure. If not, some form of hash will likely work quite quickly. I'm not familiar enough with .NET to know what hash implementations are available and how fast they are.

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