public void setScattered(float[] f, float[] x1, float[] x2, float[] x3) { _f = copy(f); _mesh = new TetMesh(); int n = f.length; for (int i=0; i<n; ++i) { TetMesh.Node node = new TetMesh.Node(x1[i],x2[i],x3[i]); node.index = i; boolean added = _mesh.addNode(node); Check.argument(added,"samples have unique coordinates (x1,x2,x3)"); } }
/** * Returns the number of nodes in the surface. * @return the number of nodes. */ public int countNodes() { return _mesh.countNodes(); }
/** * Finds the node nearest to the point with specified coordinates. * @param x the x coordinate. * @param y the y coordinate. * @param z the z coordinate. * @return the nearest node. */ public synchronized Node findNodeNearest(float x, float y, float z) { return findNodeNearest((double)x,(double)y,(double)z); }
/** * Returns a tet that references the specified nodes. * @param na a node. * @param nb a node. * @return a tet that references the specified nodes; * or null, if a node is not in the mesh or the mesh * has no tets. */ public synchronized Tet findTet(Node na, Node nb) { Tet tet = findTet(na); if (tet!=null) { clearTetMarks(); tet = findTet(tet,na,nb); } return tet; }
/** * Finds an edge of a tet in the mesh that references the specified nodes. * The nodes may be specified in any order. * @param na a node. * @param nb a node. * @return an edge of a tet that references the specified nodes. * If no such edge exists in this mesh, returns null. */ public synchronized Edge findEdge(Node na, Node nb) { Tet tet = findTet(na,nb); if (tet!=null) { return edgeOfTet(tet,na,nb); } else { return null; } }
/** * Finds a face of a tet in the mesh that references the specified nodes. * The nodes may be specified in any order. However, if not null, * the returned face always has a mate, and either the returned * face or its mate references the specified nodes in the specified * order. * @param na a node. * @param nb a node. * @param nc a node. * @return a face of a tet that references the specified nodes. * If no such face exists in this mesh, returns null. */ public synchronized Face findFace(Node na, Node nb, Node nc) { Tet tet = findTet(na,nb,nc); if (tet!=null) { return faceOfTet(tet,na,nb,nc); } else { return null; } }
public void testNabors() { TetMesh tm = new TetMesh(); TetMesh.Node n0 = new TetMesh.Node(1.0f,0.0f,0.0f); TetMesh.Node n1 = new TetMesh.Node(0.0f,1.0f,0.0f); TetMesh.Node n3 = new TetMesh.Node(0.0f,0.0f,0.0f); TetMesh.Node n4 = new TetMesh.Node(1.1f,1.1f,1.1f); tm.addNode(n0); tm.addNode(n1); tm.addNode(n2); tm.addNode(n3); tm.addNode(n4); assertEquals(2,tm.getTetNabors(n0).length); assertEquals(2,tm.getTetNabors(n1).length); assertEquals(2,tm.getTetNabors(n2).length); assertEquals(1,tm.getTetNabors(n3).length); assertEquals(1,tm.getTetNabors(n4).length); assertEquals(2,tm.getTetNabors(tm.findEdge(n0,n1)).length); assertEquals(2,tm.getTetNabors(tm.findEdge(n1,n2)).length); assertEquals(2,tm.getTetNabors(tm.findEdge(n2,n0)).length); assertEquals(1,tm.getTetNabors(tm.findEdge(n0,n3)).length); assertEquals(1,tm.getTetNabors(tm.findEdge(n0,n4)).length); assertEquals(1,tm.getTetNabors(tm.findEdge(n1,n3)).length); assertEquals(1,tm.getTetNabors(tm.findEdge(n1,n4)).length); assertEquals(1,tm.getTetNabors(tm.findEdge(n2,n3)).length); assertEquals(1,tm.getTetNabors(tm.findEdge(n2,n4)).length); assertEquals(2,tm.getTetNabors(tm.findFace(n0,n1,n2)).length); assertEquals(1,tm.getTetNabors(tm.findFace(n0,n2,n3)).length); assertEquals(1,tm.getTetNabors(tm.findFace(n1,n3,n2)).length); assertEquals(1,tm.getTetNabors(tm.findFace(n0,n3,n1)).length);
public void testLine() { TetMesh tm = new TetMesh(); int n = 100; for (int i=0; i<n; ++i) { float x = (float)i; float y = 3.14f; float z = 4.13f; TetMesh.Node node = new TetMesh.Node(x,y,z); tm.addNode(node); } tm.validate(); for (int i=0; i<n; ++i) { float x = (float)i; float y = 3.14f; float z = 4.13f; TetMesh.Node node = tm.findNodeNearest(x,y,z); tm.removeNode(node); } tm.validate(); }
public void testAddFindRemove() { java.util.Random random = new java.util.Random(); TetMesh tm = new TetMesh(); //int nadd = 0; //int nremove = 0; for (int niter=0; niter<1000; ++niter) { float x = random.nextFloat(); float y = random.nextFloat(); float z = random.nextFloat(); if (tm.countNodes()<10 || random.nextFloat()>0.5f) { TetMesh.Node node = new TetMesh.Node(x,y,z); boolean ok = tm.addNode(node); assertTrue(ok); tm.validate(); //++nadd; } else if (tm.countNodes()>0) { TetMesh.Node node = tm.findNodeNearest(x,y,z); assertTrue(node!=null); TetMesh.Node nodeSlow = tm.findNodeNearestSlow(x,y,z); assertTrue(node==nodeSlow); tm.removeNode(node); tm.validate(); //++nremove; } } //System.out.println("Nodes added/removed = "+nadd+"/"+nremove); }
TetMesh.Node n110 = new TetMesh.Node(1.0f,1.0f,0.0f); TetMesh.Node n111 = new TetMesh.Node(1.0f,1.0f,1.0f); TetMesh tm = new TetMesh(); tm.addNode(n000); tm.addNode(n001); tm.addNode(n010); tm.addNode(n011); tm.addNode(n100); tm.addNode(n101); tm.addNode(n110); tm.addNode(n111); int nnode = tm.countNodes(); int ntet = tm.countTets(); assertEquals(8,nnode); TetMesh.NodePropertyMap map = tm.getNodePropertyMap("foo"); map.put(n000,0); map.put(n001,1); tm = (TetMesh)ois.readObject(); bais.close(); assertEquals(nnode,tm.countNodes()); assertEquals(ntet,tm.countTets()); String name = tm.getNodePropertyMapNames()[0]; assertEquals("foo",name); map = tm.getNodePropertyMap(name); n000 = tm.findNodeNearest(0.0f,0.0f,0.0f); n001 = tm.findNodeNearest(0.0f,0.0f,1.0f); n010 = tm.findNodeNearest(0.0f,1.0f,0.0f);
public void testFinds() { TetMesh tm = new TetMesh(); TetMesh.Node n0 = new TetMesh.Node(0.0f,0.0f,0.0f); TetMesh.Node n1 = new TetMesh.Node(1.0f,0.0f,0.0f); TetMesh.Node n3 = new TetMesh.Node(0.0f,0.0f,1.0f); TetMesh.Node n4 = new TetMesh.Node(9.0f,9.0f,9.0f); tm.addNode(n0); tm.addNode(n1); tm.addNode(n2); tm.addNode(n3); tm.addNode(n4); TetMesh.Tet tet = tm.findTet(n0); assertTrue(tet!=null); assertTrue(tet==tm.findTet(n0,n1)); assertTrue(tet==tm.findTet(n0,n2)); assertTrue(tet==tm.findTet(n0,n3)); assertTrue(tet==tm.findTet(n0,n1,n3)); assertTrue(tet==tm.findTet(n0,n1,n3)); assertTrue(tet==tm.findTet(n0,n2,n3)); assertTrue(tet==tm.findTet(n0,n1,n2,n3)); assertTrue(null==tm.findTet(n0,n4)); assertTrue(null==tm.findTet(n0,n1,n4)); assertTrue(null==tm.findTet(n0,n2,n4)); assertTrue(null==tm.findTet(n0,n3,n4)); assertTrue(null==tm.findTet(n0,n1,n2,n4)); assertTrue(null==tm.findTet(n0,n1,n3,n4)); assertTrue(null==tm.findTet(n0,n2,n3,n4));
sw.reset(); sw.start(); TetMesh tm = new TetMesh(); for (int inode=0; inode<nnode; ++inode) { float x = random.nextFloat(); float z = random.nextFloat(); TetMesh.Node node = new TetMesh.Node(x,y,z); tm.addNode(node); "Added "+nnode+" nodes to make "+tm.countTets() + " tets in "+sw.time()+" seconds."); tm.validate();
EdgeSet edgeSet = new EdgeSet(16*countNodes(),0.5f); ArrayList<Edge> edgeList = new ArrayList<Edge>(8*countNodes()); NodeIterator inode = getNodes(); while (inode.hasNext()) { Node na = inode.next(); Node[] nabors = getNodeNabors(na); int nnabor = nabors.length; for (int inabor=0; inabor<nnabor; ++inabor) { Node nb = nabors[inabor]; if (edgeSet.add(na,nb,null,null)) { Tet tet = findTet(na,nb); Edge edge = new Edge(tet,na,nb); edgeList.add(edge);
public void testTetListener() { TetMesh tm = new TetMesh(); tm.addNode(new TetMesh.Node(0.0f,0.0f,0.0f)); tm.addNode(new TetMesh.Node(1.0f,0.0f,0.0f)); tm.addNode(new TetMesh.Node(0.0f,1.0f,0.0f)); tm.addNode(new TetMesh.Node(0.0f,0.0f,1.0f)); TetListener tl = new TetListener(); tm.addTetListener(tl); TetMesh.Node node = new TetMesh.Node(0.1f,0.1f,0.1f); tm.addNode(node); assertEquals(4,tl.countAdded()); assertEquals(1,tl.countRemoved()); tm.removeNode(node); assertEquals(5,tl.countAdded()); assertEquals(5,tl.countRemoved()); } private static class TetListener implements TetMesh.TetListener {
java.util.Random random = new java.util.Random(); Stopwatch sw = new Stopwatch(); TetMesh tm = new TetMesh(); for (int inode=0; inode<nnode; ++inode) { float x = random.nextFloat(); float z = random.nextFloat(); TetMesh.Node node = new TetMesh.Node(x,y,z); tm.addNode(node); sw.start(); for (int ifind=0; ifind<nfind; ++ifind) nfast[ifind] = tm.findNodeNearest(x[ifind],y[ifind],z[ifind]); sw.stop(); int sfast = (int)(nfind/sw.time()); sw.start(); for (int ifind=0; ifind<nfind; ++ifind) nslow[ifind] = tm.findNodeNearestSlow(x[ifind],y[ifind],z[ifind]); sw.stop(); int sslow = (int)(nfind/sw.time());
mark(tet); Node n0 = tet._n0; Node n1 = tet._n1; if (na==n0) { if (nb==n1 || nb==n2 || nb==n3 || t1!=null && !isMarked(t1) && (tet=findTet(t1,na,nb))!=null || t2!=null && !isMarked(t2) && (tet=findTet(t2,na,nb))!=null || t3!=null && !isMarked(t3) && (tet=findTet(t3,na,nb))!=null) return tet; } else if (na==n1) { if (nb==n3 || nb==n2 || nb==n0 || t3!=null && !isMarked(t3) && (tet=findTet(t3,na,nb))!=null || t2!=null && !isMarked(t2) && (tet=findTet(t2,na,nb))!=null || t0!=null && !isMarked(t0) && (tet=findTet(t0,na,nb))!=null) return tet; } else if (na==n2) { if (nb==n3 || nb==n0 || nb==n1 || t3!=null && !isMarked(t3) && (tet=findTet(t3,na,nb))!=null || t0!=null && !isMarked(t0) && (tet=findTet(t0,na,nb))!=null || t1!=null && !isMarked(t1) && (tet=findTet(t1,na,nb))!=null) return tet; } else if (na==n3) { if (nb==n1 || nb==n0 || nb==n2 || t1!=null && !isMarked(t1) && (tet=findTet(t1,na,nb))!=null || t0!=null && !isMarked(t0) && (tet=findTet(t0,na,nb))!=null || t2!=null && !isMarked(t2) && (tet=findTet(t2,na,nb))!=null) return tet; } else {
Node nodeNearest = findNodeNearest(x,y,z); if (node==nodeNearest || x!=nodeNearest.x() || y!=nodeNearest.y() || z!=nodeNearest.z()) { boolean nodeInMesh = removeNode(node); node.setPosition(x,y,z); if (nodeInMesh) { boolean addedNode = addNode(node); assert addedNode;
/** * Determines whether the specified edge is an inner edge. * @param edge an edge. * @return true, if inner; false, otherwise. */ public boolean isInner(Edge edge) { Tet tet = edge.tet(); if (tet==null) tet = findTet(edge.nodeA(),edge.nodeB()); if (tet==null) return false; if (tet.isInner()) return true; Tet[] tets = getTetNabors(edge); int ntet = tets.length; for (int itet=0; itet<ntet; ++itet) { if (isInner(tets[itet])) return true; } return false; }
/** * Appends the tet nabors of the specified edge to the specified list. * @param edge the edge for which to get nabors. * @param nabors the list to which nabors are appended. */ public synchronized void getTetNabors(Edge edge, TetList nabors) { Node na = edge.nodeA(); Node nb = edge.nodeB(); Tet tet = edge.tet(); if (tet==null) tet = findTet(na,nb); if (tet==null) return; clearTetMarks(); getTetNabors(na,nb,tet,nabors); }
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) { _mesh.addNode(_nodes[i[iv]]); return fv;