예제 #1
0
        public void SetCellNeighbourhood(int cellId)
        {
            MGCell cell = cells[cellId];

            cell.neighbours.Clear();

            if (MGModel.hexagonalNeighbourhoodForCells)
            {
                cell.neighbours = Helper.GetHexagonalNeighbourhood3D(cellId, maxPopulationSize, populationSize);
                //Console.WriteLine("Hexagonal");
            }
            else if (MGModel.mooreNeighbourhoodForCells)
            {
                //cell.neighbours = Helper.GetMooreNeighbourhood3D(cellId, maxPopulationSize, populationSize);
                cell.neighbours = Helper.GetMooreNeighbourhood3D(cellId, dim, populationSize);
                //Console.WriteLine(maxPopulationSize + ", " + populationSize);
            }
            else
            {
                //Console.WriteLine("Population Size: " + populationSize);
                //Console.WriteLine("Cell ID: " + cellId);
                for (int i = 0; i < populationSize; i++)
                {
                    double distance = Vector.Distance(cell.GetPosition(), cells[i].GetPosition());

                    if (i != cellId && distance < MGModel.maximumNeighbourDistance && cell.neighbours.Count < 26)
                    {
                        cell.neighbours.Add(i);
                        //Console.WriteLine(cellId + ":" + cell.GetPosition() + ", " + i + ":" + cells[i].GetPosition() + ", " + distance + ", " + MGModel.maximumNeighbourDistance);
                    }
                }
            }
        }
예제 #2
0
        public CellPopulation(int popMaxSize, List <Tissue> tissueList)
        {
            Simulator.interCellEdges = new StringBuilder();
            Simulator.interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            populationSize    = 0;
            maxPopulationSize = popMaxSize;
            cells             = new MGCell[popMaxSize];
            sigma             = new int[popMaxSize];
            double d = Math.Round(Math.Pow(maxPopulationSize, 1f / 3f));

            dim     = new Vector(d, d, d);
            halfDim = dim / 2;

            tissues = tissueList;
            int start = 0;

            for (int i = 0; i < tissueList.Count; i++)
            {
                tissues[i].indices = new int[tissues[i].maxPopulationSize];

                start += i == 0 ? 0 : tissueList[i - 1].populationSize;
                for (int j = 0; j < tissueList[i].populationSize; j++)
                {
                    int index = start + j;
                    cells[index]            = new MGCell(index, tissueList[i].cells[j]);
                    cells[index].tissueName = tissueList[i].name;
                    tissues[i].indices[j]   = index;
                    tissues[i].cells[j]     = cells[index];
                    sigma[index]            = index;
                }
                populationSize += tissueList[i].populationSize;
            }
        }
예제 #3
0
        public void CreatePopulation(int popSize, int popMaxSize)
        {
            //interCellEdges = new StringBuilder();
            //interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            Simulator.interCellEdges = new StringBuilder();
            Simulator.interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            populationSize    = popSize;
            maxPopulationSize = popMaxSize;
            cells             = new MGCell[popMaxSize];
            sigma             = new int[maxPopulationSize];
            dim     = new Vector(Math.Pow(maxPopulationSize, 1f / 3f), Math.Pow(maxPopulationSize, 1f / 3f), Math.Pow(maxPopulationSize, 1f / 3f));
            halfDim = dim / 2;

            contacts        = new int[maxPopulationSize];
            contactsIndices = new int[maxPopulationSize];

            for (int i = 0; i < populationSize; i++)
            {
                cells[i] = new MGCell(i);
                //Console.WriteLine("Created cell " + i + ", " + cells[i].cellId);
            }

            tissues = new List <Tissue>();
        }
예제 #4
0
 public void AddCell(MGCell cell)
 {
     if (populationSize < maxPopulationSize)
     {
         cells[populationSize] = cell;
         populationSize++;
     }
 }
예제 #5
0
 public void AddCell(int tissueId, MGCell cell)
 {
     if (populationSize < maxPopulationSize)
     {
         tissues[tissueId].AddCell(cell);
         cells[populationSize] = cell;
         populationSize++;
     }
 }
