Whiteboard
An interface and tools for visualizing large and complex datasets
Density.h
Go to the documentation of this file.
1 #ifndef DENSITY_H
2 #define DENSITY_H
3 
4 #include "visual/Whiteboard.h"
5 #include "visual/Color.h"
6 #include <math.h>
7 
8 class Density
9 {
10  public:
11  Density(int nX, int nY,
12  double saturate = -1., // Uses max value if not set
13  const color & low = color(0.99, 0.99, 0.99),
14  const color & mid = color(0.99, 0.99, 0),
15  const color & hi = color(0.99, 0., 0.)) {
16  m_lo = low;
17  m_mi = mid;
18  m_hi = hi;
19  m_saturate = saturate;
20  m_dens.resize(nX);
21  for (int i=0; i<m_dens.isize(); i++)
22  m_dens[i].resize(nY, 0.);
23  m_max = 0.;
24  }
25 
26  void Add(double x, double y, double weight = 1., bool bNormalize = false) {
27  int x1 = (int)(x + 0.5);
28  int y1 = (int)(y + 0.5);
29  if (bNormalize) {
30  x1 = (int)(x / (double)m_dens.isize() + 0.5);
31  y1 = (int)(y / (double)m_dens[0].isize() + 0.5);
32  }
33  if (x1 < 0 || x1 > m_dens.isize()) {
34  cout << "ERROR: x is out of bounds: " << x << endl;
35  return;
36  }
37  if (y1 < 0 || y1 > m_dens[0].isize()) {
38  cout << "ERROR: y is out of bounds: " << y << endl;
39  return;
40  }
41 
42  svec<double> & d = m_dens[x1];
43  d[y1] += weight;
44  if (d[y1] > m_max)
45  m_max = d[y1];
46  }
47 
49  const ns_whiteboard::xy_coords & where,
50  double pointsPerPixel) {
51  int i, j;
52  for (i=0; i<m_dens.isize(); i++) {
53  svec<double> & d = m_dens[i];
54  for (j=0; j<d.isize(); j++) {
55  double v = d[j];
56  double x1 = where.first + pointsPerPixel*(double)i;
57  double y1 = where.second + pointsPerPixel*(double)(j+1);
58  double x2 = where.first + pointsPerPixel*(double)(i+1);
59  double y2 = where.second + pointsPerPixel*(double)j;
60  if (m_saturate > 0.) {
61  v /= m_saturate;
62  } else {
63  v /= m_max;
64  }
65  if (v > 0.999)
66  v = 0.999;
67  v = v*2 - 1.;
68  color cc = GradientMult(v, m_lo, m_hi, m_mi);
71  cc) );
72 
73  }
74  }
75 
76 
77  }
78 
79  private:
81  double m_saturate;
82  double m_max;
86 };
87 
88 
89 
90 
91 
92 #endif
93 
94 
Definition: Whiteboard.h:154
double m_saturate
Definition: Density.h:81
color m_mi
Definition: Density.h:84
void Add(graphic *g)
Definition: Whiteboard.h:162
pair< double, double > xy_coords
Definition: Whiteboard.h:30
color m_hi
Definition: Density.h:85
int isize() const
Definition: SVector.h:19
Definition: Density.h:8
File holding the base drawing classes of the whiteboard.
void Add(double x, double y, double weight=1., bool bNormalize=false)
Definition: Density.h:26
void Draw(ns_whiteboard::whiteboard &board, const ns_whiteboard::xy_coords &where, double pointsPerPixel)
Definition: Density.h:48
Definition: Whiteboard.h:319
Density(int nX, int nY, double saturate=-1., const color &low=color(0.99, 0.99, 0.99), const color &mid=color(0.99, 0.99, 0), const color &hi=color(0.99, 0., 0.))
Definition: Density.h:11
svec< svec< double > > m_dens
Definition: Density.h:80
color m_lo
Definition: Density.h:83
Definition: Color.h:12
color GradientMult(double val, const color &neg, const color &pos, const color &back=color(0.99, 0.99, 0.99))
Definition: Color.h:106
double m_max
Definition: Density.h:82