20 #include "../../cpp_simptshell/mesh_drawer/WallItem.h"
26 #include <QGraphicsScene>
27 #include <QGraphicsEllipseItem>
36 WallItem::WallItem(
Wall* w,
int wallnumber, QGraphicsScene* canvas,
double outlinewidth,
37 double magnification, array<double, 3> offset)
40 m_wall_number = wallnumber;
42 const Cell* c = (m_wall_number == 1) ? w->GetC1() : w->GetC2();
43 const Node& N1 = *(w->GetN1());
44 const Node& N2 = *(w->GetN2());
46 if (c->IsBoundaryPolygon()) {
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;
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]);
62 const auto center = (N1 + offset) * magnification;
63 QRectF rect(0, 0, outlinewidth, outlinewidth);
64 rect.moveCenter(QPointF(center[0], center[1]));
66 circle->setPen(Qt::NoPen);
67 circle->setBrush(QColor(
"Purple"));
68 circle->setZValue(256);
69 canvas->addItem(circle);
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;
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]);
91 void WallItem::setColor()
93 QColor diffcolor(0, 0, 0);
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);
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"));
104 if (m_wall->IsAuxinSink() && c->IsBoundaryPolygon()) {
105 setBrush(QColor(
"Blue"));
112 void WallItem::setColorWallStrength()
114 QColor diffcolor(0, 0, 0);
116 double wallstr = m_wall->GetStrength();
118 diffcolor.setRgb(255., 0, 0);
120 diffcolor.setRgb(0., 0, 255.);
126 void WallItem::setColor4Test()
129 QColor
const purple(
"Purple");
130 QColor
const blue(
"blue");
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);
144 diffcolor.setRgb( 255 , 0, 0);
148 diffcolor.setRgb( 0 , 0, 255);
151 if ((sa > (-
pi() / 4)) && (sa <= (
pi() / 4)))
153 diffcolor.setRgb( 255 , 0, 0);
155 else if ((sa <= (-
pi() * 3 / 4)) || (sa > (
pi() * 3 / 4)))
157 diffcolor.setRgb( 0 , 0, 255.);
159 else if ((sa > (-
pi() * 3 / 4)) && (sa <= (-
pi() / 4)))
161 diffcolor.setRgb( 0 , 255., 0);
163 else if ((sa > (
pi() / 4)) && (sa <= (
pi() * 3 / 4)))
165 diffcolor.setRgb( 255 , 0, 255.);
A cell contains walls and nodes.
Namespace for miscellaneous utilities.
Namespace for SimPT shell package.
see the online Qt documentation
Namespace for the core simulator.
std::array< double, 3 > GetCentroid() const
Return the centroid position.
Math constants and functions header combo.
constexpr double pi()
Math constant pi.
A cell wall, runs between cell corner points and consists of wall elements.