validate(); } catch (IllegalStateException ise) { throw new IOException(ise.getMessage());
/** * Validates the internal consistency of the mesh. * @exception RuntimeException if the mesh is invalid. */ public synchronized void validate() { // Check nodes. int nnode = 0; NodeIterator ni = getNodes(); while (ni.hasNext()) { ++nnode; Node node = ni.next(); validate(node); } assert nnode==_nnode; // Check tris. int ntri = 0; TriIterator ti = getTris(); while (ti.hasNext()) { ++ntri; Tri tri = ti.next(); validate(tri); } assert ntri==_ntri; }
/** * Validates the specified tri. */ private void validate(Tri tri) { Check.state(tri!=null,"tri not null"); Node na = tri.nodeA(); Node nb = tri.nodeB(); Node nc = tri.nodeC(); validate(na); validate(nb); validate(nc); Tri ta = tri.triA(); Tri tb = tri.triB(); Tri tc = tri.triC(); if (ta!=null) Check.state(ta.triNabor(tri.nodeNabor(ta))==tri,"a nabors ok"); if (tb!=null) Check.state(tb.triNabor(tri.nodeNabor(tb))==tri,"b nabors ok"); if (tc!=null) Check.state(tc.triNabor(tri.nodeNabor(tc))==tri,"c nabors ok"); }
public void benchAddNode() { java.util.Random random = new java.util.Random(); for (int itest=0; itest<3; ++itest) { for (int nnode=1000; nnode<=64000; nnode*=2) { Stopwatch sw = new Stopwatch(); sw.restart(); TriMesh tm = new TriMesh(); for (int inode=0; inode<nnode; ++inode) { float x = random.nextFloat(); float y = random.nextFloat(); TriMesh.Node node = new TriMesh.Node(x,y); tm.addNode(node); } sw.stop(); System.out.println( "Added "+nnode+" nodes to make "+tm.countTris() + " tris in "+sw.time()+" seconds."); tm.validate(); } try { System.out.println("Sleeping"); Thread.sleep(5000,0); } catch (InterruptedException e) { throw new RuntimeException(e); } } }
public void testAddFindRemove() { java.util.Random random = new java.util.Random(); TriMesh tm = new TriMesh(); //int nadd = 0; //int nremove = 0; for (int niter=0; niter<1000; ++niter) { float x = random.nextFloat(); float y = random.nextFloat(); if (tm.countNodes()<10 || random.nextFloat()>0.5f) { TriMesh.Node node = new TriMesh.Node(x,y); boolean ok = tm.addNode(node); assertTrue(ok); tm.validate(); //++nadd; } else if (tm.countNodes()>0) { TriMesh.Node node = tm.findNodeNearest(x,y); assertTrue(node!=null); TriMesh.Node nodeSlow = tm.findNodeNearestSlow(x,y); assertTrue(node==nodeSlow); tm.removeNode(node); tm.validate(); //++nremove; } } //System.out.println("Nodes added/removed = "+nadd+"/"+nremove); }
public void testSimple() { TriMesh tm = new TriMesh(); TriMesh.Node n0 = new TriMesh.Node(0.0f,0.0f); TriMesh.Node n1 = new TriMesh.Node(1.0f,0.0f); TriMesh.Node n2 = new TriMesh.Node(0.0f,1.0f); TriMesh.Node n3 = new TriMesh.Node(0.3f,0.3f); tm.addNode(n0); tm.addNode(n1); tm.addNode(n2); tm.addNode(n3); tm.removeNode(n3); tm.validate(); }
public void testSquare() { TriMesh tm = new TriMesh(); TriMesh.Node n0 = new TriMesh.Node(0.0f,0.0f); TriMesh.Node n1 = new TriMesh.Node(1.0f,0.0f); TriMesh.Node n2 = new TriMesh.Node(0.0f,1.0f); TriMesh.Node n3 = new TriMesh.Node(1.0f,1.0f); tm.addNode(n0); tm.addNode(n1); tm.addNode(n2); tm.addNode(n3); tm.removeNode(n3); tm.removeNode(n2); tm.removeNode(n1); tm.removeNode(n0); tm.validate(); }