예제 #1
0
        /// <summary>
        /// This will initialize the Neuron, the grid parameter is read in
        /// the grid parameter contains the geometric information from the .vrn files
        /// </summary>
        /// <param name="grid"></param>
        public Neuron(Grid grid)
        {
            Vector3[] gridMeshVertices = grid.Mesh.vertices;
            MaxRadius        = 0;
            TargetEdgeLength = 0;

            VertexAttachementAccessor <DiameterData> diameterAccessor = new VertexAttachementAccessor <DiameterData>(grid);

            for (int i = 0; i < grid.Vertices.Count; i++)
            {
                NodeData tempNode = new NodeData
                {
                    /// this gets the radius by dividing the diameter by 2
                    NodeRadius = diameterAccessor[i].Diameter / 2,
                    /// this the node id --> these may not be consecutive
                    Id = grid.Vertices[i].Id,

                    /// these are the actual coordinates of the geometry --> NOTE: these are in [um] already!
                    /// Currently uses Unity Mesh vertices. Should probably be changed to directly use geometry/Grid vertices?
                    Xcoords = gridMeshVertices[i].x,
                    Ycoords = gridMeshVertices[i].y,
                    Zcoords = gridMeshVertices[i].z
                };

                if ((tempNode.NodeRadius >= MaxRadius))
                {
                    MaxRadius = tempNode.NodeRadius;
                }

                nodes.Add(tempNode);
            }

            /// this loop collects the edges
            for (int i = 0; i < grid.Edges.Count; i++)
            {
                NodeData fromNode   = nodes[grid.Edges[i].From.Id];
                NodeData toNode     = nodes[grid.Edges[i].To.Id];
                double   edgeLength = GetEdgeLength(fromNode, toNode);
                edges.Add(new Edge {
                    From   = fromNode,
                    To     = toNode,
                    Length = edgeLength
                }
                          );
                TargetEdgeLength = TargetEdgeLength + edgeLength;

                toNode.Pid = fromNode.Id;

                /// makes an adjacency list with edge weights
                toNode.AdjacencyList.Add(fromNode.Id, edgeLength);
                fromNode.AdjacencyList.Add(toNode.Id, edgeLength);

                toNode.Neighbors.Add(new Neighbor(fromNode.Id, edgeLength));
                fromNode.Neighbors.Add(new Neighbor(toNode.Id, edgeLength));
            }

            TargetEdgeLength = TargetEdgeLength / (grid.Edges.Count);

            /// if a node has only one neighbor then it is a boundary node
            boundaryNodes.AddRange(nodes.FindAll(node => node.AdjacencyList.Count == 1));

            somaIDs = grid.Subsets["soma"].Indices.ToList();
        }
예제 #2
0
        /// <summary>
        /// Start
        /// </summary>
        void Start()
        {
            /// Which common attachments are available?
            AttachmentHandler.Available();

            /// Create an Empty grid
            grid = new Grid(new Mesh(), "3D cube");

            /// Which attachments should be populated during grid read-in process.
            /// The data is stored in the DiameterAttachment internally, and the type is DiameterData
            grid.Attach(new DiameterAttachment());

            /// Read the file with attachments specified by a list above
            // UGXReader.ReadUGX(@"C:/Users/tug41634/Desktop/cube_3d.ugx", ref grid);
            // UGXReader.ReadUGX(@"C:/Users/tug41634/Downloads/mouse4_standard_joined.ugx", ref grid);

            /// Additional attachments can be attached to the grid which will be populated with the default value for each vertex
            /// VertexAttachmentAccesors need to be created, see below, to access the attached data objects

            /// Debug for mesh
            // Debug.Log($"mesh.vertices.Length: {grid.Mesh.vertices.Length}");
            // Debug.Log($"mesh.triangles.Length: {grid.Mesh.triangles.Length}");

            /// Add visual components
            go = new GameObject(grid.Mesh.name);
            go.AddComponent <MeshFilter>();
            go.AddComponent <MeshRenderer>();
            // go.GetComponent<MeshFilter>().sharedMesh = grid.Mesh;

            /// Example usage of Diameter attachment
            VertexAttachementAccessor <DiameterData> accessor = new VertexAttachementAccessor <DiameterData>(grid);

            grid.Attach(new MappingAttachment());

            /// Iterate through diameter data
            foreach (DiameterData diam in accessor)
            {
                Debug.Log($"Diameter {diam.Diameter}");
            }

            /// CNG cells
            bool defined = Enum.IsDefined(typeof(Cell), (byte)cell);

            if (defined)
            {
                var    name     = (Cell)(byte)cell;
                string cellName = name.ToString();
                cellName = cellName.Replace("_", "-");
                cellName = cellName.Replace("Cell", "");
                /// Build the map
                Debug.Log($"Building mesh for cell: {cellName}");

                /*
                 * BuildMap(@"C:/Users/tug41634/Desktop/C2M2/c2m2-vr-grids/Cells/" + (byte) cell + "/" + cellName + ".CNG_1d.ugx",
                 *        @"C:/Users/tug41634/Desktop/C2M2/c2m2-vr-grids/Cells/" + (byte) cell + "/" + cellName + ".CNG.ugx",
                 *        @"C:/Users/tug41634/Desktop/C2M2/c2m2-vr-grids/Cells/" + (byte) cell + "/" + cellName + ".CNG_tris.ugx");
                 */
                /// Surface geom (With triangles)
                Grid grid3dvis = new Grid(new Mesh(), "3D Hippocampal Cell");
                UGXReader.Validate = false;
                UGXReader.ReadUGX(@"C:/Users/tug41634/Desktop/new mesh.ugx", ref grid3dvis);
                Debug.Log(grid3dvis);
                go.GetComponent <MeshFilter>().sharedMesh = grid3dvis.Mesh;
            }
        }
