VPTissue Reference Manual
WallItem.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "../../cpp_simptshell/mesh_drawer/WallItem.h"
21 
22 #include "bio/Cell.h"
23 #include "bio/Node.h"
24 #include "math/math.h"
25 
26 #include <QGraphicsScene>
27 #include <QGraphicsEllipseItem>
28 #include <QPainter>
29 
30 namespace SimPT_Shell {
31 
32 using namespace std;
33 using namespace SimPT_Sim::Util;
34 using namespace SimPT_Sim;
35 
36 WallItem::WallItem(Wall* w, int wallnumber, QGraphicsScene* canvas, double outlinewidth,
37  double magnification, array<double, 3> offset)
38  : m_wall(w)
39 {
40  m_wall_number = wallnumber;
41  QPolygonF polygon;
42  const Cell* c = (m_wall_number == 1) ? w->GetC1() : w->GetC2();
43  const Node& N1 = *(w->GetN1());
44  const Node& N2 = *(w->GetN2());
45 
46  if (c->IsBoundaryPolygon()) {
47  // line with "PIN1"is a bit inside the cell wall
48  const auto edgevec = Normalize(N2 - N1);
49  const auto perp = Orthogonalize(edgevec) * outlinewidth * 0.5;
50  const auto fromPlus = (N1 + offset + perp) * magnification;
51  const auto fromMin = (N1 + offset - perp) * magnification;
52  const auto toPlus = (N2 + offset + perp) * magnification;
53  const auto toMin = (N2 + offset - perp) * magnification;
54 
55  polygon << QPointF(fromPlus[0], fromPlus[1])
56  << QPointF(toPlus[0], toPlus[1])
57  << QPointF(toMin[0], toMin[1])
58  << QPointF(fromMin[0], fromMin[1])
59  << QPointF(fromPlus[0], fromPlus[1]);
60 
61  // Place a circle at the far end of each boundary polygon wallitem
62  const auto center = (N1 + offset) * magnification;
63  QRectF rect(0, 0, outlinewidth, outlinewidth);
64  rect.moveCenter(QPointF(center[0], center[1]));
65  QGraphicsEllipseItem* circle = new QGraphicsEllipseItem(rect);
66  circle->setPen(Qt::NoPen);
67  circle->setBrush(QColor("Purple"));
68  circle->setZValue(256);
69  canvas->addItem(circle);
70  } else {
71  const auto centroid = c->GetCentroid();
72  const auto middle1 = (offset + 0.5 * (centroid + N1)) * magnification;
73  const auto middle2 = (offset + 0.5 * (centroid + N2)) * magnification;
74  const auto middle11 = (offset + 0.5 * (middle1 + N1)) * magnification;
75  const auto middle22 = (offset + 0.5 * (middle2 + N2)) * magnification;
76 
77  polygon << QPointF(middle1[0], middle1[1])
78  << QPointF(middle2[0], middle2[1])
79  << QPointF(middle22[0], middle22[1])
80  << QPointF(middle11[0], middle11[1])
81  << QPointF(middle1[0], middle1[1]);
82  }
83  setPolygon(polygon);
84  setColor();//DDV
85 // setColor4Test();//DDV
86 // setColorWallStrength();//DDV
87  setZValue(120);
88  show();
89 }
90 
91 void WallItem::setColor()
92 {
93  QColor diffcolor(0, 0, 0);
94 
95  if (m_wall->GetTransporters1().size() >= 2) {
96  const double tr = m_wall_number == 1 ? m_wall->GetTransporters1(1) : m_wall->GetTransporters2(1);
97  diffcolor.setRgb(static_cast<int>((tr / (1 + tr)) * 255.0), 0, 0);
98  }
99 
100  const Cell* c = (m_wall_number == 1) ? m_wall->GetC1() : m_wall->GetC2();
101  if (m_wall->IsAuxinSource() && c->IsBoundaryPolygon()) {
102  setBrush(QColor("Purple"));
103  } else {
104  if (m_wall->IsAuxinSink() && c->IsBoundaryPolygon()) {
105  setBrush(QColor("Blue"));
106  } else {
107  setBrush(diffcolor);
108  }
109  }
110 }
111 
112 void WallItem::setColorWallStrength()
113 {
114  QColor diffcolor(0, 0, 0);
115 
116  double wallstr = m_wall->GetStrength();
117  if (wallstr >= 2) {
118  diffcolor.setRgb(255., 0, 0);
119  } else {
120  diffcolor.setRgb(0., 0, 255.);
121  }
122  setBrush(diffcolor);
123 }
124 
125 
126 void WallItem::setColor4Test()//DDV2012: alternative method for coloring walls, i.e. based on strain rates
127 {
128  QColor diffcolor;
129  QColor const purple("Purple");
130  QColor const blue("blue");
131 
132 // Wall* const w = &getWall();
133 // double const tr = wn==1?w->Transporters1(1):w->Transporters2(1);//DDV2012: redundant code ...
134 // diffcolor.setRgb( (int)( ( log2(1+tr) / (1 + log2(1+tr)) )*255.), 0, 0);//DDV2012
135 // CellBase* const c = wn==1?m_wall->C1():m_wall->C2();
136 // diffcolor.setRgb( (int)( ( tr / (1 + tr) )*255.), 0, 0);//DDV2012
137 
138  //DDV2012: alternative method for coloring walls, i.e. based on strain rates
139  std::array<double, 3> ref{{1., 0., 0.}};
140  std::array<double, 3> wa = *(m_wall->GetN2()) - *(m_wall->GetN1());
141  double sa = SignedAngle(wa, ref);
142  if (sa >= 0 )//DDV2012: linear range for small positive interval
143  {
144  diffcolor.setRgb( 255 , 0, 0);
145  }
146  else if ( sa < 0. )
147  {
148  diffcolor.setRgb( 0 , 0, 255);
149  }
150 
151  if ((sa > (-pi() / 4)) && (sa <= (pi() / 4)))
152  { //UPPER WALL: I
153  diffcolor.setRgb( 255 , 0, 0);
154  }
155  else if ((sa <= (-pi() * 3 / 4)) || (sa > (pi() * 3 / 4)))
156  { //LOWER WALL: II
157  diffcolor.setRgb( 0 , 0, 255.);
158  }
159  else if ((sa > (-pi() * 3 / 4)) && (sa <= (-pi() / 4)))
160  { //RIGHT WALL?: III
161  diffcolor.setRgb( 0 , 255., 0);
162  }
163  else if ((sa > (pi() / 4)) && (sa <= (pi() * 3 / 4)))
164  { //LEFT WALL?: IV
165  diffcolor.setRgb( 255 , 0, 255.);
166  }
167 
168  setBrush(diffcolor);
169 
170  //DDV2012 - END
171 
172 // if (w->AuxinSource() && c->BoundaryPolP())
173 // {
174 // setBrush(purple);
175 // }
176 // else
177 // {
178 // if (w->AuxinSink() && c->BoundaryPolP())
179 // {
180 // setBrush(blue);
181 // }
182 // else
183 // {
184 // setBrush(diffcolor);
185 // }
186 // }
187 }
188 
189 
190 } // namespace
STL namespace.
A cell contains walls and nodes.
Definition: Cell.h:48
Node in cell wall.
Definition: Node.h:39
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Namespace for SimPT shell package.
Definition: Client.cpp:50
see the online Qt documentation
Namespace for the core simulator.
Interface for Cell.
Interface for Node.
std::array< double, 3 > GetCentroid() const
Return the centroid position.
Definition: Cell.cpp:205
Math constants and functions header combo.
constexpr double pi()
Math constant pi.
Definition: constants.h:29
A cell wall, runs between cell corner points and consists of wall elements.
Definition: Wall.h:48