コード例 #1
0
        private bool ShouldAddLateralRoot(Root root, IPlantPartDescriptor descriptor, SimulationStateSnapshot snapshot)
        {
            // Determine if it should add new lateral root based on tick count
            ulong tick = snapshot.CurrentTime;

            uint tickCount = (uint)Options.Plant.RootTickStopGrowth.RandomNumberBetween();

            bool atTick;

            if (tickCount > 0)
            {
                atTick = tick % tickCount == 0 && tick > 0;
            }
            else
            {
                atTick = tick > 0;
            }

            // Determine if it should add new lateral root based on length
            float newRootHeight = Options.Plant.NewRootLength.RandomNumberBetween();

            int rootCount = root.Connections.Count() + 1;

            float atHeight = descriptor.Height / newRootHeight;

            bool isAtHeight = atHeight > rootCount;

            return(atTick || isAtHeight);
        }
コード例 #2
0
        private bool ShouldGrow(Internode internode, IPlantPartDescriptor descriptor)
        {
            var terminalHeight = Options.Plant.TerminalHeight.RandomNumberBetween();

            var isBelowTerminalHeight = descriptor.Height <= terminalHeight;

            return(!internode.HasUpperNode() && isBelowTerminalHeight);
        }
コード例 #3
0
        private Node CreateNewUpperNode(Internode internode, IPlantPartDescriptor descriptor)
        {
            var node = nodePartFactory.CreateNode(internode, descriptor, true);

            var upperInternode = internodeFactory.CreateInternode(descriptor.Top, node, 0, internode.BranchCount);

            node.UpperInternode = upperInternode;

            return(node);
        }
コード例 #4
0
        private Vector3 CreateStemCenterVector(IPlantPartDescriptor descriptor)
        {
            bool spawnOnLeft = ShouldSpawnOnLeftSide();

            float x = spawnOnLeft ? descriptor.MinX : descriptor.MaxX;
            float y = descriptor.Top.Y;
            float z = descriptor.Top.Z;

            return(new Vector3(x, y, z));
        }
コード例 #5
0
        private bool ShouldGrow(Root root, IPlantPartDescriptor descriptor, SimulationStateSnapshot snapshot)
        {
            var atHeight = descriptor.Height >= Options.Plant.TerminalHeight.RandomNumberBetween();

            var atTick = snapshot.CurrentTime >= (uint)Options.Plant.RootTickStopGrowth.RandomNumberBetween();

            var atTerminalHeight = descriptor.Height >= Options.Plant.TerminalRootLength.RandomNumberBetween();

            return(!atTerminalHeight || !(atHeight || atTick));
        }
コード例 #6
0
        private Vector3 CreateNewRootCenter(IPlantPartDescriptor descriptor)
        {
            bool left = ShouldSpawnOnLeft();

            float x = left ? descriptor.MinX : descriptor.MaxX;
            float y = descriptor.Bottom.Y;
            float z = descriptor.Bottom.Z;

            return(new Vector3(x, y, z));
        }
コード例 #7
0
        private Root CreateNewRoot(IPlantPartDescriptor descriptor, Root root)
        {
            var center = CreateNewRootCenter(descriptor);

            var branchCount = root.BranchCount + 1;

            var newRoot = rootFactory.CreateRoot(center, branchCount);

            return(newRoot);
        }
コード例 #8
0
        private IEnumerable <IPlantCell> CreateNodeCells(IPlantPartDescriptor descriptor)
        {
            var top     = descriptor.Top;
            var bottom  = new Vector3(top.X, top.Y, top.Z);
            var polygon = new Vector2[0];
            var face    = new Face(polygon);
            var geo     = new CellGeometry(top, bottom, face);
            var cell    = cellFactory.CreateCell(PlantCellType.Parenchyma, geo, new Vacuole(), new CellWall());

            return(new [] { cell });
        }
コード例 #9
0
        private IEnumerable <Stem> CreateStems(IPlantPartDescriptor descriptor, Node node)
        {
            var amount = Options.Plant.StemsPerNode.RandomNumberBetween();

            Stem[] stems = new Stem[amount];

            for (int i = 0; i < amount; i++)
            {
                stems[i] = CreateStem(descriptor, node);
            }

            return(stems);
        }
コード例 #10
0
        private IEnumerable <Petiole> CreatePetioles(IPlantPartDescriptor descriptor)
        {
            var amount = Options.Plant.PetiolesPerNode.RandomNumberBetween();

            Petiole[] petioles = new Petiole[amount];

            for (int i = 0; i < amount; i++)
            {
                petioles[i] = CreatePetiole(descriptor);
            }

            return(petioles);
        }
コード例 #11
0
        public GenericNode CreateNode(Internode lowerInternode, IPlantPartDescriptor descriptor, bool withOptions)
        {
            var cells = CreateNodeCells(descriptor);

            var node = new GenericNode(lowerInternode, cells, lowerInternode.BranchCount);

            // If the node is created according to the options, then
            // the created stems and petioles will be added to the lists
            // above, otherwise they will just be empty lists.
            if (withOptions)
            {
                node.Stems    = CreateStems(descriptor, node);
                node.Petioles = CreatePetioles(descriptor);
            }

            return(node);
        }
コード例 #12
0
        private Petiole CreatePetiole(IPlantPartDescriptor descriptor)
        {
            bool spawnOnLeft = ShouldSpawnOnLeftSide();

            Vector3 center;

            if (spawnOnLeft)
            {
                center = new Vector3(descriptor.MinX, descriptor.Top.Y, descriptor.Top.Z);
            }
            else
            {
                center = new Vector3(descriptor.MaxX, descriptor.Top.Y, descriptor.Top.Z);
            }

            var length = Options.Plant.PetioleLength.RandomNumberBetween();

            Vector3 direction = new Vector3(length, length, 0);

            return(petioleFactory.CreatePetiole(center, direction));
        }
コード例 #13
0
        private Stem CreateStem(IPlantPartDescriptor descriptor, Node node)
        {
            var center = CreateStemCenterVector(descriptor);

            return(stemFactory.CreateStem(center, node));
        }
コード例 #14
0
        private float ComputeThickness(IPlantPartDescriptor descriptor)
        {
            var top = descriptor.Top;

            return(Vector2.Distance(new Vector2(top.X, top.Y), new Vector2(descriptor.MaxX, top.Y)));
        }