Search in sources :

Example 1 with DynamicArray

use of maspack.util.DynamicArray in project artisynth_core by artisynth.

the class MFreeFactory method findNodesContaining.

// public static ArrayList<MFreeElement3d> createPartitionedElements(
// MFreeShapeFunction fun,
// List<MFreeNode3d> nodes, DirectedGraph<int[],Integer> connectivityGraph) {
// 
// ArrayList<MFreeElement3d> elems =
// new ArrayList<MFreeElement3d>(connectivityGraph.numVertices());
// 
// for (Vertex<int[],Integer> vtx : connectivityGraph.getVertices()) {
// 
// int[] idxs = vtx.getData();
// if (idxs.length > 0) {
// MFreeNode3d[] enodes = new MFreeNode3d[idxs.length];
// for (int i = 0; i < idxs.length; i++) {
// enodes[i] = nodes.get(idxs[i]);
// }
// MFreeElement3d elem = new MFreeElement3d(fun, enodes);
// elem.setAllTermsActive(true);
// elems.add(elem);
// }
// }
// 
// return elems;
// 
// }
// public static ArrayList<MFreeElement3d> createPairedElements(
// MFreeShapeFunction fun,
// List<MFreeNode3d> nodes, boolean[][] iChart) {
// // elements from node pairs
// ArrayList<MFreeElement3d> elemList = new ArrayList<MFreeElement3d>();
// for (int i = 0; i < nodes.size(); i++) {
// MFreeNode3d nodeA = nodes.get(i);
// MFreeElement3d e = new MFreeElement3d(fun, new MFreeNode3d[] { nodeA });
// e.setTermActive(0, 0, true);
// elemList.add(e);
// for (int j = i + 1; j < nodes.size(); j++) {
// if (iChart[i][j]) {
// e =
// new MFreeElement3d(fun, new MFreeNode3d[] { nodeA, nodes.get(j) });
// e.setTermActive(0, 1, true);
// e.setTermActive(1, 0, true);
// e.setTermActive(0, 0, false);
// e.setTermActive(1, 1, false);
// elemList.add(e);
// }
// }
// }
// 
// return elemList;
// }
// 
// public static void createNodeMeshes(MFreeModel3d model,
// Collection<MFreeNode3d> nodes, PolygonalMesh surface) {
// 
// // set nodal influence regions
// PolygonalMesh icoSphere = MeshFactory.createIcosahedralSphere(1, 2);
// 
// if (nodes == null) {
// nodes = model.getNodes();
// }
// 
// HashMap<MFreeNode3d,PolygonalMesh> meshMap = new HashMap<MFreeNode3d,PolygonalMesh>();
// AffineTransform3d trans = new AffineTransform3d();
// for (MFreeNode3d node : nodes) {
// PolygonalMesh nmesh = null;
// if (node.isRadial()) {
// nmesh = new PolygonalMesh(icoSphere);
// double r = node.getInfluenceRadius();
// trans.setIdentity();
// trans.setTranslation(node.getRestPosition());
// trans.applyScaling(r, r, r);
// nmesh.transform(trans);
// 
// if (surface != null) {
// nmesh = MeshFactory.getIntersection(nmesh, surface);
// }
// meshMap.put(node, nmesh);
// }
// }
// 
// // I do this after generating all meshes so that isInDomain doesn't start
// // using the meshes before all are ready (speed issue)
// for (MFreeNode3d node : nodes) {
// PolygonalMesh nmesh = meshMap.get(node);
// if (nmesh != null) {
// node.setBoundaryMesh(nmesh);
// }
// // model.addMesh("node_" + node.getNumber(), nmesh);
// }
// }
// public static void createPairedElemMeshes(List<MFreeElement3d> elemList,
// BVTree nodeTree) {
// 
// // only intersections
// for (MFreeElement3d elem : elemList) {
// if (elem.numNodes() == 1) {
// elem.setBoundaryMesh(elem.getNode(0).getBoundaryMesh());
// } else {
// PolygonalMesh mesh =
// new PolygonalMesh(elem.getNode(0).getBoundaryMesh());
// for (int i = 1; i < elem.numNodes(); i++) {
// mesh =
// MeshFactory.getIntersection(mesh, elem
// .getNode(i).getBoundaryMesh());
// }
// mesh = (PolygonalMesh)convertToMFreeMesh(mesh, nodeTree, DEFAULT_TOLERANCE);
// elem.setBoundaryMesh(mesh);
// }
// }
// 
// }
// public static void createElemMeshes(
// MFreeModel3d model, Collection<MFreeElement3d> elemList, PolygonalMesh surface) {
// 
// if (elemList == null) {
// elemList = model.getElements();
// }
// 
// // pre-build BSP trees for all nodes
// HashMap<Integer,BSPTree> meshMap = new HashMap<Integer,BSPTree>();
// HashMap<BSPTree,MFreeNode3d> meshMapInv = new HashMap<BSPTree,MFreeNode3d>();
// 
// HashSet<MFreeNode3d> nodeset = new HashSet<>();
// for (MFreeElement3d elem : elemList) {
// for (MFreeNode3d node : elem.getNodes()) {
// nodeset.add(node);
// }
// }
// ArrayList<MFreeNode3d> nodes = new ArrayList<>(nodeset);
// 
// boolean[][] connectivityChart = buildIntersectionChart(nodes);
// DirectedGraph<int[],Integer> connectivityGraph = IntersectionFactory.buildConnectivityGraph(connectivityChart);
// 
// HashMap<int[],BSPTree> nullMap = new HashMap<int[],BSPTree>(1);
// for (int i = 0; i < nodes.size(); i++) {
// MFreeNode3d node = nodes.get(i);
// BSPTree tree = new BSPTree(node.getBoundaryMesh());
// meshMap.put(i, tree);
// meshMapInv.put(tree, node);
// }
// 
// DirectedGraph<BSPTree,BSPTree> meshGraph = connectivityGraph.exchangeData(nullMap, meshMap);
// IntersectionFactory.buildSpatialPartition(meshGraph, null);
// DirectedGraph<BSPTree,MFreeNode3d> nodeGraph = meshGraph.exchangeEdgeData(meshMapInv);
// Vertex<BSPTree,MFreeNode3d> root = nodeGraph.getVertex(0);
// 
// for (MFreeElement3d elem : elemList) {
// Vertex<BSPTree,MFreeNode3d> vtx = root;
// for (MFreeNode3d node : elem.getNodes()) {
// for (DirectedEdge<BSPTree,MFreeNode3d> edge : vtx.getForwardEdges()) {
// if (edge.getData() == node) {
// vtx = edge.traverseForwards();
// break;
// }
// }
// }
// 
// PolygonalMesh mesh = vtx.getData().generateMesh();
// if (mesh.numFaces() > 0) {
// elem.setBoundaryMesh(mesh);
// // model.addMesh("elem_" + elem.getNumber(), mesh);
// }
// 
// }
// }
// public static ArrayList<MFreeElement3d> findPairdElementsContaining(
// Point3d pnt, BVTree bvtree, double tol) {
// 
// ArrayList<MFreeElement3d> deps = new ArrayList<MFreeElement3d>();
// ArrayList<BVNode> bvNodes = new ArrayList<BVNode>(16);
// bvtree.intersectPoint(bvNodes, pnt);
// 
// if (bvNodes.size() == 0) {
// return deps;
// }
// 
// for (BVNode n : bvNodes) {
// Boundable[] elements = n.getElements();
// for (int i = 0; i < elements.length; i++) {
// MFreeElement3d elem = (MFreeElement3d)elements[i];
// 
// boolean isInside = true;
// for (MFreeNode3d node : elem.getNodes()) {
// if (!node.isInDomain(pnt, tol)) {
// isInside = false;
// break;
// }
// }
// if (isInside) {
// deps.add(elem);
// }
// }
// }
// return deps;
// }
// public static ArrayList<MFreeElement3d> findPartitionedElementsContaining(
// Point3d pnt, DirectedGraph<MFreeElement3d,MFreeNode3d> connectivity,
// BVTree bvtree, double tol) {
// 
// ArrayList<MFreeElement3d> deps = new ArrayList<MFreeElement3d>();
// ArrayList<BVNode> bvNodes = new ArrayList<BVNode>(16);
// bvtree.intersectPoint(bvNodes, pnt);
// 
// if (bvNodes.size() == 0) {
// return deps;
// }
// 
// for (BVNode n : bvNodes) {
// Boundable[] elements = n.getElements();
// for (int i = 0; i < elements.length; i++) {
// MFreeElement3d elem = (MFreeElement3d)elements[i];
// 
// boolean isInside = true;
// for (MFreeNode3d node : elem.getNodes()) {
// if (!node.isInDomain(pnt, tol)) {
// isInside = false;
// break;
// }
// }
// 
// // exclude deeper intersections
// if (isInside) {
// Vertex<MFreeElement3d,MFreeNode3d> vtx =
// connectivity.findVertex(elem);
// for (DirectedEdge<MFreeElement3d,MFreeNode3d> edge : vtx
// .getForwardEdges()) {
// MFreeNode3d node = edge.getData();
// if (node.isInDomain(pnt, tol)) {
// isInside = false;
// break;
// }
// }
// }
// if (isInside) {
// deps.add(elem);
// }
// }
// }
// return deps;
// }
// public static DirectedGraph<MFreeElement3d,MFreeNode3d> convertConnectivity(
// List<MFreeNode3d> nodes, List<MFreeElement3d> elems,
// DirectedGraph<int[],Integer> graph) {
// 
// DirectedGraph<MFreeElement3d,MFreeNode3d> out = graph.cloneStructure();
// 
// // copy over nodes
// for (int i = 0; i < graph.numDirectedEdges(); i++) {
// DirectedEdge<int[],Integer> idxEdge = graph.getDirectedEdge(i);
// DirectedEdge<MFreeElement3d,MFreeNode3d> nodeEdge =
// out.getDirectedEdge(i);
// nodeEdge.setData(nodes.get(idxEdge.getData()));
// }
// 
// // fill in vertices by traversing along edges
// Vertex<MFreeElement3d,MFreeNode3d> base = out.getVertex(0);
// for (MFreeElement3d elem : elems) {
// MFreeNode3d[] nodeArray = elem.getNodes();
// Vertex<MFreeElement3d,MFreeNode3d> elemVtx =
// out.traverseEdgesForward(base, nodeArray);
// elemVtx.setData(elem);
// }
// 
// return out;
// 
// }
// public static ArrayList<MFreeElement3d> findPairedElementsContaining(
// Point3d pnt, BVTree bvtree, double tol) {
// 
// ArrayList<MFreeElement3d> deps = new ArrayList<MFreeElement3d>();
// ArrayList<BVNode> bvNodes = new ArrayList<BVNode>(16);
// bvtree.intersectPoint(bvNodes, pnt);
// 
// if (bvNodes.size() == 0) {
// return deps;
// }
// 
// for (BVNode n : bvNodes) {
// Boundable[] elements = n.getElements();
// for (int i = 0; i < elements.length; i++) {
// MFreeElement3d elem = (MFreeElement3d)elements[i];
// 
// boolean isInside = true;
// for (MFreeNode3d node : elem.getNodes()) {
// if (!node.isInDomain(pnt, tol)) {
// isInside = false;
// break;
// }
// }
// if (isInside) {
// deps.add(elem);
// }
// }
// }
// return deps;
// }
private static MFreeNode3d[] findNodesContaining(Point3d pnt, BVTree bvtree, double tol) {
    DynamicArray<MFreeNode3d> deps = new DynamicArray<>(MFreeNode3d.class);
    ArrayList<BVNode> bvNodes = new ArrayList<BVNode>(16);
    bvtree.intersectPoint(bvNodes, pnt);
    if (bvNodes.size() == 0) {
        return deps.getArray();
    }
    for (BVNode n : bvNodes) {
        Boundable[] elements = n.getElements();
        for (int i = 0; i < elements.length; i++) {
            RestNode rnode = (RestNode) elements[i];
            MFreeNode3d node = rnode.getNode();
            if (node.isInDomain(pnt, tol)) {
                deps.add(node);
            }
        }
    }
    return deps.getArray();
}
Also used : DynamicArray(maspack.util.DynamicArray) BVNode(maspack.geometry.BVNode) ArrayList(java.util.ArrayList) Boundable(maspack.geometry.Boundable)

Aggregations

ArrayList (java.util.ArrayList)1 BVNode (maspack.geometry.BVNode)1 Boundable (maspack.geometry.Boundable)1 DynamicArray (maspack.util.DynamicArray)1