private void Update2DGrid() { /// Retrieve mesh names from archive string meshName2D = VrnReader.Retrieve2DMeshName(VisualInflation, RefinementLevel); /// Empty 2D grid which stores geometry + mapping data Grid2D = new Grid(new Mesh(), meshName2D); Grid2D.Attach(new MappingAttachment()); VrnReader.ReadUGX(meshName2D, ref grid2D); }
private void UpdateGrid1D() { string meshName1D = VrnReader.Retrieve1DMeshName(RefinementLevel); /// Create empty grid with name of grid in archive Grid1D = new Grid(new Mesh(), meshName1D); Grid1D.Attach(new DiameterAttachment()); VrnReader.ReadUGX(meshName1D, ref grid1D); Neuron = new Neuron(grid1D); }
public void PreviewCell(string vrnFileName, Color32 color) { if (vrnFileName == "null") { Debug.LogError("Null cell given to NeuronCellPreview"); if (fileNameDisplay != null) { fileNameDisplay.text = "null"; } return; } char sl = Path.DirectorySeparatorChar; if (!vrnFileName.EndsWith(".vrn")) { vrnFileName = vrnFileName + ".vrn"; } vrnReader = new VrnReader(Application.streamingAssetsPath + sl + "NeuronalDynamics" + sl + "Geometries" + sl + vrnFileName); refinements = vrnReader.ListRefinements(); string meshName1D = vrnReader.Retrieve1DMeshName(refinement); /// Create empty grid with name of grid in archive Grid grid = new Grid(new Mesh(), meshName1D); grid.Attach(new DiameterAttachment()); // Read the cell vrnReader.ReadUGX(meshName1D, ref grid); // Scale the parent object by 1 / max scale to make the cell fit within size (1,1,1) float scale = 1 / Math.Max(grid.Mesh.bounds.size); transform.localScale = new Vector3(scale, scale, scale); // Adjust center so cell mesh is centered at (0,0,0) transform.localPosition = -scale * grid.Mesh.bounds.center; if (lines != null) { Destroy(lines); lines = null; } // Render cells lines = gameObject.AddComponent <LinesRenderer>(); // (line width = scale) //lines.Draw(grid, color, 3*scale); lines.Draw(grid, color, 0.005f); // Displays file name without file extension if (fileNameDisplay != null) { fileNameDisplay.text = vrnFileName.Remove(vrnFileName.LastIndexOf('.')); } FillLabels(); void FillLabels() { // Draw scale labels Vector3 cellSize = grid.Mesh.bounds.size; if (sizeLabel != null) { sizeLabel.text = "Size: (" + cellSize.x.ToString() + ", " + cellSize.y.ToString() + ", " + cellSize.z.ToString() + " " + LengthScale + ")"; } bool shouldWarn = grid.Mesh.vertexCount > 8000; Color warnColor = new Color(1, 100f / 255f, 0, 1); if (vertLabel != null) { vertLabel.text = "Vertices: " + grid.Mesh.vertexCount; vertLabel.color = shouldWarn ? warnColor : Color.white; } if (cellSizeWarning != null) { cellSizeWarning.SetActive(shouldWarn); } VrnReader.MetaInfo metaInfo = (VrnReader.MetaInfo)vrnReader.GetMetaInfo(); string species = "Missing"; string strain = "Missing"; string archive = "Missing"; // If the metainfo object exists if (!metaInfo.Equals(default(VrnReader.MetaInfo))) { // If the information given is not empty, retrieve it if (!metaInfo.SPECIES.Equals(string.Empty)) { species = metaInfo.SPECIES; } if (!metaInfo.STRAIN.Equals(string.Empty)) { strain = metaInfo.STRAIN; } if (!metaInfo.ARCHIVE.Equals(string.Empty)) { archive = metaInfo.ARCHIVE; } } // Capitalizes the first letter of each label species = char.ToUpper(species[0]) + species.Substring(1).ToLower(); strain = char.ToUpper(strain[0]) + strain.Substring(1).ToLower(); archive = char.ToUpper(archive[0]) + archive.Substring(1).ToLower(); if (speciesLabel != null) { speciesLabel.text = "Species: " + species; } if (strainLabel != null) { strainLabel.text = "Strain: " + strain; } if (archiveLabel != null) { archiveLabel.text = "Archive: " + archive; } } }