/// <summary> /// Attempt to latch a clamp onto a given simulation /// </summary> public NDSimulation AttachSimulation(NDSimulation simulation, int clampIndex) { if (this.simulation == null) { this.simulation = simulation; transform.parent.parent = this.simulation.transform; if (this.simulation.Neuron.somaIDs.Contains(clampIndex)) { somaClamp = true; } PlaceClamp(clampIndex); this.simulation.OnVisualInflationChange += VisualInflationChangeHandler; // wait for clamp list access, add to list this.simulation.clampMutex.WaitOne(); this.simulation.clamps.Add(this); this.simulation.clampMutex.ReleaseMutex(); } return(this.simulation); }
/// <returns> True if the 1D index is available, otherwise returns false</returns> private bool VertIsAvailable(int clampIndex, NDSimulation simulation) { bool validLocation = true; foreach (NDLineGraph graph in graphs) { if (graph.vert == clampIndex) { Debug.LogWarning("Clamp already exists on vertex [" + clampIndex + "]."); validLocation = false; } } return(validLocation); }
/// <summary> /// Attempt to latch a graph onto a given simulation /// </summary> public void AttachToSimulation(NDLineGraph graph, NDSimulation simulation, RaycastHit hit) { int vertIndex = simulation.GetNearestPoint(hit); // Check for duplicates if (!VertIsAvailable(vertIndex, simulation)) { Destroy(graph.gameObject); return; } graph.vert = vertIndex; graphs.Add(graph); }
/// <summary> /// Looks for NDSimulation instance and adds neuronClamp object if possible /// </summary> /// <param name="hit"></param> public void InstantiateGraph(RaycastHit hit) { // Make sure we have a valid prefab and simulation if (graphPrefab == null) { Debug.LogError("No Clamp prefab found"); } NDSimulation sim = hit.collider.GetComponentInParent <NDSimulation>(); // If there is no NDSimulation, don't try instantiating a clamp if (sim == null) { return; } var graphObj = Instantiate(graphPrefab); NDLineGraph graph = graphObj.GetComponent <NDLineGraph>(); graph.manager = this; AttachToSimulation(graph, sim, hit); }
// TODO: Allow SparseSolverTestv1 to be a variable script public void Load(RaycastHit hit) { GameObject solveObj = new GameObject(); solveObj.AddComponent <MeshFilter>(); solveObj.AddComponent <MeshRenderer>(); Type solverType = Type.GetType(solverName); if (solverType == null || !solverType.IsSubclassOf(typeof(NDSimulation))) { if (solverType == null) { Debug.LogError(solverName + " could not be found."); } else if (!solverType.IsSubclassOf(typeof(NDSimulation))) { Debug.LogError(solverName + " is not a NDSimulation."); } Destroy(solveObj); return; } solveObj.name = "(Solver)" + solverName.Substring(solverName.LastIndexOf('.') + 1); NDSimulation solver = (NDSimulation)solveObj.AddComponent(solverType); //NDSimulation solver = solveObj.AddComponent<SparseSolverTestv1>(); // Close current simulation, if any if (GameManager.instance.activeSim != null) { Destroy(GameManager.instance.activeSim); } // Store the new active simulation GameManager.instance.activeSim = solver; TransferValues(); solver.Initialize(); transform.gameObject.SetActive(false); void TransferValues() { // Set solver values solver.vrnFileName = vrnFileName; solver.gradient = gradient; solver.globalMin = globalMin; solver.globalMax = globalMax; solver.timeStep = timestepSize; solver.endTime = endTime; solver.raycastHitValue = raycastHitValue; solver.unit = unit; solver.unitScaler = unitScaler; solver.colorMarkerPrecision = colorScalePrecision; try { solver.RefinementLevel = refinementLevel; } catch (Exception e) { Debug.LogWarning("Refinement level " + refinementLevel + " not found. Reverting to 0 refinement."); refinementLevel = 0; solver.RefinementLevel = 0; Debug.LogError(e); } } }