예제 #6
0
        public CellPopulation(int popSize, int popMaxSize, List <Tissue> tissueList, short cellType, bool randomCycleTime)
        {
            //interCellEdges = new StringBuilder();
            //interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            Simulator.interCellEdges = new StringBuilder();
            Simulator.interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            populationSize    = popSize;
            maxPopulationSize = popMaxSize;
            //Console.WriteLine(popMaxSize);
            cells = new MGCell[popMaxSize];
            sigma = new int[popMaxSize];
            double d = Math.Round(Math.Pow(maxPopulationSize, 1f / 3f));

            dim     = new Vector(d, d, d);
            halfDim = dim / 2;

            contacts        = new int[maxPopulationSize];
            contactsIndices = new int[maxPopulationSize];

            tissues = tissueList;
            int    start = 0;
            Random rand  = new Random(0);

            for (int i = 0; i < tissueList.Count; i++)
            {
                tissues[i].indices = new int[tissues[i].maxPopulationSize];

                start += i == 0 ? 0 : tissueList[i - 1].populationSize;
                for (int j = 0; j < tissueList[i].populationSize; j++)
                {
                    int index = start + j;

                    cells[index]            = new MGCell(index, tissueList[i].mesh);
                    cells[index].tissueId   = i;
                    cells[index].tissueName = tissueList[i].name;

                    tissues[i].indices[j]  = index;
                    tissues[i].cells[j]    = cells[index];
                    sigma[index]           = index;
                    cells[index].cycleTime = 0;// rand.Next(MGModel.cellCyclePeriod);

                    contactsIndices[index] = index;
                    contacts[index]        = 0;
                }
            }
        }
예제 #7
0
        public CellPopulation(int popSize, int popMaxSize, List <Tissue> tissueList, short cellType)
        {
            Simulator.interCellEdges = new StringBuilder();
            Simulator.interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            populationSize    = popSize;
            maxPopulationSize = popMaxSize;
            cells             = new MGCell[popMaxSize];
            sigma             = new int[popMaxSize];
            double d = Math.Round(Math.Pow(maxPopulationSize, 1f / 3f));

            dim     = new Vector(d, d, d);
            halfDim = dim / 2;

            contacts        = new int[maxPopulationSize];
            contactsIndices = new int[maxPopulationSize];

            tissues = tissueList;
            int start = 0;

            for (int i = 0; i < tissueList.Count; i++)
            {
                tissues[i].indices = new int[tissues[i].maxPopulationSize];

                start += i == 0 ? 0 : tissueList[i - 1].populationSize;
                for (int j = 0; j < tissueList[i].populationSize; j++)
                {
                    int index = start + j;
                    switch (cellType)
                    {
                    case 1: cells[index] = new RedBloodCell(index, tissueList[i].mesh); break;

                    case 2: cells[index] = new EpithelialCell(index, tissueList[i].mesh); break;

                    default: cells[index] = new MGCell(index, tissueList[i].mesh); break;
                    }
                    //cells[index] = new MGCell(index, tissueList[i].mesh);
                    cells[index].tissueName = tissueList[i].name;
                    tissues[i].indices[j]   = index;
                    tissues[i].cells[j]     = cells[index];
                    sigma[index]            = index;

                    contactsIndices[index] = index;
                    contacts[index]        = 0;
                }
            }
        }
예제 #8
0
        public void AddTissue(Tissue tissue)
        {
            int i = tissues.Count;

            tissue.indices = new int[tissue.maxPopulationSize];

            int start = populationSize;

            for (int j = 0; j < tissue.populationSize; j++)
            {
                int index = start + j;
                cells[index] = new MGCell(index, tissue.mesh);

                tissue.indices[j] = index;
                tissue.cells[j]   = cells[index];
                sigma[index]      = index;
            }
            tissues.Add(tissue);
            populationSize += tissue.populationSize;
        }
