-
Notifications
You must be signed in to change notification settings - Fork 0
/
tissue.cpp
1182 lines (1078 loc) · 48 KB
/
tissue.cpp
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "tissue.hpp"
// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
const std::string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
// for more information about date/time format
strftime(buf, sizeof(buf), "%Y-%m-%d.%T", &tstruct);
return buf;
}
void SVDDecompX(const Matrix3d &M, Matrix3d &U, Matrix3d &S, Matrix3d &V){
gsl_matrix* Mgsl = gsl_matrix_alloc(3, 3);
gsl_vector* Sgsl = gsl_vector_alloc(3);
gsl_matrix* Vgsl = gsl_matrix_alloc(3, 3);
gsl_vector* wgsl = gsl_vector_alloc(3);
for(int i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j)
gsl_matrix_set(Mgsl, i, j, M[i][j]);
gsl_linalg_SV_decomp(Mgsl, Vgsl, Sgsl, wgsl);
for(int i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j){
U[i][j] = gsl_matrix_get(Mgsl,i,j);
V[i][j] = gsl_matrix_get(Vgsl,i,j);
}
//This could be passed around as just a 3D vector, but we'll use a matrix for now
S = Matrix<3,3,double>::Diagonal(Point3d(gsl_vector_get(Sgsl, 0), gsl_vector_get(Sgsl, 1), gsl_vector_get(Sgsl, 2)));
gsl_matrix_free(Mgsl);
gsl_matrix_free(Vgsl);
gsl_vector_free(Sgsl);
gsl_vector_free(wgsl);
}
void PolarDecompX(Matrix3d &M,Matrix3d &S, Matrix3d &U){
Matrix3d Usvd;
Matrix3d Ssvd;
Matrix3d Vsvd;
SVDDecompX(M,Usvd,Ssvd,Vsvd);
U = Usvd*transpose(Vsvd);
S = Vsvd*Ssvd*transpose(Vsvd);
}
Point3d Rotate(Point3d v, double angle)
{
Point3d p = v;
double Tx=p[0],Ty=p[1];
double X=(Tx*cos(angle))-(Ty*sin(angle));
double Y=(Ty*cos(angle))+(Tx*sin(angle));
p[0] = X;
p[1] = Y;
return p;
}
bool PointInPolygon(Point3d point, std::vector<Point3d> points) {
int i, j, nvert = points.size();
bool c = false;
for(i = 0, j = nvert - 1; i < nvert; j = i++) {
if(((points[i].y() > point.y()) != (points[j].y() > point.y())) &&
(point.x() < (points[j].x() - points[i].x()) * (point.y() - points[i].y()) /
(points[j].y() - points[i].y()) +
points[i].x()))
c = !c;
}
return c;
}
Point3d shortenLength(Point3d A, float reductionLength) {
Point3d B = A;
B *= (1 - reductionLength / A.norm());
return B;
}
float DistancePtLine(Point3d a, Point3d b, Point3d p) {
Point3d n = b - a;
Point3d pa = a - p;
Point3d c = n * ((pa * n) / (n * n));
Point3d d = pa - c;
return sqrt((d * d));
}
Point3d findClosestLineToLine(Point3d targetLine,
Point3d line1, Point3d line2) {
Point3d finalLine;
double minAxis1;
if(mdx::angle(targetLine, line1) < mdx::angle(targetLine, -line1))
minAxis1 = mdx::angle(targetLine, line1);
else
minAxis1 = mdx::angle(targetLine, -line1);
double minAxis2;
if(mdx::angle(targetLine, line2) < mdx::angle(targetLine, -line2))
minAxis2 = mdx::angle(targetLine, line2);
else
minAxis2 = mdx::angle(targetLine, -line2);
if(minAxis1 < minAxis2)
finalLine = line1;
else
finalLine = line2;
return finalLine;
}
std::vector<double> softmax(std::vector<double> v) {
double sum = 0;
std::vector<double> r;
for(double i : v) {
r.push_back(exp(i));
sum += exp(i);
}
for(uint i = 0; i < r.size(); i++)
r[i] /= sum;
return r;
}
void MBR(std::vector<Point3d> points, std::vector<Point3d>& rect) {
std::vector<int> permutation;
sortPolygonPoints(points, Point3d(0, 0, -1), permutation);
std::vector<Point3d> p;
for(auto i : permutation)
p.push_back(points[i]);
p.push_back(p[0]);
std::vector<Point3d> e;
for(uint i = 1; i < p.size(); i++)
e.push_back(p[i] - p[i - 1]);
std::vector<double> norms;
for(auto i : e)
norms.push_back(norm(i));
std::vector<Point3d> v;
for(uint i = 0; i < e.size(); i++)
v.push_back(e[i] / norms[i]);
std::vector<Point3d> w;
for(uint i = 0; i < v.size(); i++)
w.push_back(Point3d(-v[i][1], v[i][0], 0));
std::vector<double> a, b, areas;
std::vector<std::vector<double>> x, y;
for(uint i = 0; i < v.size(); i++) {
a.clear();
b.clear();
for(uint j = 0; j < p.size(); j++) {
a.push_back(p[j] * v[i]);
b.push_back(p[j] * w[i]);
}
double max_a = *max_element(a.begin(), a.end());
double min_a = *min_element(a.begin(), a.end());
double max_b = *max_element(b.begin(), b.end());
double min_b = *min_element(b.begin(), b.end());
areas.push_back((min_b - max_b) * (min_a - max_a));
x.push_back({min_a, max_a});
y.push_back({min_b, max_b});
}
int k = std::min_element(areas.begin(), areas.end()) - areas.begin();
int qx[4] = {0, 1, 1, 0};
int qy[4] = {0, 0, 1, 1};
Matrix<4, 2, double> M1;
for(int i = 0; i < 4; i++)
M1[i] = Point2d(x[k][qx[i]], y[k][qy[i]]);
Matrix<2, 3, double> M2;
M2[0] = v[k];
M2[1] = w[k];
Matrix<4, 3, double> M = M1 * M2;
rect.clear();
for(int i = 0; i < 4; i++)
rect.push_back(M[i]);
}
// extended version of the official one
void neighborhood2D(Mesh& mesh,
const CCStructure& cs,
const CCIndexDataAttr& indexAttr,
std::map<IntIntPair, double>& wallAreas,
std::map<IntIntPair, std::set<CCIndex>>& wallEdges) {
wallAreas.clear();
wallEdges.clear();
//#pragma omp parallel for
for(uint i = 0; i < cs.edges().size(); i++) {
CCIndex e = cs.edges()[i];
std::set<CCIndex> edgeVtxs = cs.incidentCells(e, 0);
CCIndex v1 = *(edgeVtxs.begin());
CCIndex v2 = *(++edgeVtxs.begin());
double edgeLength = norm(indexAttr[v1].pos - indexAttr[v2].pos);
std::set<CCIndex> edgeFaces = cs.incidentCells(e, 2);
CCIndex f1 = *(edgeFaces.begin());
CCIndex f2;
if(edgeFaces.size() > 1)
f2 = *(++edgeFaces.begin());
// ignore edges inside of a cell
if(mesh.getLabel(indexAttr[f1].label) == mesh.getLabel(indexAttr[f2].label))
continue;
//#pragma omp critical
{
wallAreas[std::make_pair(indexAttr[f1].label, indexAttr[f2].label)] += edgeLength;
wallAreas[std::make_pair(indexAttr[f2].label, indexAttr[f1].label)] += edgeLength;
wallEdges[std::make_pair(indexAttr[f1].label, indexAttr[f2].label)].insert(e);
wallEdges[std::make_pair(indexAttr[f2].label, indexAttr[f1].label)].insert(e);
}
}
}
bool Tissue::initialize(bool create_dual, bool extended_dual) {
if(parm("Verbose") == "True")
mdxInfo << "Tissue::initialize" << endl;
Mesh* mesh = getMesh("Mesh 1");
if(!mesh or mesh->file().isEmpty())
throw(QString("Tissue::initialize No current mesh"));
// Get the tissue and cell graph names
int cellDim = parm("Dimension").toInt();
TissueName = parm("Tissue");
TissueDualName = parm("Tissue Dual");
cellTissue.processTissueParms(*this);
if(mesh->ccStructure(TissueName).maxDimension != cellDim)
mesh->ccStructure(TissueName) = CCStructure(cellDim);
if(mesh->ccStructure(TissueDualName).maxDimension < 2)
mesh->ccStructure(TissueDualName) = CCStructure(2);
cellTissue.initialize(
&mesh->ccStructure(TissueName), &mesh->ccStructure(TissueDualName), &mesh->indexAttr());
// necessary for createdualextended
restore(mesh->ccStructure(TissueName));
// restore the tissue if requested
if(create_dual) {
if(parm("Verbose") == "True")
mdxInfo << "Tissue::initialize: Dual graph restored" << endl;
if(!extended_dual) {
cellTissue.createDual();
cellTissue.updateGeometry();
}
else
createDualExtended( mesh->ccStructure(TissueName), mesh->ccStructure(TissueDualName));
}
// Setup the complex attributes
mesh->ccAttr(TissueName, "Type") = "Tissue";
mesh->ccAttr(TissueName, "Dual") = TissueDualName;
mesh->ccAttr(TissueDualName, "Type") = "TissueDual";
mesh->ccAttr(TissueDualName, "Dual") = TissueName;
mesh->updateAll();
return true;
}
// Rewritten function from the original
void Tissue::createDualExtended(CCStructure &cs, CCStructure &csDual) {
Mesh* mesh = getMesh("Mesh 1");
if(!mesh)
throw(QString("Tissue::createDualExtended No current mesh"));
CCIndexDataAttr& indexAttr = mesh->indexAttr();
Tissue::CellDataAttr& cellAttr = mesh->attributes().attrMap<int, Tissue::CellData>("CellData");
Tissue::VertexDataAttr& vMAttr =
mesh->attributes().attrMap<CCIndex, Tissue::VertexData>("VertexData");
csDual.clear();
for(uint i = 0; i < cellAttr.size(); i++) {
auto it = cellAttr.begin();
advance(it, i);
Tissue::CellData& cD = it->second;
CCIndex v = CCIndexFactory.getIndex();
csDual.addCell(v);
indexAttr[v].pos = cD.centroid;
vMAttr[v].dualCell = &cD;
cD.dualVertex = v;
}
for(uint i = 0; i < cellAttr.size(); i++) {
auto it = cellAttr.begin();
advance(it, i);
Tissue::CellData& cD = it->second;
std::set<int> labels;
for(CCIndex e : cD.perimeterEdges)
for(CCIndex f : cs.incidentCells(e, 2))
if(indexAttr[f].label != cD.label)
labels.insert(indexAttr[f].label);
for(int label : labels) {
CCIndex e = CCIndexFactory.getIndex();
csDual.addCell(e, +cD.dualVertex -cellAttr[label].dualVertex);
}
}
}
// basically restore tissue's properties
void Tissue::restore(CCStructure csCurr) {
Mesh* mesh = getMesh("Mesh 1");
if(!mesh)
throw(QString("CellTissueProcess::restore No current mesh"));
Tissue::CellDataAttr& cellAttr = mesh->attributes().attrMap<int, Tissue::CellData>("CellData");
Tissue::EdgeDataAttr& edgeAttr =
mesh->attributes().attrMap<CCIndex, Tissue::EdgeData>("EdgeData");
Tissue::FaceDataAttr& faceAttr =
mesh->attributes().attrMap<CCIndex, Tissue::FaceData>("FaceData");
Tissue::VertexDataAttr& vMAttr =
mesh->attributes().attrMap<CCIndex, Tissue::VertexData>("VertexData");
if(parm("Verbose") == "True")
mdxInfo << "Tissue::restore" << endl;
CCIndexDataAttr& indexAttr = mesh->indexAttr();
CCStructure& cs = mesh->ccStructure("Tissue");
CCStructure& csDual = mesh->ccStructure("TissueDual");
CCStructure& csVisual = mesh->ccStructure("TissueVisual");
csVisual.clear();
updateGeometry(cs, indexAttr);
updateGeometry(csDual, indexAttr);
updateGeometry(csVisual, indexAttr);
// perimeters and borders lengths between cells
neighborhood2D(*mesh, cs, indexAttr, wallAreas, wallEdges);
// initialize cellAttr, at the beginning, owners are based on labels
std::set<int> labels = getAllLabelsFaces(cs, indexAttr);
for(int label : labels) {
if(label < 1)
throw(QString("Tissue::restore: cell with unallowed label " + label));
// if a cell with the same label exist, we just reset its faces set,
// which will be refilled in the next loop, otherwise, create a new cell
if(cellAttr.find(label) != cellAttr.end()) {
// verify that the cell was actually initialized
if(!cellAttr[label].cellFaces)
cellAttr[label].cellFaces = new std::set<CCIndex>();
} else {
cellAttr[label] = Tissue::CellData();
cellAttr[label].tissue = this;
cellAttr[label].label = label;
if(parm("Verbose") == "True")
mdxInfo << "Tissue::restore: A new cell has been created, label: " << label << endl;
}
}
// cells that are not present anymore should be removed
std::set<int> to_delete;
for(auto c : cellAttr) {
if(labels.find(c.second.label) == labels.end() || c.second.label < 1)
to_delete.insert(c.second.label);
}
for(int label : to_delete) {
Tissue::CellType type = cellAttr[label].type; /// IMPORTANT, if you refer to cellAttr the cell is recreated!
cellAttr.erase(label);
if(parm("Verbose") == "True")
mdxInfo << "Tissue::restore: cell " << label << ", " << Tissue::ToString(type) << " not in the system anymore and therefore removed" << endl;
}
// restore CELLS properties
for(uint i = 0; i < cellAttr.size(); i++) {
auto it = cellAttr.begin();
advance(it, i);
Tissue::CellData& cD = it->second;
cD.restore(mesh, this, cs, csDual, indexAttr, faceAttr, edgeAttr, vMAttr);
cD.update(cs, indexAttr, faceAttr, edgeAttr, vMAttr, EPS);
// restore the MF visuals
if(parm("Draw MF") == "True") {
cD.a1_v1 = CCIndexFactory.getIndex();
csVisual.addCell(cD.a1_v1);
cD.a1_v2 = CCIndexFactory.getIndex();
csVisual.addCell(cD.a1_v2);
cD.a1_e = CCIndexFactory.getIndex();
csVisual.addCell(cD.a1_e, +cD.a1_v1 - cD.a1_v2);
cD.a2_v1 = CCIndexFactory.getIndex();
csVisual.addCell(cD.a2_v1);
cD.a2_v2 = CCIndexFactory.getIndex();
csVisual.addCell(cD.a2_v2);
cD.a2_e = CCIndexFactory.getIndex();
csVisual.addCell(cD.a2_e, +cD.a2_v1 - cD.a2_v2);
}
if(parm("Draw Bounding Box") == "True") {
cD.box_v[0] = CCIndexFactory.getIndex();
cD.box_v[1] = CCIndexFactory.getIndex();
cD.box_v[2] = CCIndexFactory.getIndex();
cD.box_v[3] = CCIndexFactory.getIndex();
cD.box_e[0] = CCIndexFactory.getIndex();
cD.box_e[1] = CCIndexFactory.getIndex();
cD.box_e[2] = CCIndexFactory.getIndex();
cD.box_e[3] = CCIndexFactory.getIndex();
cD.axisCenter_v = CCIndexFactory.getIndex();
cD.axisMax_v = CCIndexFactory.getIndex();
cD.axisMin_v = CCIndexFactory.getIndex();
cD.axisMax_e = CCIndexFactory.getIndex();
cD.axisMin_e = CCIndexFactory.getIndex();
csVisual.addCell(cD.box_v[0]);
csVisual.addCell(cD.box_v[1]);
csVisual.addCell(cD.box_v[2]);
csVisual.addCell(cD.box_v[3]);
csVisual.addCell(cD.box_e[0], +cD.box_v[0] - cD.box_v[1]);
csVisual.addCell(cD.box_e[1], +cD.box_v[1] - cD.box_v[2]);
csVisual.addCell(cD.box_e[2], +cD.box_v[2] - cD.box_v[3]);
csVisual.addCell(cD.box_e[3], +cD.box_v[3] - cD.box_v[0]);
csVisual.addCell(cD.axisCenter_v);
csVisual.addCell(cD.axisMax_v);
csVisual.addCell(cD.axisMin_v);
csVisual.addCell(cD.axisMax_e, +cD.axisCenter_v - cD.axisMax_v);
csVisual.addCell(cD.axisMin_e, +cD.axisCenter_v - cD.axisMin_v);
}
if(parm("Draw Auxin-Flux Rescale").toDouble() > 0) {
cD.auxinFlux_v1 = CCIndexFactory.getIndex();
csVisual.addCell(cD.auxinFlux_v1);
cD.auxinFlux_v2 = CCIndexFactory.getIndex();
csVisual.addCell(cD.auxinFlux_v2);
cD.auxinFlux_e = CCIndexFactory.getIndex();
csVisual.addCell(cD.auxinFlux_e, +cD.auxinFlux_v1 - cD.auxinFlux_v2);
cD.auxinFlux_v3 = CCIndexFactory.getIndex();
csVisual.addCell(cD.auxinFlux_v3);
cD.auxinFlux_v4 = CCIndexFactory.getIndex();
csVisual.addCell(cD.auxinFlux_v4);
cD.auxinFlux_f = CCIndexFactory.getIndex();
std::vector<CCIndex> vs;
vs.push_back(cD.auxinFlux_v2);
vs.push_back(cD.auxinFlux_v3);
vs.push_back(cD.auxinFlux_v4);
addFace(csVisual, cD.auxinFlux_f, vs);
indexAttr[cD.auxinFlux_f].label = 1;
}
if(parm("Draw PGD Rescale").toDouble() > 0) {
cD.PDGmax_v1 = CCIndexFactory.getIndex();
cD.PDGmax_v2 = CCIndexFactory.getIndex();
cD.PDGmin_v1 = CCIndexFactory.getIndex();
cD.PDGmin_v2 = CCIndexFactory.getIndex();
csVisual.addCell(cD.PDGmax_v1);
csVisual.addCell(cD.PDGmax_v2);
csVisual.addCell(cD.PDGmin_v1);
csVisual.addCell(cD.PDGmin_v2);
cD.PDGmax_e = CCIndexFactory.getIndex();
csVisual.addCell(cD.PDGmax_e, +cD.PDGmax_v1 - cD.PDGmax_v2);
cD.PDGmin_e = CCIndexFactory.getIndex();
csVisual.addCell(cD.PDGmin_e, +cD.PDGmin_v1 - cD.PDGmin_v2);
}
}
// restore FACES previous properties and initialize them
for(uint i = 0; i < cs.faces().size(); i++) {
CCIndex f = cs.faces()[i];
Tissue::FaceData& fD = faceAttr[f];
fD.restore(f, cs, indexAttr);
fD.update(f, cs, indexAttr, vMAttr);
if(cellAttr[indexAttr[f].label].selected)
indexAttr[f].selected = true;
// restore the tensor strain rate visuals
fD.G_v0 = CCIndexFactory.getIndex();
csVisual.addCell(fD.G_v0);
fD.G_v1 = CCIndexFactory.getIndex();
csVisual.addCell(fD.G_v1);
fD.G_v2 = CCIndexFactory.getIndex();
csVisual.addCell(fD.G_v2);
fD.G_e1 = CCIndexFactory.getIndex();
csVisual.addCell(fD.G_e1, +fD.G_v0 - fD.G_v1);
fD.G_e2 = CCIndexFactory.getIndex();
csVisual.addCell(fD.G_e2, +fD.G_v0 - fD.G_v2);
if(parm("Draw MF") == "True") {
fD.a1_v1 = CCIndexFactory.getIndex();
csVisual.addCell(fD.a1_v1);
fD.a1_v2 = CCIndexFactory.getIndex();
csVisual.addCell(fD.a1_v2);
fD.a1_e = CCIndexFactory.getIndex();
csVisual.addCell(fD.a1_e, +fD.a1_v1 - fD.a1_v2);
fD.a2_v1 = CCIndexFactory.getIndex();
csVisual.addCell(fD.a2_v1);
fD.a2_v2 = CCIndexFactory.getIndex();
csVisual.addCell(fD.a2_v2);
fD.a2_e = CCIndexFactory.getIndex();
csVisual.addCell(fD.a2_e);
fD.a2_e = CCIndexFactory.getIndex();
csVisual.addCell(fD.a2_e, +fD.a2_v1 - fD.a2_v2);
}
}
// Restore EDGES
for(uint i = 0; i < cs.edges().size(); i++) {
CCIndex e = cs.edges()[i];
Tissue::EdgeData& eD = edgeAttr[e];
eD.restore(e, cs, indexAttr, cellAttr);
eD.update(e, cs, indexAttr, vMAttr, faceAttr);
if(parm("Draw PINs").toDouble() > 0) {
if(eD.type == Wall) {
eD.pin_v1_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v1_1);
eD.pin_v2_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v2_1);
eD.pin_v3_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v3_1);
eD.pin_v4_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v4_1);
eD.pin_e1_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e1_1, + eD.pin_v1_1 - eD.pin_v2_1);
eD.pin_e2_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e2_1, + eD.pin_v2_1 - eD.pin_v3_1);
eD.pin_e3_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e3_1, + eD.pin_v3_1 - eD.pin_v4_1);
eD.pin_e4_1 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e4_1, + eD.pin_v4_1 - eD.pin_v1_1);
std::vector<CCIndex> vs;
vs.push_back(eD.pin_v1_1);
vs.push_back(eD.pin_v2_1);
vs.push_back(eD.pin_v3_1);
vs.push_back(eD.pin_v4_1);
eD.pin_f_1 = CCIndexFactory.getIndex();
addFace(csVisual, eD.pin_f_1, vs);
indexAttr[eD.pin_f_1].label = 2; // to color pins
eD.pin_v1_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v1_2);
eD.pin_v2_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v2_2);
eD.pin_v3_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v3_2);
eD.pin_v4_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_v4_2);
eD.pin_e1_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e1_2, + eD.pin_v1_2 - eD.pin_v2_2);
eD.pin_e2_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e2_2, + eD.pin_v2_2 - eD.pin_v3_2);
eD.pin_e3_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e3_2, + eD.pin_v3_2 - eD.pin_v4_2);
eD.pin_e4_2 = CCIndexFactory.getIndex();
csVisual.addCell(eD.pin_e4_2, + eD.pin_v4_2 - eD.pin_v1_2);
vs.clear();
vs.push_back(eD.pin_v1_2);
vs.push_back(eD.pin_v2_2);
vs.push_back(eD.pin_v3_2);
vs.push_back(eD.pin_v4_2);
eD.pin_f_2 = CCIndexFactory.getIndex();
addFace(csVisual, eD.pin_f_2, vs);
indexAttr[eD.pin_f_2].label = 2; // to color pins
}
}
}
// restore VERTICES
for(uint i = 0; i < cs.vertices().size(); i++) {
CCIndex v = cs.vertices()[i];
Tissue::VertexData& vD = vMAttr[v];
vD.restore(v, cs, indexAttr, cellAttr, edgeAttr);
vMAttr[v].prevPos = indexAttr[v].pos;
vD.V_v0 = CCIndexFactory.getIndex();
csVisual.addCell(vD.V_v0);
vD.V_v1 = CCIndexFactory.getIndex();
csVisual.addCell(vD.V_v1);
vD.V_e = CCIndexFactory.getIndex();
csVisual.addCell(vD.V_e, +vD.V_v0 - vD.V_v1);
}
// clear unused edges
std::set<CCIndex> old_cells;
for(auto i : edgeAttr)
if(!cs.hasCell(i.first) && !csVisual.hasCell(i.first) && !csDual.hasCell(i.first))
old_cells.insert(i.first);
for(CCIndex e : old_cells)
edgeAttr.erase(e);
old_cells.clear();
// clear unused vertices
for(auto i : vMAttr)
if(!cs.hasCell(i.first) && !csVisual.hasCell(i.first) && !csDual.hasCell(i.first))
old_cells.insert(i.first);
for(CCIndex v : old_cells)
vMAttr.erase(v);
old_cells.clear();
// clear unused faces
for(auto i : faceAttr)
if(!cs.hasCell(i.first) && !csVisual.hasCell(i.first) && !csDual.hasCell(i.first))
old_cells.insert(i.first);
for(CCIndex f : old_cells)
faceAttr.erase(f);
old_cells.clear();
// clear unused indexes
for(auto i : indexAttr)
if(!cs.hasCell(i.first) && !csVisual.hasCell(i.first) && !csDual.hasCell(i.first)) // IMPORTANT: you have to check all the cell complexes
old_cells.insert(i.first);
for(CCIndex i : old_cells)
indexAttr.erase(i);
mesh->updateAll();
}
// update geometries, signals....
bool Tissue::step(double Dt) {
Mesh* mesh = getMesh("Mesh 1");
if(!mesh)
throw(QString("CellTissueProcess::initialize No current mesh"));
Tissue::CellDataAttr& cellAttr = mesh->attributes().attrMap<int, Tissue::CellData>("CellData");
Tissue::EdgeDataAttr& edgeAttr =
mesh->attributes().attrMap<CCIndex, Tissue::EdgeData>("EdgeData");
Tissue::FaceDataAttr& faceAttr =
mesh->attributes().attrMap<CCIndex, Tissue::FaceData>("FaceData");
Tissue::VertexDataAttr& vMAttr =
mesh->attributes().attrMap<CCIndex, Tissue::VertexData>("VertexData");
CCIndexDataAttr& indexAttr = mesh->indexAttr();
CCStructure& cs = mesh->ccStructure("Tissue");
CCStructure& csDual = mesh->ccStructure("TissueDual");
CCStructure& csVisual = mesh->ccStructure("TissueVisual");
updateGeometry(cs, indexAttr);
updateGeometry(csDual, indexAttr);
updateGeometry(csVisual, indexAttr);
CCIndexIntAttr& cellTypeSignal = mesh->signalAttr<int>("Cell Type");
CCIndexIntAttr& cellLineageSignal = mesh->signalAttr<int>("Cell Lineage");
CCIndexDoubleAttr& divisionCountSignal = mesh->signalAttr<double>("Division Count");
CCIndexDoubleAttr& lifeTimeSignal = mesh->signalAttr<double>("Life Time");
CCIndexDoubleAttr& areaSignal = mesh->signalAttr<double>("Cell Area");
CCIndexDoubleAttr& stageSignal = mesh->signalAttr<double>("Stage");
CCIndexDoubleAttr& auxinSignal = mesh->signalAttr<double>("Chems: Auxin");
CCIndexDoubleAttr& auxinByAreaSignal = mesh->signalAttr<double>("Chems: Auxin By Area");
CCIndexDoubleAttr& intercellularAuxinSignal = mesh->signalAttr<double>("Chems: Intercellular Auxin");
CCIndexDoubleAttr& Aux1CytSignal = mesh->signalAttr<double>("Chems: Aux1 Cyt");
CCIndexDoubleAttr& Aux1MemSignal = mesh->signalAttr<double>("Chems: Aux1 Mem");
CCIndexDoubleAttr& MFImpactSignal = mesh->signalAttr<double>("Chems: MF Impact");
CCIndexDoubleAttr& geomImpactSignal = mesh->signalAttr<double>("Chems: Geometry Impact");
CCIndexDoubleAttr& auxinRatioSignal = mesh->signalAttr<double>("Chems: Auxin Transport");
CCIndexDoubleAttr& auxinGradSignal = mesh->signalAttr<double>("Chems: Auxin Gradient");
CCIndexDoubleAttr& auxinFluxImpactSignal = mesh->signalAttr<double>("Chems: Auxin Flux Impact");
CCIndexDoubleAttr& divInhibitorCytSignal = mesh->signalAttr<double>("Chems: Division Inhibitor");
CCIndexDoubleAttr& divPromoterCytSignal = mesh->signalAttr<double>("Chems: Division Promoter");
CCIndexDoubleAttr& divProbSignal = mesh->signalAttr<double>("Chems: Division Probability");
CCIndexDoubleAttr& Pin1CytSignal = mesh->signalAttr<double>("Chems: Pin1 Cyt");
CCIndexDoubleAttr& Pin1MemSignal = mesh->signalAttr<double>("Chems: Pin1 Mem");
CCIndexDoubleAttr& pin1SensitivitySignal = mesh->signalAttr<double>("Chems: Pin Sensitivity");
CCIndexDoubleAttr& quasimodoCytSignal = mesh->signalAttr<double>("Chems: Quasimodo");
CCIndexDoubleAttr& wox5CytSignal = mesh->signalAttr<double>("Chems: WOX5");
CCIndexDoubleAttr& PINOIDCytSignal = mesh->signalAttr<double>("Chems: PINOID Cyt");
CCIndexDoubleAttr& PP2ACytSignal = mesh->signalAttr<double>("Chems: PP2A Cyt");
CCIndexDoubleAttr& PINOIDMemSignal = mesh->signalAttr<double>("Chems: PINOID Mem");
CCIndexDoubleAttr& PP2AMemSignal = mesh->signalAttr<double>("Chems: PP2A Mem");
CCIndexDoubleAttr& brassinosteroidsSignal = mesh->signalAttr<double>("Chems: Brassinosteroids");
CCIndexDoubleAttr& brassinosteroidSignal = mesh->signalAttr<double>("Chems: Brassinosteroid Signal");
CCIndexDoubleAttr& brassinosteroidTopSignal = mesh->signalAttr<double>("Chems: Brassinosteroid Top");
CCIndexDoubleAttr& ccvTIR1Signal = mesh->signalAttr<double>("Chems: ccvTIR1");
CCIndexDoubleAttr& growthSignal = mesh->signalAttr<double>("Chems: Growth Signal");
CCIndexDoubleAttr& pressureSignal = mesh->signalAttr<double>("Mechs: Turgor Pressure");
CCIndexDoubleAttr& edgeStiffnessSignal = mesh->signalAttr<double>("Mechs: Edge Stiffness");
CCIndexDoubleAttr& cellStiffnessSignal = mesh->signalAttr<double>("Mechs: Cell Stiffness");
CCIndexDoubleAttr& edgeStrainSignal = mesh->signalAttr<double>("Mechs: Edge Strain Rate");
CCIndexDoubleAttr& edgeRestLengthUpdateSignal = mesh->signalAttr<double>("Mechs: Edge RestLength Update Rate");
CCIndexDoubleAttr& growthRateSignal = mesh->signalAttr<double>("Mechs: Growth Rate");
CCIndexDoubleAttr& distanceConstrainSignal = mesh->signalAttr<double>("PBD: distance constrain");
CCIndexDoubleAttr& bendingConstrainSignal = mesh->signalAttr<double>("PBD: bending constrain");
CCIndexDoubleAttr& shapeConstrainSignal = mesh->signalAttr<double>("PBD: shape constrain");
CCIndexDoubleAttr& strainConstrainSignal = mesh->signalAttr<double>("PBD: strain constrain");
CCIndexDoubleAttr& pressureConstrainSignal = mesh->signalAttr<double>("PBD: pressure constrain");
cellTypeSignal.clear();
cellLineageSignal.clear();
divisionCountSignal.clear();
stageSignal.clear();
auxinSignal.clear();
auxinByAreaSignal.clear();
intercellularAuxinSignal.clear();
Aux1CytSignal.clear();
Aux1MemSignal.clear();
MFImpactSignal.clear();
geomImpactSignal.clear();
auxinFluxImpactSignal.clear();
auxinRatioSignal.clear();
auxinGradSignal.clear();
divInhibitorCytSignal.clear();
divPromoterCytSignal.clear();
quasimodoCytSignal.clear();
wox5CytSignal.clear();
divProbSignal.clear();
Pin1CytSignal.clear();
Pin1MemSignal.clear();
pin1SensitivitySignal.clear();
PINOIDCytSignal.clear();
PP2ACytSignal.clear();
PINOIDMemSignal.clear();
PP2AMemSignal.clear();
ccvTIR1Signal.clear();
pressureSignal.clear();
edgeStrainSignal.clear();
edgeStiffnessSignal.clear();
cellStiffnessSignal.clear();
edgeRestLengthUpdateSignal.clear();
growthRateSignal.clear();
//updateGeometry(cs, indexAttr);
//updateGeometry(csDual, indexAttr);
// update TissueDual positions
for(CCIndex v : csDual.vertices()) {
Tissue::VertexData& vD = vMAttr[v];
if(vD.dualCell)
indexAttr[v].pos = ((CellData*)vD.dualCell)->centroid;
}
// update EDGES geometry
//#pragma omp parallel for
for(uint i = 0; i < cs.edges().size(); i++) {
CCIndex e = cs.edges()[i];
Tissue::EdgeData& eD = edgeAttr[e];
eD.update(e, cs, indexAttr, vMAttr, faceAttr);
// PINs
double shift = 0.1; // distance from the walls
if(parm("Draw PINs").toDouble() > 0) {
double extension = parm("Draw PINs").toDouble();
if(eD.type == Wall) {
std::vector<CCIndex> fs;
for(auto f : cs.incidentCells(e, 2))
fs.push_back(f);
Tissue::FaceData fD = faceAttr[fs[0]];
Point3d c = eD.outwardNormal[fs[0]];
int label = fD.owner->label;
double pin = eD.Pin1[label] + EPS;
auto eb = cs.edgeBounds(e);
CCIndex v1 = eb.first;
CCIndex v2 = eb.second;
Point3d versor = indexAttr[v2].pos - indexAttr[v1].pos;
versor /= norm(versor);
Point3d p1 = indexAttr[v1].pos + -c * shift + versor * shift;
Point3d p2 = indexAttr[v2].pos + -c * shift - versor * shift;
Point3d p4 = p1 + (-c * extension * pin) + versor * shift*3;
Point3d p3 = p2 + (-c * extension * pin) - versor * shift*3;
indexAttr[eD.pin_v1_1].pos = p1+ Point3d(0,0,0.04);
indexAttr[eD.pin_v2_1].pos = p2+ Point3d(0,0,0.04);
indexAttr[eD.pin_v3_1].pos = p3+ Point3d(0,0,0.04);
indexAttr[eD.pin_v4_1].pos = p4+ Point3d(0,0,0.04);
if(fs.size() > 1) {
fD = faceAttr[fs[1]];
c = eD.outwardNormal[fs[1]];
label = fD.owner->label;
pin = eD.Pin1[label] + EPS;
p1 = indexAttr[v1].pos + -c * shift + versor * shift;
p2 = indexAttr[v2].pos + -c * shift - versor * shift;
p4 = p1 + (-c * extension * pin) + versor * shift*3;
p3 = p2 + (-c * extension * pin) - versor * shift*3;
indexAttr[eD.pin_v1_2].pos = p1 + Point3d(0,0,0.04);
indexAttr[eD.pin_v2_2].pos = p2 + Point3d(0,0,0.04);
indexAttr[eD.pin_v3_2].pos = p3 + Point3d(0,0,0.04);
indexAttr[eD.pin_v4_2].pos = p4 + Point3d(0,0,0.04);
}
}
}
}
// update VERTICES, forces etc...visuals
//#pragma omp parallel for
for(uint i = 0; i < cs.vertices().size(); i++) {
CCIndex v = cs.vertices()[i];
Tissue::VertexData& vD = vMAttr[v];
Point3d totalForce;
distanceConstrainSignal[v] = norm(vD.corrections["distance"]);
bendingConstrainSignal[v] = norm(vD.corrections["bending"]);
shapeConstrainSignal[v] = norm(vD.corrections["shape"]);
strainConstrainSignal[v] = norm(vD.corrections["strain"]);
pressureConstrainSignal[v] = norm(vD.corrections["pressure"]);
for(auto m : vD.forces) {
totalForce += std::get<2>(m);
}
if(parm("Draw Velocity Rescale").toDouble() > 0) {
indexAttr[vD.V_v0].pos = indexAttr[v].pos;
indexAttr[vD.V_v1].pos = indexAttr[vD.V_v0].pos + vD.velocity * parm("Draw Velocity Rescale").toDouble();
}
}
// update basic CELL data and visuals (has to go before faces as we are setting cD.selected, this it limit iterations)
for(uint i = 0; i < cellAttr.size(); i++) {
auto it = cellAttr.begin();
advance(it, i);
Tissue::CellData& cD = it->second;
cD.update(cs, indexAttr, faceAttr, edgeAttr, vMAttr, Dt);
cD.selected = false;
if(parm("Draw MF") == "True") {
indexAttr[cD.a1_v1].pos = cD.centroid;
indexAttr[cD.a1_v2].pos = cD.centroid + cD.a1;
indexAttr[cD.a2_v1].pos = cD.centroid;
indexAttr[cD.a2_v2].pos = cD.centroid + cD.a2;
}
if(parm("Draw Auxin-Flux Rescale").toDouble() > 0) { // Draw auxin flow arrows
indexAttr[cD.auxinFlux_v1].pos = cD.centroid;
indexAttr[cD.auxinFlux_v2].pos = cD.centroid + cD.auxinFluxVector * parm("Draw Auxin-Flux Rescale").toDouble();
indexAttr[cD.auxinFlux_v3].pos = indexAttr[cD.auxinFlux_v2].pos;
indexAttr[cD.auxinFlux_v3].pos = mdx::rotatePoint2D(indexAttr[cD.auxinFlux_v3].pos, cD.centroid, 0.15);
Point3d v = cD.centroid - indexAttr[cD.auxinFlux_v3].pos;
indexAttr[cD.auxinFlux_v3].pos += v / norm(v) * (0.35 * norm(v));;
indexAttr[cD.auxinFlux_v4].pos = indexAttr[cD.auxinFlux_v2].pos;
indexAttr[cD.auxinFlux_v4].pos = mdx::rotatePoint2D(indexAttr[cD.auxinFlux_v4].pos, cD.centroid, -0.15);
v = cD.centroid - indexAttr[cD.auxinFlux_v4].pos;
indexAttr[cD.auxinFlux_v4].pos += v / norm(v) * (0.35 * norm(v));
indexAttr[cD.auxinFlux_v1].pos[2] += 0.1;
indexAttr[cD.auxinFlux_v2].pos[2] += 0.1;
indexAttr[cD.auxinFlux_v3].pos[2] += 0.2;
indexAttr[cD.auxinFlux_v4].pos[2] += 0.2;
}
if(parm("Draw Bounding Box") == "True") {
indexAttr[cD.box_v[0]].pos = cD.box[0];
indexAttr[cD.box_v[1]].pos = cD.box[1];
indexAttr[cD.box_v[2]].pos = cD.box[2];
indexAttr[cD.box_v[3]].pos = cD.box[3];
indexAttr[cD.axisCenter_v].pos = cD.centroid;
indexAttr[cD.axisMax_v].pos = cD.centroid + cD.axisMax;
indexAttr[cD.axisMin_v].pos = cD.centroid + cD.axisMin;
}
if(parm("Draw PGD Rescale").toDouble() > 0) {
double axixMax_gr = cD.axisMax_growthRate * parm("Draw PGD Rescale").toDouble();
double axixMin_gr = cD.axisMin_growthRate * parm("Draw PGD Rescale").toDouble();
indexAttr[cD.PDGmax_v1].pos = cD.centroid - (cD.axisMax / norm(cD.axisMax)) * axixMax_gr ;
indexAttr[cD.PDGmax_v2].pos = cD.centroid + (cD.axisMax / norm(cD.axisMax)) * axixMax_gr ;
indexAttr[cD.PDGmin_v1].pos = cD.centroid - (cD.axisMin / norm(cD.axisMin)) * axixMin_gr ;
indexAttr[cD.PDGmin_v2].pos = cD.centroid + (cD.axisMin / norm(cD.axisMin)) * axixMin_gr ;
}
}
// update FACES, MF, tensors etc...visuals
//#pragma omp parallel for
for(uint i = 0; i < cs.faces().size(); i++) {
CCIndex f = cs.faces()[i];
Tissue::FaceData& fD = faceAttr[f];
Tissue::CellData& cD = cellAttr[indexAttr[f].label];
fD.update(f, cs, indexAttr, vMAttr);
if(indexAttr[f].selected)
cD.selected = true;
// Green Strain Tensor?
if(parm("Draw Strain Tensors Rescale").toDouble() > 0) {
indexAttr[fD.G_v0].pos = indexAttr[f].pos;
indexAttr[fD.G_v1].pos = indexAttr[f].pos;
indexAttr[fD.G_v2].pos = indexAttr[f].pos;
indexAttr[fD.G_v1].pos += (Rotate(Point3d(cD.gMax,0,0), cD.gAngle) * parm("Draw Strain Tensors Rescale").toDouble());
indexAttr[fD.G_v2].pos += (Rotate(Point3d(cD.gMin,0,0), cD.gAngle + M_PI/2) * parm("Draw Strain Tensors Rescale").toDouble());
}
// MF
if(parm("Draw MF") == "True") {
indexAttr[fD.a1_v1].pos = indexAttr[f].pos;
indexAttr[fD.a1_v2].pos = indexAttr[f].pos + fD.a1;
indexAttr[fD.a2_v1].pos = indexAttr[f].pos;
indexAttr[fD.a2_v2].pos = indexAttr[f].pos + fD.a2;
}
// Signals
cellTypeSignal[f] = cellAttr[indexAttr[f].label].type;
cellLineageSignal[f] = cellAttr[indexAttr[f].label].lineage;
divisionCountSignal[f] = cellAttr[indexAttr[f].label].divisionCount;
areaSignal[f] = cD.area;
lifeTimeSignal[f] = cD.lifeTime;
stageSignal[f] = cD.stage;
auxinSignal[f] = cD.auxin;
auxinByAreaSignal[f] = cD.auxin / cD.area;
Aux1CytSignal[f] = fD.Aux1Cyt;
Aux1MemSignal[f] = fD.Aux1Mem;
divInhibitorCytSignal[f] = cD.divInhibitor;
divPromoterCytSignal[f] = cD.divPromoter;
divProbSignal[f] = cD.divProb;
Pin1CytSignal[f] = cD.Pin1;
Pin1MemSignal[f] = fD.Pin1Mem;
PINOIDCytSignal[f] = cD.PINOID;
PP2ACytSignal[f] = cD.PP2A;
PINOIDMemSignal[f] = fD.PINOIDMem;
PP2AMemSignal[f] = fD.PP2AMem;
quasimodoCytSignal[f] = cD.quasimodo;
wox5CytSignal[f] = cD.wox5;
pressureSignal[f] = cD.pressure;
brassinosteroidsSignal[f] = cD.brassinosteroids;
brassinosteroidSignal[f] = cD.brassinosteroidSignal;
brassinosteroidTopSignal[f] = cD.brassinosteroidTop;
ccvTIR1Signal[f] = cD.is_ccvTIR1tissue;
growthSignal[f] = cD.growthSignal;
cellStiffnessSignal[f] = cD.totalStiffness;
fD.auxin = cD.auxin;
fD.intercellularAuxin = 0;
fD.Aux1Cyt = cD.Aux1;
fD.Pin1Cyt = cD.Pin1;
fD.auxinRatio = 0;
fD.auxinGrad = 0;
fD.pin1Sensitivity = 0;
fD.Pin1Mem = 0;
fD.Aux1Mem = 0;
fD.PINOIDMem = 0;
fD.PP2AMem = 0;
fD.MFImpact = 0;
fD.geomImpact = 0;
fD.auxinFluxImpact = 0;
fD.edgeStrain = 0;
fD.edgeStiffness = 0;
fD.edgeUpdateRate = 0;
if(fD.type == Membrane) {
int es = 0;
for(CCIndex e : cs.incidentCells(f, 1)) {
Tissue::EdgeData& eD = edgeAttr[e];
if(eD.type == Tissue::Wall) {
fD.Pin1Mem += eD.Pin1[cD.label] / eD.length;
fD.Aux1Mem += eD.Aux1[cD.label] / eD.length;
fD.PINOIDMem += eD.PINOID[cD.label] / eD.length;
fD.PP2AMem += eD.PP2A[cD.label] / eD.length;
fD.intercellularAuxin += eD.intercellularAuxin / eD.length;
fD.edgeStrain += eD.strainRate;
fD.edgeStiffness += eD.eStiffness;
fD.edgeUpdateRate += eD.updateRate;
fD.pin1Sensitivity += eD.pin1Sensitivity[indexAttr[f].label];
fD.MFImpact += eD.MFImpact[indexAttr[f].label];
fD.geomImpact += eD.geomImpact[indexAttr[f].label];
fD.auxinFluxImpact += eD.auxinFluxImpact[indexAttr[f].label];
fD.auxinRatio += eD.auxinRatio[indexAttr[f].label];
fD.auxinGrad += eD.auxinGrad[indexAttr[f].label];
es++;
}
}
fD.edgeStrain /= es;
fD.edgeStiffness /= es;
fD.edgeUpdateRate /= es;
fD.pin1Sensitivity /= es;
fD.MFImpact /= es;
fD.geomImpact /= es;
fD.auxinFluxImpact /= es;
fD.auxinRatio /= es;
fD.auxinGrad /= es;
fD.Pin1Mem /= es;
fD.Aux1Mem /= es;
fD.PINOIDMem /= es;
fD.PP2AMem /= es;
fD.intercellularAuxin /= es;
}
intercellularAuxinSignal[f] = fD.intercellularAuxin;
edgeStrainSignal[f] = fD.edgeStrain;
edgeStiffnessSignal[f] = fD.edgeStiffness;
edgeRestLengthUpdateSignal[f] = fD.edgeUpdateRate;
pin1SensitivitySignal[f] = fD.pin1Sensitivity;
MFImpactSignal[f] = fD.MFImpact;
geomImpactSignal[f] = fD.geomImpact;
auxinFluxImpactSignal[f] = fD.auxinFluxImpact;
auxinGradSignal[f] = fD.auxinGrad;
auxinRatioSignal[f] = fD.auxinRatio;
growthRateSignal[f] = fD.growthRate;
}
// perimeters and borders lengths between cells
neighborhood2D(*mesh, cs, indexAttr, wallAreas, wallEdges);
return false;
}
void Tissue::CellData::division(const CCStructure &cs, const CCIndexDataAttr& indexAttr,
CellDataAttr& cellAttr, FaceDataAttr& faceAttr, EdgeDataAttr& edgeAttr, VertexDataAttr& vMAttr,
CellData& cD1, CellData& cD2, std::map<CellType, int> maxAreas, bool ignoreCellType) {
if(!tissue)
throw(QString("Tissue::CellData::division: tissue not set"));
Point3d cm, QCcm;
for(auto c : cellAttr) {
Tissue::CellData& cDn = cellAttr[c.first];
cm += cDn.centroid;
if(cDn.type == QC)
QCcm += cDn.centroid;
}
cm /= cellAttr.size();
QCcm /= 2; // assumes two QC cells
Point3d rootAxisY0 = Point3d(QCcm[0], -BIG_VAL, 0);
Point3d rootAxisY1 = Point3d(QCcm[0], BIG_VAL, 0);
Point3d rootAxisX0 = Point3d(-BIG_VAL, QCcm[1], 0);
Point3d rootAxisX1 = Point3d(BIG_VAL, QCcm[1], 0);
CellType type1 = type, type2 = type;
bool periclinalDivision1 = false, periclinalDivision2 = false;
if(!ignoreCellType) {
if(type == CEI) {
double dist1 = DistancePtLine(rootAxisX0, rootAxisX1, cD1.centroid);
double dist2 = DistancePtLine(rootAxisX0, rootAxisX1, cD2.centroid);