private void removeGhostNodes() { // First make a list of all ghost nodes. ArrayList<TriMesh.Node> gnodes = new ArrayList<TriMesh.Node>(4); TriMesh.NodeIterator ni = _mesh.getNodes(); while (ni.hasNext()) { TriMesh.Node n = ni.next(); if (ghost(n)) gnodes.add(n); } // Then remove the ghost nodes from the mesh. for (TriMesh.Node gnode:gnodes) _mesh.removeNode(gnode); }
/** * Interpolates at specified sample points without using those samples. * This method implements a form of cross-validation. Differences * between the values of the specified samples and the returned * interpolated values are measures of errors for those samples. * <p> * If bounds have not been set explicitly, then this method will return * null values if the validated sample is on the convex hull of samples. * <p> * This method does not recompute gradients that may have been estimated * using the samples to be validated. Therefore, validation should be * performed without using gradients. * @param i array of indices of samples to validate. * @return array of values interpolated at validated sample points. */ public float[] validate(int[] i) { int nv = i.length; for (int iv=0; iv<nv; ++iv) _mesh.removeNode(_nodes[i[iv]]); float[] fv = new float[nv]; for (int iv=0; iv<nv; ++iv) { TriMesh.Node node = _nodes[i[iv]]; float xn = node.x(); float yn = node.y(); fv[iv] = interpolate(xn,yn); } for (int iv=0; iv<nv; ++iv) _mesh.addNode(_nodes[i[iv]]); return fv; }
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(); }
/** * Moves a node in the mesh to the specified (x,y) coordinates. * Roughly equivalent to (but potentially more efficient than) * first removing and then adding the node to the mesh at the * specified coordinates. However, if the node is not in the mesh, * then it will be moved, but not added to the mesh. Also, if the * specified coordinates are already occupied by another node in * the mesh, then the specified node is not moved. * @param node a node in the mesh. * @param x the x coordinate of the moved node. * @param y the y coordinate of the moved node. * @return true, if the node was moved; false, otherwise. */ public synchronized boolean moveNode(Node node, float x, float y) { // TODO: optimize for small movements that require no retriangulation. if (x!=node.x() || y!=node.y()) { Node nodeNearest = findNodeNearest(x,y); if (node==nodeNearest || x!=nodeNearest.x() || y!=nodeNearest.y()) { boolean nodeInMesh = removeNode(node); node.setPosition(x,y); if (nodeInMesh) { boolean addedNode = addNode(node); assert addedNode; } return true; } } return false; }
double xn = n.xp(); double yn = n.yp(); _mesh.removeNode(n); double asum = computeAreas((float)xn,(float)yn); _mesh.addNode(n);
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 testTriListener() { TriMesh tm = new TriMesh(); tm.addNode(new TriMesh.Node(0.0f,0.0f)); tm.addNode(new TriMesh.Node(1.0f,0.0f)); tm.addNode(new TriMesh.Node(0.0f,1.0f)); TriListener tl = new TriListener(); tm.addTriListener(tl); TriMesh.Node node = new TriMesh.Node(0.1f,0.1f); tm.addNode(node); assertEquals(3,tl.countAdded()); assertEquals(1,tl.countRemoved()); tm.removeNode(node); assertEquals(4,tl.countAdded()); assertEquals(4,tl.countRemoved()); } private static class TriListener implements TriMesh.TriListener {