Advertisement

Checking a Closed Polyhedra!

Started by October 10, 2001 08:46 AM
11 comments, last by Jankey 23 years, 3 months ago
Ill just drop in my version as well
  void solidmesh::addEdge(int a,int b) {//check for exactly one a->b edge + one b->a edge	for (long i=0;i<numEdges;i++)		//b->a edge 		if (edges[i].vA == b && edges[i].vB == a) {			edges[i].ref++;			return;			}//one a->b edge	edges[numEdges].vA = a;	edges[numEdges].vB = b;	numEdges++;	}void solidmesh::buildEdges() {	//max amount of edges is Triangles*3	edges = (EDGE *) malloc(sizeof(EDGE) * numFaces * 3);	memset(edges,0,sizeof(EDGE) * numFaces * 3);	for (long i=0;i < numFaces ; i++ ) {		addEdge(face[i].a,face[i].b);		addEdge(face[i].b,face[i].c);		addEdge(face[i].c,face[i].a);		}	edges = (EDGE *) realloc(edges,sizeof(EDGE) * numEdges);	//check whether every edge occured twice	for (long i=0;i<numEdges;i++) assert(edges[i].ref == 1);	//eulers formula	assert(numVertices - numEdges + numFaces == 2 );	}  
wow, .. i have to make some speed ups in this code ( ms P3 667 Calculated a mesh about 3 Mins ( where where a few Thousands Of Triangles ...)) ...
J.A.N.K.E.Y.: Journeying Artificial Nocturnal Killing and Exploration Youth
Advertisement
notice that you have implemented an O(n2) algorithm here, eg. time taken to run the algorithm is proportional to square of number of polygons. No matter how you optimise the code, it will be slow on large poly counts.
My version should be slightly faster, something like O(n + n log E) where E is total number of edges on model.

BTW i think you have a typo here
  ....{tri[0] = object.pfaces.vertexIndex[0];tri[1] = object.pfaces[i].vertexIndex[1];....  

Shouldnt it be
  ....{tri[0] = object.pfaces[i].vertexIndex[0];tri[1] = object.pfaces[i].vertexIndex[1];....  

This topic is closed to new replies.

Advertisement