+
+ // Phase 3, apply cavities to mesh, if still applicable
+ // this phase can proceed in parallel when a cavity's
+ // start nodes are still present
+ for(int i=0;i<numWorkers;i++) {
+
+ Cavity cavity = cavities[i];
+
+ Node nodeForBadTri = null;
+
+ sese applyCavity {
+
+ // go ahead with applying cavity when all of its
+ // pre-nodes are still in
+ if( cavity.getPre().allNodesStillInCompleteGraph() ) {
+
+ //remove old data
+ Node node;
+
+ //Takes up 8.9% of runtime
+ for (Iterator iterator = cavity.getPre().getNodes().iterator(); iterator.hasNext();) {
+ node = (Node) iterator.next();
+ mesh.removeNode(node);
+ }
+
+ //add new data
+ //Takes up 1.7% of runtime
+ for (Iterator iterator1 = cavity.getPost().getNodes().iterator(); iterator1.hasNext();) {
+ node = (Node) iterator1.next();
+ mesh.addNode(node);
+ }
+
+ //Takes up 7.8% of runtime
+ Edge_d edge;
+ for (Iterator iterator2 = cavity.getPost().getEdges().iterator(); iterator2.hasNext();) {
+ edge = (Edge_d) iterator2.next();
+ mesh.addEdge(edge);
+ }
+
+ } else {
+ // otherwise forget the cavity and reschedule the bad triangle
+ nodeForBadTri = nodesForBadTris[i];
+ }
+ }
+
+
+ sese scheduleMoreBad {
+
+ // if we couldn't even apply this cavity, just
+ // throw it back on the worklist
+ if( nodeForBadTri != null ) {
+
+ if( nodeForBadTri.inGraph ) {
+ worklist.push( nodeForBadTri );
+ }
+
+ } else {
+ // otherwise we did apply the cavity, but we
+ // may have introduced new bad triangles
+ HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator();
+ while (it2.hasNext()) {
+ worklist.push((Node)it2.next());
+ }
+ }
+ } // end scheduleMoreBad
+ } // end phase 3
+
+ } // end while( !worklist.isEmpty() )
+