outNeighbors = new Vector();
}
-// public Object getData() {
-// return getNodeData(this);
-// }
-//
-// public Object setData(Object n) {
-// return setNodeData(this, n);
-// }
-
+ //public Object getData() {
+ // return getNodeData(this);
+ //}
+ //
+ //public Object setData(Object n) {
+ // return setNodeData(this, n);
+ //}
+
public final boolean addInNeighbor(GraphNode n) {
if (inNeighbors.contains(n)) {
return false;
-public class Node {
+abstract public class Node {
//None of the program actually uses getData/setData so I use leave Node as a
//wrapper interface.
-// public abstract Object getData();
-// public abstract Object setData(Object obj);
+ //public abstract Object getData();
+ //public abstract Object setData(Object obj);
}
if (runtime < mintime) {
mintime = runtime;
}
+ //System.exit( 0 ); // GC STALLS FOREVER????
System.gc();
}
System.gc();
+
+ int zzz = 0;
+
+
// long id = Time.getNewTimeId();
long startTime = System.currentTimeMillis();
+
while (!worklist.isEmpty()) {
Node bad_element = (Node) worklist.pop();
// System.out.println("Bad Node"+ ((Element)mesh.getNodeData(bad_element)).toString());
cavity.initialize(bad_element);
cavity.build();
cavity.update();
+
+
+ //boolean printChange = true; //(zzz % 10 == 0);
//remove old data
+ //if( printChange ) {
+ // System.out.println( "\n\n\nbad tri: "+mesh.getNodeData( bad_element ) );
+ // System.out.println( "\npre nodes: " );
+ //}
Node node;
for (Iterator iterator = cavity.getPre().getNodes().iterator(); iterator.hasNext();) {
node = (Node) iterator.next();
+ //if( printChange ) {
+ // System.out.println( " "+mesh.getNodeData( node ) );
+ //}
mesh.removeNode(node);
}
//add new data
+ //if( printChange ) {
+ // System.out.println( "post nodes: " );
+ //}
for (Iterator iterator1 = cavity.getPost().getNodes().iterator(); iterator1.hasNext();) {
node = (Node) iterator1.next();
+ //if( printChange ) {
+ // System.out.println( " "+mesh.getNodeData( node ) );
+ //}
mesh.addNode(node);
}
+ //if( printChange ) {
+ // System.out.println( "post edges: " );
+ //}
Edge_d edge;
for (Iterator iterator2 = cavity.getPost().getEdges().iterator(); iterator2.hasNext();) {
edge = (Edge_d) iterator2.next();
+ //if( printChange ) {
+ // System.out.println( " "+mesh.getEdgeData( edge ) );
+ //}
mesh.addEdge(edge);
}
if (mesh.containsNode(bad_element)) {
worklist.push((Node) bad_element);
}
+ } else {
+ //System.out.println( "\n\n\nthis tri no longer a concern: "+mesh.getNodeData( bad_element ) );
}
+
+ //++zzz;
+ //System.out.println( "\n\ntris="+mesh.getNumNodes()+
+ // " [wl="+worklist.size()+"]");
+ //if( zzz == 10 ) { System.exit( 0 ); }
}
long time = System.currentTimeMillis() - startTime;
System.out.println("runtime: " + time + " ms");
}
public String toString() {
- return new String("(" + coords[0] + ", " + coords[1] + ", " + coords[2] + ")");
+ //return new String("(" + coords[0] + ", " + coords[1] + ", " + coords[2] + ")");
+
+ String x = ""+coords[0];
+ x = x.substring( 0, 4 );
+
+ String y = ""+coords[1];
+ y = y.substring( 0, 4 );
+
+ return new String("("+x+", "+y+")");
}
public static int cmp(Tuple a, Tuple b) {
--- /dev/null
+5
+0 0 1 3
+1 1 2 3
+2 2 3 5
+3 3 4 5
+4 0 3 4
--- /dev/null
+6
+0 1 1 0
+1 4 1 0
+2 7 2 0
+3 5 3 0
+4 0 9 0 //if you use this for point 4 it works fine: 2 6 0
+5 6 6 0
--- /dev/null
+ignored line
+5
+0 0 1
+1 1 2
+2 2 5
+3 5 4
+4 4 0
}
private Edge_d getOpposite(Node node) {
- Element element = (Element) getNodeData(node);
+ Element element = (Element) graph.getNodeData(node);
- System.out.println( "\n element="+element+" with obtuse="+element.getObtuse() );
+ // Don't think we'd run into it but..
+ // TODO check this.
+ // if(neighbors.size() != 3)
+ // throw new Error(String.format("neighbors %d", new Object[] {
+ // Integer.valueOf(neighbors.size())
+ // }));
- int outNeiCnt = 0;
+ int cntOutNeighbors = 0;
- for (Iterator iterator = getOutNeighbors(node); iterator.hasNext();) {
- ++outNeiCnt;
+ for (Iterator iterator = graph.getOutNeighbors(node); iterator.hasNext();) {
+ ++cntOutNeighbors;
Node neighbor = (Node) iterator.next();
- Edge_d edge = getEdge(node, neighbor);
- ElementEdge edge_data = (ElementEdge) getEdgeData(edge);
-
- System.out.println( " is "+edge_data.getPoint(0)+" and "+edge_data.getPoint(1)+
- " opposite the obtuse?");
-
- if (element.getObtuse().notEquals(edge_data.getPoint(0)) &&
- element.getObtuse().notEquals(edge_data.getPoint(1))
- )
+ Edge_d edge = graph.getEdge(node, neighbor);
+ ElementEdge edge_data = (ElementEdge) graph.getEdgeData(edge);
+ if (element.getObtuse().notEquals(edge_data.getPoint(0))
+ && element.getObtuse().notEquals(edge_data.getPoint(1)))
return edge;
}
- int inNeiCnt = 0;
-
- for (Iterator iterator = ((EdgeGraphNode)node).getInNeighbors(); iterator.hasNext();) {
- ++inNeiCnt;
- Node neighbor = (Node) iterator.next();
- }
-
- if( outNeiCnt != 3 ) {
- System.out.println( "Get opposite when "+outNeiCnt+" out-neighbors? in-nei="+inNeiCnt );
- }
-
System.out.println("Error: \"Edge\" in Cavity.java getOpposite(Node)");
+ System.out.println(" tri="+element+" has "+cntOutNeighbors+" out-neighbors");
+ System.out.println(" obtuse="+element.getObtuse());
System.exit(-1);
return null; // it's here so the compiler doesn't complain.
}
}
}
}
-
- System.out.println( "Graph has "+nodes.size()+" nodes currently." );
- }
-
-// // keep the nodes set up-to-date, but use AFTER...
-// public void addNodeToAllNodesSet( Node n ) {
-// if( !n.inGraph ) {
-// System.out.println( "Error: adding a node NOT IN the graph to the all-nodes set!" );
-// System.exit( -1 );
-// }
-// nodes.add( n );
-// }
-//
-// public void removeNodeFromAllNodesSet( Node n ) {
-// if( n.inGraph ) {
-// System.out.println( "Error: removing a node IN the graph from the all-nodes set!" );
-// System.exit( -1 );
-// }
-// nodes.add( n );
-// }
+ }
// these are the normal methods for truly adding and removing nodes
// from the graph, nodes know locally if they are in and out but they
public boolean removeNode(Node n) {
boolean wasIn = n.inGraph;
+ n.inGraph = false;
removeConnectingEdges((EdgeGraphNode) n);
return wasIn;
}
Cavity lastAppliedCavity = null;
+ int zzz = 0;
+
+
long startTime = System.currentTimeMillis();
while (!worklist.isEmpty()) {
nodeForBadTri.inGraph
) {
- System.out.println( "computing a cavity..." );
+ //System.out.println( "computing a cavity for tri "+
+ // mesh.getNodeData( nodeForBadTri )+"..." );
sese computeCavity {
//takes < 1 sec
//Takes up a whooping 50% of computation time and changes NOTHING but cavity :D
cavity.update();
}
-
+
sese storeCavity {
cavities[i] = cavity;
}
appliedCavity = true;
lastAppliedCavity = cavity;
+
+ //boolean printChange = true; //(zzz % 10 == 0);
+
+
//remove old data
Node node;
-
+ //if( printChange ) {
+ // System.out.println( "\n\n\nbad tri: "+mesh.getNodeData( nodeForBadTri ) );
+ // System.out.println( "\npre nodes: " );
+ //}
//Takes up 8.9% of runtime
for (Iterator iterator = cavity.getPre().getNodes().iterator();
iterator.hasNext();) {
node = (Node) iterator.next();
+ //if( printChange ) {
+ // System.out.println( " "+mesh.getNodeData( node ) );
+ //}
mesh.removeNode(node);
}
//add new data
+ //if( printChange ) {
+ // System.out.println( "post nodes: " );
+ //}
//Takes up 1.7% of runtime
for (Iterator iterator1 = cavity.getPost().getNodes().iterator();
iterator1.hasNext();) {
node = (Node) iterator1.next();
+ //if( printChange ) {
+ // System.out.println( " "+mesh.getNodeData( node ) );
+ //}
mesh.addNode(node);
}
+ //if( printChange ) {
+ // System.out.println( "post edges: " );
+ //}
//Takes up 7.8% of runtime
Edge_d edge;
for (Iterator iterator2 = cavity.getPost().getEdges().iterator();
iterator2.hasNext();) {
edge = (Edge_d) iterator2.next();
+ //if( printChange ) {
+ // System.out.println( " "+mesh.getEdgeData( edge ) );
+ //}
mesh.addEdge(edge);
}
}
sese scheduleMoreBad {
+
+ if( appliedCavity ) {
+ // we did apply the cavity, and we may
+ // have introduced new bad triangles
+ HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator();
+ while (it2.hasNext()) {
+ worklist.push((Node)it2.next());
+ }
+ }
+
+ // the logic of having this out here seems wacky, and overconservative,
+ // but it matches the original algorithm and it works...
+ if( nodeForBadTri != null && mesh.containsNode( nodeForBadTri ) ) {
+ worklist.push( nodeForBadTri );
+ }
+ /*
if( !appliedCavity ) {
// if we couldn't even apply this cavity, just
// throw it back on the worklist
if( nodeForBadTri != null && nodeForBadTri.inGraph ) {
worklist.push( nodeForBadTri );
+ } else {
+ System.out.println( "\n\n\nthis tri no longer a concern: "+
+ mesh.getNodeData( nodeForBadTri ) );
}
} else {
- // otherwise we did apply the cavity, so repair the all-nodes set of the mesh
- //Iterator itrPreNodes = cavity.getPre().getNodes().iterator();
- //while( itrPreNodes.hasNext() ) {
- // System.out.println( "yere" );
- // mesh.removeNodeFromAllNodesSet( (Node)itrPreNodes.next() );
- // System.out.println( "yeres" );
- //}
- //Iterator itrPostNodes = cavity.getPost().getNodes().iterator();
- //while( itrPostNodes.hasNext() ) {
- // mesh.addNodeToAllNodesSet( (Node)itrPostNodes.next() );
- //}
-
+ // otherwise we did apply the cavity,
// and 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
+ //++zzz;
+ //Node aNode = (Node)lastAppliedCavity.getPost().getNodes().iterator().next();
+ //mesh.discoverAllNodes( aNode );
+ //System.out.println( "\n\ntris="+mesh.getNumNodes()+
+ // " [wl="+worklist.size()+"]");
+ //if( zzz == 10 ) { System.exit( 0 ); }
+
} // end while( !worklist.isEmpty() )
long time = System.currentTimeMillis() - startTime;
return 57.295779513082323D * Math.acos(d);
}
- public String toString() {
- return new String("(" + coords[0] + ", " + coords[1] + ", " + coords[2] + ")");
+ public String toString() {
+ //return new String("(" + coords[0] + ", " + coords[1] + ", " + coords[2] + ")");
+
+ String x = ""+coords[0];
+ x = x.substring( 0, 4 );
+
+ String y = ""+coords[1];
+ y = y.substring( 0, 4 );
+
+ return new String("("+x+", "+y+")");
}
public static int cmp(Tuple a, Tuple b) {
--- /dev/null
+5
+0 0 1 3
+1 1 2 3
+2 2 3 5
+3 3 4 5
+4 0 3 4
--- /dev/null
+6
+0 1 1 0
+1 4 1 0
+2 7 2 0
+3 5 3 0
+4 0 9 0 //if you use this for point 4 it works fine: 2 6 0
+5 6 6 0
--- /dev/null
+ignored line
+5
+0 0 1
+1 1 2
+2 2 5
+3 5 4
+4 4 0