コード例 #1
0
ファイル: NDSimulation.cs プロジェクト: c2m2/NeuroVISOR
        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);
        }
コード例 #2
0
ファイル: NDSimulation.cs プロジェクト: c2m2/NeuroVISOR
        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);
        }
コード例 #3
0
ファイル: VrnReader.cs プロジェクト: c2m2/NeuroVISOR
            static void Main(string[] args)
            {
                string fileName = "testNew.vrn";

                try
                {
                    /// Instantiate the VRN reader with the desired file name
                    VrnReader reader = new VrnReader(fileName);
                    /// Get the name of the 1d mesh (0-th refinement aka coarse grid)
                    Console.WriteLine(reader.Retrieve1DMeshName());
                    /// Get the name of the inflated 2d mesh by a factor of 2.5
                    Console.WriteLine(reader.Retrieve2DMeshName(2.5));
                }
                catch (Exception ex) when(ex is System.IO.FileNotFoundException || ex is System.ArgumentNullException)
                {
                    Console.Error.WriteLine($"Archive not found or unable to open the .vrn archive: {fileName}.");
                    Console.Error.WriteLine(ex);
                }
                catch (Exception ex) when(ex is CouldNotReadMeshFromVRNArchive)
                {
                    Console.Error.WriteLine($"Requested mesh not contained in MetaInfo.json or given .vrn archive {fileName}.");
                    Console.Error.WriteLine(ex);
                }
            }
コード例 #4
0
ファイル: NeuronCellPreview.cs プロジェクト: c2m2/NeuroVISOR
        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;
                }
            }
        }