예제 #3
0
        /// <summary>
        /// This will initialize the NeuronCell, the grid parameter is read in
        /// the grid parameter contains the geometric information from the .vrn files
        /// </summary>
        /// <param name="grid"></param>
        public NeuronCell(Grid grid)
        {
            NodeData tempNode = new NodeData();
            VertexAttachementAccessor <DiameterData> accessor = new VertexAttachementAccessor <DiameterData>(grid);
            Mesh mesh = grid.Mesh;

            Vector3[] vertices = mesh.vertices;

            int count     = 0;
            int edgeCount = grid.Edges.Count;

            foreach (DiameterData diam in accessor)
            {
                /// this gets the diameter, make sure to divide by 2
                tempNode.nodeRadius = diam.Diameter / 2;
                /// this the node id --> these may not be consecutive
                tempNode.id = grid.Vertices[count].Id;

                /// this for loop is for setting the pid, parent id
                for (int i = 0; i < edgeCount; i++)
                {
                    if (tempNode.id == grid.Edges[i].To.Id)
                    {
                        tempNode.pidAlternate = grid.Edges[i].From.Id;
                    }
                    /// the zero-th node has parent -1 --> NOTE: is this alway true, need to check this!!
                    if (tempNode.id == 0)
                    {
                        tempNode.pidAlternate = -1;
                    }
                }

                /// these are the actual coordinates of the geometry --> NOTE: these are in [um] already!
                tempNode.xcoords = vertices[count].x;
                tempNode.ycoords = vertices[count].y;
                tempNode.zcoords = vertices[count].z;
                /// this initializes an empty list for the neighbor id nodes
                tempNode.neighborIDs = new List <int>();
                /// if a node has only one neighbor then it is a boundary node
                if (grid.Vertices[count].Neighbors.Count == 1)
                {
                    /// add the boundary node id to the list
                    boundaryID.Add(grid.Vertices[count].Id);
                }
                /// this adds the neigbor ids to the list for this node
                for (int i = 0; i < grid.Vertices[count].Neighbors.Count; i++)
                {
                    tempNode.neighborIDs.Add(grid.Vertices[count].Neighbors[i].Id);
                }

                nodeData.Add(tempNode);
                /// this increments the counter for the number of vertices --> is this even used?? may need to remove!
                count = count + 1;
            }
            vertCount = mesh.vertexCount;
            /// this loop collects the edges and gets the lengths of the edges
            for (int i = 0; i < edgeCount; i++)
            {
                edges.Add((Tuple.Create(grid.Edges[i].From.Id, grid.Edges[i].To.Id)));
                edgeLengths.Add(GetEdgeLength(grid.Edges[i].From.Id, grid.Edges[i].To.Id));
            }

            this.edgeCount = edgeCount;
            this.somaID    = grid.Subsets["soma"].Indices.ToList();
        }