예제 #9
0
        public void CreatePopulation(int popSize, int popMaxSize)
        {
            //interCellEdges = new StringBuilder();
            //interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            Simulator.interCellEdges = new StringBuilder();
            Simulator.interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            populationSize    = popSize;
            maxPopulationSize = popMaxSize;
            cells             = new MGCell[popMaxSize];
            sigma             = new int[maxPopulationSize];
            dim     = new Vector(Math.Pow(maxPopulationSize, 1f / 3f), Math.Pow(maxPopulationSize, 1f / 3f), Math.Pow(maxPopulationSize, 1f / 3f));
            halfDim = dim / 2;

            for (int i = 0; i < populationSize; i++)
            {
                cells[i] = new MGCell(i);
            }
        }
예제 #10
0
        public CellPopulation(int popSize, Vector dim)
        {
            Simulator.interCellEdges = new StringBuilder();
            Simulator.interCellEdges.AppendLine("frame,cell1,p1,cell2,p2");

            populationSize    = popSize;
            maxPopulationSize = (int)(dim.x * dim.y * dim.z);
            cells             = new MGCell[maxPopulationSize];
            sigma             = new int[maxPopulationSize];
            this.dim          = dim;
            halfDim           = dim / 2;

            contacts        = new int[maxPopulationSize];
            contactsIndices = new int[maxPopulationSize];
            for (int i = 0; i < populationSize; i++)
            {
                cells[i]           = new MGCell(i);
                contactsIndices[i] = i;
                contacts[i]        = 0;
            }
        }
예제 #11
0
        void CreateCellPopulation(string folder)
        {
            CellProvider provider = new CellProvider();

            provider.ReadParameters(folder);
            provider.ReadResults();
            provider.ReadParticleNeighbourhoods();
            provider.PlayResults(0);

            populationSize    = provider.popSize;
            maxPopulationSize = provider.maxPopSize;

            cells = new MGCell[provider.maxPopSize];
            sigma = new int[provider.maxPopSize];

            contacts        = new int[maxPopulationSize];
            contactsIndices = new int[maxPopulationSize];

            int start = 0;

            tissues = new List <Tissue>(provider.nbOfCellTypes);

            Random rand = new Random(0);

            for (int i = 0; i < provider.nbOfCellTypesPerFrame[provider.nbOfFrames - 1]; i++)
            {
                //Console.WriteLine(provider.nbOfCellsPerTypePerFrame[provider.nbOfFrames - 1][i]);
                tissues.Add(new Tissue(provider.nbOfCellsPerTypePerFrame[provider.nbOfFrames - 1][i], provider.maxPopSize));
                tissues[i].indices = new int[tissues[i].maxPopulationSize];

                start += i == 0 ? 0 : tissues[i - 1].populationSize;
                for (int j = 0; j < tissues[i].populationSize; j++)
                {
                    int index = start + j;

                    //Console.WriteLine(index);
                    cells[index] = new MGCell(index, i, provider.meshPerCell[index]);
                    //Console.WriteLine(index + ", " + provider.meshPerCell[index].vertexCount());
                    cells[index].tissueId = i;

                    tissues[i].indices[j]  = index;
                    tissues[i].cells[j]    = cells[index];
                    sigma[index]           = index;
                    cells[index].cycleTime = rand.Next(MGModel.cellCyclePeriod);
                    tissues[i].reference  += cells[index].ComputeCentreFromMesh();
                    //Console.WriteLine(cells[index].cycleTime);

                    contactsIndices[index] = index;
                    contacts[index]        = 0;
                }
                tissues[i].mesh       = provider.meshPerCell[start];
                tissues[i].reference /= tissues[i].populationSize;
            }

            for (int i = 0; i < provider.externalEdges.Count; i++)
            {
                Edge edge = new Edge(cells[(int)provider.externalEdges[i].x].vertices[(int)provider.externalEdges[i].y],
                                     cells[(int)provider.externalEdges[i].z].vertices[(int)provider.externalEdges[i].w]);

                cells[(int)provider.externalEdges[i].x].externalEdges.add(edge);
                cells[(int)provider.externalEdges[i].z].externalEdges.add(new Edge(edge.ends[1], edge.ends[0]));

                cells[(int)provider.externalEdges[i].x].vertices[(int)provider.externalEdges[i].y].externalNeighbours.Add(new int[] {
                    (int)provider.externalEdges[i].z,
                    (int)provider.externalEdges[i].w
                });

                cells[(int)provider.externalEdges[i].z].vertices[(int)provider.externalEdges[i].w].externalNeighbours.Add(new int[] {
                    (int)provider.externalEdges[i].x,
                    (int)provider.externalEdges[i].y
                });

                if ((int)provider.externalEdges[i].x == 0 && (int)provider.externalEdges[i].y == 26)
                {
                    //Console.WriteLine(provider.externalEdges[i].z + ", " + provider.externalEdges[i].w);
                }
            }

            for (int i = 0; i < populationSize; i++)
            {
                contacts[i] = cells[i].externalEdges.getCount();
            }
        }
