BinToColorScaleMovingBrkPt.cxx
Go to the documentation of this file.
1 
13 
14 #include <cmath>
15 #include <cassert>
16 
17 using std::vector;
18 
19 using namespace hippodraw;
20 
22 BinToColorScaleMovingBrkPt ( const char * name )
23  : BinToColor ( name )
24 {
25  m_control_points.push_back(0.5);
26  m_control_points.push_back(0.25);
27  m_control_points.push_back(0);
28 
29 }
30 
32 BinToColorScaleMovingBrkPt ( const std::vector < double > & sv,
33  const char * model_name)
34  : BinToColor ( model_name )
35 {
36  assert(sv.size()!=0);
37  m_control_points.push_back(sv[0]);
38  m_control_points.push_back(sv[1]);
39  m_control_points.push_back(sv[2]);
40 }
41 
44  : BinToColor ( bin_to_color )
45 {
46 
47  if(m_control_points.size()==0)
48  {
49  m_control_points.push_back( 0.5 );
50  m_control_points.push_back( 0.25 );
51  m_control_points.push_back( 0 );
52  }
53 }
54 
56 {
57  return new BinToColorScaleMovingBrkPt ( *this );
58 }
59 
60 
61 void
63 doubleToColor ( double value, Color & color ) const
64 {
65  double r = 1; double g = 1; double b = 1;
66  double v = value;
67 
68  assert(m_control_points.size()!=0);
69  double brk_pt = m_control_points[0];
70  double flat = m_control_points[1];
71  double col = m_control_points[2];
72 
73 
74  if ( brk_pt <= (1 - brk_pt))
75  flat = flat * ( brk_pt);
76  else flat = flat * ( 1 - brk_pt);
77 
78  if ( v < ( m_vmin + col*m_dv ) )
79  v = v + 1.5 * m_dv;
80 
81  //Red
82  if ( v < ( m_vmin + ( 1.25 * brk_pt - 0.5 * flat + col) * m_dv ) )
83  r = 0;
84 
85  else if ( v > ( m_vmin + ( 1.25 * brk_pt - 0.5 * flat + col) * m_dv ) &&
86  v < ( m_vmin + ( 1.25 * brk_pt + 0.5 * flat + col) * m_dv ) )
87  r = ( v - m_vmin - ( 1.25 * brk_pt - 0.5 * flat + col) * m_dv ) /
88  ( ( (flat+0.001) ) * m_dv );
89 
90  else if( v > ( m_vmin + ( 1.25 * brk_pt + 0.5 * flat + col) * m_dv ) &&
91  v < ( m_vmin + ( 1.25 + col ) * m_dv ) )
92  r = 1;
93 
94  else r = 1 - 4 * ( v - m_vmin - ( 1.25 + col ) * m_dv ) / m_dv;
95 
96 
97  //Green
98  if ( v < (m_vmin + (brk_pt - flat + col) * m_dv ))
99  g = (v - m_vmin - col*m_dv ) / ( (0.001+brk_pt - flat ) * m_dv );
100 
101  else if ( v > (m_vmin + (brk_pt - flat + col) * m_dv ) &&
102  v < ( m_vmin + (brk_pt + flat + col) * m_dv ) )
103  g = 1;
104 
105  else if ( v > ( m_vmin + (brk_pt + flat + col) * m_dv ) &&
106  v < ( m_vmin + ( 1 + col ) * m_dv ) )
107 
108  g = 1 - ( v - m_vmin - ( brk_pt + flat + col )*m_dv)/
109  ( (1.001 - brk_pt - flat ) * m_dv );
110 
111  else g = 0;
112 
113 
114  //Blue
115  if ( v < (m_vmin + ( 0.75 * brk_pt - 0.5 * flat + col ) * m_dv ) )
116  b = 1;
117 
118  else if ( v > (m_vmin + ( 0.75 * brk_pt - 0.5 * flat + col ) * m_dv ) &&
119  v < (m_vmin + ( 0.75 * brk_pt + 0.5 * flat + col) * m_dv ) )
120 
121  b = 1 - ( v - m_vmin - ( 0.75 * brk_pt - 0.5 * flat + col )*m_dv ) /
122  ( ( (flat + 0.001) ) * m_dv );
123 
124  else if ( v > (m_vmin + ( 0.75 * brk_pt + 0.5 * flat + col) * m_dv ) &&
125  v < ( m_vmin + ( 1 + col ) * m_dv ) )
126  b = 0;
127 
128  else if ( v > ( m_vmin + ( 1 + col ) * m_dv ) &&
129  v < ( m_vmin + ( 1.25 + col ) * m_dv ) )
130 
131  b = 4 * ( v - m_vmin - ( 1 + col ) * m_dv ) / m_dv ;
132 
133  else b = 1;
134 
135  int red = static_cast < int > ( r * 255. );
136  int green = static_cast < int > ( g * 255. );
137  int blue = static_cast < int > ( b * 255. );
138 
139 
140  assert ( red < 256 && green < 256 && blue < 256 );
141  color.setColor ( red, green, blue );
142 }
143 
144 bool
147 {
148  return true;
149 }

Generated for HippoDraw Class Library by doxygen