public double accumulateAreas( double xp, double yp, TriMesh mesh, TriMesh.NodeList nodeList, TriMesh.TriList triList) { clear(); int ntri = triList.ntri(); TriMesh.Tri[] tris = triList.tris(); for (int itri=0; itri<ntri; ++itri) { TriMesh.Tri tri = tris[itri]; TriMesh.Node na = tri.nodeA(); TriMesh.Node nb = tri.nodeB(); TriMesh.Node nc = tri.nodeC(); double xa = na.xp(), ya = na.yp(); double xb = nb.xp(), yb = nb.yp(); double xc = nc.xp(), yc = nc.yp(); Geometry.centerCircle(xp,yp,xb,yb,xc,yc,_ca); Geometry.centerCircle(xp,yp,xc,yc,xa,ya,_cb); Geometry.centerCircle(xp,yp,xa,ya,xb,yb,_cc); Geometry.centerCircle(xa,ya,xb,yb,xc,yc,_ct); double aa = area(_cb,_cc,_ct); double ab = area(_cc,_ca,_ct); double ac = area(_ca,_cb,_ct); accumulate(na,aa); accumulate(nb,ab); accumulate(nc,ac); } return sum(); } private double[] _ca = new double[2]; // circumcenter of fake tri pbc
private void processTris( double xp, double yp, TriMesh mesh, TriMesh.TriList triList) { _edgeList.clear(); int ntri = triList.ntri(); TriMesh.Tri[] tris = triList.tris(); for (int itri=0; itri<ntri; ++itri) { TriMesh.Tri tri = tris[itri]; TriMesh.Tri ta = tri.triA(); TriMesh.Tri tb = tri.triB(); TriMesh.Tri tc = tri.triC(); TriMesh.Node na = tri.nodeA(); TriMesh.Node nb = tri.nodeB(); TriMesh.Node nc = tri.nodeC(); tri.centerCircle(_xy); double xt = _xy[0]-xp, yt = _xy[1]-yp; processTriNabor(xp,yp,xt,yt,mesh,ta,nb,nc); processTriNabor(xp,yp,xt,yt,mesh,tb,nc,na); processTriNabor(xp,yp,xt,yt,mesh,tc,na,nb); } } private void processTriNabor(
/** * Returns a new tri, possibly one resurrected from the dead. * Resurrection reduces the need for garbage collection of dead tris. */ private Tri makeTri(Node n0, Node n1, Node n2) { ++_ntri; int ndead = _deadTris.ntri(); if (ndead==0) { _troot = new Tri(n0,n1,n2); } else { _troot = _deadTris.remove(ndead-1); _troot.init(n0,n1,n2); } if (_ntriListeners>0) fireTriAdded(_troot); return _troot; }
/** * Kills a tri and, if there is room, buries it in the graveyard, * from where it may be resurrected later. */ private void killTri(Tri tri) { --_ntri; fireTriRemoved(tri); int ndead = _deadTris.ntri(); if (ndead<256) { _deadTris.add(tri); } // We assume that killTri is called only within contexts in // which _troot is updated to point to a live tri in the mesh. // Therefore, we do not update _troot here, when _troot==tri. }