public static void select(YaoGraph paths, TreeIterationParam param) { List <YaoNode> candidates = new List <YaoNode>(); for (int i = 0; i < paths.data.samples.Length; i++) { switch (param.endpointMethod) { case TreeIterationParam.PlacementType.VOLUME: Ellipsoid e = param.volume.GetComponent <Ellipsoid>(); if (e != null && e.testPoint(paths.data.samples[i])) { candidates.Add(paths[paths.sample2Yao[i]]); } if (e == null && param.volume.GetComponent <Collider>().bounds.Contains(paths.data.samples[i])) { candidates.Add(paths[paths.sample2Yao[i]]); } break; case TreeIterationParam.PlacementType.HOPS: if (paths.graph[i].hopsFromSource == param.nHops) { candidates.Add(paths[paths.sample2Yao[i]]); } break; } } selectFromCandidates(paths, candidates, param); }
private static void markAsStem(YaoNode n, YaoGraph g, int iteration) { n.isStem = iteration; if (n.parentID != -1 && g[n.parentID].isStem == -1) // mark parent as stem as well, if it is nor already { markAsStem(g[n.parentID], g, iteration); } }
public Dijkstra(YaoGraph p_graph, Vector3 stem) { graph = p_graph; setStemNodes(stem); visit(); }
public static void visualize(YaoGraph paths) { foreach (YaoNode node in paths) { if (node.isStem != -1 && node.parentID != -1) // draw only stem nodes { Vector3 pos1 = paths.data.samples[node.ID]; Vector3 pos2 = paths.data.samples[node.parentID]; drawLine(pos1, pos2, Color.red, 0.2f / Mathf.Pow((node.isStem), 1)); // Color iterations differently //if (node.isStem == 1) drawLine(pos1, pos2, Color.red); //if (node.isStem == 2) drawLine(pos1, pos2, Color.blue); //if (node.isStem == 3) drawLine(pos1, pos2, Color.green); } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown("space")) { // Initialization GridJitterSampling sampling = new GridJitterSampling(getStemTop(), size, minDist, nSamples); YaoGraph yao = new YaoGraph(sampling.data, connectivity); // Perform selection iterations TreeIterationParam[] iterations = gameObject.GetComponents <TreeIterationParam>(); Assert.IsTrue(iterations.Length == nIterations); foreach (TreeIterationParam iteration in iterations) { yao.prepareNextIteration(); // Dijkstra Dijkstra paths = new Dijkstra(yao, getStemTop()); //paths.visualize(); // Endpoint placement EndPointSelection.select(yao, iteration); } // Visualize //sampling.visualize(); //sampling.data.visualize(); //yao.visualize(); EndPointSelection.visualize(yao); /* * Meshifier meshGenerator = new Meshifier(yao, ElementsPerRing); * // add Mesh Filter and Mesh Renderer * MeshFilter mf = gameObject.AddComponent<MeshFilter>(); * gameObject.AddComponent<MeshRenderer>(); * * mf.mesh = meshGenerator.generatedMesh; */ } }
private static void selectFromCandidates(YaoGraph paths, List <YaoNode> candidates, TreeIterationParam param) { int nBranches = param.nBranches; int iteration = param.iterationCounter; if (candidates.Count < nBranches) { throw new System.Exception("Not enough branches available with the number of hops from source requested."); } int selected = 0; while (selected < nBranches) { int r = Random.Range(0, candidates.Count); markAsStem(candidates[r], paths, iteration); candidates.RemoveAt(r); selected++; } }
public Meshifier(YaoGraph t, int n) { tree = t; nElements = n; generateMesh(); }