VPTissue Reference Manual
ChemGreen.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 "ChemGreen.h"
21 
22 #include "bio/Cell.h"
23 #include "util/color/hsv.h"
24 #include "util/color/Hsv2Rgb.h"
25 
26 #include <boost/property_tree/ptree.hpp>
27 
28 namespace SimPT_Default {
29 namespace CellColor {
30 
31 using namespace std;
32 using namespace SimPT_Sim::Color;
33 
34 ChemGreen::ChemGreen(const boost::property_tree::ptree& , unsigned int index)
35  : m_index(index)
36 {
37 }
38 
39 array<double, 3> ChemGreen::operator()(SimPT_Sim::Cell* cell)
40 {
41  const double c0 = (cell->GetChemicals().size() > m_index) ? cell->GetChemical(m_index) : 0.0;
42  const double conc = max(c0, 0.0) / cell->GetArea();
43 
44  // ------------------------------------------------------------------
45  // Lime green at full saturation; brightness (value) proportional
46  // to log10 of concentration with 1.0 as reference concentration
47  // and a range of four orders of magnitude: concentrations above
48  // that get mapped to brightness 1.0 anyway.
49  // ------------------------------------------------------------------
50 // const double h = 120.0 / 360.0; // lime green
51 // const double s = 1.0; // full saturation
52 // // value 0.0 corresponds to black; value 1.0 is green.
53 // const double lower = 1.0e-4;
54 // const double v = min(max(0.0, log10(conc/lower)), 1.0);
55 
56  const double x = log10(conc);
57 
58  const double x_black = -4.0;
59  const double x_lime = -3.0;
60 
61  hsv_t t_color;
62  if (x < x_black) {
63  t_color = black;
64  }
65  else if (x < x_lime) {
66  t_color = interpolate(x, black, x_black, lime, x_lime);
67  }
68  else {
69  t_color = lime;
70  }
71 
72  return Hsv2Rgb(get<0>(t_color), get<1>(t_color), get<2>(t_color));
73 }
74 
75 } // namespace
76 } // namespace
77 
78 
STL namespace.
A cell contains walls and nodes.
Definition: Cell.h:48
ChemGreen(const boost::property_tree::ptree &pt, unsigned int index)
Straight initialization.
Definition: ChemGreen.cpp:34
Namespace for components of the Default model group.
Interface for Cell.
Header file for HSV colors.
std::array< double, 3 > operator()(SimPT_Sim::Cell *cell)
Return color value.
Definition: ChemGreen.cpp:39
Namespace for color utilities.
Definition: hsv.h:27
Rgb color def to Hsv color def: r,g,b values are from 0 to 1 and h = [0,360], s = [0...
CellColor ChemGreen scheme (use black background).
double GetArea() const
Return the area of the cell.
Definition: Cell.cpp:178