BinToMovingBrkPt.cxx
Go to the documentation of this file.
1 
12 #include "BinToMovingBrkPt.h"
13 
14 #include <cassert>
15 
16 namespace hippodraw {
17 
19 BinToMovingBrkPt ( const char * name )
20  : BinToColor ( name )
21 {
22  m_control_points.push_back(0.5);
23  m_control_points.push_back(0.5);
24  m_control_points.push_back(0.5);
25 }
26 
28  : BinToColor ( bin_to_color )
29 {
30 
31  if(m_control_points.size()==0)
32  {
33  m_control_points.push_back(0.5);
34  m_control_points.push_back(0.5);
35  m_control_points.push_back(0.5);
36  }
37 }
38 
40 {
41  return new BinToMovingBrkPt ( *this );
42 }
43 
44 void BinToMovingBrkPt::doubleToColor ( double value, Color & color ) const
45 {
46  double r=1;double g = 1;double b =1;
47 // double dv = m_range.length ();
48 // double vmin = m_range.low ();
49  double v = value;
50  assert(m_control_points.size()!=0);
51 
52  double brk_pt = m_control_points[0];
53  double flat = m_control_points[1];
54 
55  if ( brk_pt < (1 - brk_pt))
56  flat = flat * ( brk_pt);
57  else flat = flat * ( 1 - brk_pt);
58 
59  if ( v < (m_vmin + brk_pt * m_dv))
60  r = 0;
61  else r = ( v - m_vmin - brk_pt*m_dv ) / ( ( 1.05 - brk_pt ) * m_dv );
62 
63 
64  if ( v < (m_vmin + (brk_pt - flat) * m_dv ))
65  g = (v - m_vmin) / ( (0.05+brk_pt - flat) * m_dv );
66  else if ( v > ( m_vmin + (brk_pt + flat) * m_dv ))
67  g = 1 - ( v - m_vmin - ( brk_pt + flat )*m_dv) /
68  ( (1.05 - brk_pt - flat) * m_dv );
69  else g = 1;
70 
71 
72  if ( v < ( m_vmin + brk_pt *m_dv))
73  b = ( m_vmin + brk_pt*m_dv - v ) / ( (brk_pt+0.05) * m_dv );
74  else b = 0;
75 
76 
77  int red = static_cast < int > ( r * 255. );
78  int green = static_cast < int > ( g * 255. );
79  int blue = static_cast < int > ( b * 255. );
80 
81 
82  assert ( red < 256 && green < 256 && blue < 256 );
83  color.setColor ( red, green, blue );
84 }
85 
86 bool
89 {
90  return true;
91 }
92 
93 } // namespace hippodraw

Generated for HippoDraw Class Library by doxygen