/*=================================================================================== ClearAllocationSet (private helper) EFFECTS: Empty the set of allocated blocks. ====================================================================================*/ void TestController::ClearAllocationSet() { if ( !using_alloc_set ) { using_alloc_set = true; alloc_set().clear(); using_alloc_set = false; } }
static void* OperatorNew( size_t s ) { if ( !using_alloc_set ) { simulate_possible_failure(); alloc_count++; } char *p = AllocateBlock(s); if ( gTestController.TrackingEnabled() && gTestController.LeakDetectionEnabled() && !using_alloc_set ) { using_alloc_set = true; EH_ASSERT( alloc_set().find( p ) == alloc_set().end() ); alloc_set().insert( p ); using_alloc_set = false; } return p; }
void _STLP_CALL operator delete(void* s) # endif { if ( s != 0 ) { if ( !using_alloc_set ) { alloc_count--; if ( gTestController.TrackingEnabled() && gTestController.LeakDetectionEnabled() ) { using_alloc_set = true; allocation_set::iterator p = alloc_set().find( (char*)s ); EH_ASSERT( p != alloc_set().end() ); alloc_set().erase( p ); using_alloc_set = false; } } # if ! defined (NO_FAST_ALLOCATOR) if ( !gFastAllocator.Free( s ) ) # endif EH_CSTD::free(s); } }
bool TestController::ReportLeaked() { EndLeakDetection(); if (using_alloc_set) EH_ASSERT( alloc_count == static_cast<int>(alloc_set().size()) ); if ( alloc_count!=0 || object_count!=0 ) { EH_STD::cerr<<"\nEH TEST FAILURE !\n"; PrintTestName(true); if (alloc_count) EH_STD::cerr<<"ERROR : "<<alloc_count<<" outstanding allocations.\n"; if (object_count) EH_STD::cerr<<"ERROR : "<<object_count<<" non-destroyed objects.\n"; alloc_count = object_count = 0; return true; } return false; }
void SurfaceObject::draw(bool drawPoints, bool drawLines, bool drawTransparent, bool pocketView, double * offset, double * c) { int i = 0; int j = 0; int pt1, pt2, pt3; ////Declare Materials GLfloat mat_solid[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_zero[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat mat_transparent[] = { 0.2, 0.2, 0.2, 0.2 }; GLfloat mat_emission[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat mat_specular[] = { 0.1, 0.1, 0.1, 0.0 }; GLfloat low_shininess[] = { .5 }; float amb[] = {0.20f, 0.50f, 1.0f, 0.1f}; float diff[] = {0.20f, 0.50f, 1.0f, 0.1f}; float spec[] = {1.0f, 1.0f, 1.0f, 1.0f}; float shine[] = {0.8 * 128.0f}; // The glass is very shiny double * cent = new double[3]; cent[0] = 0; cent[1] = 0; cent[2] = 0; if(offset != NULL){ delete[](cent); cent = offset; } ///drawPoints if(drawPoints){ glBegin(GL_POINTS); glColor3f(1.00000f, 1.00000f, 1.00000f); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); } glEnd(); } if(drawLines){ glBegin(GL_LINES); glColor3f(0.00000f, 1.00000f, 0.00000f); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); } glEnd(); } bool drawNormals = false; if(drawNormals){ glColor3f(1.00000f, 1.00000f, 1.00000f); glBegin(GL_LINES); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; double * p1 = new double[3]; p1[0] = surfacePoints [3*pt1+0]-cent[0]; p1[1] = surfacePoints [3*pt1+1]-cent[1]; p1[2] = surfacePoints [3*pt1+2]-cent[2]; double * p2 = new double[3]; p2[0] = surfacePoints [3*pt2+0]-cent[0]; p2[1] = surfacePoints [3*pt2+1]-cent[1]; p2[2] = surfacePoints [3*pt2+2]-cent[2]; double * p3 = new double[3]; p3[0] = surfacePoints [3*pt3+0]-cent[0]; p3[1] = surfacePoints [3*pt3+1]-cent[1]; p3[2] = surfacePoints [3*pt3+2]-cent[2]; double * v1 = new double[3]; v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2]; double * v2 = new double[3]; v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2]; double * cross = crossProd(v1, v2); double * norm = normalizeVector(cross); double * avg = new double[3]; avg[0] = (p1[0]+p2[0]+p3[0])/3; avg[1] = (p1[1]+p2[1]+p3[1])/3; avg[2] = (p1[2]+p2[2]+p3[2])/3; double * newPt = new double[3]; newPt[0] = avg[0] + norm[0]; newPt[1] = avg[1] + norm[1]; newPt[2] = avg[2] + norm[2]; glVertex3f( avg[0], avg[1], avg[2] ); glVertex3f( newPt[0], newPt[1], newPt[2] ); //printf("vectorSize: %lf\n", vectorSize( newPt[0]-avg[0], newPt[1]-avg[1], newPt[2]-avg[2]) ); delete[](p1); delete[](p2); delete[](p3); delete[](v1); delete[](v2); delete[](cross); delete[](norm); delete[](avg); delete[](newPt); } glEnd(); } //set material properties if(drawTransparent == true){ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shine); glEnable(GL_BLEND); glDepthMask(GL_FALSE); // glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else{ glMaterialfv(GL_FRONT, GL_EMISSION, mat_zero); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_solid); } double * color = new double[3]; if(c != NULL){ color[0] = c[0]; color[1] = c[1]; color[2] = c[2]; } else{ if(drawTransparent){ color[0] = 0.5f; color[1] = 0.5f; color[2] = 0.0f; } else{ color[0] = 0.0f; color[1] = 0.5f; color[2] = 0.5f; } } set_t debug_triangleSet = alloc_set(0); // debug_triangleSet = put_set(debug_triangleSet, 37); // debug_triangleSet = put_set(debug_triangleSet, 38); // debug_triangleSet = put_set(debug_triangleSet, 39); // debug_triangleSet = put_set(debug_triangleSet, 213); // debug_triangleSet = put_set(debug_triangleSet, 215); ///render the triangles glBegin(GL_TRIANGLES); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; double s = 1.00; ///surface geometry hack - scales up slightly so there isnt so much z-buffer collision. // if(i == 215){ glColor4f(1, 0, 0, .5); } if(drawTransparent){///surface geometry hack glColor4f(color[0], color[1], color[2], .5); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, .5); } glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( s*(surfacePoints [3*pt1+0]-cent[0]),s*(surfacePoints [3*pt1+1]-cent[1]),s*(surfacePoints [3*pt1+2]-cent[2]) ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( s*(surfacePoints [3*pt2+0]-cent[0]),s*(surfacePoints [3*pt2+1]-cent[1]),s*(surfacePoints [3*pt2+2]-cent[2]) ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( s*(surfacePoints [3*pt3+0]-cent[0]),s*(surfacePoints [3*pt3+1]-cent[1]),s*(surfacePoints [3*pt3+2]-cent[2]) ); } else{ if(colorFlag == true){ glColor4f( colors[3*pt1+0], colors[3*pt1+1], colors[3*pt1+2], 1.0 ); glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glColor4f( colors[3*pt2+0], colors[3*pt2+1], colors[3*pt2+2], 1.0 ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glColor4f( colors[3*pt3+0], colors[3*pt3+1], colors[3*pt3+2], 1.0 ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); } else{ glColor4f(color[0], color[1], color[2], 1.0); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, 1); } glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); } } } for(i = 0; i<numTriangles; i++){ double s = 1.00; ///surface geometry hack - scales up slightly so there isnt so much z-buffer collision. pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; if(pocketView){/// we render both sides by drawing backwards triangles too. //glColor4f(color[0]/2, color[1]/2, color[2]/2, 1.0); if(drawTransparent){///surface geometry hack glColor4f(color[0], color[1], color[2], .3); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, .5); } glNormal3f( -surfaceNormals[3*pt1+0], -surfaceNormals[3*pt1+1], -surfaceNormals[3*pt1+2] ); glVertex3f( s*(surfacePoints [3*pt1+0]-cent[0]),s*(surfacePoints [3*pt1+1]-cent[1]),s*(surfacePoints [3*pt1+2]-cent[2]) ); glNormal3f( -surfaceNormals[3*pt3+0], -surfaceNormals[3*pt3+1], -surfaceNormals[3*pt3+2] ); glVertex3f( s*(surfacePoints [3*pt3+0]-cent[0]),s*(surfacePoints [3*pt3+1]-cent[1]),s*(surfacePoints [3*pt3+2]-cent[2]) ); glNormal3f( -surfaceNormals[3*pt2+0], -surfaceNormals[3*pt2+1], -surfaceNormals[3*pt2+2] ); glVertex3f( s*(surfacePoints [3*pt2+0]-cent[0]),s*(surfacePoints [3*pt2+1]-cent[1]),s*(surfacePoints [3*pt2+2]-cent[2]) ); } else{ glColor4f(color[0]/4, color[1]/4, color[2]/4, 1.0); glColor3f(0.00000f, 0.250000f, 0.2500000f); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, 1); } glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); } } } glEnd(); free_set(debug_triangleSet); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); if( highlights != NULL ){ glBegin(GL_POINTS); for(i = 0; i<numPoints; i++){ if(contains_set(highlights, i)){ //glPushMatrix(); glVertex3f( surfacePoints[3*i+0]-cent[0], surfacePoints[3*i+1]-cent[1], surfacePoints[3*i+2]-cent[2] ); //glTranslatef(surfacePoints[3*i+0], surfacePoints[3*i+1], surfacePoints[3*i+2] ); //glutSolidSphere ( .3, 4, 4) ; //glPopMatrix(); } } glEnd(); } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); if(edges != NULL && drawTransparent == false){ glBegin(GL_LINES); for(i = 0; i<size_set(edges); i++){ set_t tempSet = (set_t) mapsto_set(edges, edges[i]); for(j = 0; j<size_set(tempSet); j++){ if(tempSet[j] > edges[i]){ glVertex3f( surfacePoints[3*edges[i]+0]-cent[0], surfacePoints[3*edges[i]+1]-cent[1], surfacePoints[3*edges[i]+2]-cent[2] ); glVertex3f( surfacePoints[3*tempSet[j]+0]-cent[0], surfacePoints[3*tempSet[j]+1]-cent[1], surfacePoints[3*tempSet[j]+2]-cent[2] ); } } } glEnd(); } ///fix material properties if(drawTransparent == true){ glDepthMask(GL_TRUE); glDisable(GL_BLEND); } if(offset == NULL){ delete[](cent); } delete[](color); }
///identifies edges which are not surrounded by triangles - locations where the surface ///is non manifold. ///This turns the edges variable non-null. // //NOTE: THIS FUNCTION IS CURRENTLY BROKEN // // void SurfaceObject::identifyNonManifoldEdges(void) { int i = 0; int j = 0; ///create a set of sets to hold non-manifold edges set_t nonManifold = alloc_set(SP_MAP); ///Create a set of sets to remember which triangles associate with which vertex. Allocate that here. set_t verticesMappingToTris = alloc_set(SP_MAP); for(i = 0; i<numPoints; i++){ set_t tris = alloc_set(0); verticesMappingToTris = associate_set(verticesMappingToTris, i, tris); } ///associate each vertex with a list of triangles it is part of. ///we do this by interating through all triangles set_t tris; for(i = 0; i<numTriangles; i++){ tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+0]); tris = put_set(tris, i); verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+0], tris); tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+1]); tris = put_set(tris, i); verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+1], tris); tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+2]); tris = put_set(tris, i); verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+2], tris); } int min = 100000; int max = 0; int counter = 0; for(i = 0; i<size_set(verticesMappingToTris); i++){ tris = (set_t) mapsto_set(verticesMappingToTris, verticesMappingToTris[i]); if(min > size_set(tris)){ min = size_set(tris); if(size_set(tris) == 0){ counter++; } } if(max < size_set(tris)){ max = size_set(tris); } } printf("MAXIMUM NUMBER OF TRIANLGES ASSOCIATED WITH A point: %i\n", max); printf("MINIMUM NUMBER OF TRIANLGES ASSOCIATED WITH A point: %i (total 0: %i)\n", min, counter); set_t set1; set_t set2; set_t tempSet; int numCommon; int * tri = new int[3]; ///iterate through all triangles, for(i = 0; i<numTriangles; i++){ tri[0] = triangles[3*i+0]; tri[1] = triangles[3*i+1]; tri[2] = triangles[3*i+2]; ///for each edge on the triangle, verify that exactly two ///distinct triangles are part of that edge. otherwise it is ///a non-manifold edge. for(j = 0; j<3; j++){ //set the two vertices of the edge we are working on int t1 = tri[(j+0)%3]; int t2 = tri[(j+1)%3]; //identify the set of triangles adjacent to each endpoint set1 = (set_t) mapsto_set(verticesMappingToTris, t1); set2 = (set_t) mapsto_set(verticesMappingToTris, t2); ///find out how many triangles are common between these endpoints numCommon = countNumCommon(set1, set2); //if numCommon == 1, then this is an edge of a nonmanifold surface. Store it. if(numCommon == 1){ if(!contains_set(nonManifold, t1)){ tempSet = alloc_set(0); } else{ tempSet = (set_t) mapsto_set(nonManifold, t1); } tempSet = put_set(tempSet, t2); nonManifold = associate_set(nonManifold, t1, tempSet); if(!contains_set(nonManifold, t2)){ tempSet = alloc_set(0); } else{ tempSet = (set_t) mapsto_set(nonManifold, t2); } tempSet = put_set(tempSet, t1); nonManifold = associate_set(nonManifold, t2, tempSet); // printf("Edge: %i %i\n", t1, t2); } //if numCommon is zero, then there is a serious issue with triangle topology. Report it. if(numCommon == 0){ printf("ERROR: Two vertices of the same triangle (vertex %i and %i in triangle %i) \n", t1, t2, i); printf("ERROR: are not members of at least one triangle, according to our data!!\n"); } //if numCommon is greater than two, there is impossible surface occuring. Report it. if(numCommon > 2){ printf("ERROR: Vertices %i and %i appear to be adjacent to an edge which is part of \n", t1, t2); printf("ERROR: more than two triangles, creating a non-manifold surface! error!\n"); } ///if numCommon is equal to two, that is fine. Report nothing. } ///The end of this loop creates a list of non-manifold edges at the border of the surface, if it exists. } edges = nonManifold; delete[](tri); //free the data structure for(i = 0; i<numPoints; i++){ tris = (set_t) mapsto_set(verticesMappingToTris, i); free_set(tris); } free_set(verticesMappingToTris); }