예제 #12
0
        void CreateCellPopulation(string folder)
        {
            CellProvider provider = new CellProvider();

            provider.ReadParameters(folder);
            provider.ReadResults();
            provider.PlayResults(0);

            populationSize    = provider.popSize;
            maxPopulationSize = provider.maxPopSize;

            cells = new MGCell[provider.maxPopSize];
            sigma = new int[provider.maxPopSize];

            int start = 0;

            tissues = new List <Tissue>(provider.nbOfCellTypes);

            /*
             * for (int i = 0; i < provider.nbOfCellTypes; i++)
             * {
             *  tissues.Add(new Tissue(provider.nbOfCellsPerType[i], provider.maxPopSize));
             *  tissues[i].indices = new int[tissues[i].maxPopulationSize];
             *
             *  start += i == 0 ? 0 : tissues[i - 1].populationSize;
             *  for (int j = 0; j < tissues[i].populationSize; j++)
             *  {
             *      int index = start + j;
             *
             *      //Console.WriteLine(index);
             *      cells[index] = new MGCell(index, provider.meshPerCell[index]);
             *      //Console.WriteLine(index + ", " + provider.meshPerCell[index].vertexCount());
             *      cells[index].tissueId = i;
             *
             *      tissues[i].indices[j] = index;
             *      tissues[i].cells[j] = cells[index];
             *      sigma[index] = index;
             *      cells[index].cycleTime = new Random().Next(MGModel.cellCyclePeriod);
             *      tissues[i].reference += cells[index].ComputeCentreFromMesh();
             *  }
             *  tissues[i].mesh = provider.meshPerCell[start];
             *  tissues[i].reference /= tissues[i].populationSize;
             * }
             */

            for (int i = 0; i < provider.nbOfCellTypesPerFrame[provider.nbOfFrames - 1]; i++)
            {
                //Console.WriteLine(provider.nbOfCellsPerTypePerFrame[provider.nbOfFrames - 1][i]);
                tissues.Add(new Tissue(provider.nbOfCellsPerTypePerFrame[provider.nbOfFrames - 1][i], provider.maxPopSize));
                tissues[i].indices = new int[tissues[i].maxPopulationSize];

                start += i == 0 ? 0 : tissues[i - 1].populationSize;
                for (int j = 0; j < tissues[i].populationSize; j++)
                {
                    int index = start + j;

                    //Console.WriteLine(index);
                    cells[index] = new MGCell(index, provider.meshPerCell[index]);
                    //Console.WriteLine(index + ", " + provider.meshPerCell[index].vertexCount());
                    cells[index].tissueId = i;

                    tissues[i].indices[j]  = index;
                    tissues[i].cells[j]    = cells[index];
                    sigma[index]           = index;
                    cells[index].cycleTime = new Random().Next(MGModel.cellCyclePeriod);
                    tissues[i].reference  += cells[index].ComputeCentreFromMesh();
                }
                tissues[i].mesh       = provider.meshPerCell[start];
                tissues[i].reference /= tissues[i].populationSize;
            }

            //Console.WriteLine(tissues.Capacity);

            /*
             * int cellTypeStartStates = 0;
             * for (int i = 0; i < provider.nbOfCellTypes; i++)
             * {
             *  if (i > 0) cellTypeStartStates += provider.nbOfCellsPerType[i - 1];
             *  for (int j = 0; j < provider.nbOfCellsPerType[i]; j++)
             *  {
             *      cells[cellTypeStartStates + j] = new MGCell(cellTypeStartStates + j, provider.meshPerCell[cellTypeStartStates + j]);
             *  }
             * }
             * //*/
        }