FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CRootBox/src/Seed.cpp at master · Plant-Root-Soil-Interactions-Modelling/CRootBox · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Plant-Root-Soil-Interactions-Modelling
/
CRootBox
Public
Notifications
You must be signed in to change notification settings
Fork
12
Star
20
Code
Issues
3
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CRootBox
/
src
/
Seed.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
181 lines (171 loc) · 7.22 KB
Breadcrumbs
CRootBox
/
src
/
Seed.cpp
Copy path
File metadata and controls
181 lines (171 loc) · 7.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//
-*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
include
"
Seed.h
"
#
include
"
Root.h
"
namespace
CRootBox
{
/*
*
*
*/
void
Seed::initialize
()
{
/*
* Create base roots
*/
const
double
maxT =
365
.;
//
maximal simulation time
const
SeedSpecificParameter* rs =
this
->
param
();
//
rename
Vector3d
iheading
(
0
,
0
,-
1
);
//
Taproot
Root* taproot =
new
Root
(plant,
1
, iheading ,
0
,
nullptr
,
0
,
0
);
//
tap root has root type 1
taproot->
addNode
(rs->
seedPos
,
0
);
this
->
addChild
(taproot);
auto
pmap = plant->
getOrganRandomParameter
(Organism::ot_root);
//
Basal roots
int
bt =
getParamSubType
(Organism::ot_root,
"
basal
"
);
if
(bt>
0
) {
basalType = bt;
}
//
otherwise stick with default
if
(rs->
maxB
>
0
) {
try
{
plant->
getOrganRandomParameter
(Organism::ot_root, basalType);
//
if the type is not defined an exception is thrown
}
catch
(...) {
std::cout <<
"
Seed::initialize: Basal root type #
"
<< basalType <<
"
was not defined, using tap root parameters instead
\n
"
<< std::flush;
RootRandomParameter* brtp = (RootRandomParameter*)plant->
getOrganRandomParameter
(Organism::ot_root,
1
)->
copy
(plant);
brtp->
subType
= basalType;
plant->
setOrganRandomParameter
(brtp);
}
int
maxB = rs->
maxB
;
if
(rs->
delayB
>
0
) {
//
limit if possible
maxB =
std::min
(maxB,
int
(
ceil
((maxT-rs->
firstB
)/rs->
delayB
)));
//
maximal for simtime maxT
}
double
delay = rs->
firstB
;
for
(
int
i=
0
; i<maxB; i++) {
Root* basalroot =
new
Root
(plant, basalType, iheading, delay,
nullptr
,
0
,
0
);
basalroot->
addNode
(taproot->
getNode
(
0
), taproot->
getNodeId
(
0
), delay);
this
->
addChild
(basalroot);
delay += rs->
delayB
;
}
}
//
Shoot borne roots
int
st =
getParamSubType
(Organism::ot_root,
"
shootborne
"
);
if
(st>
0
) {
shootborneType = st;
}
//
otherwise stick with default
if
((rs->
nC
>
0
) && (rs->
firstSB
+rs->
delaySB
<maxT)) {
//
only if there are any shootborne roots
try
{
plant->
getOrganRandomParameter
(Organism::ot_root, shootborneType);
//
if the type is not defined an exception is thrown
}
catch
(...) {
std::cout <<
"
Seed::initialize:Shootborne root type #
"
<< shootborneType <<
"
was not defined, using tap root parameters instead
\n
"
;
RootRandomParameter* srtp = (RootRandomParameter*)plant->
getOrganRandomParameter
(Organism::ot_root,
1
)->
copy
(plant);
srtp->
subType
= shootborneType;
plant->
setOrganRandomParameter
(srtp);
}
Vector3d sbpos = rs->
seedPos
;
sbpos.
z
=sbpos.
z
/
2
.;
//
half way up the mesocotyl
numberOfRootCrowns =
ceil
((maxT-rs->
firstSB
)/rs->
delayRC
);
//
maximal number of root crowns
double
delay = rs->
firstSB
;
for
(
int
i=
0
; i<numberOfRootCrowns; i++) {
Root* shootborne0 =
new
Root
(plant, shootborneType, iheading ,delay,
nullptr
,
0
,
0
);
//
TODO fix the initial radial heading
shootborne0->
addNode
(sbpos,delay);
this
->
addChild
(shootborne0);
delay += rs->
delaySB
;
for
(
int
j=
1
; j<rs->
nC
; j++) {
Root* shootborne =
new
Root
(plant, shootborneType, iheading ,delay,
nullptr
,
0
,
0
);
//
TODO fix the initial radial heading
shootborne->
addNode
(shootborne0->
getNode
(
0
), shootborne0->
getNodeId
(
0
),delay);
this
->
addChild
(shootborne);
delay += rs->
delaySB
;
}
sbpos.
z
+=rs->
nz
;
//
move up, for next root crown
delay = rs->
firstSB
+ i*rs->
delayRC
;
//
reset age
}
}
else
{
numberOfRootCrowns =
0
;
}
/*
* Create Stem
*/
//
if (Plant::noParamFile[2] == 1) {
//
std::cout<<"no stem parameter, maybe the XML based parameter file is directly converted from the old rparam file"<<std::endl;
//
} else {
//
// Vector3d isheading(0,0,1);//Initial Stem heading
//
Vector3d isheading(0, 0, 1);//Initial Stem heading
//
Stem* mainstem = new Stem(plant, this, 1, 0., isheading, 0., 0.); // tap root has subtype 1
//
mainstem->addNode(sparam->seedPos, 0);
//
children.push_back(mainstem);
//
//
//
if (sparam->maxTi>0) {
//
if (plant->getParameter(Organ::ot_stem, tillerType)->subType<1) { // if the type is not defined, copy tap root
//
std::cout << "Basal root type #" << basalType << " was not defined, using tap root parameters instead\n";
//
StemTypeParameter* tillParam = (StemTypeParameter*)plant->getParameter(Organ::ot_stem, 1);
//
// StemTypeParameter* titp = new StemTypeParameter(*tillParam);
//
// titp->subType = tillerType;
//
// plant->setParameter(titp);
//
std::cout << "default maxT type is main stem = " << sparam->maxTi << "\n";
//
//
} else{
//
int maxTi = sparam->maxTi;
//
if (sparam->delayB>0) {
//
maxTi = std::min(maxTi,int(std::ceil((maxT-sparam->firstB)/sparam->delayB))); // maximal for simtime maxT
//
}
//
std::cout << "maxT = " << sparam->maxTi << "\n";
//
double delay = sparam->firstB;
//
StemTypeParameter* tillParam = (StemTypeParameter*)plant->getParameter(Organ::ot_stem, 4);
//
for (int i=0; i<maxTi; i++) {
//
Stem* tiller = new Stem(plant, this, 4, delay, isheading ,0., 0.);
//
tiller->addNode(sparam->seedPos,0);
//
children.push_back(tiller);
//
//
std::cout << "new maxT type is main stem = " << sparam->maxTi << "\n";
//
}
//
//
}
//
//
// Stem* tiller1 = new Stem(plant, this, 1, 2, isheading ,0., 0.); // tap root has subtype 1
//
// tiller1->addNode(sparam->seedPos,0);
//
// children.push_back(tiller1);
//
//
//
// Stem* tiller2 = new Stem(plant, this, 1, 4 , isheading ,0., 0.); // tap root has subtype 1
//
// tiller2->addNode(sparam->seedPos,0);
//
// children.push_back(tiller2);
//
// Stem* tiller3 = new Stem(plant, this, 1, 5, isheading ,0., 0.); // tap root has subtype 1
//
// tiller3->addNode(sparam->seedPos,0);
//
// children.push_back(tiller3);
//
}
//
//
}
}
/*
*
* Creates a shallow copy of the seeds child organs
*/
std::vector<Organ*>
Seed::copyBaseOrgans
()
{
std::vector<Organ*> organs;
for
(
auto
& o : children) {
organs.
push_back
(o->
copy
(plant));
}
return
organs;
}
/*
* Searches for a parameter with name @param str, and returns its subtype
*/
int
Seed::getParamSubType
(
int
organtype, std::string str)
{
auto
orp = plant->
getOrganRandomParameter
(organtype);
for
(
auto
& o:orp) {
if
(o->
name
== str) {
return
o->
subType
;
}
}
return
-
1
;
}
/*
*
* Quick info about the object for debugging (TODO)
*/
std::string
Seed::toString
()
const
{
std::stringstream str;
str <<
"
Seed #
"
<< id <<
"
: type
"
<< param_->
subType
<<
"
, length:
"
<< length <<
"
, age:
"
<< age;
return
str.
str
();
}
}
//
namespace CPlantBox
Back
|
FazBrowse Home
|
New Git URL