CMlib
Cell mapping algorithms in C++
coloring.h
Go to the documentation of this file.
1 #ifndef CELL_MAPPING_CPP_COLORING_H
2 #define CELL_MAPPING_CPP_COLORING_H
3 
4 #include <vector>
5 #include <cmath>
6 #include "cell.h"
7 
8 namespace cm {
9 
10  void hsv2rgb(double h, double s, double v, double& r, double& g, double& b);
11 
12  template <class CellType, class IDType>
14  public:
15  virtual std::vector<char> createColor(const CellType& cell, const IDType periodicGroups) {
16  return std::vector<char>(3, 0);
17  }
18  };
19 
20  template <class CellType, class IDType>
21  class SCMDefaultColoring : public SCMColoringMethod<CellType, IDType> {
22  std::vector<char> createColor(const CellType& cell,
23  const IDType periodicGroups) {
24  IDType group = cell.getGroup();
25  IDType step = cell.getStep();
26  // Create a HSV color with constant saturation
27  double h, s, v;
28  h = double(group) / periodicGroups;
29  s = 0.8; // Constant saturation
30  double transient_steps = 500.0;
31  if (step > 0) { /* Transient with shading */
32  v = 0.85 - fmin(0.5 * (double(step) / transient_steps), 0.5);
33  } else { // Periodic cells will be white
34  v=1.0; s=0.0;
35  }
36  if (group == 0) { // Sink cell's domain is white
37  v=1.0; s=0.0;
38  }
39  double r, g, b;
40  hsv2rgb(h, s, v, r, g, b);
41  std::vector<char> rgb(3);
42  rgb[0]=(char)(r*255.0);
43  rgb[1]=(char)(g*255.0);
44  rgb[2]=(char)(b*255.0);
45  return rgb;
46  }
47  };
48 
49  template <class CellType, class IDType>
50  class ClusteredSCMDefaultColoring : public SCMColoringMethod<CellType, IDType> {
51  std::vector<char> createColor(const CellType& cell,
52  const IDType periodicGroups) {
53  IDType group = cell.getGroup();
54  IDType step = cell.getStep();
55  IDType clusterID = cell.getClusterID();
56  // Create a HSV color with constant saturation
57  double h, s, v;
58  h = double(group) / periodicGroups;
59  s = 0.8;
60  double transient_steps = 500.0;
61  if (step > 0) { /* Transient with shading */
62  v = 0.85 - fmin(0.5 * (double(step) / transient_steps), 0.5);
63  } else { // Periodic cells will be white
64  v=1.0; s=0.0;
65  }
66  if (group == 0) { // Sink cell's domain is white
67  v=1.0; s=0.0;
68  }
69  double r, g, b;
70  hsv2rgb(h, s, v, r, g, b);
71  std::vector<char> rgb(3);
72  rgb[0]=(char)(r*255.0);
73  rgb[1]=(char)(g*255.0);
74  rgb[2]=(char)(b*255.0);
75  return rgb;
76  }
77  };
78 
79  template <class CellType, class IDType>
80  class SCMHeatMapColoring : public SCMColoringMethod<CellType, IDType> {
81  std::vector<char> createColor(const CellType& cell,
82  const IDType periodicGroups) {
83  IDType group = cell.getGroup();
84  IDType step = cell.getStep();
85  // Create a HSV color
86  double h, s, v;
87  double transient_steps = 200.0;
88  h = double(step)/transient_steps; // Hue based on step number
89  s = 0.8; // Constant saturation
90  v = 0.8; // Constant value
91  if (group == 0) {
92  v = 0; // Sink cell's domain
93  }
94  double r, g, b;
95  hsv2rgb(h, s, v, r, g, b);
96  std::vector<char> rgb(3);
97  rgb[0]=(char)(r*255);
98  rgb[1]=(char)(g*255);
99  rgb[2]=(char)(b*255);
100  return rgb;
101  }
102  };
103 
104  template <class CellType, class IDType>
105  class SCMBlackAndWhiteColoring : public SCMColoringMethod<CellType, IDType> {
106  std::vector<char> createColor(const CellType& cell,
107  const IDType periodicGroups) {
108  IDType group = cell.getGroup();
109  IDType step = cell.getStep();
110  // Create a HSV color
111  double h, s, v;
112  h = 0.0;
113  s = 0.0; // Constant saturation
114  v = 0.6+0.4*double(step)/200.0; if (v > 1.0) v = 1.0;
115  if (step == 0) { v = 0.0; } // Periodic cells will be black
116  double r, g, b;
117  hsv2rgb(h, s, v, r, g, b);
118  std::vector<char> rgb(3);
119  rgb[0]=(char)(r*255);
120  rgb[1]=(char)(g*255);
121  rgb[2]=(char)(b*255);
122  return rgb;
123  }
124  };
125 }
126 
127 
128 #endif //CELL_MAPPING_CPP_COLORING_H
Definition: coloring.h:80
Definition: coloring.h:50
void hsv2rgb(double h, double s, double v, double &r, double &g, double &b)
Definition: coloring.cpp:9
Definition: coloring.h:21
Definition: coloring.h:105
Definition: coloring.h:13
virtual std::vector< char > createColor(const CellType &cell, const IDType periodicGroups)
Definition: coloring.h:15
Definition: cell.h:6