Source

Pleasant3D_OpenSource / ToolPlugins / STLImport / edgeMatch.cl

//
//  edgeMatch.cl
//  STLImport
//
//  Created by Eberhard Rensch on 12.01.10.
//  Copyright 2010 Pleasant Software. All rights reserved.
//

#include "clEdgeIndexTypes.h"
__kernel void edgeMatch(__constant FacetEdge* inFacetEdges, __global EdgeIndex* inOutIndexedEdges, __constant const uint numberOfEdges)
{
	const uint idx = get_global_id(0);
		
	if(inOutIndexedEdges[idx].touchesFacetIndex == (uint)-1) // if not handled already
	{
		// TODO: There probably is a faster way to do the following search!
		uint edgeIndex;			
		for(edgeIndex=0;edgeIndex<numberOfEdges;edgeIndex++)
		{
			if(all(isequal(inOutIndexedEdges[idx].roundedP, inFacetEdges[edgeIndex].roundedP)))
				break;
		}
		
		
		while(edgeIndex<numberOfEdges && all(isequal(inOutIndexedEdges[idx].roundedP, inFacetEdges[edgeIndex].roundedP)))
		{
			if(inFacetEdges[edgeIndex].facetIndex!=inOutIndexedEdges[idx].facetIndex && 
				all(isequal(inOutIndexedEdges[idx].roundedQ, inFacetEdges[edgeIndex].roundedQ)))
			{
				inOutIndexedEdges[idx].touchesFacetIndex = inFacetEdges[edgeIndex].facetIndex;
				inOutIndexedEdges[idx].touchesEdgeIndex = inFacetEdges[edgeIndex].edgeIndex;
				
				uint otherIndex = inFacetEdges[edgeIndex].facetIndex*3+inFacetEdges[edgeIndex].edgeIndex;
				inOutIndexedEdges[otherIndex].touchesFacetIndex = inOutIndexedEdges[idx].facetIndex;
				inOutIndexedEdges[otherIndex].touchesEdgeIndex = inOutIndexedEdges[idx].edgeIndex;
				break;
			}
			edgeIndex++;
		}
	}
}